From: Alp Toker Date: Sun, 18 May 2014 18:38:19 +0000 (+0000) Subject: Format the two RecursiveASTVisitors X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c480f5d670c68574216ca8c280cd29dd499c648b;p=clang Format the two RecursiveASTVisitors Apply current ToT clang-format on the two RAVs to reduce delta and help identify differences between the two. We lose a little pretty formatting in the headers but that's the price to pay so we can diff these two files effectively and look to a future where we don't have to maintain two copies of this code. Formatting and whitespace only. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209092 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 2e59e2898f..27d78a75d1 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -38,34 +38,24 @@ // using them is responsible for defining macro OPERATOR(). // All unary operators. -#define UNARYOP_LIST() \ - OPERATOR(PostInc) OPERATOR(PostDec) \ - OPERATOR(PreInc) OPERATOR(PreDec) \ - OPERATOR(AddrOf) OPERATOR(Deref) \ - OPERATOR(Plus) OPERATOR(Minus) \ - OPERATOR(Not) OPERATOR(LNot) \ - OPERATOR(Real) OPERATOR(Imag) \ - OPERATOR(Extension) +#define UNARYOP_LIST() \ + OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec) \ + OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus) \ + OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag) \ + OPERATOR(Extension) // All binary operators (excluding compound assign operators). -#define BINOP_LIST() \ - OPERATOR(PtrMemD) OPERATOR(PtrMemI) \ - OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) \ - OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) \ - OPERATOR(Shr) \ - \ - OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) \ - OPERATOR(GE) OPERATOR(EQ) OPERATOR(NE) \ - OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) \ - OPERATOR(LAnd) OPERATOR(LOr) \ - \ - OPERATOR(Assign) \ - OPERATOR(Comma) +#define BINOP_LIST() \ + OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div) \ + OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr) \ + OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ) \ + OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd) \ + OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma) // All compound assign operators. -#define CAO_LIST() \ - OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \ - OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor) +#define CAO_LIST() \ + OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \ + OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor) namespace clang { @@ -77,8 +67,11 @@ namespace clang { // invokes CALL_EXPR, which must be a method call, on the derived // object (s.t. a user of RecursiveASTVisitor can override the method // in CALL_EXPR). -#define TRY_TO(CALL_EXPR) \ - do { if (!getDerived().CALL_EXPR) return false; } while (0) +#define TRY_TO(CALL_EXPR) \ + do { \ + if (!getDerived().CALL_EXPR) \ + return false; \ + } while (0) /// \brief A class that does preorder depth-first traversal on the /// entire Clang AST and visits each node. @@ -144,11 +137,10 @@ namespace clang { /// to return true, in which case all known implicit and explicit /// instantiations will be visited at the same time as the pattern /// from which they were produced. -template -class RecursiveASTVisitor { +template class RecursiveASTVisitor { public: /// \brief Return a reference to the derived class. - Derived &getDerived() { return *static_cast(this); } + Derived &getDerived() { return *static_cast(this); } /// \brief Return whether this visitor should recurse into /// template instantiations. @@ -255,114 +247,111 @@ public: // \brief Visit an attribute. bool VisitAttr(Attr *A) { return true; } - // Declare Traverse* and empty Visit* for all Attr classes. +// Declare Traverse* and empty Visit* for all Attr classes. #define ATTR_VISITOR_DECLS_ONLY #include "clang/AST/AttrVisitor.inc" #undef ATTR_VISITOR_DECLS_ONLY - // ---- Methods on Stmts ---- +// ---- Methods on Stmts ---- - // Declare Traverse*() for all concrete Stmt classes. +// Declare Traverse*() for all concrete Stmt classes. #define ABSTRACT_STMT(STMT) -#define STMT(CLASS, PARENT) \ - bool Traverse##CLASS(CLASS *S); +#define STMT(CLASS, PARENT) bool Traverse##CLASS(CLASS *S); #include "clang/AST/StmtNodes.inc" // The above header #undefs ABSTRACT_STMT and STMT upon exit. // Define WalkUpFrom*() and empty Visit*() for all Stmt classes. bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); } bool VisitStmt(Stmt *S) { return true; } -#define STMT(CLASS, PARENT) \ - bool WalkUpFrom##CLASS(CLASS *S) { \ - TRY_TO(WalkUpFrom##PARENT(S)); \ - TRY_TO(Visit##CLASS(S)); \ - return true; \ - } \ +#define STMT(CLASS, PARENT) \ + bool WalkUpFrom##CLASS(CLASS *S) { \ + TRY_TO(WalkUpFrom##PARENT(S)); \ + TRY_TO(Visit##CLASS(S)); \ + return true; \ + } \ bool Visit##CLASS(CLASS *S) { return true; } #include "clang/AST/StmtNodes.inc" - // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary - // operator methods. Unary operators are not classes in themselves - // (they're all opcodes in UnaryOperator) but do have visitors. -#define OPERATOR(NAME) \ - bool TraverseUnary##NAME(UnaryOperator *S) { \ - TRY_TO(WalkUpFromUnary##NAME(S)); \ - StmtQueueAction StmtQueue(*this); \ - StmtQueue.queue(S->getSubExpr()); \ - return true; \ - } \ - bool WalkUpFromUnary##NAME(UnaryOperator *S) { \ - TRY_TO(WalkUpFromUnaryOperator(S)); \ - TRY_TO(VisitUnary##NAME(S)); \ - return true; \ - } \ +// Define Traverse*(), WalkUpFrom*(), and Visit*() for unary +// operator methods. Unary operators are not classes in themselves +// (they're all opcodes in UnaryOperator) but do have visitors. +#define OPERATOR(NAME) \ + bool TraverseUnary##NAME(UnaryOperator *S) { \ + TRY_TO(WalkUpFromUnary##NAME(S)); \ + StmtQueueAction StmtQueue(*this); \ + StmtQueue.queue(S->getSubExpr()); \ + return true; \ + } \ + bool WalkUpFromUnary##NAME(UnaryOperator *S) { \ + TRY_TO(WalkUpFromUnaryOperator(S)); \ + TRY_TO(VisitUnary##NAME(S)); \ + return true; \ + } \ bool VisitUnary##NAME(UnaryOperator *S) { return true; } UNARYOP_LIST() #undef OPERATOR - // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary - // operator methods. Binary operators are not classes in themselves - // (they're all opcodes in BinaryOperator) but do have visitors. -#define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \ - bool TraverseBin##NAME(BINOP_TYPE *S) { \ - TRY_TO(WalkUpFromBin##NAME(S)); \ - StmtQueueAction StmtQueue(*this); \ - StmtQueue.queue(S->getLHS()); \ - StmtQueue.queue(S->getRHS()); \ - return true; \ - } \ - bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \ - TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \ - TRY_TO(VisitBin##NAME(S)); \ - return true; \ - } \ +// Define Traverse*(), WalkUpFrom*(), and Visit*() for binary +// operator methods. Binary operators are not classes in themselves +// (they're all opcodes in BinaryOperator) but do have visitors. +#define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \ + bool TraverseBin##NAME(BINOP_TYPE *S) { \ + TRY_TO(WalkUpFromBin##NAME(S)); \ + StmtQueueAction StmtQueue(*this); \ + StmtQueue.queue(S->getLHS()); \ + StmtQueue.queue(S->getRHS()); \ + return true; \ + } \ + bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \ + TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \ + TRY_TO(VisitBin##NAME(S)); \ + return true; \ + } \ bool VisitBin##NAME(BINOP_TYPE *S) { return true; } #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator) BINOP_LIST() #undef OPERATOR - // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound - // assignment methods. Compound assignment operators are not - // classes in themselves (they're all opcodes in - // CompoundAssignOperator) but do have visitors. -#define OPERATOR(NAME) \ +// Define Traverse*(), WalkUpFrom*(), and Visit*() for compound +// assignment methods. Compound assignment operators are not +// classes in themselves (they're all opcodes in +// CompoundAssignOperator) but do have visitors. +#define OPERATOR(NAME) \ GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator) CAO_LIST() #undef OPERATOR #undef GENERAL_BINOP_FALLBACK - // ---- Methods on Types ---- - // FIXME: revamp to take TypeLoc's rather than Types. +// ---- Methods on Types ---- +// FIXME: revamp to take TypeLoc's rather than Types. - // Declare Traverse*() for all concrete Type classes. +// Declare Traverse*() for all concrete Type classes. #define ABSTRACT_TYPE(CLASS, BASE) -#define TYPE(CLASS, BASE) \ - bool Traverse##CLASS##Type(CLASS##Type *T); +#define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T); #include "clang/AST/TypeNodes.def" // The above header #undefs ABSTRACT_TYPE and TYPE upon exit. // Define WalkUpFrom*() and empty Visit*() for all Type classes. bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); } bool VisitType(Type *T) { return true; } -#define TYPE(CLASS, BASE) \ - bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \ - TRY_TO(WalkUpFrom##BASE(T)); \ - TRY_TO(Visit##CLASS##Type(T)); \ - return true; \ - } \ +#define TYPE(CLASS, BASE) \ + bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \ + TRY_TO(WalkUpFrom##BASE(T)); \ + TRY_TO(Visit##CLASS##Type(T)); \ + return true; \ + } \ bool Visit##CLASS##Type(CLASS##Type *T) { return true; } #include "clang/AST/TypeNodes.def" - // ---- Methods on TypeLocs ---- - // FIXME: this currently just calls the matching Type methods +// ---- Methods on TypeLocs ---- +// FIXME: this currently just calls the matching Type methods - // Declare Traverse*() for all concrete Type classes. +// Declare Traverse*() for all concrete Type classes. #define ABSTRACT_TYPELOC(CLASS, BASE) -#define TYPELOC(CLASS, BASE) \ - bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL); +#define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL); #include "clang/AST/TypeLocNodes.def" // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit. @@ -381,34 +370,33 @@ public: } bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; } - // Note that BASE includes trailing 'Type' which CLASS doesn't. -#define TYPE(CLASS, BASE) \ - bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ - TRY_TO(WalkUpFrom##BASE##Loc(TL)); \ - TRY_TO(Visit##CLASS##TypeLoc(TL)); \ - return true; \ - } \ +// Note that BASE includes trailing 'Type' which CLASS doesn't. +#define TYPE(CLASS, BASE) \ + bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ + TRY_TO(WalkUpFrom##BASE##Loc(TL)); \ + TRY_TO(Visit##CLASS##TypeLoc(TL)); \ + return true; \ + } \ bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; } #include "clang/AST/TypeNodes.def" - // ---- Methods on Decls ---- +// ---- Methods on Decls ---- - // Declare Traverse*() for all concrete Decl classes. +// Declare Traverse*() for all concrete Decl classes. #define ABSTRACT_DECL(DECL) -#define DECL(CLASS, BASE) \ - bool Traverse##CLASS##Decl(CLASS##Decl *D); +#define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D); #include "clang/AST/DeclNodes.inc" // The above header #undefs ABSTRACT_DECL and DECL upon exit. // Define WalkUpFrom*() and empty Visit*() for all Decl classes. bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); } bool VisitDecl(Decl *D) { return true; } -#define DECL(CLASS, BASE) \ - bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \ - TRY_TO(WalkUpFrom##BASE(D)); \ - TRY_TO(Visit##CLASS##Decl(D)); \ - return true; \ - } \ +#define DECL(CLASS, BASE) \ + bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \ + TRY_TO(WalkUpFrom##BASE(D)); \ + TRY_TO(Visit##CLASS##Decl(D)); \ + return true; \ + } \ bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; } #include "clang/AST/DeclNodes.inc" @@ -417,7 +405,7 @@ private: bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL); bool TraverseClassInstantiations(ClassTemplateDecl *D); bool TraverseVariableInstantiations(VarTemplateDecl *D); - bool TraverseFunctionInstantiations(FunctionTemplateDecl *D) ; + bool TraverseFunctionInstantiations(FunctionTemplateDecl *D); bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL, unsigned Count); bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL); @@ -429,27 +417,24 @@ private: bool TraverseVarHelper(VarDecl *D); bool TraverseOMPClause(OMPClause *C); bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); -#define OPENMP_CLAUSE(Name, Class) \ - bool Visit##Class(Class *C); +#define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C); #include "clang/Basic/OpenMPKinds.def" /// \brief Process clauses with list of variables. - template - void VisitOMPClauseList(T *Node); + template void VisitOMPClauseList(T *Node); typedef SmallVector StmtsTy; typedef SmallVector QueuesTy; - + QueuesTy Queues; class NewQueueRAII { RecursiveASTVisitor &RAV; + public: NewQueueRAII(StmtsTy &queue, RecursiveASTVisitor &RAV) : RAV(RAV) { RAV.Queues.push_back(&queue); } - ~NewQueueRAII() { - RAV.Queues.pop_back(); - } + ~NewQueueRAII() { RAV.Queues.pop_back(); } }; StmtsTy &getCurrentQueue() { @@ -460,20 +445,19 @@ private: public: class StmtQueueAction { StmtsTy &CurrQueue; + public: explicit StmtQueueAction(RecursiveASTVisitor &RAV) - : CurrQueue(RAV.getCurrentQueue()) { } + : CurrQueue(RAV.getCurrentQueue()) {} - void queue(Stmt *S) { - CurrQueue.push_back(S); - } + void queue(Stmt *S) { CurrQueue.push_back(S); } }; }; -#define DISPATCH(NAME, CLASS, VAR) \ - return getDerived().Traverse##NAME(static_cast(VAR)) +#define DISPATCH(NAME, CLASS, VAR) \ + return getDerived().Traverse##NAME(static_cast(VAR)) -template +template bool RecursiveASTVisitor::TraverseStmt(Stmt *S) { if (!S) return true; @@ -489,84 +473,89 @@ bool RecursiveASTVisitor::TraverseStmt(Stmt *S) { StmtsToEnqueu.clear(); -#define DISPATCH_STMT(NAME, CLASS, VAR) \ - TRY_TO(Traverse##NAME(static_cast(VAR))); break +#define DISPATCH_STMT(NAME, CLASS, VAR) \ + TRY_TO(Traverse##NAME(static_cast(VAR))); \ + break // If we have a binary expr, dispatch to the subcode of the binop. A smart // optimizer (e.g. LLVM) will fold this comparison into the switch stmt // below. if (BinaryOperator *BinOp = dyn_cast(S)) { switch (BinOp->getOpcode()) { -#define OPERATOR(NAME) \ - case BO_##NAME: DISPATCH_STMT(Bin##NAME, BinaryOperator, S); - - BINOP_LIST() +#define OPERATOR(NAME) \ + case BO_##NAME: \ + DISPATCH_STMT(Bin##NAME, BinaryOperator, S); + + BINOP_LIST() #undef OPERATOR #undef BINOP_LIST - -#define OPERATOR(NAME) \ - case BO_##NAME##Assign: \ - DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S); - - CAO_LIST() + +#define OPERATOR(NAME) \ + case BO_##NAME##Assign: \ + DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S); + + CAO_LIST() #undef OPERATOR #undef CAO_LIST } } else if (UnaryOperator *UnOp = dyn_cast(S)) { switch (UnOp->getOpcode()) { -#define OPERATOR(NAME) \ - case UO_##NAME: DISPATCH_STMT(Unary##NAME, UnaryOperator, S); - - UNARYOP_LIST() +#define OPERATOR(NAME) \ + case UO_##NAME: \ + DISPATCH_STMT(Unary##NAME, UnaryOperator, S); + + UNARYOP_LIST() #undef OPERATOR #undef UNARYOP_LIST } } else { - + // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt. switch (S->getStmtClass()) { - case Stmt::NoStmtClass: break; + case Stmt::NoStmtClass: + break; #define ABSTRACT_STMT(STMT) -#define STMT(CLASS, PARENT) \ - case Stmt::CLASS##Class: DISPATCH_STMT(CLASS, CLASS, S); +#define STMT(CLASS, PARENT) \ + case Stmt::CLASS##Class: \ + DISPATCH_STMT(CLASS, CLASS, S); #include "clang/AST/StmtNodes.inc" } } - for (SmallVectorImpl::reverse_iterator - RI = StmtsToEnqueu.rbegin(), - RE = StmtsToEnqueu.rend(); RI != RE; ++RI) + for (SmallVectorImpl::reverse_iterator RI = StmtsToEnqueu.rbegin(), + RE = StmtsToEnqueu.rend(); + RI != RE; ++RI) Queue.push_back(*RI); } return true; } -template +template bool RecursiveASTVisitor::TraverseType(QualType T) { if (T.isNull()) return true; switch (T->getTypeClass()) { #define ABSTRACT_TYPE(CLASS, BASE) -#define TYPE(CLASS, BASE) \ - case Type::CLASS: DISPATCH(CLASS##Type, CLASS##Type, \ - const_cast(T.getTypePtr())); +#define TYPE(CLASS, BASE) \ + case Type::CLASS: \ + DISPATCH(CLASS##Type, CLASS##Type, const_cast(T.getTypePtr())); #include "clang/AST/TypeNodes.def" } return true; } -template +template bool RecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { if (TL.isNull()) return true; switch (TL.getTypeLocClass()) { #define ABSTRACT_TYPELOC(CLASS, BASE) -#define TYPELOC(CLASS, BASE) \ - case TypeLoc::CLASS: \ +#define TYPELOC(CLASS, BASE) \ + case TypeLoc::CLASS: \ return getDerived().Traverse##CLASS##TypeLoc(TL.castAs()); #include "clang/AST/TypeLocNodes.def" } @@ -574,13 +563,12 @@ bool RecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { return true; } - // Define the Traverse*Attr(Attr* A) methods #define VISITORCLASS RecursiveASTVisitor #include "clang/AST/AttrVisitor.inc" #undef VISITORCLASS -template +template bool RecursiveASTVisitor::TraverseDecl(Decl *D) { if (!D) return true; @@ -593,10 +581,10 @@ bool RecursiveASTVisitor::TraverseDecl(Decl *D) { switch (D->getKind()) { #define ABSTRACT_DECL(DECL) -#define DECL(CLASS, BASE) \ - case Decl::CLASS: \ - if (!getDerived().Traverse##CLASS##Decl(static_cast(D))) \ - return false; \ +#define DECL(CLASS, BASE) \ + case Decl::CLASS: \ + if (!getDerived().Traverse##CLASS##Decl(static_cast(D))) \ + return false; \ break; #include "clang/AST/DeclNodes.inc" } @@ -611,9 +599,9 @@ bool RecursiveASTVisitor::TraverseDecl(Decl *D) { #undef DISPATCH -template +template bool RecursiveASTVisitor::TraverseNestedNameSpecifier( - NestedNameSpecifier *NNS) { + NestedNameSpecifier *NNS) { if (!NNS) return true; @@ -635,14 +623,14 @@ bool RecursiveASTVisitor::TraverseNestedNameSpecifier( return true; } -template +template bool RecursiveASTVisitor::TraverseNestedNameSpecifierLoc( - NestedNameSpecifierLoc NNS) { + NestedNameSpecifierLoc NNS) { if (!NNS) return true; - if (NestedNameSpecifierLoc Prefix = NNS.getPrefix()) - TRY_TO(TraverseNestedNameSpecifierLoc(Prefix)); + if (NestedNameSpecifierLoc Prefix = NNS.getPrefix()) + TRY_TO(TraverseNestedNameSpecifierLoc(Prefix)); switch (NNS.getNestedNameSpecifier()->getKind()) { case NestedNameSpecifier::Identifier: @@ -660,9 +648,9 @@ bool RecursiveASTVisitor::TraverseNestedNameSpecifierLoc( return true; } -template +template bool RecursiveASTVisitor::TraverseDeclarationNameInfo( - DeclarationNameInfo NameInfo) { + DeclarationNameInfo NameInfo) { switch (NameInfo.getName().getNameKind()) { case DeclarationName::CXXConstructorName: case DeclarationName::CXXDestructorName: @@ -685,7 +673,7 @@ bool RecursiveASTVisitor::TraverseDeclarationNameInfo( return true; } -template +template bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier())); @@ -695,9 +683,9 @@ bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { return true; } -template +template bool RecursiveASTVisitor::TraverseTemplateArgument( - const TemplateArgument &Arg) { + const TemplateArgument &Arg) { switch (Arg.getKind()) { case TemplateArgument::Null: case TemplateArgument::Declaration: @@ -711,7 +699,7 @@ bool RecursiveASTVisitor::TraverseTemplateArgument( case TemplateArgument::Template: case TemplateArgument::TemplateExpansion: return getDerived().TraverseTemplateName( - Arg.getAsTemplateOrTemplatePattern()); + Arg.getAsTemplateOrTemplatePattern()); case TemplateArgument::Expression: return getDerived().TraverseStmt(Arg.getAsExpr()); @@ -726,9 +714,9 @@ bool RecursiveASTVisitor::TraverseTemplateArgument( // FIXME: no template name location? // FIXME: no source locations for a template argument pack? -template +template bool RecursiveASTVisitor::TraverseTemplateArgumentLoc( - const TemplateArgumentLoc &ArgLoc) { + const TemplateArgumentLoc &ArgLoc) { const TemplateArgument &Arg = ArgLoc.getArgument(); switch (Arg.getKind()) { @@ -750,9 +738,9 @@ bool RecursiveASTVisitor::TraverseTemplateArgumentLoc( case TemplateArgument::TemplateExpansion: if (ArgLoc.getTemplateQualifierLoc()) TRY_TO(getDerived().TraverseNestedNameSpecifierLoc( - ArgLoc.getTemplateQualifierLoc())); + ArgLoc.getTemplateQualifierLoc())); return getDerived().TraverseTemplateName( - Arg.getAsTemplateOrTemplatePattern()); + Arg.getAsTemplateOrTemplatePattern()); case TemplateArgument::Expression: return getDerived().TraverseStmt(ArgLoc.getSourceExpression()); @@ -765,10 +753,9 @@ bool RecursiveASTVisitor::TraverseTemplateArgumentLoc( return true; } -template +template bool RecursiveASTVisitor::TraverseTemplateArguments( - const TemplateArgument *Args, - unsigned NumArgs) { + const TemplateArgument *Args, unsigned NumArgs) { for (unsigned I = 0; I != NumArgs; ++I) { TRY_TO(TraverseTemplateArgument(Args[I])); } @@ -776,9 +763,9 @@ bool RecursiveASTVisitor::TraverseTemplateArguments( return true; } -template +template bool RecursiveASTVisitor::TraverseConstructorInitializer( - CXXCtorInitializer *Init) { + CXXCtorInitializer *Init) { if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); @@ -795,81 +782,64 @@ bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaCapture C) { // ----------------- Type traversal ----------------- // This macro makes available a variable T, the passed-in type. -#define DEF_TRAVERSE_TYPE(TYPE, CODE) \ - template \ - bool RecursiveASTVisitor::Traverse##TYPE (TYPE *T) { \ - TRY_TO(WalkUpFrom##TYPE (T)); \ - { CODE; } \ - return true; \ +#define DEF_TRAVERSE_TYPE(TYPE, CODE) \ + template \ + bool RecursiveASTVisitor::Traverse##TYPE(TYPE *T) { \ + TRY_TO(WalkUpFrom##TYPE(T)); \ + { CODE; } \ + return true; \ } -DEF_TRAVERSE_TYPE(BuiltinType, { }) +DEF_TRAVERSE_TYPE(BuiltinType, {}) -DEF_TRAVERSE_TYPE(ComplexType, { - TRY_TO(TraverseType(T->getElementType())); - }) +DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); }) -DEF_TRAVERSE_TYPE(PointerType, { - TRY_TO(TraverseType(T->getPointeeType())); - }) +DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); }) -DEF_TRAVERSE_TYPE(BlockPointerType, { - TRY_TO(TraverseType(T->getPointeeType())); - }) +DEF_TRAVERSE_TYPE(BlockPointerType, + { TRY_TO(TraverseType(T->getPointeeType())); }) -DEF_TRAVERSE_TYPE(LValueReferenceType, { - TRY_TO(TraverseType(T->getPointeeType())); - }) +DEF_TRAVERSE_TYPE(LValueReferenceType, + { TRY_TO(TraverseType(T->getPointeeType())); }) -DEF_TRAVERSE_TYPE(RValueReferenceType, { - TRY_TO(TraverseType(T->getPointeeType())); - }) +DEF_TRAVERSE_TYPE(RValueReferenceType, + { TRY_TO(TraverseType(T->getPointeeType())); }) DEF_TRAVERSE_TYPE(MemberPointerType, { - TRY_TO(TraverseType(QualType(T->getClass(), 0))); - TRY_TO(TraverseType(T->getPointeeType())); - }) + TRY_TO(TraverseType(QualType(T->getClass(), 0))); + TRY_TO(TraverseType(T->getPointeeType())); +}) -DEF_TRAVERSE_TYPE(DecayedType, { - TRY_TO(TraverseType(T->getOriginalType())); - }) +DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); }) -DEF_TRAVERSE_TYPE(AdjustedType, { - TRY_TO(TraverseType(T->getOriginalType())); - }) +DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); }) -DEF_TRAVERSE_TYPE(ConstantArrayType, { - TRY_TO(TraverseType(T->getElementType())); - }) +DEF_TRAVERSE_TYPE(ConstantArrayType, + { TRY_TO(TraverseType(T->getElementType())); }) -DEF_TRAVERSE_TYPE(IncompleteArrayType, { - TRY_TO(TraverseType(T->getElementType())); - }) +DEF_TRAVERSE_TYPE(IncompleteArrayType, + { TRY_TO(TraverseType(T->getElementType())); }) DEF_TRAVERSE_TYPE(VariableArrayType, { - TRY_TO(TraverseType(T->getElementType())); - TRY_TO(TraverseStmt(T->getSizeExpr())); - }) + TRY_TO(TraverseType(T->getElementType())); + TRY_TO(TraverseStmt(T->getSizeExpr())); +}) DEF_TRAVERSE_TYPE(DependentSizedArrayType, { - TRY_TO(TraverseType(T->getElementType())); - if (T->getSizeExpr()) - TRY_TO(TraverseStmt(T->getSizeExpr())); - }) + TRY_TO(TraverseType(T->getElementType())); + if (T->getSizeExpr()) + TRY_TO(TraverseStmt(T->getSizeExpr())); +}) DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, { - if (T->getSizeExpr()) - TRY_TO(TraverseStmt(T->getSizeExpr())); - TRY_TO(TraverseType(T->getElementType())); - }) + if (T->getSizeExpr()) + TRY_TO(TraverseStmt(T->getSizeExpr())); + TRY_TO(TraverseType(T->getElementType())); +}) -DEF_TRAVERSE_TYPE(VectorType, { - TRY_TO(TraverseType(T->getElementType())); - }) +DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); }) -DEF_TRAVERSE_TYPE(ExtVectorType, { - TRY_TO(TraverseType(T->getElementType())); - }) +DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); }) DEF_TRAVERSE_TYPE(FunctionNoProtoType, { TRY_TO(TraverseType(T->getReturnType())); }) @@ -886,87 +856,72 @@ DEF_TRAVERSE_TYPE(FunctionProtoType, { } }) -DEF_TRAVERSE_TYPE(UnresolvedUsingType, { }) -DEF_TRAVERSE_TYPE(TypedefType, { }) +DEF_TRAVERSE_TYPE(UnresolvedUsingType, {}) +DEF_TRAVERSE_TYPE(TypedefType, {}) -DEF_TRAVERSE_TYPE(TypeOfExprType, { - TRY_TO(TraverseStmt(T->getUnderlyingExpr())); - }) +DEF_TRAVERSE_TYPE(TypeOfExprType, + { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); }) -DEF_TRAVERSE_TYPE(TypeOfType, { - TRY_TO(TraverseType(T->getUnderlyingType())); - }) +DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); }) -DEF_TRAVERSE_TYPE(DecltypeType, { - TRY_TO(TraverseStmt(T->getUnderlyingExpr())); - }) +DEF_TRAVERSE_TYPE(DecltypeType, + { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); }) DEF_TRAVERSE_TYPE(UnaryTransformType, { - TRY_TO(TraverseType(T->getBaseType())); - TRY_TO(TraverseType(T->getUnderlyingType())); - }) + TRY_TO(TraverseType(T->getBaseType())); + TRY_TO(TraverseType(T->getUnderlyingType())); +}) -DEF_TRAVERSE_TYPE(AutoType, { - TRY_TO(TraverseType(T->getDeducedType())); - }) +DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); }) -DEF_TRAVERSE_TYPE(RecordType, { }) -DEF_TRAVERSE_TYPE(EnumType, { }) -DEF_TRAVERSE_TYPE(TemplateTypeParmType, { }) -DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { }) -DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, { }) +DEF_TRAVERSE_TYPE(RecordType, {}) +DEF_TRAVERSE_TYPE(EnumType, {}) +DEF_TRAVERSE_TYPE(TemplateTypeParmType, {}) +DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {}) +DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {}) DEF_TRAVERSE_TYPE(TemplateSpecializationType, { - TRY_TO(TraverseTemplateName(T->getTemplateName())); - TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs())); - }) + TRY_TO(TraverseTemplateName(T->getTemplateName())); + TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs())); +}) -DEF_TRAVERSE_TYPE(InjectedClassNameType, { }) +DEF_TRAVERSE_TYPE(InjectedClassNameType, {}) -DEF_TRAVERSE_TYPE(AttributedType, { - TRY_TO(TraverseType(T->getModifiedType())); - }) +DEF_TRAVERSE_TYPE(AttributedType, + { TRY_TO(TraverseType(T->getModifiedType())); }) -DEF_TRAVERSE_TYPE(ParenType, { - TRY_TO(TraverseType(T->getInnerType())); - }) +DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); }) DEF_TRAVERSE_TYPE(ElaboratedType, { - if (T->getQualifier()) { - TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); - } - TRY_TO(TraverseType(T->getNamedType())); - }) - -DEF_TRAVERSE_TYPE(DependentNameType, { + if (T->getQualifier()) { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); - }) + } + TRY_TO(TraverseType(T->getNamedType())); +}) + +DEF_TRAVERSE_TYPE(DependentNameType, + { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); }) DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, { - TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); - TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs())); - }) + TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); + TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs())); +}) -DEF_TRAVERSE_TYPE(PackExpansionType, { - TRY_TO(TraverseType(T->getPattern())); - }) +DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); }) -DEF_TRAVERSE_TYPE(ObjCInterfaceType, { }) +DEF_TRAVERSE_TYPE(ObjCInterfaceType, {}) DEF_TRAVERSE_TYPE(ObjCObjectType, { - // We have to watch out here because an ObjCInterfaceType's base - // type is itself. - if (T->getBaseType().getTypePtr() != T) - TRY_TO(TraverseType(T->getBaseType())); - }) + // We have to watch out here because an ObjCInterfaceType's base + // type is itself. + if (T->getBaseType().getTypePtr() != T) + TRY_TO(TraverseType(T->getBaseType())); +}) -DEF_TRAVERSE_TYPE(ObjCObjectPointerType, { - TRY_TO(TraverseType(T->getPointeeType())); - }) +DEF_TRAVERSE_TYPE(ObjCObjectPointerType, + { TRY_TO(TraverseType(T->getPointeeType())); }) -DEF_TRAVERSE_TYPE(AtomicType, { - TRY_TO(TraverseType(T->getValueType())); - }) +DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); }) #undef DEF_TRAVERSE_TYPE @@ -977,19 +932,19 @@ DEF_TRAVERSE_TYPE(AtomicType, { // in addition to WalkUpFrom* for the TypeLoc itself, such that existing // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods // continue to work. -#define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \ - template \ - bool RecursiveASTVisitor::Traverse##TYPE##Loc(TYPE##Loc TL) { \ - if (getDerived().shouldWalkTypesOfTypeLocs()) \ - TRY_TO(WalkUpFrom##TYPE(const_cast(TL.getTypePtr()))); \ - TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ - { CODE; } \ - return true; \ +#define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \ + template \ + bool RecursiveASTVisitor::Traverse##TYPE##Loc(TYPE##Loc TL) { \ + if (getDerived().shouldWalkTypesOfTypeLocs()) \ + TRY_TO(WalkUpFrom##TYPE(const_cast(TL.getTypePtr()))); \ + TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ + { CODE; } \ + return true; \ } -template -bool RecursiveASTVisitor::TraverseQualifiedTypeLoc( - QualifiedTypeLoc TL) { +template +bool +RecursiveASTVisitor::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) { // Move this over to the 'main' typeloc tree. Note that this is a // move -- we pretend that we were really looking at the unqualified // typeloc all along -- rather than a recursion, so we don't follow @@ -1008,46 +963,40 @@ bool RecursiveASTVisitor::TraverseQualifiedTypeLoc( return TraverseTypeLoc(TL.getUnqualifiedLoc()); } -DEF_TRAVERSE_TYPELOC(BuiltinType, { }) +DEF_TRAVERSE_TYPELOC(BuiltinType, {}) // FIXME: ComplexTypeLoc is unfinished DEF_TRAVERSE_TYPELOC(ComplexType, { - TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); - }) + TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); +}) -DEF_TRAVERSE_TYPELOC(PointerType, { - TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); - }) +DEF_TRAVERSE_TYPELOC(PointerType, + { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) -DEF_TRAVERSE_TYPELOC(BlockPointerType, { - TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); - }) +DEF_TRAVERSE_TYPELOC(BlockPointerType, + { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) -DEF_TRAVERSE_TYPELOC(LValueReferenceType, { - TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); - }) +DEF_TRAVERSE_TYPELOC(LValueReferenceType, + { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) -DEF_TRAVERSE_TYPELOC(RValueReferenceType, { - TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); - }) +DEF_TRAVERSE_TYPELOC(RValueReferenceType, + { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) // FIXME: location of base class? // We traverse this in the type case as well, but how is it not reached through // the pointee type? DEF_TRAVERSE_TYPELOC(MemberPointerType, { - TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0))); - TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); - }) + TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0))); + TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); +}) -DEF_TRAVERSE_TYPELOC(DecayedType, { - TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); - }) +DEF_TRAVERSE_TYPELOC(DecayedType, + { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); }) -DEF_TRAVERSE_TYPELOC(AdjustedType, { - TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); - }) +DEF_TRAVERSE_TYPELOC(AdjustedType, + { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); }) -template +template bool RecursiveASTVisitor::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { // This isn't available for ArrayType, but is for the ArrayTypeLoc. TRY_TO(TraverseStmt(TL.getSizeExpr())); @@ -1055,156 +1004,147 @@ bool RecursiveASTVisitor::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { } DEF_TRAVERSE_TYPELOC(ConstantArrayType, { - TRY_TO(TraverseTypeLoc(TL.getElementLoc())); - return TraverseArrayTypeLocHelper(TL); - }) + TRY_TO(TraverseTypeLoc(TL.getElementLoc())); + return TraverseArrayTypeLocHelper(TL); +}) DEF_TRAVERSE_TYPELOC(IncompleteArrayType, { - TRY_TO(TraverseTypeLoc(TL.getElementLoc())); - return TraverseArrayTypeLocHelper(TL); - }) + TRY_TO(TraverseTypeLoc(TL.getElementLoc())); + return TraverseArrayTypeLocHelper(TL); +}) DEF_TRAVERSE_TYPELOC(VariableArrayType, { - TRY_TO(TraverseTypeLoc(TL.getElementLoc())); - return TraverseArrayTypeLocHelper(TL); - }) + TRY_TO(TraverseTypeLoc(TL.getElementLoc())); + return TraverseArrayTypeLocHelper(TL); +}) DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, { - TRY_TO(TraverseTypeLoc(TL.getElementLoc())); - return TraverseArrayTypeLocHelper(TL); - }) + TRY_TO(TraverseTypeLoc(TL.getElementLoc())); + return TraverseArrayTypeLocHelper(TL); +}) // FIXME: order? why not size expr first? // FIXME: base VectorTypeLoc is unfinished DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, { - if (TL.getTypePtr()->getSizeExpr()) - TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr())); - TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); - }) + if (TL.getTypePtr()->getSizeExpr()) + TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr())); + TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); +}) // FIXME: VectorTypeLoc is unfinished DEF_TRAVERSE_TYPELOC(VectorType, { - TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); - }) + TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); +}) // FIXME: size and attributes // FIXME: base VectorTypeLoc is unfinished DEF_TRAVERSE_TYPELOC(ExtVectorType, { - TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); - }) + TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); +}) -DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, { - TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); - }) +DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, + { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); }) // FIXME: location of exception specifications (attributes?) DEF_TRAVERSE_TYPELOC(FunctionProtoType, { - TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); + TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); - const FunctionProtoType *T = TL.getTypePtr(); + const FunctionProtoType *T = TL.getTypePtr(); - for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) { - if (TL.getParam(I)) { - TRY_TO(TraverseDecl(TL.getParam(I))); - } else if (I < T->getNumParams()) { - TRY_TO(TraverseType(T->getParamType(I))); - } + for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) { + if (TL.getParam(I)) { + TRY_TO(TraverseDecl(TL.getParam(I))); + } else if (I < T->getNumParams()) { + TRY_TO(TraverseType(T->getParamType(I))); } + } - for (const auto &E : T->exceptions()) { - TRY_TO(TraverseType(E)); - } - }) + for (const auto &E : T->exceptions()) { + TRY_TO(TraverseType(E)); + } +}) -DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, { }) -DEF_TRAVERSE_TYPELOC(TypedefType, { }) +DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {}) +DEF_TRAVERSE_TYPELOC(TypedefType, {}) -DEF_TRAVERSE_TYPELOC(TypeOfExprType, { - TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); - }) +DEF_TRAVERSE_TYPELOC(TypeOfExprType, + { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); }) DEF_TRAVERSE_TYPELOC(TypeOfType, { - TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); - }) + TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); +}) // FIXME: location of underlying expr DEF_TRAVERSE_TYPELOC(DecltypeType, { - TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr())); - }) + TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr())); +}) DEF_TRAVERSE_TYPELOC(UnaryTransformType, { - TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); - }) + TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); +}) DEF_TRAVERSE_TYPELOC(AutoType, { - TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType())); - }) + TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType())); +}) -DEF_TRAVERSE_TYPELOC(RecordType, { }) -DEF_TRAVERSE_TYPELOC(EnumType, { }) -DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, { }) -DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { }) -DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, { }) +DEF_TRAVERSE_TYPELOC(RecordType, {}) +DEF_TRAVERSE_TYPELOC(EnumType, {}) +DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {}) +DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {}) +DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {}) // FIXME: use the loc for the template name? DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, { - TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName())); - for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { - TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); - } - }) + TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName())); + for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { + TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); + } +}) -DEF_TRAVERSE_TYPELOC(InjectedClassNameType, { }) +DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {}) -DEF_TRAVERSE_TYPELOC(ParenType, { - TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); - }) +DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); }) -DEF_TRAVERSE_TYPELOC(AttributedType, { - TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); - }) +DEF_TRAVERSE_TYPELOC(AttributedType, + { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); }) DEF_TRAVERSE_TYPELOC(ElaboratedType, { - if (TL.getQualifierLoc()) { - TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); - } - TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc())); - }) + if (TL.getQualifierLoc()) { + TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); + } + TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc())); +}) DEF_TRAVERSE_TYPELOC(DependentNameType, { - TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); - }) + TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); +}) DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, { - if (TL.getQualifierLoc()) { - TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); - } + if (TL.getQualifierLoc()) { + TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); + } - for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { - TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); - } - }) + for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { + TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); + } +}) -DEF_TRAVERSE_TYPELOC(PackExpansionType, { - TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); - }) +DEF_TRAVERSE_TYPELOC(PackExpansionType, + { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); }) -DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, { }) +DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {}) DEF_TRAVERSE_TYPELOC(ObjCObjectType, { - // We have to watch out here because an ObjCInterfaceType's base - // type is itself. - if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr()) - TRY_TO(TraverseTypeLoc(TL.getBaseLoc())); - }) + // We have to watch out here because an ObjCInterfaceType's base + // type is itself. + if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr()) + TRY_TO(TraverseTypeLoc(TL.getBaseLoc())); +}) -DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, { - TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); - }) +DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, + { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) -DEF_TRAVERSE_TYPELOC(AtomicType, { - TRY_TO(TraverseTypeLoc(TL.getValueLoc())); - }) +DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); }) #undef DEF_TRAVERSE_TYPELOC @@ -1215,7 +1155,7 @@ DEF_TRAVERSE_TYPELOC(AtomicType, { // Therefore each Traverse* only needs to worry about children other // than those. -template +template bool RecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { if (!DC) return true; @@ -1231,131 +1171,121 @@ bool RecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { } // This macro makes available a variable D, the passed-in decl. -#define DEF_TRAVERSE_DECL(DECL, CODE) \ -template \ -bool RecursiveASTVisitor::Traverse##DECL (DECL *D) { \ - TRY_TO(WalkUpFrom##DECL (D)); \ - { CODE; } \ - TRY_TO(TraverseDeclContextHelper(dyn_cast(D))); \ - return true; \ -} +#define DEF_TRAVERSE_DECL(DECL, CODE) \ + template \ + bool RecursiveASTVisitor::Traverse##DECL(DECL *D) { \ + TRY_TO(WalkUpFrom##DECL(D)); \ + { CODE; } \ + TRY_TO(TraverseDeclContextHelper(dyn_cast(D))); \ + return true; \ + } -DEF_TRAVERSE_DECL(AccessSpecDecl, { }) +DEF_TRAVERSE_DECL(AccessSpecDecl, {}) DEF_TRAVERSE_DECL(BlockDecl, { - if (TypeSourceInfo *TInfo = D->getSignatureAsWritten()) - TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); - TRY_TO(TraverseStmt(D->getBody())); - // This return statement makes sure the traversal of nodes in - // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) - // is skipped - don't remove it. - return true; - }) + if (TypeSourceInfo *TInfo = D->getSignatureAsWritten()) + TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); + TRY_TO(TraverseStmt(D->getBody())); + // This return statement makes sure the traversal of nodes in + // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) + // is skipped - don't remove it. + return true; +}) DEF_TRAVERSE_DECL(CapturedDecl, { - TRY_TO(TraverseStmt(D->getBody())); - // This return statement makes sure the traversal of nodes in - // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) - // is skipped - don't remove it. - return true; - }) + TRY_TO(TraverseStmt(D->getBody())); + // This return statement makes sure the traversal of nodes in + // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) + // is skipped - don't remove it. + return true; +}) -DEF_TRAVERSE_DECL(EmptyDecl, { }) +DEF_TRAVERSE_DECL(EmptyDecl, {}) -DEF_TRAVERSE_DECL(FileScopeAsmDecl, { - TRY_TO(TraverseStmt(D->getAsmString())); - }) +DEF_TRAVERSE_DECL(FileScopeAsmDecl, + { TRY_TO(TraverseStmt(D->getAsmString())); }) -DEF_TRAVERSE_DECL(ImportDecl, { }) +DEF_TRAVERSE_DECL(ImportDecl, {}) DEF_TRAVERSE_DECL(FriendDecl, { - // Friend is either decl or a type. - if (D->getFriendType()) - TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); - else - TRY_TO(TraverseDecl(D->getFriendDecl())); - }) + // Friend is either decl or a type. + if (D->getFriendType()) + TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); + else + TRY_TO(TraverseDecl(D->getFriendDecl())); +}) DEF_TRAVERSE_DECL(FriendTemplateDecl, { - if (D->getFriendType()) - TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); - else - TRY_TO(TraverseDecl(D->getFriendDecl())); - for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) { - TemplateParameterList *TPL = D->getTemplateParameterList(I); - for (TemplateParameterList::iterator ITPL = TPL->begin(), - ETPL = TPL->end(); - ITPL != ETPL; ++ITPL) { - TRY_TO(TraverseDecl(*ITPL)); - } + if (D->getFriendType()) + TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); + else + TRY_TO(TraverseDecl(D->getFriendDecl())); + for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) { + TemplateParameterList *TPL = D->getTemplateParameterList(I); + for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end(); + ITPL != ETPL; ++ITPL) { + TRY_TO(TraverseDecl(*ITPL)); } - }) + } +}) -DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, { - TRY_TO(TraverseDecl(D->getSpecialization())); - }) +DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, + { TRY_TO(TraverseDecl(D->getSpecialization())); }) -DEF_TRAVERSE_DECL(LinkageSpecDecl, { }) +DEF_TRAVERSE_DECL(LinkageSpecDecl, {}) -DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, { - // FIXME: implement this - }) +DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this + }) DEF_TRAVERSE_DECL(StaticAssertDecl, { - TRY_TO(TraverseStmt(D->getAssertExpr())); - TRY_TO(TraverseStmt(D->getMessage())); - }) + TRY_TO(TraverseStmt(D->getAssertExpr())); + TRY_TO(TraverseStmt(D->getMessage())); +}) -DEF_TRAVERSE_DECL(TranslationUnitDecl, { - // Code in an unnamed namespace shows up automatically in - // decls_begin()/decls_end(). Thus we don't need to recurse on - // D->getAnonymousNamespace(). - }) +DEF_TRAVERSE_DECL( + TranslationUnitDecl, + {// Code in an unnamed namespace shows up automatically in + // decls_begin()/decls_end(). Thus we don't need to recurse on + // D->getAnonymousNamespace(). + }) DEF_TRAVERSE_DECL(NamespaceAliasDecl, { - // We shouldn't traverse an aliased namespace, since it will be - // defined (and, therefore, traversed) somewhere else. - // - // This return statement makes sure the traversal of nodes in - // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) - // is skipped - don't remove it. - return true; - }) - -DEF_TRAVERSE_DECL(LabelDecl, { - // There is no code in a LabelDecl. + // We shouldn't traverse an aliased namespace, since it will be + // defined (and, therefore, traversed) somewhere else. + // + // This return statement makes sure the traversal of nodes in + // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) + // is skipped - don't remove it. + return true; }) +DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl. + }) -DEF_TRAVERSE_DECL(NamespaceDecl, { - // Code in an unnamed namespace shows up automatically in - // decls_begin()/decls_end(). Thus we don't need to recurse on - // D->getAnonymousNamespace(). - }) +DEF_TRAVERSE_DECL( + NamespaceDecl, + {// Code in an unnamed namespace shows up automatically in + // decls_begin()/decls_end(). Thus we don't need to recurse on + // D->getAnonymousNamespace(). + }) -DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement + }) -DEF_TRAVERSE_DECL(ObjCCategoryDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement + }) -DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement + }) -DEF_TRAVERSE_DECL(ObjCImplementationDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement + }) -DEF_TRAVERSE_DECL(ObjCInterfaceDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement + }) -DEF_TRAVERSE_DECL(ObjCProtocolDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement + }) DEF_TRAVERSE_DECL(ObjCMethodDecl, { if (D->getReturnTypeSourceInfo()) { @@ -1371,29 +1301,28 @@ DEF_TRAVERSE_DECL(ObjCMethodDecl, { return true; }) -DEF_TRAVERSE_DECL(ObjCPropertyDecl, { - // FIXME: implement - }) +DEF_TRAVERSE_DECL(ObjCPropertyDecl, {// FIXME: implement + }) DEF_TRAVERSE_DECL(UsingDecl, { - TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); - TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); - }) + TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); + TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); +}) DEF_TRAVERSE_DECL(UsingDirectiveDecl, { - TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); - }) + TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); +}) -DEF_TRAVERSE_DECL(UsingShadowDecl, { }) +DEF_TRAVERSE_DECL(UsingShadowDecl, {}) DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, { - for (auto *I : D->varlists()) { - TRY_TO(TraverseStmt(I)); - } - }) + for (auto *I : D->varlists()) { + TRY_TO(TraverseStmt(I)); + } +}) // A helper method for TemplateDecl's children. -template +template bool RecursiveASTVisitor::TraverseTemplateParameterListHelper( TemplateParameterList *TPL) { if (TPL) { @@ -1407,7 +1336,7 @@ bool RecursiveASTVisitor::TraverseTemplateParameterListHelper( // A helper method for traversing the implicit instantiations of a // class template. -template +template bool RecursiveASTVisitor::TraverseClassInstantiations( ClassTemplateDecl *D) { for (auto *SD : D->specializations()) { @@ -1416,8 +1345,8 @@ bool RecursiveASTVisitor::TraverseClassInstantiations( if (cast(RD)->isInjectedClassName()) continue; - switch (cast(RD)-> - getSpecializationKind()) { + switch ( + cast(RD)->getSpecializationKind()) { // Visit the implicit instantiations with the requested pattern. case TSK_Undeclared: case TSK_ImplicitInstantiation: @@ -1439,24 +1368,24 @@ bool RecursiveASTVisitor::TraverseClassInstantiations( } DEF_TRAVERSE_DECL(ClassTemplateDecl, { - CXXRecordDecl* TempDecl = D->getTemplatedDecl(); - TRY_TO(TraverseDecl(TempDecl)); - TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); - - // By default, we do not traverse the instantiations of - // class templates since they do not appear in the user code. The - // following code optionally traverses them. - // - // We only traverse the class instantiations when we see the canonical - // declaration of the template, to ensure we only visit them once. - if (getDerived().shouldVisitTemplateInstantiations() && - D == D->getCanonicalDecl()) - TRY_TO(TraverseClassInstantiations(D)); - - // Note that getInstantiatedFromMemberTemplate() is just a link - // from a template instantiation back to the template from which - // it was instantiated, and thus should not be traversed. - }) + CXXRecordDecl *TempDecl = D->getTemplatedDecl(); + TRY_TO(TraverseDecl(TempDecl)); + TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); + + // By default, we do not traverse the instantiations of + // class templates since they do not appear in the user code. The + // following code optionally traverses them. + // + // We only traverse the class instantiations when we see the canonical + // declaration of the template, to ensure we only visit them once. + if (getDerived().shouldVisitTemplateInstantiations() && + D == D->getCanonicalDecl()) + TRY_TO(TraverseClassInstantiations(D)); + + // Note that getInstantiatedFromMemberTemplate() is just a link + // from a template instantiation back to the template from which + // it was instantiated, and thus should not be traversed. +}) // A helper method for traversing the implicit instantiations of a // class template. @@ -1465,8 +1394,8 @@ bool RecursiveASTVisitor::TraverseVariableInstantiations( VarTemplateDecl *D) { for (auto *SD : D->specializations()) { for (auto *RD : SD->redecls()) { - switch (cast(RD)-> - getSpecializationKind()) { + switch ( + cast(RD)->getSpecializationKind()) { // Visit the implicit instantiations with the requested pattern. case TSK_Undeclared: case TSK_ImplicitInstantiation: @@ -1487,9 +1416,7 @@ bool RecursiveASTVisitor::TraverseVariableInstantiations( return true; } -DEF_TRAVERSE_DECL( - VarTemplateDecl, - { +DEF_TRAVERSE_DECL(VarTemplateDecl, { VarDecl *TempDecl = D->getTemplatedDecl(); TRY_TO(TraverseDecl(TempDecl)); TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); @@ -1504,14 +1431,14 @@ DEF_TRAVERSE_DECL( D == D->getCanonicalDecl()) TRY_TO(TraverseVariableInstantiations(D)); - // Note that getInstantiatedFromMemberTemplate() is just a link - // from a template instantiation back to the template from which - // it was instantiated, and thus should not be traversed. + // Note that getInstantiatedFromMemberTemplate() is just a link + // from a template instantiation back to the template from which + // it was instantiated, and thus should not be traversed. }) // A helper method for traversing the instantiations of a // function while skipping its specializations. -template +template bool RecursiveASTVisitor::TraverseFunctionInstantiations( FunctionTemplateDecl *D) { for (auto *FD : D->specializations()) { @@ -1541,80 +1468,78 @@ bool RecursiveASTVisitor::TraverseFunctionInstantiations( } DEF_TRAVERSE_DECL(FunctionTemplateDecl, { - TRY_TO(TraverseDecl(D->getTemplatedDecl())); - TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); - - // By default, we do not traverse the instantiations of - // function templates since they do not appear in the user code. The - // following code optionally traverses them. - // - // We only traverse the function instantiations when we see the canonical - // declaration of the template, to ensure we only visit them once. - if (getDerived().shouldVisitTemplateInstantiations() && - D == D->getCanonicalDecl()) - TRY_TO(TraverseFunctionInstantiations(D)); - }) + TRY_TO(TraverseDecl(D->getTemplatedDecl())); + TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); + + // By default, we do not traverse the instantiations of + // function templates since they do not appear in the user code. The + // following code optionally traverses them. + // + // We only traverse the function instantiations when we see the canonical + // declaration of the template, to ensure we only visit them once. + if (getDerived().shouldVisitTemplateInstantiations() && + D == D->getCanonicalDecl()) + TRY_TO(TraverseFunctionInstantiations(D)); +}) DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, { - // D is the "T" in something like - // template