diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-11 11:10:40 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-11 11:10:40 -0700 |
| commit | 8452129809858e0b51eca87f8965496e6b6735a1 (patch) | |
| tree | 0a351264f1085e39fd2b753dca3d4df60dc0b9a9 /tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp | |
| parent | 8de0a2ebc58c510d62df1a3d211643bfb463d9c4 (diff) | |
| parent | 1c77c4454facf4cb31d0b647ef6e5ce766d61498 (diff) | |
Merge branch 'master' into dyndispatch
Diffstat (limited to 'tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp')
| -rw-r--r-- | tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp b/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp index 3fa191394..5c8b521fe 100644 --- a/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp +++ b/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp @@ -1288,21 +1288,68 @@ void CPPExtractor::_consumeTypeModifiers() while (advanceIfStyle(IdentifierStyle::TypeModifier)); } +// True if two of these token types of the same type placed immediately after one another +// produce a different token. Can be conservative, as if not strictly required +// it will just mean more spacing in the output +static bool _canRepeatTokenType(TokenType type) +{ + switch (type) + { + case TokenType::OpAdd: + case TokenType::OpSub: + case TokenType::OpAnd: + case TokenType::OpOr: + case TokenType::OpGreater: + case TokenType::OpLess: + case TokenType::Identifier: + case TokenType::OpAssign: + case TokenType::Colon: + { + return false; + } + default: break; + } + return true; +} + +// Returns true if there needs to be a spave between the previous token type, and the current token +// type for correct output. It is assumed that the token stream is appropriate. +// The implementation might need more sophistication, but this at least avoids Blah const * -> Blahconst* +static bool _tokenConcatNeedsSpace(TokenType prev, TokenType cur) +{ + if ((cur == TokenType::OpAssign) || + (prev == cur && !_canRepeatTokenType(cur))) + { + return true; + } + return false; +} + UnownedStringSlice CPPExtractor::_concatTokens(TokenReader::ParsingCursor start) { auto endCursor = m_reader.getCursor(); m_reader.setCursor(start); + TokenType prevTokenType = TokenType::Unknown; + StringBuilder buf; while (!m_reader.isAtCursor(endCursor)) { const Token token = m_reader.advanceToken(); + // Check if we need a space between tokens + if (_tokenConcatNeedsSpace(prevTokenType, token.type)) + { + buf << " "; + } buf << token.getContent(); + + prevTokenType = token.type; } return m_typePool->getSlice(m_typePool->add(buf)); } + SlangResult CPPExtractor::_maybeParseType(UnownedStringSlice& outType, Index& ioTemplateDepth) { auto startCursor = m_reader.getCursor(); |
