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