Divide TraverseInitListExpr to a different function for each form.

Summary: create TraverseSyntacticInitListExpr and TraverseSemanticInitListExpr.

Reviewers: rsmith, klimek

Subscribers: klimek, cfe-commits, alexfh

Differential Revision: http://reviews.llvm.org/D13249

llvm-svn: 249129
This commit is contained in:
Angel Garcia Gomez 2015-10-02 13:25:51 +00:00
parent 7d76847da3
commit b1a73fa94d
1 changed files with 28 additions and 20 deletions

View File

@ -255,6 +255,12 @@ public:
/// \returns false if the visitation was terminated early, true otherwise. /// \returns false if the visitation was terminated early, true otherwise.
bool TraverseLambdaBody(LambdaExpr *LE); bool TraverseLambdaBody(LambdaExpr *LE);
/// \brief Recursively visit the syntactic or semantic form of an
/// initialization list.
///
/// \returns false if the visitation was terminated early, true otherwise.
bool TraverseSynOrSemInitListExpr(InitListExpr *S);
// ---- Methods on Attrs ---- // ---- Methods on Attrs ----
// \brief Visit an attribute. // \brief Visit an attribute.
@ -2056,28 +2062,30 @@ DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
}) })
// InitListExpr is a tricky one, because we want to do all our work on template <typename Derived>
// the syntactic form of the listexpr, but this method takes the bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(InitListExpr *S) {
// semantic form by default. We can't use the macro helper because it if (S) {
// calls WalkUp*() on the semantic form, before our code can convert TRY_TO(WalkUpFromInitListExpr(S));
// to the syntactic form. // All we need are the default actions. FIXME: use a helper function.
for (Stmt *SubStmt : S->children()) {
TRY_TO(TraverseStmt(SubStmt));
}
}
return true;
}
// This method is called once for each pair of syntactic and semantic
// InitListExpr, and it traverses the subtrees defined by the two forms. This
// may cause some of the children to be visited twice, if they appear both in
// the syntactic and the semantic form.
//
// There is no guarantee about which form \p S takes when this method is called.
template <typename Derived> template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) { bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
InitListExpr *Syn = S->isSemanticForm() ? S->getSyntacticForm() : S; TRY_TO(TraverseSynOrSemInitListExpr(
if (Syn) { S->isSemanticForm() ? S->getSyntacticForm() : S));
TRY_TO(WalkUpFromInitListExpr(Syn)); TRY_TO(TraverseSynOrSemInitListExpr(
// All we need are the default actions. FIXME: use a helper function. S->isSemanticForm() ? S : S->getSemanticForm()));
for (Stmt *SubStmt : Syn->children()) {
TRY_TO(TraverseStmt(SubStmt));
}
}
InitListExpr *Sem = S->isSemanticForm() ? S : S->getSemanticForm();
if (Sem) {
TRY_TO(WalkUpFromInitListExpr(Sem));
for (Stmt *SubStmt : Sem->children()) {
TRY_TO(TraverseStmt(SubStmt));
}
}
return true; return true;
} }