Skip to content

Commit e3e44c8

Browse files
Do type-checking as a function pass
After convert each function in convert_lazy_method call instrument and typecheck
1 parent 2ba1364 commit e3e44c8

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

src/java_bytecode/java_bytecode_instrument.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ void java_bytecode_instrument_symbol(
598598
message_handler);
599599
INVARIANT(
600600
symbol.value.id()==ID_code,
601-
"java_bytecode_instrument expects a code-typed symbol");
601+
"java_bytecode_instrument expects a code-typed symbol but was called with"
602+
" " + id2string(symbol.name) + " which has a value with an id of " +
603+
id2string(symbol.value.id()));
602604
instrument(symbol.value);
603605
}
604606

src/java_bytecode/java_bytecode_language.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,33 @@ void java_bytecode_languaget::methods_provided(id_sett &methods) const
372372
/// to have a value representing the method body identical to that produced
373373
/// using eager method conversion.
374374
/// \param function_id: method ID to convert
375-
/// \param symbol_table: global symbol table
375+
/// \param symtab: global symbol table
376376
void java_bytecode_languaget::convert_lazy_method(
377377
const irep_idt &function_id,
378-
symbol_tablet &symbol_table)
378+
symbol_tablet &symtab)
379379
{
380+
const symbolt &symbol = symtab.lookup_ref(function_id);
381+
if(symbol.value.is_not_nil())
382+
return;
383+
384+
journalling_symbol_tablet symbol_table=
385+
journalling_symbol_tablet::wrap(symtab);
386+
380387
convert_single_method(function_id, symbol_table);
388+
389+
// Instrument runtime exceptions (unless symbol is a stub)
390+
if(symbol.value.is_not_nil())
391+
{
392+
java_bytecode_instrument_symbol(
393+
symbol_table,
394+
symbol_table.get_writeable_ref(function_id),
395+
throw_runtime_exceptions,
396+
get_message_handler());
397+
}
398+
399+
// now typecheck this function
400+
java_bytecode_typecheck_updated_symbols(
401+
symbol_table, get_message_handler(), string_refinement_enabled);
381402
}
382403

383404
/// \brief Convert a method (one whose type is known but whose body hasn't

src/java_bytecode/java_bytecode_typecheck.cpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,35 @@ void java_bytecode_typecheckt::typecheck()
3838
{
3939
// The hash table iterators are not stable,
4040
// and we might add new symbols.
41-
42-
std::vector<irep_idt> identifiers;
41+
journalling_symbol_tablet::changesett identifiers;
4342
identifiers.reserve(symbol_table.symbols.size());
4443
forall_symbols(s_it, symbol_table.symbols)
45-
identifiers.push_back(s_it->first);
44+
identifiers.insert(s_it->first);
45+
typecheck(identifiers);
46+
}
4647

48+
void java_bytecode_typecheckt::typecheck(
49+
const journalling_symbol_tablet::changesett &identifiers)
50+
{
4751
// We first check all type symbols,
4852
// recursively doing base classes first.
4953
for(const irep_idt &id : identifiers)
5054
{
5155
symbolt &symbol=*symbol_table.get_writeable(id);
52-
if(!symbol.is_type)
53-
continue;
54-
typecheck_type_symbol(symbol);
56+
if(symbol.is_type)
57+
typecheck_type_symbol(symbol);
5558
}
56-
5759
// We now check all non-type symbols
5860
for(const irep_idt &id : identifiers)
5961
{
6062
symbolt &symbol=*symbol_table.get_writeable(id);
61-
if(symbol.is_type)
62-
continue;
63-
typecheck_non_type_symbol(symbol);
63+
if(!symbol.is_type)
64+
typecheck_non_type_symbol(symbol);
6465
}
6566
}
6667

6768
bool java_bytecode_typecheck(
68-
symbol_tablet &symbol_table,
69+
symbol_table_baset &symbol_table,
6970
message_handlert &message_handler,
7071
bool string_refinement_enabled)
7172
{
@@ -74,6 +75,16 @@ bool java_bytecode_typecheck(
7475
return java_bytecode_typecheck.typecheck_main();
7576
}
7677

78+
void java_bytecode_typecheck_updated_symbols(
79+
journalling_symbol_tablet &symbol_table,
80+
message_handlert &message_handler,
81+
bool string_refinement_enabled)
82+
{
83+
java_bytecode_typecheckt java_bytecode_typecheck(
84+
symbol_table, message_handler, string_refinement_enabled);
85+
return java_bytecode_typecheck.typecheck(symbol_table.get_updated());
86+
}
87+
7788
bool java_bytecode_typecheck(
7889
exprt &expr,
7990
message_handlert &message_handler,

src/java_bytecode/java_bytecode_typecheck.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ Author: Daniel Kroening, [email protected]
1515
#include <set>
1616
#include <map>
1717

18-
#include <util/symbol_table.h>
18+
#include <util/journalling_symbol_table.h>
1919
#include <util/typecheck.h>
2020
#include <util/namespace.h>
2121
#include <util/std_code.h>
2222
#include <util/std_expr.h>
2323
#include <util/std_types.h>
2424

2525
bool java_bytecode_typecheck(
26-
symbol_tablet &symbol_table,
26+
symbol_table_baset &symbol_table,
27+
message_handlert &message_handler,
28+
bool string_refinement_enabled);
29+
30+
void java_bytecode_typecheck_updated_symbols(
31+
journalling_symbol_tablet &symbol_table,
2732
message_handlert &message_handler,
2833
bool string_refinement_enabled);
2934

@@ -36,7 +41,7 @@ class java_bytecode_typecheckt:public typecheckt
3641
{
3742
public:
3843
java_bytecode_typecheckt(
39-
symbol_tablet &_symbol_table,
44+
symbol_table_baset &_symbol_table,
4045
message_handlert &_message_handler,
4146
bool _string_refinement_enabled):
4247
typecheckt(_message_handler),
@@ -49,10 +54,11 @@ class java_bytecode_typecheckt:public typecheckt
4954
virtual ~java_bytecode_typecheckt() { }
5055

5156
virtual void typecheck();
57+
void typecheck(const journalling_symbol_tablet::changesett &identifiers);
5258
virtual void typecheck_expr(exprt &expr);
5359

5460
protected:
55-
symbol_tablet &symbol_table;
61+
symbol_table_baset &symbol_table;
5662
const namespacet ns;
5763
bool string_refinement_enabled;
5864

0 commit comments

Comments
 (0)