summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-12-28 02:13:37 -0500
committerGitHub <noreply@github.com>2017-12-28 02:13:37 -0500
commit7e340c29dfc0ca2f9ebb0189b698a9987da9c50c (patch)
tree3ae6f64ec51a2714ac06310723a1c320e91e5974 /source
parente370fe2984e7e260dc2d78d67b087e542d0102b0 (diff)
parent57d9498b69b8c751f631e0097e6316d04bf2425b (diff)
Merge pull request #337 from csyonghe/master
Using a visitor to replace lookup scopes of generic function's return type expr
Diffstat (limited to 'source')
-rw-r--r--source/slang/parser.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 35cc96b5c..662b75a2c 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -4,6 +4,7 @@
#include "compiler.h"
#include "lookup.h"
+#include "visitor.h"
namespace Slang
{
@@ -1099,6 +1100,40 @@ namespace Slang
}
}
+ // systematically replace all scopes in an expression tree
+ class ReplaceScopeVisitor : public ExprVisitor<ReplaceScopeVisitor>
+ {
+ public:
+ RefPtr<Scope> scope;
+ void visitDeclRefExpr(DeclRefExpr* expr)
+ {
+ expr->scope = scope;
+ }
+ void visitGenericAppExpr(GenericAppExpr * expr)
+ {
+ expr->FunctionExpr->accept(this, nullptr);
+ for (auto arg : expr->Arguments)
+ arg->accept(this, nullptr);
+ }
+ void visitIndexExpr(IndexExpr * expr)
+ {
+ expr->BaseExpression->accept(this, nullptr);
+ expr->IndexExpression->accept(this, nullptr);
+ }
+ void visitMemberExpr(MemberExpr * expr)
+ {
+ expr->BaseExpression->accept(this, nullptr);
+ expr->scope = scope;
+ }
+ void visitStaticMemberExpr(StaticMemberExpr * expr)
+ {
+ expr->BaseExpression->accept(this, nullptr);
+ expr->scope = scope;
+ }
+ void visitExpr(Expr* /*expr*/)
+ {}
+ };
+
static RefPtr<Decl> ParseFuncDeclHeader(
Parser* parser,
DeclaratorInfo const& declaratorInfo,
@@ -1114,8 +1149,9 @@ namespace Slang
// if return type is a DeclRef type, we need to update its scope to use this function decl's scope
// so that LookUp can find the generic type parameters declared after the function name
- if (auto declRefRetType = declaratorInfo.typeSpec.As<DeclRefExpr>())
- declRefRetType->scope = parser->currentScope;
+ ReplaceScopeVisitor replaceScopeVisitor;
+ replaceScopeVisitor.scope = parser->currentScope;
+ declaratorInfo.typeSpec->accept(&replaceScopeVisitor, nullptr);
decl->ReturnType = TypeExp(declaratorInfo.typeSpec);
auto parseFuncDeclHeaderInner = [&](GenericDecl *)