mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
implement set block sequence
This commit is contained in:
parent
48e3738c05
commit
0cafabc44e
@ -20,7 +20,7 @@ public:
|
||||
bool m_is_reusable;
|
||||
bool m_is_leaf;
|
||||
std::unique_ptr<IEvaluation> m_condition;
|
||||
FastFileBlock* m_fast_file_block;
|
||||
const FastFileBlock* m_fast_file_block;
|
||||
|
||||
MemberInformation(StructureInformation* parent, StructureInformation* type, Variable* member);
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
bool m_reference_from_non_default_normal_block_exists;
|
||||
|
||||
std::unique_ptr<CustomAction> m_post_load_action;
|
||||
FastFileBlock* m_block;
|
||||
const FastFileBlock* m_block;
|
||||
std::vector<MemberInformation*> m_name_chain;
|
||||
|
||||
explicit StructureInformation(DefinitionWithMembers* definition);
|
||||
|
@ -9,7 +9,7 @@ SequenceSetBlock::SequenceSetBlock()
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("set").Capture(CAPTURE_START),
|
||||
create.Keyword("block"),
|
||||
create.Or({
|
||||
create.And({
|
||||
@ -24,4 +24,29 @@ SequenceSetBlock::SequenceSetBlock()
|
||||
|
||||
void SequenceSetBlock::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
{
|
||||
StructureInformation* information;
|
||||
std::vector<MemberInformation*> memberChain;
|
||||
|
||||
if (result.HasNextCapture(CAPTURE_TYPE))
|
||||
{
|
||||
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
|
||||
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), information, memberChain))
|
||||
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||
}
|
||||
else if (state->GetInUse() != nullptr)
|
||||
{
|
||||
information = state->GetInUse();
|
||||
}
|
||||
else
|
||||
throw ParsingException(result.NextCapture(CAPTURE_START).GetPos(), "No type is used. Therefore one needs to be specified directly.");
|
||||
|
||||
const auto& blockNameToken = result.NextCapture(CAPTURE_BLOCK_ENUM_ENTRY);
|
||||
auto* fastFileBlock = state->GetRepository()->GetFastFileBlockByName(blockNameToken.IdentifierValue());
|
||||
if (fastFileBlock == nullptr)
|
||||
throw ParsingException(blockNameToken.GetPos(), "Unknown block");
|
||||
|
||||
if (!memberChain.empty())
|
||||
memberChain.back()->m_fast_file_block = fastFileBlock;
|
||||
else
|
||||
information->m_block = fastFileBlock;
|
||||
}
|
||||
|
@ -4,8 +4,9 @@
|
||||
|
||||
class SequenceSetBlock final : public CommandsParser::sequence_t
|
||||
{
|
||||
static constexpr auto CAPTURE_TYPE = 1;
|
||||
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 2;
|
||||
static constexpr auto CAPTURE_START = 1;
|
||||
static constexpr auto CAPTURE_TYPE = 2;
|
||||
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 3;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
|
||||
|
@ -43,4 +43,5 @@ public:
|
||||
_NODISCARD virtual DataDefinition* GetDataDefinitionByName(const std::string& name) const = 0;
|
||||
_NODISCARD virtual StructureInformation* GetInformationFor(const DefinitionWithMembers* definitionWithMembers) const = 0;
|
||||
_NODISCARD virtual EnumMember* GetEnumMemberByName(const std::string& name) const = 0;
|
||||
_NODISCARD virtual FastFileBlock* GetFastFileBlockByName(const std::string& name) const = 0;
|
||||
};
|
||||
|
@ -61,7 +61,9 @@ void InMemoryRepository::Add(std::unique_ptr<StructureInformation> structureInfo
|
||||
|
||||
void InMemoryRepository::Add(std::unique_ptr<FastFileBlock> fastFileBlock)
|
||||
{
|
||||
m_fast_file_blocks.push_back(fastFileBlock.release());
|
||||
auto* raw = fastFileBlock.release();
|
||||
m_fast_file_blocks.push_back(raw);
|
||||
m_fast_file_blocks_by_name[raw->m_name] = raw;
|
||||
}
|
||||
|
||||
const std::string& InMemoryRepository::GetGameName() const
|
||||
@ -143,3 +145,13 @@ EnumMember* InMemoryRepository::GetEnumMemberByName(const std::string& name) con
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FastFileBlock* InMemoryRepository::GetFastFileBlockByName(const std::string& name) const
|
||||
{
|
||||
const auto foundEntry = m_fast_file_blocks_by_name.find(name);
|
||||
|
||||
if (foundEntry != m_fast_file_blocks_by_name.end())
|
||||
return foundEntry->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ class InMemoryRepository final : public IDataRepository
|
||||
std::vector<FastFileBlock*> m_fast_file_blocks;
|
||||
std::map<std::string, DataDefinition*> m_data_definitions_by_name;
|
||||
std::map<std::string, EnumMember*> m_enum_members_by_name;
|
||||
std::map<std::string, FastFileBlock*> m_fast_file_blocks_by_name;
|
||||
std::map<const DefinitionWithMembers*, StructureInformation*> m_structure_information_by_definition;
|
||||
std::string m_game_name;
|
||||
Architecture m_architecture;
|
||||
@ -35,7 +36,7 @@ public:
|
||||
|
||||
_NODISCARD const std::string& GetGameName() const override;
|
||||
void SetGame(std::string gameName) override;
|
||||
Architecture GetArchitecture() const override;
|
||||
_NODISCARD Architecture GetArchitecture() const override;
|
||||
void SetArchitecture(Architecture architecture) override;
|
||||
|
||||
_NODISCARD const std::vector<EnumDefinition*>& GetAllEnums() const override;
|
||||
@ -48,4 +49,5 @@ public:
|
||||
_NODISCARD DataDefinition* GetDataDefinitionByName(const std::string& name) const override;
|
||||
_NODISCARD StructureInformation* GetInformationFor(const DefinitionWithMembers* definitionWithMembers) const override;
|
||||
_NODISCARD EnumMember* GetEnumMemberByName(const std::string& name) const override;
|
||||
_NODISCARD FastFileBlock* GetFastFileBlockByName(const std::string& name) const override;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user