clang 8.0.0

QualTypeNames.h
Go to the documentation of this file.
1 //===--- QualTypeNames.h - Generate Complete QualType Names ----*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 // ===----------------------------------------------------------------------===//
7 //
8 // \file
9 // Functionality to generate the fully-qualified names of QualTypes,
10 // including recursively expanding any subtypes and template
11 // parameters.
12 //
13 // More precisely: Generates a name that can be used to name the same
14 // type if used at the end of the current translation unit--with
15 // certain limitations. See below.
16 //
17 // This code desugars names only very minimally, so in this code:
18 //
19 // namespace A {
20 // struct X {};
21 // }
22 // using A::X;
23 // namespace B {
24 // using std::tuple;
25 // typedef tuple<X> TX;
26 // TX t;
27 // }
28 //
29 // B::t's type is reported as "B::TX", rather than std::tuple<A::X>.
30 //
31 // Also, this code replaces types found via using declarations with
32 // their more qualified name, so for the code:
33 //
34 // using std::tuple;
35 // tuple<int> TInt;
36 //
37 // TInt's type will be named, "std::tuple<int>".
38 //
39 // Limitations:
40 //
41 // Some types have ambiguous names at the end of a translation unit,
42 // are not namable at all there, or are special cases in other ways.
43 //
44 // 1) Types with only local scope will have their local names:
45 //
46 // void foo() {
47 // struct LocalType {} LocalVar;
48 // }
49 //
50 // LocalVar's type will be named, "struct LocalType", without any
51 // qualification.
52 //
53 // 2) Types that have been shadowed are reported normally, but a
54 // client using that name at the end of the translation unit will be
55 // referring to a different type.
56 //
57 // ===----------------------------------------------------------------------===//
58
59 #ifndef LLVM_CLANG_AST_QUALTYPENAMES_H
60 #define LLVM_CLANG_AST_QUALTYPENAMES_H
61
62 #include "clang/AST/ASTContext.h"
63
64 namespace clang {
65 namespace TypeName {
66 /// Get the fully qualified name for a type. This includes full
67 /// qualification of all template parameters etc.
68 ///
69 /// \param[in] QT - the type for which the fully qualified name will be
70 /// returned.
71 /// \param[in] Ctx - the ASTContext to be used.
72 /// \param[in] WithGlobalNsPrefix - If true, then the global namespace
73 /// specifier "::" will be prepended to the fully qualified name.
74 std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx,
75 const PrintingPolicy &Policy,
76 bool WithGlobalNsPrefix = false);
77
78 /// Generates a QualType that can be used to name the same type
79 /// if used at the end of the current translation unit. This ignores
80 /// issues such as type shadowing.
81 ///
82 /// \param[in] QT - the type for which the fully qualified type will be
83 /// returned.
84 /// \param[in] Ctx - the ASTContext to be used.
85 /// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
86 /// specifier "::" should be prepended or not.
87 QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
88 bool WithGlobalNsPrefix = false);
89 } // end namespace TypeName
90 } // end namespace clang
91 #endif // LLVM_CLANG_TOOLING_CORE_QUALTYPENAMES_H
ASTContext.h
Defines the clang::ASTContext interface.
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::TypeName::getFullyQualifiedName
std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx, const PrintingPolicy &Policy, bool WithGlobalNsPrefix=false)
Get the fully qualified name for a type.
Definition: QualTypeNames.cpp:453
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::TypeName::getFullyQualifiedType
QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, bool WithGlobalNsPrefix=false)
Generates a QualType that can be used to name the same type if used at the end of the current transla...
Definition: QualTypeNames.cpp:371