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 ();
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;
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);
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 ();
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 (),
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 ());
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);
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 () << " ";
622
unit.append (*tree->token ()->duplicate ());
635
unit << tree->token ()->text () << " ";
626
639
for (unsigned i = 0; i < (unsigned)tree->Sons (); i++)
627
640
copyTree (unit, tree->Son (i), gen_spaces, desturbing);
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 ()) {
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);
665
if (darg->TemplateArg ()) {
666
copyTree (unit, darg->TemplateArg (), gen_spaces);
669
replaced = dumpDeducedArg (darg, unit);
687
711
if (i) out << ",";
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 ();
696
out << arg->Value ()->convert_to_float ();
712
dumpDeducedArg (arg, out);
718
bool CCInstantiation::dumpDeducedArg (DeducedArgument *arg, std::ostringstream &out) {
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 ();
727
out << arg->Value ()->convert_to_float ();
703
735
CT_SimpleName *CCInstantiation::getSimpleName () {
704
736
if (PointOfInstantiation ()->NodeName () == CT_SimpleName::NodeId () ||
705
737
PointOfInstantiation ()->NodeName () == CT_QualName::NodeId () ||