blob: ceea04f276c970e92f22ac23bea1715cc1c8a656 [file] [log] [blame]
Douglas Gregor899b68f2011-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
Ted Kremenekb79ee572013-12-18 23:30:06 +000022DelayedDiagnostic
23DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD,
24 SourceLocation Loc,
Fariborz Jahanian7923ef42012-03-02 21:50:02 +000025 const NamedDecl *D,
26 const ObjCInterfaceDecl *UnknownObjCClass,
Fariborz Jahanian974c9482012-09-21 20:46:37 +000027 const ObjCPropertyDecl *ObjCProperty,
Fariborz Jahanian89ea9612014-06-16 17:25:41 +000028 StringRef Msg,
29 bool ObjCPropertyAccess) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000030 DelayedDiagnostic DD;
Ted Kremenekb79ee572013-12-18 23:30:06 +000031 switch (AD) {
32 case Sema::AD_Deprecation:
33 DD.Kind = Deprecation;
34 break;
35 case Sema::AD_Unavailable:
36 DD.Kind = Unavailable;
37 break;
Nico Weber0055a192015-03-19 19:18:22 +000038 case Sema::AD_Partial:
39 llvm_unreachable("AD_Partial diags should not be delayed");
Ted Kremenekb79ee572013-12-18 23:30:06 +000040 }
Douglas Gregor899b68f2011-03-23 15:13:44 +000041 DD.Triggered = false;
42 DD.Loc = Loc;
43 DD.DeprecationData.Decl = D;
Fariborz Jahanian7923ef42012-03-02 21:50:02 +000044 DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
Fariborz Jahanian974c9482012-09-21 20:46:37 +000045 DD.DeprecationData.ObjCProperty = ObjCProperty;
Craig Topperc3ec1492014-05-26 06:22:03 +000046 char *MessageData = nullptr;
Douglas Gregor899b68f2011-03-23 15:13:44 +000047 if (Msg.size()) {
48 MessageData = new char [Msg.size()];
49 memcpy(MessageData, Msg.data(), Msg.size());
50 }
51
52 DD.DeprecationData.Message = MessageData;
53 DD.DeprecationData.MessageLen = Msg.size();
Fariborz Jahanian89ea9612014-06-16 17:25:41 +000054 DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess;
Douglas Gregor899b68f2011-03-23 15:13:44 +000055 return DD;
56}
57
58void DelayedDiagnostic::Destroy() {
Jordan Rose7d2a5e62014-04-24 17:27:18 +000059 switch (static_cast<DDKind>(Kind)) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000060 case Access:
61 getAccessData().~AccessedEntity();
62 break;
63
Jordan Rose7d2a5e62014-04-24 17:27:18 +000064 case Deprecation:
65 case Unavailable:
Douglas Gregor899b68f2011-03-23 15:13:44 +000066 delete [] DeprecationData.Message;
67 break;
John McCall31168b02011-06-15 23:02:42 +000068
69 case ForbiddenType:
70 break;
Douglas Gregor899b68f2011-03-23 15:13:44 +000071 }
72}