CBMC
ansi_c_typecheck.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: ANSI-C Language Type Checking
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "ansi_c_typecheck.h"
13 
14 #include "ansi_c_parse_tree.h"
15 
17 {
19 
20  for(auto &item : parse_tree.items)
22 }
23 
25  ansi_c_parse_treet &ansi_c_parse_tree,
26  symbol_tablet &symbol_table,
27  const std::string &module,
28  message_handlert &message_handler)
29 {
31  ansi_c_parse_tree, symbol_table, module, message_handler);
32  return ansi_c_typecheck.typecheck_main();
33 }
34 
36  exprt &expr,
37  message_handlert &message_handler,
38  const namespacet &ns)
39 {
40  const unsigned errors_before=
41  message_handler.get_message_count(messaget::M_ERROR);
42 
43  symbol_tablet symbol_table;
44  ansi_c_parse_treet ansi_c_parse_tree;
45 
47  ansi_c_parse_tree, symbol_table,
48  ns.get_symbol_table(), "", message_handler);
49 
50  try
51  {
52  ansi_c_typecheck.typecheck_expr(expr);
53  }
54 
55  catch(int)
56  {
57  ansi_c_typecheck.error();
58  }
59 
60  catch(const char *e)
61  {
62  ansi_c_typecheck.error() << e << messaget::eom;
63  }
64 
65  catch(const std::string &e)
66  {
67  ansi_c_typecheck.error() << e << messaget::eom;
68  }
69 
70  catch(const invalid_source_file_exceptiont &e)
71  {
72  ansi_c_typecheck.error().source_location = e.get_source_location();
73  ansi_c_typecheck.error() << e.get_reason() << messaget::eom;
74  }
75 
76  return message_handler.get_message_count(messaget::M_ERROR)!=errors_before;
77 }
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
ansi_c_typecheck.h
ansi_c_parse_tree.h
c_typecheck_baset::typecheck_declaration
void typecheck_declaration(ansi_c_declarationt &)
Definition: c_typecheck_base.cpp:704
ansi_c_typecheckt::parse_tree
ansi_c_parse_treet & parse_tree
Definition: ansi_c_typecheck.h:60
ansi_c_parse_treet::items
itemst items
Definition: ansi_c_parse_tree.h:22
exprt
Base class for all expressions.
Definition: expr.h:55
invalid_source_file_exceptiont
Thrown when we can't handle something in an input source file.
Definition: exception_utils.h:171
messaget::eom
static eomt eom
Definition: message.h:297
invalid_source_file_exceptiont::get_source_location
const source_locationt & get_source_location() const
Definition: exception_utils.h:184
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
ansi_c_typecheckt::typecheck
virtual void typecheck()
Definition: ansi_c_typecheck.cpp:16
messaget::M_ERROR
@ M_ERROR
Definition: message.h:170
ansi_c_parse_treet
Definition: ansi_c_parse_tree.h:17
message_handlert
Definition: message.h:27
namespacet::get_symbol_table
const symbol_table_baset & get_symbol_table() const
Return first symbol table registered with the namespace.
Definition: namespace.h:123
ansi_c_typecheck
bool ansi_c_typecheck(ansi_c_parse_treet &ansi_c_parse_tree, symbol_tablet &symbol_table, const std::string &module, message_handlert &message_handler)
Definition: ansi_c_typecheck.cpp:24
invalid_source_file_exceptiont::get_reason
const std::string & get_reason() const
Definition: exception_utils.h:179
c_typecheck_baset::start_typecheck_code
virtual void start_typecheck_code()
Definition: c_typecheck_code.cpp:24
message_handlert::get_message_count
std::size_t get_message_count(unsigned level) const
Definition: message.h:56
ansi_c_typecheckt
Definition: ansi_c_typecheck.h:30