CBMC
java_bytecode_typecheck_code.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 
15 
16 #include <util/std_code.h>
17 
19 {
20  const irep_idt &statement=code.get_statement();
21 
22  if(statement==ID_assign)
23  {
25  typecheck_expr(code_assign.lhs());
26  typecheck_expr(code_assign.rhs());
27 
28  code_assign.rhs() = typecast_exprt::conditional_cast(
29  code_assign.rhs(), code_assign.lhs().type());
30  }
31  else if(statement==ID_block)
32  {
33  Forall_operands(it, code)
34  typecheck_code(to_code(*it));
35  }
36  else if(statement==ID_label)
37  {
38  code_labelt &code_label=to_code_label(code);
39  typecheck_code(code_label.code());
40  }
41  else if(statement==ID_goto)
42  {
43  }
44  else if(statement==ID_ifthenelse)
45  {
46  code_ifthenelset &code_ifthenelse=to_code_ifthenelse(code);
47  typecheck_expr(code_ifthenelse.cond());
48  typecheck_code(code_ifthenelse.then_case());
49  if(code_ifthenelse.else_case().is_not_nil())
50  typecheck_code(code_ifthenelse.else_case());
51  }
52  else if(statement==ID_switch)
53  {
54  code_switcht &code_switch = to_code_switch(code);
55  typecheck_expr(code_switch.value());
56  }
57  else if(statement==ID_return)
58  {
59  code_returnt &code_return = to_code_return(code);
60  typecheck_expr(code_return.return_value());
61  }
62  else if(statement==ID_function_call)
63  {
64  code_function_callt &code_function_call=to_code_function_call(code);
65  typecheck_expr(code_function_call.lhs());
66  typecheck_expr(code_function_call.function());
67 
68  for(code_function_callt::argumentst::iterator
69  a_it=code_function_call.arguments().begin();
70  a_it!=code_function_call.arguments().end();
71  a_it++)
72  typecheck_expr(*a_it);
73  }
74  else if(statement==ID_assert || statement==ID_assume)
75  {
76  typecheck_expr(code.op0());
77  }
78 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
typecast_exprt::conditional_cast
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition: std_expr.h:2025
to_code_function_call
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
Definition: goto_instruction_code.h:385
Forall_operands
#define Forall_operands(it, expr)
Definition: expr.h:27
codet::op0
exprt & op0()
Definition: expr.h:125
goto_instruction_code.h
code_ifthenelset::then_case
const codet & then_case() const
Definition: std_code.h:488
java_bytecode_typecheckt::typecheck_code
void typecheck_code(codet &)
Definition: java_bytecode_typecheck_code.cpp:18
code_ifthenelset::cond
const exprt & cond() const
Definition: std_code.h:478
code_function_callt::lhs
exprt & lhs()
Definition: goto_instruction_code.h:297
code_ifthenelset
codet representation of an if-then-else statement.
Definition: std_code.h:459
code_frontend_assignt::lhs
exprt & lhs()
Definition: std_code.h:41
code_labelt::code
codet & code()
Definition: std_code.h:977
to_code
const codet & to_code(const exprt &expr)
Definition: std_code_base.h:104
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:84
code_function_callt
goto_instruction_codet representation of a function call statement.
Definition: goto_instruction_code.h:271
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:380
code_frontend_assignt::rhs
exprt & rhs()
Definition: std_code.h:46
to_code_frontend_assign
const code_frontend_assignt & to_code_frontend_assign(const codet &code)
Definition: std_code.h:113
to_code_ifthenelse
const code_ifthenelset & to_code_ifthenelse(const codet &code)
Definition: std_code.h:530
code_labelt
codet representation of a label for branch targets.
Definition: std_code.h:958
to_code_label
const code_labelt & to_code_label(const codet &code)
Definition: std_code.h:1004
code_frontend_assignt
A codet representing an assignment in the program.
Definition: std_code.h:23
std_code.h
code_function_callt::arguments
argumentst & arguments()
Definition: goto_instruction_code.h:317
code_switcht::value
const exprt & value() const
Definition: std_code.h:555
code_returnt
goto_instruction_codet representation of a "return from a function" statement.
Definition: goto_instruction_code.h:494
code_switcht
codet representing a switch statement.
Definition: std_code.h:547
code_ifthenelset::else_case
const codet & else_case() const
Definition: std_code.h:498
to_code_switch
const code_switcht & to_code_switch(const codet &code)
Definition: std_code.h:592
code_returnt::return_value
const exprt & return_value() const
Definition: goto_instruction_code.h:502
codet::get_statement
const irep_idt & get_statement() const
Definition: std_code_base.h:65
to_code_return
const code_returnt & to_code_return(const goto_instruction_codet &code)
Definition: goto_instruction_code.h:537
code_function_callt::function
exprt & function()
Definition: goto_instruction_code.h:307
java_bytecode_typecheck.h
java_bytecode_typecheckt::typecheck_expr
virtual void typecheck_expr(exprt &expr)
Definition: java_bytecode_typecheck_expr.cpp:22
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:28