ParentMap.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- ParentMap.h - Mappings from Stmts to their Parents -----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ParentMap class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_PARENTMAP_H
  18. #define LLVM_CLANG_AST_PARENTMAP_H
  19. namespace clang {
  20. class Stmt;
  21. class Expr;
  22. class ParentMap {
  23. void* Impl;
  24. public:
  25. ParentMap(Stmt* ASTRoot);
  26. ~ParentMap();
  27. /// 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. /// 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. Stmt *getParent(Stmt*) const;
  36. Stmt *getParentIgnoreParens(Stmt *) const;
  37. Stmt *getParentIgnoreParenCasts(Stmt *) const;
  38. Stmt *getParentIgnoreParenImpCasts(Stmt *) const;
  39. Stmt *getOuterParenParent(Stmt *) const;
  40. const Stmt *getParent(const Stmt* S) const {
  41. return getParent(const_cast<Stmt*>(S));
  42. }
  43. const Stmt *getParentIgnoreParens(const Stmt *S) const {
  44. return getParentIgnoreParens(const_cast<Stmt*>(S));
  45. }
  46. const Stmt *getParentIgnoreParenCasts(const Stmt *S) const {
  47. return getParentIgnoreParenCasts(const_cast<Stmt*>(S));
  48. }
  49. bool hasParent(const Stmt *S) const { return getParent(S) != nullptr; }
  50. bool isConsumedExpr(Expr *E) const;
  51. bool isConsumedExpr(const Expr *E) const {
  52. return isConsumedExpr(const_cast<Expr*>(E));
  53. }
  54. };
  55. } // end clang namespace
  56. #endif
  57. #ifdef __GNUC__
  58. #pragma GCC diagnostic pop
  59. #endif