diff --git a/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp b/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp index 5ad03661..72e69af7 100644 --- a/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp +++ b/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp @@ -19,7 +19,7 @@ namespace return pos + 1 && (isalpha(value[pos + 1]) || value[pos + 1] == '_'); } - bool IsTokenJoiningOperatorForwardLookup(const std::string& value, unsigned pos) + bool IsTokenPastingOperatorForwardLookup(const std::string& value, unsigned pos) { return pos + 1 < value.size() && value[pos + 1] == '#'; } @@ -40,12 +40,12 @@ DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition(const unsig } DefinesStreamProxy::Define::Define() - : m_contains_token_joining_operators(false){}; + : m_contains_token_pasting_operators(false){}; DefinesStreamProxy::Define::Define(std::string name, std::string value) : m_name(std::move(name)), m_value(std::move(value)), - m_contains_token_joining_operators(false) + m_contains_token_pasting_operators(false) { } @@ -54,13 +54,13 @@ DefinesStreamProxy::MacroParameterState::MacroParameterState() { } -void DefinesStreamProxy::Define::IdentifyTokenJoinsOnly() +void DefinesStreamProxy::Define::IdentifyTokenPasteOperatorOnly() { for (auto i = 0u; i < m_value.size(); i++) { - if (m_value[i] == '#' && IsTokenJoiningOperatorForwardLookup(m_value, i)) + if (m_value[i] == '#' && IsTokenPastingOperatorForwardLookup(m_value, i)) { - m_contains_token_joining_operators = true; + m_contains_token_pasting_operators = true; return; } } @@ -70,7 +70,7 @@ void DefinesStreamProxy::Define::IdentifyParameters(const std::vector 2) out << std::string(input, m_start + 1, m_end - m_start - 2); } else { - assert(m_type == TokenJoinTokenType::IDENTIFIER || m_type == TokenJoinTokenType::SYMBOL); + assert(m_type == TokenPasteTokenType::IDENTIFIER || m_type == TokenPasteTokenType::SYMBOL); out << std::string(input, m_start, m_end - m_start); } } - TokenJoinTokenType m_type; + TokenPasteTokenType m_type; unsigned m_start; unsigned m_end; }; - void EmitJoinedToken( - ParserLine& line, unsigned& linePos, std::ostream& out, const std::string& input, const TokenJoinToken& token0, const TokenJoinToken& token1) + void EmitPastedTokens( + ParserLine& line, unsigned& linePos, std::ostream& out, const std::string& input, const TokenPasteToken& token0, const TokenPasteToken& token1) { - if ((token0.m_type == TokenJoinTokenType::STRING) != (token1.m_type == TokenJoinTokenType::STRING)) + if ((token0.m_type == TokenPasteTokenType::STRING) != (token1.m_type == TokenPasteTokenType::STRING)) throw new ParsingException(TokenPos(*line.m_filename, line.m_line_number, static_cast(linePos + 1)), "String token can only use token-pasting operator on other string token"); - if (token0.m_type == TokenJoinTokenType::STRING) + if (token0.m_type == TokenPasteTokenType::STRING) { out << '"'; token0.EmitValue(out, input); @@ -758,7 +758,7 @@ namespace } else { - assert(token0.m_type == TokenJoinTokenType::IDENTIFIER || token0.m_type == TokenJoinTokenType::SYMBOL); + assert(token0.m_type == TokenPasteTokenType::IDENTIFIER || token0.m_type == TokenPasteTokenType::SYMBOL); token0.EmitValue(out, input); token1.EmitValue(out, input); @@ -766,14 +766,14 @@ namespace } } // namespace -void DefinesStreamProxy::ProcessTokenJoiningOperators( +void DefinesStreamProxy::ProcessTokenPastingOperators( ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos) { std::ostringstream ss; - auto joinNext = false; - TokenJoinToken previousToken; - TokenJoinToken currentToken; + auto pasteNext = false; + TokenPasteToken previousToken; + TokenPasteToken currentToken; const auto inputSize = input.size(); for (auto i = 0u; i < inputSize;) @@ -786,16 +786,16 @@ void DefinesStreamProxy::ProcessTokenJoiningOperators( continue; } - if (c == '#' && IsTokenJoiningOperatorForwardLookup(input, i)) + if (c == '#' && IsTokenPastingOperatorForwardLookup(input, i)) { - if (currentToken.m_type == TokenJoinTokenType::NONE) - throw new ParsingException(CreatePos(line, linePos), "Cannot use token-joining operator without previous token"); + if (currentToken.m_type == TokenPasteTokenType::NONE) + throw new ParsingException(CreatePos(line, linePos), "Cannot use token-pasting operator without previous token"); if (previousToken.m_end < currentToken.m_start) ss << std::string(input, previousToken.m_end, currentToken.m_start - previousToken.m_end); previousToken = currentToken; - joinNext = true; + pasteNext = true; // Skip second # i += 2; @@ -803,11 +803,11 @@ void DefinesStreamProxy::ProcessTokenJoiningOperators( else { currentToken.SetFromInput(line, linePos, input, i); - if (joinNext) + if (pasteNext) { - EmitJoinedToken(line, linePos, ss, input, previousToken, currentToken); + EmitPastedTokens(line, linePos, ss, input, previousToken, currentToken); previousToken = currentToken; - joinNext = false; + pasteNext = false; } } } @@ -815,8 +815,8 @@ void DefinesStreamProxy::ProcessTokenJoiningOperators( if (inputSize > previousToken.m_end) ss << std::string(input, previousToken.m_end, inputSize - previousToken.m_end); - if (joinNext) - throw new ParsingException(CreatePos(line, linePos), "Cannot use token-joining operator without following token"); + if (pasteNext) + throw new ParsingException(CreatePos(line, linePos), "Cannot use token-pasting operator without following token"); input = ss.str(); } @@ -866,8 +866,8 @@ void DefinesStreamProxy::ExpandMacro(ParserLine& line, unsigned nestedPos = 0; ProcessNestedMacros(line, linePos, callstack, str, nestedPos); - if (macro->m_contains_token_joining_operators) - ProcessTokenJoiningOperators(line, linePos, callstack, str, nestedPos); + if (macro->m_contains_token_pasting_operators) + ProcessTokenPastingOperators(line, linePos, callstack, str, nestedPos); out << str; } diff --git a/src/Parser/Parsing/Impl/DefinesStreamProxy.h b/src/Parser/Parsing/Impl/DefinesStreamProxy.h index 73071eb6..21ff4fad 100644 --- a/src/Parser/Parsing/Impl/DefinesStreamProxy.h +++ b/src/Parser/Parsing/Impl/DefinesStreamProxy.h @@ -42,14 +42,14 @@ public: std::string m_name; std::string m_value; std::vector m_parameter_positions; - bool m_contains_token_joining_operators; + bool m_contains_token_pasting_operators; Define(); Define(std::string name, std::string value); void IdentifyParameters(const std::vector& parameterNames); private: - void IdentifyTokenJoinsOnly(); + void IdentifyTokenPasteOperatorOnly(); }; enum class ParameterState : uint8_t @@ -116,7 +116,7 @@ private: bool FindNextMacro(const std::string& input, unsigned& inputPos, unsigned& defineStart, const DefinesStreamProxy::Define*& define); - void ProcessTokenJoiningOperators(ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos); + void ProcessTokenPastingOperators(ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos); void InsertMacroParameters(std::ostringstream& out, const DefinesStreamProxy::Define* macro, std::vector& parameterValues); void ExpandMacro(ParserLine& line, unsigned& linePos,