summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-04-19 12:13:35 -0400
committerGitHub <noreply@github.com>2021-04-19 09:13:35 -0700
commit22b562d1a47443f266b114b4b207bcdd4eb3c54f (patch)
tree48dc9675bff696296b3b51cc012636f976c1f313 /source
parent2886bc35e7b023370a8b8d56d78e5335eee2eb98 (diff)
Infinite generic parsing bug fix (#1799)
* #include an absolute path didn't work - because paths were taken to always be relative. * Fix bug causing infinite loop in parser. * Add a faster path for LookAheadToken when the offset is 0. * Fix typo introduced in last commit.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-parser.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index bca493780..6d2abef49 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -147,9 +147,14 @@ namespace Slang
Token ReadToken();
Token ReadToken(TokenType type);
- Token ReadToken(const char * string);
- bool LookAheadToken(TokenType type, int offset = 0);
- bool LookAheadToken(const char * string, int offset = 0);
+ Token ReadToken(const char* string);
+
+ bool LookAheadToken(TokenType type);
+ bool LookAheadToken(const char* string);
+
+ bool LookAheadToken(TokenType type, int offset);
+ bool LookAheadToken(const char* string, int offset);
+
void parseSourceFile(ModuleDecl* program);
Decl* ParseStruct();
ClassDecl* ParseClass();
@@ -537,7 +542,7 @@ namespace Slang
}
}
- bool Parser::LookAheadToken(const char * string, int offset)
+ bool Parser::LookAheadToken(const char* string, int offset)
{
TokenReader r = tokenReader;
for (int ii = 0; ii < offset; ++ii)
@@ -556,6 +561,17 @@ namespace Slang
return r.peekTokenType() == type;
}
+ bool Parser::LookAheadToken(TokenType type)
+ {
+ return tokenReader.peekTokenType() == type;
+ }
+
+ bool Parser::LookAheadToken(const char* string)
+ {
+ const auto& token = tokenReader.peekToken();
+ return token.type == TokenType::Identifier && token.getContent() == string;
+ }
+
// Consume a token and return true it if matches, otherwise false
bool AdvanceIf(Parser* parser, TokenType tokenType)
{
@@ -1291,8 +1307,15 @@ namespace Slang
{
parser->ReadToken(TokenType::OpLess);
parser->genericDepth++;
- while (!parser->LookAheadToken(TokenType::OpGreater))
+ for (;;)
{
+ const TokenType tokenType = parser->tokenReader.peekTokenType();
+ if (tokenType == TokenType::OpGreater ||
+ tokenType == TokenType::EndOfFile)
+ {
+ break;
+ }
+
AddMember(decl, ParseGenericParamDecl(parser, decl));
if (parser->LookAheadToken(TokenType::OpGreater))