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 |
| 23 | DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD, |
| 24 | SourceLocation Loc, |
Fariborz Jahanian | 7923ef4 | 2012-03-02 21:50:02 +0000 | [diff] [blame] | 25 | const NamedDecl *D, |
| 26 | const ObjCInterfaceDecl *UnknownObjCClass, |
Fariborz Jahanian | 974c948 | 2012-09-21 20:46:37 +0000 | [diff] [blame] | 27 | const ObjCPropertyDecl *ObjCProperty, |
Fariborz Jahanian | 89ea961 | 2014-06-16 17:25:41 +0000 | [diff] [blame] | 28 | StringRef Msg, |
| 29 | bool ObjCPropertyAccess) { |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 30 | DelayedDiagnostic DD; |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 31 | switch (AD) { |
| 32 | case Sema::AD_Deprecation: |
| 33 | DD.Kind = Deprecation; |
| 34 | break; |
| 35 | case Sema::AD_Unavailable: |
| 36 | DD.Kind = Unavailable; |
| 37 | break; |
Nico Weber | 0055a19 | 2015-03-19 19:18:22 +0000 | [diff] [blame] | 38 | case Sema::AD_Partial: |
| 39 | llvm_unreachable("AD_Partial diags should not be delayed"); |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 40 | } |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 41 | DD.Triggered = false; |
| 42 | DD.Loc = Loc; |
| 43 | DD.DeprecationData.Decl = D; |
Fariborz Jahanian | 7923ef4 | 2012-03-02 21:50:02 +0000 | [diff] [blame] | 44 | DD.DeprecationData.UnknownObjCClass = UnknownObjCClass; |
Fariborz Jahanian | 974c948 | 2012-09-21 20:46:37 +0000 | [diff] [blame] | 45 | DD.DeprecationData.ObjCProperty = ObjCProperty; |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 46 | char *MessageData = nullptr; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 47 | if (Msg.size()) { |
| 48 | MessageData = new char [Msg.size()]; |
| 49 | memcpy(MessageData, Msg.data(), Msg.size()); |
| 50 | } |
| 51 | |
| 52 | DD.DeprecationData.Message = MessageData; |
| 53 | DD.DeprecationData.MessageLen = Msg.size(); |
Fariborz Jahanian | 89ea961 | 2014-06-16 17:25:41 +0000 | [diff] [blame] | 54 | DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 55 | return DD; |
| 56 | } |
| 57 | |
| 58 | void DelayedDiagnostic::Destroy() { |
Jordan Rose | 7d2a5e6 | 2014-04-24 17:27:18 +0000 | [diff] [blame] | 59 | switch (static_cast<DDKind>(Kind)) { |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 60 | case Access: |
| 61 | getAccessData().~AccessedEntity(); |
| 62 | break; |
| 63 | |
Jordan Rose | 7d2a5e6 | 2014-04-24 17:27:18 +0000 | [diff] [blame] | 64 | case Deprecation: |
| 65 | case Unavailable: |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 66 | delete [] DeprecationData.Message; |
| 67 | break; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 68 | |
| 69 | case ForbiddenType: |
| 70 | break; |
Douglas Gregor | 899b68f | 2011-03-23 15:13:44 +0000 | [diff] [blame] | 71 | } |
| 72 | } |