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; 38288943Sdim case Sema::AD_Partial: 39288943Sdim llvm_unreachable("AD_Partial diags should not be delayed"); 40276479Sdim } 41221339Sdim DD.Triggered = false; 42221339Sdim DD.Loc = Loc; 43221339Sdim DD.DeprecationData.Decl = D; 44234353Sdim DD.DeprecationData.UnknownObjCClass = UnknownObjCClass; 45243830Sdim DD.DeprecationData.ObjCProperty = ObjCProperty; 46276479Sdim char *MessageData = nullptr; 47221339Sdim if (Msg.size()) { 48221339Sdim MessageData = new char [Msg.size()]; 49221339Sdim memcpy(MessageData, Msg.data(), Msg.size()); 50221339Sdim } 51221339Sdim 52221339Sdim DD.DeprecationData.Message = MessageData; 53221339Sdim DD.DeprecationData.MessageLen = Msg.size(); 54276479Sdim DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess; 55221339Sdim return DD; 56221339Sdim} 57221339Sdim 58221339Sdimvoid DelayedDiagnostic::Destroy() { 59276479Sdim switch (static_cast<DDKind>(Kind)) { 60221339Sdim case Access: 61221339Sdim getAccessData().~AccessedEntity(); 62221339Sdim break; 63221339Sdim 64276479Sdim case Deprecation: 65276479Sdim case Unavailable: 66221339Sdim delete [] DeprecationData.Message; 67221339Sdim break; 68224145Sdim 69224145Sdim case ForbiddenType: 70224145Sdim break; 71221339Sdim } 72221339Sdim} 73