ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
jimple_type.h
Go to the documentation of this file.
1#ifndef ESBMC_JIMPLE_TYPE_H
2#define ESBMC_JIMPLE_TYPE_H
3
5#include <irep2/irep2_type.h>
6#include <irep2/irep2_utils.h>
7#include <util/irep/migrate.h>
9#include <util/lang/c_types.h>
10#include <util/expr/expr_util.h>
11
12// TODO: Specialize this class
13class jimple_type : public jimple_ast
14{
15public:
16 virtual void from_json(const json &j) override;
17 virtual std::string to_string() const override;
18 virtual typet to_typet(const contextt &ctx) const;
19
28 virtual type2tc to_type2t(const contextt &ctx) const;
29
30 bool is_array() const
31 {
32 return dimensions > 0;
33 }
34
35 std::string name; // e.g. int[][][][][] => name = int
36 short dimensions; // e.g. int[][][][][] => dimensions = 5
37
38protected:
39 typet get_base_type(const contextt &ctx) const;
40 type2tc get_base_type2(const contextt &ctx) const;
42
43 typet get_arr_type(const contextt &ctx) const
44 {
46 typet ptr_type = pointer_typet(base);
47 for (int i = 1; i < dimensions; i++)
48 ptr_type = pointer_typet(ptr_type);
49
50 return ptr_type;
51 }
52
53 type2tc get_arr_type2(const contextt &ctx) const
54 {
55 type2tc ptr_type = pointer_type2tc(get_base_type2(ctx));
56 for (int i = 1; i < dimensions; i++)
57 ptr_type = pointer_type2tc(ptr_type);
58
59 return ptr_type;
60 }
61
62private:
63 enum class BASE_TYPES
64 {
65 INT,
66 BOOLEAN,
67 _VOID,
68 OTHER
69 };
70 BASE_TYPES bt;
71 std::map<std::string, BASE_TYPES> from_map = {
72 /* Basic JVM types */
73 {"int", BASE_TYPES::INT},
74 {"byte", BASE_TYPES::INT},
75 {"char", BASE_TYPES::INT},
76 {"short", BASE_TYPES::INT},
77 {"boolean", BASE_TYPES::INT},
78 {"long", BASE_TYPES::INT},
79 {"float", BASE_TYPES::INT},
80 {"double", BASE_TYPES::INT},
81 {"void", BASE_TYPES::_VOID},
82 /* Basic Java classes that can work as primitive types */
83 {"java.lang.Integer", BASE_TYPES::INT},
84 {"java.util.Random", BASE_TYPES::INT}, // We dont really care about the
85 // initialization of this mode
86 {"java.lang.String", BASE_TYPES::INT}, // TODO: handle this properly
87 /* TODO: these are hacks and should be moved into an intrinsics class */
88 {"Main", BASE_TYPES::INT}, // TODO: handle this properly
89 {"java.lang.AssertionError", BASE_TYPES::INT}, // TODO: handle this properly
90 {"java.lang.Runtime", BASE_TYPES::INT}, // TODO: handle this properly
91 {"java.lang.Class", BASE_TYPES::INT}, // TODO: handle this properly
92 {"__other", BASE_TYPES::OTHER}};
93};
94
95#endif // ESBMC_JIMPLE_TYPE_H
static const twodig_t base
Definition bigint.cpp:28
Definition context.h:57
Base interface for Jimple AST.
Definition jimple_ast.h:19
Definition jimple_type.h:14
short dimensions
Definition jimple_type.h:36
std::string name
Definition jimple_type.h:35
virtual void from_json(const json &j) override
Initializes the current instance by parsing a JSON.
Definition jimple_type.cpp:3
virtual typet to_typet(const contextt &ctx) const
Definition jimple_type.cpp:32
virtual type2tc to_type2t(const contextt &ctx) const
IREP2 form of to_typet, for the natively-built expressions and for the declaration sites.
Definition jimple_type.cpp:61
typet get_arr_type(const contextt &ctx) const
Definition jimple_type.h:43
typet get_base_type(const contextt &ctx) const
Definition jimple_type.cpp:11
type2tc get_arr_type2(const contextt &ctx) const
Definition jimple_type.h:53
typet get_builtin_type() const
virtual std::string to_string() const override
Converts the object into a string.
Definition jimple_type.cpp:68
type2tc get_base_type2(const contextt &ctx) const
Definition jimple_type.cpp:39
bool is_array() const
Definition jimple_type.h:30
Definition std_types.h:438
Definition type.h:9
@ OTHER
Definition goto_program.h:33
irep_container< type2t > type2tc
Definition irep2.h:430
nlohmann::json json
Definition json.cpp:12
@ INT
Definition ld_ast.h:174