clang API Documentation

DelayedDiagnostic.cpp
Go to the documentation of this file.
00001 //===--- DelayedDiagnostic.cpp - Delayed declarator diagnostics -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the DelayedDiagnostic class implementation, which
00011 // is used to record diagnostics that are being conditionally produced
00012 // during declarator parsing.
00013 //
00014 // This file also defines AccessedEntity.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 #include "clang/Sema/DelayedDiagnostic.h"
00018 #include <string.h>
00019 using namespace clang;
00020 using namespace sema;
00021 
00022 DelayedDiagnostic
00023 DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD,
00024                                     SourceLocation Loc,
00025                                     const NamedDecl *D,
00026                                     const ObjCInterfaceDecl *UnknownObjCClass,
00027                                     const ObjCPropertyDecl  *ObjCProperty,
00028                                     StringRef Msg,
00029                                     bool ObjCPropertyAccess) {
00030   DelayedDiagnostic DD;
00031   switch (AD) {
00032     case Sema::AD_Deprecation:
00033       DD.Kind = Deprecation;
00034       break;
00035     case Sema::AD_Unavailable:
00036       DD.Kind = Unavailable;
00037       break;
00038   }
00039   DD.Triggered = false;
00040   DD.Loc = Loc;
00041   DD.DeprecationData.Decl = D;
00042   DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
00043   DD.DeprecationData.ObjCProperty = ObjCProperty;
00044   char *MessageData = nullptr;
00045   if (Msg.size()) {
00046     MessageData = new char [Msg.size()];
00047     memcpy(MessageData, Msg.data(), Msg.size());
00048   }
00049 
00050   DD.DeprecationData.Message = MessageData;
00051   DD.DeprecationData.MessageLen = Msg.size();
00052   DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess;
00053   return DD;
00054 }
00055 
00056 void DelayedDiagnostic::Destroy() {
00057   switch (static_cast<DDKind>(Kind)) {
00058   case Access: 
00059     getAccessData().~AccessedEntity(); 
00060     break;
00061 
00062   case Deprecation:
00063   case Unavailable:
00064     delete [] DeprecationData.Message;
00065     break;
00066 
00067   case ForbiddenType:
00068     break;
00069   }
00070 }