From 879ec1b385d290a4375682ec613a9e7a1967fc7d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 10 Oct 2018 13:56:25 -0400 Subject: Feature/source loc refactor (#668) * * Remove the need for IRHighLevelDecoration in Emit * Use the IRLayoutDecoration for GeometryShaderPrimitiveTypeModifier * Initial look at at variable byte encoding, and simple unit test. * Fixing problems with comparison due to naming differences with slang/fxc. * * More tests and perf improvements for byte encoding. * Mechanism to detect processor and processor features in main slang header. * Split out cpu based defines into slang-cpu-defines.h so do not polute slang.h * Support for variable byte encoding on serialization. * Removed unused flag. * Fix warning. * Fix calcMsByte32 for 0 values without using intrinsic. * Fix a mistake in calculating maximum instruction size. * Introduced the idea of SourceUnit. * Small improvements around naming. Add more functionality - including getting the HumaneLoc. * Add support for #line default * Compiling with new SourceLoc handling. * Fix off by one on #line directives. * Can use 32bits for SourceLoc. Fix serialize to use that. * Small fixes and comment on usage. * Premake run. * Fix signed warning. * Fix typo on StringSlicePool::has found in review. --- source/slang/lexer.cpp | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'source/slang/lexer.cpp') diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp index 9ea86cc82..339d98d49 100644 --- a/source/slang/lexer.cpp +++ b/source/slang/lexer.cpp @@ -84,22 +84,22 @@ namespace Slang // Lexer void Lexer::initialize( - SourceFile* inSourceFile, + SourceUnit* inSourceUnit, DiagnosticSink* inSink, NamePool* inNamePool) { - sourceFile = inSourceFile; + sourceUnit = inSourceUnit; sink = inSink; namePool = inNamePool; - auto content = inSourceFile->content; + auto content = inSourceUnit->getSourceFile()->content; begin = content.begin(); cursor = content.begin(); end = content.end(); - spellingStartLoc = inSourceFile->sourceRange.begin; - presumedStartLoc = spellingStartLoc; + // Set the start location + startLoc = inSourceUnit->getRange().begin; tokenFlags = TokenFlag::AtStartOfLine | TokenFlag::AfterWhitespace; lexerFlags = 0; @@ -227,7 +227,7 @@ namespace Slang lexer->tokenFlags |= TokenFlag::ScrubbingNeeded; // Now try again, looking at the character after the - // escaped nmewline. + // escaped newline. continue; default: @@ -333,23 +333,7 @@ namespace Slang static SourceLoc getSourceLoc(Lexer* lexer) { - return lexer->presumedStartLoc + (lexer->cursor - lexer->begin); - } - - // Begin overriding the reported locations of tokens, - // based on a `#line` directives - void Lexer::startOverridingSourceLocations( - SourceLoc loc) - { - if(loc.isValid()) - { - presumedStartLoc = loc; - } - } - - void Lexer::stopOverridingSourceLocations() - { - presumedStartLoc = spellingStartLoc; + return lexer->startLoc + (lexer->cursor - lexer->begin); } static void lexDigits(Lexer* lexer, int base) -- cgit v1.2.3