CBMC
literal_expr.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_SOLVERS_PROP_LITERAL_EXPR_H
11 #define CPROVER_SOLVERS_PROP_LITERAL_EXPR_H
12 
13 #include <util/std_expr.h>
14 
15 #include "literal.h"
16 
18 {
19 public:
20  explicit literal_exprt(literalt a):
21  predicate_exprt(ID_literal)
22  {
23  set_literal(a);
24  }
25 
27  {
28  literalt result;
29  result.set(literalt::var_not(get_long_long(ID_literal)));
30  return result;
31  }
32 
34  {
35  set(ID_literal, a.get());
36  }
37 };
38 
39 template <>
40 inline bool can_cast_expr<literal_exprt>(const exprt &base)
41 {
42  return base.id() == ID_literal;
43 }
44 
45 inline void validate_expr(const literal_exprt &literal)
46 {
48  !literal.has_operands(), "literal expression should not have operands");
49 }
50 
56 inline const literal_exprt &to_literal_expr(const exprt &expr)
57 {
58  PRECONDITION(expr.id() == ID_literal);
60  !expr.has_operands(), "literal expression should not have operands");
61  return static_cast<const literal_exprt &>(expr);
62 }
63 
67 {
68  PRECONDITION(expr.id() == ID_literal);
70  !expr.has_operands(), "literal expression should not have operands");
71  return static_cast<literal_exprt &>(expr);
72 }
73 
74 #endif // CPROVER_SOLVERS_PROP_LITERAL_EXPR_H
Base class for all expressions.
Definition: expr.h:56
bool has_operands() const
Return true if there is at least one operand.
Definition: expr.h:91
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:412
const irep_idt & id() const
Definition: irep.h:388
long long get_long_long(const irep_idt &name) const
Definition: irep.cpp:72
literal_exprt(literalt a)
Definition: literal_expr.h:20
literalt get_literal() const
Definition: literal_expr.h:26
void set_literal(literalt a)
Definition: literal_expr.h:33
unsigned var_not
Definition: literal.h:31
var_not get() const
Definition: literal.h:103
void set(var_not _l)
Definition: literal.h:93
A base class for expressions that are predicates, i.e., Boolean-typed.
Definition: std_expr.h:574
void validate_expr(const literal_exprt &literal)
Definition: literal_expr.h:45
const literal_exprt & to_literal_expr(const exprt &expr)
Cast a generic exprt to a literal_exprt.
Definition: literal_expr.h:56
bool can_cast_expr< literal_exprt >(const exprt &base)
Definition: literal_expr.h:40
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:534
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
API to expression classes.