1 //===--- DelayedDiagnostic.cpp - Delayed declarator diagnostics -*- C++ -*-===//
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 #include "clang/Sema/DelayedDiagnostic.h"
18 #include <string.h>
19 using namespace clang;
20 using namespace sema;
21 
22 DelayedDiagnostic
23 DelayedDiagnostic::makeAvailability(AvailabilityResult AR,
24                                     SourceLocation Loc,
25                                     const NamedDecl *D,
26                                     const ObjCInterfaceDecl *UnknownObjCClass,
27                                     const ObjCPropertyDecl  *ObjCProperty,
28                                     StringRef Msg,
29                                     bool ObjCPropertyAccess) {
30   DelayedDiagnostic DD;
31   DD.Kind = Availability;
32   DD.Triggered = false;
33   DD.Loc = Loc;
34   DD.AvailabilityData.Decl = D;
35   DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
36   DD.AvailabilityData.ObjCProperty = ObjCProperty;
37   char *MessageData = nullptr;
38   if (Msg.size()) {
39     MessageData = new char [Msg.size()];
40     memcpy(MessageData, Msg.data(), Msg.size());
41   }
42 
43   DD.AvailabilityData.Message = MessageData;
44   DD.AvailabilityData.MessageLen = Msg.size();
45   DD.AvailabilityData.AR = AR;
46   DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
47   return DD;
48 }
49 
50 void DelayedDiagnostic::Destroy() {
51   switch (Kind) {
52   case Access:
53     getAccessData().~AccessedEntity();
54     break;
55 
56   case Availability:
57     delete[] AvailabilityData.Message;
58     break;
59 
60   case ForbiddenType:
61     break;
62   }
63 }
64