blob: 2fa5718d4e9b5e46857d750aabb9034b07836ece [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,
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;
Erik Pilkingtona8003972016-10-28 21:39:27 +000031 DD.Kind = Availability;
Douglas Gregor899b68f2011-03-23 15:13:44 +000032 DD.Triggered = false;
33 DD.Loc = Loc;
Erik Pilkingtona8003972016-10-28 21:39:27 +000034 DD.AvailabilityData.Decl = D;
35 DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
36 DD.AvailabilityData.ObjCProperty = ObjCProperty;
Craig Topperc3ec1492014-05-26 06:22:03 +000037 char *MessageData = nullptr;
Douglas Gregor899b68f2011-03-23 15:13:44 +000038 if (Msg.size()) {
39 MessageData = new char [Msg.size()];
40 memcpy(MessageData, Msg.data(), Msg.size());
41 }
42
Erik Pilkingtona8003972016-10-28 21:39:27 +000043 DD.AvailabilityData.Message = MessageData;
44 DD.AvailabilityData.MessageLen = Msg.size();
45 DD.AvailabilityData.AR = AR;
46 DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
Douglas Gregor899b68f2011-03-23 15:13:44 +000047 return DD;
48}
49
50void DelayedDiagnostic::Destroy() {
Erik Pilkingtona8003972016-10-28 21:39:27 +000051 switch (Kind) {
Douglas Gregor899b68f2011-03-23 15:13:44 +000052 case Access:
53 getAccessData().~AccessedEntity();
54 break;
55
Erik Pilkingtona8003972016-10-28 21:39:27 +000056 case Availability:
57 delete[] AvailabilityData.Message;
Douglas Gregor899b68f2011-03-23 15:13:44 +000058 break;
John McCall31168b02011-06-15 23:02:42 +000059
60 case ForbiddenType:
61 break;
Douglas Gregor899b68f2011-03-23 15:13:44 +000062 }
63}