summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-19 13:20:53 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-19 13:20:53 -0700
commit411b24361e31503171b2940ebd44dc436550a716 (patch)
treeb8f797ff5869d4130a35ac09fafd6f59bd2fa3e7 /source
parent838e8331da24744948539c12d2a8edcd9c594ee5 (diff)
Don't emit redundant `#line` directives
If the line number for the next token is within a small range, then go ahead and output newlines to get caught up, rather than emit a `#line` directive. This saves a small amount of clutter, and in the particular case where the number of lines is 1, it stops our current behavior of putting a directive on each line.
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index ef5df830f..21ae498b6 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -1424,6 +1424,9 @@ static void emitLineDirective(
emitRawText(context, charBuffer);
break;
+ // The incoming file path might use `/` and/or `\\` as
+ // a directory separator. We want to canonicalize this.
+ //
// TODO: should probably canonicalize paths to not use backslash somewhere else
// in the compilation pipeline...
case '\\':
@@ -1463,7 +1466,26 @@ static void advanceToSourceLocation(
|| sourceLocation.Line != context->loc.Line
|| sourceLocation.Col < context->loc.Col)
{
- emitLineDirectiveAndUpdateSourceLocation(context, sourceLocation);
+ // Special case: if we are in the same file, and within a small number
+ // of lines of the target location, then go ahead and output newlines
+ // to get us caught up.
+ enum { kSmallLineCount = 3 };
+ auto lineDiff = sourceLocation.Line - context->loc.Line;
+ if(sourceLocation.FileName == context->loc.FileName
+ && sourceLocation.Line > context->loc.Line
+ && lineDiff <= kSmallLineCount)
+ {
+ for(int ii = 0; ii < lineDiff; ++ii )
+ {
+ Emit(context, "\n");
+ }
+ assert(sourceLocation.Line == context->loc.Line);
+ }
+ else
+ {
+ // Go ahead and output a `#line` directive to get us caught up
+ emitLineDirectiveAndUpdateSourceLocation(context, sourceLocation);
+ }
}
// Now indent up to the appropriate column, so that error messages