diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-05 16:39:38 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-05 16:39:38 -0500 |
| commit | 296e89ca4f3d6d99126bf2ee59666bc946add431 (patch) | |
| tree | bff41e36c9b6843d83a5ca5e83645310be6687f3 /source/slang/lower-to-ir.cpp | |
| parent | c6fb1de9547bd24a693915b758cc35499f1d949f (diff) | |
| parent | ff7c46a11787ca6ecebf0a224772a41efef33fc0 (diff) | |
Merge pull request #243 from csyonghe/master
Adding associated types
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index a659326e4..2672c5698 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -871,9 +871,12 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower auto subs = declRef.substitutions; while(subs) { - for(auto aa : subs->args) + if (auto genSubst = subs.As<GenericSubstitution>()) { - (*ioArgs).Add(getSimpleVal(context, lowerVal(context, aa))); + for (auto aa : genSubst->args) + { + (*ioArgs).Add(getSimpleVal(context, lowerVal(context, aa))); + } } subs = subs->outer; } @@ -2060,6 +2063,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> SLANG_UNIMPLEMENTED_X("decl catch-all"); } + LoweredValInfo visitTypeDefDecl(TypeDefDecl * decl) + { + return LoweredValInfo::simple(context->irBuilder->getTypeVal(decl->type.type)); + } + LoweredValInfo visitGenericTypeParamDecl(GenericTypeParamDecl* /*decl*/) { return LoweredValInfo(); @@ -2303,9 +2311,13 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> ensureDecl(context, inheritanceDecl); } - // For now, we don't have an IR-level representation - // for the type itself. - return LoweredValInfo(); + // TODO: we currently store a Decl* in the witness table, which causes this function + // being invoked to translate the witness table entry into an IRValue. + // We should really allow a witness table entry to represent a type and not having to + // construct the type here. The current implementation will not work when the struct type + // is defined in a generic parent (we lose the environmental substitutions). + return LoweredValInfo::simple(context->irBuilder->getTypeVal(DeclRefType::Create(context->getSession(), + DeclRef<Decl>(decl, nullptr)))); } @@ -3029,24 +3041,33 @@ RefPtr<Substitutions> lowerSubstitutions( { if(!subst) return nullptr; + RefPtr<Substitutions> result; + if (auto genSubst = dynamic_cast<GenericSubstitution*>(subst)) + { + RefPtr<GenericSubstitution> newSubst = new GenericSubstitution(); + newSubst->genericDecl = genSubst->genericDecl; + + for (auto arg : genSubst->args) + { + auto newArg = lowerSubstitutionArg(context, arg); + newSubst->args.Add(newArg); + } - RefPtr<Substitutions> newSubst = new Substitutions(); + result = newSubst; + } + else if (auto thisSubst = dynamic_cast<ThisTypeSubstitution*>(subst)) + { + RefPtr<ThisTypeSubstitution> newSubst = new ThisTypeSubstitution(); + newSubst->sourceType = lowerSubstitutionArg(context, thisSubst->sourceType); + result = newSubst; + } if (subst->outer) { - newSubst->outer = lowerSubstitutions( + result->outer = lowerSubstitutions( context, subst->outer); } - - newSubst->genericDecl = subst->genericDecl; - - for (auto arg : subst->args) - { - auto newArg = lowerSubstitutionArg(context, arg); - newSubst->args.Add(newArg); - } - - return newSubst; + return result; } LoweredValInfo emitDeclRef( @@ -3059,7 +3080,7 @@ LoweredValInfo emitDeclRef( // If this declaration reference doesn't involve any specializations, // then we are done at this point. - if(!declRef.substitutions) + if(!hasGenericSubstitutions(declRef.substitutions)) return loweredDecl; auto val = getSimpleVal(context, loweredDecl); |
