clang  14.0.0git
NodeIntrospection.h
Go to the documentation of this file.
1 //===- NodeIntrospection.h ------------------------------------*- 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 // This file contains the implementation of the NodeIntrospection.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_TOOLING_NODEINTROSPECTION_H
14 #define LLVM_CLANG_TOOLING_NODEINTROSPECTION_H
15 
18 #include "llvm/ADT/IntrusiveRefCntPtr.h"
19 #include <set>
20 
21 namespace clang {
22 
23 class Stmt;
24 class Decl;
25 class CXXCtorInitializer;
26 class NestedNameSpecifierLoc;
27 class TemplateArgumentLoc;
28 class CXXBaseSpecifier;
29 struct DeclarationNameInfo;
30 
31 namespace tooling {
32 
33 class LocationCall;
35 
36 class LocationCall : public llvm::ThreadSafeRefCountedBase<LocationCall> {
37 public:
40  LocationCallFlags flags = NoFlags)
41  : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)) {}
42 
43  LocationCall *on() const { return m_on.get(); }
44  StringRef name() const { return m_name; }
45  bool returnsPointer() const { return m_flags & ReturnsPointer; }
46  bool isCast() const { return m_flags & IsCast; }
47 
48 private:
49  LocationCallFlags m_flags;
50  SharedLocationCall m_on;
51  std::string m_name;
52 };
53 
55 public:
56  static void print(const LocationCall &Call, llvm::raw_ostream &OS);
57  static std::string format(const LocationCall &Call);
58 };
59 
60 namespace internal {
61 struct RangeLessThan {
62  bool operator()(std::pair<SourceRange, SharedLocationCall> const &LHS,
63  std::pair<SourceRange, SharedLocationCall> const &RHS) const;
64  bool
65  operator()(std::pair<SourceLocation, SharedLocationCall> const &LHS,
66  std::pair<SourceLocation, SharedLocationCall> const &RHS) const;
67 };
68 
69 } // namespace internal
70 
71 // Note that this container stores unique results in a deterministic, but
72 // the location calls are in an unspecified order. Clients which desire
73 // a particular order for the location calls, such as alphabetical,
74 // should sort results after retrieval, because the order is dependent
75 // on how the LocationCalls are formatted.
76 template <typename T, typename U>
77 using UniqueMultiMap = std::set<std::pair<T, U>, internal::RangeLessThan>;
78 
81 
85 };
86 
87 namespace NodeIntrospection {
98 } // namespace NodeIntrospection
99 } // namespace tooling
100 } // namespace clang
101 #endif
clang::tooling::LocationCall::ReturnsPointer
@ ReturnsPointer
Definition: NodeIntrospection.h:38
clang::tooling::LocationCall::name
StringRef name() const
Definition: NodeIntrospection.h:44
clang::tooling::SourceRangeMap
UniqueMultiMap< SourceRange, SharedLocationCall > SourceRangeMap
Definition: NodeIntrospection.h:80
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::tooling::LocationCall::LocationCall
LocationCall(SharedLocationCall on, std::string name, LocationCallFlags flags=NoFlags)
Definition: NodeIntrospection.h:39
clang::tooling::NodeLocationAccessors::LocationAccessors
SourceLocationMap LocationAccessors
Definition: NodeIntrospection.h:83
clang::tooling::SourceLocationMap
UniqueMultiMap< SourceLocation, SharedLocationCall > SourceLocationMap
Definition: NodeIntrospection.h:79
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::tooling::NodeLocationAccessors::RangeAccessors
SourceRangeMap RangeAccessors
Definition: NodeIntrospection.h:84
clang::tooling::internal::RangeLessThan::operator()
bool operator()(std::pair< SourceRange, SharedLocationCall > const &LHS, std::pair< SourceRange, SharedLocationCall > const &RHS) const
Definition: NodeIntrospection.cpp:61
Node
DynTypedNode Node
Definition: ASTMatchFinder.cpp:67
clang::tooling::LocationCall::on
LocationCall * on() const
Definition: NodeIntrospection.h:43
clang::tooling::LocationCallFormatterCpp::print
static void print(const LocationCall &Call, llvm::raw_ostream &OS)
Definition: NodeIntrospection.cpp:22
clang::tooling::UniqueMultiMap
std::set< std::pair< T, U >, internal::RangeLessThan > UniqueMultiMap
Definition: NodeIntrospection.h:77
clang::tooling::LocationCall::isCast
bool isCast() const
Definition: NodeIntrospection.h:46
clang::TemplateArgumentLoc
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:458
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:243
clang::tooling::LocationCallFormatterCpp::format
static std::string format(const LocationCall &Call)
Definition: NodeIntrospection.cpp:35
clang::tooling::internal::RangeLessThan
Definition: NodeIntrospection.h:61
clang::tooling::NodeIntrospection::hasIntrospectionSupport
bool hasIntrospectionSupport()
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
clang::tooling::NodeLocationAccessors
Definition: NodeIntrospection.h:82
clang::tooling::LocationCall::NoFlags
@ NoFlags
Definition: NodeIntrospection.h:38
ASTTypeTraits.h
clang::tooling::LocationCall::returnsPointer
bool returnsPointer() const
Definition: NodeIntrospection.h:45
std
Definition: Format.h:4034
DeclarationName.h
clang::tooling::NodeIntrospection::GetLocations
NodeLocationAccessors GetLocations(clang::Stmt const *Object)
clang
Definition: CalledOnceCheck.h:17
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::tooling::LocationCall::LocationCallFlags
LocationCallFlags
Definition: NodeIntrospection.h:38
clang::CXXBaseSpecifier
Represents a base class of a C++ class.
Definition: DeclCXX.h:147
clang::tooling::LocationCallFormatterCpp
Definition: NodeIntrospection.h:54
clang::DynTypedNode
A dynamically typed AST node container.
Definition: ASTTypeTraits.h:243
clang::tooling::LocationCall
Definition: NodeIntrospection.h:36
clang::CXXCtorInitializer
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2172
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:758
llvm::IntrusiveRefCntPtr< LocationCall >
clang::tooling::LocationCall::IsCast
@ IsCast
Definition: NodeIntrospection.h:38