Skip to content

Commit d425cd7

Browse files
committed
Declarator -> symbol conversion to match C implementation
Still missing: attribute-weak parsing
1 parent 63f0ef8 commit d425cd7

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

src/cpp/cpp_declarator_converter.cpp

+33-41
Original file line numberDiff line numberDiff line change
@@ -436,58 +436,50 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
436436
symbol.base_name=base_name;
437437
symbol.value=declarator.value();
438438
symbol.location=declarator.name().source_location();
439+
symbol.is_extern = storage_spec.is_extern();
439440
symbol.is_parameter = declarator.get_is_parameter();
441+
symbol.is_weak = storage_spec.is_weak();
440442
symbol.mode=linkage_spec==ID_auto?ID_cpp:linkage_spec;
441443
symbol.module=cpp_typecheck.module;
442444
symbol.type=final_type;
443445
symbol.is_type=is_typedef;
444446
symbol.is_macro=is_typedef && !is_template_parameter;
445447
symbol.pretty_name=pretty_name;
446448

449+
if(is_code && !symbol.is_type)
450+
{
451+
// it is a function
452+
symbol.is_static_lifetime = false;
453+
symbol.is_thread_local = false;
447454

448-
if(member_spec.is_inline())
449-
symbol.type.set(ID_C_inlined, true);
455+
symbol.is_file_local = storage_spec.is_static();
450456

451-
if(!symbol.is_type)
457+
if(member_spec.is_inline())
458+
symbol.type.set(ID_C_inlined, true);
459+
}
460+
else
452461
{
453-
if(is_code)
454-
{
455-
// it is a function
456-
if(storage_spec.is_static())
457-
symbol.is_file_local=true;
458-
}
459-
else
460-
{
461-
// it is a variable
462-
symbol.is_state_var=true;
463-
symbol.is_lvalue = !is_reference(symbol.type) &&
464-
!(symbol.type.get_bool(ID_C_constant) &&
465-
is_number(symbol.type) &&
466-
symbol.value.id() == ID_constant);
467-
468-
if(cpp_typecheck.cpp_scopes.current_scope().is_global_scope())
469-
{
470-
symbol.is_static_lifetime=true;
471-
472-
if(storage_spec.is_extern())
473-
symbol.is_extern=true;
474-
}
475-
else
476-
{
477-
if(storage_spec.is_static())
478-
{
479-
symbol.is_static_lifetime=true;
480-
symbol.is_file_local=true;
481-
}
482-
else if(storage_spec.is_extern())
483-
{
484-
cpp_typecheck.error().source_location=storage_spec.location();
485-
cpp_typecheck.error() << "external storage not permitted here"
486-
<< messaget::eom;
487-
throw 0;
488-
}
489-
}
490-
}
462+
symbol.is_lvalue = !is_reference(symbol.type) &&
463+
!(symbol.type.get_bool(ID_C_constant) &&
464+
is_number(symbol.type) &&
465+
symbol.value.id() == ID_constant);
466+
467+
symbol.is_static_lifetime =
468+
!symbol.is_macro && !symbol.is_type &&
469+
(cpp_typecheck.cpp_scopes.current_scope().is_global_scope() ||
470+
storage_spec.is_static());
471+
472+
symbol.is_thread_local =
473+
(!symbol.is_static_lifetime && !storage_spec.is_extern()) ||
474+
storage_spec.is_thread_local();
475+
476+
symbol.is_file_local =
477+
symbol.is_macro ||
478+
(!cpp_typecheck.cpp_scopes.current_scope().is_global_scope() &&
479+
!storage_spec.is_extern()) ||
480+
(cpp_typecheck.cpp_scopes.current_scope().is_global_scope() &&
481+
storage_spec.is_static()) ||
482+
symbol.is_parameter;
491483
}
492484

493485
if(symbol.is_static_lifetime)

src/cpp/cpp_storage_spec.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class cpp_storage_spect:public irept
3636
bool is_mutable() const { return get_bool(ID_mutable); }
3737
bool is_thread_local() const { return get_bool(ID_thread_local); }
3838
bool is_asm() const { return get_bool(ID_asm); }
39+
bool is_weak() const { return get_bool(ID_weak); }
3940

4041
void set_static() { set(ID_static, true); }
4142
void set_extern() { set(ID_extern, true); }
@@ -44,12 +45,13 @@ class cpp_storage_spect:public irept
4445
void set_mutable() { set(ID_mutable, true); }
4546
void set_thread_local() { set(ID_thread_local, true); }
4647
void set_asm() { set(ID_asm, true); }
48+
void set_weak() { set(ID_weak, true); }
4749

4850
bool is_empty() const
4951
{
5052
return !is_static() && !is_extern() && !is_auto() &&
5153
!is_register() && !is_mutable() && !is_thread_local() &&
52-
!is_asm();
54+
!is_asm() && !is_weak();
5355
}
5456
};
5557

0 commit comments

Comments
 (0)