CBMC
expr_skeleton.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Symbolic Execution
4 
5 Author: Romain Brenguier, romain.brenguier@diffblue.com
6 
7 \*******************************************************************/
8 
11 
12 #include "expr_skeleton.h"
13 
14 #include <util/std_expr.h>
15 
17 {
18 }
19 
21 {
22  PRECONDITION(e.id() != ID_symbol);
23  PRECONDITION(e.operands().size() >= 1);
25  return expr_skeletont{std::move(e)};
26 }
27 
29 {
30  PRECONDITION(skeleton.id() != ID_symbol);
31  exprt result = skeleton;
32  exprt *p = &result;
33 
34  while(p->is_not_nil())
35  {
36  INVARIANT(
37  p->id() != ID_symbol,
38  "expected pointed-to expression not to be a symbol");
39  INVARIANT(
40  p->operands().size() >= 1,
41  "expected pointed-to expression to have at least one operand");
42  p = &to_multi_ary_expr(*p).op0();
43  }
44 
45  INVARIANT(p->is_nil(), "expected pointed-to expression to be nil");
46 
47  *p = std::move(expr);
48  return result;
49 }
50 
52 {
53  return expr_skeletont(apply(other.skeleton));
54 }
expr_skeletont::apply
exprt apply(exprt expr) const
Replace the missing part by the given expression, to end-up with a complete expression.
Definition: expr_skeleton.cpp:28
irept::make_nil
void make_nil()
Definition: irep.h:454
expr_skeleton.h
exprt
Base class for all expressions.
Definition: expr.h:55
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:380
PRECONDITION
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
nil_exprt
The NIL expression.
Definition: std_expr.h:3025
expr_skeletont::remove_op0
static expr_skeletont remove_op0(exprt e)
Create a skeleton by removing the first operand of e.
Definition: expr_skeleton.cpp:20
irept::is_nil
bool is_nil() const
Definition: irep.h:376
irept::id
const irep_idt & id() const
Definition: irep.h:396
expr_skeletont::skeleton
exprt skeleton
In skeleton, nil_exprt is used to mark the sub expression to be substituted.
Definition: expr_skeleton.h:51
expr_skeletont::compose
expr_skeletont compose(expr_skeletont other) const
Replace the missing part of the current skeleton by another skeleton, ending in a bigger skeleton cor...
Definition: expr_skeleton.cpp:51
exprt::operands
operandst & operands()
Definition: expr.h:94
multi_ary_exprt::op0
exprt & op0()
Definition: std_expr.h:877
to_multi_ary_expr
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
Definition: std_expr.h:932
std_expr.h
expr_skeletont
Expression in which some part is missing and can be substituted for another expression.
Definition: expr_skeleton.h:25
validation_modet::INVARIANT
@ INVARIANT
expr_skeletont::expr_skeletont
expr_skeletont()
Empty skeleton.
Definition: expr_skeleton.cpp:16