summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-diagnostic-sink.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-05-21 18:41:54 -0400
committerGitHub <noreply@github.com>2021-05-21 15:41:54 -0700
commit172538fdb418f7a2faab1f5a410f3b2cb8e18ba5 (patch)
treeb17fd1cae7ace4bb3f2dbdd4ad29f4f57df0b286 /source/compiler-core/slang-diagnostic-sink.cpp
parent0389546b0b065303d3c6874891a9fab4428910b9 (diff)
Downstream option handling (#1850)
* #include an absolute path didn't work - because paths were taken to always be relative. * Added SourceLoc handling for command line parsing. * Fix typo in debug. * Fix issue around the DiagnosticSink used in options parsing not having a writer available - by having DiagnosticSink parenting. * Small rename for clarity. * WIP extracting command line args for downstream tools. * Unit tests/bug fixes around extracting args. * Use DownstreamArgs in the EndToEndCompileRequest * Passing downstream compiler options downstream. * Fix issue with endToEndReq being nullptr. * Fix issue with diagnostics number change. * Small improvements to how the source line is displayed if it's too long. Default to 120, as suggested in previous review. Co-authored-by: T. Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/compiler-core/slang-diagnostic-sink.cpp')
-rw-r--r--source/compiler-core/slang-diagnostic-sink.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/source/compiler-core/slang-diagnostic-sink.cpp b/source/compiler-core/slang-diagnostic-sink.cpp
index 0ad16b2b4..a6502abc9 100644
--- a/source/compiler-core/slang-diagnostic-sink.cpp
+++ b/source/compiler-core/slang-diagnostic-sink.cpp
@@ -239,10 +239,10 @@ static UnownedStringSlice _extractLineContainingPosition(const UnownedStringSlic
return UnownedStringSlice(start, end);
}
-static void _reduceLength(Index startIndex, StringBuilder& ioBuf)
+static void _reduceLength(Index startIndex, const UnownedStringSlice& prefix, StringBuilder& ioBuf)
{
StringBuilder buf;
- buf << "...";
+ buf << prefix;
buf.append(ioBuf.getUnownedSlice().tail(startIndex));
ioBuf = buf;
}
@@ -313,21 +313,28 @@ static void _sourceLocationNoteDiagnostic(DiagnosticSink* sink, SourceView* sour
const Index maxLength = sink->getSourceLineMaxLength();
if (maxLength > 0)
{
- Index endIndex = lexer ? caretLine.getLength() : (caretIndex + (maxLength / 4));
+ const UnownedStringSlice ellipsis = UnownedStringSlice::fromLiteral("...");
+ const UnownedStringSlice spaces = UnownedStringSlice::fromLiteral(" ");
+ SLANG_ASSERT(ellipsis.getLength() == spaces.getLength());
+
+ // We use the caretLine length if we have a lexer, because it will have underscores such that it's end is the end of
+ // the item at issue.
+ // If we don't have the lexer, we guesstimate using 1/4 of the maximum length
+ const Index endIndex = lexer ? caretLine.getLength() : (caretIndex + (maxLength / 4));
if (endIndex > maxLength)
{
- Index startIndex = endIndex - (maxLength - 3);
+ const Index startIndex = endIndex - (maxLength - ellipsis.getLength());
- _reduceLength(startIndex, sourceLine);
- _reduceLength(startIndex, caretLine);
+ _reduceLength(startIndex, ellipsis, sourceLine);
+ _reduceLength(startIndex, spaces, caretLine);
}
if (sourceLine.getLength() > maxLength)
{
StringBuilder buf;
- buf.append(sourceLine.getUnownedSlice().head(maxLength - 3));
- buf << "...";
+ buf.append(sourceLine.getUnownedSlice().head(maxLength - ellipsis.getLength()));
+ buf << ellipsis;
sourceLine = buf;
}
}