blob: 664a6b1a8998056da80db4b79eecede495aa724d [file] [log] [blame]
Douglas Gregor29233802011-03-23 15:13:44 +00001//===--- 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>
19using namespace clang;
20using namespace sema;
21
Stephen Hines651f13c2014-04-23 16:59:28 -070022DelayedDiagnostic
23DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD,
24 SourceLocation Loc,
Fariborz Jahanianb0a66152012-03-02 21:50:02 +000025 const NamedDecl *D,
26 const ObjCInterfaceDecl *UnknownObjCClass,
Fariborz Jahanianfd090882012-09-21 20:46:37 +000027 const ObjCPropertyDecl *ObjCProperty,
Stephen Hinesef822542014-07-21 00:47:37 -070028 StringRef Msg,
29 bool ObjCPropertyAccess) {
Douglas Gregor29233802011-03-23 15:13:44 +000030 DelayedDiagnostic DD;
Stephen Hines651f13c2014-04-23 16:59:28 -070031 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 }
Douglas Gregor29233802011-03-23 15:13:44 +000039 DD.Triggered = false;
40 DD.Loc = Loc;
41 DD.DeprecationData.Decl = D;
Fariborz Jahanianb0a66152012-03-02 21:50:02 +000042 DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
Fariborz Jahanianfd090882012-09-21 20:46:37 +000043 DD.DeprecationData.ObjCProperty = ObjCProperty;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070044 char *MessageData = nullptr;
Douglas Gregor29233802011-03-23 15:13:44 +000045 if (Msg.size()) {
46 MessageData = new char [Msg.size()];
47 memcpy(MessageData, Msg.data(), Msg.size());
48 }
49
50 DD.DeprecationData.Message = MessageData;
51 DD.DeprecationData.MessageLen = Msg.size();
Stephen Hinesef822542014-07-21 00:47:37 -070052 DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess;
Douglas Gregor29233802011-03-23 15:13:44 +000053 return DD;
54}
55
56void DelayedDiagnostic::Destroy() {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070057 switch (static_cast<DDKind>(Kind)) {
Douglas Gregor29233802011-03-23 15:13:44 +000058 case Access:
59 getAccessData().~AccessedEntity();
60 break;
61
Stephen Hines6bcf27b2014-05-29 04:14:42 -070062 case Deprecation:
63 case Unavailable:
Douglas Gregor29233802011-03-23 15:13:44 +000064 delete [] DeprecationData.Message;
65 break;
John McCallf85e1932011-06-15 23:02:42 +000066
67 case ForbiddenType:
68 break;
Douglas Gregor29233802011-03-23 15:13:44 +000069 }
70}