mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-11-07 01:01:59 +00:00
fix: Paste tokens in arguments of nested macros (#1062)
This commit is contained in:
2 files changed
+39
-1
No files matched your search
@@ -7,6 +7,7 @@
|
||||
#include "Parsing/Simple/SimpleExpressionInterpreter.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
@@ -879,8 +880,25 @@ void DefinesStreamProxy::ExpandMacro(ParserLine& line,
|
||||
const Define* macro,
|
||||
const std::vector<std::string>& parameterValues)
|
||||
{
|
||||
std::vector<std::string> pastedValues;
|
||||
const auto* values = ¶meterValues;
|
||||
if (std::ranges::any_of(parameterValues,
|
||||
[](const std::string& value)
|
||||
{
|
||||
return value.find("##") != std::string::npos;
|
||||
}))
|
||||
{
|
||||
pastedValues = parameterValues;
|
||||
for (auto& value : pastedValues)
|
||||
{
|
||||
if (value.find("##") != std::string::npos)
|
||||
ProcessTokenPastingOperators(line, linePos, value);
|
||||
}
|
||||
values = &pastedValues;
|
||||
}
|
||||
|
||||
std::ostringstream rawOutput;
|
||||
InsertMacroParameters(rawOutput, macro, parameterValues);
|
||||
InsertMacroParameters(rawOutput, macro, *values);
|
||||
|
||||
std::string str = rawOutput.str();
|
||||
ProcessNestedMacros(line, linePos, callstack, str);
|
||||
|
||||
@@ -1127,6 +1127,26 @@ namespace test::parsing::impl::defines_stream_proxy
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Can use token-pasting operator in arguments of nested macros", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
"#define s(t) #t",
|
||||
"#define tag(id) s(id##_tag)",
|
||||
"#define outer(list) tag(list##_member0)",
|
||||
"outer(party)",
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
DefinesStreamProxy proxy(&mockStream);
|
||||
|
||||
ExpectLine(&proxy, 1, "");
|
||||
ExpectLine(&proxy, 2, "");
|
||||
ExpectLine(&proxy, 3, "");
|
||||
ExpectLine(&proxy, 4, "\"party_member0_tag\"");
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Can use token-pasting operator with string and stringization outside macro", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
|
||||
Reference in new issue
Block a user