ThreadSafetyLogical.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ThreadSafetyLogical.h -----------------------------------*- 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. // This file defines a representation for logical expressions with SExpr leaves
  14. // that are used as part of fact-checking capability expressions.
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYLOGICAL_H
  17. #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYLOGICAL_H
  18. #include "clang/Analysis/Analyses/ThreadSafetyTIL.h"
  19. namespace clang {
  20. namespace threadSafety {
  21. namespace lexpr {
  22. class LExpr {
  23. public:
  24. enum Opcode {
  25. Terminal,
  26. And,
  27. Or,
  28. Not
  29. };
  30. Opcode kind() const { return Kind; }
  31. /// Logical implication. Returns true if the LExpr implies RHS, i.e. if
  32. /// the LExpr holds, then RHS must hold. For example, (A & B) implies A.
  33. inline bool implies(const LExpr *RHS) const;
  34. protected:
  35. LExpr(Opcode Kind) : Kind(Kind) {}
  36. private:
  37. Opcode Kind;
  38. };
  39. class Terminal : public LExpr {
  40. til::SExpr *Expr;
  41. public:
  42. Terminal(til::SExpr *Expr) : LExpr(LExpr::Terminal), Expr(Expr) {}
  43. const til::SExpr *expr() const { return Expr; }
  44. til::SExpr *expr() { return Expr; }
  45. static bool classof(const LExpr *E) { return E->kind() == LExpr::Terminal; }
  46. };
  47. class BinOp : public LExpr {
  48. LExpr *LHS, *RHS;
  49. protected:
  50. BinOp(LExpr *LHS, LExpr *RHS, Opcode Code) : LExpr(Code), LHS(LHS), RHS(RHS) {}
  51. public:
  52. const LExpr *left() const { return LHS; }
  53. LExpr *left() { return LHS; }
  54. const LExpr *right() const { return RHS; }
  55. LExpr *right() { return RHS; }
  56. };
  57. class And : public BinOp {
  58. public:
  59. And(LExpr *LHS, LExpr *RHS) : BinOp(LHS, RHS, LExpr::And) {}
  60. static bool classof(const LExpr *E) { return E->kind() == LExpr::And; }
  61. };
  62. class Or : public BinOp {
  63. public:
  64. Or(LExpr *LHS, LExpr *RHS) : BinOp(LHS, RHS, LExpr::Or) {}
  65. static bool classof(const LExpr *E) { return E->kind() == LExpr::Or; }
  66. };
  67. class Not : public LExpr {
  68. LExpr *Exp;
  69. public:
  70. Not(LExpr *Exp) : LExpr(LExpr::Not), Exp(Exp) {}
  71. const LExpr *exp() const { return Exp; }
  72. LExpr *exp() { return Exp; }
  73. static bool classof(const LExpr *E) { return E->kind() == LExpr::Not; }
  74. };
  75. /// Logical implication. Returns true if LHS implies RHS, i.e. if LHS
  76. /// holds, then RHS must hold. For example, (A & B) implies A.
  77. bool implies(const LExpr *LHS, const LExpr *RHS);
  78. bool LExpr::implies(const LExpr *RHS) const {
  79. return lexpr::implies(this, RHS);
  80. }
  81. }
  82. }
  83. }
  84. #endif
  85. #ifdef __GNUC__
  86. #pragma GCC diagnostic pop
  87. #endif