~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/src/parser/ccparser/CCSemantic.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:
145
145
  _postfix_expr.push (0);
146
146
  _in_expr.push (false); 
147
147
  _in_class_def.push (false); 
 
148
  _in_base_spec.push (false); 
148
149
  _in_extern_decl.push (0); 
149
150
  _in_nested_name.push (false); 
150
151
  _in_conv_type_id.push (false); 
161
162
// TEMPORARY HACK --->
162
163
  real_inst = false;
163
164
// TEMPORARY HACK <---
 
165
  support_implicit_int = false;
164
166
}
165
167
 
166
168
  
204
206
  // language string is top on builder stack
205
207
  CTree *lang = builder ().get_node (builder ().nodes () - 1);
206
208
  if (lang && lang->token ()) {
207
 
    const char *str = lang->token ()->text ().c_str ();
 
209
    const char *str = lang->token ()->text ();
208
210
    unsigned len = strlen (++str);
209
211
    if (len) {
210
212
      char *literal = new char[len];
374
376
    }
375
377
  } else
376
378
    qn << name->Text ();
377
 
  qn << std::ends;
378
379
}
379
380
 
380
381
 
455
456
}
456
457
 
457
458
 
 
459
bool CCSemantic::non_primary_loc () {
 
460
  Token* token = syntax ().token_provider->current ();
 
461
  if (token) {
 
462
    Unit* unit = (Unit*)token->belonging_to ();
 
463
    if (unit) {
 
464
      // if macro expansion, get the file containing the macro call
 
465
      while (unit && unit->isMacroExp ())
 
466
        unit = ((MacroUnit*)unit)->CallingUnit ();
 
467
      
 
468
      // not the primary file?
 
469
      if (unit != _file->Primary ()) {
 
470
        return true;
 
471
      }
 
472
    }
 
473
  }
 
474
  return false;
 
475
}
 
476
 
 
477
 
458
478
/*****************************************************************************/
459
479
/*                                                                           */
460
480
/*                                Names                                      */
477
497
  
478
498
  // not the same lookup as before, start new lookup
479
499
  shared_nl.reset ();
480
 
  if (in_nested) {
481
 
    shared_nl.lookupType (tok->text (), scope, nested, true);
 
500
  if (in_nested || in_base_spec ()) {
 
501
    shared_nl.lookupType (tok->dtext (), scope, nested, true);
482
502
    if (! shared_nl.Objects ())
483
 
      shared_nl.lookup (tok->text (), scope, nested, true);
 
503
      shared_nl.lookup (tok->dtext (), scope, nested, true);
484
504
  } else 
485
 
    shared_nl.lookup (tok->text (), scope, nested, true);
 
505
    shared_nl.lookup (tok->dtext (), scope, nested, true);
486
506
  
487
507
  // remember the parameters of the last lookup
488
508
  last_token_nl.tok = tok;
1312
1332
      return false;
1313
1333
    if (atl)
1314
1334
      for (unsigned i = 0; i < atl->Entries (); i++)
1315
 
        if (*atl->Entry (i) != *tatl->Entry (i) ||
 
1335
        if (*atl->Entry (i) != *tatl->Entry (i)  ||
1316
1336
            (consider_dependent && 
1317
1337
             (atl->Entry (i)->isDependent () || 
1318
 
              tatl->Entry (i)->isDependent ())))
 
1338
              tatl->Entry (i)->isDependent ())) )
1319
1339
          return false;
1320
1340
 
1321
1341
//    if ((f1->Record () && ! f2->Record ()) ||
1418
1438
  
1419
1439
  // complete semantic information about the enum
1420
1440
  info = current_scope->newEnum ();
 
1441
  setProtection (info);
1421
1442
  common_settings (info, ed);
1422
1443
  info->TypeInfo (new CTypeEnum (info->EnumInfo ()));
1423
1444
  info->Name (ed->Name ()->Text ());
1483
1504
  CTypeInfo *type;
1484
1505
  CConstant *v;
1485
1506
  CTree *init;
1486
 
  long value;
 
1507
  LONG_LONG value;
 
1508
  unsigned numenums;
1487
1509
  
1488
1510
  e = (CT_Enumerator*)builder ().enumerator_def ();
1489
1511
 
1490
1512
  if (e && e->Object ()) {
1491
1513
    einfo = e->Object ()->EnumeratorInfo ();
1492
1514
    enuminfo = einfo->Enum ();
 
1515
    numenums = enuminfo->Enumerators ();
1493
1516
    value = 0;
1494
1517
    
1495
1518
    // if the enumerator has an initializer, get the value 
1513
1536
        }
1514
1537
      }
1515
1538
    // else get the value from the predecessor enumerator incremented by 1
1516
 
    } else if (enuminfo->Enumerators () > 1) {
 
1539
    } else if (numenums > 1) {
1517
1540
      value = enuminfo->Enumerator (enuminfo->Enumerators () - 2)->Value ();
1518
1541
      value++;
1519
1542
    // else this is the first enumerator, so the value is 0
1523
1546
 
1524
1547
    // set the value
1525
1548
    einfo->Value (value);
 
1549
    
 
1550
    // determine the underlying type of the enumeration,
 
1551
    // must be big enough to hold all enumerator values
 
1552
    type = enuminfo->UnderlyingType ();
 
1553
    bool long_gt_int = LONG_SIZE > INT_SIZE;
 
1554
    if (value < 0) {
 
1555
      // signed type
 
1556
      if (type->is_unsigned ()) {
 
1557
        type = long_gt_int && type == &CTYPE_UNSIGNED_INT ? &CTYPE_LONG : &CTYPE_LONG_LONG;
 
1558
      } else if (value < LONG_MIN) {
 
1559
        type = &CTYPE_LONG_LONG;
 
1560
      } else if (value < INT_MIN) {
 
1561
        type = long_gt_int && type == &CTYPE_INT ? &CTYPE_LONG : &CTYPE_LONG_LONG;
 
1562
      } 
 
1563
    } else {
 
1564
      // unsigned, if value cannot be represented by a 
 
1565
      // signed type and no other value is signed
 
1566
      bool is_unsigned = numenums == 1 || type->is_unsigned ();
 
1567
      if (value <= INT_MAX) {
 
1568
        type = &CTYPE_INT;
 
1569
      } else if (value <= UINT_MAX) {
 
1570
        type = is_unsigned ? &CTYPE_UNSIGNED_INT : long_gt_int ? &CTYPE_LONG : &CTYPE_LONG_LONG;
 
1571
      } else if (value <= LONG_MAX) {
 
1572
        type = &CTYPE_LONG;
 
1573
      } else if (value <= ULONG_MAX) {
 
1574
        type = is_unsigned ? &CTYPE_UNSIGNED_LONG : &CTYPE_LONG_LONG;
 
1575
      } else if (value <= LLONG_MAX) {
 
1576
        type = &CTYPE_LONG_LONG;
 
1577
      } else {
 
1578
        type = is_unsigned ? &CTYPE_UNSIGNED_LONG_LONG : &CTYPE_LONG_LONG;
 
1579
      }
 
1580
    }
 
1581
    if (enuminfo->UnderlyingType ()->rank () < type->rank ()) {
 
1582
      enuminfo->UnderlyingType (type);
 
1583
    }
1526
1584
  }
1527
1585
  
1528
1586
  return e;
1590
1648
    reject_rules ();
1591
1649
    return (CTree*)0;
1592
1650
  }
1593
 
 
 
1651
  
1594
1652
  // union definition
1595
1653
  if (cs->NodeName () == CT_UnionDef::NodeId ()) {
1596
1654
    if (parsing_class_inst && ! tpl_inst->Instance () && 
1601
1659
      info = current_scope->newUnion ();
1602
1660
    info->TypeInfo (new CTypeUnion (info->UnionInfo ()));
1603
1661
    // set member access
 
1662
    setProtection (info);
1604
1663
    _protection.push (CProtection::PROT_PUBLIC);
1605
1664
  // class definition
1606
1665
  } else {
1612
1671
      info = current_scope->newClass ();
1613
1672
    info->TypeInfo (new CTypeClass (info->ClassInfo ()));
1614
1673
    // set member access
 
1674
    setProtection (info);
1615
1675
    if (cs->token ()->type () == TOK_STRUCT)
1616
1676
      _protection.push (CProtection::PROT_PUBLIC);
1617
1677
    else
1663
1723
 
1664
1724
 
1665
1725
void CCSemantic::add_base_classes (CTree *cs) {
1666
 
  CT_ClassDef *cd = (CT_ClassDef*)builder ().class_head (cs);
1667
 
  addBaseClasses (current_scope->ClassInfo (), cd); 
 
1726
  if (builder ().nodes ()) {
 
1727
    CT_ClassDef *cd = (CT_ClassDef*)builder ().class_head (cs);
 
1728
    addBaseClasses (current_scope->ClassInfo (), cd); 
 
1729
  }
1668
1730
}
1669
1731
 
1670
1732
 
1937
1999
  // implicit destructor
1938
2000
  if (! has_dtor) {
1939
2001
    std::ostringstream name;
1940
 
    name << "~" << scope->Name () << std::ends;
 
2002
    name << "~" << scope->Name ();
1941
2003
    type = new CTypeFunction (&CTYPE_UNDEFINED, new CTypeList (1), true);
1942
2004
    info = createMethod (name.str ().c_str (), scope, type);
1943
2005
    info->isDestructor (true);
2374
2436
  deleteContainer (2);
2375
2437
 
2376
2438
  // create tag
2377
 
  if (! is_typename) {
 
2439
  if (! is_typename && (!prev || prev->isTemplate ())) {
 
2440
    bool is_instance = parsing_class_inst && ! tpl_inst->Instance () && current_scope->isNamespace ();
2378
2441
    // forward class declaration
2379
2442
    if (tag->NodeName () == CT_ClassSpec::NodeId ()) {
2380
 
      if (parsing_class_inst && ! tpl_inst->Instance () && 
2381
 
          current_scope->isNamespace ()) {
 
2443
      if (is_instance) {
2382
2444
        info = new CClassInstance;
2383
2445
        tpl_inst->insertInstance (info);
2384
2446
      } else 
2386
2448
      info->TypeInfo (new CTypeClass (info->ClassInfo ()));
2387
2449
    // forward union declaration
2388
2450
    } else if (tag->NodeName () == CT_UnionSpec::NodeId ()) {
2389
 
      if (parsing_class_inst && ! tpl_inst->Instance () && 
2390
 
          current_scope->isNamespace ()) {
 
2451
      if (is_instance) {
2391
2452
        info = new CUnionInstance;
2392
2453
        tpl_inst->insertInstance (info);
2393
2454
      } else 
2399
2460
      info->TypeInfo (new CTypeEnum (info->EnumInfo ()));
2400
2461
    }
2401
2462
  
2402
 
    // �3.3.1 introduce name into enclosing non-class scope
2403
 
    // if declaration has the form `.. class-key identifier ..'
 
2463
    // �3.3.1 introduce name into enclosing non-class, non-function 
 
2464
    // prototype scope if declaration has the form `.. class-key identifier ..'
2404
2465
    scope = current_scope;
2405
2466
    if (is_friend || ! syntax ().look_ahead (TOK_SEMI_COLON)) {
2406
2467
      if (prev && info->Record ()) {
2407
2468
        info->Record ()->isHiddenForwardDecl (true);
2408
2469
      }
2409
 
      while (scope->isRecord ())
 
2470
      while (scope->isRecord () || scope->isFunction ())
2410
2471
        scope = scope->Parent ()->Structure ();
 
2472
    } else {
 
2473
      setProtection (info);
2411
2474
    }
2412
2475
 
2413
2476
    if (! info->EnumInfo ())
2414
2477
      info->ScopeInfo ()->Parent (scope);
2415
2478
    if (is_friend)
2416
2479
      info->Structure ()->addFriend (current_scope->Record ());
 
2480
    
2417
2481
    scope->addType (info);
2418
2482
    
2419
2483
    // complete semantic information about the forward declaration
2870
2934
    if (cse.isDependent (arg))
2871
2935
      pseudo = true;
2872
2936
 
2873
 
    // �14.3.2 address as non-type template argument
 
2937
    // §14.3.2 address as non-type template argument
2874
2938
    if ((type->isArray () || type->isFunction ()) || isAddrExpr (arg))
2875
2939
      calculateAddress (arg);
2876
2940
 
2877
 
    // �14.3.2.5 implicit template argument conversions
 
2941
    // §14.3.2.5 implicit template argument conversions
2878
2942
    if (type->isAddress ()) 
2879
2943
      type = type->BaseType ();
2880
2944
 
2968
3032
    return tn;
2969
3033
  }
2970
3034
 
2971
 
  // don't instantiate template template parameters, entity 
2972
 
  // names, and non-base templates
 
3035
  // don't instantiate entity names, and non-base templates
2973
3036
  if ((is_entity_name () && ! in_nested_name ()) || 
2974
 
      info->TemplateParamInfo () || 
2975
 
      (tpinfo && ! tpinfo->isBaseTemplate ()))
 
3037
      (tpinfo && ! tpinfo->isBaseTemplate ())) {
2976
3038
    instantiate = false;
 
3039
  // template template parameter
 
3040
  } else if (info->TemplateParamInfo ()) {
 
3041
    instantiate = true;
 
3042
    pseudo = true;
 
3043
  } 
2977
3044
 
2978
3045
  // instantiate non-function templates
2979
3046
  if (instantiate) {
3174
3241
    is_template = nl.Objects () ? false : true;
3175
3242
    for (unsigned i = 0; i < nl.Objects (); i++) {
3176
3243
      prev = nl.Object (i);
3177
 
      if (prev && prev->isTemplate () && equalType (prev->TypeInfo (), type)) {
 
3244
      if (prev && prev->isTemplate () && equalType (prev->TypeInfo (), type, false)) {
3178
3245
        is_template = true;
3179
3246
        break;
3180
3247
      }
3206
3273
 
3207
3274
  if (scope && scope->Name ())
3208
3275
    name << scope->Name () << "::";
3209
 
  name << oinfo->Name () << std::ends;
 
3276
  name << oinfo->Name ();
3210
3277
  info->Name (name.str ().c_str ());
3211
3278
}
3212
3279
 
3337
3404
  Push (info);
3338
3405
  
3339
3406
  // template template parameter
3340
 
  if (td->Parameters ())
 
3407
  if (td->Parameters ()) {
3341
3408
    info->TemplateTemplate (td->Parameters ()->Scope ()->TemplateInfo ());
 
3409
    info->TemplateTemplate ()->ObjectInfo (info);
 
3410
  }
3342
3411
  
3343
3412
  common_settings (info, td);
3344
3413
  info->Name (td->Name ()->Text ());
4205
4274
  // check for dependent name
4206
4275
  info = getLastResolvedName (ad->Member ());
4207
4276
  if (info && info->TypeInfo () && info->TypeInfo ()->isDependent ()) {
4208
 
    deleteContainer (3);
4209
4277
    return ad;
4210
4278
  }
4211
4279
 
4232
4300
    }
4233
4301
  }
4234
4302
 
4235
 
  // delete possibly created container object because it would
4236
 
  // be deleted by the builder only when the rule fails
4237
 
  deleteContainer (3);
4238
 
 
4239
4303
  // introduce aliases of the base class members looked up
4240
4304
  // into the current scope
4241
4305
  for (unsigned i = 0; i < nl.Objects (); i++) {