From 172538fdb418f7a2faab1f5a410f3b2cb8e18ba5 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 21 May 2021 18:41:54 -0400 Subject: 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 --- source/compiler-core/slang-diagnostic-sink.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source/compiler-core/slang-diagnostic-sink.cpp') 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; } } -- cgit v1.2.3