reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
//===--- QualTypeNames.h - Generate Complete QualType Names ----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// ===----------------------------------------------------------------------===//
//
// \file
// Functionality to generate the fully-qualified names of QualTypes,
// including recursively expanding any subtypes and template
// parameters.
//
// More precisely: Generates a name that can be used to name the same
// type if used at the end of the current translation unit--with
// certain limitations. See below.
//
// This code desugars names only very minimally, so in this code:
//
// namespace A {
//   struct X {};
// }
// using A::X;
// namespace B {
//   using std::tuple;
//   typedef tuple<X> TX;
//   TX t;
// }
//
// B::t's type is reported as "B::TX", rather than std::tuple<A::X>.
//
// Also, this code replaces types found via using declarations with
// their more qualified name, so for the code:
//
// using std::tuple;
// tuple<int> TInt;
//
// TInt's type will be named, "std::tuple<int>".
//
// Limitations:
//
// Some types have ambiguous names at the end of a translation unit,
// are not namable at all there, or are special cases in other ways.
//
// 1) Types with only local scope will have their local names:
//
// void foo() {
//   struct LocalType {} LocalVar;
// }
//
// LocalVar's type will be named, "struct LocalType", without any
// qualification.
//
// 2) Types that have been shadowed are reported normally, but a
// client using that name at the end of the translation unit will be
// referring to a different type.
//
// ===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_QUALTYPENAMES_H
#define LLVM_CLANG_AST_QUALTYPENAMES_H

#include "clang/AST/ASTContext.h"

namespace clang {
namespace TypeName {
/// Get the fully qualified name for a type. This includes full
/// qualification of all template parameters etc.
///
/// \param[in] QT - the type for which the fully qualified name will be
/// returned.
/// \param[in] Ctx - the ASTContext to be used.
/// \param[in] WithGlobalNsPrefix - If true, then the global namespace
/// specifier "::" will be prepended to the fully qualified name.
std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx,
                                  const PrintingPolicy &Policy,
                                  bool WithGlobalNsPrefix = false);

/// Generates a QualType that can be used to name the same type
/// if used at the end of the current translation unit. This ignores
/// issues such as type shadowing.
///
/// \param[in] QT - the type for which the fully qualified type will be
/// returned.
/// \param[in] Ctx - the ASTContext to be used.
/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
/// specifier "::" should be prepended or not.
QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
                               bool WithGlobalNsPrefix = false);
} // end namespace TypeName
} // end namespace clang
#endif // LLVM_CLANG_TOOLING_CORE_QUALTYPENAMES_H