CBMC
jsil_typecheck.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Jsil Language
4 
5 Author: Michael Tautschnig, tautschn@amazon.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_JSIL_JSIL_TYPECHECK_H
13 #define CPROVER_JSIL_JSIL_TYPECHECK_H
14 
15 #include <unordered_set>
16 
17 #include <util/namespace.h>
18 #include <util/typecheck.h>
19 
20 class code_assignt;
22 class code_ifthenelset;
24 class code_try_catcht;
25 class codet;
26 class message_handlert;
28 class symbol_exprt;
29 class symbol_tablet;
30 
31 bool jsil_typecheck(
32  symbol_tablet &symbol_table,
33  message_handlert &message_handler);
34 
35 bool jsil_typecheck(
36  exprt &expr,
37  message_handlert &message_handler,
38  const namespacet &ns);
39 
41 {
42 public:
44  symbol_table_baset &_symbol_table,
45  message_handlert &_message_handler)
46  : typecheckt(_message_handler),
47  symbol_table(_symbol_table),
49  proc_name()
50  {
51  }
52 
53  virtual ~jsil_typecheckt() { }
54 
55  virtual void typecheck();
56  virtual void typecheck_expr(exprt &expr);
57 
58 protected:
60  const namespacet ns;
61  // prefix to variables which is set in typecheck_declaration
63 
64  void update_expr_type(exprt &expr, const typet &type);
65  void make_type_compatible(exprt &expr, const typet &type, bool must);
67  void typecheck_non_type_symbol(symbolt &symbol);
68  void typecheck_symbol_expr(symbol_exprt &symbol_expr);
70  void typecheck_expr_delete(exprt &expr);
71  void typecheck_expr_index(exprt &expr);
73  void typecheck_expr_proto_obj(exprt &expr);
74  void typecheck_expr_has_field(exprt &expr);
75  void typecheck_expr_ref(exprt &expr);
76  void typecheck_expr_field(exprt &expr);
77  void typecheck_expr_base(exprt &expr);
78  void typecheck_expr_constant(exprt &expr);
80  void typecheck_expr_subtype(exprt &expr);
87  void typecheck_expr_unary_num(exprt &expr);
88  void typecheck_expr_operands(exprt &expr);
89  void typecheck_expr_main(exprt &expr);
90  void typecheck_code(codet &code);
91  void typecheck_function_call(code_function_callt &function_call);
93  void typecheck_block(codet &code);
95  void typecheck_assign(code_assignt &code);
97  void typecheck_type(typet &type);
98  irep_idt add_prefix(const irep_idt &ds);
99 
100  // overload to use language-specific syntax
101  virtual std::string to_string(const exprt &expr);
102  virtual std::string to_string(const typet &type);
103 
104  std::unordered_set<irep_idt> already_typechecked;
105 };
106 
107 #endif // CPROVER_JSIL_JSIL_TYPECHECK_H
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
jsil_typecheckt::typecheck_expr_operands
void typecheck_expr_operands(exprt &expr)
Definition: jsil_typecheck.cpp:149
jsil_typecheckt::update_expr_type
void update_expr_type(exprt &expr, const typet &type)
Definition: jsil_typecheck.cpp:40
jsil_typecheckt::typecheck_expr_has_field
void typecheck_expr_has_field(exprt &expr)
Definition: jsil_typecheck.cpp:357
jsil_typecheckt::typecheck_expr_binary_compare
void typecheck_expr_binary_compare(exprt &expr)
Definition: jsil_typecheck.cpp:503
jsil_typecheckt::typecheck_expr_unary_string
void typecheck_expr_unary_string(exprt &expr)
Definition: jsil_typecheck.cpp:532
jsil_typecheckt::typecheck_expr_ref
void typecheck_expr_ref(exprt &expr)
Definition: jsil_typecheck.cpp:400
jsil_typecheckt::typecheck_function_call
void typecheck_function_call(code_function_callt &function_call)
Definition: jsil_typecheck.cpp:713
jsil_typecheckt::typecheck_return
void typecheck_return(code_frontend_returnt &)
Definition: jsil_typecheck.cpp:683
jsil_typecheckt::to_string
virtual std::string to_string(const exprt &expr)
Definition: jsil_typecheck.cpp:24
typet
The type of an expression, extends irept.
Definition: type.h:28
jsil_typecheckt::typecheck_assign
void typecheck_assign(code_assignt &code)
Definition: jsil_typecheck.cpp:827
jsil_typecheckt::typecheck_expr_base
void typecheck_expr_base(exprt &expr)
Definition: jsil_typecheck.cpp:386
code_try_catcht
codet representation of a try/catch block.
Definition: std_code.h:1985
jsil_typecheckt::typecheck_try_catch
void typecheck_try_catch(code_try_catcht &code)
Definition: jsil_typecheck.cpp:695
jsil_typecheckt
Definition: jsil_typecheck.h:40
jsil_typecheckt::typecheck_type
void typecheck_type(typet &type)
Definition: jsil_typecheck.cpp:102
jsil_typecheckt::~jsil_typecheckt
virtual ~jsil_typecheckt()
Definition: jsil_typecheck.h:53
jsil_typecheckt::typecheck_expr_index
void typecheck_expr_index(exprt &expr)
Definition: jsil_typecheck.cpp:336
exprt
Base class for all expressions.
Definition: expr.h:55
jsil_typecheckt::typecheck_code
void typecheck_code(codet &code)
Definition: jsil_typecheck.cpp:635
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:112
namespace.h
jsil_typecheckt::already_typechecked
std::unordered_set< irep_idt > already_typechecked
Definition: jsil_typecheck.h:104
code_ifthenelset
codet representation of an if-then-else statement.
Definition: std_code.h:459
jsil_typecheckt::typecheck_expr_side_effect_throw
void typecheck_expr_side_effect_throw(side_effect_expr_throwt &expr)
Definition: jsil_typecheck.cpp:272
jsil_typecheckt::typecheck_expr_unary_num
void typecheck_expr_unary_num(exprt &expr)
Definition: jsil_typecheck.cpp:546
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
code_function_callt
goto_instruction_codet representation of a function call statement.
Definition: goto_instruction_code.h:271
jsil_typecheckt::typecheck_non_type_symbol
void typecheck_non_type_symbol(symbolt &symbol)
typechecking procedure declaration; any other symbols should have been typechecked during typecheckin...
Definition: jsil_typecheck.cpp:838
jsil_typecheckt::typecheck_expr_main
void typecheck_expr_main(exprt &expr)
Definition: jsil_typecheck.cpp:155
typecheck.h
jsil_typecheckt::jsil_typecheckt
jsil_typecheckt(symbol_table_baset &_symbol_table, message_handlert &_message_handler)
Definition: jsil_typecheck.h:43
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:21
jsil_typecheckt::typecheck_expr_unary_boolean
void typecheck_expr_unary_boolean(exprt &expr)
Definition: jsil_typecheck.cpp:518
jsil_typecheckt::typecheck_expr_proto_field
void typecheck_expr_proto_field(exprt &expr)
Definition: jsil_typecheck.cpp:291
jsil_typecheckt::typecheck_ifthenelse
void typecheck_ifthenelse(code_ifthenelset &code)
Definition: jsil_typecheck.cpp:815
message_handlert
Definition: message.h:27
jsil_typecheckt::typecheck_expr_proto_obj
void typecheck_expr_proto_obj(exprt &expr)
Definition: jsil_typecheck.cpp:306
jsil_typecheckt::typecheck_expr
virtual void typecheck_expr(exprt &expr)
Definition: jsil_typecheck.cpp:140
jsil_typecheckt::typecheck_expr_binary_boolean
void typecheck_expr_binary_boolean(exprt &expr)
Definition: jsil_typecheck.cpp:459
jsil_typecheckt::typecheck_symbol_expr
void typecheck_symbol_expr(symbol_exprt &symbol_expr)
Definition: jsil_typecheck.cpp:558
code_frontend_returnt
codet representation of a "return from a function" statement.
Definition: std_code.h:892
jsil_typecheckt::symbol_table
symbol_table_baset & symbol_table
Definition: jsil_typecheck.h:59
jsil_typecheckt::typecheck_expr_constant
void typecheck_expr_constant(exprt &expr)
Definition: jsil_typecheck.cpp:281
jsil_typecheckt::ns
const namespacet ns
Definition: jsil_typecheck.h:60
jsil_typecheckt::typecheck_type_symbol
void typecheck_type_symbol(symbolt &)
Definition: jsil_typecheck.h:66
jsil_typecheckt::typecheck_expr_concatenation
void typecheck_expr_concatenation(exprt &expr)
Definition: jsil_typecheck.cpp:429
symbolt
Symbol table entry.
Definition: symbol.h:27
jsil_typecheckt::typecheck_block
void typecheck_block(codet &code)
Definition: jsil_typecheck.cpp:689
jsil_typecheckt::proc_name
irep_idt proc_name
Definition: jsil_typecheck.h:62
jsil_typecheckt::typecheck_expr_binary_arith
void typecheck_expr_binary_arith(exprt &expr)
Definition: jsil_typecheck.cpp:474
side_effect_expr_throwt
A side_effect_exprt representation of a side effect that throws an exception.
Definition: std_code.h:1756
jsil_typecheck
bool jsil_typecheck(symbol_tablet &symbol_table, message_handlert &message_handler)
Definition: jsil_typecheck.cpp:900
jsil_typecheckt::typecheck_expr_subtype
void typecheck_expr_subtype(exprt &expr)
Definition: jsil_typecheck.cpp:444
typecheckt
Definition: typecheck.h:15
jsil_typecheckt::typecheck
virtual void typecheck()
Definition: jsil_typecheck.cpp:870
jsil_typecheckt::typecheck_expr_field
void typecheck_expr_field(exprt &expr)
Definition: jsil_typecheck.cpp:372
code_assignt
A goto_instruction_codet representing an assignment in the program.
Definition: goto_instruction_code.h:22
jsil_typecheckt::add_prefix
irep_idt add_prefix(const irep_idt &ds)
Prefix parameters and variables with a procedure name.
Definition: jsil_typecheck.cpp:35
jsil_typecheckt::typecheck_exp_binary_equal
void typecheck_exp_binary_equal(exprt &expr)
Definition: jsil_typecheck.cpp:489
jsil_typecheckt::make_type_compatible
void make_type_compatible(exprt &expr, const typet &type, bool must)
Definition: jsil_typecheck.cpp:63
jsil_typecheckt::typecheck_expr_delete
void typecheck_expr_delete(exprt &expr)
Definition: jsil_typecheck.cpp:321
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:28