1 //===- DelayedDiagnostic.cpp - Delayed declarator diagnostics -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the DelayedDiagnostic class implementation, which
11 // is used to record diagnostics that are being conditionally produced
12 // during declarator parsing.
13 //
14 // This file also defines AccessedEntity.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #include "clang/Sema/DelayedDiagnostic.h"
19 #include <cstring>
20 
21 using namespace clang;
22 using namespace sema;
23 
24 DelayedDiagnostic
25 DelayedDiagnostic::makeAvailability(AvailabilityResult AR,
26                                     ArrayRef<SourceLocation> Locs,
27                                     const NamedDecl *ReferringDecl,
28                                     const NamedDecl *OffendingDecl,
29                                     const ObjCInterfaceDecl *UnknownObjCClass,
30                                     const ObjCPropertyDecl  *ObjCProperty,
31                                     StringRef Msg,
32                                     bool ObjCPropertyAccess) {
33   assert(!Locs.empty());
34   DelayedDiagnostic DD;
35   DD.Kind = Availability;
36   DD.Triggered = false;
37   DD.Loc = Locs.front();
38   DD.AvailabilityData.ReferringDecl = ReferringDecl;
39   DD.AvailabilityData.OffendingDecl = OffendingDecl;
40   DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
41   DD.AvailabilityData.ObjCProperty = ObjCProperty;
42   char *MessageData = nullptr;
43   if (!Msg.empty()) {
44     MessageData = new char [Msg.size()];
45     memcpy(MessageData, Msg.data(), Msg.size());
46   }
47   DD.AvailabilityData.Message = MessageData;
48   DD.AvailabilityData.MessageLen = Msg.size();
49 
50   DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()];
51   memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(),
52          sizeof(SourceLocation) * Locs.size());
53   DD.AvailabilityData.NumSelectorLocs = Locs.size();
54 
55   DD.AvailabilityData.AR = AR;
56   DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
57   return DD;
58 }
59 
60 void DelayedDiagnostic::Destroy() {
61   switch (Kind) {
62   case Access:
63     getAccessData().~AccessedEntity();
64     break;
65 
66   case Availability:
67     delete[] AvailabilityData.Message;
68     delete[] AvailabilityData.SelectorLocs;
69     break;
70 
71   case ForbiddenType:
72     break;
73   }
74 }
75