forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeclCollector.h
129 lines (102 loc) · 4.23 KB
/
DeclCollector.h
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
#ifndef CLING_DECL_COLLECTOR_H
#define CLING_DECL_COLLECTOR_H
#include "clang/AST/ASTConsumer.h"
#include "clang/Serialization/ASTDeserializationListener.h"
#include "ASTTransformer.h"
#include <vector>
#include <memory>
namespace clang {
class ASTContext;
class CodeGenerator;
class Decl;
class DeclGroupRef;
class Preprocessor;
class Token;
class Module;
}
namespace cling {
class ASTTransformer;
class WrapperTransformer;
class DeclCollector;
class IncrementalParser;
class Transaction;
///\brief Collects declarations and fills them in cling::Transaction.
///
/// cling::Transaction becomes is a main building block in the interpreter.
/// cling::DeclCollector is responsible for appending all the declarations
/// seen by clang.
///
class DeclCollector : public clang::ASTConsumer , public clang::ASTDeserializationListener {
/// \brief PPCallbacks overrides/ Macro support
class PPAdapter;
///\brief Contains the transaction AST transformers.
///
std::vector<std::unique_ptr<ASTTransformer>> m_TransactionTransformers;
///\brief Contains the AST transformers operating on the wrapper.
///
std::vector<std::unique_ptr<WrapperTransformer>> m_WrapperTransformers;
IncrementalParser* m_IncrParser;
clang::ASTConsumer* m_Consumer;
Transaction* m_CurTransaction;
/// Whether Transform() is active; prevents recursion.
bool m_Transforming = false;
///\brief Test whether the first decl of the DeclGroupRef comes from an AST
/// file.
///
bool comesFromASTReader(clang::DeclGroupRef DGR) const;
bool comesFromASTReader(const clang::Decl* D) const;
bool Transform(clang::DeclGroupRef& DGR);
///\brief Runs AST transformers on a transaction.
///
///\param[in] D - the decl to be transformed.
///
ASTTransformer::Result TransformDecl(clang::Decl* D) const;
public:
DeclCollector() :
m_IncrParser(0), m_Consumer(0), m_CurTransaction(0) {}
virtual ~DeclCollector();
void SetTransformers(std::vector<std::unique_ptr<ASTTransformer>>&& allTT,
std::vector<std::unique_ptr<WrapperTransformer>>&& allWT){
m_TransactionTransformers.swap(allTT);
m_WrapperTransformers.swap(allWT);
for (auto&& TT: m_TransactionTransformers)
TT->SetConsumer(this);
for (auto&& WT: m_WrapperTransformers)
WT->SetConsumer(this);
}
void Setup(IncrementalParser* IncrParser, ASTConsumer* Consumer,
clang::Preprocessor& PP);
/// \{
/// \name ASTConsumer overrides
bool HandleTopLevelDecl(clang::DeclGroupRef DGR) final;
void HandleInterestingDecl(clang::DeclGroupRef DGR) final;
void HandleTagDeclDefinition(clang::TagDecl* TD) final;
void HandleInvalidTagDeclDefinition(clang::TagDecl* TD) final;
void HandleVTable(clang::CXXRecordDecl* RD) final;
void CompleteTentativeDefinition(clang::VarDecl* VD) final;
void HandleTranslationUnit(clang::ASTContext& Ctx) final;
void HandleCXXImplicitFunctionInstantiation(clang::FunctionDecl *D) final;
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *D) final;
/// \}
/// \{
/// \name Transaction Support
Transaction* getTransaction() { return m_CurTransaction; }
const Transaction* getTransaction() const { return m_CurTransaction; }
void setTransaction(Transaction* curT) { m_CurTransaction = curT; }
/// \}
// dyn_cast/isa support
static bool classof(const clang::ASTConsumer*) { return true; }
static bool classof(const clang::ASTDeserializationListener*) { return true; }
///\brief ASTDeserializationListener function which gets callback when a decl is deserialized
void DeclRead(clang::serialization::DeclID, const clang::Decl *D) final;
};
} // namespace cling
#endif // CLING_DECL_COLLECTOR_H