Skip to content

Commit adde262

Browse files
authored
Fix modifier parsing. (#6347)
* Fix modifier parsing. * Fix. * Fix. * Fix.
1 parent 1ea2ab1 commit adde262

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

source/slang-core-module/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ add_custom_command(
121121
slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source
122122
${core_module_generated_header} -save-glsl-module-bin-source
123123
${glsl_module_generated_header}
124-
DEPENDS slang-bootstrap
124+
DEPENDS slang-bootstrap slang-without-embedded-core-module
125125
VERBATIM
126126
)
127127
# Add a target so that we can depend on the above step when we create the glsl

source/slang/slang-ast-support-types.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,8 @@ enum class LookupMask : uint8_t
12171217
Function = 0x2,
12181218
Value = 0x4,
12191219
Attribute = 0x8,
1220-
Default = type | Function | Value,
1220+
SyntaxDecl = 0x10,
1221+
Default = type | Function | Value | SyntaxDecl,
12211222
};
12221223

12231224
/// Flags for options to be used when looking up declarations

source/slang/slang-lookup.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ bool DeclPassesLookupMask(Decl* decl, LookupMask mask)
7171
{
7272
return (int(mask) & int(LookupMask::Attribute)) != 0;
7373
}
74-
74+
// syntax declaration
75+
else if (const auto syntaxDecl = as<SyntaxDecl>(decl))
76+
{
77+
return (int(mask) & int(LookupMask::SyntaxDecl)) != 0;
78+
}
7579
// default behavior is to assume a value declaration
7680
// (no overloading allowed)
7781

source/slang/slang-parser.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,10 @@ static Token peekToken(Parser* parser)
10911091
return parser->tokenReader.peekToken();
10921092
}
10931093

1094-
static SyntaxDecl* tryLookUpSyntaxDecl(Parser* parser, Name* name)
1094+
static SyntaxDecl* tryLookUpSyntaxDecl(
1095+
Parser* parser,
1096+
Name* name,
1097+
LookupMask syntaxLookupMask = LookupMask::Default)
10951098
{
10961099
// Let's look up the name and see what we find.
10971100

@@ -1100,7 +1103,7 @@ static SyntaxDecl* tryLookUpSyntaxDecl(Parser* parser, Name* name)
11001103
nullptr, // no semantics visitor available yet
11011104
name,
11021105
parser->currentScope,
1103-
LookupMask::Default,
1106+
syntaxLookupMask,
11041107
true);
11051108

11061109
// If we didn't find anything, or the result was overloaded,
@@ -1175,23 +1178,26 @@ bool tryParseUsingSyntaxDeclImpl(Parser* parser, SyntaxDecl* syntaxDecl, T** out
11751178
}
11761179

11771180
template<typename T>
1178-
bool tryParseUsingSyntaxDecl(Parser* parser, T** outSyntax)
1181+
bool tryParseUsingSyntaxDecl(
1182+
Parser* parser,
1183+
T** outSyntax,
1184+
LookupMask syntaxLookupMask = LookupMask::Default)
11791185
{
11801186
if (peekTokenType(parser) != TokenType::Identifier)
11811187
return false;
11821188

11831189
auto nameToken = peekToken(parser);
11841190
auto name = nameToken.getName();
11851191

1186-
auto syntaxDecl = tryLookUpSyntaxDecl(parser, name);
1192+
auto syntaxDecl = tryLookUpSyntaxDecl(parser, name, syntaxLookupMask);
11871193

11881194
if (!syntaxDecl)
11891195
return false;
11901196

11911197
return tryParseUsingSyntaxDeclImpl<T>(parser, syntaxDecl, outSyntax);
11921198
}
11931199

1194-
static Modifiers ParseModifiers(Parser* parser)
1200+
static Modifiers ParseModifiers(Parser* parser, LookupMask modifierLookupMask = LookupMask::Default)
11951201
{
11961202
Modifiers modifiers;
11971203
Modifier** modifierLink = &modifiers.first;
@@ -1212,7 +1218,7 @@ static Modifiers ParseModifiers(Parser* parser)
12121218
Token nameToken = peekToken(parser);
12131219

12141220
Modifier* parsedModifier = nullptr;
1215-
if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier))
1221+
if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier, modifierLookupMask))
12161222
{
12171223
parsedModifier->keywordName = nameToken.getName();
12181224
if (!parsedModifier->loc.isValid())
@@ -4253,7 +4259,7 @@ static ParamDecl* parseModernParamDecl(Parser* parser)
42534259
// like `in`, `out`, and `in out`/`inout` be applied to the
42544260
// type (after the colon).
42554261
//
4256-
auto modifiers = ParseModifiers(parser);
4262+
auto modifiers = ParseModifiers(parser, LookupMask::SyntaxDecl);
42574263

42584264
// We want to allow both "modern"-style and traditional-style
42594265
// parameters to appear in any modern-style parameter list,
@@ -4918,7 +4924,7 @@ static DeclBase* ParseDeclWithModifiers(
49184924
// as a declaration keyword and parse a declaration using
49194925
// its associated callback:
49204926
Decl* parsedDecl = nullptr;
4921-
if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl))
4927+
if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl, LookupMask::Default))
49224928
{
49234929
decl = parsedDecl;
49244930
break;
@@ -6293,7 +6299,7 @@ ExpressionStmt* Parser::ParseExpressionStatement()
62936299
ParamDecl* Parser::ParseParameter()
62946300
{
62956301
ParamDecl* parameter = astBuilder->create<ParamDecl>();
6296-
parameter->modifiers = ParseModifiers(this);
6302+
parameter->modifiers = ParseModifiers(this, LookupMask::SyntaxDecl);
62976303
currentLookupScope = currentScope->parent;
62986304
_parseTraditionalParamDeclCommonBase(this, parameter, kDeclaratorParseOption_AllowEmpty);
62996305
resetLookupScope();

tests/front-end/in-redeclare.slang

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//TEST:SIMPLE(filecheck=CHECK):-target spirv
2+
3+
// CHECK: OpEntryPoint
4+
5+
struct Foo{ float4 v; }
6+
7+
[shader("vertex")]
8+
float4 vert(in Foo in, in Foo o) : SV_Position
9+
{
10+
return in.v;
11+
}

0 commit comments

Comments
 (0)