~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to Puma/src/parser/cparser/CSemantic.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
303
303
      break;
304
304
    case TAG:
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 ())) {
 
312
          result = tdef;
 
313
        } else {
 
314
          result = (CObjectInfo*)0;
 
315
        }
 
316
      }
308
317
      break;
309
318
    case NON_TAG:
310
319
      for (unsigned i = scope->Objects (); i > 0; i--) {
564
573
  oi = lookup (name->Text (), scope, TAG, false);
565
574
 
566
575
  if (oi) {
 
576
    if (isRedefiningTypedef (oi, CTypeInfo::TYPE_ENUM)) {
 
577
      oi = oi->TypeInfo ()->TypeEnum ()->EnumInfo ();
 
578
    } else if (oi->TypedefInfo ()) {
 
579
      oi = 0;
 
580
    }
 
581
  }
 
582
  if (oi) {
567
583
    if (oi->EnumInfo () && oi->EnumInfo ()->isDefined ()) {
568
584
      SEM_ERROR__redefinition (ed, "enum ", oi);
569
585
      delete ed;
575
591
    }
576
592
  } 
577
593
  
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);
581
599
  Push (info);
582
600
 
583
601
  current_enum = info->EnumInfo ();
589
607
    oi->NextObject (info);
590
608
  ed->Object (info);
591
609
 
592
 
  // introduce alias of enum into enclosing non-class scope
593
 
  if (scope != current_scope)
594
 
    makeAlias (info, scope);
595
 
 
596
610
  return ed;
597
611
}
598
612
 
599
613
 
600
614
 
601
 
void CSemantic::makeAlias (CObjectInfo *info, CStructure *scope) {
602
 
  CMemberAliasInfo *minfo;
603
 
  
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 ());
610
 
  Push (minfo);
611
 
}
612
 
 
613
 
 
614
 
 
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);
635
635
  Push (info);
636
636
  
810
810
  oi = lookup (cs->Name ()->Text (), scope, TAG, false);
811
811
  
812
812
  if (oi) {
 
813
    if (isRedefiningTypedef (oi, CTypeInfo::TYPE_CLASS)) {
 
814
      oi = oi->TypeInfo ()->TypeClass ()->ClassInfo ();
 
815
    } else if (oi->TypedefInfo ()) {
 
816
      oi = 0;
 
817
    }
 
818
  }
 
819
  if (oi) {
813
820
    if ((oi->ClassInfo () && oi->ClassInfo ()->isDefined ()) ||
814
821
        (oi->UnionInfo () && oi->UnionInfo ()->isDefined ())) {
815
822
      SEM_ERROR__redefinition (cs, 
826
833
  } 
827
834
  
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 ()));
831
838
  } else {
832
 
    info = current_scope->newUnion ();
 
839
    info = scope->newUnion ();
833
840
    info->TypeInfo (new CTypeUnion (info->UnionInfo ()));
834
841
  }
835
842
  info->Name (cs->Name ()->Text ());
 
843
  if (scope != current_scope)
 
844
    info->AssignedScope (scope);
836
845
    
837
846
  // common settings
838
847
  enter_scope (info->Structure ()); 
843
852
  if (oi)
844
853
    oi->NextObject (info);
845
854
  _db->Insert (info);
846
 
  
847
 
  // introduce alias of class or union into enclosing non-class scope
848
 
  if (scope != current_scope->Parent ())
849
 
    makeAlias (info, scope);
850
855
 
851
856
  return cs;
852
857
}
898
903
  tag = (CT_ClassSpec*) builder ().elaborated_type_spec ();
899
904
  oi = lookup (tag->Name ()->Text (), TAG, true);
900
905
  
901
 
  if (oi)
 
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; 
 
915
  }
 
916
  if (oi) {
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;
907
922
    }
 
923
  }
908
924
 
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 ()));
916
932
  } else {
917
 
    info = current_scope->newEnum ();
 
933
    info = scope->newEnum ();
918
934
    info->TypeInfo (new CTypeEnum (info->EnumInfo ()));
919
935
  }
 
936
  if (scope != current_scope)
 
937
    info->AssignedScope (scope);
920
938
  
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 ());
926
944
  Push (info);
927
945
  if (oi)
928
946
    oi->NextObject (info);
929
947
  _db->Insert (info);
930
 
  
931
 
  // introduce alias of enum, class, or union into enclosing non-class scope
932
 
  if (scope != current_scope && ! oi)
933
 
    makeAlias (info, scope);
934
948
 
935
949
  return tag;
936
950
}
962
976
      return (CTree*)0;
963
977
    } 
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 ()) {
991
1005
    delete id;
992
1006
    return (CTree*)0;
993
1007
  } 
997
1011
  if (! info) {
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 ()
1058
1072
  
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?
1063
1077
 
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));
1105
1119
  return dss;
1106
1120
}
1107
1121
 
1375
1389
 
1376
1390
 
1377
1391
bool CSemantic::implicit_int () {
1378
 
  if (! current_scope->isNamespace ())
 
1392
  if (! support_implicit_int || ! current_scope->isNamespace ())
1379
1393
    return false;
1380
1394
    
1381
1395
  CT_DeclSpecSeq *dss = new CT_DeclSpecSeq;
1395
1409
}
1396
1410
 
1397
1411
 
 
1412
bool CSemantic::isRedefiningTypedef (CObjectInfo* info, int obj_type) const {
 
1413
  CTypedefInfo* tdef = info->TypedefInfo ();
 
1414
  if (! tdef)
 
1415
    return false;
 
1416
  CTypeInfo* type = tdef->TypeInfo ();
 
1417
  if (! type)
 
1418
    return false;
 
1419
  CObjectInfo* oinfo = 0;
 
1420
  switch (obj_type) {
 
1421
    case CTypeInfo::TYPE_CLASS: 
 
1422
      oinfo = type->TypeClass () ? type->TypeClass ()->ClassInfo () : 0; 
 
1423
      break;
 
1424
    case CTypeInfo::TYPE_UNION: 
 
1425
      oinfo = type->TypeUnion () ? type->TypeUnion ()->UnionInfo () : 0; 
 
1426
      break;
 
1427
    case CTypeInfo::TYPE_ENUM: 
 
1428
      oinfo = type->TypeEnum () ? type->TypeEnum ()->EnumInfo () : 0; 
 
1429
      break;
 
1430
    default: 
 
1431
      break;
 
1432
  }
 
1433
  if (oinfo && oinfo->Name () == tdef->Name ())
 
1434
    return true;
 
1435
  return false;
 
1436
}
 
1437
 
 
1438
 
1398
1439
} // namespace Puma