1193326Sed//===--- ParentMap.h - Mappings from Stmts to their Parents -----*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the ParentMap class. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_PARENTMAP_H 15193326Sed#define LLVM_CLANG_PARENTMAP_H 16193326Sed 17193326Sednamespace clang { 18193326Sedclass Stmt; 19193326Sedclass Expr; 20198092Srdivacky 21193326Sedclass ParentMap { 22193326Sed void* Impl; 23193326Sedpublic: 24193326Sed ParentMap(Stmt* ASTRoot); 25193326Sed ~ParentMap(); 26193326Sed 27218893Sdim /// \brief Adds and/or updates the parent/child-relations of the complete 28218893Sdim /// stmt tree of S. All children of S including indirect descendants are 29218893Sdim /// visited and updated or inserted but not the parents of S. 30218893Sdim void addStmt(Stmt* S); 31218893Sdim 32263509Sdim /// Manually sets the parent of \p S to \p Parent. 33263509Sdim /// 34263509Sdim /// If \p S is already in the map, this method will update the mapping. 35263509Sdim void setParent(const Stmt *S, const Stmt *Parent); 36263509Sdim 37193326Sed Stmt *getParent(Stmt*) const; 38193326Sed Stmt *getParentIgnoreParens(Stmt *) const; 39218893Sdim Stmt *getParentIgnoreParenCasts(Stmt *) const; 40226890Sdim Stmt *getParentIgnoreParenImpCasts(Stmt *) const; 41224145Sdim Stmt *getOuterParenParent(Stmt *) const; 42193326Sed 43193326Sed const Stmt *getParent(const Stmt* S) const { 44193326Sed return getParent(const_cast<Stmt*>(S)); 45193326Sed } 46198092Srdivacky 47193326Sed const Stmt *getParentIgnoreParens(const Stmt *S) const { 48193326Sed return getParentIgnoreParens(const_cast<Stmt*>(S)); 49193326Sed } 50193326Sed 51218893Sdim const Stmt *getParentIgnoreParenCasts(const Stmt *S) const { 52218893Sdim return getParentIgnoreParenCasts(const_cast<Stmt*>(S)); 53218893Sdim } 54218893Sdim 55193326Sed bool hasParent(Stmt* S) const { 56193326Sed return getParent(S) != 0; 57193326Sed } 58198092Srdivacky 59193326Sed bool isConsumedExpr(Expr *E) const; 60198092Srdivacky 61193326Sed bool isConsumedExpr(const Expr *E) const { 62193326Sed return isConsumedExpr(const_cast<Expr*>(E)); 63193326Sed } 64193326Sed}; 65198092Srdivacky 66193326Sed} // end clang namespace 67193326Sed#endif 68