From 494e09af2cebafa34db49dc1f60afd43aebed619 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 29 Oct 2020 11:45:56 -0400 Subject: Handling imported/exporting symbols from serialized modules (#1589) * #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. Co-authored-by: Tim Foley --- source/slang/slang-mangled-lexer.cpp | 55 +++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'source/slang/slang-mangled-lexer.cpp') diff --git a/source/slang/slang-mangled-lexer.cpp b/source/slang/slang-mangled-lexer.cpp index f1f5ec903..237f9f2a5 100644 --- a/source/slang/slang-mangled-lexer.cpp +++ b/source/slang/slang-mangled-lexer.cpp @@ -7,13 +7,13 @@ namespace Slang { UInt MangledLexer::readCount() { - int c = _peek(); - if (!_isDigit((char)c)) + int c = peekChar(); + if (!CharUtil::isDigit((char)c)) { SLANG_UNEXPECTED("bad name mangling"); UNREACHABLE_RETURN(0); } - _next(); + nextChar(); if (c == '0') return 0; @@ -22,25 +22,25 @@ UInt MangledLexer::readCount() for (;;) { count = count * 10 + c - '0'; - c = _peek(); - if (!_isDigit((char)c)) + c = peekChar(); + if (!CharUtil::isDigit((char)c)) return count; - _next(); + nextChar(); } } void MangledLexer::readGenericParam() { - switch (_peek()) + switch (peekChar()) { case 'T': case 'C': - _next(); + nextChar(); break; case 'v': - _next(); + nextChar(); readType(); break; @@ -62,7 +62,7 @@ void MangledLexer::readGenericParams() void MangledLexer::readType() { - int c = _peek(); + int c = peekChar(); switch (c) { case 'V': @@ -73,11 +73,11 @@ void MangledLexer::readType() case 'h': case 'f': case 'd': - _next(); + nextChar(); break; case 'v': - _next(); + nextChar(); readSimpleIntVal(); readType(); break; @@ -90,15 +90,15 @@ void MangledLexer::readType() void MangledLexer::readVal() { - switch (_peek()) + switch (peekChar()) { case 'k': - _next(); + nextChar(); readCount(); break; case 'K': - _next(); + nextChar(); readRawStringSegment(); break; @@ -124,7 +124,7 @@ UnownedStringSlice MangledLexer::readSimpleName() UnownedStringSlice result; for (;;) { - int c = _peek(); + int c = peekChar(); if (c == 'g') { @@ -142,7 +142,7 @@ UnownedStringSlice MangledLexer::readSimpleName() continue; } - if (!_isDigit((char)c)) + if (!CharUtil::isDigit((char)c)) return result; // Read the length part @@ -181,4 +181,25 @@ UInt MangledLexer::readParamCount() return count; } +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MangledNameParser !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +/* static */SlangResult MangledNameParser::parseModuleName(const UnownedStringSlice& in, UnownedStringSlice& outModuleName) +{ + MangledLexer lexer(in); + + if (lexer.peekChar() == 'T') + { + lexer.nextChar(); + } + + UnownedStringSlice name = lexer.readRawStringSegment(); + if (name.getLength() == 0) + { + return SLANG_FAIL; + } + + outModuleName = name; + return SLANG_OK; +} + } // namespace Slang -- cgit v1.2.3