cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
std_code_base.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Data structures representing statements in a program
4
5
Author: 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
28
class
codet
:
public
exprt
29
{
30
public
:
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
70
codet
&
first_statement
();
71
const
codet
&
first_statement
()
const
;
72
codet
&
last_statement
();
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
81
namespace
detail
// NOLINT
82
{
83
template
<
typename
Tag>
84
inline
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
95
template
<>
96
inline
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
104
inline
const
codet
&
to_code
(
const
exprt
&expr)
105
{
106
PRECONDITION
(expr.
id
() == ID_code);
107
return
static_cast<
const
codet
&
>
(expr);
108
}
109
110
inline
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
codet
Data structure for representing an arbitrary statement in a program.
Definition
std_code_base.h:29
codet::codet
codet(const irep_idt &statement, source_locationt loc)
Definition
std_code_base.h:39
codet::codet
codet(const irep_idt &statement)
Definition
std_code_base.h:34
codet::codet
codet(const irep_idt &statement, operandst op, source_locationt loc)
Definition
std_code_base.h:54
codet::first_statement
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
codet & last_statement()
In the case of a codet type that represents multiple statements, return the last of them.
Definition
std_code.cpp:52
codet::get_statement
const irep_idt & get_statement() const
Definition
std_code_base.h:65
codet::set_statement
void set_statement(const irep_idt &statement)
Definition
std_code_base.h:60
codet::codet
codet(const irep_idt &statement, operandst _op)
Definition
std_code_base.h:49
empty_typet
The empty type.
Definition
std_types.h:51
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::op3
exprt & op3()
Definition
expr.h:143
exprt::operandst
std::vector< exprt > operandst
Definition
expr.h:59
exprt::exprt
exprt()
Definition
expr.h:62
exprt::op0
exprt & op0()
Definition
expr.h:134
exprt::op1
exprt & op1()
Definition
expr.h:137
exprt::operands
operandst & operands()
Definition
expr.h:95
exprt::op2
exprt & op2()
Definition
expr.h:140
irept::get
const irep_idt & get(const irep_idt &name) const
Definition
irep.cpp:44
irept::set
void set(const irep_idt &name, const irep_idt &value)
Definition
irep.h:412
irept::id
const irep_idt & id() const
Definition
irep.h:388
source_locationt
Definition
source_location.h:20
expr_cast.h
Templated functions to cast to specific exprt-derived classes.
expr_try_dynamic_cast
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
Definition
expr_cast.h:81
detail
Definition
expr_cast.h:52
detail::can_cast_code_impl
bool can_cast_code_impl(const exprt &expr, const Tag &tag)
Definition
std_code_base.h:84
std
STL namespace.
invariant.h
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
can_cast_expr< codet >
bool can_cast_expr< codet >(const exprt &base)
Definition
std_code_base.h:96
to_code
const codet & to_code(const exprt &expr)
Definition
std_code_base.h:104
std_types.h
Pre-defined types.
validate.h
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
util
std_code_base.h
Generated by
1.17.0