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

« back to all changes in this revision

Viewing changes to Puma/gen-release/step2/src/CCInstantiation.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:
114
114
    real_inst = false;
115
115
// TEMPORARY HACK <---
116
116
 
117
 
  // �14.8.2 deduce template arguments
 
117
  // §14.8.2 deduce template arguments
118
118
  if (! First ().deduceArguments (real_inst))
119
119
    return instance;
120
120
  
151
151
}
152
152
 
153
153
 
154
 
// �14.5.4.1 matching of template partial specializations
 
154
// §14.5.4.1 matching of template partial specializations
155
155
bool CCInstantiation::chooseSpecialization () {
156
156
  bool no_default;
157
157
  unsigned entries;
200
200
    if (no_default)
201
201
      continue;
202
202
    
203
 
    // �14.5.4.1.2 try to match the partial specialization 
 
203
    // §14.5.4.1.2 try to match the partial specialization 
204
204
    // against the actual template argument list
205
205
    if (! cand->match ()) {
206
206
      // does not match, not a candidate for instantiation
218
218
    candidates.remove (0); 
219
219
  // if more than one specialization is matching, the
220
220
  // best specialization is chosen using the partial 
221
 
  // ordering rules (�14.5.4.2 and �14.5.5.2)
 
221
  // ordering rules (§14.5.4.2 and §14.5.5.2)
222
222
  } else if (candidates.length () > 2) {
223
223
    return chooseBestSpecialization ();
224
224
  }
230
230
bool CCInstantiation::chooseBestSpecialization () {
231
231
  // run a tournament to choose the best specialization 
232
232
  // comparing two specializations using the partial 
233
 
  // ordering rules (�14.5.4.2 and �14.5.5.2)
 
233
  // ordering rules (§14.5.4.2 and §14.5.5.2)
234
234
  InstantiationCandidate *challenger, *champion;
235
235
  unsigned num;
236
236
 
299
299
      if (cand->ObjectInfo ()->Tree () && cand->ObjectInfo ()->Tree ()->token ())
300
300
        err << cand->ObjectInfo ()->Tree ()->token ()->location ();
301
301
      if (i == 1)
302
 
        err << "candidates are ";
 
302
        err << "candidates are: ";
303
303
      else
304
 
        err << "               ";
305
 
      err << "`" << name.str ().c_str () << "'" << endMessage;
 
304
        err << "                ";
 
305
      err << name.str ().c_str () << endMessage;
306
306
    }
307
307
  }
308
308
 
354
354
 
355
355
 
356
356
void CCInstantiation::createPseudoInstance () {
357
 
  if (ObjectInfo ()->FunctionInfo ())
 
357
  CTemplateInstance *ti;
 
358
  if (ObjectInfo ()->FunctionInfo ()) {
358
359
    instance = makeScope ()->newFunction (true);
359
 
  else if (ObjectInfo ()->UnionInfo ())
 
360
    ti = instance->TemplateInstance ();
 
361
  } else if (ObjectInfo ()->UnionInfo ()) {
360
362
    instance = makeScope ()->newUnion (true);
361
 
  else
 
363
    ti = instance->TemplateInstance ();
 
364
  } else if (ObjectInfo ()->ClassInfo ()) {
362
365
    instance = makeScope ()->newClass (true);
363
 
  instance->TemplateInstance ()->isPseudoInstance (true);
 
366
    ti = instance->TemplateInstance ();
 
367
  } else if (ObjectInfo ()->TemplateParamInfo ()) {
 
368
    instance = ObjectInfo ()->TemplateParamInfo ()->TemplateTemplate ()->newTemplateParam (false);
 
369
    instance->TemplateParamInfo ()->TemplateInstance (new CTemplateInstance);
 
370
    instance->TemplateParamInfo ()->isTypeParam (ObjectInfo ()->TemplateParamInfo ()->isTypeParam ());
 
371
    instance->TemplateParamInfo ()->ValueType (ObjectInfo ()->TemplateParamInfo ()->ValueType ()->Duplicate ());
 
372
    instance->TemplateParamInfo ()->TemplateTemplate (ObjectInfo ()->TemplateParamInfo ()->TemplateTemplate ());
 
373
    ObjectInfo ()->NextObject (instance);
 
374
    ti = instance->TemplateParamInfo ()->TemplateInstance ();
 
375
  }
364
376
  instance->Name (ObjectInfo ()->Name ());  
365
377
  instance->ClassDB (ObjectInfo ()->ClassDB ());
366
378
  instance->SourceInfo ()->FileInfo (ObjectInfo ()->SourceInfo ()->FileInfo ());
367
379
  instance->SourceInfo ()->StartToken (PointOfInstantiation ()->token_node ());
368
380
  instance->TypeInfo (ObjectInfo ()->TypeInfo ()->Duplicate ());
369
 
  instance->TemplateInstance ()->PointOfInstantiation (getSimpleName (),
370
 
    current_scope);
371
 
  instance->TemplateInstance ()->Template (TemplateInfo ());
 
381
  ti->PointOfInstantiation (getSimpleName (), current_scope);
 
382
  ti->Template (TemplateInfo ());
 
383
  ti->isPseudoInstance (true);
372
384
  if (instance->FunctionInfo ())
373
385
    instance->TypeInfo ()->TypeFunction ()->FunctionInfo (instance->FunctionInfo ());
 
386
  else if (instance->TemplateParamInfo ())
 
387
    instance->TypeInfo ()->TypeTemplateParam ()->TemplateParamInfo (instance->TemplateParamInfo ());
374
388
  else
375
389
    instance->TypeInfo ()->TypeRecord ()->Record (instance->Record ());
376
390
  for (unsigned i = 0; i < DeducedArgs (); i++)
377
 
    instance->TemplateInstance ()->addDeducedArg (DeducedArg (i));
 
391
    ti->addDeducedArg (DeducedArg (i));
378
392
  for (unsigned i = 0; i < base_candidate->DeducedArgs (); i++)
379
 
    instance->TemplateInstance ()->addInstantiationArg (base_candidate->DeducedArg (i));
380
 
  TemplateInfo ()->addPseudoInstance (instance);
 
393
    ti->addInstantiationArg (base_candidate->DeducedArg (i));
 
394
  if (! instance->TemplateParamInfo ()) {
 
395
    TemplateInfo ()->addPseudoInstance (instance);
 
396
  }
381
397
}
382
398
 
383
399
 
616
632
  // copy the rest
617
633
  } else if (tree->NodeName () == CT_Token::NodeId ()) {
618
634
    if (tree->token ()) {
619
 
      if (gen_spaces || TRACE_INSTANCE_CODE)
620
 
        unit << tree->token ()->text () << " ";
621
 
      else
622
 
        unit.append (*tree->token ()->duplicate ()); 
 
635
      unit << tree->token ()->text () << " ";
623
636
    }
624
637
  }
625
638
  
626
639
  for (unsigned i = 0; i < (unsigned)tree->Sons (); i++)
627
640
    copyTree (unit, tree->Son (i), gen_spaces, desturbing);
 
641
    
 
642
  // function bodies might be error nodes, because they were skipped
 
643
  // ==> replace by ';'
 
644
  if (tree->NodeName () == CT_FctDef::NodeId ()) {
 
645
    if (((CT_FctDef*)tree)->Body ()->NodeName () == CT_Error::NodeId ()) {
 
646
      unit << ";";
 
647
    }
 
648
  }
628
649
}
629
650
 
630
651
 
641
662
      if (pos != -1) {
642
663
        // get deduced argument for this parameter and insert it here
643
664
        DeducedArgument *darg = DeducedArg (pos);
644
 
        copyTree (unit, darg->TemplateArg (), gen_spaces);
645
 
        replaced = true;
 
665
        if (darg->TemplateArg ()) {
 
666
          copyTree (unit, darg->TemplateArg (), gen_spaces);
 
667
          replaced = true;
 
668
        } else {
 
669
          replaced = dumpDeducedArg (darg, unit);
 
670
        }
646
671
      }
647
672
    }
648
673
  }
660
685
  std::ostringstream sname;
661
686
  sname << "%" << ObjectInfo ()->Name ();
662
687
  listArguments (*base_candidate, sname);
663
 
  sname << std::ends;
664
688
 
665
689
//  if (current_scope)
666
690
//    scope = current_scope->newNamespace ();    
685
709
      break;
686
710
 
687
711
    if (i) out << ",";
688
 
    if (arg->Type ()) {
689
 
      arg->Type ()->TypeText (out);
690
 
    } else if (arg->Value ()) {
691
 
      if (arg->Value ()->isSigned ())
692
 
        out << arg->Value ()->convert_to_int ();
693
 
      else if (arg->Value ()->isUnsigned ())
694
 
        out << arg->Value ()->convert_to_uint ();
695
 
      else 
696
 
        out << arg->Value ()->convert_to_float ();
697
 
    }
 
712
    dumpDeducedArg (arg, out);
698
713
  }
699
714
  out << ">";
700
715
}
701
716
 
702
717
 
 
718
bool CCInstantiation::dumpDeducedArg (DeducedArgument *arg, std::ostringstream &out) {
 
719
  if (arg->Type ()) {
 
720
    arg->Type ()->TypeText (out);
 
721
  } else if (arg->Value ()) {
 
722
    if (arg->Value ()->isSigned ())
 
723
      out << arg->Value ()->convert_to_int ();
 
724
    else if (arg->Value ()->isUnsigned ())
 
725
      out << arg->Value ()->convert_to_uint ();
 
726
    else 
 
727
      out << arg->Value ()->convert_to_float ();
 
728
  } else {
 
729
    return false;
 
730
  }
 
731
  return true;
 
732
}
 
733
 
 
734
 
703
735
CT_SimpleName *CCInstantiation::getSimpleName () {
704
736
  if (PointOfInstantiation ()->NodeName () == CT_SimpleName::NodeId () ||
705
737
      PointOfInstantiation ()->NodeName () == CT_QualName::NodeId () ||