clang  14.0.0git
DelayedDiagnostic.cpp
Go to the documentation of this file.
1 //===- DelayedDiagnostic.cpp - Delayed declarator diagnostics -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the DelayedDiagnostic class implementation, which
10 // is used to record diagnostics that are being conditionally produced
11 // during declarator parsing.
12 //
13 // This file also defines AccessedEntity.
14 //
15 //===----------------------------------------------------------------------===//
16 
18 #include <cstring>
19 
20 using namespace clang;
21 using namespace sema;
22 
26  const NamedDecl *ReferringDecl,
27  const NamedDecl *OffendingDecl,
28  const ObjCInterfaceDecl *UnknownObjCClass,
29  const ObjCPropertyDecl *ObjCProperty,
30  StringRef Msg,
31  bool ObjCPropertyAccess) {
32  assert(!Locs.empty());
34  DD.Kind = Availability;
35  DD.Triggered = false;
36  DD.Loc = Locs.front();
37  DD.AvailabilityData.ReferringDecl = ReferringDecl;
38  DD.AvailabilityData.OffendingDecl = OffendingDecl;
39  DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
40  DD.AvailabilityData.ObjCProperty = ObjCProperty;
41  char *MessageData = nullptr;
42  if (!Msg.empty()) {
43  MessageData = new char [Msg.size()];
44  memcpy(MessageData, Msg.data(), Msg.size());
45  }
46  DD.AvailabilityData.Message = MessageData;
47  DD.AvailabilityData.MessageLen = Msg.size();
48 
49  DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()];
50  memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(),
51  sizeof(SourceLocation) * Locs.size());
52  DD.AvailabilityData.NumSelectorLocs = Locs.size();
53 
54  DD.AvailabilityData.AR = AR;
55  DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
56  return DD;
57 }
58 
60  switch (Kind) {
61  case Access:
62  getAccessData().~AccessedEntity();
63  break;
64 
65  case Availability:
66  delete[] AvailabilityData.Message;
67  delete[] AvailabilityData.SelectorLocs;
68  break;
69 
70  case ForbiddenType:
71  break;
72  }
73 }
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1151
clang::sema::DelayedDiagnostic::getAccessData
AccessedEntity & getAccessData()
Definition: DelayedDiagnostic.h:168
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::sema::DelayedDiagnostic::Loc
SourceLocation Loc
Definition: DelayedDiagnostic.h:131
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1549
clang::sema::DelayedDiagnostic
A diagnostic message which has been conditionally emitted pending the complete parsing of the current...
Definition: DelayedDiagnostic.h:124
clang::sema::DelayedDiagnostic::Kind
DDKind Kind
Definition: DelayedDiagnostic.h:128
clang::sema::DelayedDiagnostic::Destroy
void Destroy()
Definition: DelayedDiagnostic.cpp:59
DelayedDiagnostic.h
clang::sema::DelayedDiagnostic::Availability
@ Availability
Definition: DelayedDiagnostic.h:126
clang::sema::DelayedDiagnostic::Access
@ Access
Definition: DelayedDiagnostic.h:126
clang::sema::DelayedDiagnostic::ForbiddenType
@ ForbiddenType
Definition: DelayedDiagnostic.h:126
clang::sema::DelayedDiagnostic::AvailabilityData
struct AD AvailabilityData
Definition: DelayedDiagnostic.h:254
llvm::ArrayRef
Definition: LLVM.h:34
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:732
clang
Definition: CalledOnceCheck.h:17
clang::AvailabilityResult
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:75
clang::sema::DelayedDiagnostic::makeAvailability
static DelayedDiagnostic makeAvailability(AvailabilityResult AR, ArrayRef< SourceLocation > Locs, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess)
Definition: DelayedDiagnostic.cpp:24
clang::sema::DelayedDiagnostic::Triggered
bool Triggered
Definition: DelayedDiagnostic.h:129