cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
java_bytecode_typecheck.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: JAVA Bytecode Conversion / Type Checking
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
11
12
#include "
java_bytecode_typecheck.h
"
13
14
#include "
expr2java.h
"
15
16
std::string
java_bytecode_typecheckt::to_string
(
const
exprt
&expr)
17
{
18
return
expr2java
(expr,
ns
);
19
}
20
21
std::string
java_bytecode_typecheckt::to_string
(
const
typet
&type)
22
{
23
return
type2java
(type,
ns
);
24
}
25
26
void
java_bytecode_typecheckt::typecheck_non_type_symbol
(
symbolt
&symbol)
27
{
28
PRECONDITION
(!symbol.
is_type
);
29
typecheck_type
(symbol.
type
);
30
typecheck_expr
(symbol.
value
);
31
}
32
33
void
java_bytecode_typecheckt::typecheck
()
34
{
35
// The hash table iterators are not stable,
36
// and we might add new symbols.
37
journalling_symbol_tablet::changesett
identifiers;
38
identifiers.reserve(
symbol_table
.symbols.size());
39
for
(
const
auto
&symbol_pair :
symbol_table
.symbols)
40
identifiers.insert(symbol_pair.first);
41
typecheck
(identifiers);
42
}
43
44
void
java_bytecode_typecheckt::typecheck
(
45
const
journalling_symbol_tablet::changesett
&identifiers)
46
{
47
// We first check all type symbols,
48
// recursively doing base classes first.
49
for
(
const
irep_idt
&
id
: identifiers)
50
{
51
symbolt
&symbol =
symbol_table
.get_writeable_ref(
id
);
52
if
(symbol.
is_type
)
53
typecheck_type_symbol
(symbol);
54
}
55
// We now check all non-type symbols
56
for
(
const
irep_idt
&
id
: identifiers)
57
{
58
symbolt
&symbol =
symbol_table
.get_writeable_ref(
id
);
59
if
(!symbol.
is_type
)
60
typecheck_non_type_symbol
(symbol);
61
}
62
}
63
64
bool
java_bytecode_typecheck
(
65
symbol_table_baset
&symbol_table,
66
message_handlert
&message_handler,
67
bool
string_refinement_enabled)
68
{
69
java_bytecode_typecheckt
java_bytecode_typecheck
(
70
symbol_table, message_handler, string_refinement_enabled);
71
return
java_bytecode_typecheck
.typecheck_main();
72
}
73
74
void
java_bytecode_typecheck_updated_symbols
(
75
journalling_symbol_tablet
&symbol_table,
76
message_handlert
&message_handler,
77
bool
string_refinement_enabled)
78
{
79
java_bytecode_typecheckt
java_bytecode_typecheck
(
80
symbol_table, message_handler, string_refinement_enabled);
81
return
java_bytecode_typecheck
.typecheck(symbol_table.
get_updated
());
82
}
83
84
bool
java_bytecode_typecheck
(
85
exprt
&expr,
86
message_handlert
&message_handler,
87
const
namespacet
&ns)
88
{
89
#if 0
90
symbol_tablet
symbol_table;
91
java_bytecode_parse_treet
java_bytecode_parse_tree;
92
93
java_bytecode_typecheckt
java_bytecode_typecheck
(
94
java_bytecode_parse_tree, symbol_table,
95
""
, message_handler);
96
97
try
98
{
99
java_bytecode_typecheck
.typecheck_expr(expr);
100
}
101
102
catch
(
int
e)
103
{
104
java_bytecode_typecheck
.error();
105
}
106
107
catch
(
const
char
*e)
108
{
109
java_bytecode_typecheck
.error(e);
110
}
111
112
catch
(
const
std::string &e)
113
{
114
java_bytecode_typecheck
.error(e);
115
}
116
117
return
java_bytecode_typecheck
.get_error_found();
118
#else
119
// unused parameters
120
(void)expr;
121
(void)message_handler;
122
(void)ns;
123
#endif
124
125
// fail for now
126
return
true
;
127
}
exprt
Base class for all expressions.
Definition
expr.h:57
java_bytecode_typecheckt
Definition
java_bytecode_typecheck.h:40
java_bytecode_typecheckt::typecheck_type_symbol
void typecheck_type_symbol(symbolt &)
Definition
java_bytecode_typecheck_type.cpp:55
java_bytecode_typecheckt::typecheck_type
void typecheck_type(typet &)
Definition
java_bytecode_typecheck_type.cpp:19
java_bytecode_typecheckt::to_string
virtual std::string to_string(const exprt &expr)
Definition
java_bytecode_typecheck.cpp:16
java_bytecode_typecheckt::typecheck_expr
virtual void typecheck_expr(exprt &expr)
Definition
java_bytecode_typecheck_expr.cpp:20
java_bytecode_typecheckt::typecheck_non_type_symbol
void typecheck_non_type_symbol(symbolt &)
Definition
java_bytecode_typecheck.cpp:26
java_bytecode_typecheckt::typecheck
virtual void typecheck()
Definition
java_bytecode_typecheck.cpp:33
java_bytecode_typecheckt::ns
const namespacet ns
Definition
java_bytecode_typecheck.h:61
java_bytecode_typecheckt::symbol_table
symbol_table_baset & symbol_table
Definition
java_bytecode_typecheck.h:60
journalling_symbol_tablet
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
Definition
journalling_symbol_table.h:37
journalling_symbol_tablet::changesett
std::unordered_set< irep_idt > changesett
Definition
journalling_symbol_table.h:39
journalling_symbol_tablet::get_updated
const changesett & get_updated() const
Definition
journalling_symbol_table.h:157
message_handlert
Definition
message.h:27
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
symbol_table_baset
The symbol table base class interface.
Definition
symbol_table_base.h:23
symbol_tablet
The symbol table.
Definition
symbol_table.h:14
symbolt
Symbol table entry.
Definition
symbol.h:28
symbolt::is_type
bool is_type
Definition
symbol.h:61
symbolt::type
typet type
Type of symbol.
Definition
symbol.h:31
symbolt::value
exprt value
Initial value of symbol.
Definition
symbol.h:34
typet
The type of an expression, extends irept.
Definition
type.h:29
type2java
std::string type2java(const typet &type, const namespacet &ns)
Definition
expr2java.cpp:461
expr2java
std::string expr2java(const exprt &expr, const namespacet &ns)
Definition
expr2java.cpp:454
expr2java.h
java_bytecode_typecheck
bool java_bytecode_typecheck(symbol_table_baset &symbol_table, message_handlert &message_handler, bool string_refinement_enabled)
Definition
java_bytecode_typecheck.cpp:64
java_bytecode_typecheck_updated_symbols
void java_bytecode_typecheck_updated_symbols(journalling_symbol_tablet &symbol_table, message_handlert &message_handler, bool string_refinement_enabled)
Definition
java_bytecode_typecheck.cpp:74
java_bytecode_typecheck.h
JAVA Bytecode Language Type Checking.
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
java_bytecode_parse_treet
Definition
java_bytecode_parse_tree.h:23
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
jbmc
src
java_bytecode
java_bytecode_typecheck.cpp
Generated by
1.17.0