-
Notifications
You must be signed in to change notification settings - Fork 273
Store the typedef identifier in the symbol_type #345
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ Author: Daniel Kroening, [email protected] | |
#include "type2name.h" | ||
#include "c_storage_spec.h" | ||
|
||
#include <iostream> | ||
|
||
/*******************************************************************\ | ||
|
||
Function: c_typecheck_baset::to_string | ||
|
@@ -96,6 +98,9 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol) | |
bool is_function=symbol.type.id()==ID_code; | ||
|
||
const typet &final_type=follow(symbol.type); | ||
// std::cout << "BASENAME: " << symbol.base_name << std::endl; | ||
// std::cout << "TYPE: " << symbol.type.pretty() << std::endl; | ||
// std::cout << "FINAL: " << final_type.pretty() << std::endl; | ||
|
||
// set a few flags | ||
symbol.is_lvalue=!symbol.is_type && !symbol.is_macro; | ||
|
@@ -127,13 +132,23 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol) | |
(final_type.id()==ID_struct || | ||
final_type.id()==ID_incomplete_struct)) | ||
{ | ||
symbol.pretty_name="struct "+id2string(symbol.base_name); | ||
if(symbol.type.find(ID_typedef).is_not_nil()) | ||
symbol.pretty_name=symbol.type.get(ID_typedef); | ||
else | ||
symbol.pretty_name="struct "+id2string(symbol.base_name); | ||
} | ||
else if(symbol.is_type && | ||
(final_type.id()==ID_union || | ||
final_type.id()==ID_incomplete_union)) | ||
{ | ||
symbol.pretty_name="union "+id2string(symbol.base_name); | ||
if(symbol.type.find(ID_typedef).is_not_nil()) | ||
{ | ||
symbol.pretty_name=symbol.type.get(ID_typedef); | ||
symbol_table.symbols.find(symbol.type.get(ID_identifier))->second.pretty_name=symbol.type.get(ID_typedef); | ||
symbol_table.symbols.find(symbol.type.get(ID_identifier))->second.type.set(ID_typedef,symbol.pretty_name); | ||
} | ||
else | ||
symbol.pretty_name="union "+id2string(symbol.base_name); | ||
} | ||
else if(symbol.is_type && | ||
(final_type.id()==ID_c_enum || | ||
|
@@ -149,6 +164,7 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol) | |
// see if we have it already | ||
symbol_tablet::symbolst::iterator old_it=symbol_table.symbols.find(symbol.name); | ||
|
||
|
||
if(old_it==symbol_table.symbols.end()) | ||
{ | ||
// just put into symbol_table | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ Author: Daniel Kroening, [email protected] | |
#include "type2name.h" | ||
#include "ansi_c_convert_type.h" | ||
|
||
#include <iostream> | ||
|
||
/*******************************************************************\ | ||
|
||
Function: c_typecheck_baset::typecheck_type | ||
|
@@ -52,12 +54,14 @@ void c_typecheck_baset::typecheck_type(typet &type) | |
c_qualifiers+=c_qualifierst(type.subtype()); | ||
bool packed=type.get_bool(ID_C_packed); | ||
exprt alignment=static_cast<const exprt &>(type.find(ID_C_alignment)); | ||
irept _typedef=type.find(ID_typedef); | ||
|
||
type.swap(type.subtype()); | ||
|
||
c_qualifiers.write(type); | ||
if(packed) type.set(ID_C_packed, true); | ||
if(alignment.is_not_nil()) type.add(ID_C_alignment, alignment); | ||
if(_typedef.is_not_nil()) type.add(ID_typedef, _typedef); | ||
|
||
return; // done | ||
} | ||
|
@@ -726,11 +730,15 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type) | |
// Anonymous? Must come with body. | ||
assert(have_body); | ||
|
||
// std::cout << "__TYPE: " << type.pretty() << std::endl; | ||
|
||
// produce symbol | ||
symbolt compound_symbol; | ||
compound_symbol.is_type=true; | ||
compound_symbol.type=type; | ||
compound_symbol.location=type.source_location(); | ||
if(compound_symbol.type.find(ID_typedef).is_not_nil()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be required, but I don't really understand the "already_typechecked" thing so don't know what can cause that to fail. |
||
compound_symbol.pretty_name=compound_symbol.type.get(ID_typedef); | ||
|
||
typecheck_compound_body(to_struct_union_type(compound_symbol.type)); | ||
|
||
|
@@ -739,6 +747,9 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type) | |
compound_symbol.name="tag-#anon#"+typestr; | ||
identifier=compound_symbol.name; | ||
|
||
// std::cout << "TYPEDEF: " << compound_symbol.type.get_string(ID_typedef) << std::endl; | ||
// std::cout << "BASENAME: " << id2string(compound_symbol.base_name) << std::endl; | ||
|
||
// We might already have the same anonymous union/struct, | ||
// and this is simply ok. Note that the C standard treats | ||
// these as different types. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,7 +360,12 @@ std::string expr2ct::convert_rec( | |
{ | ||
const struct_typet &struct_type=to_struct_type(src); | ||
|
||
std::string dest=q+"struct"; | ||
std::string dest=q; | ||
|
||
if(src.find(ID_typedef).is_not_nil()) | ||
dest+="typedef struct"; | ||
else | ||
dest+="struct"; | ||
|
||
const irep_idt &tag=struct_type.get_tag(); | ||
if(tag!="") dest+=" "+id2string(tag); | ||
|
@@ -378,7 +383,10 @@ std::string expr2ct::convert_rec( | |
|
||
dest+=" }"; | ||
|
||
dest+=d; | ||
if(src.find(ID_typedef).is_not_nil()) | ||
dest+=src.get_string(ID_typedef); | ||
else | ||
dest+=d; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @peterschrammel How come we only add on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does appear to be a bug, for the following code:
I get the following symbols:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return dest; | ||
} | ||
|
@@ -396,7 +404,12 @@ std::string expr2ct::convert_rec( | |
{ | ||
const union_typet &union_type=to_union_type(src); | ||
|
||
std::string dest=q+"union"; | ||
std::string dest=q; | ||
|
||
if(src.find(ID_typedef).is_not_nil()) | ||
dest+="typedef union"; | ||
else | ||
dest+="union"; | ||
|
||
const irep_idt &tag=union_type.get_tag(); | ||
if(tag!="") dest+=" "+id2string(tag); | ||
|
@@ -414,7 +427,10 @@ std::string expr2ct::convert_rec( | |
|
||
dest+=" }"; | ||
|
||
dest+=d; | ||
if(src.find(ID_typedef).is_not_nil()) | ||
dest+=src.get_string(ID_typedef); | ||
else | ||
dest+=d; | ||
|
||
return dest; | ||
} | ||
|
@@ -538,29 +554,47 @@ std::string expr2ct::convert_rec( | |
} | ||
else if(src.id()==ID_symbol) | ||
{ | ||
const typet &followed=ns.follow(src); | ||
symbol_typet symbolic_type=to_symbol_type(src); | ||
const irep_idt &typedef_identifer=symbolic_type.get(ID_typedef); | ||
|
||
if(followed.id()==ID_struct) | ||
// Providing we have a valid identifer, we can just use that rather than | ||
// trying to find the concrete type | ||
if(typedef_identifer!="") | ||
{ | ||
std::string dest=q+"struct"; | ||
const irep_idt &tag=to_struct_type(followed).get_tag(); | ||
if(tag!="") dest+=" "+id2string(tag); | ||
dest+=d; | ||
return dest; | ||
return q+id2string(typedef_identifer)+d; | ||
} | ||
else if(followed.id()==ID_union) | ||
else | ||
{ | ||
std::string dest=q+"union"; | ||
const irep_idt &tag=to_union_type(followed).get_tag(); | ||
if(tag!="") dest+=" "+id2string(tag); | ||
dest+=d; | ||
return dest; | ||
const typet &followed=ns.follow(src); | ||
|
||
if(followed.id()==ID_struct) | ||
{ | ||
if(followed.find(ID_typedef).is_not_nil()) | ||
return followed.get_string(ID_typedef)+d; | ||
std::string dest=q+"struct"; | ||
const irep_idt &tag=to_struct_type(followed).get_tag(); | ||
if(tag!="") dest+=" "+id2string(tag); | ||
dest+=d; | ||
return dest; | ||
} | ||
else if(followed.id()==ID_union) | ||
{ | ||
if(followed.find(ID_typedef).is_not_nil()) | ||
return followed.get_string(ID_typedef)+d; | ||
std::string dest=q+"union"; | ||
const irep_idt &tag=to_union_type(followed).get_tag(); | ||
if(tag!="") dest+=" "+id2string(tag); | ||
dest+=d; | ||
return dest; | ||
} | ||
else | ||
return convert_rec(followed, new_qualifiers, declarator); | ||
} | ||
else | ||
return convert_rec(followed, new_qualifiers, declarator); | ||
} | ||
else if(src.id()==ID_struct_tag) | ||
{ | ||
if(src.find(ID_typedef).is_not_nil()) | ||
return src.get_string(ID_typedef)+d; | ||
const struct_tag_typet &struct_tag_type= | ||
to_struct_tag_type(src); | ||
|
||
|
@@ -573,6 +607,8 @@ std::string expr2ct::convert_rec( | |
} | ||
else if(src.id()==ID_union_tag) | ||
{ | ||
if(src.find(ID_typedef).is_not_nil()) | ||
return src.get_string(ID_typedef)+d; | ||
const union_tag_typet &union_tag_type= | ||
to_union_tag_type(src); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems weird and not required.