clang  14.0.0git
ThreadSafetyLogical.h
Go to the documentation of this file.
1 //===- ThreadSafetyLogical.h -----------------------------------*- 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 // This file defines a representation for logical expressions with SExpr leaves
9 // that are used as part of fact-checking capability expressions.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYLOGICAL_H
13 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYLOGICAL_H
14 
16 
17 namespace clang {
18 namespace threadSafety {
19 namespace lexpr {
20 
21 class LExpr {
22 public:
23  enum Opcode {
25  And,
26  Or,
28  };
29  Opcode kind() const { return Kind; }
30 
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 
35 protected:
36  LExpr(Opcode Kind) : Kind(Kind) {}
37 
38 private:
39  Opcode Kind;
40 };
41 
42 class Terminal : public LExpr {
44 
45 public:
47 
48  const til::SExpr *expr() const { return Expr; }
49  til::SExpr *expr() { return Expr; }
50 
51  static bool classof(const LExpr *E) { return E->kind() == LExpr::Terminal; }
52 };
53 
54 class BinOp : public LExpr {
55  LExpr *LHS, *RHS;
56 
57 protected:
58  BinOp(LExpr *LHS, LExpr *RHS, Opcode Code) : LExpr(Code), LHS(LHS), RHS(RHS) {}
59 
60 public:
61  const LExpr *left() const { return LHS; }
62  LExpr *left() { return LHS; }
63 
64  const LExpr *right() const { return RHS; }
65  LExpr *right() { return RHS; }
66 };
67 
68 class And : public BinOp {
69 public:
70  And(LExpr *LHS, LExpr *RHS) : BinOp(LHS, RHS, LExpr::And) {}
71 
72  static bool classof(const LExpr *E) { return E->kind() == LExpr::And; }
73 };
74 
75 class Or : public BinOp {
76 public:
77  Or(LExpr *LHS, LExpr *RHS) : BinOp(LHS, RHS, LExpr::Or) {}
78 
79  static bool classof(const LExpr *E) { return E->kind() == LExpr::Or; }
80 };
81 
82 class Not : public LExpr {
83  LExpr *Exp;
84 
85 public:
86  Not(LExpr *Exp) : LExpr(LExpr::Not), Exp(Exp) {}
87 
88  const LExpr *exp() const { return Exp; }
89  LExpr *exp() { return Exp; }
90 
91  static bool classof(const LExpr *E) { return E->kind() == LExpr::Not; }
92 };
93 
94 /// Logical implication. Returns true if LHS implies RHS, i.e. if LHS
95 /// holds, then RHS must hold. For example, (A & B) implies A.
96 bool implies(const LExpr *LHS, const LExpr *RHS);
97 
98 bool LExpr::implies(const LExpr *RHS) const {
99  return lexpr::implies(this, RHS);
100 }
101 
102 }
103 }
104 }
105 
106 #endif
107 
clang::threadSafety::lexpr::BinOp::right
LExpr * right()
Definition: ThreadSafetyLogical.h:65
ThreadSafetyTIL.h
clang::threadSafety::lexpr::And::classof
static bool classof(const LExpr *E)
Definition: ThreadSafetyLogical.h:72
clang::threadSafety::lexpr::BinOp::BinOp
BinOp(LExpr *LHS, LExpr *RHS, Opcode Code)
Definition: ThreadSafetyLogical.h:58
clang::threadSafety::lexpr::LExpr::Terminal
@ Terminal
Definition: ThreadSafetyLogical.h:24
clang::threadSafety::lexpr::Terminal::expr
const til::SExpr * expr() const
Definition: ThreadSafetyLogical.h:48
clang::threadSafety::lexpr::Terminal::classof
static bool classof(const LExpr *E)
Definition: ThreadSafetyLogical.h:51
clang::threadSafety::lexpr::LExpr::LExpr
LExpr(Opcode Kind)
Definition: ThreadSafetyLogical.h:36
clang::threadSafety::lexpr::Not::exp
LExpr * exp()
Definition: ThreadSafetyLogical.h:89
clang::threadSafety::lexpr::Or::Or
Or(LExpr *LHS, LExpr *RHS)
Definition: ThreadSafetyLogical.h:77
clang::threadSafety::lexpr::LExpr::Not
@ Not
Definition: ThreadSafetyLogical.h:27
clang::threadSafety::lexpr::And::And
And(LExpr *LHS, LExpr *RHS)
Definition: ThreadSafetyLogical.h:70
clang::threadSafety::lexpr::Not::classof
static bool classof(const LExpr *E)
Definition: ThreadSafetyLogical.h:91
clang::threadSafety::lexpr::Not::Not
Not(LExpr *Exp)
Definition: ThreadSafetyLogical.h:86
clang::threadSafety::lexpr::LExpr::Opcode
Opcode
Definition: ThreadSafetyLogical.h:23
clang::threadSafety::lexpr::LExpr::kind
Opcode kind() const
Definition: ThreadSafetyLogical.h:29
clang::threadSafety::lexpr::BinOp::left
LExpr * left()
Definition: ThreadSafetyLogical.h:62
clang::threadSafety::lexpr::BinOp::left
const LExpr * left() const
Definition: ThreadSafetyLogical.h:61
clang::threadSafety::lexpr::Terminal
Definition: ThreadSafetyLogical.h:42
clang::threadSafety::lexpr::LExpr::And
@ And
Definition: ThreadSafetyLogical.h:25
clang::threadSafety::lexpr::LExpr::implies
bool implies(const LExpr *RHS) const
Logical implication.
Definition: ThreadSafetyLogical.h:98
clang::threadSafety::lexpr::LExpr::Or
@ Or
Definition: ThreadSafetyLogical.h:26
clang::threadSafety::lexpr::Or
Definition: ThreadSafetyLogical.h:75
clang::threadSafety::lexpr::LExpr
Definition: ThreadSafetyLogical.h:21
clang::threadSafety::lexpr::Not::exp
const LExpr * exp() const
Definition: ThreadSafetyLogical.h:88
clang::threadSafety::lexpr::Or::classof
static bool classof(const LExpr *E)
Definition: ThreadSafetyLogical.h:79
clang::threadSafety::lexpr::Not
Definition: ThreadSafetyLogical.h:82
clang::threadSafety::lexpr::implies
bool implies(const LExpr *LHS, const LExpr *RHS)
Logical implication.
Definition: ThreadSafetyLogical.cpp:105
clang::threadSafety::lexpr::Terminal::Terminal
Terminal(til::SExpr *Expr)
Definition: ThreadSafetyLogical.h:46
clang
Definition: CalledOnceCheck.h:17
clang::threadSafety::lexpr::BinOp
Definition: ThreadSafetyLogical.h:54
clang::threadSafety::lexpr::And
Definition: ThreadSafetyLogical.h:68
clang::threadSafety::lexpr::BinOp::right
const LExpr * right() const
Definition: ThreadSafetyLogical.h:64
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::threadSafety::lexpr::Terminal::expr
til::SExpr * expr()
Definition: ThreadSafetyLogical.h:49
clang::threadSafety::til::SExpr
Base class for AST nodes in the typed intermediate language.
Definition: ThreadSafetyTIL.h:277