Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 1 | //===--- 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> |
| 19 | using namespace clang; |
| 20 | using namespace sema; |
| 21 | |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 22 | DelayedDiagnostic |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 23 | DelayedDiagnostic::makeAvailability(AvailabilityResult AR, |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 24 | SourceLocation Loc, |
Erik Pilkington | 4042f3c | 2017-07-05 17:08:56 +0000 | [diff] [blame] | 25 | const NamedDecl *ReferringDecl, |
| 26 | const NamedDecl *OffendingDecl, |
Fariborz Jahanian | 7923ef4 | 2012-03-02 21:50:02 +0000 | [diff] [blame] | 27 | const ObjCInterfaceDecl *UnknownObjCClass, |
Fariborz Jahanian | 974c948 | 2012-09-21 20:46:37 +0000 | [diff] [blame] | 28 | const ObjCPropertyDecl *ObjCProperty, |
Fariborz Jahanian | 89ea961 | 2014-06-16 17:25:41 +0000 | [diff] [blame] | 29 | StringRef Msg, |
| 30 | bool ObjCPropertyAccess) { |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 31 | DelayedDiagnostic DD; |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 32 | DD.Kind = Availability; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 33 | DD.Triggered = false; |
| 34 | DD.Loc = Loc; |
Erik Pilkington | 4042f3c | 2017-07-05 17:08:56 +0000 | [diff] [blame] | 35 | DD.AvailabilityData.ReferringDecl = ReferringDecl; |
| 36 | DD.AvailabilityData.OffendingDecl = OffendingDecl; |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 37 | DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass; |
| 38 | DD.AvailabilityData.ObjCProperty = ObjCProperty; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 39 | char *MessageData = nullptr; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 40 | if (Msg.size()) { |
| 41 | MessageData = new char [Msg.size()]; |
| 42 | memcpy(MessageData, Msg.data(), Msg.size()); |
| 43 | } |
| 44 | |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 45 | DD.AvailabilityData.Message = MessageData; |
| 46 | DD.AvailabilityData.MessageLen = Msg.size(); |
| 47 | DD.AvailabilityData.AR = AR; |
| 48 | DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 49 | return DD; |
| 50 | } |
| 51 | |
| 52 | void DelayedDiagnostic::Destroy() { |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 53 | switch (Kind) { |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 54 | case Access: |
| 55 | getAccessData().~AccessedEntity(); |
| 56 | break; |
| 57 | |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 58 | case Availability: |
| 59 | delete[] AvailabilityData.Message; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 60 | break; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 61 | |
| 62 | case ForbiddenType: |
| 63 | break; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 64 | } |
| 65 | } |