Path: blob/main/contrib/llvm-project/clang/lib/Sema/DelayedDiagnostic.cpp
35234 views
//===- DelayedDiagnostic.cpp - Delayed declarator diagnostics -------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the DelayedDiagnostic class implementation, which9// is used to record diagnostics that are being conditionally produced10// during declarator parsing.11//12// This file also defines AccessedEntity.13//14//===----------------------------------------------------------------------===//1516#include "clang/Sema/DelayedDiagnostic.h"17#include <cstring>1819using namespace clang;20using namespace sema;2122DelayedDiagnostic23DelayedDiagnostic::makeAvailability(AvailabilityResult AR,24ArrayRef<SourceLocation> Locs,25const NamedDecl *ReferringDecl,26const NamedDecl *OffendingDecl,27const ObjCInterfaceDecl *UnknownObjCClass,28const ObjCPropertyDecl *ObjCProperty,29StringRef Msg,30bool ObjCPropertyAccess) {31assert(!Locs.empty());32DelayedDiagnostic DD;33DD.Kind = Availability;34DD.Triggered = false;35DD.Loc = Locs.front();36DD.AvailabilityData.ReferringDecl = ReferringDecl;37DD.AvailabilityData.OffendingDecl = OffendingDecl;38DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;39DD.AvailabilityData.ObjCProperty = ObjCProperty;40char *MessageData = nullptr;41if (!Msg.empty()) {42MessageData = new char [Msg.size()];43memcpy(MessageData, Msg.data(), Msg.size());44}45DD.AvailabilityData.Message = MessageData;46DD.AvailabilityData.MessageLen = Msg.size();4748DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()];49memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(),50sizeof(SourceLocation) * Locs.size());51DD.AvailabilityData.NumSelectorLocs = Locs.size();5253DD.AvailabilityData.AR = AR;54DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;55return DD;56}5758void DelayedDiagnostic::Destroy() {59switch (Kind) {60case Access:61getAccessData().~AccessedEntity();62break;6364case Availability:65delete[] AvailabilityData.Message;66delete[] AvailabilityData.SelectorLocs;67break;6869case ForbiddenType:70break;71}72}737475