1 //===--- ParentMap.h - Mappings from Stmts to their Parents -----*- 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 ParentMap class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_PARENTMAP_H 15 #define LLVM_CLANG_PARENTMAP_H 16 17 namespace clang { 18 class Stmt; 19 class Expr; 20 21 class ParentMap { 22 void* Impl; 23 public: 24 ParentMap(Stmt* ASTRoot); 25 ~ParentMap(); 26 27 /// \brief Adds and/or updates the parent/child-relations of the complete 28 /// stmt tree of S. All children of S including indirect descendants are 29 /// visited and updated or inserted but not the parents of S. 30 void addStmt(Stmt* S); 31 32 Stmt *getParent(Stmt*) const; 33 Stmt *getParentIgnoreParens(Stmt *) const; 34 Stmt *getParentIgnoreParenCasts(Stmt *) const; 35 Stmt *getParentIgnoreParenImpCasts(Stmt *) const; 36 Stmt *getOuterParenParent(Stmt *) const; 37 getParent(const Stmt * S)38 const Stmt *getParent(const Stmt* S) const { 39 return getParent(const_cast<Stmt*>(S)); 40 } 41 getParentIgnoreParens(const Stmt * S)42 const Stmt *getParentIgnoreParens(const Stmt *S) const { 43 return getParentIgnoreParens(const_cast<Stmt*>(S)); 44 } 45 getParentIgnoreParenCasts(const Stmt * S)46 const Stmt *getParentIgnoreParenCasts(const Stmt *S) const { 47 return getParentIgnoreParenCasts(const_cast<Stmt*>(S)); 48 } 49 hasParent(Stmt * S)50 bool hasParent(Stmt* S) const { 51 return getParent(S) != 0; 52 } 53 54 bool isConsumedExpr(Expr *E) const; 55 isConsumedExpr(const Expr * E)56 bool isConsumedExpr(const Expr *E) const { 57 return isConsumedExpr(const_cast<Expr*>(E)); 58 } 59 }; 60 61 } // end clang namespace 62 #endif 63