cprover
std_code.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #include "std_code.h"
11 
12 #include "std_expr.h"
13 
15 {
17 }
18 
20 {
22 }
23 
25 {
26  if(get_statement()==ID_block)
27  return static_cast<code_blockt &>(*this);
28 
29  exprt tmp;
30  tmp.swap(*this);
31 
32  *this=codet();
33  set_statement(ID_block);
34  move_to_operands(tmp);
35 
36  return static_cast<code_blockt &>(*this);
37 }
38 
40 {
41  const irep_idt &statement=get_statement();
42 
43  if(has_operands())
44  {
45  if(statement==ID_block)
46  return to_code(op0()).first_statement();
47  else if(statement==ID_label)
48  return to_code(op0()).first_statement();
49  }
50 
51  return *this;
52 }
53 
55 {
56  const irep_idt &statement=get_statement();
57 
58  if(has_operands())
59  {
60  if(statement==ID_block)
61  return to_code(op0()).first_statement();
62  else if(statement==ID_label)
63  return to_code(op0()).first_statement();
64  }
65 
66  return *this;
67 }
68 
70 {
71  const irep_idt &statement=get_statement();
72 
73  if(has_operands())
74  {
75  if(statement==ID_block)
76  return to_code(operands().back()).last_statement();
77  else if(statement==ID_label)
78  return to_code(operands().back()).last_statement();
79  }
80 
81  return *this;
82 }
83 
85 {
86  const irep_idt &statement=get_statement();
87 
88  if(has_operands())
89  {
90  if(statement==ID_block)
91  return to_code(operands().back()).last_statement();
92  else if(statement==ID_label)
93  return to_code(operands().back()).last_statement();
94  }
95 
96  return *this;
97 }
98 
101 void code_blockt::append(const code_blockt &extra_block)
102 {
103  operands().reserve(operands().size()+extra_block.operands().size());
104 
105  for(const auto &operand : extra_block.operands())
106  {
107  add(to_code(operand));
108  }
109 }
const irep_idt & get_statement() const
Definition: std_code.h:37
const irep_idt & get_identifier() const
Definition: std_code.cpp:19
exprt & op0()
Definition: expr.h:84
exprt & symbol()
Definition: std_code.h:205
const irep_idt & get_identifier() const
Definition: std_expr.h:120
void move_to_operands(exprt &expr)
Definition: expr.cpp:28
codet & first_statement()
Definition: std_code.cpp:39
void add(const codet &code)
Definition: std_code.h:81
class code_blockt & make_block()
Definition: std_code.cpp:24
codet & last_statement()
Definition: std_code.cpp:69
API to expression classes.
const irep_idt & get_identifier() const
Definition: std_code.cpp:14
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
Definition: std_code.cpp:101
exprt & symbol()
Definition: std_code.h:247
bool has_operands() const
Definition: expr.h:67
void set_statement(const irep_idt &statement)
Definition: std_code.h:32
Base class for all expressions.
Definition: expr.h:46
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
Definition: std_expr.h:202
codet()
Definition: std_code.h:22
void swap(irept &irep)
Definition: irep.h:231
Sequential composition.
Definition: std_code.h:63
const codet & to_code(const exprt &expr)
Definition: std_code.h:49
A statement in a programming language.
Definition: std_code.h:19
operandst & operands()
Definition: expr.h:70