Skip to content

Commit ddbc0fb

Browse files
committed
C and jsil front-ends: make to_symbol return by value
Instead of creating and dummy-initialising a symbolt upfront, return a locally allocated symbol. This removes the last users of symbolt::clear, which had maintenance risks in that it had to list all members.
1 parent 5f12ab4 commit ddbc0fb

7 files changed

+13
-36
lines changed

src/ansi-c/ansi_c_declaration.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ typet ansi_c_declarationt::full_type(
125125
return result;
126126
}
127127

128-
void ansi_c_declarationt::to_symbol(
129-
const ansi_c_declaratort &declarator,
130-
symbolt &symbol) const
128+
symbolt
129+
ansi_c_declarationt::to_symbol(const ansi_c_declaratort &declarator) const
131130
{
132-
symbol.clear();
131+
symbolt symbol{declarator.get_name(), full_type(declarator), ID_C};
133132
symbol.value=declarator.value();
134-
symbol.type=full_type(declarator);
135-
symbol.name=declarator.get_name();
136133
symbol.pretty_name=symbol.name;
137134
symbol.base_name=declarator.get_base_name();
138135
symbol.is_type=get_is_typedef();
@@ -196,4 +193,6 @@ void ansi_c_declarationt::to_symbol(
196193
(get_is_global() && get_is_static() && !get_is_used()) ||
197194
symbol.is_parameter;
198195
}
196+
197+
return symbol;
199198
}

src/ansi-c/ansi_c_declaration.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ class ansi_c_declarationt:public exprt
205205
set(ID_is_used, is_used);
206206
}
207207

208-
void to_symbol(
209-
const ansi_c_declaratort &,
210-
symbolt &symbol) const;
208+
symbolt to_symbol(const ansi_c_declaratort &) const;
211209

212210
typet full_type(const ansi_c_declaratort &) const;
213211

src/ansi-c/c_typecheck_base.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,7 @@ void c_typecheck_baset::typecheck_declaration(
737737
declaration.set_is_weak(full_spec.is_weak);
738738
declaration.set_is_used(full_spec.is_used);
739739

740-
symbolt symbol;
741-
declaration.to_symbol(declarator, symbol);
740+
symbolt symbol = declaration.to_symbol(declarator);
742741
current_symbol=symbol;
743742

744743
// now check other half of type

src/jsil/jsil_convert.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ bool jsil_convertt::operator()(
4242
it!=parse_tree.items.end();
4343
++it)
4444
{
45-
symbolt new_symbol;
46-
it->to_symbol(new_symbol);
45+
symbolt new_symbol = it->to_symbol();
4746

4847
if(convert_code(new_symbol, to_code(new_symbol.value)))
4948
return true;

src/jsil/jsil_parse_tree.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ static bool insert_at_label(
4040
return true;
4141
}
4242

43-
void jsil_declarationt::to_symbol(symbolt &symbol) const
43+
symbolt jsil_declarationt::to_symbol() const
4444
{
45-
symbol.clear();
46-
4745
symbol_exprt s(to_symbol_expr(
4846
static_cast<const exprt&>(find(ID_declarator))));
4947

@@ -56,10 +54,8 @@ void jsil_declarationt::to_symbol(symbolt &symbol) const
5654
else if(proc_type=="spec")
5755
symbol_type=jsil_spec_code_typet(symbol_type);
5856

59-
symbol.name=s.get_identifier();
57+
symbolt symbol{s.get_identifier(), symbol_type, "jsil"};
6058
symbol.base_name=s.get_identifier();
61-
symbol.mode="jsil";
62-
symbol.type=symbol_type;
6359
symbol.location=s.source_location();
6460

6561
code_blockt code(to_code_block(
@@ -79,6 +75,8 @@ void jsil_declarationt::to_symbol(symbolt &symbol) const
7975
throw "throw label "+throws.get_string(ID_label)+" not found";
8076

8177
symbol.value.swap(code);
78+
79+
return symbol;
8280
}
8381

8482
void jsil_declarationt::output(std::ostream &out) const

src/jsil/jsil_parse_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class jsil_declarationt:public exprt
9292
return static_cast<code_blockt &>(add(ID_value));
9393
}
9494

95-
void to_symbol(symbolt &symbol) const;
95+
symbolt to_symbol() const;
9696

9797
void output(std::ostream &) const;
9898
};

src/util/symbol.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,6 @@ class symbolt
9393
{
9494
}
9595

96-
/// Zero initialise a symbol object.
97-
void clear()
98-
{
99-
type.make_nil();
100-
value.make_nil();
101-
location.make_nil();
102-
103-
name=module=base_name=mode=pretty_name=irep_idt();
104-
105-
is_type=is_macro=is_exported=
106-
is_input=is_output=is_state_var=is_property=
107-
is_static_lifetime=is_thread_local=
108-
is_lvalue=is_file_local=is_extern=is_volatile=
109-
is_parameter=is_auxiliary=is_weak=false;
110-
}
111-
11296
void swap(symbolt &b);
11397
void show(std::ostream &out) const;
11498

0 commit comments

Comments
 (0)