1/*******************************************************************\
5Author: Daniel Kroening, kroening@kroening.com
7\*******************************************************************/
42 const std::string &path,
55 const std::string &path,
73 std::istringstream
codestr(code);
79 ansi_c_parser.ts_18661_3_Floatn_types=
config.
ansi_c.ts_18661_3_Floatn_types;
80 ansi_c_parser.__float128_is_keyword =
config.
ansi_c.__float128_is_keyword;
84 ansi_c_parser.cpp98=
false;
// it's not C++
85 ansi_c_parser.cpp11=
false;
// it's not C++
95 bool result=ansi_c_parser.parse();
99 ansi_c_parser.set_line_no(0);
100 ansi_c_parser.set_file(path);
103 result=ansi_c_parser.parse();
119 for(
auto it = symbol_table.
begin(); it != symbol_table.
end(); ++it)
121 const symbolt &symbol = it->second;
138 // Apply the type updates to the values (initializers) of all symbols.
139 for(
auto it = symbol_table.
begin(); it != symbol_table.
end(); ++it)
142 !it->second.is_type && !it->second.is_macro &&
143 it->second.value.is_not_nil())
152 const std::string &
module,
154 const bool keep_file_local)
156 return typecheck(symbol_table,
module, message_handler, keep_file_local, {});
161 const std::string &
module,
163 const bool keep_file_local,
164 const std::set<irep_idt> &
keep)
173 // C standard 6.9.2(5): non-extern file-scope incomplete array definitions
174 // are adjusted to an array of size 1. Done here (in the front end, before
175 // linking) so the symbol's type and the types carried on symbol expressions
176 // in code stay consistent.
180 new_symbol_table, message_handler, keep_file_local,
keep);
182 if(
linking(symbol_table, new_symbol_table, message_handler))
192 // This creates __CPROVER_start and __CPROVER_initialize:
204 return std::make_unique<ansi_c_languaget>();
235 const std::string &code,
243 // no preprocessing yet...
246 "void __my_expression = (void) (\n"+code+
"\n);");
253 ansi_c_parser.for_has_scope =
config.
ansi_c.for_has_scope;
254 ansi_c_parser.ts_18661_3_Floatn_types=
config.
ansi_c.ts_18661_3_Floatn_types;
255 ansi_c_parser.__float128_is_keyword =
config.
ansi_c.__float128_is_keyword;
256 ansi_c_parser.float16_type =
config.
ansi_c.float16_type;
259 ansi_c_parser.cpp98 =
false;
// it's not C++
260 ansi_c_parser.cpp11 =
false;
// it's not C++
264 bool result=ansi_c_parser.parse();
266 if(ansi_c_parser.parse_tree.items.empty())
270 expr=ansi_c_parser.parse_tree.items.front().declarator().value();
276 // now remove that (void) cast
bool ansi_c_entry_point(symbol_table_baset &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
void ansi_c_internal_additions(std::string &code, bool support_float16_type)
static void adjust_tentative_array_definitions(symbol_table_baset &symbol_table)
Adjust non-extern file-scope incomplete array definitions (tentative definitions without a size) to a...
std::unique_ptr< languaget > new_ansi_c_language()
void ansi_c_scanner_init(ansi_c_parsert &)
bool ansi_c_typecheck(ansi_c_parse_treet &ansi_c_parse_tree, symbol_table_baset &symbol_table, const std::string &module, message_handlert &message_handler)
ANSI-C Language Type Checking.
bool c_preprocess(std::istream &instream, std::ostream &outstream, message_handlert &message_handler)
ANSI-C preprocessing.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
~ansi_c_languaget() override
std::set< std::string > extensions() const override
void show_parse(std::ostream &out, message_handlert &) override
bool from_type(const typet &type, std::string &code, const namespacet &ns) override
Formats the given type in a language-specific way.
bool from_expr(const exprt &expr, std::string &code, const namespacet &ns) override
Formats the given expression in a language-specific way.
bool to_expr(const std::string &code, const std::string &module, exprt &expr, const namespacet &ns, message_handlert &message_handler) override
Parses the given string into an expression.
void modules_provided(std::set< std::string > &modules) override
bool type_to_name(const typet &type, std::string &name, const namespacet &ns) override
Encodes the given type in a language-specific way.
bool typecheck(symbol_table_baset &symbol_table, const std::string &module, message_handlert &message_handler, const bool keep_file_local) override
typecheck without removing specified entries from the symbol table
bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream, message_handlert &message_handler) override
ANSI-C preprocessing.
bool generate_support_functions(symbol_table_baset &symbol_table, message_handlert &message_handler) override
Create language-specific support functions, such as __CPROVER_start, __CPROVER_initialize and languag...
ansi_c_parse_treet parse_tree
c_object_factory_parameterst object_factory_params
bool parse(std::istream &instream, const std::string &path, message_handlert &message_handler) override
void swap(ansi_c_parse_treet &other)
void output(std::ostream &out) const
struct configt::ansi_ct ansi_c
Base class for all expressions.
typet & type()
Return the type of the expression.
const irep_idt & id() const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Expression to hold a symbol (variable)
The symbol table base class interface.
virtual iteratort begin()=0
virtual iteratort end()=0
typet type
Type of symbol.
The type of an expression, extends irept.
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
bool linking(symbol_table_baset &dest_symbol_table, const symbol_table_baset &new_symbol_table, message_handlert &message_handler)
Merges the symbol table new_symbol_table into dest_symbol_table, renaming symbols from new_symbol_tab...
void remove_internal_symbols(symbol_table_baset &symbol_table, message_handlert &mh, const bool keep_file_local)
Removes internal symbols from a symbol table A symbol is EXPORTED if it is a.
Remove symbols that are internal only.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
static std::string type2name(const typet &type, const namespacet &ns, symbol_numbert &symbol_number)