From c985f5f2f95dc95998fdfb8400baa0a04760ada2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 5 Nov 2020 13:43:00 -0500 Subject: Standard library save/loadable (#1592) * #include an absolute path didn't work - because paths were taken to always be relative. * Fix handling of access modifiers inside type definition. * Fix access problem for AST node. Make dumping produce a single function with switch, to potentially make available without Dump specific access. * WIP on serialization design doc. * Remove project references to previously generated files. * More docs on serialization design. * Improve serialization documentation. Remove unused function from IRSerialReader. * Small fixes around naming. Remove long comment from slang-serialize.h - as covered in serialization.md * Remove long comment in slang-serialize.h as covered in serialization.md * More information about doing replacements on read for AST and problems surrounding. * Typo fix. * Spelling fixes. * Value serialize. * Value types with inheritence. * Use value reflection serial conversion for more AST types * Use automatic serialization on more of AST. * Get the types via decltype, simplifies what the extractor has to do. * Update the serialization.md for the value serialization. * Small doc improvements. * Update project. * Remove ImportExternalDecl type Added addImportSymbol and ImportSymbol type Fixed bug in container which meant it wouldn't read back AST module * Because of change of how imports and handled, store objects as SerialPointers. * First pass symbol lookup from mangled names. * Cache current module looked up from mangled name. * Fix SourceLoc bug. Improve comments. * Added diagnostic on mangled symbol not being found * Fix typo. * WIP serializing stdlib. * WIP serializing stdlib in. * Fix problem serializing arrays that hold data that is already serialized. * Remove clash of names in MagicTypeModifier. * Make conversion from char to String explicit. Fix reference count issue with SerialReader. * Add code to save/load stdlib. * Use return code to avoid warning - SerialContainerUtil::write(module, options, &stream)) * Make all String numeric ctors explicit. Added isChar to UnownedStringSlice. Added operator== for UnownedStringSlice to String to avoid need to convert to String and allocate. * Add error check to readAllText. * tabs -> spaces on String.h * tab -> spaces String.cpp * Remove msg for StringBuilder, just build inplace for exceptions. * Check SerialClasses - for name clashes. Renamed Modifier::name as Modifier::keywordName * Handling of extensions when deserializing AST - updating the moduleDecl->mapTypeToCandidateExtensions Co-authored-by: Tim Foley --- source/core/slang-string.cpp | 166 +++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 83 deletions(-) (limited to 'source/core/slang-string.cpp') diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 3ce4c7ec9..975c83315 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -147,112 +147,112 @@ namespace Slang // - _EndLine EndLine; + _EndLine EndLine; String operator+(const char * op1, const String & op2) - { + { String result(op1); result.append(op2); return result; - } + } - String operator+(const String & op1, const char * op2) - { + String operator+(const String & op1, const char * op2) + { String result(op1); result.append(op2); return result; - } + } - String operator+(const String & op1, const String & op2) - { + String operator+(const String & op1, const String & op2) + { String result(op1); result.append(op2); return result; - } - - int StringToInt(const String & str, int radix) - { - if (str.startsWith("0x")) - return (int)strtoll(str.getBuffer(), NULL, 16); - else - return (int)strtoll(str.getBuffer(), NULL, radix); - } - unsigned int StringToUInt(const String & str, int radix) - { - if (str.startsWith("0x")) - return (unsigned int)strtoull(str.getBuffer(), NULL, 16); - else - return (unsigned int)strtoull(str.getBuffer(), NULL, radix); - } - double StringToDouble(const String & str) - { - return (double)strtod(str.getBuffer(), NULL); - } - float StringToFloat(const String & str) - { - return strtof(str.getBuffer(), NULL); - } + } + + int StringToInt(const String & str, int radix) + { + if (str.startsWith("0x")) + return (int)strtoll(str.getBuffer(), NULL, 16); + else + return (int)strtoll(str.getBuffer(), NULL, radix); + } + unsigned int StringToUInt(const String & str, int radix) + { + if (str.startsWith("0x")) + return (unsigned int)strtoull(str.getBuffer(), NULL, 16); + else + return (unsigned int)strtoull(str.getBuffer(), NULL, radix); + } + double StringToDouble(const String & str) + { + return (double)strtod(str.getBuffer(), NULL); + } + float StringToFloat(const String & str) + { + return strtof(str.getBuffer(), NULL); + } #if 0 - String String::ReplaceAll(String src, String dst) const - { - String rs = *this; - int index = 0; - int srcLen = src.length; - int len = rs.length; - while ((index = rs.IndexOf(src, index)) != -1) - { - rs = rs.SubString(0, index) + dst + rs.SubString(index + srcLen, len - index - srcLen); - len = rs.length; - } - return rs; - } + String String::ReplaceAll(String src, String dst) const + { + String rs = *this; + int index = 0; + int srcLen = src.length; + int len = rs.length; + while ((index = rs.IndexOf(src, index)) != -1) + { + rs = rs.SubString(0, index) + dst + rs.SubString(index + srcLen, len - index - srcLen); + len = rs.length; + } + return rs; + } #endif - String String::fromWString(const wchar_t * wstr) - { + String String::fromWString(const wchar_t * wstr) + { #ifdef _WIN32 - return Slang::Encoding::UTF16->ToString((const char*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t))); + return Slang::Encoding::UTF16->ToString((const char*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t))); #else - return Slang::Encoding::UTF32->ToString((const char*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t))); + return Slang::Encoding::UTF32->ToString((const char*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t))); #endif - } + } - String String::fromWString(const wchar_t * wstr, const wchar_t * wend) - { + String String::fromWString(const wchar_t * wstr, const wchar_t * wend) + { #ifdef _WIN32 - return Slang::Encoding::UTF16->ToString((const char*)wstr, (int)((wend - wstr) * sizeof(wchar_t))); + return Slang::Encoding::UTF16->ToString((const char*)wstr, (int)((wend - wstr) * sizeof(wchar_t))); #else - return Slang::Encoding::UTF32->ToString((const char*)wstr, (int)((wend - wstr) * sizeof(wchar_t))); + return Slang::Encoding::UTF32->ToString((const char*)wstr, (int)((wend - wstr) * sizeof(wchar_t))); #endif - } + } - String String::fromWChar(const wchar_t ch) - { + String String::fromWChar(const wchar_t ch) + { #ifdef _WIN32 - return Slang::Encoding::UTF16->ToString((const char*)&ch, (int)(sizeof(wchar_t))); + return Slang::Encoding::UTF16->ToString((const char*)&ch, (int)(sizeof(wchar_t))); #else - return Slang::Encoding::UTF32->ToString((const char*)&ch, (int)(sizeof(wchar_t))); + return Slang::Encoding::UTF32->ToString((const char*)&ch, (int)(sizeof(wchar_t))); #endif - } - - String String::fromUnicodePoint(unsigned int codePoint) - { - char buf[6]; - int len = Slang::EncodeUnicodePointToUTF8(buf, (int)codePoint); - buf[len] = 0; - return String(buf); - } - - OSString String::toWString(Index* outLength) const - { - if (!m_buffer) - { + } + + String String::fromUnicodePoint(unsigned int codePoint) + { + char buf[6]; + int len = Slang::EncodeUnicodePointToUTF8(buf, (int)codePoint); + buf[len] = 0; + return String(buf); + } + + OSString String::toWString(Index* outLength) const + { + if (!m_buffer) + { return OSString(); - } - else - { - List buf; + } + else + { + List buf; switch(sizeof(wchar_t)) { case 2: @@ -268,20 +268,20 @@ namespace Slang } auto length = Index(buf.getCount() / sizeof(wchar_t)); - if (outLength) - *outLength = length; + if (outLength) + *outLength = length; for(int ii = 0; ii < sizeof(wchar_t); ++ii) - buf.add(0); + buf.add(0); wchar_t* beginData = (wchar_t*)buf.getBuffer(); wchar_t* endData = beginData + length; - buf.detachBuffer(); + buf.detachBuffer(); return OSString(beginData, endData); - } - } + } + } // -- cgit v1.2.3