2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-07 05:23:02 +00:00

chore: update ZoneCodeGenerator code style

This commit is contained in:
Jan
2025-04-19 23:01:22 +02:00
parent 9f738da517
commit 9f8a933277
135 changed files with 4406 additions and 4299 deletions

View File

@@ -17,6 +17,12 @@
#include <chrono>
#include <iostream>
namespace
{
static constexpr const char* ZONE_CODE_GENERATOR_DEFINE_NAME = "__zonecodegenerator";
static constexpr const char* ZONE_CODE_GENERATOR_DEFINE_VALUE = "1";
} // namespace
CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
: m_args(args),
m_filename(std::move(filename)),
@@ -30,7 +36,7 @@ bool CommandsFileReader::OpenBaseStream()
auto stream = std::make_unique<ParserFilesystemStream>(m_filename);
if (!stream->IsOpen())
{
std::cout << "Could not open commands file\n";
std::cerr << "Could not open commands file\n";
return false;
}
@@ -68,7 +74,7 @@ bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
{
if (m_args->m_verbose)
{
std::cout << "Reading commands file: " << m_filename << "\n";
std::cout << std::format("Reading commands file: {}\n", m_filename);
}
if (!OpenBaseStream())
@@ -84,9 +90,7 @@ bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
const auto end = std::chrono::steady_clock::now();
if (m_args->m_verbose)
{
std::cout << "Processing commands took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms\n";
}
std::cout << std::format("Processing commands took {}ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
if (!result)
return false;

View File

@@ -9,8 +9,15 @@
class CommandsFileReader
{
static constexpr const char* ZONE_CODE_GENERATOR_DEFINE_NAME = "__zonecodegenerator";
static constexpr const char* ZONE_CODE_GENERATOR_DEFINE_VALUE = "1";
public:
CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename);
bool ReadCommandsFile(IDataRepository* repository);
private:
bool OpenBaseStream();
void SetupStreamProxies();
void SetupPostProcessors();
const ZoneCodeGeneratorArguments* m_args;
std::string m_filename;
@@ -19,13 +26,4 @@ class CommandsFileReader
IParserLineStream* m_stream;
std::vector<std::unique_ptr<IPostProcessor>> m_post_processors;
bool OpenBaseStream();
void SetupStreamProxies();
void SetupPostProcessors();
public:
explicit CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename);
bool ReadCommandsFile(IDataRepository* repository);
};

View File

@@ -5,9 +5,9 @@
class CommandsLexer final : public AbstractLexer<CommandsParserValue>
{
protected:
CommandsParserValue GetNextToken() override;
public:
explicit CommandsLexer(IParserLineStream* stream);
protected:
CommandsParserValue GetNextToken() override;
};

View File

@@ -8,11 +8,12 @@
class CommandsParser final : public AbstractParser<CommandsParserValue, CommandsParserState>
{
IDataRepository* m_repository;
public:
CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository);
protected:
const std::vector<sequence_t*>& GetTestsForState() override;
public:
CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository);
private:
IDataRepository* m_repository;
};

View File

@@ -1,16 +1,28 @@
#pragma once
#include "Persistence/IDataRepository.h"
#include "Utils/ClassUtils.h"
#include <memory>
#include <string>
class CommandsParserState
{
IDataRepository* m_repository;
StructureInformation* m_in_use;
public:
explicit CommandsParserState(IDataRepository* repository);
[[nodiscard]] const IDataRepository* GetRepository() const;
void AddBlock(std::unique_ptr<FastFileBlock> block) const;
void SetArchitecture(Architecture architecture) const;
void SetGame(std::string gameName) const;
[[nodiscard]] StructureInformation* GetInUse() const;
void SetInUse(StructureInformation* structure);
bool GetMembersFromTypename(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members) const;
bool GetTypenameAndMembersFromTypename(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members) const;
private:
static MemberInformation* GetMemberWithName(const std::string& memberName, StructureInformation* type);
static bool GetNextTypenameSeparatorPos(const std::string& typeNameValue, unsigned startPos, unsigned& separatorPos);
static bool ExtractMembersFromTypenameInternal(const std::string& typeNameValue,
@@ -18,18 +30,6 @@ class CommandsParserState
StructureInformation* type,
std::vector<MemberInformation*>& members);
public:
explicit CommandsParserState(IDataRepository* repository);
_NODISCARD const IDataRepository* GetRepository() const;
void AddBlock(std::unique_ptr<FastFileBlock> block) const;
void SetArchitecture(Architecture architecture) const;
void SetGame(std::string gameName) const;
_NODISCARD StructureInformation* GetInUse() const;
void SetInUse(StructureInformation* structure);
bool GetMembersFromTypename(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members) const;
bool GetTypenameAndMembersFromTypename(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members) const;
IDataRepository* m_repository;
StructureInformation* m_in_use;
};

View File

@@ -52,10 +52,6 @@ enum class CommandsParserValueType
class CommandsParserValue final : public IParserValue
{
public:
TokenPos m_pos;
CommandsParserValueType m_type;
size_t m_hash;
union ValueType
{
char char_value;
@@ -83,25 +79,28 @@ public:
static CommandsParserValue TypeName(TokenPos pos, std::string* typeName);
static CommandsParserValue OpType(TokenPos pos, const OperationType* operationType);
private:
CommandsParserValue(TokenPos pos, CommandsParserValueType type);
public:
~CommandsParserValue() override;
CommandsParserValue(const CommandsParserValue& other) = delete;
~CommandsParserValue() override;
CommandsParserValue(CommandsParserValue&& other) noexcept;
CommandsParserValue& operator=(const CommandsParserValue& other) = delete;
CommandsParserValue& operator=(CommandsParserValue&& other) noexcept;
_NODISCARD bool IsEof() const override;
_NODISCARD const TokenPos& GetPos() const override;
[[nodiscard]] bool IsEof() const override;
[[nodiscard]] const TokenPos& GetPos() const override;
_NODISCARD char CharacterValue() const;
_NODISCARD int IntegerValue() const;
_NODISCARD double FloatingPointValue() const;
_NODISCARD std::string& StringValue() const;
_NODISCARD std::string& IdentifierValue() const;
_NODISCARD size_t IdentifierHash() const;
_NODISCARD std::string& TypeNameValue() const;
_NODISCARD const OperationType* OpTypeValue() const;
[[nodiscard]] char CharacterValue() const;
[[nodiscard]] int IntegerValue() const;
[[nodiscard]] double FloatingPointValue() const;
[[nodiscard]] std::string& StringValue() const;
[[nodiscard]] std::string& IdentifierValue() const;
[[nodiscard]] size_t IdentifierHash() const;
[[nodiscard]] std::string& TypeNameValue() const;
[[nodiscard]] const OperationType* OpTypeValue() const;
TokenPos m_pos;
CommandsParserValueType m_type;
size_t m_hash;
private:
CommandsParserValue(TokenPos pos, CommandsParserValueType type);
};

View File

@@ -5,11 +5,12 @@
class CommandsMatcherCharacter final : public AbstractMatcher<CommandsParserValue>
{
char m_char;
public:
explicit CommandsMatcherCharacter(char c);
protected:
MatcherResult<CommandsParserValue> CanMatch(ILexer<CommandsParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit CommandsMatcherCharacter(char c);
private:
char m_char;
};

View File

@@ -10,10 +10,10 @@ class CommandsMatcherFactory final : public AbstractMatcherFactory<CommandsParse
public:
explicit CommandsMatcherFactory(const IMatcherForLabelSupplier<CommandsParserValue>* labelSupplier);
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Type(CommandsParserValueType type) const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Keyword(std::string value) const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Identifier() const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Integer() const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> FloatingPoint() const;
_NODISCARD MatcherFactoryWrapper<CommandsParserValue> Char(char c) const;
[[nodiscard]] MatcherFactoryWrapper<CommandsParserValue> Type(CommandsParserValueType type) const;
[[nodiscard]] MatcherFactoryWrapper<CommandsParserValue> Keyword(std::string value) const;
[[nodiscard]] MatcherFactoryWrapper<CommandsParserValue> Identifier() const;
[[nodiscard]] MatcherFactoryWrapper<CommandsParserValue> Integer() const;
[[nodiscard]] MatcherFactoryWrapper<CommandsParserValue> FloatingPoint() const;
[[nodiscard]] MatcherFactoryWrapper<CommandsParserValue> Char(char c) const;
};

View File

@@ -7,12 +7,13 @@
class CommandsMatcherKeyword final : public AbstractMatcher<CommandsParserValue>
{
size_t m_hash;
std::string m_value;
public:
explicit CommandsMatcherKeyword(std::string value);
protected:
MatcherResult<CommandsParserValue> CanMatch(ILexer<CommandsParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit CommandsMatcherKeyword(std::string value);
private:
size_t m_hash;
std::string m_value;
};

View File

@@ -5,11 +5,12 @@
class CommandsMatcherValueType final : public AbstractMatcher<CommandsParserValue>
{
CommandsParserValueType m_type;
public:
explicit CommandsMatcherValueType(CommandsParserValueType type);
protected:
MatcherResult<CommandsParserValue> CanMatch(ILexer<CommandsParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit CommandsMatcherValueType(CommandsParserValueType type);
private:
CommandsParserValueType m_type;
};

View File

@@ -3,6 +3,15 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_ACTION_NAME = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_ARG_TYPE = 3;
static constexpr auto LABEL_ACTION_ARGS = 1;
} // namespace
SequenceAction::SequenceAction()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,15 +4,9 @@
class SequenceAction final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_ACTION_NAME = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_ARG_TYPE = 3;
static constexpr auto LABEL_ACTION_ARGS = 1;
public:
SequenceAction();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceAction();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceAllocAlign::SequenceAllocAlign()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceAllocAlign final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceAllocAlign();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceAllocAlign();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_ARCHITECTURE = 1;
}
SequenceArchitecture::SequenceArchitecture()
{
const CommandsMatcherFactory create(this);

View File

@@ -2,15 +2,16 @@
#include "Parsing/Commands/Impl/CommandsParser.h"
#include <unordered_map>
class SequenceArchitecture final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_ARCHITECTURE = 1;
std::unordered_map<std::string, Architecture> m_architecture_mapping;
public:
SequenceArchitecture();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceArchitecture();
private:
std::unordered_map<std::string, Architecture> m_architecture_mapping;
};

View File

@@ -4,6 +4,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceArrayCount::SequenceArrayCount()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceArrayCount final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceArrayCount();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceArrayCount();
};

View File

@@ -4,6 +4,12 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_EVALUATION = 2;
} // namespace
SequenceArraySize::SequenceArraySize()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,12 +4,9 @@
class SequenceArraySize final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_EVALUATION = 2;
public:
SequenceArraySize();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceArraySize();
};

View File

@@ -3,6 +3,12 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ENUM_ENTRY = 2;
} // namespace
SequenceAsset::SequenceAsset()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,12 +4,9 @@
class SequenceAsset final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ENUM_ENTRY = 2;
public:
SequenceAsset();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceAsset();
};

View File

@@ -5,6 +5,14 @@
#include <algorithm>
namespace
{
static constexpr auto TAG_DEFAULT = 1;
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ASSET_TYPE_ENUM_ENTRY = 2;
} // namespace
SequenceAssetRef::SequenceAssetRef()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,14 +4,9 @@
class SequenceAssetRef final : public CommandsParser::sequence_t
{
static constexpr auto TAG_DEFAULT = 1;
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ASSET_TYPE_ENUM_ENTRY = 2;
public:
SequenceAssetRef();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceAssetRef();
};

View File

@@ -3,6 +3,14 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto TAG_DEFAULT = 1;
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 1;
static constexpr auto CAPTURE_BLOCK_TYPE = 2;
} // namespace
SequenceBlock::SequenceBlock()
{
const CommandsMatcherFactory create(this);

View File

@@ -7,19 +7,15 @@
class SequenceBlock final : public CommandsParser::sequence_t
{
static constexpr auto TAG_DEFAULT = 1;
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 1;
static constexpr auto CAPTURE_BLOCK_TYPE = 2;
std::unordered_map<std::string, FastFileBlockType> m_type_lookup;
void AddFastFileBlockToLookup(std::string name, FastFileBlockType type);
_NODISCARD bool GetFastFileBlockNameByType(const std::string& name, FastFileBlockType& type) const;
public:
SequenceBlock();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceBlock();
private:
void AddFastFileBlockToLookup(std::string name, FastFileBlockType type);
[[nodiscard]] bool GetFastFileBlockNameByType(const std::string& name, FastFileBlockType& type) const;
std::unordered_map<std::string, FastFileBlockType> m_type_lookup;
};

View File

@@ -4,6 +4,16 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto TAG_ALWAYS = 1;
static constexpr auto TAG_NEVER = 2;
static constexpr auto TAG_EVALUATION = 3;
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_EVALUATION = 2;
} // namespace
SequenceCondition::SequenceCondition()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,16 +4,9 @@
class SequenceCondition final : public CommandsParser::sequence_t
{
static constexpr auto TAG_ALWAYS = 1;
static constexpr auto TAG_NEVER = 2;
static constexpr auto TAG_EVALUATION = 3;
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_EVALUATION = 2;
public:
SequenceCondition();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceCondition();
};

View File

@@ -5,6 +5,76 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
#include <memory>
#include <vector>
namespace
{
static constexpr auto TAG_POINTER_RESOLVE = 1;
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_ARRAY_INDEX = 3;
void SetCountByArrayIndex(CommandsParserState* state,
SequenceResult<CommandsParserValue>& result,
MemberInformation* member,
PointerDeclarationModifier* pointer,
std::unique_ptr<IEvaluation> evaluation)
{
std::vector<int> arraySizes;
std::vector<int> depthSize;
for (const auto& modifier : member->m_member->m_type_declaration->m_declaration_modifiers)
{
if (modifier->GetType() == DeclarationModifierType::ARRAY)
arraySizes.push_back(dynamic_cast<ArrayDeclarationModifier*>(modifier.get())->m_size);
}
depthSize.resize(arraySizes.size());
auto currentDepthSize = 1u;
for (auto i = arraySizes.size(); i > 0; i--)
{
if (i < arraySizes.size())
currentDepthSize *= arraySizes[i];
depthSize[i - 1] = currentDepthSize;
}
if (pointer->m_count_evaluation_by_array_index.empty())
{
auto neededCapacity = 0u;
for (auto arraySize : arraySizes)
{
if (neededCapacity == 0)
neededCapacity = arraySize;
else
neededCapacity *= arraySize;
}
pointer->m_count_evaluation_by_array_index.resize(neededCapacity);
}
auto currentIndex = 0u;
auto currentIndexOffset = 0u;
while (result.HasNextCapture(CAPTURE_ARRAY_INDEX) && currentIndexOffset < depthSize.size())
{
const auto& arrayIndexToken = result.NextCapture(CAPTURE_ARRAY_INDEX);
if (arrayIndexToken.m_type == CommandsParserValueType::INTEGER)
{
currentIndex += depthSize[currentIndexOffset++] * arrayIndexToken.IntegerValue();
}
else
{
auto* enumEntry = state->GetRepository()->GetEnumMemberByName(arrayIndexToken.IdentifierValue());
if (enumEntry == nullptr)
throw ParsingException(arrayIndexToken.GetPos(), "Unknown enum entry");
currentIndex += depthSize[currentIndexOffset++] * enumEntry->m_value;
}
}
pointer->m_count_evaluation_by_array_index[currentIndex] = std::move(evaluation);
}
} // namespace
SequenceCount::SequenceCount()
{
const CommandsMatcherFactory create(this);
@@ -23,64 +93,6 @@ SequenceCount::SequenceCount()
});
}
void SequenceCount::SetCountByArrayIndex(CommandsParserState* state,
SequenceResult<CommandsParserValue>& result,
MemberInformation* member,
PointerDeclarationModifier* pointer,
std::unique_ptr<IEvaluation> evaluation)
{
std::vector<int> arraySizes;
std::vector<int> depthSize;
for (const auto& modifier : member->m_member->m_type_declaration->m_declaration_modifiers)
{
if (modifier->GetType() == DeclarationModifierType::ARRAY)
arraySizes.push_back(dynamic_cast<ArrayDeclarationModifier*>(modifier.get())->m_size);
}
depthSize.resize(arraySizes.size());
auto currentDepthSize = 1u;
for (auto i = arraySizes.size(); i > 0; i--)
{
if (i < arraySizes.size())
currentDepthSize *= arraySizes[i];
depthSize[i - 1] = currentDepthSize;
}
if (pointer->m_count_evaluation_by_array_index.empty())
{
auto neededCapacity = 0u;
for (auto arraySize : arraySizes)
{
if (neededCapacity == 0)
neededCapacity = arraySize;
else
neededCapacity *= arraySize;
}
pointer->m_count_evaluation_by_array_index.resize(neededCapacity);
}
auto currentIndex = 0u;
auto currentIndexOffset = 0u;
while (result.HasNextCapture(CAPTURE_ARRAY_INDEX) && currentIndexOffset < depthSize.size())
{
const auto& arrayIndexToken = result.NextCapture(CAPTURE_ARRAY_INDEX);
if (arrayIndexToken.m_type == CommandsParserValueType::INTEGER)
{
currentIndex += depthSize[currentIndexOffset++] * arrayIndexToken.IntegerValue();
}
else
{
auto* enumEntry = state->GetRepository()->GetEnumMemberByName(arrayIndexToken.IdentifierValue());
if (enumEntry == nullptr)
throw ParsingException(arrayIndexToken.GetPos(), "Unknown enum entry");
currentIndex += depthSize[currentIndexOffset++] * enumEntry->m_value;
}
}
pointer->m_count_evaluation_by_array_index[currentIndex] = std::move(evaluation);
}
void SequenceCount::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);

View File

@@ -5,21 +5,9 @@
class SequenceCount final : public CommandsParser::sequence_t
{
static constexpr auto TAG_POINTER_RESOLVE = 1;
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_ARRAY_INDEX = 3;
static void SetCountByArrayIndex(CommandsParserState* state,
SequenceResult<CommandsParserValue>& result,
MemberInformation* member,
PointerDeclarationModifier* pointer,
std::unique_ptr<IEvaluation> evaluation);
public:
SequenceCount();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceCount();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_GAME = 1;
}
SequenceGame::SequenceGame()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceGame final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_GAME = 1;
public:
SequenceGame();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceGame();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceName::SequenceName()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceName final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceName();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceName();
};

View File

@@ -5,6 +5,43 @@
#include <list>
namespace
{
static constexpr auto TAG_FIND_FIRST = 1;
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_ENTRY = 3;
StructureInformation* GetType(CommandsParserState* state, SequenceResult<CommandsParserValue>& result)
{
if (result.HasNextCapture(CAPTURE_TYPE))
{
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
StructureInformation* information;
std::vector<MemberInformation*> memberChain;
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), information, memberChain))
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
if (memberChain.empty())
return information;
auto* lastMember = memberChain.back();
if (lastMember->m_type == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Member type must either be struct or union");
return lastMember->m_type;
}
if (state->GetInUse() != nullptr)
return state->GetInUse();
throw ParsingException(result.NextCapture(CAPTURE_START).GetPos(), "No type is used. Therefore one needs to be specified directly.");
}
} // namespace
SequenceReorder::SequenceReorder()
{
const CommandsMatcherFactory create(this);
@@ -26,34 +63,6 @@ SequenceReorder::SequenceReorder()
});
}
StructureInformation* SequenceReorder::GetType(CommandsParserState* state, SequenceResult<CommandsParserValue>& result)
{
if (result.HasNextCapture(CAPTURE_TYPE))
{
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
StructureInformation* information;
std::vector<MemberInformation*> memberChain;
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), information, memberChain))
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
if (memberChain.empty())
return information;
auto* lastMember = memberChain.back();
if (lastMember->m_type == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Member type must either be struct or union");
return lastMember->m_type;
}
if (state->GetInUse() != nullptr)
return state->GetInUse();
throw ParsingException(result.NextCapture(CAPTURE_START).GetPos(), "No type is used. Therefore one needs to be specified directly.");
}
void SequenceReorder::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{
auto* information = GetType(state, result);

View File

@@ -4,17 +4,9 @@
class SequenceReorder final : public CommandsParser::sequence_t
{
static constexpr auto TAG_FIND_FIRST = 1;
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_ENTRY = 3;
static StructureInformation* GetType(CommandsParserState* state, SequenceResult<CommandsParserValue>& result);
public:
SequenceReorder();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceReorder();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceReusable::SequenceReusable()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceReusable final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceReusable();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceReusable();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceScriptString::SequenceScriptString()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceScriptString final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceScriptString();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceScriptString();
};

View File

@@ -3,6 +3,13 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 3;
} // namespace
SequenceSetBlock::SequenceSetBlock()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,13 +4,9 @@
class SequenceSetBlock final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 3;
public:
SequenceSetBlock();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceSetBlock();
};

View File

@@ -5,6 +5,11 @@
#include <algorithm>
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceString::SequenceString()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceString final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceString();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceString();
};

View File

@@ -3,6 +3,11 @@
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
namespace
{
static constexpr auto CAPTURE_TYPE = 1;
}
SequenceUse::SequenceUse()
{
const CommandsMatcherFactory create(this);

View File

@@ -4,11 +4,9 @@
class SequenceUse final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
public:
SequenceUse();
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceUse();
};