From 714b0881974965e8fcfbc57b452ef648290d14a1 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 21 Jun 2019 17:39:32 -0400 Subject: Parsing CPP Compiler output (#994) * Added extractLine line parsing to StringUtil. Use for matching lines instead of calcLines. calcLines uses extractLine to extract lines. Fixed problems found in output of some tests- due to how a how final line is handled. Now a final line has a \r or \n\r combination, but nothing else after it, it is considered the last line (not the line after it). * Use StringUtil::extractLine in slang-generate. * Improved comment on extractLine * Remove test code from StringUtil::extractLine * Made StringUtil::extractLine act as if line terminators are 'separators'. Added unit-test-string.cpp - to check behavior. * Adding LineParser - not entirely necessary, but slightly easier to use. * Hack to output start of tests. * WIP parsing CPPCompiler output. * Make extractLine return a bool. * First attempt at Visual Studio output parsing. * Add handling for checking error returning from CPPCompiler. * First pass parsing output of Gcc/Clang. * Split out VisualStudioCompilerUtil and GCCCompilerUtil. Simplified parsing of versions. * Simplify CPPCompiler::Output interface. * Fix problem with cpp-compiler on linux targets. * Add shared library link error. * Improving GCC/Clang parsing output. * Make cpp compiler parsing function able to return a SlangResult. * Handling for 'info' on clang * Add expected result for c-compile-shared-library-error.c * * Add flags such that link errors on shared libraries are supported. * Added StringUtil::join * Turn off the link shared library unfound symbol option on MacOS because it causes an error (and it's not needed on that target). * Add natvis inclusion back to visual studio projects. * Display message to try and determine crash problem on travisbuild. * Fix bug in handling continuations for clang. Disabled output of exception text. * WIP: See what clang is outputting that is parsing incorrectly on travis. * More handling for travis clang parsing issue. * Restore natvis to core.vcxproj * Fix visual studio project such that it still as natvis. --- source/core/slang-string-util.cpp | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'source/core/slang-string-util.cpp') diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index 95caf8319..4295a2c52 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -39,6 +39,45 @@ static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; } } +/* static */void StringUtil::join(const List& values, char separator, StringBuilder& out) +{ + join(values, UnownedStringSlice(&separator, 1), out); +} + +/* static */void StringUtil::join(const List& values, const UnownedStringSlice& separator, StringBuilder& out) +{ + const Index count = values.getCount(); + if (count <= 0) + { + return; + } + out.append(values[0]); + for (Index i = 1; i < count; i++) + { + out.append(separator); + out.append(values[i]); + } +} + +/* static */void StringUtil::join(const UnownedStringSlice* values, Index valueCount, char separator, StringBuilder& out) +{ + join(values, valueCount, UnownedStringSlice(&separator, 1), out); +} + +/* static */void StringUtil::join(const UnownedStringSlice* values, Index valueCount, const UnownedStringSlice& separator, StringBuilder& out) +{ + if (valueCount <= 0) + { + return; + } + out.append(values[0]); + for (Index i = 1; i < valueCount; i++) + { + out.append(separator); + out.append(values[i]); + } +} + /* static */int StringUtil::indexOfInSplit(const UnownedStringSlice& in, char splitChar, const UnownedStringSlice& find) { const char* start = in.begin(); @@ -285,4 +324,45 @@ ComPtr StringUtil::createStringBlob(const String& string) } } +SLANG_FORCE_INLINE static bool _isDigit(char c) +{ + return (c >= '0' && c <= '9'); +} + +/* static */SlangResult StringUtil::parseInt(const UnownedStringSlice& in, Int& outValue) +{ + const char* cur = in.begin(); + const char* end = in.end(); + + bool negate = false; + if (cur < end && *cur == '-') + { + negate = true; + cur++; + } + + // We need at least one digit + if (cur >= end || !_isDigit(*cur)) + { + return SLANG_FAIL; + } + + Int value = *cur++ - '0'; + // Do the remaining digits + for (; cur < end; ++cur) + { + const char c = *cur; + if (!_isDigit(c)) + { + return SLANG_FAIL; + } + value = value * 10 + (c - '0'); + } + + value = negate ? -value : value; + + outValue = value; + return SLANG_OK; +} + } // namespace Slang -- cgit v1.2.3