mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-07 13:04:58 +00:00
chore: detect structs that differ on different architectures
* and exclude them from assetstructtests
This commit is contained in:
parent
088d14f894
commit
4e9599aabf
@ -6,3 +6,11 @@ enum class Architecture
|
||||
X86,
|
||||
X64
|
||||
};
|
||||
|
||||
static constexpr Architecture OWN_ARCHITECTURE =
|
||||
#if defined(ARCH_x86)
|
||||
Architecture::X86
|
||||
#elif defined(ARCH_x64)
|
||||
Architecture::X64
|
||||
#endif
|
||||
;
|
||||
|
@ -5,6 +5,7 @@ StructureInformation::StructureInformation(DefinitionWithMembers* definition)
|
||||
m_asset_enum_entry(nullptr),
|
||||
m_is_leaf(false),
|
||||
m_requires_marking(false),
|
||||
m_has_matching_cross_platform_structure(false),
|
||||
m_non_embedded_reference_exists(false),
|
||||
m_single_pointer_reference_exists(false),
|
||||
m_array_pointer_reference_exists(false),
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
|
||||
bool m_is_leaf;
|
||||
bool m_requires_marking;
|
||||
bool m_has_matching_cross_platform_structure;
|
||||
|
||||
bool m_non_embedded_reference_exists;
|
||||
bool m_single_pointer_reference_exists;
|
||||
|
@ -37,11 +37,13 @@ namespace
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
if (m_env.m_asset->m_has_matching_cross_platform_structure)
|
||||
TestMethod(m_env.m_asset);
|
||||
|
||||
for (auto* structure : m_env.m_used_structures)
|
||||
{
|
||||
StructureComputations computations(structure->m_info);
|
||||
if (!structure->m_info->m_definition->m_anonymous && !computations.IsAsset())
|
||||
if (!structure->m_info->m_definition->m_anonymous && !computations.IsAsset() && structure->m_info->m_has_matching_cross_platform_structure)
|
||||
TestMethod(structure->m_info);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "IPostProcessor.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
class CrossPlatformStructurePostProcessor final : public IPostProcessor
|
||||
{
|
||||
public:
|
||||
bool PostProcess(IDataRepository* repository) override;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user