@@ -127,6 +127,8 @@ class SyntaxTree::Impl {
127
127
128
128
SyntaxTree *Parent;
129
129
ASTContext *
130
+ // / Nodes in preorder.
131
+ std::vector<Node> Nodes;
130
132
std::vector<NodeId> Leaves;
131
133
// Maps preorder indices to postorder ones.
132
134
std::vector<int > PostorderIds;
@@ -155,9 +157,6 @@ class SyntaxTree::Impl {
155
157
std::string getStmtValue (const Stmt *S) const ;
156
158
157
159
private:
158
- // / Nodes in preorder.
159
- std::vector<Node> Nodes;
160
-
161
160
void initTree ();
162
161
void setLeftMostDescendants ();
163
162
};
@@ -181,32 +180,6 @@ static bool isNodeExcluded(const SourceManager &SrcMgr, T *N) {
181
180
return isSpecializedNodeExcluded (N);
182
181
}
183
182
184
- namespace {
185
- // / Counts the number of nodes that will be compared.
186
- struct NodeCountVisitor : public RecursiveASTVisitor <NodeCountVisitor> {
187
- int Count = 0 ;
188
- const SyntaxTree::Impl &Tree;
189
- NodeCountVisitor (const SyntaxTree::Impl &Tree) : Tree(Tree) {}
190
- bool TraverseDecl (Decl *D) {
191
- if (isNodeExcluded (Tree.AST .getSourceManager (), D))
192
- return true ;
193
- ++Count;
194
- RecursiveASTVisitor<NodeCountVisitor>::TraverseDecl (D);
195
- return true ;
196
- }
197
- bool TraverseStmt (Stmt *S) {
198
- if (S)
199
- S = S->IgnoreImplicit ();
200
- if (isNodeExcluded (Tree.AST .getSourceManager (), S))
201
- return true ;
202
- ++Count;
203
- RecursiveASTVisitor<NodeCountVisitor>::TraverseStmt (S);
204
- return true ;
205
- }
206
- bool TraverseType (QualType T) { return true ; }
207
- };
208
- } // end anonymous namespace
209
-
210
183
namespace {
211
184
// Sets Height, Parent and Children for each node.
212
185
struct PreorderVisitor : public RecursiveASTVisitor <PreorderVisitor> {
@@ -218,6 +191,7 @@ struct PreorderVisitor : public RecursiveASTVisitor<PreorderVisitor> {
218
191
219
192
template <class T > std::tuple<NodeId, NodeId> PreTraverse (T *ASTNode) {
220
193
NodeId MyId = Id;
194
+ Tree.Nodes .emplace_back ();
221
195
Node &N = Tree.getMutableNode (MyId);
222
196
N.Parent = Parent;
223
197
N.Depth = Depth;
@@ -274,19 +248,13 @@ struct PreorderVisitor : public RecursiveASTVisitor<PreorderVisitor> {
274
248
275
249
SyntaxTree::Impl::Impl (SyntaxTree *Parent, Decl *N, ASTContext &AST)
276
250
: Parent(Parent), AST(AST) {
277
- NodeCountVisitor NodeCounter (*this );
278
- NodeCounter.TraverseDecl (N);
279
- Nodes.resize (NodeCounter.Count );
280
251
PreorderVisitor PreorderWalker (*this );
281
252
PreorderWalker.TraverseDecl (N);
282
253
initTree ();
283
254
}
284
255
285
256
SyntaxTree::Impl::Impl (SyntaxTree *Parent, Stmt *N, ASTContext &AST)
286
257
: Parent(Parent), AST(AST) {
287
- NodeCountVisitor NodeCounter (*this );
288
- NodeCounter.TraverseStmt (N);
289
- Nodes.resize (NodeCounter.Count );
290
258
PreorderVisitor PreorderWalker (*this );
291
259
PreorderWalker.TraverseStmt (N);
292
260
initTree ();
0 commit comments