From 360d4f7a17a066cc878cdb2c558464bfdeaa3418 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 17 Feb 2021 19:04:48 -0500 Subject: More #line improvements (#1713) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP: First pass in supporting output of line error information. * Add support for lexing to better be able to indicate SourceLocation information. * Fix lexer usage in DiagnosticSink in C++ extractor. * Update diagnostics tests to have line location info. * Fixed test expected output that now have source location information in them. * Better handling of tab. * Fix test expected results for tabbing change. * DiagnosticLexer -> DiagnosticSink::SourceLocationLexer Added line continuation tests. * Fix typo. * Added String::appendRepeatedChar * Change to rerun tests. * Added source locations to IR dumping. * Output column for IR dump source loc. * Add support for closing brace location to AST. Use closing brace location in lowering when adding return void. * Set the source location through SourceLoc - simplifies identifying if current loc is valid. * Copy terminator sloc. * Test for improved #line handling. * Made writer the last parameter for dumpIR. Small improvements to comments. * Disable sloc output on dump IR by default. * Fix issue with #line and inlining. * Fix for output with improved #line output. * Small comment change - mainly to kick off TC build. Co-authored-by: Tim Foley --- source/slang/slang-parser.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 68d06714d..493e707c2 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -557,6 +557,16 @@ namespace Slang return false; } + bool AdvanceIf(Parser* parser, TokenType tokenType, Token* outToken) + { + if (parser->LookAheadToken(tokenType)) + { + *outToken = parser->ReadToken(); + return true; + } + return false; + } + // Consume a token and return true it if matches, otherwise false bool AdvanceIf(Parser* parser, char const* text) { @@ -590,6 +600,24 @@ namespace Slang return false; } + bool AdvanceIfMatch(Parser* parser, TokenType tokenType, Token* outToken) + { + // If we've run into a syntax error, but haven't recovered inside + // the block, then try to recover here. + if (parser->isRecovering) + { + TryRecoverBefore(parser, tokenType); + } + if (AdvanceIf(parser, tokenType, outToken)) + return true; + if (parser->tokenReader.peekTokenType() == TokenType::EndOfFile) + { + *outToken = parser->ReadToken(tokenType); + return true; + } + return false; + } + NodeBase* parseTypeDef(Parser* parser, void* /*userData*/) { TypeDefDecl* typeDefDecl = parser->astBuilder->create(); @@ -3925,7 +3953,9 @@ namespace Slang { FillPosition(blockStatement); } - while (!AdvanceIfMatch(this, TokenType::RBrace)) + + Token closingBraceToken; + while (!AdvanceIfMatch(this, TokenType::RBrace, &closingBraceToken)) { auto stmt = ParseStatement(); if(stmt) @@ -3952,6 +3982,9 @@ namespace Slang } PopScope(); + // Save the closing braces source loc + blockStatement->closingSourceLoc = closingBraceToken.loc; + if(!body) { body = astBuilder->create(); -- cgit v1.2.3