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