summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-parser.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-08-10 01:58:41 -0700
committerGitHub <noreply@github.com>2022-08-10 01:58:41 -0700
commit89083c4b50af8e48e70b25b63cc62aca21ab706c (patch)
tree38e9544cd218dbeea0a2f26f267ac16f275c0291 /source/slang/slang-parser.cpp
parent9df7fcb023bd5a22f35ecd609b7a50cc6634976c (diff)
Language server pointer type support + add `DLLImport` test (#2350)
* Language server pointer type support. + Natvis for AST. * Add completion suggestion for GUID. * Make executable test able to use slang-rt. * Fix gcc argument for rpath. * Fix DLLImport on linux. * Fix windows. * Fix. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-parser.cpp')
-rw-r--r--source/slang/slang-parser.cpp30
1 files changed, 8 insertions, 22 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index cdf418d3d..17794a4b5 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -4336,26 +4336,9 @@ namespace Slang
// isn't a keyword should we fall back to the approach
// here.
//
+ bool prevHasSeenCompletionToken = hasSeenCompletionToken;
Expr* type = ParseType();
- if (type && hasSeenCompletionToken)
- {
- // If we encountered a completion token, just return the parsed expr
- // as an ExprStmt.
- for (auto tokenPos = startPos.tokenReaderCursor;
- tokenPos && tokenPos < tokenReader.getCursor().tokenReaderCursor;
- ++tokenPos)
- {
- if (tokenPos && tokenPos->type == TokenType::CompletionRequest)
- {
- auto exprStmt = astBuilder->create<ExpressionStmt>();
- exprStmt->loc = type->loc;
- exprStmt->expression = type;
- return exprStmt;
- }
- }
- }
-
// We don't actually care about the type, though, so
// don't retain it
//
@@ -4385,15 +4368,17 @@ namespace Slang
// general kinds of declarators (notably pointer declarators),
// so we'll need to be careful about this.
//
- // If the lookahead token is `*`, then we have to decide
- // whether to parse a pointer declarator or a multiply
- // expression. In this context it makes sense to disambiguate
+ // If the line being parsed token is `Something* ...`, then the `*`
+ // is already consumed by `ParseType` above and the current logic
+ // will continue to parse as var declaration instead of a mul expr.
+ // In this context it makes sense to disambiguate
// in favor of a pointer over a multiply, since a multiply
// expression can't appear at the start of a statement
// with any side effects.
//
//
- if (LookAheadToken(TokenType::Identifier) || LookAheadToken(TokenType::OpMul))
+ if (!hasSeenCompletionToken && (LookAheadToken(TokenType::Identifier) ||
+ LookAheadToken(TokenType::CompletionRequest)))
{
// Reset the cursor and try to parse a declaration now.
// Note: the declaration will consume any modifiers
@@ -4404,6 +4389,7 @@ namespace Slang
}
// Fallback: reset and parse an expression
+ hasSeenCompletionToken = prevHasSeenCompletionToken;
tokenReader.setCursor(startPos);
statement = ParseExpressionStatement();
}