DelayedDiagnostic.cpp revision 276479
1221339Sdim//===--- DelayedDiagnostic.cpp - Delayed declarator diagnostics -*- C++ -*-===// 2221339Sdim// 3221339Sdim// The LLVM Compiler Infrastructure 4221339Sdim// 5221339Sdim// This file is distributed under the University of Illinois Open Source 6221339Sdim// License. See LICENSE.TXT for details. 7221339Sdim// 8221339Sdim//===----------------------------------------------------------------------===// 9221339Sdim// 10221339Sdim// This file defines the DelayedDiagnostic class implementation, which 11221339Sdim// is used to record diagnostics that are being conditionally produced 12221339Sdim// during declarator parsing. 13221339Sdim// 14221339Sdim// This file also defines AccessedEntity. 15221339Sdim// 16221339Sdim//===----------------------------------------------------------------------===// 17221339Sdim#include "clang/Sema/DelayedDiagnostic.h" 18221339Sdim#include <string.h> 19221339Sdimusing namespace clang; 20221339Sdimusing namespace sema; 21221339Sdim 22276479SdimDelayedDiagnostic 23276479SdimDelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD, 24276479Sdim SourceLocation Loc, 25234353Sdim const NamedDecl *D, 26234353Sdim const ObjCInterfaceDecl *UnknownObjCClass, 27243830Sdim const ObjCPropertyDecl *ObjCProperty, 28276479Sdim StringRef Msg, 29276479Sdim bool ObjCPropertyAccess) { 30221339Sdim DelayedDiagnostic DD; 31276479Sdim switch (AD) { 32276479Sdim case Sema::AD_Deprecation: 33276479Sdim DD.Kind = Deprecation; 34276479Sdim break; 35276479Sdim case Sema::AD_Unavailable: 36276479Sdim DD.Kind = Unavailable; 37276479Sdim break; 38276479Sdim } 39221339Sdim DD.Triggered = false; 40221339Sdim DD.Loc = Loc; 41221339Sdim DD.DeprecationData.Decl = D; 42234353Sdim DD.DeprecationData.UnknownObjCClass = UnknownObjCClass; 43243830Sdim DD.DeprecationData.ObjCProperty = ObjCProperty; 44276479Sdim char *MessageData = nullptr; 45221339Sdim if (Msg.size()) { 46221339Sdim MessageData = new char [Msg.size()]; 47221339Sdim memcpy(MessageData, Msg.data(), Msg.size()); 48221339Sdim } 49221339Sdim 50221339Sdim DD.DeprecationData.Message = MessageData; 51221339Sdim DD.DeprecationData.MessageLen = Msg.size(); 52276479Sdim DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess; 53221339Sdim return DD; 54221339Sdim} 55221339Sdim 56221339Sdimvoid DelayedDiagnostic::Destroy() { 57276479Sdim switch (static_cast<DDKind>(Kind)) { 58221339Sdim case Access: 59221339Sdim getAccessData().~AccessedEntity(); 60221339Sdim break; 61221339Sdim 62276479Sdim case Deprecation: 63276479Sdim case Unavailable: 64221339Sdim delete [] DeprecationData.Message; 65221339Sdim break; 66224145Sdim 67224145Sdim case ForbiddenType: 68224145Sdim break; 69221339Sdim } 70221339Sdim} 71