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 
22 DelayedDiagnostic DelayedDiagnostic::makeDeprecation(SourceLocation Loc,
23                                                      const NamedDecl *D,
24                                                      StringRef Msg) {
25   DelayedDiagnostic DD;
26   DD.Kind = Deprecation;
27   DD.Triggered = false;
28   DD.Loc = Loc;
29   DD.DeprecationData.Decl = D;
30   char *MessageData = 0;
31   if (Msg.size()) {
32     MessageData = new char [Msg.size()];
33     memcpy(MessageData, Msg.data(), Msg.size());
34   }
35 
36   DD.DeprecationData.Message = MessageData;
37   DD.DeprecationData.MessageLen = Msg.size();
38   return DD;
39 }
40 
41 void DelayedDiagnostic::Destroy() {
42   switch (Kind) {
43   case Access:
44     getAccessData().~AccessedEntity();
45     break;
46 
47   case Deprecation:
48     delete [] DeprecationData.Message;
49     break;
50 
51   case ForbiddenType:
52     break;
53   }
54 }
55