diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-06-26 18:11:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-26 15:11:02 -0700 |
| commit | 7175f647f576a4d613928a87dc7140280df4217f (patch) | |
| tree | 0d5deab6d9ff79e4223e78f1c7d10c6dc6017318 /source | |
| parent | 49389f3a1e14576c95c0163c66554f67fe241ff7 (diff) | |
Multiple cast issue fix (#2940)
* Small fixes and improvements around reflection tool.
* Make PrettyWriter printing a class.
* WIP parens casting issue.
* Fix issue with multiple casts.
* Match previous location point for casting, with 'fast' path.
* Removed logic to output the found decl, as not needed to construct ExplicitCastExpr.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-parser.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index fdc5c19b5..d606698a1 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -4362,7 +4362,7 @@ namespace Slang nullptr, // no semantics visitor available yet name, parser->currentScope); - if(!lookupResult.isValid() || lookupResult.isOverloaded()) + if (!lookupResult.isValid() || lookupResult.isOverloaded()) return false; return _isType(lookupResult.item.declRef.getDecl()); @@ -4370,7 +4370,7 @@ namespace Slang static bool peekTypeName(Parser* parser) { - if(!parser->LookAheadToken(TokenType::Identifier)) + if (!parser->LookAheadToken(TokenType::Identifier)) return false; auto name = parser->tokenReader.peekToken().getName(); @@ -5597,14 +5597,26 @@ namespace Slang case TokenType::LParent: { Token openParen = parser->ReadToken(TokenType::LParent); - Expr* typeExpr = nullptr; - if (peekTypeName(parser) && parser->LookAheadToken(TokenType::RParent)) + + // Only handles cases of `(type)`, where type is a single identifier, + // and at this point the type is known + if (peekTypeName(parser) && parser->LookAheadToken(TokenType::RParent, 1)) { - TypeCastExpr* tcexpr = parser->astBuilder->create<ExplicitCastExpr>(); - parser->FillPosition(tcexpr); - tcexpr->functionExpr = typeExpr; + // Get the identifier for the type + const Token typeToken = advanceToken(parser); + // Consume the closing `)` parser->ReadToken(TokenType::RParent); + auto varExpr = parser->astBuilder->create<VarExpr>(); + varExpr->scope = parser->currentScope; + varExpr->loc = typeToken.loc; + varExpr->name = typeToken.getName(); + + TypeCastExpr* tcexpr = parser->astBuilder->create<ExplicitCastExpr>(); + tcexpr->loc = openParen.loc; + + tcexpr->functionExpr = varExpr; + auto arg = parsePrefixExpr(parser); tcexpr->arguments.add(arg); |
