diff --git a/src/ansi-c/ansi_c_declaration.cpp b/src/ansi-c/ansi_c_declaration.cpp index a888e993ed2..f520ad2fc4a 100644 --- a/src/ansi-c/ansi_c_declaration.cpp +++ b/src/ansi-c/ansi_c_declaration.cpp @@ -125,14 +125,11 @@ typet ansi_c_declarationt::full_type( return result; } -void ansi_c_declarationt::to_symbol( - const ansi_c_declaratort &declarator, - symbolt &symbol) const +symbolt +ansi_c_declarationt::to_symbol(const ansi_c_declaratort &declarator) const { - symbol.clear(); + symbolt symbol{declarator.get_name(), full_type(declarator), ID_C}; symbol.value=declarator.value(); - symbol.type=full_type(declarator); - symbol.name=declarator.get_name(); symbol.pretty_name=symbol.name; symbol.base_name=declarator.get_base_name(); symbol.is_type=get_is_typedef(); @@ -190,4 +187,6 @@ void ansi_c_declarationt::to_symbol( symbol.is_macro || (!get_is_global() && !get_is_extern()) || (get_is_global() && get_is_static()) || symbol.is_parameter; } + + return symbol; } diff --git a/src/ansi-c/ansi_c_declaration.h b/src/ansi-c/ansi_c_declaration.h index c7b096544f0..7088c93f884 100644 --- a/src/ansi-c/ansi_c_declaration.h +++ b/src/ansi-c/ansi_c_declaration.h @@ -195,9 +195,7 @@ class ansi_c_declarationt:public exprt set(ID_is_weak, is_weak); } - void to_symbol( - const ansi_c_declaratort &, - symbolt &symbol) const; + symbolt to_symbol(const ansi_c_declaratort &) const; typet full_type(const ansi_c_declaratort &) const; diff --git a/src/ansi-c/c_typecheck_base.cpp b/src/ansi-c/c_typecheck_base.cpp index f6c1441936b..b3889fb343a 100644 --- a/src/ansi-c/c_typecheck_base.cpp +++ b/src/ansi-c/c_typecheck_base.cpp @@ -781,8 +781,7 @@ void c_typecheck_baset::typecheck_declaration( declaration.set_is_typedef(full_spec.is_typedef); declaration.set_is_weak(full_spec.is_weak); - symbolt symbol; - declaration.to_symbol(declarator, symbol); + symbolt symbol = declaration.to_symbol(declarator); current_symbol=symbol; // now check other half of type diff --git a/src/jsil/jsil_convert.cpp b/src/jsil/jsil_convert.cpp index 5317d6f93b0..8344603bf14 100644 --- a/src/jsil/jsil_convert.cpp +++ b/src/jsil/jsil_convert.cpp @@ -43,8 +43,7 @@ bool jsil_convertt::operator()( it!=parse_tree.items.end(); ++it) { - symbolt new_symbol; - it->to_symbol(new_symbol); + symbolt new_symbol = it->to_symbol(); if(convert_code(new_symbol, to_code(new_symbol.value))) return true; diff --git a/src/jsil/jsil_parse_tree.cpp b/src/jsil/jsil_parse_tree.cpp index 6faecac52fe..92638195d74 100644 --- a/src/jsil/jsil_parse_tree.cpp +++ b/src/jsil/jsil_parse_tree.cpp @@ -40,10 +40,8 @@ static bool insert_at_label( return true; } -void jsil_declarationt::to_symbol(symbolt &symbol) const +symbolt jsil_declarationt::to_symbol() const { - symbol.clear(); - symbol_exprt s(to_symbol_expr( static_cast(find(ID_declarator)))); @@ -56,10 +54,8 @@ void jsil_declarationt::to_symbol(symbolt &symbol) const else if(proc_type=="spec") symbol_type=jsil_spec_code_typet(symbol_type); - symbol.name=s.get_identifier(); + symbolt symbol{s.get_identifier(), symbol_type, "jsil"}; symbol.base_name=s.get_identifier(); - symbol.mode="jsil"; - symbol.type=symbol_type; symbol.location=s.source_location(); code_blockt code(to_code_block( @@ -79,6 +75,8 @@ void jsil_declarationt::to_symbol(symbolt &symbol) const throw "throw label "+throws.get_string(ID_label)+" not found"; symbol.value.swap(code); + + return symbol; } void jsil_declarationt::output(std::ostream &out) const diff --git a/src/jsil/jsil_parse_tree.h b/src/jsil/jsil_parse_tree.h index b561390274b..b47e50e33f9 100644 --- a/src/jsil/jsil_parse_tree.h +++ b/src/jsil/jsil_parse_tree.h @@ -92,7 +92,7 @@ class jsil_declarationt:public exprt return static_cast(add(ID_value)); } - void to_symbol(symbolt &symbol) const; + symbolt to_symbol() const; void output(std::ostream &) const; }; diff --git a/src/util/symbol.h b/src/util/symbol.h index 09ae1a670dd..1a7121234e8 100644 --- a/src/util/symbol.h +++ b/src/util/symbol.h @@ -93,22 +93,6 @@ class symbolt { } - /// Zero initialise a symbol object. - void clear() - { - type.make_nil(); - value.make_nil(); - location.make_nil(); - - name=module=base_name=mode=pretty_name=irep_idt(); - - is_type=is_macro=is_exported= - is_input=is_output=is_state_var=is_property= - is_static_lifetime=is_thread_local= - is_lvalue=is_file_local=is_extern=is_volatile= - is_parameter=is_auxiliary=is_weak=false; - } - void swap(symbolt &b); void show(std::ostream &out) const;