blob: 255520634006ba542c23af501f28684f79ff2897 [file] [log] [blame]
Eugene Zelenko9fbf6412018-02-21 01:45:26 +00001//===- DelayedDiagnostic.cpp - Delayed declarator diagnostics -------------===//
Douglas Gregor899b68f2011-03-23 15:13:44 +00002//
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//===----------------------------------------------------------------------===//
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000017
Douglas Gregor899b68f2011-03-23 15:13:44 +000018#include "clang/Sema/DelayedDiagnostic.h"
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000019#include <cstring>
20
Douglas Gregor899b68f2011-03-23 15:13:44 +000021using namespace clang;
22using namespace sema;
23
Ted Kremenekb79ee572013-12-18 23:30:06 +000024DelayedDiagnostic
Erik Pilkingtona8003972016-10-28 21:39:27 +000025DelayedDiagnostic::makeAvailability(AvailabilityResult AR,
Ted Kremenekb79ee572013-12-18 23:30:06 +000026 SourceLocation Loc,
Erik Pilkington4042f3c2017-07-05 17:08:56 +000027 const NamedDecl *ReferringDecl,
28 const NamedDecl *OffendingDecl,
Fariborz Jahanian7923ef42012-03-02 21:50:02 +000029 const ObjCInterfaceDecl *UnknownObjCClass,
Fariborz Jahanian974c9482012-09-21 20:46:37 +000030 const ObjCPropertyDecl *ObjCProperty,
Fariborz Jahanian89ea9612014-06-16 17:25:41 +000031 StringRef Msg,
32 bool ObjCPropertyAccess) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000033 DelayedDiagnostic DD;
Erik Pilkingtona8003972016-10-28 21:39:27 +000034 DD.Kind = Availability;
Douglas Gregor899b68f2011-03-23 15:13:44 +000035 DD.Triggered = false;
36 DD.Loc = Loc;
Erik Pilkington4042f3c2017-07-05 17:08:56 +000037 DD.AvailabilityData.ReferringDecl = ReferringDecl;
38 DD.AvailabilityData.OffendingDecl = OffendingDecl;
Erik Pilkingtona8003972016-10-28 21:39:27 +000039 DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
40 DD.AvailabilityData.ObjCProperty = ObjCProperty;
Craig Topperc3ec1492014-05-26 06:22:03 +000041 char *MessageData = nullptr;
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000042 if (!Msg.empty()) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000043 MessageData = new char [Msg.size()];
44 memcpy(MessageData, Msg.data(), Msg.size());
45 }
46
Erik Pilkingtona8003972016-10-28 21:39:27 +000047 DD.AvailabilityData.Message = MessageData;
48 DD.AvailabilityData.MessageLen = Msg.size();
49 DD.AvailabilityData.AR = AR;
50 DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
Douglas Gregor899b68f2011-03-23 15:13:44 +000051 return DD;
52}
53
54void DelayedDiagnostic::Destroy() {
Erik Pilkingtona8003972016-10-28 21:39:27 +000055 switch (Kind) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000056 case Access:
57 getAccessData().~AccessedEntity();
58 break;
59
Erik Pilkingtona8003972016-10-28 21:39:27 +000060 case Availability:
61 delete[] AvailabilityData.Message;
Douglas Gregor899b68f2011-03-23 15:13:44 +000062 break;
John McCall31168b02011-06-15 23:02:42 +000063
64 case ForbiddenType:
65 break;
Douglas Gregor899b68f2011-03-23 15:13:44 +000066 }
67}