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(Sema::AvailabilityDiagnostic AD,
24                                     SourceLocation Loc,
25                                     const NamedDecl *D,
26                                     const ObjCInterfaceDecl *UnknownObjCClass,
27                                     const ObjCPropertyDecl  *ObjCProperty,
28                                     StringRef Msg) {
29   DelayedDiagnostic DD;
30   switch (AD) {
31     case Sema::AD_Deprecation:
32       DD.Kind = Deprecation;
33       break;
34     case Sema::AD_Unavailable:
35       DD.Kind = Unavailable;
36       break;
37   }
38   DD.Triggered = false;
39   DD.Loc = Loc;
40   DD.DeprecationData.Decl = D;
41   DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
42   DD.DeprecationData.ObjCProperty = ObjCProperty;
43   char *MessageData = 0;
44   if (Msg.size()) {
45     MessageData = new char [Msg.size()];
46     memcpy(MessageData, Msg.data(), Msg.size());
47   }
48 
49   DD.DeprecationData.Message = MessageData;
50   DD.DeprecationData.MessageLen = Msg.size();
51   return DD;
52 }
53 
54 void DelayedDiagnostic::Destroy() {
55   switch (Kind) {
56   case Access:
57     getAccessData().~AccessedEntity();
58     break;
59 
60   case Deprecation:
61     delete [] DeprecationData.Message;
62     break;
63 
64   case ForbiddenType:
65     break;
66   }
67 }
68