clang API Documentation

ParentMap.h
Go to the documentation of this file.
00001 //===--- ParentMap.h - Mappings from Stmts to their Parents -----*- 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 ParentMap class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_PARENTMAP_H
00015 #define LLVM_CLANG_AST_PARENTMAP_H
00016 
00017 namespace clang {
00018 class Stmt;
00019 class Expr;
00020 
00021 class ParentMap {
00022   void* Impl;
00023 public:
00024   ParentMap(Stmt* ASTRoot);
00025   ~ParentMap();
00026 
00027   /// \brief Adds and/or updates the parent/child-relations of the complete
00028   /// stmt tree of S. All children of S including indirect descendants are
00029   /// visited and updated or inserted but not the parents of S.
00030   void addStmt(Stmt* S);
00031 
00032   /// Manually sets the parent of \p S to \p Parent.
00033   ///
00034   /// If \p S is already in the map, this method will update the mapping.
00035   void setParent(const Stmt *S, const Stmt *Parent);
00036 
00037   Stmt *getParent(Stmt*) const;
00038   Stmt *getParentIgnoreParens(Stmt *) const;
00039   Stmt *getParentIgnoreParenCasts(Stmt *) const;
00040   Stmt *getParentIgnoreParenImpCasts(Stmt *) const;
00041   Stmt *getOuterParenParent(Stmt *) const;
00042 
00043   const Stmt *getParent(const Stmt* S) const {
00044     return getParent(const_cast<Stmt*>(S));
00045   }
00046 
00047   const Stmt *getParentIgnoreParens(const Stmt *S) const {
00048     return getParentIgnoreParens(const_cast<Stmt*>(S));
00049   }
00050 
00051   const Stmt *getParentIgnoreParenCasts(const Stmt *S) const {
00052     return getParentIgnoreParenCasts(const_cast<Stmt*>(S));
00053   }
00054 
00055   bool hasParent(Stmt* S) const {
00056     return getParent(S) != nullptr;
00057   }
00058 
00059   bool isConsumedExpr(Expr *E) const;
00060 
00061   bool isConsumedExpr(const Expr *E) const {
00062     return isConsumedExpr(const_cast<Expr*>(E));
00063   }
00064 };
00065 
00066 } // end clang namespace
00067 #endif