void ansi_c_typecheckt::typecheck() { start_typecheck_code(); for(ansi_c_parse_treet::itemst::iterator it=parse_tree.items.begin(); it!=parse_tree.items.end(); it++) { typecheck_declaration(*it); } }
void cpp_typecheckt::convert_function(symbolt &symbol) { code_typet &function_type= to_code_type(template_subtype(symbol.type)); // only a prototype? if(symbol.value.is_nil()) return; // if it is a destructor, add the implicit code if(symbol.type.get(ID_return_type)==ID_destructor) { const symbolt &msymb=lookup(symbol.type.get(ID_C_member_name)); assert(symbol.value.id()==ID_code); assert(symbol.value.get(ID_statement)==ID_block); symbol.value.copy_to_operands(dtor(msymb)); } // enter appropriate scope cpp_save_scopet saved_scope(cpp_scopes); cpp_scopet &function_scope=cpp_scopes.set_scope(symbol.name); // fix the scope's prefix function_scope.prefix+=id2string(symbol.name)+"::"; // genuine function definition -- do the parameter declarations convert_arguments(symbol.mode, function_type); // create "this" if it's a non-static method if(function_scope.is_method && !function_scope.is_static_member) { code_typet::argumentst &arguments=function_type.arguments(); assert(arguments.size()>=1); code_typet::argumentt &this_argument_expr=arguments.front(); function_scope.this_expr=exprt(ID_symbol, this_argument_expr.type()); function_scope.this_expr.set(ID_identifier, this_argument_expr.get(ID_C_identifier)); } else function_scope.this_expr.make_nil(); // do the function body start_typecheck_code(); // save current return type typet old_return_type=return_type; return_type=function_type.return_type(); // constructor, destructor? if(return_type.id()==ID_constructor || return_type.id()==ID_destructor) return_type=empty_typet(); typecheck_code(to_code(symbol.value)); symbol.value.type()=symbol.type; return_type = old_return_type; }