blob: 3d321d561e60b754a665ce0f97ed8f54e037e515 [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
Erik Pilkingtona8003972016-10-28 21:39:27 +000023DelayedDiagnostic::makeAvailability(AvailabilityResult AR,
Ted Kremenekb79ee572013-12-18 23:30:06 +000024 SourceLocation Loc,
Erik Pilkington4042f3c2017-07-05 17:08:56 +000025 const NamedDecl *ReferringDecl,
26 const NamedDecl *OffendingDecl,
Fariborz Jahanian7923ef42012-03-02 21:50:02 +000027 const ObjCInterfaceDecl *UnknownObjCClass,
Fariborz Jahanian974c9482012-09-21 20:46:37 +000028 const ObjCPropertyDecl *ObjCProperty,
Fariborz Jahanian89ea9612014-06-16 17:25:41 +000029 StringRef Msg,
30 bool ObjCPropertyAccess) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000031 DelayedDiagnostic DD;
Erik Pilkingtona8003972016-10-28 21:39:27 +000032 DD.Kind = Availability;
Douglas Gregor899b68f2011-03-23 15:13:44 +000033 DD.Triggered = false;
34 DD.Loc = Loc;
Erik Pilkington4042f3c2017-07-05 17:08:56 +000035 DD.AvailabilityData.ReferringDecl = ReferringDecl;
36 DD.AvailabilityData.OffendingDecl = OffendingDecl;
Erik Pilkingtona8003972016-10-28 21:39:27 +000037 DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
38 DD.AvailabilityData.ObjCProperty = ObjCProperty;
Craig Topperc3ec1492014-05-26 06:22:03 +000039 char *MessageData = nullptr;
Douglas Gregor899b68f2011-03-23 15:13:44 +000040 if (Msg.size()) {
41 MessageData = new char [Msg.size()];
42 memcpy(MessageData, Msg.data(), Msg.size());
43 }
44
Erik Pilkingtona8003972016-10-28 21:39:27 +000045 DD.AvailabilityData.Message = MessageData;
46 DD.AvailabilityData.MessageLen = Msg.size();
47 DD.AvailabilityData.AR = AR;
48 DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
Douglas Gregor899b68f2011-03-23 15:13:44 +000049 return DD;
50}
51
52void DelayedDiagnostic::Destroy() {
Erik Pilkingtona8003972016-10-28 21:39:27 +000053 switch (Kind) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000054 case Access:
55 getAccessData().~AccessedEntity();
56 break;
57
Erik Pilkingtona8003972016-10-28 21:39:27 +000058 case Availability:
59 delete[] AvailabilityData.Message;
Douglas Gregor899b68f2011-03-23 15:13:44 +000060 break;
John McCall31168b02011-06-15 23:02:42 +000061
62 case ForbiddenType:
63 break;
Douglas Gregor899b68f2011-03-23 15:13:44 +000064 }
65}