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