mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Reformat code with clang format
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
#include "MemberComputations.h"
|
||||
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Domain/Definition/PointerDeclarationModifier.h"
|
||||
#include "StructureComputations.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "StructureComputations.h"
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Domain/Definition/PointerDeclarationModifier.h"
|
||||
|
||||
MemberComputations::MemberComputations(const MemberInformation* member)
|
||||
: m_info(member)
|
||||
{
|
||||
@ -21,10 +21,12 @@ bool MemberComputations::ShouldIgnore() const
|
||||
bool MemberComputations::ContainsNonEmbeddedReference() const
|
||||
{
|
||||
const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers;
|
||||
return std::any_of(declarationModifiers.begin(), declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
return std::any_of(declarationModifiers.begin(),
|
||||
declarationModifiers.end(),
|
||||
[](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
}
|
||||
|
||||
bool MemberComputations::ContainsSinglePointerReference() const
|
||||
@ -81,9 +83,8 @@ const IEvaluation* MemberComputations::GetArrayPointerCountEvaluation() const
|
||||
return nullptr;
|
||||
|
||||
const auto* lastModifier = declarationModifiers[declarationModifiers.size() - 1].get();
|
||||
return lastModifier->GetType() == DeclarationModifierType::POINTER
|
||||
? dynamic_cast<const PointerDeclarationModifier*>(lastModifier)->GetCountEvaluation()
|
||||
: nullptr;
|
||||
return lastModifier->GetType() == DeclarationModifierType::POINTER ? dynamic_cast<const PointerDeclarationModifier*>(lastModifier)->GetCountEvaluation()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
bool MemberComputations::IsArray() const
|
||||
@ -135,10 +136,12 @@ bool MemberComputations::IsPointerToArray() const
|
||||
if (lastModifier->GetType() != DeclarationModifierType::ARRAY)
|
||||
return false;
|
||||
|
||||
return std::any_of(declarationModifiers.begin(), declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
return std::any_of(declarationModifiers.begin(),
|
||||
declarationModifiers.end(),
|
||||
[](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<int> MemberComputations::GetPointerToArraySizes() const
|
||||
@ -164,7 +167,7 @@ int MemberComputations::GetPointerDepth() const
|
||||
{
|
||||
auto depth = 0;
|
||||
const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers;
|
||||
for(const auto& declarationModifier : declarationModifiers)
|
||||
for (const auto& declarationModifier : declarationModifiers)
|
||||
{
|
||||
if (declarationModifier->GetType() == DeclarationModifierType::POINTER)
|
||||
depth++;
|
||||
@ -204,11 +207,13 @@ bool MemberComputations::HasDynamicArraySize() const
|
||||
{
|
||||
const auto& declarationModifiers = m_info->m_member->m_type_declaration->m_declaration_modifiers;
|
||||
|
||||
return std::any_of(declarationModifiers.begin(), declarationModifiers.end(), [](const std::unique_ptr<DeclarationModifier>& declarationModifier)
|
||||
{
|
||||
return declarationModifier->GetType() == DeclarationModifierType::ARRAY
|
||||
&& dynamic_cast<ArrayDeclarationModifier*>(declarationModifier.get())->m_dynamic_size_evaluation;
|
||||
});
|
||||
return std::any_of(declarationModifiers.begin(),
|
||||
declarationModifiers.end(),
|
||||
[](const std::unique_ptr<DeclarationModifier>& declarationModifier)
|
||||
{
|
||||
return declarationModifier->GetType() == DeclarationModifierType::ARRAY
|
||||
&& dynamic_cast<ArrayDeclarationModifier*>(declarationModifier.get())->m_dynamic_size_evaluation;
|
||||
});
|
||||
}
|
||||
|
||||
bool MemberComputations::IsDynamicMember() const
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "MemberDeclarationModifierComputations.h"
|
||||
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Domain/Definition/PointerDeclarationModifier.h"
|
||||
#include "MemberComputations.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "MemberComputations.h"
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Domain/Definition/PointerDeclarationModifier.h"
|
||||
|
||||
DeclarationModifierComputations::DeclarationModifierComputations(const MemberInformation* member, std::vector<int> modifierIndices)
|
||||
: m_information(member),
|
||||
m_modifier_indices(std::move(modifierIndices))
|
||||
@ -135,16 +135,17 @@ bool DeclarationModifierComputations::IsSinglePointer() const
|
||||
{
|
||||
auto* declarationModifier = GetDeclarationModifier();
|
||||
|
||||
if (declarationModifier != nullptr
|
||||
&& declarationModifier->GetType() == DeclarationModifierType::POINTER
|
||||
if (declarationModifier != nullptr && declarationModifier->GetType() == DeclarationModifierType::POINTER
|
||||
&& !dynamic_cast<PointerDeclarationModifier*>(declarationModifier)->CountEvaluationIsArray(m_combined_index))
|
||||
{
|
||||
const auto following = GetFollowingDeclarationModifiers();
|
||||
|
||||
return !std::any_of(following.begin(), following.end(), [](const DeclarationModifier* modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
return !std::any_of(following.begin(),
|
||||
following.end(),
|
||||
[](const DeclarationModifier* modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -154,16 +155,17 @@ bool DeclarationModifierComputations::IsArrayPointer() const
|
||||
{
|
||||
auto* declarationModifier = GetDeclarationModifier();
|
||||
|
||||
if (declarationModifier != nullptr
|
||||
&& declarationModifier->GetType() == DeclarationModifierType::POINTER
|
||||
if (declarationModifier != nullptr && declarationModifier->GetType() == DeclarationModifierType::POINTER
|
||||
&& dynamic_cast<PointerDeclarationModifier*>(declarationModifier)->CountEvaluationIsArray(m_combined_index))
|
||||
{
|
||||
const auto following = GetFollowingDeclarationModifiers();
|
||||
|
||||
return !std::any_of(following.begin(), following.end(), [](const DeclarationModifier* modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
return !std::any_of(following.begin(),
|
||||
following.end(),
|
||||
[](const DeclarationModifier* modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -189,14 +191,14 @@ bool DeclarationModifierComputations::IsPointerArray() const
|
||||
return false;
|
||||
|
||||
const auto thisDeclModIsArray = declarationModifier->GetType() == DeclarationModifierType::POINTER
|
||||
&& dynamic_cast<PointerDeclarationModifier*>(declarationModifier)->CountEvaluationIsArray(m_combined_index)
|
||||
|| declarationModifier->GetType() == DeclarationModifierType::ARRAY;
|
||||
&& dynamic_cast<PointerDeclarationModifier*>(declarationModifier)->CountEvaluationIsArray(m_combined_index)
|
||||
|| declarationModifier->GetType() == DeclarationModifierType::ARRAY;
|
||||
|
||||
if (!thisDeclModIsArray)
|
||||
return false;
|
||||
|
||||
const auto nextDeclModIsSinglePointer = nextDeclarationModifier->GetType() == DeclarationModifierType::POINTER
|
||||
&& !dynamic_cast<PointerDeclarationModifier*>(nextDeclarationModifier)->AnyCountEvaluationIsArray();
|
||||
&& !dynamic_cast<PointerDeclarationModifier*>(nextDeclarationModifier)->AnyCountEvaluationIsArray();
|
||||
|
||||
return nextDeclModIsSinglePointer;
|
||||
}
|
||||
@ -229,14 +231,13 @@ bool DeclarationModifierComputations::IsDynamicArray() const
|
||||
return false;
|
||||
|
||||
return declarationModifier->GetType() == DeclarationModifierType::ARRAY
|
||||
&& dynamic_cast<ArrayDeclarationModifier*>(declarationModifier)->m_dynamic_size_evaluation != nullptr;
|
||||
&& dynamic_cast<ArrayDeclarationModifier*>(declarationModifier)->m_dynamic_size_evaluation != nullptr;
|
||||
}
|
||||
|
||||
const IEvaluation* DeclarationModifierComputations::GetDynamicArraySizeEvaluation() const
|
||||
{
|
||||
auto* declarationModifier = GetDeclarationModifier();
|
||||
if (declarationModifier == nullptr
|
||||
|| declarationModifier->GetType() != DeclarationModifierType::ARRAY)
|
||||
if (declarationModifier == nullptr || declarationModifier->GetType() != DeclarationModifierType::ARRAY)
|
||||
return nullptr;
|
||||
|
||||
return dynamic_cast<ArrayDeclarationModifier*>(declarationModifier)->m_dynamic_size_evaluation.get();
|
||||
@ -246,8 +247,12 @@ unsigned DeclarationModifierComputations::GetAlignment() const
|
||||
{
|
||||
const auto following = GetFollowingDeclarationModifiers();
|
||||
|
||||
return std::any_of(following.begin(), following.end(), [](const DeclarationModifier* modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
}) ? m_information->m_member->GetAlignment() : m_information->m_member->m_type_declaration->m_type->GetAlignment();
|
||||
return std::any_of(following.begin(),
|
||||
following.end(),
|
||||
[](const DeclarationModifier* modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
})
|
||||
? m_information->m_member->GetAlignment()
|
||||
: m_information->m_member->m_type_declaration->m_type->GetAlignment();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Domain/Information/MemberInformation.h"
|
||||
#include "Domain/Evaluation/IEvaluation.h"
|
||||
#include "Domain/Information/MemberInformation.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
class DeclarationModifierComputations
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "StructureComputations.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "MemberComputations.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
StructureComputations::StructureComputations(const StructureInformation* structure)
|
||||
: m_info(structure)
|
||||
{
|
||||
@ -48,4 +48,4 @@ std::vector<MemberInformation*> StructureComputations::GetUsedMembers() const
|
||||
}
|
||||
|
||||
return members;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "DeclarationModifier.h"
|
||||
#include "Domain/Evaluation/IEvaluation.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ArrayDeclarationModifier final : public DeclarationModifier
|
||||
{
|
||||
|
@ -42,21 +42,6 @@ const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_LONG = new BaseType
|
||||
const BaseTypeDefinition* const BaseTypeDefinition::LONG_LONG = new BaseTypeDefinition("long long", 8);
|
||||
const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_LONG_LONG = new BaseTypeDefinition("unsigned long long", 8);
|
||||
const BaseTypeDefinition* const BaseTypeDefinition::VOID = new BaseTypeDefinition("void", 0);
|
||||
const BaseTypeDefinition* const BaseTypeDefinition::ALL_BASE_TYPES[]
|
||||
{
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
BOOL,
|
||||
CHAR,
|
||||
UNSIGNED_CHAR,
|
||||
SHORT,
|
||||
UNSIGNED_SHORT,
|
||||
INT,
|
||||
UNSIGNED_INT,
|
||||
LONG,
|
||||
UNSIGNED_LONG,
|
||||
LONG_LONG,
|
||||
UNSIGNED_LONG_LONG,
|
||||
VOID
|
||||
};
|
||||
const size_t BaseTypeDefinition::ALL_BASE_TYPES_COUNT = std::extent<decltype(ALL_BASE_TYPES)>::value;
|
||||
const BaseTypeDefinition* const BaseTypeDefinition::ALL_BASE_TYPES[]{
|
||||
FLOAT, DOUBLE, BOOL, CHAR, UNSIGNED_CHAR, SHORT, UNSIGNED_SHORT, INT, UNSIGNED_INT, LONG, UNSIGNED_LONG, LONG_LONG, UNSIGNED_LONG_LONG, VOID};
|
||||
const size_t BaseTypeDefinition::ALL_BASE_TYPES_COUNT = std::extent<decltype(ALL_BASE_TYPES)>::value;
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include "DataDefinition.h"
|
||||
|
||||
#include "Utils/NamespaceBuilder.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
#include "Utils/NamespaceBuilder.h"
|
||||
|
||||
DataDefinition::DataDefinition(std::string _namespace, std::string name)
|
||||
: m_namespace(std::move(_namespace)),
|
||||
m_name(std::move(name))
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class DataDefinitionType
|
||||
{
|
||||
STRUCT,
|
||||
@ -27,7 +27,7 @@ public:
|
||||
|
||||
std::string m_namespace;
|
||||
std::string m_name;
|
||||
|
||||
|
||||
_NODISCARD virtual DataDefinitionType GetType() const = 0;
|
||||
_NODISCARD virtual unsigned GetAlignment() const = 0;
|
||||
_NODISCARD virtual bool GetForceAlignment() const = 0;
|
||||
|
@ -19,4 +19,4 @@ public:
|
||||
DeclarationModifier& operator=(DeclarationModifier&& other) noexcept = default;
|
||||
|
||||
_NODISCARD virtual DeclarationModifierType GetType() const = 0;
|
||||
};
|
||||
};
|
||||
|
@ -14,25 +14,25 @@ DefinitionWithMembers::DefinitionWithMembers(std::string _namespace, std::string
|
||||
{
|
||||
}
|
||||
|
||||
//void DefinitionWithMembers::CalculateAlignment()
|
||||
// void DefinitionWithMembers::CalculateAlignment()
|
||||
//{
|
||||
// if (m_has_alignment_override)
|
||||
// {
|
||||
// m_flags |= FLAG_ALIGNMENT_FORCED;
|
||||
// m_alignment = m_alignment_override;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_alignment = 0;
|
||||
// for (const auto& member : m_members)
|
||||
// {
|
||||
// const auto memberAlignment = member->GetAlignment();
|
||||
// if (memberAlignment > m_alignment)
|
||||
// m_alignment = memberAlignment;
|
||||
// }
|
||||
// }
|
||||
// m_flags |= FLAG_ALIGNMENT_CALCULATED;
|
||||
//}
|
||||
// if (m_has_alignment_override)
|
||||
// {
|
||||
// m_flags |= FLAG_ALIGNMENT_FORCED;
|
||||
// m_alignment = m_alignment_override;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_alignment = 0;
|
||||
// for (const auto& member : m_members)
|
||||
// {
|
||||
// const auto memberAlignment = member->GetAlignment();
|
||||
// if (memberAlignment > m_alignment)
|
||||
// m_alignment = memberAlignment;
|
||||
// }
|
||||
// }
|
||||
// m_flags |= FLAG_ALIGNMENT_CALCULATED;
|
||||
// }
|
||||
|
||||
unsigned DefinitionWithMembers::GetAlignment() const
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "DataDefinition.h"
|
||||
#include "Variable.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class DefinitionWithMembers : public DataDefinition
|
||||
{
|
||||
public:
|
||||
@ -30,4 +30,4 @@ public:
|
||||
_NODISCARD unsigned GetAlignment() const override;
|
||||
_NODISCARD bool GetForceAlignment() const override;
|
||||
_NODISCARD unsigned GetSize() const override;
|
||||
};
|
||||
};
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "BaseTypeDefinition.h"
|
||||
#include "DataDefinition.h"
|
||||
#include "EnumMember.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class EnumDefinition final : public DataDefinition
|
||||
{
|
||||
public:
|
||||
|
@ -10,4 +10,4 @@ public:
|
||||
|
||||
EnumMember();
|
||||
EnumMember(std::string name, int value);
|
||||
};
|
||||
};
|
||||
|
@ -49,7 +49,7 @@ bool PointerDeclarationModifier::CountEvaluationIsArray() const
|
||||
|
||||
bool PointerDeclarationModifier::CountEvaluationIsArray(const int index) const
|
||||
{
|
||||
if(index >= 0 && m_count_evaluation_by_array_index.size() > static_cast<unsigned>(index))
|
||||
if (index >= 0 && m_count_evaluation_by_array_index.size() > static_cast<unsigned>(index))
|
||||
{
|
||||
return EvaluationIsArray(m_count_evaluation_by_array_index[index].get());
|
||||
}
|
||||
@ -62,7 +62,7 @@ bool PointerDeclarationModifier::AnyCountEvaluationIsArray() const
|
||||
if (m_count_evaluation && EvaluationIsArray(m_count_evaluation.get()))
|
||||
return true;
|
||||
|
||||
for(const auto& arrayCountEvaluation : m_count_evaluation_by_array_index)
|
||||
for (const auto& arrayCountEvaluation : m_count_evaluation_by_array_index)
|
||||
{
|
||||
if (EvaluationIsArray(arrayCountEvaluation.get()))
|
||||
return true;
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "DeclarationModifier.h"
|
||||
#include "Domain/Evaluation/IEvaluation.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class PointerDeclarationModifier final : public DeclarationModifier
|
||||
{
|
||||
static const IEvaluation* const DEFAULT_COUNT;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "TypeDeclaration.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "ArrayDeclarationModifier.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
TypeDeclaration::TypeDeclaration(const DataDefinition* type)
|
||||
: m_flags(0),
|
||||
m_size(0),
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "DataDefinition.h"
|
||||
#include "DeclarationModifier.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "DataDefinition.h"
|
||||
#include "DeclarationModifier.h"
|
||||
|
||||
class TypeDeclaration
|
||||
{
|
||||
public:
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
class UnionDefinition final : public DefinitionWithMembers
|
||||
{
|
||||
//protected:
|
||||
// void CalculateSize() override;
|
||||
// protected:
|
||||
// void CalculateSize() override;
|
||||
|
||||
public:
|
||||
UnionDefinition(std::string _namespace, std::string name, int pack);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "TypeDeclaration.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "TypeDeclaration.h"
|
||||
|
||||
class Variable
|
||||
{
|
||||
public:
|
||||
|
@ -5,4 +5,4 @@ enum class Architecture
|
||||
UNKNOWN,
|
||||
X86,
|
||||
X64
|
||||
};
|
||||
};
|
||||
|
@ -23,4 +23,4 @@ public:
|
||||
_NODISCARD virtual EvaluationType GetType() const = 0;
|
||||
_NODISCARD virtual bool IsStatic() const = 0;
|
||||
_NODISCARD virtual int EvaluateNumeric() const = 0;
|
||||
};
|
||||
};
|
||||
|
@ -7,7 +7,9 @@ OperandDynamic::OperandDynamic(StructureInformation* structure)
|
||||
{
|
||||
}
|
||||
|
||||
OperandDynamic::OperandDynamic(StructureInformation* structure, std::vector<MemberInformation*> referencedMemberChain, std::vector<std::unique_ptr<IEvaluation>> arrayIndices)
|
||||
OperandDynamic::OperandDynamic(StructureInformation* structure,
|
||||
std::vector<MemberInformation*> referencedMemberChain,
|
||||
std::vector<std::unique_ptr<IEvaluation>> arrayIndices)
|
||||
: m_structure(structure),
|
||||
m_referenced_member_chain(std::move(referencedMemberChain)),
|
||||
m_array_indices(std::move(arrayIndices))
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "IEvaluation.h"
|
||||
#include "Domain/Information/MemberInformation.h"
|
||||
#include "Domain/Information/StructureInformation.h"
|
||||
#include "IEvaluation.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class OperandDynamic final : public IEvaluation
|
||||
{
|
||||
@ -14,7 +14,9 @@ public:
|
||||
std::vector<std::unique_ptr<IEvaluation>> m_array_indices;
|
||||
|
||||
explicit OperandDynamic(StructureInformation* structure);
|
||||
OperandDynamic(StructureInformation* structure, std::vector<MemberInformation*> referencedMemberChain, std::vector<std::unique_ptr<IEvaluation>> arrayIndices);
|
||||
OperandDynamic(StructureInformation* structure,
|
||||
std::vector<MemberInformation*> referencedMemberChain,
|
||||
std::vector<std::unique_ptr<IEvaluation>> arrayIndices);
|
||||
|
||||
_NODISCARD EvaluationType GetType() const override;
|
||||
_NODISCARD bool IsStatic() const override;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEvaluation.h"
|
||||
#include "Domain/Definition/EnumMember.h"
|
||||
#include "IEvaluation.h"
|
||||
|
||||
class OperandStatic final : public IEvaluation
|
||||
{
|
||||
|
@ -30,11 +30,11 @@ int Operation::EvaluateNumeric() const
|
||||
bool Operation::Operand1NeedsParenthesis() const
|
||||
{
|
||||
return m_operand1->GetType() == EvaluationType::OPERATION
|
||||
&& dynamic_cast<Operation*>(m_operand1.get())->m_operation_type->m_precedence > m_operation_type->m_precedence;
|
||||
&& dynamic_cast<Operation*>(m_operand1.get())->m_operation_type->m_precedence > m_operation_type->m_precedence;
|
||||
}
|
||||
|
||||
bool Operation::Operand2NeedsParenthesis() const
|
||||
{
|
||||
return m_operand2->GetType() == EvaluationType::OPERATION
|
||||
&& dynamic_cast<Operation*>(m_operand2.get())->m_operation_type->m_precedence >= m_operation_type->m_precedence;
|
||||
&& dynamic_cast<Operation*>(m_operand2.get())->m_operation_type->m_precedence >= m_operation_type->m_precedence;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "IEvaluation.h"
|
||||
#include "OperationType.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Operation final : public IEvaluation
|
||||
{
|
||||
|
@ -7,133 +7,147 @@ OperationType::OperationType(std::string syntax, const OperationPrecedence prece
|
||||
{
|
||||
}
|
||||
|
||||
const OperationType* const OperationType::OPERATION_ADD
|
||||
= new OperationType("+", OperationPrecedence::ADDITION_SUBTRACTION, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 + op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_ADD = new OperationType("+",
|
||||
OperationPrecedence::ADDITION_SUBTRACTION,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 + op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_SUBTRACT
|
||||
= new OperationType("-", OperationPrecedence::ADDITION_SUBTRACTION, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 - op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_SUBTRACT = new OperationType("-",
|
||||
OperationPrecedence::ADDITION_SUBTRACTION,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 - op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_MULTIPLY
|
||||
= new OperationType("*", OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 * op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_MULTIPLY = new OperationType("*",
|
||||
OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 * op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_DIVIDE
|
||||
= new OperationType("/", OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 / op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_DIVIDE = new OperationType("/",
|
||||
OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 / op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_REMAINDER
|
||||
= new OperationType("%", OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 % op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_REMAINDER = new OperationType("%",
|
||||
OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 % op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_BITWISE_AND
|
||||
= new OperationType("&", OperationPrecedence::BITWISE_AND, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 & op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_BITWISE_AND = new OperationType("&",
|
||||
OperationPrecedence::BITWISE_AND,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 & op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_BITWISE_XOR
|
||||
= new OperationType("^", OperationPrecedence::BITWISE_XOR, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 ^ op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_BITWISE_XOR = new OperationType("^",
|
||||
OperationPrecedence::BITWISE_XOR,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 ^ op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_BITWISE_OR
|
||||
= new OperationType("|", OperationPrecedence::BITWISE_OR, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 | op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_BITWISE_OR = new OperationType("|",
|
||||
OperationPrecedence::BITWISE_OR,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 | op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_SHIFT_LEFT
|
||||
= new OperationType("<<", OperationPrecedence::BITWISE_SHIFT, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 << op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_SHIFT_LEFT = new OperationType("<<",
|
||||
OperationPrecedence::BITWISE_SHIFT,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 << op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_SHIFT_RIGHT
|
||||
= new OperationType(">>", OperationPrecedence::BITWISE_SHIFT, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 >> op2;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_SHIFT_RIGHT = new OperationType(">>",
|
||||
OperationPrecedence::BITWISE_SHIFT,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 >> op2;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_GREATER_THAN
|
||||
= new OperationType(">", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 > op2 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_GREATER_THAN = new OperationType(">",
|
||||
OperationPrecedence::RELATIONAL_GREATER_LESS_THAN,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 > op2 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_GREATER_EQUAL_THAN
|
||||
= new OperationType(">=", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 >= op2 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_GREATER_EQUAL_THAN = new OperationType(">=",
|
||||
OperationPrecedence::RELATIONAL_GREATER_LESS_THAN,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 >= op2 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_LESS_THAN
|
||||
= new OperationType("<", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 < op2 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_LESS_THAN = new OperationType("<",
|
||||
OperationPrecedence::RELATIONAL_GREATER_LESS_THAN,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 < op2 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_LESS_EQUAL_THAN
|
||||
= new OperationType("<=", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 <= op2 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_LESS_EQUAL_THAN = new OperationType("<=",
|
||||
OperationPrecedence::RELATIONAL_GREATER_LESS_THAN,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 <= op2 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_EQUALS
|
||||
= new OperationType("==", OperationPrecedence::RELATIONAL_EQUALS, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 == op2 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_EQUALS = new OperationType("==",
|
||||
OperationPrecedence::RELATIONAL_EQUALS,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 == op2 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_NOT_EQUAL
|
||||
= new OperationType("!=", OperationPrecedence::RELATIONAL_EQUALS, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 != op2 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_NOT_EQUAL = new OperationType("!=",
|
||||
OperationPrecedence::RELATIONAL_EQUALS,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 != op2 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_AND
|
||||
= new OperationType("&&", OperationPrecedence::LOGICAL_AND, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 > 0 && op2 > 0 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_AND = new OperationType("&&",
|
||||
OperationPrecedence::LOGICAL_AND,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 > 0 && op2 > 0 ? 1 : 0;
|
||||
});
|
||||
|
||||
const OperationType* const OperationType::OPERATION_OR
|
||||
= new OperationType("||", OperationPrecedence::LOGICAL_OR, [](auto op1, auto op2)
|
||||
{
|
||||
return op1 > 0 || op2 > 0 ? 1 : 0;
|
||||
});
|
||||
const OperationType* const OperationType::OPERATION_OR = new OperationType("||",
|
||||
OperationPrecedence::LOGICAL_OR,
|
||||
[](auto op1, auto op2)
|
||||
{
|
||||
return op1 > 0 || op2 > 0 ? 1 : 0;
|
||||
});
|
||||
|
||||
|
||||
const OperationType* const OperationType::ALL_OPERATION_TYPES[]
|
||||
{
|
||||
OPERATION_ADD,
|
||||
OPERATION_SUBTRACT,
|
||||
OPERATION_MULTIPLY,
|
||||
OPERATION_DIVIDE,
|
||||
OPERATION_REMAINDER,
|
||||
OPERATION_BITWISE_AND,
|
||||
OPERATION_BITWISE_XOR,
|
||||
OPERATION_BITWISE_OR,
|
||||
OPERATION_SHIFT_LEFT,
|
||||
OPERATION_SHIFT_RIGHT,
|
||||
OPERATION_GREATER_THAN,
|
||||
OPERATION_GREATER_EQUAL_THAN,
|
||||
OPERATION_LESS_THAN,
|
||||
OPERATION_LESS_EQUAL_THAN,
|
||||
OPERATION_EQUALS,
|
||||
OPERATION_NOT_EQUAL,
|
||||
OPERATION_AND,
|
||||
OPERATION_OR
|
||||
};
|
||||
const OperationType* const OperationType::ALL_OPERATION_TYPES[]{OPERATION_ADD,
|
||||
OPERATION_SUBTRACT,
|
||||
OPERATION_MULTIPLY,
|
||||
OPERATION_DIVIDE,
|
||||
OPERATION_REMAINDER,
|
||||
OPERATION_BITWISE_AND,
|
||||
OPERATION_BITWISE_XOR,
|
||||
OPERATION_BITWISE_OR,
|
||||
OPERATION_SHIFT_LEFT,
|
||||
OPERATION_SHIFT_RIGHT,
|
||||
OPERATION_GREATER_THAN,
|
||||
OPERATION_GREATER_EQUAL_THAN,
|
||||
OPERATION_LESS_THAN,
|
||||
OPERATION_LESS_EQUAL_THAN,
|
||||
OPERATION_EQUALS,
|
||||
OPERATION_NOT_EQUAL,
|
||||
OPERATION_AND,
|
||||
OPERATION_OR};
|
||||
|
@ -49,4 +49,4 @@ public:
|
||||
static const OperationType* const OPERATION_OR;
|
||||
|
||||
static const OperationType* const ALL_OPERATION_TYPES[];
|
||||
};
|
||||
};
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Definition/DataDefinition.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Domain/Definition/DataDefinition.h"
|
||||
|
||||
class CustomAction
|
||||
{
|
||||
public:
|
||||
|
@ -19,4 +19,4 @@ public:
|
||||
bool m_is_default;
|
||||
|
||||
FastFileBlock(std::string name, unsigned index, FastFileBlockType type, bool isDefault);
|
||||
};
|
||||
};
|
||||
|
@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Definition/Variable.h"
|
||||
#include "Domain/Evaluation/IEvaluation.h"
|
||||
#include "Domain/FastFile/FastFileBlock.h"
|
||||
#include "StructureInformation.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "StructureInformation.h"
|
||||
#include "Domain/Definition/Variable.h"
|
||||
#include "Domain/FastFile/FastFileBlock.h"
|
||||
#include "Domain/Evaluation/IEvaluation.h"
|
||||
|
||||
class StructureInformation;
|
||||
|
||||
class MemberInformation
|
||||
{
|
||||
public:
|
||||
|
@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "MemberInformation.h"
|
||||
#include "Domain/Definition/DefinitionWithMembers.h"
|
||||
#include "Domain/Definition/EnumMember.h"
|
||||
#include "Domain/Extension/CustomAction.h"
|
||||
#include "Domain/FastFile/FastFileBlock.h"
|
||||
#include "MemberInformation.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
class MemberInformation;
|
||||
|
||||
class StructureInformation
|
||||
{
|
||||
public:
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include "CodeGenerator.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Templates/AssetStructTestsTemplate.h"
|
||||
#include "Templates/ZoneLoadTemplate.h"
|
||||
#include "Templates/ZoneWriteTemplate.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
CodeGenerator::CodeGenerator(const ZoneCodeGeneratorArguments* args)
|
||||
@ -68,7 +68,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!StructureComputations(info).IsAsset())
|
||||
if (!StructureComputations(info).IsAsset())
|
||||
{
|
||||
std::cout << "Type is not an asset '" << name << "'" << std::endl;
|
||||
return false;
|
||||
@ -109,11 +109,13 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
||||
auto context = RenderingContext::BuildContext(repository, asset);
|
||||
if (!GenerateCodeForTemplate(context.get(), foundTemplate->second.get()))
|
||||
{
|
||||
std::cout << "Failed to generate code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first << "'\n";
|
||||
std::cout << "Failed to generate code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first
|
||||
<< "'\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Successfully generated code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first << "'\n";
|
||||
|
||||
std::cout << "Successfully generated code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first
|
||||
<< "'\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ICodeTemplate.h"
|
||||
#include "ZoneCodeGeneratorArguments.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
class CodeGenerator
|
||||
{
|
||||
const ZoneCodeGeneratorArguments* m_args;
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderingContext.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "RenderingContext.h"
|
||||
|
||||
class CodeTemplateFile
|
||||
{
|
||||
public:
|
||||
@ -28,7 +28,7 @@ public:
|
||||
ICodeTemplate(ICodeTemplate&& other) noexcept = default;
|
||||
ICodeTemplate& operator=(const ICodeTemplate& other) = default;
|
||||
ICodeTemplate& operator=(ICodeTemplate&& other) noexcept = default;
|
||||
|
||||
|
||||
virtual std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) = 0;
|
||||
virtual void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) = 0;
|
||||
};
|
||||
|
@ -47,15 +47,15 @@ RenderingUsedType* RenderingContext::AddUsedType(std::unique_ptr<RenderingUsedTy
|
||||
|
||||
RenderingUsedType* RenderingContext::GetBaseType(const IDataRepository* repository, MemberComputations* computations, RenderingUsedType* usedType)
|
||||
{
|
||||
if(usedType->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||
if (usedType->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||
{
|
||||
const auto* typedefDefinition = dynamic_cast<const TypedefDefinition*>(usedType->m_type);
|
||||
|
||||
while(typedefDefinition->m_type_declaration->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||
while (typedefDefinition->m_type_declaration->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||
typedefDefinition = dynamic_cast<const TypedefDefinition*>(typedefDefinition->m_type_declaration->m_type);
|
||||
|
||||
const auto foundUsedType = m_used_types_lookup.find(typedefDefinition->m_type_declaration->m_type);
|
||||
if(foundUsedType == m_used_types_lookup.end())
|
||||
if (foundUsedType == m_used_types_lookup.end())
|
||||
{
|
||||
const auto* memberDef = dynamic_cast<const DefinitionWithMembers*>(typedefDefinition->m_type_declaration->m_type);
|
||||
StructureInformation* info = nullptr;
|
||||
@ -75,23 +75,23 @@ RenderingUsedType* RenderingContext::GetBaseType(const IDataRepository* reposito
|
||||
|
||||
void RenderingContext::AddMembersToContext(const IDataRepository* repository, StructureInformation* info)
|
||||
{
|
||||
for(const auto& member : info->m_ordered_members)
|
||||
for (const auto& member : info->m_ordered_members)
|
||||
{
|
||||
MemberComputations computations(member.get());
|
||||
|
||||
if(computations.ShouldIgnore())
|
||||
if (computations.ShouldIgnore())
|
||||
continue;
|
||||
|
||||
RenderingUsedType* usedType;
|
||||
const auto existingUsedType = m_used_types_lookup.find(member->m_member->m_type_declaration->m_type);
|
||||
if(existingUsedType == m_used_types_lookup.end())
|
||||
if (existingUsedType == m_used_types_lookup.end())
|
||||
usedType = AddUsedType(std::make_unique<RenderingUsedType>(member->m_member->m_type_declaration->m_type, member->m_type));
|
||||
else
|
||||
usedType = existingUsedType->second.get();
|
||||
|
||||
auto* baseUsedType = GetBaseType(repository, &computations, usedType);
|
||||
|
||||
if(!computations.IsInRuntimeBlock())
|
||||
if (!computations.IsInRuntimeBlock())
|
||||
{
|
||||
usedType->m_non_runtime_reference_exists = true;
|
||||
|
||||
@ -105,7 +105,7 @@ void RenderingContext::AddMembersToContext(const IDataRepository* repository, St
|
||||
if (computations.ContainsArrayPointerReference() || computations.ContainsArrayReference())
|
||||
usedType->m_array_reference_exists = true;
|
||||
|
||||
if(computations.ContainsPointerArrayReference() && !member->m_is_string)
|
||||
if (computations.ContainsPointerArrayReference() && !member->m_is_string)
|
||||
{
|
||||
usedType->m_pointer_array_reference_exists = true;
|
||||
|
||||
@ -136,29 +136,27 @@ void RenderingContext::MakeAsset(const IDataRepository* repository, StructureInf
|
||||
|
||||
void RenderingContext::CreateUsedTypeCollections()
|
||||
{
|
||||
for(auto* usedType : m_used_types)
|
||||
for (auto* usedType : m_used_types)
|
||||
{
|
||||
if (usedType->m_info != nullptr)
|
||||
{
|
||||
StructureComputations computations(usedType->m_info);
|
||||
|
||||
if(usedType->m_info->m_definition == usedType->m_type)
|
||||
if (usedType->m_info->m_definition == usedType->m_type)
|
||||
m_used_structures.push_back(usedType);
|
||||
|
||||
if(computations.IsAsset() && usedType->m_info != m_asset)
|
||||
if (computations.IsAsset() && usedType->m_info != m_asset)
|
||||
m_referenced_assets.push_back(usedType);
|
||||
|
||||
if (!m_has_actions)
|
||||
{
|
||||
if ((!computations.IsAsset() || usedType->m_is_context_asset)
|
||||
&& usedType->m_non_runtime_reference_exists
|
||||
if ((!computations.IsAsset() || usedType->m_is_context_asset) && usedType->m_non_runtime_reference_exists
|
||||
&& usedType->m_info->m_post_load_action)
|
||||
{
|
||||
m_has_actions = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Domain/Computations/MemberComputations.h"
|
||||
#include "Domain/Information/StructureInformation.h"
|
||||
#include "Persistence/IDataRepository.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class RenderingUsedType
|
||||
{
|
||||
public:
|
||||
|
@ -1,31 +1,33 @@
|
||||
#include "AssetStructTestsTemplate.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Internal/BaseTemplate.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
class AssetStructTestsTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
void TestMethod(StructureInformation* structure)
|
||||
{
|
||||
LINE("TEST_CASE(\""<<m_env.m_game<<"::"<<m_env.m_asset->m_definition->GetFullName()<<": Tests for "<<structure->m_definition->GetFullName()<<"\", \"[assetstruct]\")")
|
||||
LINE("TEST_CASE(\"" << m_env.m_game << "::" << m_env.m_asset->m_definition->GetFullName() << ": Tests for " << structure->m_definition->GetFullName()
|
||||
<< "\", \"[assetstruct]\")")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
for(const auto& member : structure->m_ordered_members)
|
||||
for (const auto& member : structure->m_ordered_members)
|
||||
{
|
||||
if(!member->m_member->m_name.empty() && !member->m_member->m_type_declaration->m_has_custom_bit_size)
|
||||
if (!member->m_member->m_name.empty() && !member->m_member->m_type_declaration->m_has_custom_bit_size)
|
||||
{
|
||||
LINE("REQUIRE(offsetof(" << structure->m_definition->GetFullName() << ", " << member->m_member->m_name << ") == " << member->m_member->m_offset << ");")
|
||||
LINE("REQUIRE(offsetof(" << structure->m_definition->GetFullName() << ", " << member->m_member->m_name << ") == " << member->m_member->m_offset
|
||||
<< ");")
|
||||
}
|
||||
}
|
||||
|
||||
LINE("")
|
||||
|
||||
LINE("REQUIRE("<<structure->m_definition->GetSize()<<"u == sizeof("<<structure->m_definition->GetFullName()<<"));")
|
||||
LINE("REQUIRE("<<structure->m_definition->GetAlignment()<<"u == alignof("<<structure->m_definition->GetFullName()<<"));")
|
||||
LINE("REQUIRE(" << structure->m_definition->GetSize() << "u == sizeof(" << structure->m_definition->GetFullName() << "));")
|
||||
LINE("REQUIRE(" << structure->m_definition->GetAlignment() << "u == alignof(" << structure->m_definition->GetFullName() << "));")
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
@ -51,7 +53,7 @@ public:
|
||||
LINE("")
|
||||
LINE("using namespace " << m_env.m_game << ";")
|
||||
LINE("")
|
||||
LINE("namespace game::"<<m_env.m_game<<"::xassets::asset_"<<Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINE("namespace game::" << m_env.m_game << "::xassets::asset_" << Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include "BaseTemplate.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#include "Domain/Computations/MemberComputations.h"
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
BaseTemplate::BaseTemplate(std::ostream& stream, RenderingContext* context)
|
||||
: m_out(stream),
|
||||
m_env(*context),
|
||||
@ -88,7 +87,6 @@ std::string BaseTemplate::MakeTypeVarName(const DataDefinition* def)
|
||||
return str.str();
|
||||
}
|
||||
|
||||
|
||||
std::string BaseTemplate::MakeTypeWrittenVarName(const DataDefinition* def)
|
||||
{
|
||||
std::ostringstream str;
|
||||
@ -137,7 +135,10 @@ std::string BaseTemplate::MakeWrittenMemberAccess(StructureInformation* info, Me
|
||||
return str.str();
|
||||
}
|
||||
|
||||
std::string BaseTemplate::MakeMemberAccess(const std::string& variableName, StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier)
|
||||
std::string BaseTemplate::MakeMemberAccess(const std::string& variableName,
|
||||
StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << variableName << "->" << member->m_member->m_name;
|
||||
@ -210,7 +211,7 @@ std::string BaseTemplate::MakeCustomActionCall(CustomAction* action)
|
||||
|
||||
std::string BaseTemplate::MakeArrayCount(const ArrayDeclarationModifier* arrayModifier)
|
||||
{
|
||||
if(arrayModifier->m_dynamic_count_evaluation)
|
||||
if (arrayModifier->m_dynamic_count_evaluation)
|
||||
{
|
||||
return MakeEvaluation(arrayModifier->m_dynamic_count_evaluation.get());
|
||||
}
|
||||
@ -234,11 +235,11 @@ void BaseTemplate::MakeOperandDynamic(const OperandDynamic* op, std::ostringstre
|
||||
{
|
||||
MakeTypeVarNameInternal(op->m_structure->m_definition, str);
|
||||
|
||||
if(!op->m_referenced_member_chain.empty())
|
||||
if (!op->m_referenced_member_chain.empty())
|
||||
{
|
||||
str << "->";
|
||||
const auto lastEntry = op->m_referenced_member_chain.end() - 1;
|
||||
for(auto i = op->m_referenced_member_chain.begin(); i != lastEntry; ++i)
|
||||
for (auto i = op->m_referenced_member_chain.begin(); i != lastEntry; ++i)
|
||||
{
|
||||
MemberComputations computations(*i);
|
||||
str << (*i)->m_member->m_name;
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Domain/Computations/MemberDeclarationModifierComputations.h"
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Domain/Evaluation/OperandDynamic.h"
|
||||
@ -10,6 +7,9 @@
|
||||
#include "Domain/Evaluation/Operation.h"
|
||||
#include "Generating/RenderingContext.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
class BaseTemplate
|
||||
{
|
||||
protected:
|
||||
@ -45,7 +45,10 @@ protected:
|
||||
static std::string MakeSafeTypeName(const DataDefinition* def);
|
||||
static std::string MakeMemberAccess(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier);
|
||||
static std::string MakeWrittenMemberAccess(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier);
|
||||
static std::string MakeMemberAccess(const std::string& variableName, StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier);
|
||||
static std::string MakeMemberAccess(const std::string& variableName,
|
||||
StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier);
|
||||
static std::string MakeTypeDecl(const TypeDeclaration* decl);
|
||||
static std::string MakeFollowingReferences(const std::vector<DeclarationModifier*>& modifiers);
|
||||
static std::string MakeArrayIndices(const DeclarationModifierComputations& modifierComputations);
|
||||
@ -54,7 +57,21 @@ protected:
|
||||
static std::string MakeEvaluation(const IEvaluation* evaluation);
|
||||
};
|
||||
|
||||
#define LINE(x) {DoIntendation(); m_out << x << "\n";}
|
||||
#define LINE_START(x) {DoIntendation(); m_out << x;}
|
||||
#define LINE_MIDDLE(x) {m_out << x;}
|
||||
#define LINE_END(x) {m_out << x << "\n";}
|
||||
#define LINE(x) \
|
||||
{ \
|
||||
DoIntendation(); \
|
||||
m_out << x << "\n"; \
|
||||
}
|
||||
#define LINE_START(x) \
|
||||
{ \
|
||||
DoIntendation(); \
|
||||
m_out << x; \
|
||||
}
|
||||
#define LINE_MIDDLE(x) \
|
||||
{ \
|
||||
m_out << x; \
|
||||
}
|
||||
#define LINE_END(x) \
|
||||
{ \
|
||||
m_out << x << "\n"; \
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "ZoneLoadTemplate.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Domain/Computations/MemberComputations.h"
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Internal/BaseTemplate.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
enum class MemberLoadType
|
||||
@ -43,52 +43,52 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintHeaderPtrArrayLoadMethodDeclaration(const DataDefinition* def) const
|
||||
{
|
||||
LINE("void LoadPtrArray_"<< MakeSafeTypeName(def)<<"(bool atStreamStart, size_t count);")
|
||||
LINE("void LoadPtrArray_" << MakeSafeTypeName(def) << "(bool atStreamStart, size_t count);")
|
||||
}
|
||||
|
||||
void PrintHeaderArrayLoadMethodDeclaration(const DataDefinition* def) const
|
||||
{
|
||||
LINE("void LoadArray_"<< MakeSafeTypeName(def)<<"(bool atStreamStart, size_t count);")
|
||||
LINE("void LoadArray_" << MakeSafeTypeName(def) << "(bool atStreamStart, size_t count);")
|
||||
}
|
||||
|
||||
void PrintHeaderLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void Load_"<< MakeSafeTypeName(info->m_definition)<<"(bool atStreamStart);")
|
||||
LINE("void Load_" << MakeSafeTypeName(info->m_definition) << "(bool atStreamStart);")
|
||||
}
|
||||
|
||||
void PrintHeaderTempPtrLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void LoadPtr_"<< MakeSafeTypeName(info->m_definition)<<"(bool atStreamStart);")
|
||||
LINE("void LoadPtr_" << MakeSafeTypeName(info->m_definition) << "(bool atStreamStart);")
|
||||
}
|
||||
|
||||
void PrintHeaderAssetLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void LoadAsset_"<< MakeSafeTypeName(info->m_definition)<<"("<<info->m_definition->GetFullName()<<"** pAsset);")
|
||||
LINE("void LoadAsset_" << MakeSafeTypeName(info->m_definition) << "(" << info->m_definition->GetFullName() << "** pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderGetNameMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("static std::string GetAssetName("<<info->m_definition->GetFullName()<<"* pAsset);")
|
||||
LINE("static std::string GetAssetName(" << info->m_definition->GetFullName() << "* pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderMainLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("XAssetInfo<"<<info->m_definition->GetFullName()<<">* Load("<<info->m_definition->GetFullName()<<"** pAsset);")
|
||||
LINE("XAssetInfo<" << info->m_definition->GetFullName() << ">* Load(" << info->m_definition->GetFullName() << "** pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderConstructor() const
|
||||
{
|
||||
LINE(LoaderClassName(m_env.m_asset)<<"(Zone* zone, IZoneInputStream* stream);")
|
||||
LINE(LoaderClassName(m_env.m_asset) << "(Zone* zone, IZoneInputStream* stream);")
|
||||
}
|
||||
|
||||
void PrintVariableInitialization(const DataDefinition* def) const
|
||||
{
|
||||
LINE("var"<<def->m_name<<" = nullptr;")
|
||||
LINE("var" << def->m_name << " = nullptr;")
|
||||
}
|
||||
|
||||
void PrintPointerVariableInitialization(const DataDefinition* def) const
|
||||
{
|
||||
LINE("var"<<def->m_name<<"Ptr = nullptr;")
|
||||
LINE("var" << def->m_name << "Ptr = nullptr;")
|
||||
}
|
||||
|
||||
void PrintConstructorMethod()
|
||||
@ -96,7 +96,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE(LoaderClassName(m_env.m_asset) << "::" << LoaderClassName(m_env.m_asset) << "(Zone* zone, IZoneInputStream* stream)")
|
||||
|
||||
m_intendation++;
|
||||
LINE_START(": AssetLoader("<<m_env.m_asset->m_asset_enum_entry->m_name<<", zone, stream)")
|
||||
LINE_START(": AssetLoader(" << m_env.m_asset->m_asset_enum_entry->m_name << ", zone, stream)")
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINE_MIDDLE(", m_actions(zone)")
|
||||
@ -133,16 +133,16 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintLoadPtrArrayMethod_Loading(const DataDefinition* def, StructureInformation* info) const
|
||||
{
|
||||
LINE("*"<< MakeTypePtrVarName(def)<<" = m_stream->Alloc<"<<def->GetFullName()<<">("<< def->GetAlignment() <<");")
|
||||
LINE("*" << MakeTypePtrVarName(def) << " = m_stream->Alloc<" << def->GetFullName() << ">(" << def->GetAlignment() << ");")
|
||||
|
||||
if (info && !info->m_is_leaf)
|
||||
{
|
||||
LINE(MakeTypeVarName(info->m_definition)<<" = *"<< MakeTypePtrVarName(def)<<";")
|
||||
LINE("Load_"<< MakeSafeTypeName(def)<<"(true);")
|
||||
LINE(MakeTypeVarName(info->m_definition) << " = *" << MakeTypePtrVarName(def) << ";")
|
||||
LINE("Load_" << MakeSafeTypeName(def) << "(true);")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Load<"<<def->GetFullName()<<">(*"<< MakeTypePtrVarName(def)<<");")
|
||||
LINE("m_stream->Load<" << def->GetFullName() << ">(*" << MakeTypePtrVarName(def) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,8 +154,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (info && StructureComputations(info).IsAsset())
|
||||
{
|
||||
LINE(LoaderClassName(info)<<" loader(m_zone, m_stream);")
|
||||
LINE("AddDependency(loader.Load("<< MakeTypePtrVarName(def)<<"));")
|
||||
LINE(LoaderClassName(info) << " loader(m_zone, m_stream);")
|
||||
LINE("AddDependency(loader.Load(" << MakeTypePtrVarName(def) << "));")
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -173,7 +173,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("*"<< MakeTypePtrVarName(def)<<" = m_stream->ConvertOffsetToPointer(*"<< MakeTypePtrVarName(def)<<");")
|
||||
LINE("*" << MakeTypePtrVarName(def) << " = m_stream->ConvertOffsetToPointer(*" << MakeTypePtrVarName(def) << ");")
|
||||
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
@ -190,7 +190,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintLoadPtrArrayMethod(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
{
|
||||
LINE("void "<<LoaderClassName(m_env.m_asset)<<"::LoadPtrArray_"<< MakeSafeTypeName(def)<<"(const bool atStreamStart, const size_t count)")
|
||||
LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadPtrArray_" << MakeSafeTypeName(def) << "(const bool atStreamStart, const size_t count)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -199,7 +199,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
LINE("if(atStreamStart)")
|
||||
m_intendation++;
|
||||
LINE("m_stream->Load<"<<def->GetFullName()<<"*>("<< MakeTypePtrVarName(def)<<", count);")
|
||||
LINE("m_stream->Load<" << def->GetFullName() << "*>(" << MakeTypePtrVarName(def) << ", count);")
|
||||
m_intendation--;
|
||||
|
||||
LINE("")
|
||||
@ -229,7 +229,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
LINE("if(atStreamStart)")
|
||||
m_intendation++;
|
||||
LINE("m_stream->Load<"<<def->GetFullName()<<">("<<MakeTypeVarName(def)<<", count);")
|
||||
LINE("m_stream->Load<" << def->GetFullName() << ">(" << MakeTypeVarName(def) << ", count);")
|
||||
m_intendation--;
|
||||
|
||||
LINE("")
|
||||
@ -239,7 +239,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
m_intendation++;
|
||||
|
||||
LINE(MakeTypeVarName(info->m_definition) << " = var;")
|
||||
LINE("Load_"<<info->m_definition->m_name<<"(false);")
|
||||
LINE("Load_" << info->m_definition->m_name << "(false);")
|
||||
LINE("var++;")
|
||||
|
||||
m_intendation--;
|
||||
@ -249,7 +249,10 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void LoadMember_ScriptString(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const
|
||||
void LoadMember_ScriptString(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType) const
|
||||
{
|
||||
if (loadType == MemberLoadType::ARRAY_POINTER)
|
||||
{
|
||||
@ -272,12 +275,15 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_Asset(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const
|
||||
void LoadMember_Asset(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType) const
|
||||
{
|
||||
if (loadType == MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
LINE(LoaderClassName(member->m_type)<<" loader(m_zone, m_stream);")
|
||||
LINE("AddDependency(loader.Load(&"<<MakeMemberAccess(info, member, modifier)<<"));")
|
||||
LINE(LoaderClassName(member->m_type) << " loader(m_zone, m_stream);")
|
||||
LINE("AddDependency(loader.Load(&" << MakeMemberAccess(info, member, modifier) << "));")
|
||||
}
|
||||
else if (loadType == MemberLoadType::POINTER_ARRAY)
|
||||
{
|
||||
@ -290,7 +296,10 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_String(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const
|
||||
void LoadMember_String(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType) const
|
||||
{
|
||||
if (loadType == MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
@ -309,17 +318,17 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("varXString = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
if (modifier.IsArray())
|
||||
{
|
||||
LINE("LoadXStringArray(false, "<<modifier.GetArraySize()<<");")
|
||||
LINE("LoadXStringArray(false, " << modifier.GetArraySize() << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("LoadXStringArray(true, "<<MakeEvaluation(modifier.GetPointerArrayCountEvaluation())<<");")
|
||||
LINE("LoadXStringArray(true, " << MakeEvaluation(modifier.GetPointerArrayCountEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
LINE("#error unsupported loadType "<<static_cast<int>(loadType)<<" for string")
|
||||
LINE("#error unsupported loadType " << static_cast<int>(loadType) << " for string")
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,7 +338,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
if (member->m_type && !member->m_type->m_is_leaf && !computations.IsInRuntimeBlock())
|
||||
{
|
||||
LINE(MakeTypeVarName(member->m_member->m_type_declaration->m_type) << " = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
LINE("LoadArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
LINE("LoadArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "
|
||||
<< MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
|
||||
if (member->m_type->m_post_load_action)
|
||||
{
|
||||
@ -339,8 +349,9 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,11 +360,12 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE(MakeTypePtrVarName(member->m_member->m_type_declaration->m_type) << " = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
if (modifier.IsArray())
|
||||
{
|
||||
LINE("LoadPtrArray_"<<MakeSafeTypeName(member->m_member->m_type_declaration->m_type)<<"(false, "<<modifier.GetArraySize()<<");")
|
||||
LINE("LoadPtrArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(false, " << modifier.GetArraySize() << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("LoadPtrArray_"<<MakeSafeTypeName(member->m_member->m_type_declaration->m_type)<<"(true, "<<MakeEvaluation(modifier.GetPointerArrayCountEvaluation())<<");")
|
||||
LINE("LoadPtrArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "
|
||||
<< MakeEvaluation(modifier.GetPointerArrayCountEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,11 +385,11 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (computations.IsAfterPartialLoad())
|
||||
{
|
||||
LINE("LoadArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "<<arraySizeStr <<");")
|
||||
LINE("LoadArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, " << arraySizeStr << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("LoadArray_"<<MakeSafeTypeName(member->m_member->m_type_declaration->m_type)<<"(false, "<<arraySizeStr <<");")
|
||||
LINE("LoadArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(false, " << arraySizeStr << ");")
|
||||
}
|
||||
|
||||
if (member->m_type->m_post_load_action)
|
||||
@ -388,8 +400,9 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else if (computations.IsAfterPartialLoad())
|
||||
{
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) <<", "<<arraySizeStr <<");")
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ", " << arraySizeStr << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,12 +411,14 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
if (member->m_type && !member->m_type->m_is_leaf)
|
||||
{
|
||||
LINE(MakeTypeVarName(member->m_member->m_type_declaration->m_type) << " = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
LINE("LoadArray_"<<MakeSafeTypeName(member->m_member->m_type_declaration->m_type)<<"(true, "<<MakeEvaluation(modifier.GetDynamicArraySizeEvaluation())<<");")
|
||||
LINE("LoadArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "
|
||||
<< MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Load<"<<MakeTypeDecl(member->m_member->m_type_declaration.get())<<MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<<">("<<MakeMemberAccess(info, member, modifier)<<", "<<MakeEvaluation(modifier.GetDynamicArraySizeEvaluation())<<");")
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ", " << MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,8 +446,9 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else if (computations.IsAfterPartialLoad())
|
||||
{
|
||||
LINE("m_stream->Load<"<<MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(&" << MakeMemberAccess(info, member, modifier)<<");")
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(&" << MakeMemberAccess(info, member, modifier)
|
||||
<< ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,12 +468,16 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) << ");")
|
||||
LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ");")
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_TypeCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const
|
||||
void LoadMember_TypeCheck(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType) const
|
||||
{
|
||||
if (member->m_is_string)
|
||||
{
|
||||
@ -506,11 +526,12 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
static bool LoadMember_ShouldMakeAlloc(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType)
|
||||
static bool LoadMember_ShouldMakeAlloc(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType)
|
||||
{
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER
|
||||
&& loadType != MemberLoadType::POINTER_ARRAY
|
||||
&& loadType != MemberLoadType::SINGLE_POINTER)
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER && loadType != MemberLoadType::POINTER_ARRAY && loadType != MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -544,23 +565,25 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
const MemberComputations computations(member);
|
||||
if (computations.IsInTempBlock())
|
||||
{
|
||||
LINE(member->m_member->m_type_declaration->m_type->GetFullName()<< "* ptr = "<<MakeMemberAccess(info, member, modifier)<<";")
|
||||
LINE(member->m_member->m_type_declaration->m_type->GetFullName() << "* ptr = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
}
|
||||
|
||||
const auto typeDecl = MakeTypeDecl(member->m_member->m_type_declaration.get());
|
||||
const auto followingReferences = MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers());
|
||||
|
||||
// This used to use `alignof()` to calculate alignment but due to inconsistencies between compilers and bugs discovered in MSVC
|
||||
// (Alignment specified via `__declspec(align())` showing as correct via intellisense but is incorrect when compiled for types that have a larger alignment than the specified value)
|
||||
// this was changed to make ZoneCodeGenerator calculate what is supposed to be used as alignment when allocating.
|
||||
// (Alignment specified via `__declspec(align())` showing as correct via intellisense but is incorrect when compiled for types that have a larger
|
||||
// alignment than the specified value) this was changed to make ZoneCodeGenerator calculate what is supposed to be used as alignment when allocating.
|
||||
// This is more reliable when being used with different compilers and the value used can be seen in the source code directly
|
||||
if (member->m_alloc_alignment)
|
||||
{
|
||||
LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">("<<MakeEvaluation(member->m_alloc_alignment.get())<<");")
|
||||
LINE(MakeMemberAccess(info, member, modifier)
|
||||
<< " = m_stream->Alloc<" << typeDecl << followingReferences << ">(" << MakeEvaluation(member->m_alloc_alignment.get()) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">("<<modifier.GetAlignment()<<");")
|
||||
LINE(MakeMemberAccess(info, member, modifier)
|
||||
<< " = m_stream->Alloc<" << typeDecl << followingReferences << ">(" << modifier.GetAlignment() << ");")
|
||||
}
|
||||
|
||||
if (computations.IsInTempBlock())
|
||||
@ -569,7 +592,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE(member->m_member->m_type_declaration->m_type->GetFullName() << "** toInsert = nullptr;")
|
||||
LINE("if(ptr == PTR_INSERT)")
|
||||
m_intendation++;
|
||||
LINE("toInsert = m_stream->InsertPointer<"<<member->m_member->m_type_declaration->m_type->GetFullName() << ">();")
|
||||
LINE("toInsert = m_stream->InsertPointer<" << member->m_member->m_type_declaration->m_type->GetFullName() << ">();")
|
||||
m_intendation--;
|
||||
LINE("")
|
||||
}
|
||||
@ -581,22 +604,22 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
LINE("if(toInsert != nullptr)")
|
||||
m_intendation++;
|
||||
LINE("*toInsert = "<<MakeTypeVarName(info->m_definition)<<"->"<<member->m_member->m_name<<";")
|
||||
LINE("*toInsert = " << MakeTypeVarName(info->m_definition) << "->" << member->m_member->m_name << ";")
|
||||
m_intendation--;
|
||||
}
|
||||
}
|
||||
|
||||
static bool LoadMember_ShouldMakeReuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType)
|
||||
static bool LoadMember_ShouldMakeReuse(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType)
|
||||
{
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER
|
||||
&& loadType != MemberLoadType::SINGLE_POINTER
|
||||
&& loadType != MemberLoadType::POINTER_ARRAY)
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER && loadType != MemberLoadType::SINGLE_POINTER && loadType != MemberLoadType::POINTER_ARRAY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (loadType == MemberLoadType::POINTER_ARRAY
|
||||
&& modifier.IsArray())
|
||||
if (loadType == MemberLoadType::POINTER_ARRAY && modifier.IsArray())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -606,8 +629,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
void LoadMember_Reuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType)
|
||||
{
|
||||
if (!LoadMember_ShouldMakeReuse(info, member, modifier, loadType)
|
||||
|| !member->m_is_reusable)
|
||||
if (!LoadMember_ShouldMakeReuse(info, member, modifier, loadType) || !member->m_is_reusable)
|
||||
{
|
||||
LoadMember_Alloc(info, member, modifier, loadType);
|
||||
return;
|
||||
@ -616,7 +638,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
const MemberComputations computations(member);
|
||||
if (computations.IsInTempBlock())
|
||||
{
|
||||
LINE("if("<<MakeMemberAccess(info, member, modifier)<<" == PTR_FOLLOWING || "<<MakeMemberAccess(info, member, modifier)<<" == PTR_INSERT)")
|
||||
LINE("if(" << MakeMemberAccess(info, member, modifier) << " == PTR_FOLLOWING || " << MakeMemberAccess(info, member, modifier) << " == PTR_INSERT)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -635,7 +657,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("if("<<MakeMemberAccess(info, member, modifier)<<" == PTR_FOLLOWING)")
|
||||
LINE("if(" << MakeMemberAccess(info, member, modifier) << " == PTR_FOLLOWING)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -647,11 +669,12 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE(MakeMemberAccess(info, member, modifier)<< " = m_stream->ConvertOffsetToPointer("<<MakeMemberAccess(info, member, modifier)<<");")
|
||||
LINE(MakeMemberAccess(info, member, modifier) << " = m_stream->ConvertOffsetToPointer(" << MakeMemberAccess(info, member, modifier) << ");")
|
||||
|
||||
if (member->m_is_script_string && loadType == MemberLoadType::ARRAY_POINTER)
|
||||
{
|
||||
LINE("MarkScriptStringArrayAsUsed(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
LINE("MarkScriptStringArrayAsUsed(" << MakeMemberAccess(info, member, modifier) << ", "
|
||||
<< MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
@ -659,11 +682,12 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
static bool LoadMember_ShouldMakePointerCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, MemberLoadType loadType)
|
||||
static bool LoadMember_ShouldMakePointerCheck(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
MemberLoadType loadType)
|
||||
{
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER
|
||||
&& loadType != MemberLoadType::POINTER_ARRAY
|
||||
&& loadType != MemberLoadType::SINGLE_POINTER)
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER && loadType != MemberLoadType::POINTER_ARRAY && loadType != MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -681,7 +705,10 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadMember_PointerCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType)
|
||||
void LoadMember_PointerCheck(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType)
|
||||
{
|
||||
if (LoadMember_ShouldMakePointerCheck(info, member, modifier, loadType))
|
||||
{
|
||||
@ -769,7 +796,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
LINE("#error LoadMemberReference failed @ "<<member->m_member->m_name)
|
||||
LINE("#error LoadMemberReference failed @ " << member->m_member->m_name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -778,7 +805,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
if (member->m_condition)
|
||||
{
|
||||
LINE("if("<<MakeEvaluation(member->m_condition.get())<<")")
|
||||
LINE("if(" << MakeEvaluation(member->m_condition.get()) << ")")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -802,7 +829,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
if (member->m_condition)
|
||||
{
|
||||
LINE("if("<<MakeEvaluation(member->m_condition.get())<<")")
|
||||
LINE("if(" << MakeEvaluation(member->m_condition.get()) << ")")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -820,7 +847,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
if (member->m_condition)
|
||||
{
|
||||
LINE("else if("<<MakeEvaluation(member->m_condition.get())<<")")
|
||||
LINE("else if(" << MakeEvaluation(member->m_condition.get()) << ")")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -845,7 +872,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
if (member->m_condition)
|
||||
{
|
||||
LINE("else if("<<MakeEvaluation(member->m_condition.get())<<")")
|
||||
LINE("else if(" << MakeEvaluation(member->m_condition.get()) << ")")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -856,7 +883,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("#error Middle member of union must have condition ("<<member->m_member->m_name<<")")
|
||||
LINE("#error Middle member of union must have condition (" << member->m_member->m_name << ")")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -867,10 +894,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
if (computations.ShouldIgnore())
|
||||
return;
|
||||
|
||||
if (member->m_is_string
|
||||
|| member->m_is_script_string
|
||||
|| computations.ContainsNonEmbeddedReference()
|
||||
|| member->m_type && !member->m_type->m_is_leaf
|
||||
if (member->m_is_string || member->m_is_script_string || computations.ContainsNonEmbeddedReference() || member->m_type && !member->m_type->m_is_leaf
|
||||
|| computations.IsAfterPartialLoad())
|
||||
{
|
||||
if (info->m_definition->GetType() == DataDefinitionType::UNION)
|
||||
@ -887,7 +911,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("assert(" <<MakeTypeVarName(info->m_definition) << " != nullptr);")
|
||||
LINE("assert(" << MakeTypeVarName(info->m_definition) << " != nullptr);")
|
||||
|
||||
auto* dynamicMember = computations.GetDynamicMember();
|
||||
if (!(info->m_definition->GetType() == DataDefinitionType::UNION && dynamicMember))
|
||||
@ -898,12 +922,13 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (dynamicMember == nullptr)
|
||||
{
|
||||
LINE("m_stream->Load<"<<info->m_definition->GetFullName()<<">("<<MakeTypeVarName(info->m_definition)<<"); // Size: "<<info->m_definition->GetSize())
|
||||
LINE("m_stream->Load<" << info->m_definition->GetFullName() << ">(" << MakeTypeVarName(info->m_definition)
|
||||
<< "); // Size: " << info->m_definition->GetSize())
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->LoadPartial<"<<info->m_definition->GetFullName()<<">("<<MakeTypeVarName(info->m_definition)<<", offsetof("<<info->m_definition->GetFullName()
|
||||
<<", "<<dynamicMember->m_member->m_name<<"));")
|
||||
LINE("m_stream->LoadPartial<" << info->m_definition->GetFullName() << ">(" << MakeTypeVarName(info->m_definition) << ", offsetof("
|
||||
<< info->m_definition->GetFullName() << ", " << dynamicMember->m_member->m_name << "));")
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
@ -921,7 +946,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
else if (info->m_block)
|
||||
{
|
||||
LINE("")
|
||||
LINE("m_stream->PushBlock("<<info->m_block->m_name<<");")
|
||||
LINE("m_stream->PushBlock(" << info->m_block->m_name << ");")
|
||||
}
|
||||
|
||||
for (const auto& member : info->m_ordered_members)
|
||||
@ -942,16 +967,16 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
void PrintLoadPtrMethod(StructureInformation* info)
|
||||
{
|
||||
const bool inTemp = info->m_block && info->m_block->m_type == FastFileBlockType::TEMP;
|
||||
LINE("void "<<LoaderClassName(m_env.m_asset)<<"::LoadPtr_"<<MakeSafeTypeName(info->m_definition)<<"(const bool atStreamStart)")
|
||||
LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadPtr_" << MakeSafeTypeName(info->m_definition) << "(const bool atStreamStart)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("assert("<<MakeTypePtrVarName(info->m_definition)<<" != nullptr);")
|
||||
LINE("assert(" << MakeTypePtrVarName(info->m_definition) << " != nullptr);")
|
||||
LINE("")
|
||||
|
||||
LINE("if(atStreamStart)")
|
||||
m_intendation++;
|
||||
LINE("m_stream->Load<"<<info->m_definition->GetFullName()<<"*>("<< MakeTypePtrVarName(info->m_definition)<<");")
|
||||
LINE("m_stream->Load<" << info->m_definition->GetFullName() << "*>(" << MakeTypePtrVarName(info->m_definition) << ");")
|
||||
m_intendation--;
|
||||
|
||||
LINE("")
|
||||
@ -961,7 +986,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
}
|
||||
|
||||
LINE("if(*"<< MakeTypePtrVarName(info->m_definition)<<" != nullptr)")
|
||||
LINE("if(*" << MakeTypePtrVarName(info->m_definition) << " != nullptr)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -980,7 +1005,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
LINE(info->m_definition->GetFullName() << "* ptr = *" << MakeTypePtrVarName(info->m_definition) << ";")
|
||||
}
|
||||
LINE("*" << MakeTypePtrVarName(info->m_definition) << " = m_stream->Alloc<" << info->m_definition->GetFullName() << ">("<< info->m_definition->GetAlignment() <<");")
|
||||
LINE("*" << MakeTypePtrVarName(info->m_definition) << " = m_stream->Alloc<" << info->m_definition->GetFullName() << ">("
|
||||
<< info->m_definition->GetAlignment() << ");")
|
||||
|
||||
if (inTemp)
|
||||
{
|
||||
@ -1001,8 +1027,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
startLoadSection = false;
|
||||
LINE("")
|
||||
}
|
||||
LINE(MakeTypeVarName(info->m_definition)<<" = *"<< MakeTypePtrVarName(info->m_definition)<<";")
|
||||
LINE("Load_"<<MakeSafeTypeName(info->m_definition)<<"(true);")
|
||||
LINE(MakeTypeVarName(info->m_definition) << " = *" << MakeTypePtrVarName(info->m_definition) << ";")
|
||||
LINE("Load_" << MakeSafeTypeName(info->m_definition) << "(true);")
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1018,7 +1044,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
if (StructureComputations(info).IsAsset())
|
||||
{
|
||||
LINE("")
|
||||
LINE("LoadAsset_"<<MakeSafeTypeName(info->m_definition)<<"("<<MakeTypePtrVarName(info->m_definition)<<");")
|
||||
LINE("LoadAsset_" << MakeSafeTypeName(info->m_definition) << "(" << MakeTypePtrVarName(info->m_definition) << ");")
|
||||
}
|
||||
|
||||
if (inTemp)
|
||||
@ -1067,12 +1093,13 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintLoadAssetMethod(StructureInformation* info)
|
||||
{
|
||||
LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadAsset_" << MakeSafeTypeName(info->m_definition) << "(" << info->m_definition->GetFullName() << "** pAsset)")
|
||||
LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadAsset_" << MakeSafeTypeName(info->m_definition) << "(" << info->m_definition->GetFullName()
|
||||
<< "** pAsset)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("assert(pAsset != nullptr);")
|
||||
LINE("m_asset_info = reinterpret_cast<XAssetInfo<"<<info->m_definition->GetFullName()<<">*>(LinkAsset(GetAssetName(*pAsset), *pAsset));")
|
||||
LINE("m_asset_info = reinterpret_cast<XAssetInfo<" << info->m_definition->GetFullName() << ">*>(LinkAsset(GetAssetName(*pAsset), *pAsset));")
|
||||
LINE("*pAsset = m_asset_info->Asset();")
|
||||
|
||||
m_intendation--;
|
||||
@ -1081,7 +1108,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintMainLoadMethod()
|
||||
{
|
||||
LINE("XAssetInfo<" << m_env.m_asset->m_definition->GetFullName() << ">* " << LoaderClassName(m_env.m_asset) << "::Load(" << m_env.m_asset->m_definition->GetFullName() << "** pAsset)")
|
||||
LINE("XAssetInfo<" << m_env.m_asset->m_definition->GetFullName() << ">* " << LoaderClassName(m_env.m_asset) << "::Load("
|
||||
<< m_env.m_asset->m_definition->GetFullName() << "** pAsset)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -1094,7 +1122,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
LINE("if(m_asset_info == nullptr && *pAsset != nullptr)")
|
||||
m_intendation++;
|
||||
LINE("m_asset_info = reinterpret_cast<XAssetInfo<"<<m_env.m_asset->m_definition->GetFullName()<<">*>(GetAssetInfo(GetAssetName(*pAsset)));")
|
||||
LINE("m_asset_info = reinterpret_cast<XAssetInfo<" << m_env.m_asset->m_definition->GetFullName() << ">*>(GetAssetInfo(GetAssetName(*pAsset)));")
|
||||
m_intendation--;
|
||||
LINE("")
|
||||
LINE("return m_asset_info;")
|
||||
@ -1119,7 +1147,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
LINE_MIDDLE("->"<<member->m_member->m_name)
|
||||
LINE_MIDDLE("->" << member->m_member->m_name)
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1130,7 +1158,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("return \""<<m_env.m_asset->m_definition->m_name<<"\";")
|
||||
LINE("return \"" << m_env.m_asset->m_definition->m_name << "\";")
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
@ -1157,7 +1185,8 @@ public:
|
||||
LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\"")
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINE("#include \"Game/" << m_env.m_game << "/XAssets/" << Lower(m_env.m_asset->m_definition->m_name) << "/" << Lower(m_env.m_asset->m_definition->m_name) << "_actions.h\"")
|
||||
LINE("#include \"Game/" << m_env.m_game << "/XAssets/" << Lower(m_env.m_asset->m_definition->m_name) << "/"
|
||||
<< Lower(m_env.m_asset->m_definition->m_name) << "_actions.h\"")
|
||||
}
|
||||
LINE("#include <string>")
|
||||
LINE("")
|
||||
@ -1168,10 +1197,10 @@ public:
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("XAssetInfo<"<<m_env.m_asset->m_definition->GetFullName()<<">* m_asset_info;")
|
||||
LINE("XAssetInfo<" << m_env.m_asset->m_definition->GetFullName() << ">* m_asset_info;")
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINE("Actions_"<<m_env.m_asset->m_definition->m_name<<" m_actions;")
|
||||
LINE("Actions_" << m_env.m_asset->m_definition->m_name << " m_actions;")
|
||||
}
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
@ -1242,7 +1271,7 @@ public:
|
||||
LINE("// Any changes will be discarded when regenerating.")
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINE("#include \""<<Lower(m_env.m_asset->m_definition->m_name)<<"_load_db.h\"")
|
||||
LINE("#include \"" << Lower(m_env.m_asset->m_definition->m_name) << "_load_db.h\"")
|
||||
LINE("#include <cassert>")
|
||||
LINE("")
|
||||
|
||||
@ -1251,7 +1280,7 @@ public:
|
||||
LINE("// Referenced Assets:")
|
||||
for (auto* type : m_env.m_referenced_assets)
|
||||
{
|
||||
LINE("#include \"../"<<Lower(type->m_type->m_name)<<"/"<<Lower(type->m_type->m_name)<<"_load_db.h\"")
|
||||
LINE("#include \"../" << Lower(type->m_type->m_name) << "/" << Lower(type->m_type->m_name) << "_load_db.h\"")
|
||||
}
|
||||
LINE("")
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "ZoneWriteTemplate.h"
|
||||
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Internal/BaseTemplate.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Internal/BaseTemplate.h"
|
||||
|
||||
class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
enum class MemberWriteType
|
||||
@ -86,7 +86,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintHeaderConstructor() const
|
||||
{
|
||||
LINE(WriterClassName(m_env.m_asset) << "("<<m_env.m_asset->m_definition->GetFullName()<<"* asset, Zone* zone, IZoneOutputStream* stream);")
|
||||
LINE(WriterClassName(m_env.m_asset) << "(" << m_env.m_asset->m_definition->GetFullName() << "* asset, Zone* zone, IZoneOutputStream* stream);")
|
||||
}
|
||||
|
||||
void PrintVariableInitialization(const DataDefinition* def) const
|
||||
@ -111,10 +111,12 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintConstructorMethod()
|
||||
{
|
||||
LINE(WriterClassName(m_env.m_asset) << "::" << WriterClassName(m_env.m_asset) << "("<<m_env.m_asset->m_definition->GetFullName()<<"* asset, Zone* zone, IZoneOutputStream* stream)")
|
||||
LINE(WriterClassName(m_env.m_asset) << "::" << WriterClassName(m_env.m_asset) << "(" << m_env.m_asset->m_definition->GetFullName()
|
||||
<< "* asset, Zone* zone, IZoneOutputStream* stream)")
|
||||
|
||||
m_intendation++;
|
||||
LINE_START(": AssetWriter(zone->m_pools->GetAsset("<<m_env.m_asset->m_asset_enum_entry->m_name<<", GetAssetName(asset))"<<", zone, stream)")
|
||||
LINE_START(": AssetWriter(zone->m_pools->GetAsset(" << m_env.m_asset->m_asset_enum_entry->m_name << ", GetAssetName(asset))"
|
||||
<< ", zone, stream)")
|
||||
LINE_END("")
|
||||
m_intendation--;
|
||||
|
||||
@ -148,12 +150,15 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void WriteMember_ScriptString(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType) const
|
||||
void WriteMember_ScriptString(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType) const
|
||||
{
|
||||
if (writeType == MemberWriteType::ARRAY_POINTER)
|
||||
{
|
||||
LINE("varScriptString = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
LINE("m_stream->MarkFollowing("<<MakeWrittenMemberAccess(info, member, modifier)<<");")
|
||||
LINE("m_stream->MarkFollowing(" << MakeWrittenMemberAccess(info, member, modifier) << ");")
|
||||
LINE("WriteScriptStringArray(true, " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
}
|
||||
else if (writeType == MemberWriteType::EMBEDDED_ARRAY)
|
||||
@ -172,11 +177,14 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
void WriteMember_Asset(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType) const
|
||||
void WriteMember_Asset(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType) const
|
||||
{
|
||||
if (writeType == MemberWriteType::SINGLE_POINTER)
|
||||
{
|
||||
LINE(WriterClassName(member->m_type) << " writer("<<MakeMemberAccess(info, member, modifier)<<", m_zone, m_stream);")
|
||||
LINE(WriterClassName(member->m_type) << " writer(" << MakeMemberAccess(info, member, modifier) << ", m_zone, m_stream);")
|
||||
LINE("writer.Write(&" << MakeWrittenMemberAccess(info, member, modifier) << ");")
|
||||
}
|
||||
else if (writeType == MemberWriteType::POINTER_ARRAY)
|
||||
@ -190,7 +198,10 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
void WriteMember_String(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType) const
|
||||
void WriteMember_String(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType) const
|
||||
{
|
||||
if (writeType == MemberWriteType::SINGLE_POINTER)
|
||||
{
|
||||
@ -232,12 +243,14 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
if (member->m_type && !member->m_type->m_is_leaf && !computations.IsInRuntimeBlock())
|
||||
{
|
||||
LINE(MakeTypeVarName(member->m_member->m_type_declaration->m_type) << " = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
LINE("WriteArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
LINE("WriteArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "
|
||||
<< MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +265,8 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
else
|
||||
{
|
||||
LINE("m_stream->MarkFollowing(" << MakeWrittenMemberAccess(info, member, modifier) << ");")
|
||||
LINE("WritePtrArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, " << MakeEvaluation(modifier.GetPointerArrayCountEvaluation()) << ");")
|
||||
LINE("WritePtrArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "
|
||||
<< MakeEvaluation(modifier.GetPointerArrayCountEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +284,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
if (computations.IsAfterPartialLoad())
|
||||
{
|
||||
LINE(MakeTypeVarName(member->m_member->m_type_declaration->m_type)<<" = "<< MakeMemberAccess(info, member, modifier) <<";")
|
||||
LINE(MakeTypeVarName(member->m_member->m_type_declaration->m_type) << " = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
LINE("WriteArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, " << arraySizeStr << ");")
|
||||
}
|
||||
else
|
||||
@ -282,8 +296,9 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else if (computations.IsAfterPartialLoad())
|
||||
{
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) << ", " << arraySizeStr << ");")
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ", " << arraySizeStr << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,12 +307,14 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
if (member->m_type && !member->m_type->m_is_leaf)
|
||||
{
|
||||
LINE(MakeTypeVarName(member->m_member->m_type_declaration->m_type) << " = " << MakeMemberAccess(info, member, modifier) << ";")
|
||||
LINE("WriteArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, " << MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()) << ");")
|
||||
LINE("WriteArray_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, "
|
||||
<< MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()) << ");")
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ", " << MakeEvaluation(modifier.GetDynamicArraySizeEvaluation()) << ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,8 +338,9 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else if (computations.IsAfterPartialLoad())
|
||||
{
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(&" << MakeMemberAccess(info, member, modifier) << ");")
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(&" << MakeMemberAccess(info, member, modifier)
|
||||
<< ");")
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,12 +355,16 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers())
|
||||
<< ">(" << MakeMemberAccess(info, member, modifier) << ");")
|
||||
LINE("m_stream->Write<" << MakeTypeDecl(member->m_member->m_type_declaration.get())
|
||||
<< MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) << ">(" << MakeMemberAccess(info, member, modifier)
|
||||
<< ");")
|
||||
}
|
||||
}
|
||||
|
||||
void WriteMember_TypeCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType) const
|
||||
void WriteMember_TypeCheck(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType) const
|
||||
{
|
||||
if (member->m_is_string)
|
||||
{
|
||||
@ -391,17 +413,17 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
static bool WriteMember_ShouldMakeInsertReuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
static bool WriteMember_ShouldMakeInsertReuse(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER
|
||||
&& writeType != MemberWriteType::SINGLE_POINTER
|
||||
&& writeType != MemberWriteType::POINTER_ARRAY)
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER && writeType != MemberWriteType::SINGLE_POINTER && writeType != MemberWriteType::POINTER_ARRAY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (writeType == MemberWriteType::POINTER_ARRAY
|
||||
&& modifier.IsArray())
|
||||
if (writeType == MemberWriteType::POINTER_ARRAY && modifier.IsArray())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -425,7 +447,10 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
return true;
|
||||
}
|
||||
|
||||
void WriteMember_InsertReuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
void WriteMember_InsertReuse(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (!WriteMember_ShouldMakeInsertReuse(info, member, modifier, writeType))
|
||||
{
|
||||
@ -435,7 +460,8 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (writeType == MemberWriteType::ARRAY_POINTER)
|
||||
{
|
||||
LINE("m_stream->ReusableAddOffset("<<MakeMemberAccess(info, member, modifier)<<", "<<MakeEvaluation(modifier.GetArrayPointerCountEvaluation())<<");")
|
||||
LINE("m_stream->ReusableAddOffset(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation())
|
||||
<< ");")
|
||||
}
|
||||
else if (writeType == MemberWriteType::POINTER_ARRAY)
|
||||
{
|
||||
@ -443,7 +469,8 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (evaluation)
|
||||
{
|
||||
LINE("m_stream->ReusableAddOffset(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetPointerArrayCountEvaluation()) << ");")
|
||||
LINE("m_stream->ReusableAddOffset(" << MakeMemberAccess(info, member, modifier) << ", "
|
||||
<< MakeEvaluation(modifier.GetPointerArrayCountEvaluation()) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -452,17 +479,18 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->ReusableAddOffset("<<MakeMemberAccess(info, member, modifier)<<");")
|
||||
LINE("m_stream->ReusableAddOffset(" << MakeMemberAccess(info, member, modifier) << ");")
|
||||
}
|
||||
|
||||
WriteMember_TypeCheck(info, member, modifier, writeType);
|
||||
}
|
||||
|
||||
static bool WriteMember_ShouldMakeAlign(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
static bool WriteMember_ShouldMakeAlign(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER
|
||||
&& writeType != MemberWriteType::POINTER_ARRAY
|
||||
&& writeType != MemberWriteType::SINGLE_POINTER)
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER && writeType != MemberWriteType::POINTER_ARRAY && writeType != MemberWriteType::SINGLE_POINTER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -485,7 +513,10 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
return true;
|
||||
}
|
||||
|
||||
void WriteMember_Align(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
void WriteMember_Align(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (!WriteMember_ShouldMakeAlign(info, member, modifier, writeType))
|
||||
{
|
||||
@ -498,27 +529,27 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (member->m_alloc_alignment)
|
||||
{
|
||||
LINE("m_stream->Align("<<MakeEvaluation(member->m_alloc_alignment.get())<<");")
|
||||
LINE("m_stream->Align(" << MakeEvaluation(member->m_alloc_alignment.get()) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("m_stream->Align("<<modifier.GetAlignment()<<");")
|
||||
LINE("m_stream->Align(" << modifier.GetAlignment() << ");")
|
||||
}
|
||||
|
||||
WriteMember_InsertReuse(info, member, modifier, writeType);
|
||||
}
|
||||
|
||||
static bool WriteMember_ShouldMakeReuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
static bool WriteMember_ShouldMakeReuse(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER
|
||||
&& writeType != MemberWriteType::SINGLE_POINTER
|
||||
&& writeType != MemberWriteType::POINTER_ARRAY)
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER && writeType != MemberWriteType::SINGLE_POINTER && writeType != MemberWriteType::POINTER_ARRAY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (writeType == MemberWriteType::POINTER_ARRAY
|
||||
&& modifier.IsArray())
|
||||
if (writeType == MemberWriteType::POINTER_ARRAY && modifier.IsArray())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -526,7 +557,10 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
return member->m_is_reusable;
|
||||
}
|
||||
|
||||
void WriteMember_Reuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
void WriteMember_Reuse(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (!WriteMember_ShouldMakeReuse(info, member, modifier, writeType))
|
||||
{
|
||||
@ -544,11 +578,12 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
static bool WriteMember_ShouldMakePointerCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
static bool WriteMember_ShouldMakePointerCheck(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER
|
||||
&& writeType != MemberWriteType::POINTER_ARRAY
|
||||
&& writeType != MemberWriteType::SINGLE_POINTER)
|
||||
if (writeType != MemberWriteType::ARRAY_POINTER && writeType != MemberWriteType::POINTER_ARRAY && writeType != MemberWriteType::SINGLE_POINTER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -566,7 +601,10 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
return true;
|
||||
}
|
||||
|
||||
void WriteMember_PointerCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberWriteType writeType)
|
||||
void WriteMember_PointerCheck(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberWriteType writeType)
|
||||
{
|
||||
if (WriteMember_ShouldMakePointerCheck(info, member, modifier, writeType))
|
||||
{
|
||||
@ -752,10 +790,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
if (computations.ShouldIgnore())
|
||||
return;
|
||||
|
||||
if (member->m_is_string
|
||||
|| member->m_is_script_string
|
||||
|| computations.ContainsNonEmbeddedReference()
|
||||
|| member->m_type && !member->m_type->m_is_leaf
|
||||
if (member->m_is_string || member->m_is_script_string || computations.ContainsNonEmbeddedReference() || member->m_type && !member->m_type->m_is_leaf
|
||||
|| computations.IsAfterPartialLoad())
|
||||
{
|
||||
if (info->m_definition->GetType() == DataDefinitionType::UNION)
|
||||
@ -783,13 +818,14 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (dynamicMember == nullptr)
|
||||
{
|
||||
LINE(MakeTypeWrittenVarName(info->m_definition)<<" = m_stream->Write<" << info->m_definition->GetFullName() << ">(" << MakeTypeVarName(info->m_definition) << "); // Size: "
|
||||
<< info->m_definition->GetSize())
|
||||
LINE(MakeTypeWrittenVarName(info->m_definition) << " = m_stream->Write<" << info->m_definition->GetFullName() << ">("
|
||||
<< MakeTypeVarName(info->m_definition) << "); // Size: " << info->m_definition->GetSize())
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE(MakeTypeWrittenVarName(info->m_definition) << " = m_stream->WritePartial<" << info->m_definition->GetFullName() << ">(" << MakeTypeVarName(info->m_definition) << ", offsetof(" <<
|
||||
info->m_definition->GetFullName() << ", " << dynamicMember->m_member->m_name << "));")
|
||||
LINE(MakeTypeWrittenVarName(info->m_definition)
|
||||
<< " = m_stream->WritePartial<" << info->m_definition->GetFullName() << ">(" << MakeTypeVarName(info->m_definition) << ", offsetof("
|
||||
<< info->m_definition->GetFullName() << ", " << dynamicMember->m_member->m_name << "));")
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
@ -840,7 +876,8 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
LINE("if(atStreamStart)")
|
||||
m_intendation++;
|
||||
LINE(MakeTypeWrittenPtrVarName(info->m_definition)<<" = m_stream->Write<" << info->m_definition->GetFullName() << "*>(" << MakeTypePtrVarName(info->m_definition) << ");")
|
||||
LINE(MakeTypeWrittenPtrVarName(info->m_definition)
|
||||
<< " = m_stream->Write<" << info->m_definition->GetFullName() << "*>(" << MakeTypePtrVarName(info->m_definition) << ");")
|
||||
m_intendation--;
|
||||
|
||||
LINE("")
|
||||
@ -857,7 +894,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
m_intendation++;
|
||||
|
||||
LINE("m_stream->Align(" << info->m_definition->GetAlignment() << ");")
|
||||
LINE("m_stream->ReusableAddOffset(*"<<MakeTypePtrVarName(info->m_definition)<<");")
|
||||
LINE("m_stream->ReusableAddOffset(*" << MakeTypePtrVarName(info->m_definition) << ");")
|
||||
LINE("")
|
||||
if (!info->m_is_leaf)
|
||||
{
|
||||
@ -870,7 +907,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
|
||||
LINE("")
|
||||
LINE("m_stream->MarkFollowing(*"<<MakeTypeWrittenPtrVarName(info->m_definition)<<");")
|
||||
LINE("m_stream->MarkFollowing(*" << MakeTypeWrittenPtrVarName(info->m_definition) << ");")
|
||||
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
@ -895,7 +932,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
LINE("assert(m_asset != nullptr);")
|
||||
LINE("assert(m_asset->m_ptr != nullptr);")
|
||||
LINE("")
|
||||
LINE("auto* zoneAsset = static_cast<"<<m_env.m_asset->m_definition->GetFullName()<<"*>(m_asset->m_ptr);")
|
||||
LINE("auto* zoneAsset = static_cast<" << m_env.m_asset->m_definition->GetFullName() << "*>(m_asset->m_ptr);")
|
||||
LINE(MakeTypePtrVarName(m_env.m_asset->m_definition) << " = &zoneAsset;")
|
||||
LINE(MakeTypeWrittenPtrVarName(m_env.m_asset->m_definition) << " = &zoneAsset;")
|
||||
LINE("WritePtr_" << MakeSafeTypeName(m_env.m_asset->m_definition) << "(false);")
|
||||
@ -941,11 +978,11 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
void PrintWritePtrArrayMethod_Loading(const DataDefinition* def, StructureInformation* info, const bool reusable) const
|
||||
{
|
||||
LINE("m_stream->Align("<<def->GetAlignment()<<");")
|
||||
LINE("m_stream->Align(" << def->GetAlignment() << ");")
|
||||
|
||||
if (reusable)
|
||||
{
|
||||
LINE("m_stream->ReusableAddOffset(*"<<MakeTypePtrVarName(def)<< ");")
|
||||
LINE("m_stream->ReusableAddOffset(*" << MakeTypePtrVarName(def) << ");")
|
||||
}
|
||||
|
||||
if (info && !info->m_is_leaf)
|
||||
@ -957,7 +994,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
LINE("m_stream->Write<" << def->GetFullName() << ">(*" << MakeTypePtrVarName(def) << ");")
|
||||
}
|
||||
LINE("m_stream->MarkFollowing(*"<< MakeTypeWrittenPtrVarName(def)<<");")
|
||||
LINE("m_stream->MarkFollowing(*" << MakeTypeWrittenPtrVarName(def) << ");")
|
||||
}
|
||||
|
||||
void PrintWritePtrArrayMethod_PointerCheck(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
@ -968,7 +1005,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
if (info && StructureComputations(info).IsAsset())
|
||||
{
|
||||
LINE(WriterClassName(info) << " writer(*"<< MakeTypePtrVarName(def)<<", m_zone, m_stream);")
|
||||
LINE(WriterClassName(info) << " writer(*" << MakeTypePtrVarName(def) << ", m_zone, m_stream);")
|
||||
LINE("writer.Write(" << MakeTypeWrittenPtrVarName(def) << ");")
|
||||
}
|
||||
else
|
||||
@ -1005,7 +1042,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
|
||||
LINE("if(atStreamStart)")
|
||||
m_intendation++;
|
||||
LINE(MakeTypeWrittenPtrVarName(def)<<" = m_stream->Write<" << def->GetFullName() << "*>(" << MakeTypePtrVarName(def) << ", count);")
|
||||
LINE(MakeTypeWrittenPtrVarName(def) << " = m_stream->Write<" << def->GetFullName() << "*>(" << MakeTypePtrVarName(def) << ", count);")
|
||||
m_intendation--;
|
||||
|
||||
LINE("")
|
||||
@ -1041,7 +1078,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
LINE("")
|
||||
LINE("if(atStreamStart)")
|
||||
m_intendation++;
|
||||
LINE(MakeTypeWrittenVarName(def)<<" = m_stream->Write<" << def->GetFullName() << ">(" << MakeTypeVarName(def) << ", count);")
|
||||
LINE(MakeTypeWrittenVarName(def) << " = m_stream->Write<" << def->GetFullName() << ">(" << MakeTypeVarName(def) << ", count);")
|
||||
m_intendation--;
|
||||
|
||||
LINE("")
|
||||
|
@ -1,9 +1,5 @@
|
||||
#include "CommandsFileReader.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#include "Impl/CommandsLexer.h"
|
||||
#include "Impl/CommandsParser.h"
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
@ -16,6 +12,10 @@
|
||||
#include "Parsing/PostProcessing/UnionsPostProcessor.h"
|
||||
#include "Parsing/PostProcessing/UsagesPostProcessor.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
|
||||
: m_args(args),
|
||||
m_filename(std::move(filename)),
|
||||
@ -64,7 +64,7 @@ void CommandsFileReader::SetupPostProcessors()
|
||||
|
||||
bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
||||
{
|
||||
if(m_args->m_verbose)
|
||||
if (m_args->m_verbose)
|
||||
{
|
||||
std::cout << "Reading commands file: " << m_filename << std::endl;
|
||||
}
|
||||
@ -81,7 +81,7 @@ bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
||||
const auto result = parser->Parse();
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
if(m_args->m_verbose)
|
||||
if (m_args->m_verbose)
|
||||
{
|
||||
std::cout << "Processing commands took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
|
||||
}
|
||||
@ -89,8 +89,10 @@ bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
return std::all_of(m_post_processors.begin(), m_post_processors.end(), [repository](const std::unique_ptr<IPostProcessor>& postProcessor)
|
||||
{
|
||||
return postProcessor->PostProcess(repository);
|
||||
});
|
||||
return std::all_of(m_post_processors.begin(),
|
||||
m_post_processors.end(),
|
||||
[repository](const std::unique_ptr<IPostProcessor>& postProcessor)
|
||||
{
|
||||
return postProcessor->PostProcess(repository);
|
||||
});
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ZoneCodeGeneratorArguments.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "Parsing/PostProcessing/IPostProcessor.h"
|
||||
#include "Persistence/IDataRepository.h"
|
||||
#include "ZoneCodeGeneratorArguments.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CommandsFileReader
|
||||
{
|
||||
|
@ -26,25 +26,23 @@ CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepo
|
||||
|
||||
const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceAction(),
|
||||
new SequenceAllocAlign(),
|
||||
new SequenceArchitecture(),
|
||||
new SequenceArrayCount(),
|
||||
new SequenceArraySize(),
|
||||
new SequenceAsset(),
|
||||
new SequenceBlock(),
|
||||
new SequenceCondition(),
|
||||
new SequenceCount(),
|
||||
new SequenceGame(),
|
||||
new SequenceName(),
|
||||
new SequenceReorder(),
|
||||
new SequenceReusable(),
|
||||
new SequenceScriptString(),
|
||||
new SequenceSetBlock(),
|
||||
new SequenceString(),
|
||||
new SequenceUse()
|
||||
});
|
||||
static std::vector<sequence_t*> tests({new SequenceAction(),
|
||||
new SequenceAllocAlign(),
|
||||
new SequenceArchitecture(),
|
||||
new SequenceArrayCount(),
|
||||
new SequenceArraySize(),
|
||||
new SequenceAsset(),
|
||||
new SequenceBlock(),
|
||||
new SequenceCondition(),
|
||||
new SequenceCount(),
|
||||
new SequenceGame(),
|
||||
new SequenceName(),
|
||||
new SequenceReorder(),
|
||||
new SequenceReusable(),
|
||||
new SequenceScriptString(),
|
||||
new SequenceSetBlock(),
|
||||
new SequenceString(),
|
||||
new SequenceUse()});
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
@ -54,8 +54,7 @@ bool CommandsParserState::GetNextTypenameSeparatorPos(const std::string& typeNam
|
||||
const auto typeNameValueSize = typeNameValue.size();
|
||||
for (auto currentHead = startPos + 1; currentHead < typeNameValueSize; currentHead++)
|
||||
{
|
||||
if (typeNameValue[currentHead] == ':'
|
||||
&& typeNameValue[currentHead - 1] == ':')
|
||||
if (typeNameValue[currentHead] == ':' && typeNameValue[currentHead - 1] == ':')
|
||||
{
|
||||
separatorPos = currentHead - 1;
|
||||
return true;
|
||||
@ -65,7 +64,10 @@ bool CommandsParserState::GetNextTypenameSeparatorPos(const std::string& typeNam
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommandsParserState::ExtractMembersFromTypenameInternal(const std::string& typeNameValue, unsigned typeNameOffset, StructureInformation* type, std::vector<MemberInformation*>& members)
|
||||
bool CommandsParserState::ExtractMembersFromTypenameInternal(const std::string& typeNameValue,
|
||||
unsigned typeNameOffset,
|
||||
StructureInformation* type,
|
||||
std::vector<MemberInformation*>& members)
|
||||
{
|
||||
auto startOffset = typeNameOffset;
|
||||
while (GetNextTypenameSeparatorPos(typeNameValue, typeNameOffset, typeNameOffset))
|
||||
@ -89,13 +91,17 @@ bool CommandsParserState::ExtractMembersFromTypenameInternal(const std::string&
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetMembersFromTypename(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members) const
|
||||
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);
|
||||
|| ExtractMembersFromTypenameInternal(typeNameValue, 0, baseType, members);
|
||||
}
|
||||
|
||||
bool CommandsParserState::GetTypenameAndMembersFromTypename(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members) const
|
||||
bool CommandsParserState::GetTypenameAndMembersFromTypename(const std::string& typeNameValue,
|
||||
StructureInformation*& structure,
|
||||
std::vector<MemberInformation*>& members) const
|
||||
{
|
||||
if (m_in_use != nullptr)
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Persistence/IDataRepository.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Persistence/IDataRepository.h"
|
||||
|
||||
class CommandsParserState
|
||||
{
|
||||
IDataRepository* m_repository;
|
||||
@ -13,7 +13,10 @@ class CommandsParserState
|
||||
|
||||
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);
|
||||
static bool ExtractMembersFromTypenameInternal(const std::string& typeNameValue,
|
||||
unsigned typeNameOffset,
|
||||
StructureInformation* type,
|
||||
std::vector<MemberInformation*>& members);
|
||||
|
||||
public:
|
||||
explicit CommandsParserState(IDataRepository* repository);
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Domain/Evaluation/OperationType.h"
|
||||
#include "Parsing/IParserValue.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/TokenPos.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class CommandsParserValueType
|
||||
{
|
||||
@ -55,6 +55,7 @@ public:
|
||||
TokenPos m_pos;
|
||||
CommandsParserValueType m_type;
|
||||
size_t m_hash;
|
||||
|
||||
union ValueType
|
||||
{
|
||||
char char_value;
|
||||
@ -103,4 +104,4 @@ public:
|
||||
_NODISCARD size_t IdentifierHash() const;
|
||||
_NODISCARD std::string& TypeNameValue() const;
|
||||
_NODISCARD const OperationType* OpTypeValue() const;
|
||||
};
|
||||
};
|
||||
|
@ -1,95 +1,74 @@
|
||||
#include "CommandsCommonMatchers.h"
|
||||
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#include "CommandsMatcherFactory.h"
|
||||
#include "Domain/Evaluation/OperandDynamic.h"
|
||||
#include "Domain/Evaluation/OperandStatic.h"
|
||||
#include "Domain/Evaluation/Operation.h"
|
||||
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::Typename(const supplier_t* labelSupplier)
|
||||
{
|
||||
static constexpr const char* BUILT_IN_TYPE_NAMES[]
|
||||
{
|
||||
"unsigned",
|
||||
"char",
|
||||
"short",
|
||||
"int",
|
||||
"long"
|
||||
};
|
||||
static_assert(std::extent<decltype(BUILT_IN_TYPE_NAMES)>::value == static_cast<int>(CommandsParserValueType::BUILT_IN_LAST) - static_cast<int>(CommandsParserValueType::BUILT_IN_FIRST) + 1);
|
||||
static constexpr const char* BUILT_IN_TYPE_NAMES[]{"unsigned", "char", "short", "int", "long"};
|
||||
static_assert(std::extent<decltype(BUILT_IN_TYPE_NAMES)>::value
|
||||
== static_cast<int>(CommandsParserValueType::BUILT_IN_LAST) - static_cast<int>(CommandsParserValueType::BUILT_IN_FIRST) + 1);
|
||||
|
||||
const CommandsMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.Or({
|
||||
create.And({
|
||||
create.Optional(create.Type(CommandsParserValueType::UNSIGNED)),
|
||||
create.Or({
|
||||
create.Type(CommandsParserValueType::CHAR),
|
||||
create.Type(CommandsParserValueType::SHORT),
|
||||
create.Type(CommandsParserValueType::INT),
|
||||
create.And({
|
||||
create.Type(CommandsParserValueType::LONG),
|
||||
create.Optional(create.Type(CommandsParserValueType::LONG))
|
||||
})
|
||||
})
|
||||
}).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
auto first = true;
|
||||
return create.Or(
|
||||
{create
|
||||
.And({create.Optional(create.Type(CommandsParserValueType::UNSIGNED)),
|
||||
create.Or({create.Type(CommandsParserValueType::CHAR),
|
||||
create.Type(CommandsParserValueType::SHORT),
|
||||
create.Type(CommandsParserValueType::INT),
|
||||
create.And({create.Type(CommandsParserValueType::LONG), create.Optional(create.Type(CommandsParserValueType::LONG))})})})
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
auto first = true;
|
||||
|
||||
for (const auto& token : values)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
str << " ";
|
||||
str << BUILT_IN_TYPE_NAMES[static_cast<int>(token.get().m_type) - static_cast<int>(CommandsParserValueType::BUILT_IN_FIRST)];
|
||||
}
|
||||
for (const auto& token : values)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
str << " ";
|
||||
str << BUILT_IN_TYPE_NAMES[static_cast<int>(token.get().m_type) - static_cast<int>(CommandsParserValueType::BUILT_IN_FIRST)];
|
||||
}
|
||||
|
||||
return CommandsParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
}),
|
||||
create.And({
|
||||
create.Identifier(),
|
||||
create.OptionalLoop(create.And({
|
||||
create.Char(':'),
|
||||
create.Char(':'),
|
||||
create.Identifier()
|
||||
}))
|
||||
}).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << values[0].get().IdentifierValue();
|
||||
return CommandsParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
}),
|
||||
create.And({create.Identifier(), create.OptionalLoop(create.And({create.Char(':'), create.Char(':'), create.Identifier()}))})
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << values[0].get().IdentifierValue();
|
||||
|
||||
for (auto i = 3u; i < values.size(); i += 3)
|
||||
str << "::" << values[i].get().IdentifierValue();
|
||||
for (auto i = 3u; i < values.size(); i += 3)
|
||||
str << "::" << values[i].get().IdentifierValue();
|
||||
|
||||
return CommandsParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
})
|
||||
});
|
||||
return CommandsParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
})});
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::ArrayDef(const supplier_t* labelSupplier)
|
||||
{
|
||||
const CommandsMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Char('['),
|
||||
create.Or({
|
||||
create.Integer(),
|
||||
create.Identifier()
|
||||
}),
|
||||
create.Char(']')
|
||||
}).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
if (values[1].get().m_type == CommandsParserValueType::INTEGER)
|
||||
return CommandsParserValue::Integer(values[1].get().GetPos(), values[1].get().IntegerValue());
|
||||
return create.And({create.Char('['), create.Or({create.Integer(), create.Identifier()}), create.Char(']')})
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
if (values[1].get().m_type == CommandsParserValueType::INTEGER)
|
||||
return CommandsParserValue::Integer(values[1].get().GetPos(), values[1].get().IntegerValue());
|
||||
|
||||
return CommandsParserValue::Identifier(values[1].get().GetPos(), new std::string(values[1].get().IdentifierValue()));
|
||||
});
|
||||
return CommandsParserValue::Identifier(values[1].get().GetPos(), new std::string(values[1].get().IdentifierValue()));
|
||||
});
|
||||
}
|
||||
|
||||
static constexpr int TAG_OPERAND = std::numeric_limits<int>::max() - 1;
|
||||
@ -112,125 +91,142 @@ std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::Parse
|
||||
{
|
||||
const CommandsMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Char('['),
|
||||
create.Label(LABEL_EVALUATION),
|
||||
create.Char(']').Tag(TAG_OPERAND_ARRAY_END)
|
||||
}).Tag(TAG_OPERAND_ARRAY);
|
||||
return create.And({create.Char('['), create.Label(LABEL_EVALUATION), create.Char(']').Tag(TAG_OPERAND_ARRAY_END)}).Tag(TAG_OPERAND_ARRAY);
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::ParseOperand(const supplier_t* labelSupplier)
|
||||
{
|
||||
const CommandsMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.Or({
|
||||
create.And({
|
||||
create.Label(LABEL_TYPENAME).Capture(CAPTURE_OPERAND_TYPENAME),
|
||||
create.OptionalLoop(MatcherFactoryWrapper<CommandsParserValue>(ParseOperandArray(labelSupplier)).Capture(CAPTURE_OPERAND_ARRAY))
|
||||
}).Tag(TAG_OPERAND_TYPENAME),
|
||||
create.Integer().Tag(TAG_OPERAND_INTEGER).Capture(CAPTURE_OPERAND_INTEGER)
|
||||
}).Tag(TAG_OPERAND);
|
||||
return create
|
||||
.Or({create
|
||||
.And({create.Label(LABEL_TYPENAME).Capture(CAPTURE_OPERAND_TYPENAME),
|
||||
create.OptionalLoop(MatcherFactoryWrapper<CommandsParserValue>(ParseOperandArray(labelSupplier)).Capture(CAPTURE_OPERAND_ARRAY))})
|
||||
.Tag(TAG_OPERAND_TYPENAME),
|
||||
create.Integer().Tag(TAG_OPERAND_INTEGER).Capture(CAPTURE_OPERAND_INTEGER)})
|
||||
.Tag(TAG_OPERAND);
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::ParseOperationType(const supplier_t* labelSupplier)
|
||||
{
|
||||
const CommandsMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.Or({
|
||||
create.Char('+').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_ADD);
|
||||
}),
|
||||
create.Char('-').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_SUBTRACT);
|
||||
}),
|
||||
create.Char('*').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_MULTIPLY);
|
||||
}),
|
||||
create.Char('/').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_DIVIDE);
|
||||
}),
|
||||
create.Char('%').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_REMAINDER);
|
||||
}),
|
||||
create.Char('&').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_BITWISE_AND);
|
||||
}),
|
||||
create.Char('^').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_BITWISE_XOR);
|
||||
}),
|
||||
create.Char('|').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_BITWISE_OR);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::SHIFT_LEFT).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_SHIFT_LEFT);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::SHIFT_RIGHT).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_SHIFT_RIGHT);
|
||||
}),
|
||||
create.Char('>').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_GREATER_THAN);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::GREATER_EQUAL).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_GREATER_EQUAL_THAN);
|
||||
}),
|
||||
create.Char('<').Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_LESS_THAN);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::LESS_EQUAL).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_LESS_EQUAL_THAN);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::EQUALS).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_EQUALS);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::NOT_EQUAL).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_NOT_EQUAL);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::LOGICAL_AND).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_AND);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::LOGICAL_OR).Transform([](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_OR);
|
||||
})
|
||||
}).Capture(CAPTURE_BINARY_OPERATION_TYPE);
|
||||
return create
|
||||
.Or({create.Char('+').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_ADD);
|
||||
}),
|
||||
create.Char('-').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_SUBTRACT);
|
||||
}),
|
||||
create.Char('*').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_MULTIPLY);
|
||||
}),
|
||||
create.Char('/').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_DIVIDE);
|
||||
}),
|
||||
create.Char('%').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_REMAINDER);
|
||||
}),
|
||||
create.Char('&').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_BITWISE_AND);
|
||||
}),
|
||||
create.Char('^').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_BITWISE_XOR);
|
||||
}),
|
||||
create.Char('|').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_BITWISE_OR);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::SHIFT_LEFT)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_SHIFT_LEFT);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::SHIFT_RIGHT)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_SHIFT_RIGHT);
|
||||
}),
|
||||
create.Char('>').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_GREATER_THAN);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::GREATER_EQUAL)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_GREATER_EQUAL_THAN);
|
||||
}),
|
||||
create.Char('<').Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_LESS_THAN);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::LESS_EQUAL)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_LESS_EQUAL_THAN);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::EQUALS)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_EQUALS);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::NOT_EQUAL)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_NOT_EQUAL);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::LOGICAL_AND)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_AND);
|
||||
}),
|
||||
create.Type(CommandsParserValueType::LOGICAL_OR)
|
||||
.Transform(
|
||||
[](CommandsMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return CommandsParserValue::OpType(values[0].get().GetPos(), OperationType::OPERATION_OR);
|
||||
})})
|
||||
.Capture(CAPTURE_BINARY_OPERATION_TYPE);
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::Evaluation(const supplier_t* labelSupplier)
|
||||
{
|
||||
const CommandsMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Or({
|
||||
create.And({
|
||||
create.Optional(create.Char('!').Tag(TAG_EVALUATION_NOT)),
|
||||
create.Char('('),
|
||||
create.Label(LABEL_EVALUATION),
|
||||
create.Char(')').Tag(TAG_EVALUATION_PARENTHESIS_END)
|
||||
}).Tag(TAG_EVALUATION_PARENTHESIS),
|
||||
ParseOperand(labelSupplier)
|
||||
}),
|
||||
create.Optional(create.And({
|
||||
ParseOperationType(labelSupplier),
|
||||
create.Label(LABEL_EVALUATION)
|
||||
}).Tag(TAG_EVALUATION_OPERATION))
|
||||
}).Tag(TAG_EVALUATION);
|
||||
return create
|
||||
.And({create.Or({create
|
||||
.And({create.Optional(create.Char('!').Tag(TAG_EVALUATION_NOT)),
|
||||
create.Char('('),
|
||||
create.Label(LABEL_EVALUATION),
|
||||
create.Char(')').Tag(TAG_EVALUATION_PARENTHESIS_END)})
|
||||
.Tag(TAG_EVALUATION_PARENTHESIS),
|
||||
ParseOperand(labelSupplier)}),
|
||||
create.Optional(create.And({ParseOperationType(labelSupplier), create.Label(LABEL_EVALUATION)}).Tag(TAG_EVALUATION_OPERATION))})
|
||||
.Tag(TAG_EVALUATION);
|
||||
}
|
||||
|
||||
std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessEvaluationInParenthesis(CommandsParserState* state, SequenceResult<CommandsParserValue>& result)
|
||||
@ -248,7 +244,8 @@ std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessEvaluationInParenthe
|
||||
return processedEvaluation;
|
||||
}
|
||||
|
||||
std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessOperand(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType)
|
||||
std::unique_ptr<IEvaluation>
|
||||
CommandsCommonMatchers::ProcessOperand(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType)
|
||||
{
|
||||
const auto nextTag = result.NextTag();
|
||||
|
||||
@ -293,7 +290,8 @@ std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessEvaluation(CommandsP
|
||||
return ProcessEvaluation(state, result, nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType)
|
||||
std::unique_ptr<IEvaluation>
|
||||
CommandsCommonMatchers::ProcessEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType)
|
||||
{
|
||||
if (result.PeekAndRemoveIfTag(TAG_EVALUATION) != TAG_EVALUATION)
|
||||
return nullptr;
|
||||
@ -332,14 +330,15 @@ std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessEvaluation(CommandsP
|
||||
throw ParsingException(TokenPos(), "Expected EvaluationTag @ Evaluation");
|
||||
}
|
||||
|
||||
operators.sort([](const std::pair<unsigned, const OperationType*>& p1, const std::pair<unsigned, const OperationType*>& p2)
|
||||
{
|
||||
if(p1.second->m_precedence != p2.second->m_precedence)
|
||||
return p1.second->m_precedence > p2.second->m_precedence;
|
||||
operators.sort(
|
||||
[](const std::pair<unsigned, const OperationType*>& p1, const std::pair<unsigned, const OperationType*>& p2)
|
||||
{
|
||||
if (p1.second->m_precedence != p2.second->m_precedence)
|
||||
return p1.second->m_precedence > p2.second->m_precedence;
|
||||
|
||||
return p1.first > p2.first;
|
||||
});
|
||||
|
||||
return p1.first > p2.first;
|
||||
});
|
||||
|
||||
while (!operators.empty())
|
||||
{
|
||||
const auto [operatorIndex, operatorType] = operators.back();
|
||||
@ -350,12 +349,12 @@ std::unique_ptr<IEvaluation> CommandsCommonMatchers::ProcessEvaluation(CommandsP
|
||||
|
||||
operators.pop_back();
|
||||
|
||||
for(auto& [opIndex, _] : operators)
|
||||
for (auto& [opIndex, _] : operators)
|
||||
{
|
||||
if (opIndex > operatorIndex)
|
||||
opIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return std::move(operands.front());
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "Domain/Evaluation/IEvaluation.h"
|
||||
#include "Domain/Evaluation/OperationType.h"
|
||||
#include "Parsing/Commands/Impl/CommandsParserState.h"
|
||||
@ -11,6 +8,9 @@
|
||||
#include "Parsing/Matcher/MatcherLabel.h"
|
||||
#include "Parsing/Sequence/SequenceResult.h"
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
class CommandsCommonMatchers
|
||||
{
|
||||
public:
|
||||
@ -20,7 +20,7 @@ public:
|
||||
static constexpr int LABEL_TYPENAME = std::numeric_limits<int>::max() - 1;
|
||||
static constexpr int LABEL_ARRAY_DEF = std::numeric_limits<int>::max() - 2;
|
||||
static constexpr int LABEL_EVALUATION = std::numeric_limits<int>::max() - 3;
|
||||
|
||||
|
||||
static std::unique_ptr<matcher_t> Typename(const supplier_t* labelSupplier);
|
||||
static std::unique_ptr<matcher_t> ArrayDef(const supplier_t* labelSupplier);
|
||||
|
||||
@ -30,10 +30,12 @@ private:
|
||||
static std::unique_ptr<matcher_t> ParseOperationType(const supplier_t* labelSupplier);
|
||||
|
||||
static std::unique_ptr<IEvaluation> ProcessEvaluationInParenthesis(CommandsParserState* state, SequenceResult<CommandsParserValue>& result);
|
||||
static std::unique_ptr<IEvaluation> ProcessOperand(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType);
|
||||
static std::unique_ptr<IEvaluation>
|
||||
ProcessOperand(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType);
|
||||
|
||||
public:
|
||||
static std::unique_ptr<matcher_t> Evaluation(const supplier_t* labelSupplier);
|
||||
static std::unique_ptr<IEvaluation> ProcessEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result);
|
||||
static std::unique_ptr<IEvaluation> ProcessEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType);
|
||||
static std::unique_ptr<IEvaluation>
|
||||
ProcessEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, StructureInformation* currentType);
|
||||
};
|
||||
|
@ -8,7 +8,6 @@ CommandsMatcherCharacter::CommandsMatcherCharacter(const char c)
|
||||
MatcherResult<CommandsParserValue> CommandsMatcherCharacter::CanMatch(ILexer<CommandsParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
return token.m_type == CommandsParserValueType::CHARACTER && token.CharacterValue() == m_char
|
||||
? MatcherResult<CommandsParserValue>::Match(1)
|
||||
: MatcherResult<CommandsParserValue>::NoMatch();
|
||||
return token.m_type == CommandsParserValueType::CHARACTER && token.CharacterValue() == m_char ? MatcherResult<CommandsParserValue>::Match(1)
|
||||
: MatcherResult<CommandsParserValue>::NoMatch();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Parsing/Commands/Impl/CommandsParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcherFactory.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CommandsMatcherFactory final : public AbstractMatcherFactory<CommandsParserValue>
|
||||
{
|
||||
public:
|
||||
|
@ -11,6 +11,6 @@ MatcherResult<CommandsParserValue> CommandsMatcherKeyword::CanMatch(ILexer<Comma
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
return token.m_type == CommandsParserValueType::IDENTIFIER && token.IdentifierHash() == m_hash && token.IdentifierValue() == m_value
|
||||
? MatcherResult<CommandsParserValue>::Match(1)
|
||||
: MatcherResult<CommandsParserValue>::NoMatch();
|
||||
? MatcherResult<CommandsParserValue>::Match(1)
|
||||
: MatcherResult<CommandsParserValue>::NoMatch();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Parsing/Commands/Impl/CommandsParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CommandsMatcherKeyword final : public AbstractMatcher<CommandsParserValue>
|
||||
{
|
||||
size_t m_hash;
|
||||
|
@ -7,7 +7,5 @@ CommandsMatcherValueType::CommandsMatcherValueType(CommandsParserValueType type)
|
||||
|
||||
MatcherResult<CommandsParserValue> CommandsMatcherValueType::CanMatch(ILexer<CommandsParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
return lexer->GetToken(tokenOffset).m_type == m_type
|
||||
? MatcherResult<CommandsParserValue>::Match(1)
|
||||
: MatcherResult<CommandsParserValue>::NoMatch();
|
||||
return lexer->GetToken(tokenOffset).m_type == m_type ? MatcherResult<CommandsParserValue>::Match(1) : MatcherResult<CommandsParserValue>::NoMatch();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "SequenceAction.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceAction::SequenceAction()
|
||||
{
|
||||
@ -9,31 +9,20 @@ SequenceAction::SequenceAction()
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddLabeledMatchers(
|
||||
{
|
||||
create.Char('('),
|
||||
create.Optional(create.And({
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_ARG_TYPE),
|
||||
create.OptionalLoop(create.And({
|
||||
create.Char(','),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_ARG_TYPE)
|
||||
}))
|
||||
})),
|
||||
create.Char(')')
|
||||
}, LABEL_ACTION_ARGS);
|
||||
{create.Char('('),
|
||||
create.Optional(
|
||||
create.And({create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_ARG_TYPE),
|
||||
create.OptionalLoop(create.And({create.Char(','), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_ARG_TYPE)}))})),
|
||||
create.Char(')')},
|
||||
LABEL_ACTION_ARGS);
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("action"),
|
||||
create.Or({
|
||||
create.And({
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_ACTION_NAME)
|
||||
}),
|
||||
create.Identifier().Capture(CAPTURE_ACTION_NAME)
|
||||
}),
|
||||
create.Label(LABEL_ACTION_ARGS),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers(
|
||||
{create.Keyword("set"),
|
||||
create.Keyword("action"),
|
||||
create.Or({create.And({create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Identifier().Capture(CAPTURE_ACTION_NAME)}),
|
||||
create.Identifier().Capture(CAPTURE_ACTION_NAME)}),
|
||||
create.Label(LABEL_ACTION_ARGS),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceAction::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
@ -67,7 +56,7 @@ void SequenceAction::ProcessMatch(CommandsParserState* state, SequenceResult<Com
|
||||
|
||||
// Extract all parameter types that were specified
|
||||
std::vector<DataDefinition*> parameterTypes;
|
||||
while(result.HasNextCapture(CAPTURE_ARG_TYPE))
|
||||
while (result.HasNextCapture(CAPTURE_ARG_TYPE))
|
||||
{
|
||||
const auto& argTypeToken = result.NextCapture(CAPTURE_ARG_TYPE);
|
||||
auto* dataDefinition = state->GetRepository()->GetDataDefinitionByName(argTypeToken.TypeNameValue());
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "SequenceAllocAlign.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceAllocAlign::SequenceAllocAlign()
|
||||
{
|
||||
@ -9,13 +9,11 @@ SequenceAllocAlign::SequenceAllocAlign()
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("allocalign"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set"),
|
||||
create.Keyword("allocalign"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceAllocAlign::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
@ -26,7 +24,7 @@ void SequenceAllocAlign::ProcessMatch(CommandsParserState* state, SequenceResult
|
||||
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, memberChain))
|
||||
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||
|
||||
if(memberChain.empty())
|
||||
if (memberChain.empty())
|
||||
throw ParsingException(typeNameToken.GetPos(), "Need to specify a member");
|
||||
|
||||
auto allocAlignEvaluation = CommandsCommonMatchers::ProcessEvaluation(state, result, type);
|
||||
|
@ -1,17 +1,13 @@
|
||||
#include "SequenceArchitecture.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceArchitecture::SequenceArchitecture()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("architecture"),
|
||||
create.Identifier().Capture(CAPTURE_ARCHITECTURE),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("architecture"), create.Identifier().Capture(CAPTURE_ARCHITECTURE), create.Char(';')});
|
||||
|
||||
m_architecture_mapping["x86"] = Architecture::X86;
|
||||
m_architecture_mapping["x64"] = Architecture::X64;
|
||||
@ -23,7 +19,7 @@ void SequenceArchitecture::ProcessMatch(CommandsParserState* state, SequenceResu
|
||||
|
||||
const auto foundArchitecture = m_architecture_mapping.find(architectureToken.IdentifierValue());
|
||||
|
||||
if(foundArchitecture == m_architecture_mapping.end())
|
||||
if (foundArchitecture == m_architecture_mapping.end())
|
||||
throw ParsingException(architectureToken.GetPos(), "Unknown architecture");
|
||||
|
||||
state->SetArchitecture(foundArchitecture->second);
|
||||
|
@ -1,9 +1,8 @@
|
||||
#include "SequenceArrayCount.h"
|
||||
|
||||
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceArrayCount::SequenceArrayCount()
|
||||
{
|
||||
@ -11,13 +10,11 @@ SequenceArrayCount::SequenceArrayCount()
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("arraycount"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set"),
|
||||
create.Keyword("arraycount"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceArrayCount::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
@ -29,7 +26,7 @@ void SequenceArrayCount::ProcessMatch(CommandsParserState* state, SequenceResult
|
||||
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), structure, memberChain))
|
||||
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||
|
||||
if(memberChain.empty())
|
||||
if (memberChain.empty())
|
||||
throw ParsingException(typeNameToken.GetPos(), "Must specify type with member");
|
||||
|
||||
const auto& memberDeclarationModifiers = memberChain.back()->m_member->m_type_declaration->m_declaration_modifiers;
|
||||
|
@ -1,9 +1,8 @@
|
||||
#include "SequenceArraySize.h"
|
||||
|
||||
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceArraySize::SequenceArraySize()
|
||||
{
|
||||
@ -11,13 +10,11 @@ SequenceArraySize::SequenceArraySize()
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("arraysize"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Capture(CAPTURE_EVALUATION),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set"),
|
||||
create.Keyword("arraysize"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Capture(CAPTURE_EVALUATION),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceArraySize::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,19 +1,17 @@
|
||||
#include "SequenceAsset.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceAsset::SequenceAsset()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("asset"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_ENUM_ENTRY),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("asset"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_ENUM_ENTRY),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceAsset::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "SequenceBlock.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceBlock::SequenceBlock()
|
||||
{
|
||||
@ -14,13 +14,11 @@ SequenceBlock::SequenceBlock()
|
||||
DEFINE_FAST_FILE_BLOCK_TYPE(NORMAL);
|
||||
#undef DEFINE_FAST_FILE_BLOCK_TYPE
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("block"),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY),
|
||||
create.Optional(create.Keyword("default").Tag(TAG_DEFAULT)),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("block"),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY),
|
||||
create.Optional(create.Keyword("default").Tag(TAG_DEFAULT)),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceBlock::AddFastFileBlockToLookup(std::string name, const FastFileBlockType type)
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/Commands/Impl/CommandsParser.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
class SequenceBlock final : public CommandsParser::sequence_t
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "SequenceCondition.h"
|
||||
|
||||
#include "Domain/Evaluation/OperandStatic.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceCondition::SequenceCondition()
|
||||
{
|
||||
@ -10,17 +10,13 @@ SequenceCondition::SequenceCondition()
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("condition"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Or({
|
||||
create.Keyword("always").Tag(TAG_ALWAYS),
|
||||
create.Keyword("never").Tag(TAG_NEVER),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Tag(TAG_EVALUATION).Capture(CAPTURE_EVALUATION)
|
||||
}),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set"),
|
||||
create.Keyword("condition"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Or({create.Keyword("always").Tag(TAG_ALWAYS),
|
||||
create.Keyword("never").Tag(TAG_NEVER),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION).Tag(TAG_EVALUATION).Capture(CAPTURE_EVALUATION)}),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceCondition::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
@ -36,7 +32,7 @@ void SequenceCondition::ProcessMatch(CommandsParserState* state, SequenceResult<
|
||||
throw ParsingException(typeNameToken.GetPos(), "Conditions can only be set on members and not for types");
|
||||
|
||||
std::unique_ptr<IEvaluation> conditionEvaluation;
|
||||
switch(result.NextTag())
|
||||
switch (result.NextTag())
|
||||
{
|
||||
case TAG_ALWAYS:
|
||||
conditionEvaluation = std::make_unique<OperandStatic>(1);
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include "Domain/Definition/ArrayDeclarationModifier.h"
|
||||
#include "Domain/Definition/PointerDeclarationModifier.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceCount::SequenceCount()
|
||||
{
|
||||
@ -12,18 +12,19 @@ SequenceCount::SequenceCount()
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION);
|
||||
AddLabeledMatchers(CommandsCommonMatchers::ArrayDef(this), CommandsCommonMatchers::LABEL_ARRAY_DEF);
|
||||
AddMatchers({
|
||||
create.Keyword("set").Capture(CAPTURE_START),
|
||||
create.Keyword("count"),
|
||||
create.OptionalLoop(create.Char('*').Tag(TAG_POINTER_RESOLVE)),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.OptionalLoop(create.Label(CommandsCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY_INDEX)),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set").Capture(CAPTURE_START),
|
||||
create.Keyword("count"),
|
||||
create.OptionalLoop(create.Char('*').Tag(TAG_POINTER_RESOLVE)),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.OptionalLoop(create.Label(CommandsCommonMatchers::LABEL_ARRAY_DEF).Capture(CAPTURE_ARRAY_INDEX)),
|
||||
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceCount::SetCountByArrayIndex(CommandsParserState* state, SequenceResult<CommandsParserValue>& result, MemberInformation* member, PointerDeclarationModifier* pointer,
|
||||
void SequenceCount::SetCountByArrayIndex(CommandsParserState* state,
|
||||
SequenceResult<CommandsParserValue>& result,
|
||||
MemberInformation* member,
|
||||
PointerDeclarationModifier* pointer,
|
||||
std::unique_ptr<IEvaluation> evaluation)
|
||||
{
|
||||
std::vector<int> arraySizes;
|
||||
@ -33,12 +34,12 @@ void SequenceCount::SetCountByArrayIndex(CommandsParserState* state, SequenceRes
|
||||
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())
|
||||
if (i < arraySizes.size())
|
||||
currentDepthSize *= arraySizes[i];
|
||||
depthSize[i - 1] = currentDepthSize;
|
||||
}
|
||||
|
@ -11,7 +11,10 @@ class SequenceCount final : public CommandsParser::sequence_t
|
||||
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,
|
||||
static void SetCountByArrayIndex(CommandsParserState* state,
|
||||
SequenceResult<CommandsParserValue>& result,
|
||||
MemberInformation* member,
|
||||
PointerDeclarationModifier* pointer,
|
||||
std::unique_ptr<IEvaluation> evaluation);
|
||||
|
||||
protected:
|
||||
|
@ -1,17 +1,13 @@
|
||||
#include "SequenceGame.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceGame::SequenceGame()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("game"),
|
||||
create.Identifier().Capture(CAPTURE_GAME),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("game"), create.Identifier().Capture(CAPTURE_GAME), create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceGame::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,19 +1,14 @@
|
||||
#include "SequenceName.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceName::SequenceName()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("name"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set"), create.Keyword("name"), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceName::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,27 +1,21 @@
|
||||
#include "SequenceReorder.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
SequenceReorder::SequenceReorder()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("reorder").Capture(CAPTURE_START),
|
||||
create.Optional(create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE)),
|
||||
create.Char(':'),
|
||||
create.Optional(create.And({
|
||||
create.Char('.'),
|
||||
create.Char('.'),
|
||||
create.Char('.')
|
||||
}).Tag(TAG_FIND_FIRST)),
|
||||
create.Loop(create.Identifier().Capture(CAPTURE_ENTRY)),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("reorder").Capture(CAPTURE_START),
|
||||
create.Optional(create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE)),
|
||||
create.Char(':'),
|
||||
create.Optional(create.And({create.Char('.'), create.Char('.'), create.Char('.')}).Tag(TAG_FIND_FIRST)),
|
||||
create.Loop(create.Identifier().Capture(CAPTURE_ENTRY)),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
StructureInformation* SequenceReorder::GetType(CommandsParserState* state, SequenceResult<CommandsParserValue>& result)
|
||||
@ -58,7 +52,7 @@ void SequenceReorder::ProcessMatch(CommandsParserState* state, SequenceResult<Co
|
||||
auto findFirst = result.PeekAndRemoveIfTag(TAG_FIND_FIRST) == TAG_FIND_FIRST;
|
||||
|
||||
std::string firstVariableName;
|
||||
if(findFirst)
|
||||
if (findFirst)
|
||||
firstVariableName = result.NextCapture(CAPTURE_ENTRY).IdentifierValue();
|
||||
|
||||
std::vector<std::unique_ptr<MemberInformation>> newMembers;
|
||||
@ -67,15 +61,15 @@ void SequenceReorder::ProcessMatch(CommandsParserState* state, SequenceResult<Co
|
||||
for (auto& oldMember : information->m_ordered_members)
|
||||
oldMembers.emplace_back(std::move(oldMember));
|
||||
|
||||
while(result.HasNextCapture(CAPTURE_ENTRY))
|
||||
while (result.HasNextCapture(CAPTURE_ENTRY))
|
||||
{
|
||||
const auto& entryToken = result.NextCapture(CAPTURE_ENTRY);
|
||||
const auto& nextVariableName = entryToken.IdentifierValue();
|
||||
auto foundEntry = false;
|
||||
|
||||
for(auto i = oldMembers.begin(); i != oldMembers.end(); ++i)
|
||||
for (auto i = oldMembers.begin(); i != oldMembers.end(); ++i)
|
||||
{
|
||||
if(i->get()->m_member->m_name == nextVariableName)
|
||||
if (i->get()->m_member->m_name == nextVariableName)
|
||||
{
|
||||
newMembers.emplace_back(std::move(*i));
|
||||
oldMembers.erase(i);
|
||||
@ -90,7 +84,7 @@ void SequenceReorder::ProcessMatch(CommandsParserState* state, SequenceResult<Co
|
||||
|
||||
information->m_ordered_members.clear();
|
||||
|
||||
while(findFirst && !oldMembers.empty())
|
||||
while (findFirst && !oldMembers.empty())
|
||||
{
|
||||
if (oldMembers.front()->m_member->m_name == firstVariableName)
|
||||
findFirst = false;
|
||||
|
@ -1,19 +1,15 @@
|
||||
#include "SequenceReusable.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceReusable::SequenceReusable()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("reusable"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers(
|
||||
{create.Keyword("set"), create.Keyword("reusable"), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceReusable::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,19 +1,15 @@
|
||||
#include "SequenceScriptString.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceScriptString::SequenceScriptString()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("scriptstring"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers(
|
||||
{create.Keyword("set"), create.Keyword("scriptstring"), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceScriptString::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,25 +1,19 @@
|
||||
#include "SequenceSetBlock.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceSetBlock::SequenceSetBlock()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set").Capture(CAPTURE_START),
|
||||
create.Keyword("block"),
|
||||
create.Or({
|
||||
create.And({
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY)
|
||||
}),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY)
|
||||
}),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("set").Capture(CAPTURE_START),
|
||||
create.Keyword("block"),
|
||||
create.Or({create.And({create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY)}),
|
||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY)}),
|
||||
create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceSetBlock::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -1,22 +1,17 @@
|
||||
#include "SequenceString.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
SequenceString::SequenceString()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("string"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers(
|
||||
{create.Keyword("set"), create.Keyword("string"), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceString::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
@ -40,10 +35,12 @@ void SequenceString::ProcessMatch(CommandsParserState* state, SequenceResult<Com
|
||||
if (!hasPointerRef)
|
||||
{
|
||||
const auto& modifiers = typeDecl->m_declaration_modifiers;
|
||||
hasPointerRef = std::any_of(modifiers.begin(), modifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
hasPointerRef = std::any_of(modifiers.begin(),
|
||||
modifiers.end(),
|
||||
[](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||
|
@ -1,18 +1,14 @@
|
||||
#include "SequenceUse.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
SequenceUse::SequenceUse()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("use"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Char(';')
|
||||
});
|
||||
AddMatchers({create.Keyword("use"), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Char(';')});
|
||||
}
|
||||
|
||||
void SequenceUse::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
|
@ -19,10 +19,7 @@ HeaderBlockType HeaderBlockEnum::GetType()
|
||||
|
||||
const std::vector<IHeaderBlock::sequence_t*>& HeaderBlockEnum::GetTestsForBlock()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceCloseBlock(true),
|
||||
new SequenceEnumMember()
|
||||
});
|
||||
static std::vector<sequence_t*> tests({new SequenceCloseBlock(true), new SequenceEnumMember()});
|
||||
|
||||
return tests;
|
||||
}
|
||||
@ -51,9 +48,7 @@ void HeaderBlockEnum::OnClose(HeaderParserState* state)
|
||||
state->AddDataType(std::make_unique<TypedefDefinition>(m_namespace, m_variable_name, std::make_unique<TypeDeclaration>(m_enum_definition)));
|
||||
}
|
||||
|
||||
void HeaderBlockEnum::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
||||
{
|
||||
}
|
||||
void HeaderBlockEnum::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block) {}
|
||||
|
||||
void HeaderBlockEnum::AddEnumMember(std::unique_ptr<EnumMember> enumMember)
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Domain/Definition/BaseTypeDefinition.h"
|
||||
#include "Domain/Definition/EnumDefinition.h"
|
||||
#include "IHeaderBlock.h"
|
||||
#include "IHeaderBlockNameHolder.h"
|
||||
#include "IHeaderBlockVariableDefining.h"
|
||||
#include "Domain/Definition/BaseTypeDefinition.h"
|
||||
#include "Domain/Definition/EnumDefinition.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
class HeaderBlockEnum final : public IHeaderBlock, public IHeaderBlockNameHolder, public IHeaderBlockVariableDefining
|
||||
{
|
||||
|
@ -20,15 +20,13 @@ HeaderBlockType HeaderBlockNamespace::GetType()
|
||||
|
||||
const std::vector<IHeaderBlock::sequence_t*>& HeaderBlockNamespace::GetTestsForBlock()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceCloseBlock(false),
|
||||
new SequenceEnum(),
|
||||
new SequenceForwardDecl(),
|
||||
new SequenceNamespace(),
|
||||
new SequenceStruct(),
|
||||
new SequenceTypedef(),
|
||||
new SequenceUnion()
|
||||
});
|
||||
static std::vector<sequence_t*> tests({new SequenceCloseBlock(false),
|
||||
new SequenceEnum(),
|
||||
new SequenceForwardDecl(),
|
||||
new SequenceNamespace(),
|
||||
new SequenceStruct(),
|
||||
new SequenceTypedef(),
|
||||
new SequenceUnion()});
|
||||
|
||||
return tests;
|
||||
}
|
||||
@ -43,6 +41,4 @@ void HeaderBlockNamespace::OnClose(HeaderParserState* state)
|
||||
state->m_namespace.Pop();
|
||||
}
|
||||
|
||||
void HeaderBlockNamespace::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
||||
{
|
||||
}
|
||||
void HeaderBlockNamespace::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block) {}
|
||||
|
@ -14,26 +14,14 @@ HeaderBlockType HeaderBlockNone::GetType()
|
||||
|
||||
const std::vector<IHeaderBlock::sequence_t*>& HeaderBlockNone::GetTestsForBlock()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceEnum(),
|
||||
new SequenceForwardDecl(),
|
||||
new SequenceNamespace(),
|
||||
new SequenceStruct(),
|
||||
new SequenceTypedef(),
|
||||
new SequenceUnion()
|
||||
});
|
||||
|
||||
static std::vector<sequence_t*> tests(
|
||||
{new SequenceEnum(), new SequenceForwardDecl(), new SequenceNamespace(), new SequenceStruct(), new SequenceTypedef(), new SequenceUnion()});
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
void HeaderBlockNone::OnOpen(HeaderParserState* state)
|
||||
{
|
||||
}
|
||||
void HeaderBlockNone::OnOpen(HeaderParserState* state) {}
|
||||
|
||||
void HeaderBlockNone::OnClose(HeaderParserState* state)
|
||||
{
|
||||
}
|
||||
void HeaderBlockNone::OnClose(HeaderParserState* state) {}
|
||||
|
||||
void HeaderBlockNone::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
||||
{
|
||||
}
|
||||
void HeaderBlockNone::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block) {}
|
||||
|
@ -24,13 +24,8 @@ HeaderBlockType HeaderBlockStruct::GetType()
|
||||
|
||||
const std::vector<IHeaderBlock::sequence_t*>& HeaderBlockStruct::GetTestsForBlock()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceCloseBlock(true),
|
||||
new SequenceEnum(),
|
||||
new SequenceStruct(),
|
||||
new SequenceUnion(),
|
||||
new SequenceVariable()
|
||||
});
|
||||
static std::vector<sequence_t*> tests(
|
||||
{new SequenceCloseBlock(true), new SequenceEnum(), new SequenceStruct(), new SequenceUnion(), new SequenceVariable()});
|
||||
|
||||
return tests;
|
||||
}
|
||||
@ -66,7 +61,7 @@ void HeaderBlockStruct::OnClose(HeaderParserState* state)
|
||||
for (auto& member : m_members)
|
||||
structDefinition->m_members.emplace_back(std::move(member));
|
||||
|
||||
if(m_has_custom_align)
|
||||
if (m_has_custom_align)
|
||||
{
|
||||
structDefinition->m_alignment_override = static_cast<unsigned>(m_custom_alignment);
|
||||
structDefinition->m_has_alignment_override = true;
|
||||
@ -83,7 +78,8 @@ void HeaderBlockStruct::OnChildBlockClose(HeaderParserState* state, IHeaderBlock
|
||||
auto* variableDefining = dynamic_cast<IHeaderBlockVariableDefining*>(block);
|
||||
|
||||
if (variableDefining && variableDefining->IsDefiningVariable())
|
||||
m_members.emplace_back(std::make_shared<Variable>(variableDefining->GetVariableName(), std::make_unique<TypeDeclaration>(variableDefining->GetVariableType())));
|
||||
m_members.emplace_back(
|
||||
std::make_shared<Variable>(variableDefining->GetVariableName(), std::make_unique<TypeDeclaration>(variableDefining->GetVariableType())));
|
||||
}
|
||||
|
||||
void HeaderBlockStruct::AddVariable(std::shared_ptr<Variable> variable)
|
||||
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Domain/Definition/StructDefinition.h"
|
||||
#include "Domain/Definition/Variable.h"
|
||||
#include "IHeaderBlock.h"
|
||||
#include "IHeaderBlockNameHolder.h"
|
||||
#include "IHeaderBlockVariableDefining.h"
|
||||
#include "IHeaderBlockVariableHolder.h"
|
||||
#include "Domain/Definition/StructDefinition.h"
|
||||
#include "Domain/Definition/Variable.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class HeaderBlockStruct final : public IHeaderBlock, public IHeaderBlockNameHolder, public IHeaderBlockVariableDefining, public IHeaderBlockVariableHolder
|
||||
{
|
||||
|
@ -24,13 +24,8 @@ HeaderBlockType HeaderBlockUnion::GetType()
|
||||
|
||||
const std::vector<IHeaderBlock::sequence_t*>& HeaderBlockUnion::GetTestsForBlock()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceCloseBlock(true),
|
||||
new SequenceEnum(),
|
||||
new SequenceStruct(),
|
||||
new SequenceUnion(),
|
||||
new SequenceVariable()
|
||||
});
|
||||
static std::vector<sequence_t*> tests(
|
||||
{new SequenceCloseBlock(true), new SequenceEnum(), new SequenceStruct(), new SequenceUnion(), new SequenceVariable()});
|
||||
|
||||
return tests;
|
||||
}
|
||||
@ -83,7 +78,8 @@ void HeaderBlockUnion::OnChildBlockClose(HeaderParserState* state, IHeaderBlock*
|
||||
auto* variableDefining = dynamic_cast<IHeaderBlockVariableDefining*>(block);
|
||||
|
||||
if (variableDefining && variableDefining->IsDefiningVariable())
|
||||
m_members.emplace_back(std::make_shared<Variable>(variableDefining->GetVariableName(), std::make_unique<TypeDeclaration>(variableDefining->GetVariableType())));
|
||||
m_members.emplace_back(
|
||||
std::make_shared<Variable>(variableDefining->GetVariableName(), std::make_unique<TypeDeclaration>(variableDefining->GetVariableType())));
|
||||
}
|
||||
|
||||
void HeaderBlockUnion::AddVariable(std::shared_ptr<Variable> variable)
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
void AddVariable(std::shared_ptr<Variable> variable) override;
|
||||
void SetCustomAlignment(int alignment);
|
||||
void Inherit(const StructDefinition* parentStruct);
|
||||
|
||||
|
||||
void SetBlockName(const TokenPos& nameTokenPos, std::string name) override;
|
||||
bool IsDefiningVariable() override;
|
||||
DataDefinition* GetVariableType() override;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
enum class HeaderBlockType
|
||||
{
|
||||
@ -16,6 +16,7 @@ enum class HeaderBlockType
|
||||
|
||||
class HeaderParserValue;
|
||||
class HeaderParserState;
|
||||
|
||||
class IHeaderBlock
|
||||
{
|
||||
public:
|
||||
@ -35,4 +36,4 @@ public:
|
||||
virtual void OnOpen(HeaderParserState* state) = 0;
|
||||
virtual void OnClose(HeaderParserState* state) = 0;
|
||||
virtual void OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block) = 0;
|
||||
};
|
||||
};
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Domain/Definition/DataDefinition.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class IHeaderBlockVariableDefining
|
||||
{
|
||||
public:
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Domain/Definition/Variable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class IHeaderBlockVariableHolder
|
||||
{
|
||||
public:
|
||||
|
@ -1,9 +1,5 @@
|
||||
#include "HeaderFileReader.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#include "Impl/HeaderLexer.h"
|
||||
#include "Impl/HeaderParser.h"
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
@ -15,6 +11,10 @@
|
||||
#include "Parsing/PostProcessing/CreateStructureInformationPostProcessor.h"
|
||||
#include "Parsing/PostProcessing/IPostProcessor.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
HeaderFileReader::HeaderFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
|
||||
: m_args(args),
|
||||
m_filename(std::move(filename)),
|
||||
@ -83,7 +83,7 @@ bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository)
|
||||
result = parser->SaveToRepository(repository);
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
if(m_args->m_verbose)
|
||||
if (m_args->m_verbose)
|
||||
{
|
||||
std::cout << "Processing header took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
|
||||
}
|
||||
@ -91,8 +91,10 @@ bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository)
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
return std::all_of(m_post_processors.begin(), m_post_processors.end(), [repository](const std::unique_ptr<IPostProcessor>& postProcessor)
|
||||
{
|
||||
return postProcessor->PostProcess(repository);
|
||||
});
|
||||
return std::all_of(m_post_processors.begin(),
|
||||
m_post_processors.end(),
|
||||
[repository](const std::unique_ptr<IPostProcessor>& postProcessor)
|
||||
{
|
||||
return postProcessor->PostProcess(repository);
|
||||
});
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ZoneCodeGeneratorArguments.h"
|
||||
#include "Parsing/IPackValueSupplier.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "Parsing/PostProcessing/IPostProcessor.h"
|
||||
#include "Persistence/IDataRepository.h"
|
||||
#include "ZoneCodeGeneratorArguments.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class HeaderFileReader
|
||||
{
|
||||
|
@ -33,136 +33,136 @@ HeaderParserValue HeaderLexer::GetNextToken()
|
||||
switch (c)
|
||||
{
|
||||
case '\"':
|
||||
{
|
||||
return HeaderParserValue::String(GetPreviousCharacterPos(), new std::string(ReadString()));
|
||||
}
|
||||
{
|
||||
return HeaderParserValue::String(GetPreviousCharacterPos(), new std::string(ReadString()));
|
||||
}
|
||||
|
||||
case '<':
|
||||
{
|
||||
if (!IsLineEnd())
|
||||
{
|
||||
if (!IsLineEnd())
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
const auto nextChar = PeekChar();
|
||||
|
||||
if (nextChar == '=')
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
const auto nextChar = PeekChar();
|
||||
|
||||
if (nextChar == '=')
|
||||
{
|
||||
NextChar();
|
||||
return HeaderParserValue::LessEqual(pos);
|
||||
}
|
||||
if (nextChar == '<')
|
||||
{
|
||||
NextChar();
|
||||
return HeaderParserValue::ShiftLeft(pos);
|
||||
}
|
||||
NextChar();
|
||||
return HeaderParserValue::LessEqual(pos);
|
||||
}
|
||||
if (nextChar == '<')
|
||||
{
|
||||
NextChar();
|
||||
return HeaderParserValue::ShiftLeft(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '>':
|
||||
{
|
||||
if (!IsLineEnd())
|
||||
{
|
||||
if (!IsLineEnd())
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
const auto nextChar = PeekChar();
|
||||
|
||||
if (nextChar == '=')
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
const auto nextChar = PeekChar();
|
||||
|
||||
if (nextChar == '=')
|
||||
{
|
||||
NextChar();
|
||||
return HeaderParserValue::GreaterEqual(pos);
|
||||
}
|
||||
if (nextChar == '>')
|
||||
{
|
||||
NextChar();
|
||||
return HeaderParserValue::ShiftRight(pos);
|
||||
}
|
||||
NextChar();
|
||||
return HeaderParserValue::GreaterEqual(pos);
|
||||
}
|
||||
if (nextChar == '>')
|
||||
{
|
||||
NextChar();
|
||||
return HeaderParserValue::ShiftRight(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '=':
|
||||
{
|
||||
if (NextCharInLineIs('='))
|
||||
{
|
||||
if (NextCharInLineIs('='))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::Equals(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::Equals(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '&':
|
||||
{
|
||||
if (NextCharInLineIs('&'))
|
||||
{
|
||||
if (NextCharInLineIs('&'))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::LogicalAnd(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::LogicalAnd(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '|':
|
||||
{
|
||||
if (NextCharInLineIs('|'))
|
||||
{
|
||||
if (NextCharInLineIs('|'))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::LogicalOr(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::LogicalOr(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '!':
|
||||
{
|
||||
if (NextCharInLineIs('='))
|
||||
{
|
||||
if (NextCharInLineIs('='))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::NotEqual(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return HeaderParserValue::NotEqual(pos);
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (isspace(c))
|
||||
break;
|
||||
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
if (isdigit(c))
|
||||
{
|
||||
if (isspace(c))
|
||||
break;
|
||||
bool isFloatingPointValue;
|
||||
bool hasSignPrefix;
|
||||
double doubleValue;
|
||||
int integerValue;
|
||||
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
if(isdigit(c))
|
||||
{
|
||||
bool isFloatingPointValue;
|
||||
bool hasSignPrefix;
|
||||
double doubleValue;
|
||||
int integerValue;
|
||||
ReadNumber(isFloatingPointValue, hasSignPrefix, doubleValue, integerValue);
|
||||
|
||||
ReadNumber(isFloatingPointValue, hasSignPrefix, doubleValue, integerValue);
|
||||
if (isFloatingPointValue)
|
||||
return HeaderParserValue::FloatingPoint(pos, doubleValue);
|
||||
|
||||
if (isFloatingPointValue)
|
||||
return HeaderParserValue::FloatingPoint(pos, doubleValue);
|
||||
|
||||
return HeaderParserValue::Integer(pos, integerValue);
|
||||
}
|
||||
|
||||
if (isalpha(c) || c == '_')
|
||||
{
|
||||
auto identifier = ReadIdentifier();
|
||||
|
||||
const auto foundKeyword = m_keywords.find(identifier);
|
||||
if (foundKeyword != m_keywords.end())
|
||||
return HeaderParserValue::Keyword(pos, foundKeyword->second);
|
||||
|
||||
return HeaderParserValue::Identifier(pos, new std::string(std::move(identifier)));
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(pos, static_cast<char>(c));
|
||||
return HeaderParserValue::Integer(pos, integerValue);
|
||||
}
|
||||
|
||||
if (isalpha(c) || c == '_')
|
||||
{
|
||||
auto identifier = ReadIdentifier();
|
||||
|
||||
const auto foundKeyword = m_keywords.find(identifier);
|
||||
if (foundKeyword != m_keywords.end())
|
||||
return HeaderParserValue::Keyword(pos, foundKeyword->second);
|
||||
|
||||
return HeaderParserValue::Identifier(pos, new std::string(std::move(identifier)));
|
||||
}
|
||||
|
||||
return HeaderParserValue::Character(pos, static_cast<char>(c));
|
||||
}
|
||||
}
|
||||
|
||||
c = NextChar();
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "HeaderParserValue.h"
|
||||
#include "Parsing/Impl/AbstractLexer.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
class HeaderLexer final : public AbstractLexer<HeaderParserValue>
|
||||
{
|
||||
std::unordered_map<std::string, HeaderParserValueType> m_keywords;
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include "HeaderParserState.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "Domain/Definition/EnumDefinition.h"
|
||||
#include "Parsing/Header/Block/HeaderBlockNone.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
HeaderParserState::HeaderParserState(const IPackValueSupplier* packValueSupplier)
|
||||
: m_pack_value_supplier(packValueSupplier)
|
||||
|
||||
@ -198,7 +197,5 @@ bool HeaderParserState::MoveDefinitionsToRepository(IDataRepository* repository)
|
||||
|
||||
bool HeaderParserState::SaveToRepository(IDataRepository* repository)
|
||||
{
|
||||
return ResolveForwardDeclarations()
|
||||
&& ReplaceForwardDeclarationsInDefinitions()
|
||||
&& MoveDefinitionsToRepository(repository);
|
||||
return ResolveForwardDeclarations() && ReplaceForwardDeclarationsInDefinitions() && MoveDefinitionsToRepository(repository);
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Domain/Definition/BaseTypeDefinition.h"
|
||||
#include "Domain/Definition/DataDefinition.h"
|
||||
#include "Domain/Definition/EnumMember.h"
|
||||
#include "Domain/Definition/ForwardDeclaration.h"
|
||||
#include "Parsing/IPackValueSupplier.h"
|
||||
#include "Utils/NamespaceBuilder.h"
|
||||
#include "Parsing/Header/Block/IHeaderBlock.h"
|
||||
#include "Parsing/IPackValueSupplier.h"
|
||||
#include "Persistence/IDataRepository.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/NamespaceBuilder.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
|
||||
class IHeaderBlock;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Parsing/IParserValue.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/TokenPos.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class HeaderParserValueType
|
||||
{
|
||||
@ -63,6 +63,7 @@ class HeaderParserValue final : public IParserValue
|
||||
public:
|
||||
TokenPos m_pos;
|
||||
HeaderParserValueType m_type;
|
||||
|
||||
union ValueType
|
||||
{
|
||||
char char_value;
|
||||
@ -108,4 +109,4 @@ public:
|
||||
_NODISCARD std::string& StringValue() const;
|
||||
_NODISCARD std::string& IdentifierValue() const;
|
||||
_NODISCARD std::string& TypeNameValue() const;
|
||||
};
|
||||
};
|
||||
|
@ -1,117 +1,92 @@
|
||||
#include "HeaderCommonMatchers.h"
|
||||
|
||||
#include "HeaderMatcherFactory.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
#include "HeaderMatcherFactory.h"
|
||||
|
||||
std::unique_ptr<HeaderCommonMatchers::matcher_t> HeaderCommonMatchers::Align(const supplier_t* labelSupplier)
|
||||
{
|
||||
const HeaderMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.Or({
|
||||
create.And({
|
||||
create.Type(HeaderParserValueType::DECLSPEC),
|
||||
create.Char('('),
|
||||
create.Type(HeaderParserValueType::ALIGN),
|
||||
create.Char('('),
|
||||
create.Integer(),
|
||||
create.Char(')'),
|
||||
create.Char(')')
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return HeaderParserValue::Integer(values[4].get().GetPos(), values[4].get().IntegerValue());
|
||||
}),
|
||||
create.And({
|
||||
create.Type(HeaderParserValueType::ALIGNAS),
|
||||
create.Char('('),
|
||||
create.Integer(),
|
||||
create.Char(')')
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return HeaderParserValue::Integer(values[2].get().GetPos(), values[2].get().IntegerValue());
|
||||
})
|
||||
});
|
||||
return create.Or({create
|
||||
.And({create.Type(HeaderParserValueType::DECLSPEC),
|
||||
create.Char('('),
|
||||
create.Type(HeaderParserValueType::ALIGN),
|
||||
create.Char('('),
|
||||
create.Integer(),
|
||||
create.Char(')'),
|
||||
create.Char(')')})
|
||||
.Transform(
|
||||
[](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return HeaderParserValue::Integer(values[4].get().GetPos(), values[4].get().IntegerValue());
|
||||
}),
|
||||
create.And({create.Type(HeaderParserValueType::ALIGNAS), create.Char('('), create.Integer(), create.Char(')')})
|
||||
.Transform(
|
||||
[](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
return HeaderParserValue::Integer(values[2].get().GetPos(), values[2].get().IntegerValue());
|
||||
})});
|
||||
}
|
||||
|
||||
std::unique_ptr<HeaderCommonMatchers::matcher_t> HeaderCommonMatchers::ArrayDef(const supplier_t* labelSupplier)
|
||||
{
|
||||
const HeaderMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Char('['),
|
||||
create.Or({
|
||||
create.Integer(),
|
||||
create.Identifier()
|
||||
}),
|
||||
create.Char(']')
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
if (values[1].get().m_type == HeaderParserValueType::INTEGER)
|
||||
return HeaderParserValue::Integer(values[1].get().GetPos(), values[1].get().IntegerValue());
|
||||
return create.And({create.Char('['), create.Or({create.Integer(), create.Identifier()}), create.Char(']')})
|
||||
.Transform(
|
||||
[](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
if (values[1].get().m_type == HeaderParserValueType::INTEGER)
|
||||
return HeaderParserValue::Integer(values[1].get().GetPos(), values[1].get().IntegerValue());
|
||||
|
||||
return HeaderParserValue::Identifier(values[1].get().GetPos(), new std::string(values[1].get().IdentifierValue()));
|
||||
});
|
||||
return HeaderParserValue::Identifier(values[1].get().GetPos(), new std::string(values[1].get().IdentifierValue()));
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<HeaderCommonMatchers::matcher_t> HeaderCommonMatchers::Typename(const supplier_t* labelSupplier)
|
||||
{
|
||||
static constexpr const char* BUILT_IN_TYPE_NAMES[]
|
||||
{
|
||||
"unsigned",
|
||||
"char",
|
||||
"short",
|
||||
"int",
|
||||
"long"
|
||||
};
|
||||
static_assert(std::extent<decltype(BUILT_IN_TYPE_NAMES)>::value == static_cast<int>(HeaderParserValueType::BUILT_IN_LAST) - static_cast<int>(HeaderParserValueType::BUILT_IN_FIRST) + 1);
|
||||
static constexpr const char* BUILT_IN_TYPE_NAMES[]{"unsigned", "char", "short", "int", "long"};
|
||||
static_assert(std::extent<decltype(BUILT_IN_TYPE_NAMES)>::value
|
||||
== static_cast<int>(HeaderParserValueType::BUILT_IN_LAST) - static_cast<int>(HeaderParserValueType::BUILT_IN_FIRST) + 1);
|
||||
|
||||
const HeaderMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.Or({
|
||||
create.And({
|
||||
create.Optional(create.Type(HeaderParserValueType::UNSIGNED)),
|
||||
create.Or({
|
||||
create.Type(HeaderParserValueType::CHAR),
|
||||
create.Type(HeaderParserValueType::SHORT),
|
||||
create.Type(HeaderParserValueType::INT),
|
||||
create.And({
|
||||
create.Type(HeaderParserValueType::LONG),
|
||||
create.Optional(create.Type(HeaderParserValueType::LONG))
|
||||
})
|
||||
})
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
auto first = true;
|
||||
return create.Or(
|
||||
{create
|
||||
.And({create.Optional(create.Type(HeaderParserValueType::UNSIGNED)),
|
||||
create.Or({create.Type(HeaderParserValueType::CHAR),
|
||||
create.Type(HeaderParserValueType::SHORT),
|
||||
create.Type(HeaderParserValueType::INT),
|
||||
create.And({create.Type(HeaderParserValueType::LONG), create.Optional(create.Type(HeaderParserValueType::LONG))})})})
|
||||
.Transform(
|
||||
[](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
auto first = true;
|
||||
|
||||
for (const auto& token : values)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
str << " ";
|
||||
str << BUILT_IN_TYPE_NAMES[static_cast<int>(token.get().m_type) - static_cast<int>(HeaderParserValueType::BUILT_IN_FIRST)];
|
||||
}
|
||||
for (const auto& token : values)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
str << " ";
|
||||
str << BUILT_IN_TYPE_NAMES[static_cast<int>(token.get().m_type) - static_cast<int>(HeaderParserValueType::BUILT_IN_FIRST)];
|
||||
}
|
||||
|
||||
return HeaderParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
}),
|
||||
create.And({
|
||||
create.Identifier(),
|
||||
create.OptionalLoop(create.And({
|
||||
create.Char(':'),
|
||||
create.Char(':'),
|
||||
create.Identifier()
|
||||
}))
|
||||
}).Transform([](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << values[0].get().IdentifierValue();
|
||||
return HeaderParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
}),
|
||||
create.And({create.Identifier(), create.OptionalLoop(create.And({create.Char(':'), create.Char(':'), create.Identifier()}))})
|
||||
.Transform(
|
||||
[](HeaderMatcherFactory::token_list_t& values)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << values[0].get().IdentifierValue();
|
||||
|
||||
for (auto i = 3u; i < values.size(); i += 3)
|
||||
str << "::" << values[i].get().IdentifierValue();
|
||||
for (auto i = 3u; i < values.size(); i += 3)
|
||||
str << "::" << values[i].get().IdentifierValue();
|
||||
|
||||
return HeaderParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
})
|
||||
});
|
||||
return HeaderParserValue::TypeName(values[0].get().GetPos(), new std::string(str.str()));
|
||||
})});
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
#include "Parsing/Matcher/MatcherLabel.h"
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
class HeaderCommonMatchers
|
||||
{
|
||||
public:
|
||||
|
@ -8,7 +8,6 @@ HeaderMatcherCharacter::HeaderMatcherCharacter(const char c)
|
||||
MatcherResult<HeaderParserValue> HeaderMatcherCharacter::CanMatch(ILexer<HeaderParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
return token.m_type == HeaderParserValueType::CHARACTER && token.CharacterValue() == m_char
|
||||
? MatcherResult<HeaderParserValue>::Match(1)
|
||||
: MatcherResult<HeaderParserValue>::NoMatch();
|
||||
return token.m_type == HeaderParserValueType::CHARACTER && token.CharacterValue() == m_char ? MatcherResult<HeaderParserValue>::Match(1)
|
||||
: MatcherResult<HeaderParserValue>::NoMatch();
|
||||
}
|
||||
|
@ -7,7 +7,5 @@ HeaderMatcherValueType::HeaderMatcherValueType(HeaderParserValueType type)
|
||||
|
||||
MatcherResult<HeaderParserValue> HeaderMatcherValueType::CanMatch(ILexer<HeaderParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
return lexer->GetToken(tokenOffset).m_type == m_type
|
||||
? MatcherResult<HeaderParserValue>::Match(1)
|
||||
: MatcherResult<HeaderParserValue>::NoMatch();
|
||||
return lexer->GetToken(tokenOffset).m_type == m_type ? MatcherResult<HeaderParserValue>::Match(1) : MatcherResult<HeaderParserValue>::NoMatch();
|
||||
}
|
||||
|
@ -1,21 +1,16 @@
|
||||
#include "SequenceCloseBlock.h"
|
||||
|
||||
#include "Parsing/Header/Block/IHeaderBlockNameHolder.h"
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
|
||||
SequenceCloseBlock::SequenceCloseBlock(const bool semicolonRequired)
|
||||
: m_semicolon_required(semicolonRequired)
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Char('}').Capture(CAPTURE_CLOSING_PARENTHESIS),
|
||||
create.Optional(create.And({
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Char(';').Tag(TAG_SEMICOLON)
|
||||
}))
|
||||
});
|
||||
AddMatchers({create.Char('}').Capture(CAPTURE_CLOSING_PARENTHESIS),
|
||||
create.Optional(create.And({create.Optional(create.Identifier().Capture(CAPTURE_NAME)), create.Char(';').Tag(TAG_SEMICOLON)}))});
|
||||
}
|
||||
|
||||
void SequenceCloseBlock::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
|
||||
class SequenceCloseBlock final : public HeaderParser::sequence_t
|
||||
{
|
||||
|
@ -1,24 +1,19 @@
|
||||
#include "SequenceEnum.h"
|
||||
|
||||
#include "Parsing/Header/Block/HeaderBlockEnum.h"
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
|
||||
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
|
||||
|
||||
SequenceEnum::SequenceEnum()
|
||||
{
|
||||
const HeaderMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(HeaderCommonMatchers::Typename(this), HeaderCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Optional(create.Type(HeaderParserValueType::TYPEDEF).Tag(TAG_TYPEDEF)),
|
||||
create.Type(HeaderParserValueType::ENUM),
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Optional(create.And({
|
||||
create.Char(':'),
|
||||
create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_PARENT_TYPE)
|
||||
})),
|
||||
create.Char('{')
|
||||
});
|
||||
AddMatchers({create.Optional(create.Type(HeaderParserValueType::TYPEDEF).Tag(TAG_TYPEDEF)),
|
||||
create.Type(HeaderParserValueType::ENUM),
|
||||
create.Optional(create.Identifier().Capture(CAPTURE_NAME)),
|
||||
create.Optional(create.And({create.Char(':'), create.Label(HeaderCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_PARENT_TYPE)})),
|
||||
create.Char('{')});
|
||||
}
|
||||
|
||||
void SequenceEnum::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
|
||||
@ -30,7 +25,7 @@ void SequenceEnum::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderP
|
||||
if (result.HasNextCapture(CAPTURE_NAME))
|
||||
name = result.NextCapture(CAPTURE_NAME).IdentifierValue();
|
||||
|
||||
if(result.HasNextCapture(CAPTURE_PARENT_TYPE))
|
||||
if (result.HasNextCapture(CAPTURE_PARENT_TYPE))
|
||||
{
|
||||
const auto& typeNameToken = result.NextCapture(CAPTURE_PARENT_TYPE);
|
||||
const auto* foundTypeDefinition = state->FindType(typeNameToken.TypeNameValue());
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Header/Impl/HeaderParser.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserState.h"
|
||||
#include "Parsing/Header/Impl/HeaderParserValue.h"
|
||||
#include "Parsing/Sequence/AbstractSequence.h"
|
||||
|
||||
class SequenceEnum final : public HeaderParser::sequence_t
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user