]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/EvaluatedExprVisitor.h
Update dialog to version 1.1-20110302.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / EvaluatedExprVisitor.h
1 //===--- EvaluatedExprVisitor.h - Evaluated expression visitor --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the EvaluatedExprVisitor class template, which visits
11 //  the potentially-evaluated subexpressions of a potentially-evaluated
12 //  expression.
13 //
14 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_EVALUATEDEXPRVISITOR_H
16 #define LLVM_CLANG_AST_EVALUATEDEXPRVISITOR_H
17
18 #include "clang/AST/StmtVisitor.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.h"
22
23 namespace clang {
24   
25 class ASTContext;
26   
27 /// \begin Given a potentially-evaluated expression, this visitor visits all
28 /// of its potentially-evaluated subexpressions, recursively.
29 template<typename ImplClass>
30 class EvaluatedExprVisitor : public StmtVisitor<ImplClass> {
31   ASTContext &Context;
32   
33 public:
34   explicit EvaluatedExprVisitor(ASTContext &Context) : Context(Context) { }
35   
36   // Expressions that have no potentially-evaluated subexpressions (but may have
37   // other sub-expressions).
38   void VisitDeclRefExpr(DeclRefExpr *E) { }
39   void VisitOffsetOfExpr(OffsetOfExpr *E) { }
40   void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { }
41   void VisitBlockExpr(BlockExpr *E) { }
42   void VisitCXXUuidofExpr(CXXUuidofExpr *E) { }  
43   void VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { }
44   
45   void VisitMemberExpr(MemberExpr *E) {
46     // Only the base matters.
47     return this->Visit(E->getBase());
48   }
49   
50   void VisitChooseExpr(ChooseExpr *E) {
51     // Only the selected subexpression matters; the other one is not evaluated.
52     return this->Visit(E->getChosenSubExpr(Context));
53   }
54                  
55   void VisitDesignatedInitExpr(DesignatedInitExpr *E) {
56     // Only the actual initializer matters; the designators are all constant
57     // expressions.
58     return this->Visit(E->getInit());
59   }
60   
61   void VisitCXXTypeidExpr(CXXTypeidExpr *E) {
62     // typeid(expression) is potentially evaluated when the argument is
63     // a glvalue of polymorphic type. (C++ 5.2.8p2-3)
64     if (!E->isTypeOperand() && E->Classify(Context).isGLValue())
65       if (const RecordType *Record 
66                  = E->getExprOperand()->getType()->template getAs<RecordType>())
67         if (cast<CXXRecordDecl>(Record->getDecl())->isPolymorphic())
68           return this->Visit(E->getExprOperand());
69   }
70   
71   /// \brief The basis case walks all of the children of the statement or
72   /// expression, assuming they are all potentially evaluated.
73   void VisitStmt(Stmt *S) {
74     for (Stmt::child_range C = S->children(); C; ++C)
75       if (*C)
76         this->Visit(*C);
77   }
78 };
79
80 }
81
82 #endif // LLVM_CLANG_AST_EVALUATEDEXPRVISITOR_H