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 bool ObjCPropertyAccess) { 30 DelayedDiagnostic DD; 31 switch (AD) { 32 case Sema::AD_Deprecation: 33 DD.Kind = Deprecation; 34 break; 35 case Sema::AD_Unavailable: 36 DD.Kind = Unavailable; 37 break; 38 case Sema::AD_NotYetIntroduced: 39 DD.Kind = NotYetIntroduced; 40 break; 41 case Sema::AD_Partial: 42 llvm_unreachable("AD_Partial diags should not be delayed"); 43 } 44 DD.Triggered = false; 45 DD.Loc = Loc; 46 DD.DeprecationData.Decl = D; 47 DD.DeprecationData.UnknownObjCClass = UnknownObjCClass; 48 DD.DeprecationData.ObjCProperty = ObjCProperty; 49 char *MessageData = nullptr; 50 if (Msg.size()) { 51 MessageData = new char [Msg.size()]; 52 memcpy(MessageData, Msg.data(), Msg.size()); 53 } 54 55 DD.DeprecationData.Message = MessageData; 56 DD.DeprecationData.MessageLen = Msg.size(); 57 DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess; 58 return DD; 59 } 60 61 void DelayedDiagnostic::Destroy() { 62 switch (static_cast<DDKind>(Kind)) { 63 case Access: 64 getAccessData().~AccessedEntity(); 65 break; 66 67 case Deprecation: 68 case Unavailable: 69 case NotYetIntroduced: 70 delete [] DeprecationData.Message; 71 break; 72 73 case ForbiddenType: 74 break; 75 } 76 } 77