summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-parser.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-05-12 04:33:21 +0800
committerGitHub <noreply@github.com>2023-05-11 13:33:21 -0700
commit332f60c19336252d907b83882aa70665ca93a9d2 (patch)
tree45a3aa3ba0aa999f1a6cea00e8fcb11f7dafd9b8 /source/slang/slang-parser.cpp
parentf414a14c1eac050ff2e1bdaf4f3dd2e4ec6f644e (diff)
MVP for higher order functions (#2849)
* MVP for higher order functions * Add shader subgroup partitioned glsl intrinsics * Implement parsing and checking for tuple types Currently there is no way to do anything useful with them from the source language however * neaten * Correct precedence of function type parsing * neaten * higher order function tests * function types of any arity * Inference for higher order functions * Add second test for unsynchronized params * regenerate vs projects * dx11 -> dx12 for saturated cooperations tests * Disable saturated cooperation tests on vulkan They fail on release builds in CI, not essential for the higher order function work however * remove saturated-cooperation tests * Remove unnecessary assert and clarify control flow in AddDeclRefOverloadCandidates * Add Tuple type name mangling * Use functype keyword to introduce function types * Add more inference tests for hof --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-parser.cpp')
-rw-r--r--source/slang/slang-parser.cpp73
1 files changed, 62 insertions, 11 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 78433a96f..cce4b7e7b 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -2243,6 +2243,39 @@ namespace Slang
return parseThisTypeExpr(parser);
}
+ // (a,b,c) style tuples, curently unused
+#if 0
+ static Expr* parseTupleTypeExpr(Parser* parser)
+ {
+ parser->ReadToken(TokenType::LParent);
+ TupleTypeExpr* expr = parser->astBuilder->create<TupleTypeExpr>();
+ while(!AdvanceIfMatch(parser, MatchedTokenType::Parentheses))
+ {
+ expr->members.add(parser->ParseTypeExp());
+ if(AdvanceIf(parser, TokenType::RParent))
+ break;
+ parser->ReadToken(TokenType::Comma);
+ }
+ return expr;
+ }
+#endif
+
+ static Expr* parseFuncTypeExpr(Parser* parser)
+ {
+ parser->ReadToken(TokenType::LParent);
+ auto expr = parser->astBuilder->create<FuncTypeExpr>();
+ while(!AdvanceIfMatch(parser, MatchedTokenType::Parentheses))
+ {
+ expr->parameters.add(parser->ParseTypeExp());
+ if(AdvanceIf(parser, TokenType::RParent))
+ break;
+ parser->ReadToken(TokenType::Comma);
+ }
+ parser->ReadToken(TokenType::RightArrow);
+ expr->result = parser->ParseTypeExp();
+ return expr;
+ }
+
/// Apply the given `modifiers` (if any) to the given `typeExpr`
static Expr* _applyModifiersToTypeExpr(Parser* parser, Expr* typeExpr, Modifiers const& modifiers)
{
@@ -2438,6 +2471,17 @@ namespace Slang
typeSpec.expr = parseThisTypeExpr(parser);
return typeSpec;
}
+ // Uncomment should we decide to enable (a,b,c) tuple types
+ // else if(parser->LookAheadToken(TokenType::LParent))
+ // {
+ // typeSpec.expr = parseTupleTypeExpr(parser);
+ // return typeSpec;
+ // }
+ else if(AdvanceIf(parser, "functype"))
+ {
+ typeSpec.expr = parseFuncTypeExpr(parser);
+ return typeSpec;
+ }
Token typeName = parser->ReadToken(TokenType::Identifier);
@@ -4820,6 +4864,8 @@ namespace Slang
return parsePostfixTypeSuffix(parser, typeExpr);
}
+ static Expr* _parseInfixTypeExpr(Parser* parser);
+
static Expr* _parseInfixTypeExprSuffix(Parser* parser, Expr* leftExpr)
{
for(;;)
@@ -4829,16 +4875,20 @@ namespace Slang
// a conjunction type expression.
auto loc = peekToken(parser).loc;
- if(!AdvanceIf(parser, TokenType::OpBitAnd))
- break;
-
- auto rightExpr = _parsePostfixTypeExpr(parser);
+ if(AdvanceIf(parser, TokenType::OpBitAnd))
+ {
+ auto rightExpr = _parsePostfixTypeExpr(parser);
- auto andExpr = parser->astBuilder->create<AndTypeExpr>();
- andExpr->loc = loc;
- andExpr->left = TypeExp(leftExpr);
- andExpr->right = TypeExp(rightExpr);
- leftExpr = andExpr;
+ auto andExpr = parser->astBuilder->create<AndTypeExpr>();
+ andExpr->loc = loc;
+ andExpr->left = TypeExp(leftExpr);
+ andExpr->right = TypeExp(rightExpr);
+ leftExpr = andExpr;
+ }
+ else
+ {
+ break;
+ }
}
return leftExpr;
@@ -4846,8 +4896,9 @@ namespace Slang
/// Parse an infix type expression.
///
- /// Currently, the only infix type expression we support is the `&`
- /// operator for forming interface conjunctions.
+ /// Currently, the only infix type expressions we support are the `&`
+ /// operator for forming interface conjunctions and the `->` operator
+ /// for functions.
///
static Expr* _parseInfixTypeExpr(Parser* parser)
{