ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
python_expr_builder.h
Go to the documentation of this file.
1#pragma once
2
3#include <util/irep/expr.h>
4#include <util/irep/type.h>
7#include <vector>
8
9// Shared IREP2 expression-construction helpers for the Python frontend (V.3).
10//
11// Each helper performs the legacy<->IREP2 round-trip
12// migrate_expr -> build IREP2 node -> migrate_expr_back
13// so the frontend emits nodes pre-lowered for the legacy adjust/goto-convert
14// seam. They were originally copy-pasted into ~15 translation units; this
15// module is the single source of truth.
16//
17// Two migrate_type round-trip hazards are guarded uniformly:
18// * a dynamically-sized array type (non-constant size) throws get_width
19// downstream, so the relevant helpers fall back to the legacy constructor;
20// * some type attributes are dropped by migrate_type (#cpp_type itself is
21// carried since §10), so the member/index/typecast/dereference helpers
22// restore the exact result type
23// (result.type() = t) -- load-bearing e.g. to keep a 1-char string element
24// distinct from an 8-bit int.
25namespace python_expr
26{
27// True iff `t` is, or transitively points to/contains, an array whose size is
28// nil or non-constant (a dyn-sized array that does not survive migrate_type).
29bool contains_dyn_array(const typet &t);
30
31// Store `t` as `sym`'s type IREP2-side, or legacy when `t` holds a
32// dyn-sized array (docs/roadmap/scope-python-irep2.md §10.4).
33void set_symbol_type(symbolt &sym, const typet &t);
34
35// Store a function type, or a pointer to one, IREP2-side only when the seam
36// round-trips it up to an argument's plain `identifier` and `#location`
37// (docs/roadmap/scope-python-irep2.md §11.4).
38void set_function_type(symbolt &sym, const typet &t);
39
40// Store `t` as `sym`'s type IREP2-side unless migrate_type would lose it: a
41// nil type or a dyn-sized array (docs/roadmap/scope-python-irep2.md §10.4).
42void set_symbol_type_if_carried(symbolt &sym, const typet &t);
43
44// Symbol reference `sym`.
45exprt build_symbol(const symbolt &sym);
46
47// Typecast `from` to type `t`.
48exprt build_typecast(const exprt &from, const typet &t);
49
50// Address-of an lvalue `obj` (symbol/member/index source).
51exprt build_address_of(const exprt &obj);
52
53// A function name used as a value decays to a function pointer, as it already
54// does in call-argument position. Storing the code symbol itself aborts
55// conversion with "got invalid code for function" (#6640). Non-function
56// expressions are returned unchanged.
57exprt decay_function_to_pointer(const exprt &value);
58
59// Dereference `ptr` to a value of type `t`.
60exprt build_dereference(const exprt &ptr, const typet &t);
61
62// Struct/union member access `base.name : t`. Falls back to the legacy node
63// when the source is not a struct/union/symbol value.
64exprt build_member(const exprt &base, const irep_idt &name, const typet &t);
65
66// `(*obj).field : field_type`, where `obj` is a pointer to a struct.
68 const exprt &obj,
69 const irep_idt &field,
70 const typet &field_type);
71
72// Array index `arr[idx] : t`. Falls back to the legacy node when the source is
73// not an array/vector/symbol value.
74exprt build_index(const exprt &arr, const exprt &idx, const typet &t);
75
76// `arr[idx]` with element type taken from the source array's subtype.
77exprt build_index(const exprt &arr, const exprt &idx);
78
79// Boolean negation `not op`, `op` a bool-typed value. migrate lowers a legacy
80// "not" node to not2tc(migrate(op)), so this is the byte-identical round-trip.
81exprt build_not(const exprt &op);
82
83// `a < b` over same-width operands (lessthan2t asserts width consistency).
84exprt build_less_than(const exprt &a, const exprt &b);
85
86// `a <= b` over same-width operands (lessthanequal2t asserts width
87// consistency).
88exprt build_less_equal(const exprt &a, const exprt &b);
89
90// `a > b` over same-width operands (greaterthan2t asserts width consistency).
91exprt build_greater_than(const exprt &a, const exprt &b);
92
93// `a >= b` over same-width operands (greaterthanequal2t asserts width
94// consistency).
95exprt build_greater_equal(const exprt &a, const exprt &b);
96
97// Boolean disjunction `a || b`, both operands bool-typed. migrate lowers a
98// legacy binary "or" node to or2tc(migrate(a), migrate(b)), so this is the
99// byte-identical round-trip.
100exprt build_or(const exprt &a, const exprt &b);
101
102// Boolean conjunction `a && b`, both operands bool-typed. migrate lowers a
103// legacy binary "and" node to and2tc(migrate(a), migrate(b)), so this is the
104// byte-identical round-trip.
105exprt build_and(const exprt &a, const exprt &b);
106
107// Boolean exclusive-or `a ^ b`, both operands bool-typed. migrate lowers a
108// legacy binary "xor" node to xor2tc(migrate(a), migrate(b)), so this is the
109// byte-identical round-trip. Not to be confused with `bitxor` -- a bool-typed
110// bitxor2t is malformed and crashes the Bitwuzla BV encoder (GitHub #4548).
111exprt build_xor(const exprt &a, const exprt &b);
112
113// `a + b : t` over same-width operands (add2t asserts width consistency).
114exprt build_add(const exprt &a, const exprt &b, const typet &t);
115
116// `a - b : t` over same-width operands (sub2t asserts width consistency).
117exprt build_sub(const exprt &a, const exprt &b, const typet &t);
118
119// `a % b : t` over same-width operands (modulus2t asserts width consistency).
120exprt build_mod(const exprt &a, const exprt &b, const typet &t);
121
122// `a * b : t` over same-width operands (mul2t asserts width consistency).
123exprt build_mul(const exprt &a, const exprt &b, const typet &t);
124
125// Equality `a == b` over same-typed operands. migrate lowers a legacy
126// "=" node to equality2tc(migrate(a), migrate(b)), so this is the
127// byte-identical round-trip.
128exprt build_equal(const exprt &a, const exprt &b);
129
130// Inequality `a != b` over same-typed operands. migrate lowers a legacy
131// "notequal" node to notequal2tc(migrate(a), migrate(b)), so this is the
132// byte-identical round-trip.
133exprt build_notequal(const exprt &a, const exprt &b);
134
135// Ternary select `cond ? then : else_`. The if2t invariant requires both
136// branches to share the result type kind, so this falls back to the legacy
137// node when the branch types diverge (or contain a dyn-sized array that does
138// not round-trip). On the common matching-branch path it is the byte-identical
139// round-trip.
140exprt build_if(const exprt &cond, const exprt &then_, const exprt &else_);
141
142// Expression-context call `fn(args...) : return_type`, fn a function symbol.
143exprt build_call_expr(
144 const symbolt &fn,
145 const typet &return_type,
146 const std::vector<exprt> &args);
147
148// Expression-context call `fn_id(args...) : return_type`, the callee referenced
149// by name with a placeholder code type.
150exprt build_call_expr(
151 const irep_idt &fn_id,
152 const typet &return_type,
153 const std::vector<exprt> &args);
154
155// Expression-context call `callee(args...) : return_type`, callee an already
156// built function expression (e.g. a by-name symbol carrying a code_typet).
157exprt build_call(
158 const exprt &callee,
159 const typet &return_type,
160 const std::vector<exprt> &args);
161} // namespace python_expr
static const twodig_t base
Definition bigint.cpp:28
pthread_cond_t cond
Definition cuda.h:50
Definition python_expr_builder.cpp:12
exprt build_typecast(const exprt &from, const typet &t)
Definition python_expr_builder.cpp:73
exprt build_equal(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:330
exprt build_not(const exprt &op)
Definition python_expr_builder.cpp:195
exprt build_if(const exprt &cond, const exprt &then_, const exprt &else_)
Definition python_expr_builder.cpp:354
exprt build_deref_member(const exprt &obj, const irep_idt &field, const typet &field_type)
Definition python_expr_builder.cpp:142
exprt decay_function_to_pointer(const exprt &value)
Definition python_expr_builder.cpp:98
exprt build_symbol(const symbolt &sym)
Definition python_expr_builder.cpp:61
exprt build_less_than(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:235
exprt build_greater_than(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:248
exprt build_mul(const exprt &a, const exprt &b, const typet &t)
Definition python_expr_builder.cpp:310
exprt build_call_expr(const symbolt &fn, const typet &return_type, const std::vector< exprt > &args)
Definition python_expr_builder.cpp:375
exprt build_notequal(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:341
exprt build_call(const exprt &callee, const typet &return_type, const std::vector< exprt > &args)
Definition python_expr_builder.cpp:412
exprt build_xor(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:277
exprt build_dereference(const exprt &ptr, const typet &t)
Definition python_expr_builder.cpp:105
exprt build_add(const exprt &a, const exprt &b, const typet &t)
Definition python_expr_builder.cpp:292
exprt build_sub(const exprt &a, const exprt &b, const typet &t)
Definition python_expr_builder.cpp:301
exprt build_mod(const exprt &a, const exprt &b, const typet &t)
Definition python_expr_builder.cpp:319
exprt build_and(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:270
void set_function_type(symbolt &sym, const typet &t)
Definition python_expr_builder.cpp:45
exprt build_address_of(const exprt &obj)
Definition python_expr_builder.cpp:89
exprt build_less_equal(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:241
void set_symbol_type(symbolt &sym, const typet &t)
Definition python_expr_builder.cpp:27
exprt build_index(const exprt &arr, const exprt &idx, const typet &t)
Definition python_expr_builder.cpp:156
bool contains_dyn_array(const typet &t)
Definition python_expr_builder.cpp:13
exprt build_member(const exprt &base, const irep_idt &name, const typet &t)
Definition python_expr_builder.cpp:121
void set_symbol_type_if_carried(symbolt &sym, const typet &t)
Definition python_expr_builder.cpp:37
exprt build_greater_equal(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:255
exprt build_or(const exprt &a, const exprt &b)
Definition python_expr_builder.cpp:263
void * value
Definition solidity_mapping.c:2