clang  14.0.0git
ParentMap.h
Go to the documentation of this file.
1 //===--- ParentMap.h - Mappings from Stmts to their Parents -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ParentMap class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_PARENTMAP_H
14 #define LLVM_CLANG_AST_PARENTMAP_H
15 
16 namespace clang {
17 class Stmt;
18 class Expr;
19 
20 class ParentMap {
21  void* Impl;
22 public:
23  ParentMap(Stmt* ASTRoot);
24  ~ParentMap();
25 
26  /// Adds and/or updates the parent/child-relations of the complete
27  /// stmt tree of S. All children of S including indirect descendants are
28  /// visited and updated or inserted but not the parents of S.
29  void addStmt(Stmt* S);
30 
31  /// Manually sets the parent of \p S to \p Parent.
32  ///
33  /// If \p S is already in the map, this method will update the mapping.
34  void setParent(const Stmt *S, const Stmt *Parent);
35 
36  Stmt *getParent(Stmt*) const;
40  Stmt *getOuterParenParent(Stmt *) const;
41 
42  const Stmt *getParent(const Stmt* S) const {
43  return getParent(const_cast<Stmt*>(S));
44  }
45 
46  const Stmt *getParentIgnoreParens(const Stmt *S) const {
47  return getParentIgnoreParens(const_cast<Stmt*>(S));
48  }
49 
50  const Stmt *getParentIgnoreParenCasts(const Stmt *S) const {
51  return getParentIgnoreParenCasts(const_cast<Stmt*>(S));
52  }
53 
54  bool hasParent(const Stmt *S) const { return getParent(S) != nullptr; }
55 
56  bool isConsumedExpr(Expr *E) const;
57 
58  bool isConsumedExpr(const Expr *E) const {
59  return isConsumedExpr(const_cast<Expr*>(E));
60  }
61 };
62 
63 } // end clang namespace
64 #endif
clang::ParentMap::addStmt
void addStmt(Stmt *S)
Adds and/or updates the parent/child-relations of the complete stmt tree of S.
Definition: ParentMap.cpp:121
clang::ParentMap::~ParentMap
~ParentMap()
Definition: ParentMap.cpp:117
clang::ParentMap::getParentIgnoreParenCasts
Stmt * getParentIgnoreParenCasts(Stmt *) const
Definition: ParentMap.cpp:145
clang::ParentMap::hasParent
bool hasParent(const Stmt *S) const
Definition: ParentMap.h:54
clang::ParentMap::getParent
const Stmt * getParent(const Stmt *S) const
Definition: ParentMap.h:42
clang::ParentMap::setParent
void setParent(const Stmt *S, const Stmt *Parent)
Manually sets the parent of S to Parent.
Definition: ParentMap.cpp:127
clang::ParentMap::getParentIgnoreParenImpCasts
Stmt * getParentIgnoreParenImpCasts(Stmt *) const
Definition: ParentMap.cpp:154
clang::ParentMap::isConsumedExpr
bool isConsumedExpr(const Expr *E) const
Definition: ParentMap.h:58
clang::ParentMap::getOuterParenParent
Stmt * getOuterParenParent(Stmt *) const
Definition: ParentMap.cpp:162
clang::ParentMap
Definition: ParentMap.h:20
clang::ParentMap::getParentIgnoreParens
const Stmt * getParentIgnoreParens(const Stmt *S) const
Definition: ParentMap.h:46
clang::ParentMap::getParentIgnoreParenCasts
const Stmt * getParentIgnoreParenCasts(const Stmt *S) const
Definition: ParentMap.h:50
clang::ParentMap::getParent
Stmt * getParent(Stmt *) const
Definition: ParentMap.cpp:134
clang
Definition: CalledOnceCheck.h:17
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::ParentMap::getParentIgnoreParens
Stmt * getParentIgnoreParens(Stmt *) const
Definition: ParentMap.cpp:140
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::ParentMap::isConsumedExpr
bool isConsumedExpr(Expr *E) const
Definition: ParentMap.cpp:171
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::ParentMap::ParentMap
ParentMap(Stmt *ASTRoot)
Definition: ParentMap.cpp:109