xref: /aosp_15_r20/external/clang/lib/Sema/DelayedDiagnostic.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //===--- DelayedDiagnostic.cpp - Delayed declarator diagnostics -*- C++ -*-===//
2*67e74705SXin Li //
3*67e74705SXin Li //                     The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li //
10*67e74705SXin Li // This file defines the DelayedDiagnostic class implementation, which
11*67e74705SXin Li // is used to record diagnostics that are being conditionally produced
12*67e74705SXin Li // during declarator parsing.
13*67e74705SXin Li //
14*67e74705SXin Li // This file also defines AccessedEntity.
15*67e74705SXin Li //
16*67e74705SXin Li //===----------------------------------------------------------------------===//
17*67e74705SXin Li #include "clang/Sema/DelayedDiagnostic.h"
18*67e74705SXin Li #include <string.h>
19*67e74705SXin Li using namespace clang;
20*67e74705SXin Li using namespace sema;
21*67e74705SXin Li 
22*67e74705SXin Li DelayedDiagnostic
makeAvailability(Sema::AvailabilityDiagnostic AD,SourceLocation Loc,const NamedDecl * D,const ObjCInterfaceDecl * UnknownObjCClass,const ObjCPropertyDecl * ObjCProperty,StringRef Msg,bool ObjCPropertyAccess)23*67e74705SXin Li DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD,
24*67e74705SXin Li                                     SourceLocation Loc,
25*67e74705SXin Li                                     const NamedDecl *D,
26*67e74705SXin Li                                     const ObjCInterfaceDecl *UnknownObjCClass,
27*67e74705SXin Li                                     const ObjCPropertyDecl  *ObjCProperty,
28*67e74705SXin Li                                     StringRef Msg,
29*67e74705SXin Li                                     bool ObjCPropertyAccess) {
30*67e74705SXin Li   DelayedDiagnostic DD;
31*67e74705SXin Li   switch (AD) {
32*67e74705SXin Li     case Sema::AD_Deprecation:
33*67e74705SXin Li       DD.Kind = Deprecation;
34*67e74705SXin Li       break;
35*67e74705SXin Li     case Sema::AD_Unavailable:
36*67e74705SXin Li       DD.Kind = Unavailable;
37*67e74705SXin Li       break;
38*67e74705SXin Li     case Sema::AD_Partial:
39*67e74705SXin Li       llvm_unreachable("AD_Partial diags should not be delayed");
40*67e74705SXin Li   }
41*67e74705SXin Li   DD.Triggered = false;
42*67e74705SXin Li   DD.Loc = Loc;
43*67e74705SXin Li   DD.DeprecationData.Decl = D;
44*67e74705SXin Li   DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
45*67e74705SXin Li   DD.DeprecationData.ObjCProperty = ObjCProperty;
46*67e74705SXin Li   char *MessageData = nullptr;
47*67e74705SXin Li   if (Msg.size()) {
48*67e74705SXin Li     MessageData = new char [Msg.size()];
49*67e74705SXin Li     memcpy(MessageData, Msg.data(), Msg.size());
50*67e74705SXin Li   }
51*67e74705SXin Li 
52*67e74705SXin Li   DD.DeprecationData.Message = MessageData;
53*67e74705SXin Li   DD.DeprecationData.MessageLen = Msg.size();
54*67e74705SXin Li   DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess;
55*67e74705SXin Li   return DD;
56*67e74705SXin Li }
57*67e74705SXin Li 
Destroy()58*67e74705SXin Li void DelayedDiagnostic::Destroy() {
59*67e74705SXin Li   switch (static_cast<DDKind>(Kind)) {
60*67e74705SXin Li   case Access:
61*67e74705SXin Li     getAccessData().~AccessedEntity();
62*67e74705SXin Li     break;
63*67e74705SXin Li 
64*67e74705SXin Li   case Deprecation:
65*67e74705SXin Li   case Unavailable:
66*67e74705SXin Li     delete [] DeprecationData.Message;
67*67e74705SXin Li     break;
68*67e74705SXin Li 
69*67e74705SXin Li   case ForbiddenType:
70*67e74705SXin Li     break;
71*67e74705SXin Li   }
72*67e74705SXin Li }
73