ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
jimple_expr.h
Go to the documentation of this file.
2#include <util/irep/migrate.h>
4
5#pragma once
6
11class jimple_expr : public jimple_ast
12{
13public:
14 virtual exprt
15 to_exprt(contextt &, const std::string &, const std::string &) const
16 {
17 exprt val("at_identifier");
18 return val;
19 };
20
31 contextt &ctx,
32 const std::string &class_name,
33 const std::string &function_name) const
34 {
35 expr2tc e;
36 migrate_expr(to_exprt(ctx, class_name, function_name), e);
37 return e;
38 }
39
59 static std::shared_ptr<jimple_expr> get_expression(const json &j);
60
61protected:
71 contextt &ctx,
72 const std::string &base_class,
73 const std::string &method,
74 const std::string &this_variable,
75 const std::vector<std::shared_ptr<jimple_expr>> &parameters,
76 const expr2tc &lhs,
77 const std::string &class_name,
78 const std::string &function_name);
79};
80
88{
89public:
90 jimple_constant() = default;
91 explicit jimple_constant(const std::string &value) : value(value)
92 {
93 }
94 virtual void from_json(const json &j) override;
95 virtual std::string to_string() const override
96 {
97 return value;
98 }
99
100 virtual void setValue(const std::string &v)
101 {
102 value = v;
103 }
104 virtual expr2tc to_expr2t(
105 contextt &ctx,
106 const std::string &class_name,
107 const std::string &function_name) const override;
108
109 std::string value;
110};
111
124{
125public:
126 jimple_symbol() = default;
127 explicit jimple_symbol(std::string name) : var_name(name)
128 {
129 }
130 virtual void from_json(const json &j) override;
131 virtual std::string to_string() const override
132 {
133 return var_name;
134 }
135 virtual expr2tc to_expr2t(
136 contextt &ctx,
137 const std::string &class_name,
138 const std::string &function_name) const override;
139
140 const std::string &getVarName() const
141 {
142 return var_name;
143 }
144
145protected:
146 std::string var_name;
147};
148
156{
157public:
158 virtual void from_json(const json &j) override;
159 virtual std::string to_string() const override
160 {
161 return "Jimple BinOP";
162 }
163
164 virtual expr2tc to_expr2t(
165 contextt &ctx,
166 const std::string &class_name,
167 const std::string &function_name) const override;
168
169 std::string binop;
170 std::shared_ptr<jimple_expr> lhs;
171 std::shared_ptr<jimple_expr> rhs;
172};
173
180{
181public:
182 virtual void from_json(const json &j) override;
183 virtual std::string to_string() const override
184 {
185 return "Jimple Cast";
186 }
187
188 virtual expr2tc to_expr2t(
189 contextt &ctx,
190 const std::string &class_name,
191 const std::string &function_name) const override;
192
193 std::string var_name;
194 std::shared_ptr<jimple_expr> from;
195 std::shared_ptr<jimple_type> to;
196};
197
205{
206public:
207 virtual void from_json(const json &j) override;
208 virtual std::string to_string() const override
209 {
210 return "Jimple Lengthof";
211 }
212
213 virtual expr2tc to_expr2t(
214 contextt &ctx,
215 const std::string &class_name,
216 const std::string &function_name) const override;
217
218 std::shared_ptr<jimple_expr> from;
219};
220
230{
231public:
232 virtual void from_json(const json &j) override;
233 virtual std::string to_string() const override
234 {
235 return "Jimple New array";
236 }
237
238 virtual expr2tc to_expr2t(
239 contextt &ctx,
240 const std::string &class_name,
241 const std::string &function_name) const override;
242
243 std::shared_ptr<jimple_type> type;
244 std::shared_ptr<jimple_expr> size;
245};
246
254{
255public:
256 virtual void from_json(const json &j) override;
257 virtual std::string to_string() const override
258 {
259 return "Jimple Invoke";
260 }
261
262 virtual expr2tc to_expr2t(
263 contextt &ctx,
264 const std::string &class_name,
265 const std::string &function_name) const override;
266
267 std::string base_class;
268 std::string method;
270 std::vector<std::shared_ptr<jimple_expr>> parameters;
271
272 void set_lhs(const expr2tc &expr)
273 {
274 lhs = expr;
275 }
276
277 bool is_nondet_call() const
278 {
279 return base_class == "org.sosy_lab.sv_benchmarks.Verifier";
280 }
281
283
284protected:
285 // We need an unique name for each function
286 std::string get_hash_name() const
287 {
288 return std::to_string(parameters.size());
289 }
290};
291
299{
300public:
301 virtual void from_json(const json &j) override;
302 virtual std::string to_string() const override
303 {
304 return "Jimple Virtual Invoke";
305 }
306
307 virtual expr2tc to_expr2t(
308 contextt &ctx,
309 const std::string &class_name,
310 const std::string &function_name) const override;
311
312 std::string base_class;
313 std::string method;
315 std::string variable;
316 std::vector<std::shared_ptr<jimple_expr>> parameters;
317
318 void set_lhs(const expr2tc &expr)
319 {
320 lhs = expr;
321 }
322
323 bool is_nondet_call() const
324 {
325 return base_class == "java.util.Random";
326 }
327
328protected:
329 // We need an unique name for each function
330 std::string get_hash_name() const
331 {
332 return std::to_string(parameters.size() + 1);
333 }
334};
335
355{
356public:
357 virtual void from_json(const json &j) override;
358 virtual std::string to_string() const override
359 {
360 return "Jimple New";
361 }
362};
363
374{
375public:
376 jimple_deref() = default;
378 std::shared_ptr<jimple_expr> index,
379 std::shared_ptr<jimple_expr> base)
380 : index(index), base(base)
381 {
382 }
383 virtual void from_json(const json &j) override;
384 virtual std::string to_string() const override
385 {
386 return "Jimple Deref";
387 }
388
389 virtual expr2tc to_expr2t(
390 contextt &ctx,
391 const std::string &class_name,
392 const std::string &function_name) const override;
393
394 std::shared_ptr<jimple_expr> index;
395 std::shared_ptr<jimple_expr> base;
396};
397
403{
404public:
405 jimple_nondet() = default;
406 explicit jimple_nondet(std::string mode) : mode(mode)
407 {
408 }
409 virtual std::string to_string() const override
410 {
411 return "Jimple Nondet";
412 }
413 virtual void from_json(const json &) override
414 {
415 assert("This class shouldn't be used from Jimple directly");
416 abort();
417 }
418
419 const std::string mode; // Int, char, long, etc... e.g. Random().nextInt()
420 virtual expr2tc to_expr2t(
421 contextt &ctx,
422 const std::string &class_name,
423 const std::string &function_name) const override;
424};
425
436{
437public:
438 virtual std::string to_string() const override
439 {
440 return "Jimple Static Member";
441 }
442 virtual void from_json(const json &j) override;
443
444 virtual expr2tc to_expr2t(
445 contextt &ctx,
446 const std::string &class_name,
447 const std::string &function_name) const override;
448
449 std::string from;
450 std::string field;
451 std::shared_ptr<jimple_type> type;
452};
453
464{
465public:
466 virtual std::string to_string() const override
467 {
468 return "Jimple Virtual Member";
469 }
470 virtual void from_json(const json &j) override;
471 virtual expr2tc to_expr2t(
472 contextt &ctx,
473 const std::string &class_name,
474 const std::string &function_name) const override;
475
476 std::string variable;
477 std::string from;
478 std::string field;
479 std::shared_ptr<jimple_type> type;
480};
Definition context.h:57
Definition expr.h:34
Base interface for Jimple AST.
Definition jimple_ast.h:19
A binary operation.
Definition jimple_expr.h:156
std::shared_ptr< jimple_expr > lhs
Definition jimple_expr.h:170
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:238
std::string binop
Definition jimple_expr.h:169
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:159
std::shared_ptr< jimple_expr > rhs
Definition jimple_expr.h:171
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:163
A cast operation.
Definition jimple_expr.h:180
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:183
std::string var_name
Definition jimple_expr.h:193
std::shared_ptr< jimple_type > to
Definition jimple_expr.h:195
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:273
std::shared_ptr< jimple_expr > from
Definition jimple_expr.h:194
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:281
std::string value
Definition jimple_expr.h:109
jimple_constant()=default
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:11
jimple_constant(const std::string &value)
Definition jimple_expr.h:91
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:95
virtual void setValue(const std::string &v)
Definition jimple_expr.h:100
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:20
std::shared_ptr< jimple_expr > base
Definition jimple_expr.h:395
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:517
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:384
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:511
jimple_deref(std::shared_ptr< jimple_expr > index, std::shared_ptr< jimple_expr > base)
Definition jimple_expr.h:377
std::shared_ptr< jimple_expr > index
Definition jimple_expr.h:394
jimple_deref()=default
The result of a function call.
Definition jimple_expr.h:254
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:411
bool is_intrinsic_method
Definition jimple_expr.h:282
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:257
std::string get_hash_name() const
Definition jimple_expr.h:286
expr2tc lhs
Definition jimple_expr.h:269
std::string base_class
Definition jimple_expr.h:267
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:330
std::vector< std::shared_ptr< jimple_expr > > parameters
Definition jimple_expr.h:270
bool is_nondet_call() const
Definition jimple_expr.h:277
std::string method
Definition jimple_expr.h:268
void set_lhs(const expr2tc &expr)
Definition jimple_expr.h:272
Base interface to hold jimple expressions.
Definition jimple_expr.h:12
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const
The IREP2 form of this expression.
Definition jimple_expr.h:30
static expr2tc lower_invoke2t(contextt &ctx, const std::string &base_class, const std::string &method, const std::string &this_variable, const std::vector< std::shared_ptr< jimple_expr > > &parameters, const expr2tc &lhs, const std::string &class_name, const std::string &function_name)
Lower an invoke to the block both invoke forms produce.
Definition jimple_expr.cpp:366
virtual exprt to_exprt(contextt &, const std::string &, const std::string &) const
Definition jimple_expr.h:15
static std::shared_ptr< jimple_expr > get_expression(const json &j)
Recursively explores and initializes a jimple_expression.
Definition jimple_expr.cpp:42
Get the number of elements of an array (not bits/bytes).
Definition jimple_expr.h:205
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:208
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:292
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:297
std::shared_ptr< jimple_expr > from
Definition jimple_expr.h:218
Allocates a type.
Definition jimple_expr.h:355
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:358
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:322
Allocates a new array (dynamic).
Definition jimple_expr.h:230
std::shared_ptr< jimple_expr > size
Definition jimple_expr.h:244
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:233
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:314
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:472
std::shared_ptr< jimple_type > type
Definition jimple_expr.h:243
jimple_nondet()=default
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:534
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:409
const std::string mode
Definition jimple_expr.h:419
virtual void from_json(const json &) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.h:413
jimple_nondet(std::string mode)
Definition jimple_expr.h:406
A static member of object/class.
Definition jimple_expr.h:436
std::shared_ptr< jimple_type > type
Definition jimple_expr.h:451
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:542
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:567
std::string field
Definition jimple_expr.h:450
std::string from
Definition jimple_expr.h:449
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:438
const std::string & getVarName() const
Definition jimple_expr.h:140
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:131
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:28
std::string var_name
Definition jimple_expr.h:146
jimple_symbol()=default
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:33
jimple_symbol(std::string name)
Definition jimple_expr.h:127
The result of a function call.
Definition jimple_expr.h:299
std::string base_class
Definition jimple_expr.h:312
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:434
std::string variable
Definition jimple_expr.h:315
std::string method
Definition jimple_expr.h:313
bool is_nondet_call() const
Definition jimple_expr.h:323
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:302
std::vector< std::shared_ptr< jimple_expr > > parameters
Definition jimple_expr.h:316
std::string get_hash_name() const
Definition jimple_expr.h:330
expr2tc lhs
Definition jimple_expr.h:314
void set_lhs(const expr2tc &expr)
Definition jimple_expr.h:318
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:447
A virtual member of object.
Definition jimple_expr.h:464
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_expr.cpp:585
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_expr.h:466
std::string variable
Definition jimple_expr.h:476
std::string from
Definition jimple_expr.h:477
virtual expr2tc to_expr2t(contextt &ctx, const std::string &class_name, const std::string &function_name) const override
The IREP2 form of this expression.
Definition jimple_expr.cpp:551
std::shared_ptr< jimple_type > type
Definition jimple_expr.h:479
std::string field
Definition jimple_expr.h:478
irep_container< expr2t > expr2tc
Definition irep2.h:431
nlohmann::json json
Definition json.cpp:12
void migrate_expr(const exprt &expr, expr2tc &new_expr_ref)
Definition migrate.cpp:1512
void abort(void)
Definition stdlib.c:77