summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-02-13 13:09:11 -0800
committerGitHub <noreply@github.com>2025-02-13 13:09:11 -0800
commitadde2626720f23a5fd7151f6fb9109db14fc9263 (patch)
tree9ea4d2f0bfc9549c2e10b315b9d456264e66e649 /source
parent1ea2ab1b638b0e6d2c385b2b06157e6109417e6b (diff)
Fix modifier parsing. (#6347)
* Fix modifier parsing. * Fix. * Fix. * Fix.
Diffstat (limited to 'source')
-rw-r--r--source/slang-core-module/CMakeLists.txt2
-rw-r--r--source/slang/slang-ast-support-types.h3
-rw-r--r--source/slang/slang-lookup.cpp6
-rw-r--r--source/slang/slang-parser.cpp24
4 files changed, 23 insertions, 12 deletions
diff --git a/source/slang-core-module/CMakeLists.txt b/source/slang-core-module/CMakeLists.txt
index 051890826..67b0e9af2 100644
--- a/source/slang-core-module/CMakeLists.txt
+++ b/source/slang-core-module/CMakeLists.txt
@@ -121,7 +121,7 @@ add_custom_command(
slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source
${core_module_generated_header} -save-glsl-module-bin-source
${glsl_module_generated_header}
- DEPENDS slang-bootstrap
+ DEPENDS slang-bootstrap slang-without-embedded-core-module
VERBATIM
)
# Add a target so that we can depend on the above step when we create the glsl
diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h
index 72707ab38..d24007721 100644
--- a/source/slang/slang-ast-support-types.h
+++ b/source/slang/slang-ast-support-types.h
@@ -1217,7 +1217,8 @@ enum class LookupMask : uint8_t
Function = 0x2,
Value = 0x4,
Attribute = 0x8,
- Default = type | Function | Value,
+ SyntaxDecl = 0x10,
+ Default = type | Function | Value | SyntaxDecl,
};
/// Flags for options to be used when looking up declarations
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index 9b9034c63..a2284eaa8 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -71,7 +71,11 @@ bool DeclPassesLookupMask(Decl* decl, LookupMask mask)
{
return (int(mask) & int(LookupMask::Attribute)) != 0;
}
-
+ // syntax declaration
+ else if (const auto syntaxDecl = as<SyntaxDecl>(decl))
+ {
+ return (int(mask) & int(LookupMask::SyntaxDecl)) != 0;
+ }
// default behavior is to assume a value declaration
// (no overloading allowed)
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 38285c41f..82cb8caf3 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -1091,7 +1091,10 @@ static Token peekToken(Parser* parser)
return parser->tokenReader.peekToken();
}
-static SyntaxDecl* tryLookUpSyntaxDecl(Parser* parser, Name* name)
+static SyntaxDecl* tryLookUpSyntaxDecl(
+ Parser* parser,
+ Name* name,
+ LookupMask syntaxLookupMask = LookupMask::Default)
{
// Let's look up the name and see what we find.
@@ -1100,7 +1103,7 @@ static SyntaxDecl* tryLookUpSyntaxDecl(Parser* parser, Name* name)
nullptr, // no semantics visitor available yet
name,
parser->currentScope,
- LookupMask::Default,
+ syntaxLookupMask,
true);
// If we didn't find anything, or the result was overloaded,
@@ -1175,7 +1178,10 @@ bool tryParseUsingSyntaxDeclImpl(Parser* parser, SyntaxDecl* syntaxDecl, T** out
}
template<typename T>
-bool tryParseUsingSyntaxDecl(Parser* parser, T** outSyntax)
+bool tryParseUsingSyntaxDecl(
+ Parser* parser,
+ T** outSyntax,
+ LookupMask syntaxLookupMask = LookupMask::Default)
{
if (peekTokenType(parser) != TokenType::Identifier)
return false;
@@ -1183,7 +1189,7 @@ bool tryParseUsingSyntaxDecl(Parser* parser, T** outSyntax)
auto nameToken = peekToken(parser);
auto name = nameToken.getName();
- auto syntaxDecl = tryLookUpSyntaxDecl(parser, name);
+ auto syntaxDecl = tryLookUpSyntaxDecl(parser, name, syntaxLookupMask);
if (!syntaxDecl)
return false;
@@ -1191,7 +1197,7 @@ bool tryParseUsingSyntaxDecl(Parser* parser, T** outSyntax)
return tryParseUsingSyntaxDeclImpl<T>(parser, syntaxDecl, outSyntax);
}
-static Modifiers ParseModifiers(Parser* parser)
+static Modifiers ParseModifiers(Parser* parser, LookupMask modifierLookupMask = LookupMask::Default)
{
Modifiers modifiers;
Modifier** modifierLink = &modifiers.first;
@@ -1212,7 +1218,7 @@ static Modifiers ParseModifiers(Parser* parser)
Token nameToken = peekToken(parser);
Modifier* parsedModifier = nullptr;
- if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier))
+ if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier, modifierLookupMask))
{
parsedModifier->keywordName = nameToken.getName();
if (!parsedModifier->loc.isValid())
@@ -4253,7 +4259,7 @@ static ParamDecl* parseModernParamDecl(Parser* parser)
// like `in`, `out`, and `in out`/`inout` be applied to the
// type (after the colon).
//
- auto modifiers = ParseModifiers(parser);
+ auto modifiers = ParseModifiers(parser, LookupMask::SyntaxDecl);
// We want to allow both "modern"-style and traditional-style
// parameters to appear in any modern-style parameter list,
@@ -4918,7 +4924,7 @@ static DeclBase* ParseDeclWithModifiers(
// as a declaration keyword and parse a declaration using
// its associated callback:
Decl* parsedDecl = nullptr;
- if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl))
+ if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl, LookupMask::Default))
{
decl = parsedDecl;
break;
@@ -6293,7 +6299,7 @@ ExpressionStmt* Parser::ParseExpressionStatement()
ParamDecl* Parser::ParseParameter()
{
ParamDecl* parameter = astBuilder->create<ParamDecl>();
- parameter->modifiers = ParseModifiers(this);
+ parameter->modifiers = ParseModifiers(this, LookupMask::SyntaxDecl);
currentLookupScope = currentScope->parent;
_parseTraditionalParamDeclCommonBase(this, parameter, kDeclaratorParseOption_AllowEmpty);
resetLookupScope();