mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 08:41:52 +00:00
Calculate size and alignment in post processor
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include "CommandsParser.h"
|
||||
|
||||
#include "Parsing/Commands/Sequence/SequenceAction.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArchitecture.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArrayCount.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArraySize.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceAsset.h"
|
||||
@ -26,6 +27,7 @@ const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceAction(),
|
||||
new SequenceArchitecture(),
|
||||
new SequenceArrayCount(),
|
||||
new SequenceArraySize(),
|
||||
new SequenceAsset(),
|
||||
|
@ -16,6 +16,11 @@ void CommandsParserState::AddBlock(std::unique_ptr<FastFileBlock> block) const
|
||||
m_repository->Add(std::move(block));
|
||||
}
|
||||
|
||||
void CommandsParserState::SetArchitecture(const Architecture architecture) const
|
||||
{
|
||||
m_repository->SetArchitecture(architecture);
|
||||
}
|
||||
|
||||
void CommandsParserState::SetGame(std::string gameName) const
|
||||
{
|
||||
m_repository->SetGame(std::move(gameName));
|
||||
@ -31,12 +36,105 @@ void CommandsParserState::SetInUse(StructureInformation* structure)
|
||||
m_in_use = structure;
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetMembersFromParts(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members)
|
||||
MemberInformation* CommandsParserState::GetMemberWithName(const std::string& memberName, StructureInformation* type)
|
||||
{
|
||||
for (const auto& member : type->m_ordered_members)
|
||||
{
|
||||
if (member->m_member->m_name == memberName)
|
||||
{
|
||||
return member.get();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetNextTypenameSeparatorPos(const std::string& typeNameValue, const unsigned startPos, unsigned& separatorPos)
|
||||
{
|
||||
const auto typeNameValueSize = typeNameValue.size();
|
||||
for (auto currentHead = startPos + 1; currentHead < typeNameValueSize; currentHead++)
|
||||
{
|
||||
if (typeNameValue[currentHead] == ':'
|
||||
&& typeNameValue[currentHead - 1] == ':')
|
||||
{
|
||||
separatorPos = currentHead - 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetTypenameAndMembersFromParts(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members)
|
||||
bool CommandsParserState::ExtractMembersFromTypenameInternal(const std::string& typeNameValue, unsigned typeNameOffset, StructureInformation* type, std::vector<MemberInformation*>& members)
|
||||
{
|
||||
return false;
|
||||
auto startOffset = typeNameOffset;
|
||||
while (GetNextTypenameSeparatorPos(typeNameValue, typeNameOffset, typeNameOffset))
|
||||
{
|
||||
auto* foundMember = GetMemberWithName(std::string(typeNameValue, startOffset, typeNameOffset - startOffset), type);
|
||||
|
||||
if (foundMember == nullptr)
|
||||
return false;
|
||||
|
||||
members.push_back(foundMember);
|
||||
type = foundMember->m_type;
|
||||
typeNameOffset += 2;
|
||||
startOffset = typeNameOffset;
|
||||
}
|
||||
|
||||
auto* foundMember = GetMemberWithName(std::string(typeNameValue, startOffset, typeNameValue.size() - startOffset), type);
|
||||
if (foundMember == nullptr)
|
||||
return false;
|
||||
|
||||
members.push_back(foundMember);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetMembersFromTypename(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members) const
|
||||
{
|
||||
return m_in_use != nullptr && ExtractMembersFromTypenameInternal(typeNameValue, 0, m_in_use, members)
|
||||
|| ExtractMembersFromTypenameInternal(typeNameValue, 0, baseType, members);
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetTypenameAndMembersFromTypename(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members) const
|
||||
{
|
||||
if (m_in_use != nullptr)
|
||||
{
|
||||
if (ExtractMembersFromTypenameInternal(typeNameValue, 0, m_in_use, members))
|
||||
{
|
||||
structure = m_in_use;
|
||||
return true;
|
||||
}
|
||||
members.clear();
|
||||
}
|
||||
|
||||
DataDefinition* foundDefinition = nullptr;
|
||||
unsigned currentSeparatorPos = 0;
|
||||
while (GetNextTypenameSeparatorPos(typeNameValue, currentSeparatorPos, currentSeparatorPos))
|
||||
{
|
||||
std::string currentTypename(typeNameValue, 0, currentSeparatorPos);
|
||||
currentSeparatorPos += 2;
|
||||
|
||||
foundDefinition = m_repository->GetDataDefinitionByName(currentTypename);
|
||||
if (foundDefinition != nullptr)
|
||||
break;
|
||||
}
|
||||
|
||||
if (foundDefinition == nullptr)
|
||||
{
|
||||
currentSeparatorPos = typeNameValue.size();
|
||||
foundDefinition = m_repository->GetDataDefinitionByName(typeNameValue);
|
||||
}
|
||||
|
||||
if (foundDefinition == nullptr)
|
||||
return false;
|
||||
|
||||
auto* definitionWithMembers = dynamic_cast<DefinitionWithMembers*>(foundDefinition);
|
||||
if (definitionWithMembers == nullptr)
|
||||
return false;
|
||||
|
||||
structure = m_repository->GetInformationFor(definitionWithMembers);
|
||||
if (currentSeparatorPos >= typeNameValue.size())
|
||||
return true;
|
||||
|
||||
return ExtractMembersFromTypenameInternal(typeNameValue, currentSeparatorPos, structure, members);
|
||||
}
|
||||
|
@ -11,17 +11,22 @@ class CommandsParserState
|
||||
IDataRepository* m_repository;
|
||||
StructureInformation* m_in_use;
|
||||
|
||||
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, unsigned typeNameOffset, 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 GetMembersFromParts(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members);
|
||||
bool GetTypenameAndMembersFromParts(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members);
|
||||
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;
|
||||
};
|
||||
|
@ -105,6 +105,13 @@ CommandsParserValue CommandsParserValue::TypeName(const TokenPos pos, std::strin
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue CommandsParserValue::OpType(const TokenPos pos, const OperationType* operationType)
|
||||
{
|
||||
CommandsParserValue pv(pos, CommandsParserValueType::OPERATION_TYPE);
|
||||
pv.m_value.op_type_value = operationType;
|
||||
return pv;
|
||||
}
|
||||
|
||||
CommandsParserValue::CommandsParserValue(const TokenPos pos, const CommandsParserValueType type)
|
||||
: m_pos(pos),
|
||||
m_type(type),
|
||||
@ -201,3 +208,9 @@ std::string& CommandsParserValue::TypeNameValue() const
|
||||
assert(m_type == CommandsParserValueType::TYPE_NAME);
|
||||
return *m_value.string_value;
|
||||
}
|
||||
|
||||
const OperationType* CommandsParserValue::OpTypeValue() const
|
||||
{
|
||||
assert(m_type == CommandsParserValueType::OPERATION_TYPE);
|
||||
return m_value.op_type_value;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
#include "Domain/Evaluation/OperationType.h"
|
||||
#include "Parsing/IParserValue.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/TokenPos.h"
|
||||
@ -43,6 +45,7 @@ enum class CommandsParserValueType
|
||||
|
||||
// Parser created
|
||||
TYPE_NAME,
|
||||
OPERATION_TYPE,
|
||||
|
||||
// End
|
||||
MAX
|
||||
@ -60,6 +63,7 @@ public:
|
||||
int int_value;
|
||||
double double_value;
|
||||
std::string* string_value;
|
||||
const OperationType* op_type_value;
|
||||
} m_value;
|
||||
|
||||
static CommandsParserValue Invalid(TokenPos pos);
|
||||
@ -78,6 +82,7 @@ public:
|
||||
static CommandsParserValue String(TokenPos pos, std::string* stringValue);
|
||||
static CommandsParserValue Identifier(TokenPos pos, std::string* identifier);
|
||||
static CommandsParserValue TypeName(TokenPos pos, std::string* typeName);
|
||||
static CommandsParserValue OpType(TokenPos pos, const OperationType* operationType);
|
||||
|
||||
private:
|
||||
CommandsParserValue(TokenPos pos, CommandsParserValueType type);
|
||||
@ -99,4 +104,5 @@ public:
|
||||
_NODISCARD std::string& IdentifierValue() const;
|
||||
_NODISCARD size_t IdentifierHash() const;
|
||||
_NODISCARD std::string& TypeNameValue() const;
|
||||
_NODISCARD const OperationType* OpTypeValue() const;
|
||||
};
|
Reference in New Issue
Block a user