CBMC
java_bytecode_typecheck_type.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/invariant.h>
15 #include <util/std_types.h>
16 
17 #include "java_types.h"
18 
20 {
21  if(type.id() == ID_struct_tag)
22  {
23  irep_idt identifier = to_struct_tag_type(type).get_identifier();
24 
25  auto type_symbol = symbol_table.lookup(identifier);
27  type_symbol, "symbol " + id2string(identifier) + " must exist already");
29  type_symbol->is_type,
30  "symbol " + id2string(identifier) + " must be a type");
31  }
32  else if(type.id()==ID_pointer)
33  {
34  typecheck_type(to_pointer_type(type).base_type());
35  }
36  else if(type.id()==ID_array)
37  {
38  typecheck_type(to_array_type(type).element_type());
39  typecheck_expr(to_array_type(type).size());
40  }
41  else if(type.id()==ID_code)
42  {
43  java_method_typet &method_type = to_java_method_type(type);
44  typecheck_type(method_type.return_type());
45 
46  java_method_typet::parameterst &parameters = method_type.parameters();
47 
48  for(java_method_typet::parameterst::iterator it = parameters.begin();
49  it != parameters.end();
50  it++)
51  typecheck_type(it->type());
52  }
53 }
54 
56 {
58  symbol.is_type, "symbol " + id2string(symbol.name) + " must be a type");
59 
60  symbol.mode = ID_java;
61  typecheck_type(symbol.type);
62 }
tag_typet::get_identifier
const irep_idt & get_identifier() const
Definition: std_types.h:410
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
typet
The type of an expression, extends irept.
Definition: type.h:28
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
invariant.h
java_method_typet::parameterst
std::vector< parametert > parameterst
Definition: std_types.h:541
java_bytecode_typecheckt::typecheck_type
void typecheck_type(typet &)
Definition: java_bytecode_typecheck_type.cpp:19
java_bytecode_typecheckt::typecheck_type_symbol
void typecheck_type_symbol(symbolt &)
Definition: java_bytecode_typecheck_type.cpp:55
symbolt::mode
irep_idt mode
Language mode.
Definition: symbol.h:49
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:510
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:47
std_types.h
to_pointer_type
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: pointer_expr.h:79
java_bytecode_typecheckt::symbol_table
symbol_table_baset & symbol_table
Definition: java_bytecode_typecheck.h:60
irept::id
const irep_idt & id() const
Definition: irep.h:396
to_struct_tag_type
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:474
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:655
symbolt
Symbol table entry.
Definition: symbol.h:27
symbolt::is_type
bool is_type
Definition: symbol.h:61
to_array_type
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Definition: std_types.h:844
symbol_table_baset::lookup
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Definition: symbol_table_base.h:95
code_typet::return_type
const typet & return_type() const
Definition: std_types.h:645
java_types.h
to_java_method_type
const java_method_typet & to_java_method_type(const typet &type)
Definition: java_types.h:184
java_method_typet
Definition: java_types.h:100
symbolt::name
irep_idt name
The unique identifier.
Definition: symbol.h:40
java_bytecode_typecheck.h
java_bytecode_typecheckt::typecheck_expr
virtual void typecheck_expr(exprt &expr)
Definition: java_bytecode_typecheck_expr.cpp:22