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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===- NodeIntrospection.h ------------------------------------*- 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
//
//===----------------------------------------------------------------------===//
//
// This file contains the implementation of the NodeIntrospection.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLING_NODEINTROSPECTION_H
#define LLVM_CLANG_TOOLING_NODEINTROSPECTION_H
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/DeclarationName.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include <set>
namespace clang {
class Stmt;
class Decl;
class CXXCtorInitializer;
class NestedNameSpecifierLoc;
class TemplateArgumentLoc;
class CXXBaseSpecifier;
struct DeclarationNameInfo;
namespace tooling {
class LocationCall;
using SharedLocationCall = llvm::IntrusiveRefCntPtr<LocationCall>;
class LocationCall : public llvm::ThreadSafeRefCountedBase<LocationCall> {
public:
enum LocationCallFlags { NoFlags, ReturnsPointer, IsCast };
LocationCall(SharedLocationCall on, std::string name,
LocationCallFlags flags = NoFlags)
: m_flags(flags), m_on(std::move(on)), m_name(std::move(name)) {}
LocationCall *on() const { return m_on.get(); }
StringRef name() const { return m_name; }
bool returnsPointer() const { return m_flags & ReturnsPointer; }
bool isCast() const { return m_flags & IsCast; }
private:
LocationCallFlags m_flags;
SharedLocationCall m_on;
std::string m_name;
};
class LocationCallFormatterCpp {
public:
static void print(const LocationCall &Call, llvm::raw_ostream &OS);
static std::string format(const LocationCall &Call);
};
namespace internal {
struct RangeLessThan {
bool operator()(std::pair<SourceRange, SharedLocationCall> const &LHS,
std::pair<SourceRange, SharedLocationCall> const &RHS) const;
bool
operator()(std::pair<SourceLocation, SharedLocationCall> const &LHS,
std::pair<SourceLocation, SharedLocationCall> const &RHS) const;
};
} // namespace internal
// Note that this container stores unique results in a deterministic, but
// the location calls are in an unspecified order. Clients which desire
// a particular order for the location calls, such as alphabetical,
// should sort results after retrieval, because the order is dependent
// on how the LocationCalls are formatted.
template <typename T, typename U>
using UniqueMultiMap = std::set<std::pair<T, U>, internal::RangeLessThan>;
using SourceLocationMap = UniqueMultiMap<SourceLocation, SharedLocationCall>;
using SourceRangeMap = UniqueMultiMap<SourceRange, SharedLocationCall>;
struct NodeLocationAccessors {
SourceLocationMap LocationAccessors;
SourceRangeMap RangeAccessors;
};
namespace NodeIntrospection {
bool hasIntrospectionSupport();
NodeLocationAccessors GetLocations(clang::Stmt const *Object);
NodeLocationAccessors GetLocations(clang::Decl const *Object);
NodeLocationAccessors GetLocations(clang::CXXCtorInitializer const *Object);
NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const &);
NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const &);
NodeLocationAccessors GetLocations(clang::CXXBaseSpecifier const *);
NodeLocationAccessors GetLocations(clang::TypeLoc const &);
NodeLocationAccessors GetLocations(clang::DeclarationNameInfo const &);
NodeLocationAccessors GetLocations(clang::DynTypedNode const &Node);
} // namespace NodeIntrospection
} // namespace tooling
} // namespace clang
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|