summaryrefslogtreecommitdiff
path: root/AspectC++/ClangAdjustedTypePrinter.h
blob: 8125f78491268282d25f172cf7e78cb62ddec80c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//===--- TypePrinter.cpp - Pretty-Print Clang Types -----------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This contains code to print types from Clang's type system.
//
//===----------------------------------------------------------------------===//

// Adjusted by AspectC++ to support printing of absolute types, printing of elaborated type specifier and removing of attributes.
// The file TypePrinter.cpp was taken from clang version 3.6.2 and split into a header file and a file containing the implementations.
// Changes are marked with //AC++.
// See the ClangAdjustedTypePrinter.cpp file for more information.

//AC++: added include guard:
#ifndef __ClangAdjustedTypePrinter_h__
#define __ClangAdjustedTypePrinter_h__
#include "version.h"
#include "ClangTransformInfo.h"
#if CLANG_VERSION_NUMBER < VERSION_NUMBER_7_0_0
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Type.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#else
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/Basic/AddressSpaces.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <string>
#endif

//AC++: commented out: using namespace clang;

//AC++: commented out: namespace {

//AC++: added "clang::" nested name specifier to every clang type

  /// \brief RAII object that enables printing of the ARC __strong lifetime
  /// qualifier.
  class IncludeStrongLifetimeRAII {
    clang::PrintingPolicy &Policy;
    bool Old;
    
  public:
    explicit IncludeStrongLifetimeRAII(clang::PrintingPolicy &Policy)
      : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
        if (!Policy.SuppressLifetimeQualifiers)
          Policy.SuppressStrongLifetime = false;
    }
    
    ~IncludeStrongLifetimeRAII() {
      Policy.SuppressStrongLifetime = Old;
    }
  };

  class ParamPolicyRAII {
    clang::PrintingPolicy &Policy;
    bool Old;
    
  public:
    explicit ParamPolicyRAII(clang::PrintingPolicy &Policy)
      : Policy(Policy), Old(Policy.SuppressSpecifiers) {
      Policy.SuppressSpecifiers = false;
    }
    
    ~ParamPolicyRAII() {
      Policy.SuppressSpecifiers = Old;
    }
  };
/*AC++: commented out:
  class ElaboratedTypePolicyRAII {
    clang::PrintingPolicy &Policy;
    bool SuppressTagKeyword;
    bool SuppressScope;
    
  public:
    explicit ElaboratedTypePolicyRAII(clang::PrintingPolicy &Policy) : Policy(Policy) {
      SuppressTagKeyword = Policy.SuppressTagKeyword;
      SuppressScope = Policy.SuppressScope;
      Policy.SuppressTagKeyword = true;
      Policy.SuppressScope = true;
    }
    
    ~ElaboratedTypePolicyRAII() {
      Policy.SuppressTagKeyword = SuppressTagKeyword;
      Policy.SuppressScope = SuppressScope;
    }
  };
*/
  //AC++: renamed TypePrinter to AdjustedTypePrinter
  class AdjustedTypePrinter {
    clang::PrintingPolicy Policy;
    unsigned Indentation;
    bool HasEmptyPlaceHolder;
    bool InsideCCAttribute;
    //AC++: added members:
    TriStateEnableFeature absolute_qualified;
    bool keep_typedef;
    TriStateEnableFeature elaborated_keyword;
    bool remove_attributes;
    bool as_parameter_signature_type;
    const clang::ASTContext* ctx;

  public:
    //AC++: adjusted constructor:
    explicit AdjustedTypePrinter(const clang::PrintingPolicy &Policy,
                                 TriStateEnableFeature absolute_qualfied,
                                 bool keep_typedef,
                                 TriStateEnableFeature elaborated_keyword,
                                 bool remove_attributes,
                                 bool as_parameter_signature_type,
                                 const clang::ASTContext* ctx,
                                 unsigned Indentation = 0)
      : Policy(Policy), Indentation(Indentation), HasEmptyPlaceHolder(false),
        InsideCCAttribute(false),
        absolute_qualified(absolute_qualfied), keep_typedef(keep_typedef),
        elaborated_keyword(elaborated_keyword), remove_attributes(remove_attributes),
        as_parameter_signature_type(as_parameter_signature_type), ctx(ctx){ }

    //AC++: commented out:
    //explicit AdjustedTypePrinter(const PrintingPolicy &Policy)
    //     : AdjustedTypePrinter(Policy, false, false) { }

  //AC++: added private:
  private:
    void print(const clang::Type *ty, clang::Qualifiers qs, clang::raw_ostream &OS,
               clang::StringRef PlaceHolder);
  //AC++: added public:
  public:
    void print(clang::QualType T, clang::raw_ostream &OS, clang::StringRef PlaceHolder);
  //AC++: added private:
  private:
    static bool canPrefixQualifiers(const clang::Type *T, bool &NeedARCStrongQualifier);
    void spaceBeforePlaceHolder(clang::raw_ostream &OS);
    void printTypeSpec(/*AC++: removed: const */ clang::NamedDecl *D, clang::raw_ostream &OS);

    void printBefore(const clang::Type *ty, clang::Qualifiers qs, clang::raw_ostream &OS);
    void printBefore(clang::QualType T, clang::raw_ostream &OS);
    void printAfter(const clang::Type *ty, clang::Qualifiers qs, clang::raw_ostream &OS);
    void printAfter(clang::QualType T, clang::raw_ostream &OS);
    void AppendScope(clang::DeclContext *DC, clang::raw_ostream &OS);
    void printTag(clang::TagDecl *T, clang::raw_ostream &OS);
//Ac++: added if and "clang::"
#if CLANG_VERSION_NUMBER >= VERSION_NUMBER_5_0_0
    void printFunctionAfter(const clang::FunctionType::ExtInfo &Info, clang::raw_ostream &OS);
#endif
#define ABSTRACT_TYPE(CLASS, PARENT)
#define TYPE(CLASS, PARENT) \
    void print##CLASS##Before(const clang::CLASS##Type *T, clang::raw_ostream &OS); \
    void print##CLASS##After(const clang::CLASS##Type *T, clang::raw_ostream &OS);
#include "clang/AST/TypeNodes.def"
  //AC++: added public:
  public:
    //AC++: added member functions. For more information see implementation.
    void adjusted_PrintTemplateArgumentList(clang::raw_ostream &OS, const clang::TemplateArgument *Args,
        unsigned NumArgs, /*AC++: commented out: const clang::PrintingPolicy &Policy,*/ bool SkipBrackets = false);
    void adjusted_TemplateArgument_print(const clang::TemplateArgument& temp_arg, /*AC++: commented out:const clang::PrintingPolicy &Policy,*/
                                         clang::raw_ostream &Out);
    void adjusted_NamedDecl_printQualifiedName(const clang::NamedDecl* named_decl, clang::raw_ostream &OS /*AC++: removed:,
                                       const clang::PrintingPolicy &P*/);
    void adjusted_printIntegral(const clang::TemplateArgument &TemplArg,
                                clang::raw_ostream &Out/*AC++: commented out: , const clang::PrintingPolicy& Policy*/);
    void adjusted_TemplateName_print(const clang::TemplateName& templ_name, clang::raw_ostream &OS/*AC++: commented out: ,
                                      const PrintingPolicy &Policy, bool SuppressNNS*/);
    void adjusted_NestedNameSpecifier_print(const clang::NestedNameSpecifier* nns, clang::raw_ostream &OS/*AC++: commented out:,
                                            const PrintingPolicy &Policy*/);
  };

//AC++: continuation in ClangAdjustedTypePrinter.cc

//AC++: Added include guard:
#endif // __ClangAdjustedTypePrinter_h__