CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
std_code_base.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Data structures representing statements in a program
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#ifndef CPROVER_UTIL_STD_CODE_BASE_H
10#define CPROVER_UTIL_STD_CODE_BASE_H
11
12#include "expr_cast.h"
13#include "invariant.h"
14#include "std_types.h"
15#include "validate.h"
16
28class codet : public exprt
29{
30public:
34 explicit codet(const irep_idt &statement) : exprt(ID_code, empty_typet())
35 {
36 set_statement(statement);
37 }
38
39 codet(const irep_idt &statement, source_locationt loc)
40 : exprt(ID_code, empty_typet(), std::move(loc))
41 {
42 set_statement(statement);
43 }
44
49 explicit codet(const irep_idt &statement, operandst _op) : codet(statement)
50 {
51 operands() = std::move(_op);
52 }
53
54 codet(const irep_idt &statement, operandst op, source_locationt loc)
55 : codet(statement, std::move(loc))
56 {
57 operands() = std::move(op);
58 }
59
60 void set_statement(const irep_idt &statement)
61 {
62 set(ID_statement, statement);
63 }
64
65 const irep_idt &get_statement() const
66 {
67 return get(ID_statement);
68 }
69
71 const codet &first_statement() const;
73 const codet &last_statement() const;
74
75 using exprt::op0;
76 using exprt::op1;
77 using exprt::op2;
78 using exprt::op3;
79};
80
81namespace detail // NOLINT
82{
83template <typename Tag>
84inline bool can_cast_code_impl(const exprt &expr, const Tag &tag)
85{
86 if(const auto ptr = expr_try_dynamic_cast<codet>(expr))
87 {
88 return ptr->get_statement() == tag;
89 }
90 return false;
91}
92
93} // namespace detail
94
95template <>
96inline bool can_cast_expr<codet>(const exprt &base)
97{
98 return base.id() == ID_code;
99}
100
101// to_code has no validation other than checking the id(), so no validate_expr
102// is provided for codet
103
104inline const codet &to_code(const exprt &expr)
105{
106 PRECONDITION(expr.id() == ID_code);
107 return static_cast<const codet &>(expr);
108}
109
110inline codet &to_code(exprt &expr)
111{
112 PRECONDITION(expr.id() == ID_code);
113 return static_cast<codet &>(expr);
114}
115
116#endif // CPROVER_UTIL_STD_CODE_BASE_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Data structure for representing an arbitrary statement in a program.
codet(const irep_idt &statement, source_locationt loc)
codet(const irep_idt &statement)
codet(const irep_idt &statement, operandst op, source_locationt loc)
codet & first_statement()
In the case of a codet type that represents multiple statements, return the first of them.
Definition std_code.cpp:18
codet & last_statement()
In the case of a codet type that represents multiple statements, return the last of them.
Definition std_code.cpp:52
const irep_idt & get_statement() const
void set_statement(const irep_idt &statement)
codet(const irep_idt &statement, operandst _op)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
The empty type.
Definition std_types.h:51
Base class for all expressions.
Definition expr.h:56
exprt & op3()
Definition expr.h:142
std::vector< exprt > operandst
Definition expr.h:58
exprt & op0()
Definition expr.h:133
exprt & op1()
Definition expr.h:136
operandst & operands()
Definition expr.h:94
exprt & op2()
Definition expr.h:139
const irep_idt & get(const irep_idt &name) const
Definition irep.cpp:44
void set(const irep_idt &name, const irep_idt &value)
Definition irep.h:412
const irep_idt & id() const
Definition irep.h:388
Templated functions to cast to specific exprt-derived classes.
bool can_cast_code_impl(const exprt &expr, const Tag &tag)
STL namespace.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
bool can_cast_expr< codet >(const exprt &base)
const codet & to_code(const exprt &expr)
Pre-defined types.