@@ -61,15 +61,15 @@ const IR::Type_Declaration* SpecializationInfo::synthesize(ReferenceMap* refMap)
6161}
6262
6363const IR::Argument* SpecializationMap::convertArgument (
64- const IR::Argument* arg, SpecializationInfo* spec) {
64+ const IR::Argument* arg, SpecializationInfo* spec, const IR::Parameter* param ) {
6565 if (arg->expression ->is <IR::ConstructorCallExpression>()) {
6666 auto cce = arg->expression ->to <IR::ConstructorCallExpression>();
67- cstring nName = refMap->newName (" inst" );
67+ cstring nName = refMap->newName (param->name );
68+ IR::ID id (param->srcInfo , nName, param->name );
6869 auto decl = new IR::Declaration_Instance (
69- IR::ID (nName, nullptr ),
70- cce->constructedType , cce->arguments );
70+ param->srcInfo , id, cce->constructedType , cce->arguments );
7171 spec->declarations ->push_back (decl);
72- auto path = new IR::PathExpression (IR::ID (nName, nullptr ));
72+ auto path = new IR::PathExpression (param-> srcInfo , new IR::Path (param-> srcInfo , id ));
7373 return new IR::Argument (arg->srcInfo , arg->name , path);
7474 } else {
7575 return arg;
@@ -91,7 +91,9 @@ void SpecializationMap::addSpecialization(
9191 CHECK_NULL (ccc);
9292 spec->constructorArguments = new IR::Vector<IR::Argument>();
9393 for (auto ca : *invocation->arguments ) {
94- auto arg = convertArgument (ca, spec);
94+ auto param = cc->substitution .findParameter (ca);
95+ CHECK_NULL (param);
96+ auto arg = convertArgument (ca, spec, param);
9597 spec->constructorArguments ->push_back (arg);
9698 }
9799 spec->typeArguments = ccc->typeArguments ;
@@ -118,10 +120,14 @@ void SpecializationMap::addSpecialization(
118120 type = invocation->type ->to <IR::Type_Name>();
119121 typeArgs = new IR::Vector<IR::Type>();
120122 }
123+ Instantiation* inst = Instantiation::resolve (invocation, refMap, typeMap);
124+
121125 spec->typeArguments = typeArgs;
122126 CHECK_NULL (type);
123127 for (auto ca : *invocation->arguments ) {
124- auto arg = convertArgument (ca, spec);
128+ auto param = inst->substitution .findParameter (ca);
129+ CHECK_NULL (param);
130+ auto arg = convertArgument (ca, spec, param);
125131 spec->constructorArguments ->push_back (arg);
126132 }
127133 specializations.emplace (invocation, spec);
@@ -287,7 +293,7 @@ const IR::Node* Specialize::postorder(IR::Declaration_Instance* decl) {
287293 if (!name.isNullOrEmpty ()) {
288294 auto typeRef = new IR::Type_Name (IR::ID (name, nullptr ));
289295 replacement = new IR::Declaration_Instance (
290- decl->name , decl->annotations , typeRef,
296+ decl->srcInfo , decl-> name , decl->annotations , typeRef,
291297 new IR::Vector<IR::Argument>(), decl->initializer );
292298 LOG2 (" Replaced " << decl << " with " << replacement);
293299 }
0 commit comments