blob: a064e492c0989157ca4d3d8c82dfd5a5928abe78 [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,
Volodymyr Sapsai7d89ce92018-03-29 17:34:09 +000026 ArrayRef<SourceLocation> Locs,
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) {
Volodymyr Sapsai7d89ce92018-03-29 17:34:09 +000033 assert(!Locs.empty());
Douglas Gregor899b68f2011-03-23 15:13:44 +000034 DelayedDiagnostic DD;
Erik Pilkingtona8003972016-10-28 21:39:27 +000035 DD.Kind = Availability;
Douglas Gregor899b68f2011-03-23 15:13:44 +000036 DD.Triggered = false;
Volodymyr Sapsai7d89ce92018-03-29 17:34:09 +000037 DD.Loc = Locs.front();
Erik Pilkington4042f3c2017-07-05 17:08:56 +000038 DD.AvailabilityData.ReferringDecl = ReferringDecl;
39 DD.AvailabilityData.OffendingDecl = OffendingDecl;
Erik Pilkingtona8003972016-10-28 21:39:27 +000040 DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
41 DD.AvailabilityData.ObjCProperty = ObjCProperty;
Craig Topperc3ec1492014-05-26 06:22:03 +000042 char *MessageData = nullptr;
Eugene Zelenko9fbf6412018-02-21 01:45:26 +000043 if (!Msg.empty()) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000044 MessageData = new char [Msg.size()];
45 memcpy(MessageData, Msg.data(), Msg.size());
46 }
Erik Pilkingtona8003972016-10-28 21:39:27 +000047 DD.AvailabilityData.Message = MessageData;
48 DD.AvailabilityData.MessageLen = Msg.size();
Volodymyr Sapsai7d89ce92018-03-29 17:34:09 +000049
50 DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()];
51 memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(),
52 sizeof(SourceLocation) * Locs.size());
53 DD.AvailabilityData.NumSelectorLocs = Locs.size();
54
Erik Pilkingtona8003972016-10-28 21:39:27 +000055 DD.AvailabilityData.AR = AR;
56 DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
Douglas Gregor899b68f2011-03-23 15:13:44 +000057 return DD;
58}
59
60void DelayedDiagnostic::Destroy() {
Erik Pilkingtona8003972016-10-28 21:39:27 +000061 switch (Kind) {
Fangrui Song6907ce22018-07-30 19:24:48 +000062 case Access:
63 getAccessData().~AccessedEntity();
Douglas Gregor899b68f2011-03-23 15:13:44 +000064 break;
65
Erik Pilkingtona8003972016-10-28 21:39:27 +000066 case Availability:
67 delete[] AvailabilityData.Message;
Volodymyr Sapsai7d89ce92018-03-29 17:34:09 +000068 delete[] AvailabilityData.SelectorLocs;
Douglas Gregor899b68f2011-03-23 15:13:44 +000069 break;
John McCall31168b02011-06-15 23:02:42 +000070
71 case ForbiddenType:
72 break;
Douglas Gregor899b68f2011-03-23 15:13:44 +000073 }
74}