clang API Documentation
00001 //===--- EvaluatedExprVisitor.h - Evaluated expression visitor --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the EvaluatedExprVisitor class template, which visits 00011 // the potentially-evaluated subexpressions of a potentially-evaluated 00012 // expression. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 #ifndef LLVM_CLANG_AST_EVALUATEDEXPRVISITOR_H 00016 #define LLVM_CLANG_AST_EVALUATEDEXPRVISITOR_H 00017 00018 #include "clang/AST/DeclCXX.h" 00019 #include "clang/AST/Expr.h" 00020 #include "clang/AST/ExprCXX.h" 00021 #include "clang/AST/StmtVisitor.h" 00022 00023 namespace clang { 00024 00025 class ASTContext; 00026 00027 /// \brief Given a potentially-evaluated expression, this visitor visits all 00028 /// of its potentially-evaluated subexpressions, recursively. 00029 template<typename ImplClass> 00030 class EvaluatedExprVisitor : public StmtVisitor<ImplClass> { 00031 ASTContext &Context; 00032 00033 public: 00034 explicit EvaluatedExprVisitor(ASTContext &Context) : Context(Context) { } 00035 00036 // Expressions that have no potentially-evaluated subexpressions (but may have 00037 // other sub-expressions). 00038 void VisitDeclRefExpr(DeclRefExpr *E) { } 00039 void VisitOffsetOfExpr(OffsetOfExpr *E) { } 00040 void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { } 00041 void VisitExpressionTraitExpr(ExpressionTraitExpr *E) { } 00042 void VisitBlockExpr(BlockExpr *E) { } 00043 void VisitCXXUuidofExpr(CXXUuidofExpr *E) { } 00044 void VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { } 00045 00046 void VisitMemberExpr(MemberExpr *E) { 00047 // Only the base matters. 00048 return this->Visit(E->getBase()); 00049 } 00050 00051 void VisitChooseExpr(ChooseExpr *E) { 00052 // Don't visit either child expression if the condition is dependent. 00053 if (E->getCond()->isValueDependent()) 00054 return; 00055 // Only the selected subexpression matters; the other one is not evaluated. 00056 return this->Visit(E->getChosenSubExpr()); 00057 } 00058 00059 void VisitDesignatedInitExpr(DesignatedInitExpr *E) { 00060 // Only the actual initializer matters; the designators are all constant 00061 // expressions. 00062 return this->Visit(E->getInit()); 00063 } 00064 00065 void VisitCXXTypeidExpr(CXXTypeidExpr *E) { 00066 if (E->isPotentiallyEvaluated()) 00067 return this->Visit(E->getExprOperand()); 00068 } 00069 00070 void VisitCallExpr(CallExpr *CE) { 00071 if (!CE->isUnevaluatedBuiltinCall(Context)) 00072 return static_cast<ImplClass*>(this)->VisitExpr(CE); 00073 } 00074 00075 void VisitLambdaExpr(LambdaExpr *LE) { 00076 // Only visit the capture initializers, and not the body. 00077 for (LambdaExpr::capture_init_iterator I = LE->capture_init_begin(), 00078 E = LE->capture_init_end(); 00079 I != E; ++I) 00080 if (*I) 00081 this->Visit(*I); 00082 } 00083 00084 /// \brief The basis case walks all of the children of the statement or 00085 /// expression, assuming they are all potentially evaluated. 00086 void VisitStmt(Stmt *S) { 00087 for (Stmt::child_range C = S->children(); C; ++C) 00088 if (*C) 00089 this->Visit(*C); 00090 } 00091 }; 00092 00093 } 00094 00095 #endif // LLVM_CLANG_AST_EVALUATEDEXPRVISITOR_H