Skip to content

Commit fbaf6ac

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 8646cc1 commit fbaf6ac

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
@@ -123,14 +123,11 @@ typet ansi_c_declarationt::full_type(
123123
return result;
124124
}
125125

126-
void ansi_c_declarationt::to_symbol(
127-
const ansi_c_declaratort &declarator,
128-
symbolt &symbol) const
126+
symbolt
127+
ansi_c_declarationt::to_symbol(const ansi_c_declaratort &declarator) const
129128
{
130-
symbol.clear();
129+
symbolt symbol{declarator.get_name(), full_type(declarator), ID_C};
131130
symbol.value=declarator.value();
132-
symbol.type=full_type(declarator);
133-
symbol.name=declarator.get_name();
134131
symbol.pretty_name=symbol.name;
135132
symbol.base_name=declarator.get_base_name();
136133
symbol.is_type=get_is_typedef();
@@ -194,4 +191,6 @@ void ansi_c_declarationt::to_symbol(
194191
(get_is_global() && get_is_static() && !get_is_used()) ||
195192
symbol.is_parameter;
196193
}
194+
195+
return symbol;
197196
}

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
@@ -658,8 +658,7 @@ void c_typecheck_baset::typecheck_declaration(
658658
declaration.set_is_weak(full_spec.is_weak);
659659
declaration.set_is_used(full_spec.is_used);
660660

661-
symbolt symbol;
662-
declaration.to_symbol(declarator, symbol);
661+
symbolt symbol = declaration.to_symbol(declarator);
663662
current_symbol=symbol;
664663

665664
// 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
@@ -91,22 +91,6 @@ class symbolt
9191
location.make_nil();
9292
}
9393

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

0 commit comments

Comments
 (0)