CBMC
literal_vector_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 #ifndef CPROVER_SOLVERS_FLATTENING_LITERAL_VECTOR_EXPR_H
10 #define CPROVER_SOLVERS_FLATTENING_LITERAL_VECTOR_EXPR_H
11 
12 #include <util/std_expr.h>
13 #include <util/string2int.h>
14 
15 #include <solvers/prop/literal.h>
16 
18 {
19 public:
20  literal_vector_exprt(const bvt &__bv, typet __type)
21  : nullary_exprt(ID_literal_vector, std::move(__type))
22  {
23  bv(__bv);
24  }
25 
26  bvt bv() const
27  {
28  auto &sub = find(ID_literals).get_sub();
29  bvt result;
30  result.reserve(sub.size());
31  for(auto &literal_irep : sub)
32  {
33  literalt l;
35  unsafe_string2signedlonglong(literal_irep.id_string())));
36  result.push_back(l);
37  }
38  return result;
39  }
40 
41  void bv(const bvt &bv)
42  {
43  auto &sub = add(ID_literals).get_sub();
44  sub.clear();
45  sub.reserve(bv.size());
46  for(auto &literal : bv)
47  sub.emplace_back(irept{std::to_string(literal.get())});
48  }
49 };
50 
51 template <>
53 {
54  return base.id() == ID_literal_vector;
55 }
56 
63 {
64  PRECONDITION(expr.id() == ID_literal_vector);
66  return static_cast<const literal_vector_exprt &>(expr);
67 }
68 
72 {
73  PRECONDITION(expr.id() == ID_literal_vector);
75  return static_cast<literal_vector_exprt &>(expr);
76 }
77 
78 #endif // CPROVER_SOLVERS_FLATTENING_LITERAL_VECTOR_EXPR_H
Base class for all expressions.
Definition: expr.h:56
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:364
subt & get_sub()
Definition: irep.h:448
const irept & find(const irep_idt &name) const
Definition: irep.cpp:93
const irep_idt & id() const
Definition: irep.h:388
irept & add(const irep_idt &name)
Definition: irep.cpp:103
literal_vector_exprt(const bvt &__bv, typet __type)
void bv(const bvt &bv)
unsigned var_not
Definition: literal.h:31
void set(var_not _l)
Definition: literal.h:93
An expression without operands.
Definition: std_expr.h:22
static void check(const exprt &expr, const validation_modet vm=validation_modet::INVARIANT)
Definition: std_expr.h:29
The type of an expression, extends irept.
Definition: type.h:29
std::vector< literalt > bvt
Definition: literal.h:201
const literal_vector_exprt & to_literal_vector_expr(const exprt &expr)
Cast a generic exprt to a literal_vector_exprt.
bool can_cast_expr< literal_vector_exprt >(const exprt &base)
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
API to expression classes.
signed long long int unsafe_string2signedlonglong(const std::string &str, int base)
Definition: string2int.cpp:45
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.