1 //===- ThreadSafetyLogical.h -----------------------------------*- C++ --*-===//
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
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 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYLOGICAL_H
13 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYLOGICAL_H
15 #include "clang/Analysis/Analyses/ThreadSafetyTIL.h"
18 namespace threadSafety {
29 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;
36 LExpr(Opcode Kind) : Kind(Kind) {}
42 class Terminal : public LExpr {
46 Terminal(til::SExpr *Expr) : LExpr(LExpr::Terminal), Expr(Expr) {}
48 const til::SExpr *expr() const { return Expr; }
49 til::SExpr *expr() { return Expr; }
51 static bool classof(const LExpr *E) { return E->kind() == LExpr::Terminal; }
54 class BinOp : public LExpr {
58 BinOp(LExpr *LHS, LExpr *RHS, Opcode Code) : LExpr(Code), LHS(LHS), RHS(RHS) {}
61 const LExpr *left() const { return LHS; }
62 LExpr *left() { return LHS; }
64 const LExpr *right() const { return RHS; }
65 LExpr *right() { return RHS; }
68 class And : public BinOp {
70 And(LExpr *LHS, LExpr *RHS) : BinOp(LHS, RHS, LExpr::And) {}
72 static bool classof(const LExpr *E) { return E->kind() == LExpr::And; }
75 class Or : public BinOp {
77 Or(LExpr *LHS, LExpr *RHS) : BinOp(LHS, RHS, LExpr::Or) {}
79 static bool classof(const LExpr *E) { return E->kind() == LExpr::Or; }
82 class Not : public LExpr {
86 Not(LExpr *Exp) : LExpr(LExpr::Not), Exp(Exp) {}
88 const LExpr *exp() const { return Exp; }
89 LExpr *exp() { return Exp; }
91 static bool classof(const LExpr *E) { return E->kind() == LExpr::Not; }
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);
98 bool LExpr::implies(const LExpr *RHS) const {
99 return lexpr::implies(this, RHS);