2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-18 22:47:25 +00:00

chore: detect structs that differ on different architectures

* and exclude them from assetstructtests
This commit is contained in:
Jan Laupetin
2025-04-27 21:04:41 +02:00
parent 088d14f894
commit 4e9599aabf
7 changed files with 85 additions and 2 deletions

View File

@@ -9,6 +9,7 @@
#include "Parsing/Impl/ParserFilesystemStream.h"
#include "Parsing/PostProcessing/CreateMemberInformationPostProcessor.h"
#include "Parsing/PostProcessing/CreateStructureInformationPostProcessor.h"
#include "Parsing/PostProcessing/CrossPlatformStructurePostProcessor.h"
#include "Parsing/PostProcessing/IPostProcessor.h"
#include <algorithm>
@@ -67,6 +68,7 @@ void HeaderFileReader::SetupPostProcessors()
// Order is important
m_post_processors.emplace_back(std::make_unique<CreateStructureInformationPostProcessor>());
m_post_processors.emplace_back(std::make_unique<CreateMemberInformationPostProcessor>());
m_post_processors.emplace_back(std::make_unique<CrossPlatformStructurePostProcessor>());
}
bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository)

View File

@@ -0,0 +1,58 @@
#include "CrossPlatformStructurePostProcessor.h"
#include "Domain/Definition/PointerDeclarationModifier.h"
#include <unordered_set>
namespace
{
bool CalculateHasMatchingCrossPlatformStructure(std::unordered_set<const void*>& visitedStructures, StructureInformation* info)
{
if (visitedStructures.find(info) != visitedStructures.end())
return info->m_has_matching_cross_platform_structure;
visitedStructures.emplace(info);
for (const auto& member : info->m_ordered_members)
{
for (const auto& modifier : member->m_member->m_type_declaration->m_declaration_modifiers)
{
if (modifier->GetType() == DeclarationModifierType::POINTER)
{
info->m_has_matching_cross_platform_structure = false;
return false;
}
}
if (member->m_type != nullptr && member->m_type != info && !CalculateHasMatchingCrossPlatformStructure(visitedStructures, member->m_type))
{
info->m_has_matching_cross_platform_structure = false;
return false;
}
}
info->m_has_matching_cross_platform_structure = true;
return true;
}
} // namespace
bool CrossPlatformStructurePostProcessor::PostProcess(IDataRepository* repository)
{
const auto& allInfos = repository->GetAllStructureInformation();
if (repository->GetArchitecture() == OWN_ARCHITECTURE)
{
for (const auto& info : allInfos)
info->m_has_matching_cross_platform_structure = true;
}
else
{
std::unordered_set<const void*> visitedStructures;
for (const auto& info : allInfos)
{
CalculateHasMatchingCrossPlatformStructure(visitedStructures, info);
}
}
return true;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "IPostProcessor.h"
#include <unordered_set>
class CrossPlatformStructurePostProcessor final : public IPostProcessor
{
public:
bool PostProcess(IDataRepository* repository) override;
};