150
150
CTypeInfo *argtype) {
151
151
CArgumentInfo *info;
152
152
info = finfo->newArgument ();
153
std::ostringstream name; name << "%%anon" << _Anonymous << std::ends; _Anonymous++;
153
std::ostringstream name; name << "%%anon" << _Anonymous; _Anonymous++;
154
154
info->Name (name.str ().c_str ());
155
155
info->Storage (CStorage::CLASS_AUTOMATIC);
156
156
info->SourceInfo ()->FileInfo (_file);
305
305
result = scope->Type (id);
306
if (result && ! result->Record () && ! result->EnumInfo ())
307
result = (CObjectInfo*)0;
306
if (result && ! result->Record () && ! result->EnumInfo ()) {
307
// if searching for a struct or enum type of a tag (struct X)
308
// consider also typedefs to find struct or enum types hidden
309
// by redefining typedefs (typedef struct X X;)
310
CTypedefInfo* tdef = result->TypedefInfo ();
311
if (tdef && (tdef->TypeInfo ()->Record () || tdef->TypeInfo ()->EnumInfo ())) {
314
result = (CObjectInfo*)0;
310
319
for (unsigned i = scope->Objects (); i > 0; i--) {
564
573
oi = lookup (name->Text (), scope, TAG, false);
576
if (isRedefiningTypedef (oi, CTypeInfo::TYPE_ENUM)) {
577
oi = oi->TypeInfo ()->TypeEnum ()->EnumInfo ();
578
} else if (oi->TypedefInfo ()) {
567
583
if (oi->EnumInfo () && oi->EnumInfo ()->isDefined ()) {
568
584
SEM_ERROR__redefinition (ed, "enum ", oi);
578
info = current_scope->newEnum ();
594
info = scope->newEnum ();
579
595
info->TypeInfo (new CTypeEnum (info->EnumInfo ()));
580
596
info->Name (name->Text ());
597
if (scope != current_scope)
598
info->AssignedScope (scope);
583
601
current_enum = info->EnumInfo ();
589
607
oi->NextObject (info);
590
608
ed->Object (info);
592
// introduce alias of enum into enclosing non-class scope
593
if (scope != current_scope)
594
makeAlias (info, scope);
601
void CSemantic::makeAlias (CObjectInfo *info, CStructure *scope) {
602
CMemberAliasInfo *minfo;
604
// introduce alias of info into enclosing non-class scope
605
minfo = scope->newMemberAlias (info);
606
minfo->Name (info->Name ());
607
minfo->Member (info);
608
minfo->TypeInfo (info->TypeInfo ()->Duplicate ());
609
common_settings (minfo, info->Tree ());
615
615
CTree *CSemantic::introduce_enumerator () {
616
616
CEnumeratorInfo *info;
617
617
CStructure *scope;
630
630
e = (CT_Enumerator*) builder ().enumerator ();
631
631
info = current_enum->newEnumerator ();
632
632
info->Scope (scope);
633
info->Name (name->text ());
633
info->Name (name->dtext ());
634
634
info->Storage (CStorage::CLASS_AUTOMATIC);
810
810
oi = lookup (cs->Name ()->Text (), scope, TAG, false);
813
if (isRedefiningTypedef (oi, CTypeInfo::TYPE_CLASS)) {
814
oi = oi->TypeInfo ()->TypeClass ()->ClassInfo ();
815
} else if (oi->TypedefInfo ()) {
813
820
if ((oi->ClassInfo () && oi->ClassInfo ()->isDefined ()) ||
814
821
(oi->UnionInfo () && oi->UnionInfo ()->isDefined ())) {
815
822
SEM_ERROR__redefinition (cs,
828
835
if (cs->NodeName () == CT_ClassDef::NodeId ()) {
829
info = current_scope->newClass ();
836
info = scope->newClass ();
830
837
info->TypeInfo (new CTypeClass (info->ClassInfo ()));
832
info = current_scope->newUnion ();
839
info = scope->newUnion ();
833
840
info->TypeInfo (new CTypeUnion (info->UnionInfo ()));
835
842
info->Name (cs->Name ()->Text ());
843
if (scope != current_scope)
844
info->AssignedScope (scope);
837
846
// common settings
838
847
enter_scope (info->Structure ());
898
903
tag = (CT_ClassSpec*) builder ().elaborated_type_spec ();
899
904
oi = lookup (tag->Name ()->Text (), TAG, true);
906
// check for redefining typedef (typedef struct X X;)
907
if (oi && oi->TypedefInfo ()) {
908
CTypeInfo* t = oi->TypedefInfo ()->TypeInfo ();
909
if (t->TypeRecord ())
910
oi = t->TypeRecord ()->Record ();
911
else if (t->TypeEnum ())
912
oi = t->TypeEnum ()->EnumInfo ();
913
if (oi && oi->Name () != DString(tag->Name ()->Text ()))
914
oi = (CObjectInfo*)0;
902
917
if (tag->NodeName () == CT_ClassSpec::NodeId () && ! oi->ClassInfo () ||
903
918
tag->NodeName () == CT_UnionSpec::NodeId () && ! oi->UnionInfo () ||
904
919
tag->NodeName () == CT_EnumSpec::NodeId () && ! oi->EnumInfo ()) {
905
920
SEM_ERROR (tag, "wrong use of `" << *tag->Name () << "'");
906
921
return (CTree*)0;
909
925
scope = findParent ();
910
926
if (tag->NodeName () == CT_ClassSpec::NodeId ()) {
911
info = current_scope->newClass ();
927
info = scope->newClass ();
912
928
info->TypeInfo (new CTypeClass (info->ClassInfo ()));
913
929
} else if (tag->NodeName () == CT_UnionSpec::NodeId ()) {
914
info = current_scope->newUnion ();
930
info = scope->newUnion ();
915
931
info->TypeInfo (new CTypeUnion (info->UnionInfo ()));
917
info = current_scope->newEnum ();
933
info = scope->newEnum ();
918
934
info->TypeInfo (new CTypeEnum (info->EnumInfo ()));
936
if (scope != current_scope)
937
info->AssignedScope (scope);
921
939
// common settings
922
940
common_settings (info, tag);
923
info->Name (tag->Name ()->end_token ()->text ());
941
info->Name (tag->Name ()->end_token ()->dtext ());
924
942
tag->Name ()->Object (info);
925
943
tag->Name ()->setTypeRef (info->TypeInfo ());
928
946
oi->NextObject (info);
929
947
_db->Insert (info);
931
// introduce alias of enum, class, or union into enclosing non-class scope
932
if (scope != current_scope && ! oi)
933
makeAlias (info, scope);
962
976
return (CTree*)0;
964
978
info = fct->newArgument ();
965
info->TypeInfo (&CTYPE_UNDEFINED);
979
info->TypeInfo (&CTYPE_INT); // implicit int
966
980
info->Name (arg->Text ());
967
981
arg->Object (info);
968
982
common_settings (info, arg);
987
1001
id = (CT_InitDeclarator*) builder ().init_declarator ();
988
1002
dsi = sem_decl_specs ();
989
1003
CSemDeclarator csd (_err, dsi->make_type (), id);
990
if (! csd.Name () || ! current_scope->FunctionInfo ()) {
1004
if (! csd.Type () || ! csd.Name () || ! current_scope->FunctionInfo ()) {
992
1006
return (CTree*)0;
998
1012
SEM_ERROR (id, "declaration for unknown parameter `"
999
1013
<< csd.Name ()->Text () << "'");
1000
} else if (info->TypeInfo () && ! info->TypeInfo ()->is_undefined ()) {
1014
} else if (info->TypeInfo () && (*info->TypeInfo () != *csd.Type ())) {
1001
1015
SEM_ERROR__redefinition (id, "function parameter ", info);
1002
1016
} else if (id->Sons () == 2) {
1003
1017
SEM_ERROR (id, "parameter `" << csd.Name ()->Text ()
1059
1073
cds = builder ().decl_spec_seq1 ();
1060
1074
if (decl_specs ()->Sons () && // not first specifier?
1061
cds->NodeName () == CT_SimpleName::NodeId () && // identifier?
1075
cds->NodeName () == CT_SimpleName::NodeId () && // identifier?
1062
1076
lookup (cds->token ()->text (), TYPEDEF, true)) { // typedef name?
1064
1078
for (int i = decl_specs ()->Sons () - 1; i >= 0; i--) {
1101
1115
CTree *CSemantic::begin_decl () {
1102
1116
CT_DeclSpecSeq *dss = decl_specs ();
1103
1117
decl_specs_end ();
1104
decl_begin (new CSemDeclSpecs (_err, dss));
1118
decl_begin (new CSemDeclSpecs (_err, dss, support_implicit_int));
1412
bool CSemantic::isRedefiningTypedef (CObjectInfo* info, int obj_type) const {
1413
CTypedefInfo* tdef = info->TypedefInfo ();
1416
CTypeInfo* type = tdef->TypeInfo ();
1419
CObjectInfo* oinfo = 0;
1421
case CTypeInfo::TYPE_CLASS:
1422
oinfo = type->TypeClass () ? type->TypeClass ()->ClassInfo () : 0;
1424
case CTypeInfo::TYPE_UNION:
1425
oinfo = type->TypeUnion () ? type->TypeUnion ()->UnionInfo () : 0;
1427
case CTypeInfo::TYPE_ENUM:
1428
oinfo = type->TypeEnum () ? type->TypeEnum ()->EnumInfo () : 0;
1433
if (oinfo && oinfo->Name () == tdef->Name ())
1398
1439
} // namespace Puma