diff options
| author | Yong He <yonghe@outlook.com> | 2025-02-05 12:32:56 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-05 12:32:56 -0800 |
| commit | 7911c9437333692db275d2dff41264f4c8023be8 (patch) | |
| tree | dd83ca191f47aed0bd512dfb9412038a7b7d3f0e /source/slang/slang-check-decl.cpp | |
| parent | 613f43a080f84e2680fb78dc4ed60a553da3b418 (diff) | |
Use two-stage parsing to disambiguate generic app and comparison. (#6281)
* Use two-stage parsing to disambiguate generic app and comparison.
* Typo fix.
* Update doc.
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index b03126512..ab3335bfb 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -16,6 +16,7 @@ #include "slang-ast-reflect.h" #include "slang-ast-synthesis.h" #include "slang-lookup.h" +#include "slang-parser.h" #include "slang-syntax.h" #include <limits> @@ -4558,6 +4559,7 @@ void SemanticsVisitor::addRequiredParamsToSynthesizedDecl( synMemberExpr->elementIndices.add((uint32_t)i); synMemberExpr->type = elementType; synMemberExpr->type.isLeftValue = paramType.isLeftValue; + synMemberExpr->checked = true; synArgs.add(synMemberExpr); } } @@ -8165,6 +8167,7 @@ SemanticsContext SemanticsDeclBodyVisitor::registerDifferentiableTypesForFunc( void SemanticsDeclBodyVisitor::visitFunctionDeclBase(FunctionDeclBase* decl) { auto newContext = registerDifferentiableTypesForFunc(decl); + decl->body = maybeParseStmt(decl->body, newContext); if (const auto body = decl->body) { checkStmt(decl->body, newContext); @@ -9472,6 +9475,28 @@ void SemanticsDeclBodyVisitor::visitAggTypeDecl(AggTypeDecl* aggTypeDecl) } } +Stmt* SemanticsVisitor::maybeParseStmt(Stmt* stmt, const SemanticsContext& context) +{ + if (auto unparsedStmt = as<UnparsedStmt>(stmt)) + { + // Parse the statement now, and check it. + SemanticsVisitor subVisitor(context); + TokenList tokenList; + tokenList.m_tokens = _Move(unparsedStmt->tokens); + return parseUnparsedStmt( + m_astBuilder, + &subVisitor, + getShared()->getTranslationUnitRequest(), + unparsedStmt->sourceLanguage, + unparsedStmt->isInVariadicGenerics, + tokenList, + getShared()->getSink(), + unparsedStmt->currentScope, + unparsedStmt->outerScope); + } + return stmt; +} + void SemanticsDeclHeaderVisitor::cloneModifiers(Decl* dest, Decl* src) { dest->modifiers = src->modifiers; @@ -11182,6 +11207,9 @@ static void _dispatchDeclCheckingVisitor(Decl* decl, DeclCheckState state, Seman { switch (state) { + case DeclCheckState::ReadyForParserLookup: + // We don't need to do anything to make a decl ready for parser lookup. + break; case DeclCheckState::ModifiersChecked: SemanticsDeclModifiersVisitor(shared).dispatch(decl); break; |
