Skip to content

C and jsil front-ends: make to_symbol return by value #7407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/ansi-c/ansi_c_declaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
4 changes: 1 addition & 3 deletions src/ansi-c/ansi_c_declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/c_typecheck_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/jsil/jsil_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/jsil/jsil_parse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const exprt&>(find(ID_declarator))));

Expand All @@ -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(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/jsil/jsil_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class jsil_declarationt:public exprt
return static_cast<code_blockt &>(add(ID_value));
}

void to_symbol(symbolt &symbol) const;
symbolt to_symbol() const;

void output(std::ostream &) const;
};
Expand Down
16 changes: 0 additions & 16 deletions src/util/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down