Eugene Zelenko | 9fbf641 | 2018-02-21 01:45:26 +0000 | [diff] [blame] | 1 | //===- DelayedDiagnostic.cpp - Delayed declarator diagnostics -------------===// |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the DelayedDiagnostic class implementation, which |
| 10 | // is used to record diagnostics that are being conditionally produced |
| 11 | // during declarator parsing. |
| 12 | // |
| 13 | // This file also defines AccessedEntity. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9fbf641 | 2018-02-21 01:45:26 +0000 | [diff] [blame] | 16 | |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 17 | #include "clang/Sema/DelayedDiagnostic.h" |
Eugene Zelenko | 9fbf641 | 2018-02-21 01:45:26 +0000 | [diff] [blame] | 18 | #include <cstring> |
| 19 | |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | using namespace sema; |
| 22 | |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 23 | DelayedDiagnostic |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 24 | DelayedDiagnostic::makeAvailability(AvailabilityResult AR, |
Volodymyr Sapsai | 7d89ce9 | 2018-03-29 17:34:09 +0000 | [diff] [blame] | 25 | ArrayRef<SourceLocation> Locs, |
Erik Pilkington | 4042f3c | 2017-07-05 17:08:56 +0000 | [diff] [blame] | 26 | const NamedDecl *ReferringDecl, |
| 27 | const NamedDecl *OffendingDecl, |
Fariborz Jahanian | 7923ef4 | 2012-03-02 21:50:02 +0000 | [diff] [blame] | 28 | const ObjCInterfaceDecl *UnknownObjCClass, |
Fariborz Jahanian | 974c948 | 2012-09-21 20:46:37 +0000 | [diff] [blame] | 29 | const ObjCPropertyDecl *ObjCProperty, |
Fariborz Jahanian | 89ea961 | 2014-06-16 17:25:41 +0000 | [diff] [blame] | 30 | StringRef Msg, |
| 31 | bool ObjCPropertyAccess) { |
Volodymyr Sapsai | 7d89ce9 | 2018-03-29 17:34:09 +0000 | [diff] [blame] | 32 | assert(!Locs.empty()); |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 33 | DelayedDiagnostic DD; |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 34 | DD.Kind = Availability; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 35 | DD.Triggered = false; |
Volodymyr Sapsai | 7d89ce9 | 2018-03-29 17:34:09 +0000 | [diff] [blame] | 36 | DD.Loc = Locs.front(); |
Erik Pilkington | 4042f3c | 2017-07-05 17:08:56 +0000 | [diff] [blame] | 37 | DD.AvailabilityData.ReferringDecl = ReferringDecl; |
| 38 | DD.AvailabilityData.OffendingDecl = OffendingDecl; |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 39 | DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass; |
| 40 | DD.AvailabilityData.ObjCProperty = ObjCProperty; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 41 | char *MessageData = nullptr; |
Eugene Zelenko | 9fbf641 | 2018-02-21 01:45:26 +0000 | [diff] [blame] | 42 | if (!Msg.empty()) { |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 43 | MessageData = new char [Msg.size()]; |
| 44 | memcpy(MessageData, Msg.data(), Msg.size()); |
| 45 | } |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 46 | DD.AvailabilityData.Message = MessageData; |
| 47 | DD.AvailabilityData.MessageLen = Msg.size(); |
Volodymyr Sapsai | 7d89ce9 | 2018-03-29 17:34:09 +0000 | [diff] [blame] | 48 | |
| 49 | DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()]; |
| 50 | memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(), |
| 51 | sizeof(SourceLocation) * Locs.size()); |
| 52 | DD.AvailabilityData.NumSelectorLocs = Locs.size(); |
| 53 | |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 54 | DD.AvailabilityData.AR = AR; |
| 55 | DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 56 | return DD; |
| 57 | } |
| 58 | |
| 59 | void DelayedDiagnostic::Destroy() { |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 60 | switch (Kind) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 61 | case Access: |
| 62 | getAccessData().~AccessedEntity(); |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 63 | break; |
| 64 | |
Erik Pilkington | a800397 | 2016-10-28 21:39:27 +0000 | [diff] [blame] | 65 | case Availability: |
| 66 | delete[] AvailabilityData.Message; |
Volodymyr Sapsai | 7d89ce9 | 2018-03-29 17:34:09 +0000 | [diff] [blame] | 67 | delete[] AvailabilityData.SelectorLocs; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 68 | break; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 69 | |
| 70 | case ForbiddenType: |
| 71 | break; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 72 | } |
| 73 | } |