CBMC
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 "expr2java.h"
15 
17 {
18  return expr2java(expr, ns);
19 }
20 
22 {
23  return type2java(type, ns);
24 }
25 
27 {
28  assert(!symbol.is_type);
29  typecheck_type(symbol.type);
30  typecheck_expr(symbol.value);
31 }
32 
34 {
35  // The hash table iterators are not stable,
36  // and we might add new symbols.
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 
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  {
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  {
59  if(!symbol.is_type)
61  }
62 }
63 
65  symbol_table_baset &symbol_table,
66  message_handlert &message_handler,
67  bool string_refinement_enabled)
68 {
70  symbol_table, message_handler, string_refinement_enabled);
71  return java_bytecode_typecheck.typecheck_main();
72 }
73 
75  journalling_symbol_tablet &symbol_table,
76  message_handlert &message_handler,
77  bool string_refinement_enabled)
78 {
80  symbol_table, message_handler, string_refinement_enabled);
81  return java_bytecode_typecheck.typecheck(symbol_table.get_updated());
82 }
83 
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 
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 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
java_bytecode_parse_treet
Definition: java_bytecode_parse_tree.h:22
java_bytecode_typecheckt::to_string
virtual std::string to_string(const exprt &expr)
Definition: java_bytecode_typecheck.cpp:16
typet
The type of an expression, extends irept.
Definition: type.h:28
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
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:55
java_bytecode_typecheckt::typecheck_type
void typecheck_type(typet &)
Definition: java_bytecode_typecheck_type.cpp:19
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
java_bytecode_typecheckt::typecheck_type_symbol
void typecheck_type_symbol(symbolt &)
Definition: java_bytecode_typecheck_type.cpp:55
java_bytecode_typecheckt::ns
const namespacet ns
Definition: java_bytecode_typecheck.h:61
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:21
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:74
java_bytecode_typecheckt::symbol_table
symbol_table_baset & symbol_table
Definition: java_bytecode_typecheck.h:60
message_handlert
Definition: message.h:27
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
Definition: java_bytecode_typecheck.h:39
symbolt::value
exprt value
Initial value of symbol.
Definition: symbol.h:34
symbolt
Symbol table entry.
Definition: symbol.h:27
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:457
expr2java
std::string expr2java(const exprt &expr, const namespacet &ns)
Definition: expr2java.cpp:450
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
expr2java.h
journalling_symbol_tablet
A symbol table wrapper that records which entries have been updated/removed.
Definition: journalling_symbol_table.h:35
java_bytecode_typecheck.h
java_bytecode_typecheckt::typecheck_expr
virtual void typecheck_expr(exprt &expr)
Definition: java_bytecode_typecheck_expr.cpp:22