diff options
| author | Yong He <yonghe@outlook.com> | 2017-10-30 19:31:52 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-30 19:31:52 -0400 |
| commit | 832d9c708891b10145c6648d893b04ca4a0b879a (patch) | |
| tree | e1f44fc27bf80d94de5ac0e866c7409b2adcec22 /source/slang/lower-to-ir.cpp | |
| parent | c24c173101c2c124401af77d8c513a23efac3b7e (diff) | |
| parent | 3ffdf610d05a9318731bd7237da530c3d312a9a9 (diff) | |
Merge pull request #235 from tfoleyNV/explicit-this-expr
Support `this` expressions (explicit and implicit)
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 2f0ea810e..93b84ad31 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -288,6 +288,15 @@ struct IRGenContext IRBuilder* irBuilder; + // The value to use for any `this` expressions + // that appear in the current context. + // + // TODO: If we ever allow nesting of (non-static) + // types, then we may need to support references + // to an "outer `this`", and this representation + // might be insufficient. + LoweredValInfo thisVal; + Session* getSession() { return shared->compileRequest->mSession; @@ -1008,6 +1017,11 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo> return subscriptValue(type, baseVal, indexVal); } + LoweredValInfo visitThisExpr(ThisExpr* expr) + { + return context->thisVal; + } + LoweredValInfo visitMemberExpr(MemberExpr* expr) { auto loweredType = lowerType(context, expr->type); @@ -2360,9 +2374,18 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> }; struct ParameterInfo { + // This AST-level type of the parameter Type* type; + + // The direction (`in` vs `out` vs `in out`) ParameterDirection direction; + + // The variable/parameter declaration for + // this parameter (if any) VarDeclBase* decl; + + // Is this the representation of a `this` parameter? + bool isThisParam = false; }; // // We need a way to compute the appropriate `ParameterDirection` for a @@ -2399,6 +2422,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> info.type = paramDecl->getType(); info.decl = paramDecl; info.direction = getParameterDirection(paramDecl); + info.isThisParam = false; return info; } // @@ -2492,6 +2516,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> info.type = type; info.decl = nullptr; info.direction = direction; + info.isThisParam = true; ioParameterLists->params.Add(info); } @@ -2808,6 +2833,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> DeclRef<VarDeclBase> paramDeclRef = makeDeclRef(paramDecl); subContext->shared->declValues.Add(paramDeclRef, paramVal); } + + if (paramInfo.isThisParam) + { + subContext->thisVal = paramVal; + } } lowerStmt(subContext, decl->Body); |
