diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.cpp index b6b1becf..9b8b39d1 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.cpp @@ -2,6 +2,8 @@ #include + +#include "Domain/Computations/MemberComputations.h" #include "Domain/Definition/ArrayDeclarationModifier.h" BaseTemplate::BaseTemplate(std::ostream& stream, RenderingContext* context) @@ -33,75 +35,111 @@ std::string BaseTemplate::Lower(std::string str) return str; } -std::string BaseTemplate::TypeVarName(const DataDefinition* def) +void BaseTemplate::MakeSafeTypeNameInternal(const DataDefinition* def, std::ostringstream& str) { - std::ostringstream str; - str << "var" << SafeTypeName(def); - return str.str(); -} - -std::string BaseTemplate::TypePtrVarName(const DataDefinition* def) -{ - std::ostringstream str; - str << "var" << SafeTypeName(def) << "Ptr"; - return str.str(); -} - -std::string BaseTemplate::SafeTypeName(const DataDefinition* def) -{ - auto safeName(def->m_name); - - for (auto& c : safeName) + for (const auto& c : def->m_name) { if (isspace(c)) - c = '_'; + str << "_"; + else + str << c; } - - return safeName; } -void BaseTemplate::PrintAccessMember(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const +void BaseTemplate::MakeTypeVarNameInternal(const DataDefinition* def, std::ostringstream& str) { - LINE_MIDDLE(TypeVarName(info->m_definition) << "->" << member->m_member->m_name) - PrintArrayIndices(modifier); + str << "var"; + MakeSafeTypeNameInternal(def, str); } -void BaseTemplate::PrintTypeDecl(const TypeDeclaration* decl) const +void BaseTemplate::MakeTypePtrVarNameInternal(const DataDefinition* def, std::ostringstream& str) { + str << "var"; + MakeSafeTypeNameInternal(def, str); + str << "Ptr"; +} + +void BaseTemplate::MakeArrayIndicesInternal(const DeclarationModifierComputations& modifierComputations, std::ostringstream& str) +{ + for (auto index : modifierComputations.GetArrayIndices()) + { + str << "[" << index << "]"; + } +} + +std::string BaseTemplate::MakeTypeVarName(const DataDefinition* def) +{ + std::ostringstream str; + MakeTypeVarNameInternal(def, str); + return str.str(); +} + +std::string BaseTemplate::MakeTypePtrVarName(const DataDefinition* def) +{ + std::ostringstream str; + MakeTypePtrVarNameInternal(def, str); + return str.str(); +} + +std::string BaseTemplate::MakeSafeTypeName(const DataDefinition* def) +{ + std::ostringstream str; + MakeSafeTypeNameInternal(def, str); + return str.str(); +} + +std::string BaseTemplate::MakeMemberAccess(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) +{ + std::ostringstream str; + MakeTypeVarNameInternal(info->m_definition, str); + str << "->" << member->m_member->m_name; + MakeArrayIndicesInternal(modifier, str); + + return str.str(); +} + +std::string BaseTemplate::MakeTypeDecl(const TypeDeclaration* decl) +{ + std::ostringstream str; if (decl->m_is_const) { - LINE_MIDDLE("const ") + str << "const "; } - LINE_MIDDLE(decl->m_type->GetFullName()) + + str << decl->m_type->GetFullName(); + return str.str(); } -void BaseTemplate::PrintFollowingReferences(const std::vector& modifiers) const +std::string BaseTemplate::MakeFollowingReferences(const std::vector& modifiers) { + std::ostringstream str; for (const auto* modifier : modifiers) { if (modifier->GetType() == DeclarationModifierType::ARRAY) { const auto* array = dynamic_cast(modifier); - LINE_MIDDLE("["<< array->m_size <<"]") + str << "[" << array->m_size << "]"; } else { - LINE_MIDDLE("*") + str << "*"; } } + + return str.str(); } -void BaseTemplate::PrintArrayIndices(const DeclarationModifierComputations& modifierComputations) const +std::string BaseTemplate::MakeArrayIndices(const DeclarationModifierComputations& modifierComputations) { - for (auto index : modifierComputations.GetArrayIndices()) - { - LINE_MIDDLE("["<m_action_name << "(") + std::ostringstream str; + str << "m_actions." << action->m_action_name << "("; auto first = true; for (auto* def : action->m_parameter_types) @@ -112,82 +150,104 @@ void BaseTemplate::PrintCustomAction(CustomAction* action) const } else { - LINE_MIDDLE(", ") + str << ", "; } - LINE_MIDDLE(TypeVarName(def)) + MakeTypeVarNameInternal(def, str); } - LINE_END(");") + str << ");"; + return str.str(); } -void BaseTemplate::PrintOperandStatic(const OperandStatic* op) const +std::string BaseTemplate::MakeArrayCount(const ArrayDeclarationModifier* arrayModifier) +{ + if(arrayModifier->m_dynamic_count_evaluation) + { + return MakeEvaluation(arrayModifier->m_dynamic_count_evaluation.get()); + } + + return std::to_string(arrayModifier->m_size); +} + +void BaseTemplate::MakeOperandStatic(const OperandStatic* op, std::ostringstream& str) { if (op->m_enum_member != nullptr) { - LINE_MIDDLE(op->m_enum_member->m_name) + str << op->m_enum_member->m_name; } else { - LINE_MIDDLE(op->m_value) + str << op->m_value; } } -void BaseTemplate::PrintOperandDynamic(const OperandDynamic* op) const +void BaseTemplate::MakeOperandDynamic(const OperandDynamic* op, std::ostringstream& str) { - LINE_MIDDLE(TypeVarName(op->m_structure->m_definition)) + MakeTypeVarNameInternal(op->m_structure->m_definition, str); - auto first = true; - for (const auto* chainMember : op->m_referenced_member_chain) + if(!op->m_referenced_member_chain.empty()) { - if (first) + str << "->"; + const auto lastEntry = op->m_referenced_member_chain.end() - 1; + for(auto i = op->m_referenced_member_chain.begin(); i != lastEntry; ++i) { - first = false; - LINE_MIDDLE("->"<< chainMember->m_member->m_name) - } - else - { - LINE_MIDDLE("." << chainMember->m_member->m_name) + MemberComputations computations(*i); + str << (*i)->m_member->m_name; + + if (computations.ContainsNonEmbeddedReference()) + str << "->"; + else + str << "."; } + + str << (*lastEntry)->m_member->m_name; } for (const auto& arrayIndex : op->m_array_indices) { - LINE_MIDDLE("[") - PrintEvaluation(arrayIndex.get()); - LINE_MIDDLE("]") + str << "["; + MakeEvaluationInternal(arrayIndex.get(), str); + str << "]"; } } -void BaseTemplate::PrintOperation(const Operation* operation) const +void BaseTemplate::MakeOperation(const Operation* operation, std::ostringstream& str) { if (operation->Operand1NeedsParenthesis()) { - LINE_MIDDLE("(") - PrintEvaluation(operation->m_operand1.get()); - LINE_MIDDLE(")") + str << "("; + MakeEvaluationInternal(operation->m_operand1.get(), str); + str << ")"; } else - PrintEvaluation(operation->m_operand1.get()); + MakeEvaluationInternal(operation->m_operand1.get(), str); - LINE_MIDDLE(" "<m_operation_type->m_syntax<<" ") + str << " " << operation->m_operation_type->m_syntax << " "; if (operation->Operand2NeedsParenthesis()) { - LINE_MIDDLE("(") - PrintEvaluation(operation->m_operand2.get()); - LINE_MIDDLE(")") + str << "("; + MakeEvaluationInternal(operation->m_operand2.get(), str); + str << ")"; } else - PrintEvaluation(operation->m_operand2.get()); + MakeEvaluationInternal(operation->m_operand2.get(), str); } -void BaseTemplate::PrintEvaluation(const IEvaluation* evaluation) const +void BaseTemplate::MakeEvaluationInternal(const IEvaluation* evaluation, std::ostringstream& str) { if (evaluation->GetType() == EvaluationType::OPERATION) - PrintOperation(dynamic_cast(evaluation)); + MakeOperation(dynamic_cast(evaluation), str); else if (evaluation->GetType() == EvaluationType::OPERAND_STATIC) - PrintOperandStatic(dynamic_cast(evaluation)); + MakeOperandStatic(dynamic_cast(evaluation), str); else if (evaluation->GetType() == EvaluationType::OPERAND_DYNAMIC) - PrintOperandDynamic(dynamic_cast(evaluation)); + MakeOperandDynamic(dynamic_cast(evaluation), str); +} + +std::string BaseTemplate::MakeEvaluation(const IEvaluation* evaluation) +{ + std::ostringstream str; + MakeEvaluationInternal(evaluation, str); + return str.str(); } diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.h b/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.h index 227ecfe4..194c2d49 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.h +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/Internal/BaseTemplate.h @@ -1,8 +1,10 @@ #pragma once #include +#include #include "Domain/Computations/MemberDeclarationModifierComputations.h" +#include "Domain/Definition/ArrayDeclarationModifier.h" #include "Domain/Evaluation/OperandDynamic.h" #include "Domain/Evaluation/OperandStatic.h" #include "Domain/Evaluation/Operation.h" @@ -21,22 +23,29 @@ protected: void DoIntendation() const; +private: + static void MakeSafeTypeNameInternal(const DataDefinition* def, std::ostringstream& str); + static void MakeTypeVarNameInternal(const DataDefinition* def, std::ostringstream& str); + static void MakeTypePtrVarNameInternal(const DataDefinition* def, std::ostringstream& str); + static void MakeArrayIndicesInternal(const DeclarationModifierComputations& modifierComputations, std::ostringstream& str); + static void MakeOperandStatic(const OperandStatic* op, std::ostringstream& str); + static void MakeOperandDynamic(const OperandDynamic* op, std::ostringstream& str); + static void MakeOperation(const Operation* operation, std::ostringstream& str); + static void MakeEvaluationInternal(const IEvaluation* evaluation, std::ostringstream& str); + +protected: static std::string Upper(std::string str); static std::string Lower(std::string str); - static std::string TypeVarName(const DataDefinition* def); - static std::string TypePtrVarName(const DataDefinition* def); - static std::string SafeTypeName(const DataDefinition* def); - void PrintAccessMember(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const; - void PrintTypeDecl(const TypeDeclaration* decl) const; - void PrintFollowingReferences(const std::vector& modifiers) const; - void PrintArrayIndices(const DeclarationModifierComputations& modifierComputations) const; - - void PrintCustomAction(CustomAction* action) const; - - void PrintOperandStatic(const OperandStatic* op) const; - void PrintOperandDynamic(const OperandDynamic* op) const; - void PrintOperation(const Operation* operation) const; - void PrintEvaluation(const IEvaluation* evaluation) const; + static std::string MakeTypeVarName(const DataDefinition* def); + static std::string MakeTypePtrVarName(const DataDefinition* def); + static std::string MakeSafeTypeName(const DataDefinition* def); + static std::string MakeMemberAccess(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier); + static std::string MakeTypeDecl(const TypeDeclaration* decl); + static std::string MakeFollowingReferences(const std::vector& modifiers); + static std::string MakeArrayIndices(const DeclarationModifierComputations& modifierComputations); + static std::string MakeCustomActionCall(CustomAction* action); + static std::string MakeArrayCount(const ArrayDeclarationModifier* arrayModifier); + static std::string MakeEvaluation(const IEvaluation* evaluation); }; #define LINE(x) {DoIntendation(); m_out << x << "\n";} diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index 859a4480..32a27146 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -1,15 +1,26 @@ #include "ZoneLoadTemplate.h" + +#include #include #include - #include "Domain/Computations/MemberComputations.h" #include "Domain/Computations/StructureComputations.h" #include "Internal/BaseTemplate.h" class ZoneLoadTemplate::Internal final : BaseTemplate { + enum class MemberLoadType + { + ARRAY_POINTER, + DYNAMIC_ARRAY, + EMBEDDED, + EMBEDDED_ARRAY, + POINTER_ARRAY, + SINGLE_POINTER + }; + static std::string LoaderClassName(StructureInformation* asset) { std::ostringstream str; @@ -20,40 +31,40 @@ class ZoneLoadTemplate::Internal final : BaseTemplate static std::string VariableDecl(const DataDefinition* def) { std::ostringstream str; - str << def->GetFullName() << "* var" << SafeTypeName(def) << ";"; + str << def->GetFullName() << "* var" << MakeSafeTypeName(def) << ";"; return str.str(); } static std::string PointerVariableDecl(const DataDefinition* def) { std::ostringstream str; - str << def->GetFullName() << "** var" << SafeTypeName(def) << "Ptr;"; + str << def->GetFullName() << "** var" << MakeSafeTypeName(def) << "Ptr;"; return str.str(); } void PrintHeaderPtrArrayLoadMethodDeclaration(const DataDefinition* def) const { - LINE("void LoadPtrArray_"<m_definition)<<"(bool atStreamStart);") + LINE("void Load_"<< MakeSafeTypeName(info->m_definition)<<"(bool atStreamStart);") } void PrintHeaderTempPtrLoadMethodDeclaration(const StructureInformation* info) const { - LINE("void LoadPtr_"<m_definition)<<"(bool atStreamStart);") + LINE("void LoadPtr_"<< MakeSafeTypeName(info->m_definition)<<"(bool atStreamStart);") } void PrintHeaderAssetLoadMethodDeclaration(const StructureInformation* info) const { - LINE("void LoadAsset_"<m_definition)<<"("<m_definition->GetFullName()<<"** pAsset);") + LINE("void LoadAsset_"<< MakeSafeTypeName(info->m_definition)<<"("<m_definition->GetFullName()<<"** pAsset);") } void PrintHeaderGetNameMethodDeclaration(const StructureInformation* info) const @@ -123,35 +134,35 @@ class ZoneLoadTemplate::Internal final : BaseTemplate void PrintLoadPtrArrayMethod_Loading(const DataDefinition* def, StructureInformation* info) const { - LINE("*"<Alloc<"<GetFullName()<<">(alignof("<GetFullName()<<")); // "<GetAlignment()) + LINE("*"<< MakeTypePtrVarName(def)<<" = m_stream->Alloc<"<GetFullName()<<">(alignof("<GetFullName()<<")); // "<GetAlignment()) if (info && info->m_is_leaf) { - LINE(TypeVarName(info->m_definition)<<" = *"<m_definition)<<" = *"<< MakeTypePtrVarName(def)<<";") + LINE("Load_"<< MakeSafeTypeName(def)<<"(true);") } else { - LINE("m_stream->Load<"<GetFullName()<<">(*"<Load<"<GetFullName()<<">(*"<< MakeTypePtrVarName(def)<<");") } } void PrintLoadPtrArrayMethod_PointerCheck(const DataDefinition* def, StructureInformation* info, const bool reusable) { - LINE("if (*" << TypePtrVarName(def) << ")") + LINE("if (*" << MakeTypePtrVarName(def) << ")") LINE("{") m_intendation++; if (info && StructureComputations(info).IsAsset()) { LINE(LoaderClassName(info)<<" loader(m_zone, m_stream);") - LINE("AddDependency(loader.Load("<ConvertOffsetToPointer(*"<ConvertOffsetToPointer(*"<< MakeTypePtrVarName(def)<<");") m_intendation--; LINE("}") @@ -180,25 +191,25 @@ class ZoneLoadTemplate::Internal final : BaseTemplate void PrintLoadPtrArrayMethod(const DataDefinition* def, StructureInformation* info, const bool reusable) { - LINE("void "<Load<"<GetFullName()<<"*>("<Load<"<GetFullName()<<"*>("<< MakeTypePtrVarName(def)<<", count);") m_intendation--; LINE("") - LINE(def->GetFullName() << "** var = " << TypePtrVarName(def) << ";") + LINE(def->GetFullName() << "** var = " << MakeTypePtrVarName(def) << ";") LINE("for(size_t index = 0; index < count; index++)") LINE("{") m_intendation++; - LINE(TypePtrVarName(def) << " = var;") + LINE(MakeTypePtrVarName(def) << " = var;") PrintLoadPtrArrayMethod_PointerCheck(def, info, reusable); LINE("") LINE("var++;") @@ -211,19 +222,19 @@ class ZoneLoadTemplate::Internal final : BaseTemplate void PrintLoadArrayMethod(const DataDefinition* def, StructureInformation* info) { - LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadArray_" << SafeTypeName(def) << "(const bool atStreamStart, const size_t count)") + LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadArray_" << MakeSafeTypeName(def) << "(const bool atStreamStart, const size_t count)") LINE("{") m_intendation++; - LINE("assert(" << TypeVarName(def) << " != nullptr);") + LINE("assert(" << MakeTypeVarName(def) << " != nullptr);") LINE("") LINE("if(atStreamStart)") m_intendation++; - LINE("m_stream->Load<"<GetFullName()<<">("<Load<"<GetFullName()<<">("<GetFullName() << "* var = " << TypeVarName(def) << ";") + LINE(def->GetFullName() << "* var = " << MakeTypeVarName(def) << ";") LINE("for(size_t index = 0; index < count; index++)") LINE("{") m_intendation++; @@ -236,7 +247,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate { LINE(TypeVarName(info->m_definition) << " = var;") }*/ - LINE(TypeVarName(info->m_definition) << " = var;") + LINE(MakeTypeVarName(info->m_definition) << " = var;") LINE("Load_"<m_definition->m_name<<"(false);") LINE("var++;") @@ -249,199 +260,182 @@ class ZoneLoadTemplate::Internal final : BaseTemplate void LoadDynamicArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const { - if (member->m_type && !member->m_type->m_is_leaf) - { - LINE_START(TypeVarName(member->m_member->m_type_declaration->m_type) << " = " << TypeVarName(info->m_definition) << "->" << member->m_member->m_name) - PrintArrayIndices(modifier); - LINE_END(";") - LINE_START("LoadArray_" << SafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, ") - PrintEvaluation(modifier.GetDynamicArraySizeEvaluation()); - LINE_END(");") - } - else - { - LINE_START("m_stream->Load<") - PrintTypeDecl(member->m_member->m_type_declaration.get()); - PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); - LINE_MIDDLE(">(" << TypeVarName(info->m_definition) << "->" << member->m_member->m_name) - PrintArrayIndices(modifier); - LINE_MIDDLE(", ") - PrintEvaluation(modifier.GetDynamicArraySizeEvaluation()); - LINE_END(");") - } + // if (member->m_type && !member->m_type->m_is_leaf) + // { + // LINE_START(TypeVarName(member->m_member->m_type_declaration->m_type) << " = " << TypeVarName(info->m_definition) << "->" << member->m_member->m_name) + // PrintArrayIndices(modifier); + // LINE_END(";") + // LINE_START("LoadArray_" << SafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, ") + // PrintEvaluation(modifier.GetDynamicArraySizeEvaluation()); + // LINE_END(");") + // } + // else + // { + // LINE_START("m_stream->Load<") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_MIDDLE(">(" << TypeVarName(info->m_definition) << "->" << member->m_member->m_name) + // PrintArrayIndices(modifier); + // LINE_MIDDLE(", ") + // PrintEvaluation(modifier.GetDynamicArraySizeEvaluation()); + // LINE_END(");") + // } } void LoadSinglePointer_Inner(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) { - const MemberComputations computations(member); - if (computations.IsInTempBlock()) - { - LINE_START(member->m_member->m_type_declaration->m_type->GetFullName()<<"* ptr = ") - PrintAccessMember(info, member, modifier); - LINE_END(";") - } - - LINE_START("") - PrintAccessMember(info, member, modifier); - LINE_MIDDLE(" = m_stream->Alloc<") - PrintTypeDecl(member->m_member->m_type_declaration.get()); - PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); - LINE_MIDDLE(">(alignof(") - PrintTypeDecl(member->m_member->m_type_declaration.get()); - PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); - LINE_END(")); // "<m_member->m_type_declaration->m_type->GetAlignment()) - - if (computations.IsInTempBlock()) - { - LINE("") - LINE(member->m_member->m_type_declaration->m_type->GetFullName() << "** toInsert = nullptr;") - LINE("if(ptr == PTR_INSERT)") - m_intendation++; - LINE("toInsert = m_stream->InsertPointer<"<m_member->m_type_declaration->m_type->GetFullName()<<">();") - m_intendation--; - LINE("") - } - - if (member->m_type && !member->m_type->m_is_leaf && !computations.IsInRuntimeBlock()) - { - LINE_START(TypeVarName(member->m_member->m_type_declaration->m_type) << " = ") - PrintAccessMember(info, member, modifier); - LINE_END(";") - LINE("Load_"<m_member->m_type_declaration->m_type)<<"(true);") - - if (member->m_type->m_post_load_action) - { - PrintCustomAction(member->m_type->m_post_load_action.get()); - } - } - else - { - LINE_START("m_stream->Load<") - PrintTypeDecl(member->m_member->m_type_declaration.get()); - PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); - LINE_MIDDLE(">(") - PrintAccessMember(info, member, modifier); - LINE_END(");") - } - - if (computations.IsInTempBlock()) - { - LINE("") - LINE("if(toInsert != nullptr)") - m_intendation++; - LINE("*toInsert = "<m_definition)<<"->"<m_member->m_name<<";") - m_intendation--; - } + // const MemberComputations computations(member); + // if (computations.IsInTempBlock()) + // { + // LINE_START(member->m_member->m_type_declaration->m_type->GetFullName()<<"* ptr = ") + // PrintAccessMember(info, member, modifier); + // LINE_END(";") + // } + // + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->Alloc<") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_MIDDLE(">(alignof(") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_END(")); // "<m_member->m_type_declaration->m_type->GetAlignment()) + // + // if (computations.IsInTempBlock()) + // { + // LINE("") + // LINE(member->m_member->m_type_declaration->m_type->GetFullName() << "** toInsert = nullptr;") + // LINE("if(ptr == PTR_INSERT)") + // m_intendation++; + // LINE("toInsert = m_stream->InsertPointer<"<m_member->m_type_declaration->m_type->GetFullName()<<">();") + // m_intendation--; + // LINE("") + // } + // + // if (member->m_type && !member->m_type->m_is_leaf && !computations.IsInRuntimeBlock()) + // { + // LINE_START(TypeVarName(member->m_member->m_type_declaration->m_type) << " = ") + // PrintAccessMember(info, member, modifier); + // LINE_END(";") + // LINE("Load_"<m_member->m_type_declaration->m_type)<<"(true);") + // + // if (member->m_type->m_post_load_action) + // { + // PrintCustomAction(member->m_type->m_post_load_action.get()); + // } + // } + // else + // { + // LINE_START("m_stream->Load<") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_MIDDLE(">(") + // PrintAccessMember(info, member, modifier); + // LINE_END(");") + // } + // + // if (computations.IsInTempBlock()) + // { + // LINE("") + // LINE("if(toInsert != nullptr)") + // m_intendation++; + // LINE("*toInsert = "<m_definition)<<"->"<m_member->m_name<<";") + // m_intendation--; + // } } void LoadSinglePointer_Reuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) { - const MemberComputations computations(member); - if (computations.IsInTempBlock()) - { - LINE_START("if(") - PrintAccessMember(info, member, modifier); - LINE_MIDDLE(" == PTR_FOLLOWING || ") - PrintAccessMember(info, member, modifier); - LINE_END(" == PTR_INSERT)") - LINE("{") - m_intendation++; - - LoadSinglePointer_Inner(info, member, modifier); - - m_intendation--; - LINE("}") - LINE("else") - LINE("{") - m_intendation++; - - LINE_START("") - PrintAccessMember(info, member, modifier); - LINE_MIDDLE(" = m_stream->ConvertOffsetToAlias(") - PrintAccessMember(info, member, modifier); - LINE_END(");") - - m_intendation--; - LINE("}") - } - else - { - LINE_START("if(") - PrintAccessMember(info, member, modifier); - LINE_END(" == PTR_FOLLOWING)") - LINE("{") - m_intendation++; - - LoadSinglePointer_Inner(info, member, modifier); - - m_intendation--; - LINE("}") - LINE("else") - LINE("{") - m_intendation++; - - LINE_START("") - PrintAccessMember(info, member, modifier); - LINE_MIDDLE(" = m_stream->ConvertOffsetToPointer(") - PrintAccessMember(info, member, modifier); - LINE_END(");") - - m_intendation--; - LINE("}") - } + // const MemberComputations computations(member); + // if (computations.IsInTempBlock()) + // { + // LINE_START("if(") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" == PTR_FOLLOWING || ") + // PrintAccessMember(info, member, modifier); + // LINE_END(" == PTR_INSERT)") + // LINE("{") + // m_intendation++; + // + // LoadSinglePointer_Inner(info, member, modifier); + // + // m_intendation--; + // LINE("}") + // LINE("else") + // LINE("{") + // m_intendation++; + // + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->ConvertOffsetToAlias(") + // PrintAccessMember(info, member, modifier); + // LINE_END(");") + // + // m_intendation--; + // LINE("}") + // } + // else + // { + // LINE_START("if(") + // PrintAccessMember(info, member, modifier); + // LINE_END(" == PTR_FOLLOWING)") + // LINE("{") + // m_intendation++; + // + // LoadSinglePointer_Inner(info, member, modifier); + // + // m_intendation--; + // LINE("}") + // LINE("else") + // LINE("{") + // m_intendation++; + // + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->ConvertOffsetToPointer(") + // PrintAccessMember(info, member, modifier); + // LINE_END(");") + // + // m_intendation--; + // LINE("}") + // } } void LoadSinglePointer_Asset(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const { - LINE(LoaderClassName(member->m_type) << " loader(m_zone, m_stream);") - LINE_START("AddDependency(loader.Load(&" << TypeVarName(info->m_definition) << "->" << member->m_member->m_name) - PrintArrayIndices(modifier); - LINE_END("));") + // LINE(LoaderClassName(member->m_type) << " loader(m_zone, m_stream);") + // LINE_START("AddDependency(loader.Load(&" << TypeVarName(info->m_definition) << "->" << member->m_member->m_name) + // PrintArrayIndices(modifier); + // LINE_END("));") } void LoadSinglePointer_PointerCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) { - LINE_START("if (") - PrintAccessMember(info, member, modifier); - LINE_END(")") - LINE("{") - m_intendation++; - - if (member->m_type && StructureComputations(member->m_type).IsAsset()) - { - LoadSinglePointer_Asset(info, member, modifier); - } - else - { - if (member->m_is_reusable) - { - LoadSinglePointer_Reuse(info, member, modifier); - } - else - { - LoadSinglePointer_Inner(info, member, modifier); - } - } - - m_intendation--; - LINE("}") - } - - void LoadSinglePointer_String(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const - { - if (member->m_member->m_type_declaration->m_is_const) - { - LINE_START("varXString = &") - PrintAccessMember(info, member, modifier); - LINE_END(";") - } - else - { - LINE_START("varXString = const_cast(&") - PrintAccessMember(info, member, modifier); - LINE_END(");") - } - LINE("LoadXString(false);") + // LINE_START("if (") + // PrintAccessMember(info, member, modifier); + // LINE_END(")") + // LINE("{") + // m_intendation++; + // + // if (member->m_type && StructureComputations(member->m_type).IsAsset()) + // { + // LoadSinglePointer_Asset(info, member, modifier); + // } + // else + // { + // if (member->m_is_reusable) + // { + // LoadSinglePointer_Reuse(info, member, modifier); + // } + // else + // { + // LoadSinglePointer_Inner(info, member, modifier); + // } + // } + // + // m_intendation--; + // LINE("}") } void LoadSinglePointer(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) @@ -453,18 +447,18 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("m_stream->PushBlock("<m_fast_file_block->m_name<<");") } - if (member->m_is_string) - { - LoadSinglePointer_String(info, member, modifier); - } - else if (member->m_is_script_string) - { - LINE("#error Scriptstring "<m_member->m_name) - } - else - { - LoadSinglePointer_PointerCheck(info, member, modifier); - } + // if (member->m_is_string) + // { + // LoadSinglePointer_String(info, member, modifier); + // } + // else if (member->m_is_script_string) + // { + // LINE("#error Scriptstring "<m_member->m_name) + // } + // else + // { + // LoadSinglePointer_PointerCheck(info, member, modifier); + // } if (computations.IsNotInDefaultNormalBlock()) { @@ -472,56 +466,607 @@ class ZoneLoadTemplate::Internal final : BaseTemplate } } - void LoadArrayPointer(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + void LoadArrayPointer_Loading(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) { - LINE("// LoadArrayPointer: " << member->m_member->m_name) + // const MemberComputations computations(member); + // if (computations.IsInTempBlock()) + // { + // LINE_START(member->m_member->m_type_declaration->m_type->GetFullName() << "* ptr = ") + // PrintAccessMember(info, member, modifier); + // LINE_END(";") + // } + // + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->Alloc<") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_MIDDLE(">(alignof(") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_END(")); // " << member->m_member->m_type_declaration->m_type->GetAlignment()) + // + // if (computations.IsInTempBlock()) + // { + // LINE("") + // 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() << ">();") + // m_intendation--; + // LINE("") + // } + // + // if (member->m_type && !member->m_type->m_is_leaf && !computations.IsInRuntimeBlock()) + // { + // LINE_START(TypeVarName(member->m_member->m_type_declaration->m_type) << " = ") + // PrintAccessMember(info, member, modifier); + // LINE_END(";") + // LINE_START("LoadArray_" << SafeTypeName(member->m_member->m_type_declaration->m_type) << "(true, ") + // PrintEvaluation(computations.GetArrayPointerCountEvaluation()); + // LINE_END(");") + // + // if (member->m_type->m_post_load_action) + // { + // PrintCustomAction(member->m_type->m_post_load_action.get()); + // } + // } + // else + // { + // LINE_START("m_stream->Load<") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_MIDDLE(">(") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(", ") + // PrintEvaluation(modifier.GetArrayPointerCountEvaluation()); + // LINE_END(");") + // } + // + // if (computations.IsInTempBlock()) + // { + // LINE("") + // LINE("if(toInsert != nullptr)") + // m_intendation++; + // LINE("*toInsert = " << TypeVarName(info->m_definition) << "->" << member->m_member->m_name << ";") + // m_intendation--; + // } } - void LoadPointerArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + void LoadArrayPointer_ScriptString(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const + { + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->Alloc<") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_MIDDLE(">(alignof(") + // PrintTypeDecl(member->m_member->m_type_declaration.get()); + // PrintFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + // LINE_END(")); // " << member->m_member->m_type_declaration->m_type->GetAlignment()) + // + // LINE_START("varScriptString = ") + // PrintAccessMember(info, member, modifier); + // LINE_END(";") + // LINE_START("LoadScriptStringArray(true, ") + // PrintEvaluation(modifier.GetArrayPointerCountEvaluation()); + // LINE_END(");") + } + + void LoadArrayPointer_TypeCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + { + if (member->m_is_script_string) + { + LoadArrayPointer_ScriptString(info, member, modifier); + } + else + { + LoadArrayPointer_Loading(info, member, modifier); + } + } + + void LoadArrayPointer_Reuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + { + // const MemberComputations computations(member); + // if (computations.IsInTempBlock()) + // { + // LINE_START("if(") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" == PTR_FOLLOWING || ") + // PrintAccessMember(info, member, modifier); + // LINE_END(" == PTR_INSERT)") + // LINE("{") + // m_intendation++; + // + // LoadArrayPointer_TypeCheck(info, member, modifier); + // + // m_intendation--; + // LINE("}") + // LINE("else") + // LINE("{") + // m_intendation++; + // + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->ConvertOffsetToAlias(") + // PrintAccessMember(info, member, modifier); + // LINE_END(");") + // + // m_intendation--; + // LINE("}") + // } + // else + // { + // LINE_START("if(") + // PrintAccessMember(info, member, modifier); + // LINE_END(" == PTR_FOLLOWING)") + // LINE("{") + // m_intendation++; + // + // LoadArrayPointer_TypeCheck(info, member, modifier); + // + // m_intendation--; + // LINE("}") + // LINE("else") + // LINE("{") + // m_intendation++; + // + // LINE_START("") + // PrintAccessMember(info, member, modifier); + // LINE_MIDDLE(" = m_stream->ConvertOffsetToPointer(") + // PrintAccessMember(info, member, modifier); + // LINE_END(");") + // + // m_intendation--; + // LINE("}") + // } + } + + void LoadMember_ScriptString(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const + { + if (loadType == MemberLoadType::ARRAY_POINTER) + { + const auto typeDecl = MakeTypeDecl(member->m_member->m_type_declaration.get()); + const auto followingReferences = MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + LINE(MakeMemberAccess(info, member, modifier) << " = m_stream->Alloc<" << typeDecl << followingReferences << ">(alignof(" << typeDecl << followingReferences + << ")); // " << member->m_member->m_type_declaration->m_type->GetAlignment()) + } + + if (loadType == MemberLoadType::ARRAY_POINTER) + { + LINE("varScriptString = " << MakeMemberAccess(info, member, modifier) << ";") + LINE("LoadScriptStringArray(true, " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");") + } + else if (loadType == MemberLoadType::EMBEDDED_ARRAY) + { + LINE("varScriptString = " << MakeMemberAccess(info, member, modifier) << ";") + LINE("LoadScriptStringArray(false, " << MakeArrayCount(dynamic_cast(modifier.GetDeclarationModifier())) << ");") + } + else if (loadType == MemberLoadType::EMBEDDED) + { + LINE(MakeMemberAccess(info, member, modifier) << " = UseScriptString(" << MakeMemberAccess(info, member, modifier) << ";") + } + else + { + assert(false); + LINE("#error unsupported loadType " << static_cast(loadType) << " for scripstring") + } + } + + 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(&"<(loadType) << " for asset") + } + } + + void LoadMember_String(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const + { + if (loadType == MemberLoadType::SINGLE_POINTER) + { + if (member->m_member->m_type_declaration->m_is_const) + { + LINE("varXString = &" << MakeMemberAccess(info, member, modifier) << ";") + } + else + { + LINE("varXString = const_cast(&" << MakeMemberAccess(info, member, modifier) << ");") + } + LINE("LoadXString(false);") + } + else if (loadType == MemberLoadType::POINTER_ARRAY) + { + LINE("varXString = " << MakeMemberAccess(info, member, modifier) << ";") + if (modifier.IsArray()) + { + LINE("LoadXStringArray(false, "<(loadType)<<" for string") + } + } + + void LoadMember_ArrayPointer(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const + { + const MemberComputations computations(member); + 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(computations.GetArrayPointerCountEvaluation()) << ");") + + if (member->m_type->m_post_load_action) + { + LINE(MakeCustomActionCall(member->m_type->m_post_load_action.get())) + } + } + else + { + LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) + << ">(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");") + } + } + + void LoadMember_PointerArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const { LINE("// LoadPointerArray: " << member->m_member->m_name) } - void LoadEmbeddedArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + void LoadMember_EmbeddedArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const { LINE("// LoadEmbeddedArray: " << member->m_member->m_name) } - void LoadEmbedded(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + void LoadMember_DynamicArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const + { + LINE("// LoadDynamicArray: " << member->m_member->m_name) + } + + void LoadMember_Embedded(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const { LINE("// LoadEmbedded: " << member->m_member->m_name) } + void LoadMember_SinglePointer(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) const + { + const MemberComputations computations(member); + 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("Load_" << MakeSafeTypeName(member->m_member->m_type_declaration->m_type) << "(true);") + + if (member->m_type->m_post_load_action) + { + LINE(MakeCustomActionCall(member->m_type->m_post_load_action.get())) + } + } + else + { + LINE("m_stream->Load<" << MakeTypeDecl(member->m_member->m_type_declaration.get()) << MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()) + << ">(" << MakeMemberAccess(info, member, modifier) << ", " << MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");") + } + } + + void LoadMember_TypeCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) const + { + if (member->m_is_string) + { + LoadMember_String(info, member, modifier, loadType); + } + else if (member->m_is_script_string) + { + LoadMember_ScriptString(info, member, modifier, loadType); + } + else if (member->m_type && StructureComputations(member->m_type).IsAsset()) + { + LoadMember_Asset(info, member, modifier, loadType); + } + else + { + switch (loadType) + { + case MemberLoadType::ARRAY_POINTER: + LoadMember_ArrayPointer(info, member, modifier); + break; + + case MemberLoadType::SINGLE_POINTER: + LoadMember_SinglePointer(info, member, modifier); + break; + + case MemberLoadType::EMBEDDED: + LoadMember_Embedded(info, member, modifier); + break; + + case MemberLoadType::POINTER_ARRAY: + LoadMember_PointerArray(info, member, modifier); + break; + + case MemberLoadType::DYNAMIC_ARRAY: + LoadMember_DynamicArray(info, member, modifier); + break; + + case MemberLoadType::EMBEDDED_ARRAY: + LoadMember_EmbeddedArray(info, member, modifier); + break; + + default: + LINE("// t=" << static_cast(loadType)) + break; + } + } + } + + 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) + { + return false; + } + + if (member->m_is_string) + { + return loadType == MemberLoadType::POINTER_ARRAY && !modifier.IsArray(); + } + + if (member->m_type && StructureComputations(member->m_type).IsAsset()) + { + return false; + } + + return true; + } + + void LoadMember_Alloc(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) + { + if (!LoadMember_ShouldMakeAlloc(info, member, modifier, loadType)) + { + LoadMember_TypeCheck(info, member, modifier, loadType); + return; + } + + const MemberComputations computations(member); + if (computations.IsInTempBlock()) + { + LINE(member->m_member->m_type_declaration->m_type->GetFullName()<< "* ptr = "<m_member->m_type_declaration.get()); + const auto followingReferences = MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()); + LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<(alignof("<m_member->m_type_declaration->m_type->GetAlignment()) + + if (computations.IsInTempBlock()) + { + LINE("") + LINE(member->m_member->m_type_declaration->m_type->GetFullName() << "** toInsert = nullptr;") + LINE("if(ptr == PTR_INSERT)") + m_intendation++; + LINE("toInsert = m_stream->InsertPointer<"<m_member->m_type_declaration->m_type->GetFullName() << ">();") + m_intendation--; + LINE("") + } + + LoadMember_TypeCheck(info, member, modifier, loadType); + + if (computations.IsInTempBlock()) + { + LINE("") + LINE("if(toInsert != nullptr)") + m_intendation++; + LINE("*toInsert = "<m_definition)<<"->"<m_member->m_name<<";") + m_intendation--; + } + } + + static bool LoadMember_ShouldMakeReuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) + { + return loadType == MemberLoadType::ARRAY_POINTER + || loadType == MemberLoadType::SINGLE_POINTER + || loadType == MemberLoadType::POINTER_ARRAY; + } + + void LoadMember_Reuse(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) + { + if (!LoadMember_ShouldMakeReuse(info, member, modifier, loadType) + || !member->m_is_reusable) + { + LoadMember_Alloc(info, member, modifier, loadType); + return; + } + + const MemberComputations computations(member); + if (computations.IsInTempBlock()) + { + LINE("if("<ConvertOffsetToAlias(" << MakeMemberAccess(info, member, modifier) << ");") + + m_intendation--; + LINE("}") + } + else + { + LINE("if("<ConvertOffsetToPointer("<m_is_string) + return false; + + return true; + } + + void LoadMember_PointerCheck(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType) + { + if (LoadMember_ShouldMakePointerCheck(info, member, modifier, loadType)) + { + LINE("if (" << MakeMemberAccess(info, member, modifier) << ")") + LINE("{") + m_intendation++; + + LoadMember_Reuse(info, member, modifier, loadType); + + m_intendation--; + LINE("}") + } + else + { + LoadMember_Reuse(info, member, modifier, loadType); + } + } + + void LoadMember_Block(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier, MemberLoadType loadType) + { + const MemberComputations computations(member); + + const auto notInDefaultNormalBlock = computations.IsNotInDefaultNormalBlock(); + if (notInDefaultNormalBlock) + { + LINE("m_stream->PushBlock(" << member->m_fast_file_block->m_name << ");") + } + + LoadMember_PointerCheck(info, member, modifier, loadType); + + if (notInDefaultNormalBlock) + { + LINE("m_stream->PopBlock();") + } + } + + void LoadArrayPointer(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) + { + const MemberComputations computations(member); + + if (computations.IsNotInDefaultNormalBlock()) + { + LINE("m_stream->PushBlock(" << member->m_fast_file_block->m_name << ");") + } + + LINE("if ("<m_is_reusable) + { + LoadArrayPointer_Reuse(info, member, modifier); + } + else + { + LoadArrayPointer_TypeCheck(info, member, modifier); + } + + m_intendation--; + LINE("}") + + if (computations.IsNotInDefaultNormalBlock()) + { + LINE("m_stream->PopBlock();") + } + } + void LoadMember_ReferenceArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) { - LINE("// LoadMember_ReferenceArray: " << member->m_member->m_name) + auto first = true; + for (const auto& entry : modifier.GetArrayEntries()) + { + if (first) + { + first = false; + } + else + { + LINE("") + } + + LoadMember_Reference(info, member, entry); + } } void LoadMember_Reference(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier) { if (modifier.IsDynamicArray()) { - LoadDynamicArray(info, member, modifier); + LoadMember_Block(info, member, modifier, MemberLoadType::DYNAMIC_ARRAY); + // LoadDynamicArray(info, member, modifier); } else if (modifier.IsSinglePointer()) { - LoadSinglePointer(info, member, modifier); + LoadMember_Block(info, member, modifier, MemberLoadType::SINGLE_POINTER); + // LoadSinglePointer(info, member, modifier); } else if (modifier.IsArrayPointer()) { - LoadArrayPointer(info, member, modifier); + LoadMember_Block(info, member, modifier, MemberLoadType::ARRAY_POINTER); + //LoadArrayPointer(info, member, modifier); } else if (modifier.IsPointerArray()) { - LoadPointerArray(info, member, modifier); + LoadMember_Block(info, member, modifier, MemberLoadType::POINTER_ARRAY); + // LoadPointerArray(info, member, modifier); } else if (modifier.IsArray() && modifier.GetNextDeclarationModifier() == nullptr) { - LoadEmbeddedArray(info, member, modifier); + LoadMember_Block(info, member, modifier, MemberLoadType::EMBEDDED_ARRAY); + // LoadEmbeddedArray(info, member, modifier); } else if (modifier.GetDeclarationModifier() == nullptr) { - LoadEmbedded(info, member, modifier); + LoadMember_Block(info, member, modifier, MemberLoadType::EMBEDDED); + // LoadEmbedded(info, member, modifier); } else if (modifier.IsArray()) { @@ -538,9 +1083,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("") if (member->m_condition) { - LINE_START("if(") - PrintEvaluation(member->m_condition.get()); - LINE_END(")") + LINE("if("<m_condition.get())<<")") LINE("{") m_intendation++; @@ -564,9 +1107,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("") if (member->m_condition) { - LINE_START("if(") - PrintEvaluation(member->m_condition.get()); - LINE_END(")") + LINE("if("<m_condition.get())<<")") LINE("{") m_intendation++; @@ -584,9 +1125,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate { if (member->m_condition) { - LINE_START("else if(") - PrintEvaluation(member->m_condition.get()); - LINE_END(")") + LINE("else if("<m_condition.get())<<")") LINE("{") m_intendation++; @@ -611,9 +1150,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate { if (member->m_condition) { - LINE_START("else if(") - PrintEvaluation(member->m_condition.get()); - LINE_END(")") + LINE("else if("<m_condition.get())<<")") LINE("{") m_intendation++; @@ -655,7 +1192,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("{") m_intendation++; - LINE("assert(" << TypeVarName(info->m_definition) << " != nullptr);") + LINE("assert(" <m_definition) << " != nullptr);") auto* dynamicMember = computations.GetDynamicMember(); if (!(info->m_definition->GetType() == DataDefinitionType::UNION && dynamicMember)) @@ -666,11 +1203,11 @@ class ZoneLoadTemplate::Internal final : BaseTemplate if (dynamicMember == nullptr) { - LINE("m_stream->Load<"<m_definition->GetFullName()<<">("<m_definition)<<"); // Size: "<m_definition->GetSize()) + LINE("m_stream->Load<"<m_definition->GetFullName()<<">("<m_definition)<<"); // Size: "<m_definition->GetSize()) } else { - LINE("m_stream->LoadPartial<"<m_definition->GetFullName()<<">("<m_definition)<<", offsetof("<m_definition->GetFullName() + LINE("m_stream->LoadPartial<"<m_definition->GetFullName()<<">("<m_definition)<<", offsetof("<m_definition->GetFullName() <<", "<m_member->m_name<<"));") } @@ -709,31 +1246,31 @@ class ZoneLoadTemplate::Internal final : BaseTemplate void PrintLoadTempPtrMethod(StructureInformation* info) { - LINE("void "<m_definition)<<"(const bool atStreamStart)") + LINE("void "<m_definition)<<"(const bool atStreamStart)") LINE("{") m_intendation++; - LINE("assert("<m_definition)<<" != nullptr);") + LINE("assert("<m_definition)<<" != nullptr);") LINE("") LINE("if(atStreamStart)") m_intendation++; - LINE("m_stream->Load<"<m_definition->GetFullName()<<"*>("<m_definition)<<");") + LINE("m_stream->Load<"<m_definition->GetFullName()<<"*>("<< MakeTypePtrVarName(info->m_definition)<<");") m_intendation--; LINE("") LINE("m_stream->PushBlock("<m_name<<");") LINE("") - LINE("if(*"<m_definition)<<" != nullptr)") + LINE("if(*"<< MakeTypePtrVarName(info->m_definition)<<" != nullptr)") LINE("{") m_intendation++; - LINE("if(*" << TypePtrVarName(info->m_definition) << " == PTR_FOLLOWING || *" << TypePtrVarName(info->m_definition) << " == PTR_INSERT)") + LINE("if(*" << MakeTypePtrVarName(info->m_definition) << " == PTR_FOLLOWING || *" << MakeTypePtrVarName(info->m_definition) << " == PTR_INSERT)") LINE("{") m_intendation++; - LINE(info->m_definition->GetFullName() << "* ptr = *" << TypePtrVarName(info->m_definition) << ";") - LINE("*" << TypePtrVarName(info->m_definition) << " = m_stream->Alloc<" << info->m_definition->GetFullName() << ">(alignof(" << info->m_definition->GetFullName() << "));") + LINE(info->m_definition->GetFullName() << "* ptr = *" << MakeTypePtrVarName(info->m_definition) << ";") + LINE("*" << MakeTypePtrVarName(info->m_definition) << " = m_stream->Alloc<" << info->m_definition->GetFullName() << ">(alignof(" << info->m_definition->GetFullName() << "));") LINE("") LINE(info->m_definition->GetFullName() << "** toInsert = nullptr;") LINE("if(ptr == PTR_INSERT)") @@ -750,8 +1287,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate startLoadSection = false; LINE("") } - LINE(TypeVarName(info->m_definition)<<" = *"<m_definition)<<";") - LINE("Load_"<m_definition)<<"(true);") + LINE(MakeTypeVarName(info->m_definition)<<" = *"<< MakeTypePtrVarName(info->m_definition)<<";") + LINE("Load_"<m_definition)<<"(true);") } if (info->m_post_load_action) @@ -761,17 +1298,13 @@ class ZoneLoadTemplate::Internal final : BaseTemplate startLoadSection = false; LINE("") } - PrintCustomAction(info->m_post_load_action.get()); + LINE(MakeCustomActionCall(info->m_post_load_action.get())) } if (StructureComputations(info).IsAsset()) { - if (startLoadSection) - { - startLoadSection = false; - LINE("") - } - LINE("LoadAsset_"<m_definition)<<"("<m_definition)<<");") + LINE("") + LINE("LoadAsset_"<m_definition)<<"("<m_definition)<<");") } if (!startLoadSection) @@ -781,7 +1314,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("if(toInsert != nullptr)") m_intendation++; - LINE("*toInsert = *"<m_definition)<<";") + LINE("*toInsert = *"<m_definition)<<";") m_intendation--; m_intendation--; @@ -790,7 +1323,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("{") m_intendation++; - LINE("*"<m_definition)<<" = m_stream->ConvertOffsetToAlias(*"<m_definition)<<");") + LINE("*"<m_definition)<<" = m_stream->ConvertOffsetToAlias(*"<m_definition)<<");") m_intendation--; LINE("}") @@ -807,7 +1340,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate void PrintLoadAssetMethod(StructureInformation* info) { - LINE("void " << LoaderClassName(m_env.m_asset) << "::LoadAsset_" << SafeTypeName(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++; @@ -829,8 +1362,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate LINE("") LINE("m_asset_info = nullptr;") LINE("") - LINE(TypePtrVarName(m_env.m_asset->m_definition) << " = pAsset;") - LINE("LoadPtr_" << SafeTypeName(m_env.m_asset->m_definition) << "(false);") + LINE(MakeTypePtrVarName(m_env.m_asset->m_definition) << " = pAsset;") + LINE("LoadPtr_" << MakeSafeTypeName(m_env.m_asset->m_definition) << "(false);") LINE("") LINE("if(m_asset_info == nullptr && *pAsset != nullptr)") m_intendation++; @@ -922,14 +1455,14 @@ public: { if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset()) { - LINE(VariableDecl(type->m_type)); + LINE(VariableDecl(type->m_type)) } } for (auto* type : m_env.m_used_types) { if (type->m_pointer_array_reference_exists && !type->m_is_context_asset) { - LINE(PointerVariableDecl(type->m_type)); + LINE(PointerVariableDecl(type->m_type)) } }