cprover
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 
13 
14 #include <util/std_types.h>
15 #include <util/prefix.h>
16 #include <util/config.h>
17 
18 #include "expr2java.h"
19 
21 {
22  return expr2java(expr, ns);
23 }
24 
26 {
27  return type2java(type, ns);
28 }
29 
31 {
32  assert(!symbol.is_type);
33  typecheck_type(symbol.type);
34  typecheck_expr(symbol.value);
35 }
36 
38 {
39  // The hash table iterators are not stable,
40  // and we might add new symbols.
42  identifiers.reserve(symbol_table.symbols.size());
43  for(const auto &symbol_pair : symbol_table.symbols)
44  identifiers.insert(symbol_pair.first);
45  typecheck(identifiers);
46 }
47 
49  const journalling_symbol_tablet::changesett &identifiers)
50 {
51  // We first check all type symbols,
52  // recursively doing base classes first.
53  for(const irep_idt &id : identifiers)
54  {
56  if(symbol.is_type)
57  typecheck_type_symbol(symbol);
58  }
59  // We now check all non-type symbols
60  for(const irep_idt &id : identifiers)
61  {
63  if(!symbol.is_type)
65  }
66 }
67 
69  symbol_table_baset &symbol_table,
70  message_handlert &message_handler,
71  bool string_refinement_enabled)
72 {
74  symbol_table, message_handler, string_refinement_enabled);
75  return java_bytecode_typecheck.typecheck_main();
76 }
77 
79  journalling_symbol_tablet &symbol_table,
80  message_handlert &message_handler,
81  bool string_refinement_enabled)
82 {
84  symbol_table, message_handler, string_refinement_enabled);
85  return java_bytecode_typecheck.typecheck(symbol_table.get_updated());
86 }
87 
89  exprt &expr,
90  message_handlert &message_handler,
91  const namespacet &ns)
92 {
93 #if 0
94  symbol_tablet symbol_table;
95  java_bytecode_parse_treet java_bytecode_parse_tree;
96 
98  java_bytecode_parse_tree, symbol_table,
99  "", message_handler);
100 
101  try
102  {
103  java_bytecode_typecheck.typecheck_expr(expr);
104  }
105 
106  catch(int e)
107  {
108  java_bytecode_typecheck.error();
109  }
110 
111  catch(const char *e)
112  {
113  java_bytecode_typecheck.error(e);
114  }
115 
116  catch(const std::string &e)
117  {
118  java_bytecode_typecheck.error(e);
119  }
120 
121  return java_bytecode_typecheck.get_error_found();
122 #else
123  // unused parameters
124  (void)expr;
125  (void)message_handler;
126  (void)ns;
127 #endif
128 
129  // fail for now
130  return true;
131 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
symbol_tablet
The symbol table.
Definition: symbol_table.h:20
java_bytecode_parse_treet
Definition: java_bytecode_parse_tree.h:24
java_bytecode_typecheckt::to_string
virtual std::string to_string(const exprt &expr)
Definition: java_bytecode_typecheck.cpp:20
typet
The type of an expression, extends irept.
Definition: type.h:29
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
prefix.h
journalling_symbol_tablet::get_updated
const changesett & get_updated() const
Definition: journalling_symbol_table.h:150
exprt
Base class for all expressions.
Definition: expr.h:53
java_bytecode_typecheckt::typecheck_type
void typecheck_type(typet &)
Definition: java_bytecode_typecheck_type.cpp:17
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
java_bytecode_typecheckt::typecheck_type_symbol
void typecheck_type_symbol(symbolt &)
Definition: java_bytecode_typecheck_type.cpp:53
java_bytecode_typecheckt::ns
const namespacet ns
Definition: java_bytecode_typecheck.h:64
symbol_table_baset::get_writeable_ref
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
Definition: symbol_table_base.h:121
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:22
std_types.h
Pre-defined types.
journalling_symbol_tablet::changesett
std::unordered_set< irep_idt > changesett
Definition: journalling_symbol_table.h:38
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:78
java_bytecode_typecheckt::symbol_table
symbol_table_baset & symbol_table
Definition: java_bytecode_typecheck.h:63
message_handlert
Definition: message.h:28
java_bytecode_typecheckt::typecheck_non_type_symbol
void typecheck_non_type_symbol(symbolt &)
Definition: java_bytecode_typecheck.cpp:30
java_bytecode_typecheckt::typecheck
virtual void typecheck()
Definition: java_bytecode_typecheck.cpp:37
java_bytecode_typecheckt
Definition: java_bytecode_typecheck.h:43
symbolt::value
exprt value
Initial value of symbol.
Definition: symbol.h:34
symbolt
Symbol table entry.
Definition: symbol.h:28
symbol_table_baset::symbols
const symbolst & symbols
Read-only field, used to look up symbols given their names.
Definition: symbol_table_base.h:30
symbolt::is_type
bool is_type
Definition: symbol.h:61
type2java
std::string type2java(const typet &type, const namespacet &ns)
Definition: expr2java.cpp:462
config.h
expr2java
std::string expr2java(const exprt &expr, const namespacet &ns)
Definition: expr2java.cpp:455
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:68
expr2java.h
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:36
java_bytecode_typecheck.h
JAVA Bytecode Language Type Checking.
java_bytecode_typecheckt::typecheck_expr
virtual void typecheck_expr(exprt &expr)
Definition: java_bytecode_typecheck_expr.cpp:26