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                                     SourceLocation Loc,
27                                     const NamedDecl *ReferringDecl,
28                                     const NamedDecl *OffendingDecl,
29                                     const ObjCInterfaceDecl *UnknownObjCClass,
30                                     const ObjCPropertyDecl  *ObjCProperty,
31                                     StringRef Msg,
32                                     bool ObjCPropertyAccess) {
33   DelayedDiagnostic DD;
34   DD.Kind = Availability;
35   DD.Triggered = false;
36   DD.Loc = Loc;
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 
47   DD.AvailabilityData.Message = MessageData;
48   DD.AvailabilityData.MessageLen = Msg.size();
49   DD.AvailabilityData.AR = AR;
50   DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
51   return DD;
52 }
53 
54 void DelayedDiagnostic::Destroy() {
55   switch (Kind) {
56   case Access:
57     getAccessData().~AccessedEntity();
58     break;
59 
60   case Availability:
61     delete[] AvailabilityData.Message;
62     break;
63 
64   case ForbiddenType:
65     break;
66   }
67 }
68