clang  6.0.0svn
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 /// \brief 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  bool WithGlobalNsPrefix = false);
76 
77 /// \brief Generates a QualType that can be used to name the same type
78 /// if used at the end of the current translation unit. This ignores
79 /// issues such as type shadowing.
80 ///
81 /// \param[in] QT - the type for which the fully qualified type will be
82 /// returned.
83 /// \param[in] Ctx - the ASTContext to be used.
84 /// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
85 /// specifier "::" should be prepended or not.
87  bool WithGlobalNsPrefix = false);
88 } // end namespace TypeName
89 } // end namespace clang
90 #endif // LLVM_CLANG_TOOLING_CORE_QUALTYPENAMES_H
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
Definition: Type.h:653
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
Dataflow Directional Tag Classes.
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...
std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx, bool WithGlobalNsPrefix=false)
Get the fully qualified name for a type.