]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Sema/DelayedDiagnostic.cpp
MFV r331708:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Sema / DelayedDiagnostic.cpp
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 *ReferringDecl,
26                                     const NamedDecl *OffendingDecl,
27                                     const ObjCInterfaceDecl *UnknownObjCClass,
28                                     const ObjCPropertyDecl  *ObjCProperty,
29                                     StringRef Msg,
30                                     bool ObjCPropertyAccess) {
31   DelayedDiagnostic DD;
32   DD.Kind = Availability;
33   DD.Triggered = false;
34   DD.Loc = Loc;
35   DD.AvailabilityData.ReferringDecl = ReferringDecl;
36   DD.AvailabilityData.OffendingDecl = OffendingDecl;
37   DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
38   DD.AvailabilityData.ObjCProperty = ObjCProperty;
39   char *MessageData = nullptr;
40   if (Msg.size()) {
41     MessageData = new char [Msg.size()];
42     memcpy(MessageData, Msg.data(), Msg.size());
43   }
44
45   DD.AvailabilityData.Message = MessageData;
46   DD.AvailabilityData.MessageLen = Msg.size();
47   DD.AvailabilityData.AR = AR;
48   DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
49   return DD;
50 }
51
52 void DelayedDiagnostic::Destroy() {
53   switch (Kind) {
54   case Access: 
55     getAccessData().~AccessedEntity(); 
56     break;
57
58   case Availability:
59     delete[] AvailabilityData.Message;
60     break;
61
62   case ForbiddenType:
63     break;
64   }
65 }