2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-30 16:27:47 +00:00

refactor: adjust zcg code for working in x64

This commit is contained in:
Jan
2025-04-25 19:21:22 +01:00
committed by Jan Laupetin
parent c61dddf0e2
commit 60f5c1a18f
19 changed files with 322 additions and 312 deletions

View File

@@ -7,6 +7,7 @@
#include <algorithm>
#include <list>
#include <ranges>
static constexpr int TAG_EXPRESSION = SimpleExpressionMatchers::TAG_OFFSET_EXPRESSION + 1;
static constexpr int TAG_OPERAND = SimpleExpressionMatchers::TAG_OFFSET_EXPRESSION + 2;
@@ -103,7 +104,7 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessConditionalO
return std::make_unique<SimpleExpressionConditionalOperator>(std::move(condition), std::move(trueExpression), std::move(falseExpression));
}
std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessOperand(SequenceResult<SimpleParserValue>& result) const
std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessOperand(SequenceResult<SimpleParserValue>& result)
{
const auto& operandToken = result.NextCapture(CAPTURE_OPERAND);
@@ -133,7 +134,7 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpression(S
return nullptr;
std::vector<std::unique_ptr<ISimpleExpression>> operands;
std::list<std::pair<unsigned, const SimpleExpressionBinaryOperationType*>> operators;
std::list<std::pair<size_t, const SimpleExpressionBinaryOperationType*>> operators;
while (true)
{
@@ -200,7 +201,7 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpression(S
}
operators.sort(
[](const std::pair<unsigned, const SimpleExpressionBinaryOperationType*>& p1, const std::pair<unsigned, const SimpleExpressionBinaryOperationType*>& p2)
[](const std::pair<size_t, const SimpleExpressionBinaryOperationType*>& p1, const std::pair<size_t, const SimpleExpressionBinaryOperationType*>& p2)
{
if (p1.second->m_precedence != p2.second->m_precedence)
return p1.second->m_precedence > p2.second->m_precedence;
@@ -219,7 +220,7 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpression(S
operators.pop_back();
for (auto& [opIndex, _] : operators)
for (auto& opIndex : operators | std::views::keys)
{
if (opIndex > operatorIndex)
opIndex--;

View File

@@ -59,7 +59,7 @@ private:
std::unique_ptr<ISimpleExpression> ProcessExpressionInParenthesis(SequenceResult<SimpleParserValue>& result) const;
std::unique_ptr<ISimpleExpression> ProcessConditionalOperation(std::unique_ptr<ISimpleExpression> condition,
SequenceResult<SimpleParserValue>& result) const;
std::unique_ptr<ISimpleExpression> ProcessOperand(SequenceResult<SimpleParserValue>& result) const;
static std::unique_ptr<ISimpleExpression> ProcessOperand(SequenceResult<SimpleParserValue>& result);
public:
std::unique_ptr<matcher_t> Expression(const supplier_t* labelSupplier) const;

View File

@@ -14,7 +14,12 @@ SimpleLexer::MultiCharacterTokenLookupEntry::MultiCharacterTokenLookupEntry(cons
SimpleLexer::SimpleLexer(IParserLineStream* stream)
: AbstractLexer(stream),
m_config{false, true, false, true, true, {}},
m_config{.m_emit_new_line_tokens = false,
.m_read_strings = true,
.m_string_escape_sequences = false,
.m_read_integer_numbers = true,
.m_read_floating_point_numbers = true,
.m_multi_character_tokens = {}},
m_check_for_multi_character_tokens(false),
m_last_line(1)
{

View File

@@ -7,7 +7,7 @@
#include <limits>
#include <memory>
class SimpleLexer : public AbstractLexer<SimpleParserValue>
class SimpleLexer final : public AbstractLexer<SimpleParserValue>
{
public:
class Config
@@ -30,6 +30,9 @@ public:
std::vector<MultiCharacterToken> m_multi_character_tokens;
};
explicit SimpleLexer(IParserLineStream* stream);
SimpleLexer(IParserLineStream* stream, Config config);
protected:
class MultiCharacterTokenLookupEntry
{
@@ -41,10 +44,6 @@ protected:
MultiCharacterTokenLookupEntry(int id, std::string value);
};
Config m_config;
bool m_check_for_multi_character_tokens;
int m_last_line;
std::unique_ptr<MultiCharacterTokenLookupEntry> m_multi_character_token_lookup[std::numeric_limits<uint8_t>::max() + 1];
void AddMultiCharacterTokenConfigToLookup(Config::MultiCharacterToken tokenConfig);
@@ -52,7 +51,7 @@ protected:
SimpleParserValue GetNextToken() override;
public:
explicit SimpleLexer(IParserLineStream* stream);
SimpleLexer(IParserLineStream* stream, Config config);
Config m_config;
bool m_check_for_multi_character_tokens;
size_t m_last_line;
};