[WIP] Plumbing to expand polymorphic functions

This commit is contained in:
2017-05-04 21:26:43 -04:00
parent 93c563e073
commit 46ed9bdb3c
10 changed files with 130 additions and 7 deletions

View File

@@ -638,3 +638,42 @@ Function::IsPolyFunction() const {
return false;
}
std::vector<Function *> *
Function::ExpandPolyArguments() const {
std::vector<const Type *> toExpand;
std::vector<Function *> *expanded = new std::vector<Function *>();
for (size_t i = 0; i < args.size(); i++) {
if (args[i]->type->IsPolymorphicType()) {
toExpand.push_back(args[i]->type);
}
}
for (size_t i = 0; i < toExpand.size(); i++) {
const PolyType *pt = CastType<PolyType>(toExpand[i]->GetBaseType());
std::vector<AtomicType *>::iterator expanded;
expanded = pt->ExpandBegin();
for (; expanded != pt->ExpandEnd(); expanded++) {
Type *replacement = *expanded;
if (toExpand[i]->IsPointerType())
replacement = new PointerType(replacement,
toExpand[i]->GetVariability(),
toExpand[i]->IsConstType());
else if (toExpand[i]->IsArrayType())
replacement = new ArrayType(replacement,
(CastType<ArrayType>(toExpand[i]))->GetElementCount());
else if (toExpand[i]->IsReferenceType())
replacement = new ReferenceType(replacement);
printf("pretend I'm replacing %s with %s\n",
toExpand[i]->GetString().c_str(),
replacement->GetString().c_str());
}
}
return expanded;
}