From 2eefad105ec4648709850adae36b86ab8643f131 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Mon, 28 Apr 2025 09:36:56 +0200 Subject: [PATCH 1/5] chore: small code adjustments for generation code in zcg --- .../Generating/CodeGenerator.cpp | 23 +++++++++---------- .../Generating/CodeGenerator.h | 1 - .../Generating/ICodeTemplate.h | 6 ++--- .../Generating/Templates/ZoneLoadTemplate.cpp | 4 ++-- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp index a501e99c..b1ca0f86 100644 --- a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp @@ -7,6 +7,7 @@ #include "Templates/ZoneWriteTemplate.h" #include +#include #include #include @@ -41,7 +42,7 @@ bool CodeGenerator::GenerateCodeForTemplate(RenderingContext* context, ICodeTemp if (!stream.is_open()) { - std::cout << "Failed to open file '" << p.string() << "'\n"; + std::cerr << std::format("Failed to open file '{}'\n", p.string()); return false; } @@ -58,7 +59,7 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str auto* def = repository->GetDataDefinitionByName(name); if (def == nullptr) { - std::cout << "Could not find type with name '" << name << "'\n"; + std::cerr << std::format("Could not find type with name '{}'\n", name); return false; } @@ -66,13 +67,13 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str auto* info = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr; if (info == nullptr) { - std::cout << "Could not find type with name '" << name << "'\n"; + std::cerr << std::format("Could not find type with name '{}'\n", name); return false; } if (!StructureComputations(info).IsAsset()) { - std::cout << "Type is not an asset '" << name << "'\n"; + std::cerr << std::format("Type is not an asset '{}'\n", name); return false; } @@ -100,7 +101,7 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository) const auto foundTemplate = m_template_mapping.find(templateName); if (foundTemplate == m_template_mapping.end()) { - std::cout << "Unknown template '" << generationTask.m_template_name << "'.\n"; + std::cerr << std::format("Unknown template '{}'.\n", generationTask.m_template_name); return false; } @@ -111,13 +112,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::cerr << std::format( + "Failed to generate code for asset '{}' with preset '{}'\n", asset->m_definition->GetFullName(), foundTemplate->first); return false; } - std::cout << "Successfully generated code for asset '" << asset->m_definition->GetFullName() << "' with preset '" << foundTemplate->first - << "'\n"; + std::cout << std::format( + "Successfully generated code for asset '{}' with preset '{}'\n", asset->m_definition->GetFullName(), foundTemplate->first); } } else @@ -133,9 +134,7 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository) } const auto end = std::chrono::steady_clock::now(); if (m_args->m_verbose) - { - std::cout << "Generating code took " << std::chrono::duration_cast(end - start).count() << "ms\n"; - } + std::cout << std::format("Generating code took {}ms\n", std::chrono::duration_cast(end - start).count()); return true; } diff --git a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.h b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.h index 8c24f10f..b05bd382 100644 --- a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.h +++ b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.h @@ -21,6 +21,5 @@ private: static bool GetAssetWithName(IDataRepository* repository, const std::string& name, StructureInformation*& asset); const ZoneCodeGeneratorArguments* m_args; - std::unordered_map> m_template_mapping; }; diff --git a/src/ZoneCodeGeneratorLib/Generating/ICodeTemplate.h b/src/ZoneCodeGeneratorLib/Generating/ICodeTemplate.h index a9c449af..833d9900 100644 --- a/src/ZoneCodeGeneratorLib/Generating/ICodeTemplate.h +++ b/src/ZoneCodeGeneratorLib/Generating/ICodeTemplate.h @@ -9,14 +9,14 @@ class CodeTemplateFile { public: - std::string m_file_name; - int m_tag; - CodeTemplateFile(std::string fileName, const int tag) : m_file_name(std::move(fileName)), m_tag(tag) { } + + std::string m_file_name; + int m_tag; }; class ICodeTemplate diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index d088da67..6493a0cd 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -3,6 +3,7 @@ #include "Domain/Computations/MemberComputations.h" #include "Domain/Computations/StructureComputations.h" #include "Internal/BaseTemplate.h" +#include "Utils/StringUtils.h" #include #include @@ -1349,8 +1350,7 @@ std::vector ZoneLoadTemplate::GetFilesToRender(RenderingContex std::vector files; auto assetName = context->m_asset->m_definition->m_name; - for (auto& c : assetName) - c = static_cast(tolower(c)); + utils::MakeStringLowerCase(assetName); files.emplace_back(std::format("{0}/{0}_load_db.h", assetName), TAG_HEADER); files.emplace_back(std::format("{0}/{0}_load_db.cpp", assetName), TAG_SOURCE); From d938f9154175764f6e1d44749435daa57a438bdf Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Mon, 28 Apr 2025 09:48:34 +0200 Subject: [PATCH 2/5] fix: crash on trying to generate for specific asset --- src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp index b1ca0f86..347febe4 100644 --- a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp @@ -64,14 +64,14 @@ bool CodeGenerator::GetAssetWithName(IDataRepository* repository, const std::str } auto* defWithMembers = dynamic_cast(def); - auto* info = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr; - if (info == nullptr) + asset = defWithMembers != nullptr ? repository->GetInformationFor(defWithMembers) : nullptr; + if (asset == nullptr) { std::cerr << std::format("Could not find type with name '{}'\n", name); return false; } - if (!StructureComputations(info).IsAsset()) + if (!StructureComputations(asset).IsAsset()) { std::cerr << std::format("Type is not an asset '{}'\n", name); return false; From 3adbe5a2757e7400edec1b9c7939201eb5ed3a10 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 28 Apr 2025 11:54:51 +0100 Subject: [PATCH 3/5] refactor: fix additional zcg x64 warnings --- .../Parsing/Impl/DefinesStreamProxy.cpp | 31 ++-- src/Parser/Parsing/Impl/DefinesStreamProxy.h | 140 ++++++++---------- src/Parser/Parsing/Matcher/AbstractMatcher.h | 2 +- .../Parsing/Matcher/AbstractMatcherFactory.h | 24 +-- src/Parser/Parsing/Matcher/MatcherResult.cpp | 8 +- src/Parser/Parsing/Matcher/MatcherResult.h | 13 +- .../Expression/SimpleExpressionMatchers.cpp | 2 +- .../Simple/Matcher/SimpleMatcherFactory.h | 26 ++-- src/Parser/Parsing/Simple/SimpleLexer.cpp | 2 +- src/Utils/Utils/Arguments/ArgumentParser.cpp | 2 +- .../Commands/Impl/CommandsParserState.cpp | 2 +- .../Matcher/CommandsCommonMatchers.cpp | 2 +- 12 files changed, 124 insertions(+), 130 deletions(-) diff --git a/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp b/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp index 9c241627..631b159f 100644 --- a/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp +++ b/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp @@ -13,12 +13,22 @@ namespace { - bool IsStringizeParameterForwardLookup(const std::string& value, size_t pos) + constexpr auto DEFINE_DIRECTIVE = "define"; + constexpr auto UNDEF_DIRECTIVE = "undef"; + constexpr auto IF_DIRECTIVE = "if"; + constexpr auto ELIF_DIRECTIVE = "elif"; + constexpr auto IFDEF_DIRECTIVE = "ifdef"; + constexpr auto IFNDEF_DIRECTIVE = "ifndef"; + constexpr auto ELSE_DIRECTIVE = "else"; + constexpr auto ENDIF_DIRECTIVE = "endif"; + constexpr auto DEFINED_KEYWORD = "defined"; + + bool IsStringizeParameterForwardLookup(const std::string& value, const size_t pos) { return pos + 1 && (isalpha(value[pos + 1]) || value[pos + 1] == '_'); } - bool IsTokenPastingOperatorForwardLookup(const std::string& value, size_t pos) + bool IsTokenPastingOperatorForwardLookup(const std::string& value, const size_t pos) { return pos + 1 < value.size() && value[pos + 1] == '#'; } @@ -31,7 +41,7 @@ DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition() { } -DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition(const unsigned index, const size_t position, const bool stringize) +DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition(const unsigned index, const unsigned position, const bool stringize) : m_parameter_index(index), m_parameter_position(position), m_stringize(stringize) @@ -591,7 +601,6 @@ bool DefinesStreamProxy::FindNextMacro(const std::string& input, unsigned& input { const auto inputSize = input.size(); auto wordStart = 0u; - auto lastWordEnd = 0u; auto inWord = false; auto inString = false; auto stringEscape = false; @@ -763,8 +772,7 @@ namespace } } // namespace -void DefinesStreamProxy::ProcessTokenPastingOperators( - const ParserLine& line, const unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos) +void DefinesStreamProxy::ProcessTokenPastingOperators(const ParserLine& line, const unsigned& linePos, std::string& input) { std::ostringstream ss; @@ -853,18 +861,17 @@ void DefinesStreamProxy::ExpandMacro(ParserLine& line, unsigned& linePos, std::ostringstream& out, std::vector& callstack, - const DefinesStreamProxy::Define* macro, + const Define* macro, const std::vector& parameterValues) { std::ostringstream rawOutput; InsertMacroParameters(rawOutput, macro, parameterValues); std::string str = rawOutput.str(); - unsigned nestedPos = 0; - ProcessNestedMacros(line, linePos, callstack, str, nestedPos); + ProcessNestedMacros(line, linePos, callstack, str); if (macro->m_contains_token_pasting_operators) - ProcessTokenPastingOperators(line, linePos, callstack, str, nestedPos); + ProcessTokenPastingOperators(line, linePos, str); out << str; } @@ -966,7 +973,7 @@ void DefinesStreamProxy::ContinueMultiLineMacro(ParserLine& line) } } -void DefinesStreamProxy::ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos) +void DefinesStreamProxy::ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input) { bool usesDefines = false; @@ -1021,7 +1028,7 @@ void DefinesStreamProxy::ProcessMacrosSingleLine(ParserLine& line) { unsigned pos = 0; std::vector callstack; - ProcessNestedMacros(line, pos, callstack, line.m_line, pos); + ProcessNestedMacros(line, pos, callstack, line.m_line); } void DefinesStreamProxy::ProcessMacrosMultiLine(ParserLine& line) diff --git a/src/Parser/Parsing/Impl/DefinesStreamProxy.h b/src/Parser/Parsing/Impl/DefinesStreamProxy.h index d9beffb6..2195529c 100644 --- a/src/Parser/Parsing/Impl/DefinesStreamProxy.h +++ b/src/Parser/Parsing/Impl/DefinesStreamProxy.h @@ -13,42 +13,30 @@ class DefinesStreamProxy final : public AbstractDirectiveStreamProxy { - static constexpr const char* DEFINE_DIRECTIVE = "define"; - static constexpr const char* UNDEF_DIRECTIVE = "undef"; - static constexpr const char* IF_DIRECTIVE = "if"; - static constexpr const char* ELIF_DIRECTIVE = "elif"; - static constexpr const char* IFDEF_DIRECTIVE = "ifdef"; - static constexpr const char* IFNDEF_DIRECTIVE = "ifndef"; - static constexpr const char* ELSE_DIRECTIVE = "else"; - static constexpr const char* ENDIF_DIRECTIVE = "endif"; - static constexpr const char* DEFINED_KEYWORD = "defined"; - - static constexpr auto MAX_DEFINE_ITERATIONS = 128u; - public: class DefineParameterPosition { public: - unsigned m_parameter_index; - size_t m_parameter_position; - bool m_stringize; - DefineParameterPosition(); - DefineParameterPosition(unsigned index, size_t position, bool stringize); + DefineParameterPosition(unsigned index, unsigned position, bool stringize); + + unsigned m_parameter_index; + unsigned m_parameter_position; + bool m_stringize; }; class Define { public: + Define(); + Define(std::string name, std::string value); + void IdentifyParameters(const std::vector& parameterNames); + std::string m_name; std::string m_value; std::vector m_parameter_positions; bool m_contains_token_pasting_operators; - Define(); - Define(std::string name, std::string value); - void IdentifyParameters(const std::vector& parameterNames); - private: void IdentifyTokenPasteOperatorOnly(); }; @@ -64,14 +52,27 @@ public: class MacroParameterState { public: + MacroParameterState(); + ParameterState m_parameter_state; std::ostringstream m_current_parameter; std::vector m_parameters; std::stack m_bracket_depth; - - MacroParameterState(); }; + explicit DefinesStreamProxy(IParserLineStream* stream, bool skipDirectiveLines = false); + + void AddDefine(Define define); + void Undefine(const std::string& name); + + [[nodiscard]] std::unique_ptr ParseExpression(std::shared_ptr fileName, int lineNumber, std::string expressionString); + + ParserLine NextLine() override; + bool IncludeFile(const std::string& filename) override; + void PopCurrentFile() override; + [[nodiscard]] bool IsOpen() const override; + [[nodiscard]] bool Eof() const override; + private: enum class BlockMode : uint8_t @@ -81,6 +82,45 @@ private: BLOCK_BLOCKED }; + static int GetLineEndEscapePos(const ParserLine& line); + void MatchDefineParameters(const ParserLine& line, size_t& currentPos); + void ContinueDefine(const ParserLine& line, size_t currentPos); + void ContinueParameters(const ParserLine& line, size_t& currentPos); + [[nodiscard]] bool MatchDefineDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchUndefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchElIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchIfdefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchElseDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchEndifDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); + [[nodiscard]] bool MatchDirectives(const ParserLine& line); + + static void ExtractParametersFromMacroUsage( + const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos); + bool FindMacroForIdentifier(const std::string& input, unsigned identifierStart, unsigned identifierEnd, const Define*& value) const; + + static bool MatchDefinedExpression(const ParserLine& line, size_t& pos, std::string& definitionName); + void ExpandDefinedExpressions(ParserLine& line) const; + + bool FindNextMacro(const std::string& input, unsigned& inputPos, unsigned& defineStart, const DefinesStreamProxy::Define*& define) const; + + static void ProcessTokenPastingOperators(const ParserLine& line, const unsigned& linePos, std::string& input); + static void InsertMacroParameters(std::ostringstream& out, const DefinesStreamProxy::Define* macro, const std::vector& parameterValues); + void ExpandMacro(ParserLine& line, + unsigned& linePos, + std::ostringstream& out, + std::vector& callstack, + const DefinesStreamProxy::Define* macro, + const std::vector& parameterValues); + + static void + ContinueMacroParameters(const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos); + void ContinueMultiLineMacro(ParserLine& line); + + void ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input); + void ProcessMacrosSingleLine(ParserLine& line); + void ProcessMacrosMultiLine(ParserLine& line); + IParserLineStream* const m_stream; const bool m_skip_directive_lines; std::map m_defines; @@ -95,58 +135,4 @@ private: const Define* m_current_macro; MacroParameterState m_multi_line_macro_parameters; - - static int GetLineEndEscapePos(const ParserLine& line); - void MatchDefineParameters(const ParserLine& line, size_t& currentPos); - void ContinueDefine(const ParserLine& line, size_t currentPos); - void ContinueParameters(const ParserLine& line, size_t& currentPos); - _NODISCARD bool MatchDefineDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchUndefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchElIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchIfdefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchElseDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchEndifDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition); - _NODISCARD bool MatchDirectives(const ParserLine& line); - - static void ExtractParametersFromMacroUsage( - const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos); - bool FindMacroForIdentifier(const std::string& input, unsigned identifierStart, unsigned identifierEnd, const Define*& value) const; - - static bool MatchDefinedExpression(const ParserLine& line, size_t& pos, std::string& definitionName); - void ExpandDefinedExpressions(ParserLine& line) const; - - bool FindNextMacro(const std::string& input, unsigned& inputPos, unsigned& defineStart, const DefinesStreamProxy::Define*& define) const; - - static void ProcessTokenPastingOperators( - const ParserLine& line, const unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos); - static void InsertMacroParameters(std::ostringstream& out, const DefinesStreamProxy::Define* macro, const std::vector& parameterValues); - void ExpandMacro(ParserLine& line, - unsigned& linePos, - std::ostringstream& out, - std::vector& callstack, - const DefinesStreamProxy::Define* macro, - const std::vector& parameterValues); - - static void - ContinueMacroParameters(const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos); - void ContinueMultiLineMacro(ParserLine& line); - - void ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector& callstack, std::string& input, unsigned& inputPos); - void ProcessMacrosSingleLine(ParserLine& line); - void ProcessMacrosMultiLine(ParserLine& line); - -public: - explicit DefinesStreamProxy(IParserLineStream* stream, bool skipDirectiveLines = false); - - void AddDefine(Define define); - void Undefine(const std::string& name); - - _NODISCARD std::unique_ptr ParseExpression(std::shared_ptr fileName, int lineNumber, std::string expressionString); - - ParserLine NextLine() override; - bool IncludeFile(const std::string& filename) override; - void PopCurrentFile() override; - _NODISCARD bool IsOpen() const override; - _NODISCARD bool Eof() const override; }; diff --git a/src/Parser/Parsing/Matcher/AbstractMatcher.h b/src/Parser/Parsing/Matcher/AbstractMatcher.h index 8b112130..5e08d173 100644 --- a/src/Parser/Parsing/Matcher/AbstractMatcher.h +++ b/src/Parser/Parsing/Matcher/AbstractMatcher.h @@ -80,7 +80,7 @@ public: result.m_fabricated_tokens.push_back(m_transform_func(tokens)); result.m_matched_tokens.clear(); - result.m_matched_tokens.emplace_back(result.m_fabricated_tokens.size() - 1, true); + result.m_matched_tokens.emplace_back(static_cast(result.m_fabricated_tokens.size()) - 1u, true); } else if (result.m_matched_tokens.empty()) { diff --git a/src/Parser/Parsing/Matcher/AbstractMatcherFactory.h b/src/Parser/Parsing/Matcher/AbstractMatcherFactory.h index 1b957512..d91aa49b 100644 --- a/src/Parser/Parsing/Matcher/AbstractMatcherFactory.h +++ b/src/Parser/Parsing/Matcher/AbstractMatcherFactory.h @@ -16,7 +16,7 @@ template class MatcherFactoryWrapper { // TokenType must inherit IParserValue - static_assert(std::is_base_of::value); + static_assert(std::is_base_of_v); std::unique_ptr> m_matcher; @@ -73,7 +73,7 @@ public: template class AbstractMatcherFactory { // TokenType must inherit IParserValue - static_assert(std::is_base_of::value); + static_assert(std::is_base_of_v); const IMatcherForLabelSupplier* m_label_supplier; @@ -85,52 +85,52 @@ public: { } - _NODISCARD MatcherFactoryWrapper False() const + [[nodiscard]] MatcherFactoryWrapper False() const { return MatcherFactoryWrapper(std::make_unique>()); } - _NODISCARD MatcherFactoryWrapper True() const + [[nodiscard]] MatcherFactoryWrapper True() const { return MatcherFactoryWrapper(std::make_unique>()); } - _NODISCARD MatcherFactoryWrapper And(std::initializer_list>>> matchers) const + [[nodiscard]] MatcherFactoryWrapper And(std::initializer_list>>> matchers) const { return MatcherFactoryWrapper(std::make_unique>(matchers)); } - _NODISCARD MatcherFactoryWrapper And(std::vector>> matchers) const + [[nodiscard]] MatcherFactoryWrapper And(std::vector>> matchers) const { return MatcherFactoryWrapper(std::make_unique>(std::move(matchers))); } - _NODISCARD MatcherFactoryWrapper Or(std::initializer_list>>> matchers) const + [[nodiscard]] MatcherFactoryWrapper Or(std::initializer_list>>> matchers) const { return MatcherFactoryWrapper(std::make_unique>(matchers)); } - _NODISCARD MatcherFactoryWrapper Or(std::vector>> matchers) const + [[nodiscard]] MatcherFactoryWrapper Or(std::vector>> matchers) const { return MatcherFactoryWrapper(std::make_unique>(std::move(matchers))); } - _NODISCARD MatcherFactoryWrapper Loop(std::unique_ptr> matcher) const + [[nodiscard]] MatcherFactoryWrapper Loop(std::unique_ptr> matcher) const { return MatcherFactoryWrapper(std::make_unique>(std::move(matcher))); } - _NODISCARD MatcherFactoryWrapper OptionalLoop(std::unique_ptr> matcher) const + [[nodiscard]] MatcherFactoryWrapper OptionalLoop(std::unique_ptr> matcher) const { return MatcherFactoryWrapper(std::make_unique>(std::make_unique>(std::move(matcher)))); } - _NODISCARD MatcherFactoryWrapper Optional(std::unique_ptr> matcher) const + [[nodiscard]] MatcherFactoryWrapper Optional(std::unique_ptr> matcher) const { return MatcherFactoryWrapper(std::make_unique>(std::move(matcher))); } - _NODISCARD MatcherFactoryWrapper Label(const int label) const + [[nodiscard]] MatcherFactoryWrapper Label(const int label) const { return MatcherFactoryWrapper(std::make_unique>(m_label_supplier, label)); } diff --git a/src/Parser/Parsing/Matcher/MatcherResult.cpp b/src/Parser/Parsing/Matcher/MatcherResult.cpp index b79de9ce..5e7c7cb8 100644 --- a/src/Parser/Parsing/Matcher/MatcherResult.cpp +++ b/src/Parser/Parsing/Matcher/MatcherResult.cpp @@ -3,11 +3,11 @@ namespace { // The highest bit is the fabricated flag - constexpr size_t FABRICATED_FLAG_MASK = 1uz << (sizeof(size_t) * 8uz - 1uz); - constexpr size_t TOKEN_INDEX_MASK = ~FABRICATED_FLAG_MASK; + constexpr unsigned FABRICATED_FLAG_MASK = 1u << (sizeof(unsigned) * 8u - 1u); + constexpr unsigned TOKEN_INDEX_MASK = ~FABRICATED_FLAG_MASK; } // namespace -MatcherResultTokenIndex::MatcherResultTokenIndex(const size_t index, const bool isFabricated) +MatcherResultTokenIndex::MatcherResultTokenIndex(const unsigned index, const bool isFabricated) { m_token_index = index & TOKEN_INDEX_MASK; if (isFabricated) @@ -19,7 +19,7 @@ bool MatcherResultTokenIndex::IsFabricated() const return m_token_index & FABRICATED_FLAG_MASK; } -size_t MatcherResultTokenIndex::GetTokenIndex() const +unsigned MatcherResultTokenIndex::GetTokenIndex() const { return m_token_index & TOKEN_INDEX_MASK; } diff --git a/src/Parser/Parsing/Matcher/MatcherResult.h b/src/Parser/Parsing/Matcher/MatcherResult.h index 719f30d5..91bfc6d5 100644 --- a/src/Parser/Parsing/Matcher/MatcherResult.h +++ b/src/Parser/Parsing/Matcher/MatcherResult.h @@ -10,12 +10,12 @@ class MatcherResultTokenIndex { public: - MatcherResultTokenIndex(size_t index, bool isFabricated); + MatcherResultTokenIndex(unsigned index, bool isFabricated); [[nodiscard]] bool IsFabricated() const; - [[nodiscard]] size_t GetTokenIndex() const; + [[nodiscard]] unsigned GetTokenIndex() const; private: - size_t m_token_index; + unsigned m_token_index; }; class MatcherResultCapture @@ -54,8 +54,9 @@ public: for (const auto& capture : other.m_captures) { if (capture.m_token_index.IsFabricated()) - m_captures.emplace_back(capture.GetCaptureId(), - MatcherResultTokenIndex(m_fabricated_tokens.size() + capture.m_token_index.GetTokenIndex(), true)); + m_captures.emplace_back( + capture.GetCaptureId(), + MatcherResultTokenIndex(static_cast(m_fabricated_tokens.size()) + capture.m_token_index.GetTokenIndex(), true)); else m_captures.emplace_back(capture.GetCaptureId(), capture.m_token_index); } @@ -63,7 +64,7 @@ public: for (const auto& token : other.m_matched_tokens) { if (token.IsFabricated()) - m_matched_tokens.emplace_back(m_fabricated_tokens.size() + token.GetTokenIndex(), true); + m_matched_tokens.emplace_back(static_cast(m_fabricated_tokens.size()) + token.GetTokenIndex(), true); else m_matched_tokens.emplace_back(token.GetTokenIndex(), false); } diff --git a/src/Parser/Parsing/Simple/Expression/SimpleExpressionMatchers.cpp b/src/Parser/Parsing/Simple/Expression/SimpleExpressionMatchers.cpp index 8a347444..ea632dda 100644 --- a/src/Parser/Parsing/Simple/Expression/SimpleExpressionMatchers.cpp +++ b/src/Parser/Parsing/Simple/Expression/SimpleExpressionMatchers.cpp @@ -191,7 +191,7 @@ std::unique_ptr SimpleExpressionMatchers::ProcessExpression(S if (operationIndex < 0 || operationIndex >= static_cast(SimpleBinaryOperationId::COUNT)) throw ParsingException(TokenPos(), "Invalid binary operation id @ Expression"); - operators.emplace_back(operators.size(), SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[operationIndex]); + operators.emplace_back(static_cast(operators.size()), SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[operationIndex]); } else break; diff --git a/src/Parser/Parsing/Simple/Matcher/SimpleMatcherFactory.h b/src/Parser/Parsing/Simple/Matcher/SimpleMatcherFactory.h index 7853e450..a21456e3 100644 --- a/src/Parser/Parsing/Simple/Matcher/SimpleMatcherFactory.h +++ b/src/Parser/Parsing/Simple/Matcher/SimpleMatcherFactory.h @@ -10,17 +10,17 @@ class SimpleMatcherFactory : public AbstractMatcherFactory public: explicit SimpleMatcherFactory(const IMatcherForLabelSupplier* labelSupplier); - _NODISCARD MatcherFactoryWrapper Type(SimpleParserValueType type) const; - _NODISCARD MatcherFactoryWrapper Keyword(std::string value) const; - _NODISCARD MatcherFactoryWrapper KeywordIgnoreCase(std::string value) const; - _NODISCARD MatcherFactoryWrapper KeywordPrefix(std::string value) const; - _NODISCARD MatcherFactoryWrapper Identifier() const; - _NODISCARD MatcherFactoryWrapper String() const; - _NODISCARD MatcherFactoryWrapper Integer() const; - _NODISCARD MatcherFactoryWrapper IntegerWithSign() const; - _NODISCARD MatcherFactoryWrapper FloatingPoint() const; - _NODISCARD MatcherFactoryWrapper FloatingPointWithSign() const; - _NODISCARD MatcherFactoryWrapper Char(char c) const; - _NODISCARD MatcherFactoryWrapper MultiChar(int multiCharacterSequenceId) const; - _NODISCARD MatcherFactoryWrapper AnyCharBesides(std::vector chars) const; + [[nodiscard]] MatcherFactoryWrapper Type(SimpleParserValueType type) const; + [[nodiscard]] MatcherFactoryWrapper Keyword(std::string value) const; + [[nodiscard]] MatcherFactoryWrapper KeywordIgnoreCase(std::string value) const; + [[nodiscard]] MatcherFactoryWrapper KeywordPrefix(std::string value) const; + [[nodiscard]] MatcherFactoryWrapper Identifier() const; + [[nodiscard]] MatcherFactoryWrapper String() const; + [[nodiscard]] MatcherFactoryWrapper Integer() const; + [[nodiscard]] MatcherFactoryWrapper IntegerWithSign() const; + [[nodiscard]] MatcherFactoryWrapper FloatingPoint() const; + [[nodiscard]] MatcherFactoryWrapper FloatingPointWithSign() const; + [[nodiscard]] MatcherFactoryWrapper Char(char c) const; + [[nodiscard]] MatcherFactoryWrapper MultiChar(int multiCharacterSequenceId) const; + [[nodiscard]] MatcherFactoryWrapper AnyCharBesides(std::vector chars) const; }; diff --git a/src/Parser/Parsing/Simple/SimpleLexer.cpp b/src/Parser/Parsing/Simple/SimpleLexer.cpp index d20fee7f..6b48f1c3 100644 --- a/src/Parser/Parsing/Simple/SimpleLexer.cpp +++ b/src/Parser/Parsing/Simple/SimpleLexer.cpp @@ -79,7 +79,7 @@ bool SimpleLexer::ReadMultiCharacterToken(const MultiCharacterTokenLookupEntry* linePos++; } - m_current_line_offset = m_current_line_offset - 1 + multiTokenLookup->m_value.size(); + m_current_line_offset = m_current_line_offset - 1 + static_cast(multiTokenLookup->m_value.size()); return true; } diff --git a/src/Utils/Utils/Arguments/ArgumentParser.cpp b/src/Utils/Utils/Arguments/ArgumentParser.cpp index caff4ce1..8192f778 100644 --- a/src/Utils/Utils/Arguments/ArgumentParser.cpp +++ b/src/Utils/Utils/Arguments/ArgumentParser.cpp @@ -98,7 +98,7 @@ bool ArgumentParser::ParseArguments(std::vector& args) m_matched_options[matchedOption] = std::vector(); } - const auto parameterCount = matchedOption->m_parameters.size(); + const auto parameterCount = static_cast(matchedOption->m_parameters.size()); if (argIndex + parameterCount >= argCount) { std::cout << std::format("Not enough parameters for option '{}'.\n", arg); diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp index 00ed3005..0169d5ed 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Impl/CommandsParserState.cpp @@ -130,7 +130,7 @@ bool CommandsParserState::GetTypenameAndMembersFromTypename(const std::string& t if (foundDefinition == nullptr) { - currentSeparatorPos = typeNameValue.size(); + currentSeparatorPos = static_cast(typeNameValue.size()); foundDefinition = m_repository->GetDataDefinitionByName(typeNameValue); } diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp index 8bed3923..29aa8e4d 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Matcher/CommandsCommonMatchers.cpp @@ -376,7 +376,7 @@ std::unique_ptr operands.emplace_back(std::move(firstStatementPart)); if (result.PeekAndRemoveIfTag(TAG_EVALUATION_OPERATION) == TAG_EVALUATION_OPERATION) - operators.emplace_back(operators.size(), result.NextCapture(CAPTURE_BINARY_OPERATION_TYPE).OpTypeValue()); + operators.emplace_back(static_cast(operators.size()), result.NextCapture(CAPTURE_BINARY_OPERATION_TYPE).OpTypeValue()); else break; From 1fe1b308316474cb7bb8c63df2219fef2e5c7a50 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Mon, 28 Apr 2025 11:08:32 +0200 Subject: [PATCH 4/5] chore: use Asset definition instead of enum entry for zcg --- src/ZoneCode/Game/IW3/IW3_Commands.txt | 51 +++++----- src/ZoneCode/Game/IW4/IW4_Commands.txt | 71 +++++++------- src/ZoneCode/Game/IW5/IW5_Commands.txt | 81 ++++++++-------- src/ZoneCode/Game/T5/T5_Commands.txt | 65 ++++++------- src/ZoneCode/Game/T6/T6_Commands.txt | 97 +++++++++---------- .../Computations/StructureComputations.cpp | 2 +- .../Information/StructureInformation.cpp | 1 - .../Domain/Information/StructureInformation.h | 4 +- .../Generating/Templates/ZoneLoadTemplate.cpp | 2 +- .../Generating/Templates/ZoneMarkTemplate.cpp | 2 +- .../Templates/ZoneWriteTemplate.cpp | 2 +- .../Commands/Sequence/SequenceAsset.cpp | 14 ++- .../MarkingRequiredPostProcessor.cpp | 6 +- 13 files changed, 195 insertions(+), 203 deletions(-) diff --git a/src/ZoneCode/Game/IW3/IW3_Commands.txt b/src/ZoneCode/Game/IW3/IW3_Commands.txt index cf9d42f0..4ac4a98f 100644 --- a/src/ZoneCode/Game/IW3/IW3_Commands.txt +++ b/src/ZoneCode/Game/IW3/IW3_Commands.txt @@ -3,31 +3,31 @@ game IW3; architecture x86; // Game Assets -asset PhysPreset ASSET_TYPE_PHYSPRESET; -asset XAnimParts ASSET_TYPE_XANIMPARTS; -asset XModel ASSET_TYPE_XMODEL; -asset Material ASSET_TYPE_MATERIAL; -asset MaterialTechniqueSet ASSET_TYPE_TECHNIQUE_SET; -asset GfxImage ASSET_TYPE_IMAGE; -asset snd_alias_list_t ASSET_TYPE_SOUND; -asset SndCurve ASSET_TYPE_SOUND_CURVE; -asset LoadedSound ASSET_TYPE_LOADED_SOUND; -asset clipMap_t ASSET_TYPE_CLIPMAP_PVS; -asset ComWorld ASSET_TYPE_COMWORLD; -asset GameWorldSp ASSET_TYPE_GAMEWORLD_SP; -asset GameWorldMp ASSET_TYPE_GAMEWORLD_MP; -asset MapEnts ASSET_TYPE_MAP_ENTS; -asset GfxWorld ASSET_TYPE_GFXWORLD; -asset GfxLightDef ASSET_TYPE_LIGHT_DEF; -asset Font_s ASSET_TYPE_FONT; -asset MenuList ASSET_TYPE_MENULIST; -asset menuDef_t ASSET_TYPE_MENU; -asset LocalizeEntry ASSET_TYPE_LOCALIZE_ENTRY; -asset WeaponDef ASSET_TYPE_WEAPON; -asset FxEffectDef ASSET_TYPE_FX; -asset FxImpactTable ASSET_TYPE_IMPACT_FX; -asset RawFile ASSET_TYPE_RAWFILE; -asset StringTable ASSET_TYPE_STRINGTABLE; +asset PhysPreset AssetPhysPreset; +asset XAnimParts AssetXAnim; +asset XModel AssetXModel; +asset Material AssetMaterial; +asset MaterialTechniqueSet AssetTechniqueSet; +asset GfxImage AssetImage; +asset snd_alias_list_t AssetSound; +asset SndCurve AssetSoundCurve; +asset LoadedSound AssetLoadedSound; +asset clipMap_t AssetClipMapPvs; +asset ComWorld AssetComWorld; +asset GameWorldSp AssetGameWorldSp; +asset GameWorldMp AssetGameWorldMp; +asset MapEnts AssetMapEnts; +asset GfxWorld AssetGfxWorld; +asset GfxLightDef AssetLightDef; +asset Font_s AssetFont; +asset MenuList AssetMenuList; +asset menuDef_t AssetMenu; +asset LocalizeEntry AssetLocalize; +asset WeaponDef AssetWeapon; +asset FxEffectDef AssetFx; +asset FxImpactTable AssetImpactFx; +asset RawFile AssetRawFile; +asset StringTable AssetStringTable; // Setup blocks block temp XFILE_BLOCK_TEMP default; @@ -66,4 +66,3 @@ block normal XFILE_BLOCK_INDEX; #include "XAssets/RawFile.txt" #include "XAssets/StringTable.txt" -// EOF \ No newline at end of file diff --git a/src/ZoneCode/Game/IW4/IW4_Commands.txt b/src/ZoneCode/Game/IW4/IW4_Commands.txt index 52eacd84..cf62d97c 100644 --- a/src/ZoneCode/Game/IW4/IW4_Commands.txt +++ b/src/ZoneCode/Game/IW4/IW4_Commands.txt @@ -3,41 +3,41 @@ game IW4; architecture x86; // Game Assets -asset PhysPreset ASSET_TYPE_PHYSPRESET; -asset PhysCollmap ASSET_TYPE_PHYSCOLLMAP; -asset XAnimParts ASSET_TYPE_XANIMPARTS; -asset XModel ASSET_TYPE_XMODEL; -asset Material ASSET_TYPE_MATERIAL; -asset MaterialPixelShader ASSET_TYPE_PIXELSHADER; -asset MaterialVertexShader ASSET_TYPE_VERTEXSHADER; -asset MaterialVertexDeclaration ASSET_TYPE_VERTEXDECL; -asset MaterialTechniqueSet ASSET_TYPE_TECHNIQUE_SET; -asset GfxImage ASSET_TYPE_IMAGE; -asset snd_alias_list_t ASSET_TYPE_SOUND; -asset SndCurve ASSET_TYPE_SOUND_CURVE; -asset LoadedSound ASSET_TYPE_LOADED_SOUND; -asset clipMap_t ASSET_TYPE_CLIPMAP_MP; -asset ComWorld ASSET_TYPE_COMWORLD; -asset GameWorldSp ASSET_TYPE_GAMEWORLD_SP; -asset GameWorldMp ASSET_TYPE_GAMEWORLD_MP; -asset MapEnts ASSET_TYPE_MAP_ENTS; -asset FxWorld ASSET_TYPE_FXWORLD; -asset GfxWorld ASSET_TYPE_GFXWORLD; -asset GfxLightDef ASSET_TYPE_LIGHT_DEF; -asset Font_s ASSET_TYPE_FONT; -asset MenuList ASSET_TYPE_MENULIST; -asset menuDef_t ASSET_TYPE_MENU; -asset LocalizeEntry ASSET_TYPE_LOCALIZE_ENTRY; -asset WeaponCompleteDef ASSET_TYPE_WEAPON; -asset FxEffectDef ASSET_TYPE_FX; -asset FxImpactTable ASSET_TYPE_IMPACT_FX; -asset RawFile ASSET_TYPE_RAWFILE; -asset StringTable ASSET_TYPE_STRINGTABLE; -asset LeaderboardDef ASSET_TYPE_LEADERBOARD; -asset StructuredDataDefSet ASSET_TYPE_STRUCTURED_DATA_DEF; -asset TracerDef ASSET_TYPE_TRACER; -asset VehicleDef ASSET_TYPE_VEHICLE; -asset AddonMapEnts ASSET_TYPE_ADDON_MAP_ENTS; +asset PhysPreset AssetPhysPreset; +asset PhysCollmap AssetPhysCollMap; +asset XAnimParts AssetXAnim; +asset XModel AssetXModel; +asset Material AssetMaterial; +asset MaterialPixelShader AssetPixelShader; +asset MaterialVertexShader AssetVertexShader; +asset MaterialVertexDeclaration AssetVertexDecl; +asset MaterialTechniqueSet AssetTechniqueSet; +asset GfxImage AssetImage; +asset snd_alias_list_t AssetSound; +asset SndCurve AssetSoundCurve; +asset LoadedSound AssetLoadedSound; +asset clipMap_t AssetClipMapMp; +asset ComWorld AssetComWorld; +asset GameWorldSp AssetGameWorldSp; +asset GameWorldMp AssetGameWorldMp; +asset MapEnts AssetMapEnts; +asset FxWorld AssetFxWorld; +asset GfxWorld AssetGfxWorld; +asset GfxLightDef AssetLightDef; +asset Font_s AssetFont; +asset MenuList AssetMenuList; +asset menuDef_t AssetMenu; +asset LocalizeEntry AssetLocalize; +asset WeaponCompleteDef AssetWeapon; +asset FxEffectDef AssetFx; +asset FxImpactTable AssetImpactFx; +asset RawFile AssetRawFile; +asset StringTable AssetStringTable; +asset LeaderboardDef AssetLeaderboard; +asset StructuredDataDefSet AssetStructuredDataDef; +asset TracerDef AssetTracer; +asset VehicleDef AssetVehicle; +asset AddonMapEnts AssetAddonMapEnts; // Setup blocks block temp XFILE_BLOCK_TEMP default; @@ -85,4 +85,3 @@ block normal XFILE_BLOCK_INDEX; #include "XAssets/VehicleDef.txt" #include "XAssets/AddonMapEnts.txt" -// EOF \ No newline at end of file diff --git a/src/ZoneCode/Game/IW5/IW5_Commands.txt b/src/ZoneCode/Game/IW5/IW5_Commands.txt index eb5fae8a..e523ce91 100644 --- a/src/ZoneCode/Game/IW5/IW5_Commands.txt +++ b/src/ZoneCode/Game/IW5/IW5_Commands.txt @@ -3,46 +3,46 @@ game IW5; architecture x86; // Game Assets -asset PhysPreset ASSET_TYPE_PHYSPRESET; -asset PhysCollmap ASSET_TYPE_PHYSCOLLMAP; -asset XAnimParts ASSET_TYPE_XANIMPARTS; -asset XModelSurfs ASSET_TYPE_XMODEL_SURFS; -asset XModel ASSET_TYPE_XMODEL; -asset Material ASSET_TYPE_MATERIAL; -asset MaterialPixelShader ASSET_TYPE_PIXELSHADER; -asset MaterialVertexShader ASSET_TYPE_VERTEXSHADER; -asset MaterialVertexDeclaration ASSET_TYPE_VERTEXDECL; -asset MaterialTechniqueSet ASSET_TYPE_TECHNIQUE_SET; -asset GfxImage ASSET_TYPE_IMAGE; -asset snd_alias_list_t ASSET_TYPE_SOUND; -asset SndCurve ASSET_TYPE_SOUND_CURVE; -asset LoadedSound ASSET_TYPE_LOADED_SOUND; -asset clipMap_t ASSET_TYPE_CLIPMAP; -asset ComWorld ASSET_TYPE_COMWORLD; -asset GlassWorld ASSET_TYPE_GLASSWORLD; -asset PathData ASSET_TYPE_PATHDATA; -asset VehicleTrack ASSET_TYPE_VEHICLE_TRACK; -asset MapEnts ASSET_TYPE_MAP_ENTS; -asset FxWorld ASSET_TYPE_FXWORLD; -asset GfxWorld ASSET_TYPE_GFXWORLD; -asset GfxLightDef ASSET_TYPE_LIGHT_DEF; -asset Font_s ASSET_TYPE_FONT; -asset MenuList ASSET_TYPE_MENULIST; -asset menuDef_t ASSET_TYPE_MENU; -asset LocalizeEntry ASSET_TYPE_LOCALIZE_ENTRY; -asset WeaponAttachment ASSET_TYPE_ATTACHMENT; -asset WeaponCompleteDef ASSET_TYPE_WEAPON; -asset FxEffectDef ASSET_TYPE_FX; -asset FxImpactTable ASSET_TYPE_IMPACT_FX; -asset SurfaceFxTable ASSET_TYPE_SURFACE_FX; -asset RawFile ASSET_TYPE_RAWFILE; -asset ScriptFile ASSET_TYPE_SCRIPTFILE; -asset StringTable ASSET_TYPE_STRINGTABLE; -asset LeaderboardDef ASSET_TYPE_LEADERBOARD; -asset StructuredDataDefSet ASSET_TYPE_STRUCTURED_DATA_DEF; -asset TracerDef ASSET_TYPE_TRACER; -asset VehicleDef ASSET_TYPE_VEHICLE; -asset AddonMapEnts ASSET_TYPE_ADDON_MAP_ENTS; +asset PhysPreset AssetPhysPreset; +asset PhysCollmap AssetPhysCollMap; +asset XAnimParts AssetXAnim; +asset XModelSurfs AssetXModelSurfs; +asset XModel AssetXModel; +asset Material AssetMaterial; +asset MaterialPixelShader AssetPixelShader; +asset MaterialVertexShader AssetVertexShader; +asset MaterialVertexDeclaration AssetVertexDecl; +asset MaterialTechniqueSet AssetTechniqueSet; +asset GfxImage AssetImage; +asset snd_alias_list_t AssetSound; +asset SndCurve AssetSoundCurve; +asset LoadedSound AssetLoadedSound; +asset clipMap_t AssetClipMap; +asset ComWorld AssetComWorld; +asset GlassWorld AssetGlassWorld; +asset PathData AssetPathData; +asset VehicleTrack AssetVehicleTrack; +asset MapEnts AssetMapEnts; +asset FxWorld AssetFxWorld; +asset GfxWorld AssetGfxWorld; +asset GfxLightDef AssetLightDef; +asset Font_s AssetFont; +asset MenuList AssetMenuList; +asset menuDef_t AssetMenu; +asset LocalizeEntry AssetLocalize; +asset WeaponAttachment AssetAttachment; +asset WeaponCompleteDef AssetWeapon; +asset FxEffectDef AssetFx; +asset FxImpactTable AssetImpactFx; +asset SurfaceFxTable AssetSurfaceFx; +asset RawFile AssetRawFile; +asset ScriptFile AssetScript; +asset StringTable AssetStringTable; +asset LeaderboardDef AssetLeaderboard; +asset StructuredDataDefSet AssetStructuredDataDef; +asset TracerDef AssetTracer; +asset VehicleDef AssetVehicle; +asset AddonMapEnts AssetAddonMapEnts; // Setup blocks block temp XFILE_BLOCK_TEMP default; @@ -96,4 +96,3 @@ block normal XFILE_BLOCK_SCRIPT; #include "XAssets/VehicleDef.txt" #include "XAssets/AddonMapEnts.txt" -// EOF \ No newline at end of file diff --git a/src/ZoneCode/Game/T5/T5_Commands.txt b/src/ZoneCode/Game/T5/T5_Commands.txt index 0613abc4..977e4b0b 100644 --- a/src/ZoneCode/Game/T5/T5_Commands.txt +++ b/src/ZoneCode/Game/T5/T5_Commands.txt @@ -3,38 +3,38 @@ game T5; architecture x86; // Game Assets -asset PhysPreset ASSET_TYPE_PHYSPRESET; -asset PhysConstraints ASSET_TYPE_PHYSCONSTRAINTS; -asset DestructibleDef ASSET_TYPE_DESTRUCTIBLEDEF; -asset XAnimParts ASSET_TYPE_XANIMPARTS; -asset XModel ASSET_TYPE_XMODEL; -asset Material ASSET_TYPE_MATERIAL; -asset MaterialTechniqueSet ASSET_TYPE_TECHNIQUE_SET; -asset GfxImage ASSET_TYPE_IMAGE; -asset SndBank ASSET_TYPE_SOUND; -asset SndPatch ASSET_TYPE_SOUND_PATCH; -asset clipMap_t ASSET_TYPE_CLIPMAP_PVS; -asset ComWorld ASSET_TYPE_COMWORLD; -asset GameWorldSp ASSET_TYPE_GAMEWORLD_SP; -asset GameWorldMp ASSET_TYPE_GAMEWORLD_MP; -asset MapEnts ASSET_TYPE_MAP_ENTS; -asset GfxWorld ASSET_TYPE_GFXWORLD; -asset GfxLightDef ASSET_TYPE_LIGHT_DEF; -asset Font_s ASSET_TYPE_FONT; -asset MenuList ASSET_TYPE_MENULIST; -asset menuDef_t ASSET_TYPE_MENU; -asset LocalizeEntry ASSET_TYPE_LOCALIZE_ENTRY; -asset WeaponVariantDef ASSET_TYPE_WEAPON; -asset SndDriverGlobals ASSET_TYPE_SNDDRIVER_GLOBALS; -asset FxEffectDef ASSET_TYPE_FX; -asset FxImpactTable ASSET_TYPE_IMPACT_FX; -asset RawFile ASSET_TYPE_RAWFILE; -asset StringTable ASSET_TYPE_STRINGTABLE; -asset PackIndex ASSET_TYPE_PACK_INDEX; -asset XGlobals ASSET_TYPE_XGLOBALS; -asset ddlRoot_t ASSET_TYPE_DDL; -asset Glasses ASSET_TYPE_GLASSES; -asset EmblemSet ASSET_TYPE_EMBLEMSET; +asset PhysPreset AssetPhysPreset; +asset PhysConstraints AssetPhysConstraints; +asset DestructibleDef AssetDestructibleDef; +asset XAnimParts AssetXAnim; +asset XModel AssetXModel; +asset Material AssetMaterial; +asset MaterialTechniqueSet AssetTechniqueSet; +asset GfxImage AssetImage; +asset SndBank AssetSoundBank; +asset SndPatch AssetSoundPatch; +asset clipMap_t AssetClipMapPvs; +asset ComWorld AssetComWorld; +asset GameWorldSp AssetGameWorldSp; +asset GameWorldMp AssetGameWorldMp; +asset MapEnts AssetMapEnts; +asset GfxWorld AssetGfxWorld; +asset GfxLightDef AssetLightDef; +asset Font_s AssetFont; +asset MenuList AssetMenuList; +asset menuDef_t AssetMenu; +asset LocalizeEntry AssetLocalize; +asset WeaponVariantDef AssetWeapon; +asset SndDriverGlobals AssetSoundDriverGlobals; +asset FxEffectDef AssetFx; +asset FxImpactTable AssetImpactFx; +asset RawFile AssetRawFile; +asset StringTable AssetStringTable; +asset PackIndex AssetPackIndex; +asset XGlobals AssetXGlobals; +asset ddlRoot_t AssetDDL; +asset Glasses AssetGlasses; +asset EmblemSet AssetEmblemSet; // Setup blocks block temp XFILE_BLOCK_TEMP default; @@ -79,4 +79,3 @@ block normal XFILE_BLOCK_PHYSICAL; #include "XAssets/Glasses.txt" #include "XAssets/EmblemSet.txt" -// EOF \ No newline at end of file diff --git a/src/ZoneCode/Game/T6/T6_Commands.txt b/src/ZoneCode/Game/T6/T6_Commands.txt index 3bd115d1..80edd659 100644 --- a/src/ZoneCode/Game/T6/T6_Commands.txt +++ b/src/ZoneCode/Game/T6/T6_Commands.txt @@ -3,54 +3,54 @@ game T6; architecture x86; // Game Assets -asset PhysPreset ASSET_TYPE_PHYSPRESET; -asset PhysConstraints ASSET_TYPE_PHYSCONSTRAINTS; -asset DestructibleDef ASSET_TYPE_DESTRUCTIBLEDEF; -asset XAnimParts ASSET_TYPE_XANIMPARTS; -asset XModel ASSET_TYPE_XMODEL; -asset Material ASSET_TYPE_MATERIAL; -asset MaterialTechniqueSet ASSET_TYPE_TECHNIQUE_SET; -asset GfxImage ASSET_TYPE_IMAGE; -asset SndBank ASSET_TYPE_SOUND; -asset SndPatch ASSET_TYPE_SOUND_PATCH; -asset clipMap_t ASSET_TYPE_CLIPMAP_PVS; -asset ComWorld ASSET_TYPE_COMWORLD; -asset GameWorldSp ASSET_TYPE_GAMEWORLD_SP; -asset GameWorldMp ASSET_TYPE_GAMEWORLD_MP; -asset MapEnts ASSET_TYPE_MAP_ENTS; -asset GfxWorld ASSET_TYPE_GFXWORLD; -asset GfxLightDef ASSET_TYPE_LIGHT_DEF; -asset Font_s ASSET_TYPE_FONT; -asset FontIcon ASSET_TYPE_FONTICON; -asset MenuList ASSET_TYPE_MENULIST; -asset menuDef_t ASSET_TYPE_MENU; -asset LocalizeEntry ASSET_TYPE_LOCALIZE_ENTRY; -asset WeaponVariantDef ASSET_TYPE_WEAPON; -asset WeaponAttachment ASSET_TYPE_ATTACHMENT; -asset WeaponAttachmentUnique ASSET_TYPE_ATTACHMENT_UNIQUE; -asset WeaponCamo ASSET_TYPE_WEAPON_CAMO; -asset SndDriverGlobals ASSET_TYPE_SNDDRIVER_GLOBALS; -asset FxEffectDef ASSET_TYPE_FX; -asset FxImpactTable ASSET_TYPE_IMPACT_FX; -asset RawFile ASSET_TYPE_RAWFILE; -asset StringTable ASSET_TYPE_STRINGTABLE; -asset LeaderboardDef ASSET_TYPE_LEADERBOARD; -asset XGlobals ASSET_TYPE_XGLOBALS; -asset ddlRoot_t ASSET_TYPE_DDL; -asset Glasses ASSET_TYPE_GLASSES; -asset EmblemSet ASSET_TYPE_EMBLEMSET; -asset ScriptParseTree ASSET_TYPE_SCRIPTPARSETREE; -asset KeyValuePairs ASSET_TYPE_KEYVALUEPAIRS; -asset VehicleDef ASSET_TYPE_VEHICLEDEF; -asset MemoryBlock ASSET_TYPE_MEMORYBLOCK; -asset AddonMapEnts ASSET_TYPE_ADDON_MAP_ENTS; -asset TracerDef ASSET_TYPE_TRACER; -asset SkinnedVertsDef ASSET_TYPE_SKINNEDVERTS; -asset Qdb ASSET_TYPE_QDB; -asset Slug ASSET_TYPE_SLUG; -asset FootstepTableDef ASSET_TYPE_FOOTSTEP_TABLE; -asset FootstepFXTableDef ASSET_TYPE_FOOTSTEPFX_TABLE; -asset ZBarrierDef ASSET_TYPE_ZBARRIER; +asset PhysPreset AssetPhysPreset; +asset PhysConstraints AssetPhysConstraints; +asset DestructibleDef AssetDestructibleDef; +asset XAnimParts AssetXAnim; +asset XModel AssetXModel; +asset Material AssetMaterial; +asset MaterialTechniqueSet AssetTechniqueSet; +asset GfxImage AssetImage; +asset SndBank AssetSoundBank; +asset SndPatch AssetSoundPatch; +asset clipMap_t AssetClipMapPvs; +asset ComWorld AssetComWorld; +asset GameWorldSp AssetGameWorldSp; +asset GameWorldMp AssetGameWorldMp; +asset MapEnts AssetMapEnts; +asset GfxWorld AssetGfxWorld; +asset GfxLightDef AssetLightDef; +asset Font_s AssetFont; +asset FontIcon AssetFontIcon; +asset MenuList AssetMenuList; +asset menuDef_t AssetMenu; +asset LocalizeEntry AssetLocalize; +asset WeaponVariantDef AssetWeapon; +asset WeaponAttachment AssetAttachment; +asset WeaponAttachmentUnique AssetAttachmentUnique; +asset WeaponCamo AssetWeaponCamo; +asset SndDriverGlobals AssetSoundDriverGlobals; +asset FxEffectDef AssetFx; +asset FxImpactTable AssetImpactFx; +asset RawFile AssetRawFile; +asset StringTable AssetStringTable; +asset LeaderboardDef AssetLeaderboard; +asset XGlobals AssetXGlobals; +asset ddlRoot_t AssetDDL; +asset Glasses AssetGlasses; +asset EmblemSet AssetEmblemSet; +asset ScriptParseTree AssetScript; +asset KeyValuePairs AssetKeyValuePairs; +asset VehicleDef AssetVehicle; +asset MemoryBlock AssetMemoryBlock; +asset AddonMapEnts AssetAddonMapEnts; +asset TracerDef AssetTracer; +asset SkinnedVertsDef AssetSkinnedVerts; +asset Qdb AssetQdb; +asset Slug AssetSlug; +asset FootstepTableDef AssetFootstepTable; +asset FootstepFXTableDef AssetFootstepFxTable; +asset ZBarrierDef AssetZBarrier; // Setup blocks block temp XFILE_BLOCK_TEMP default; @@ -112,4 +112,3 @@ block normal XFILE_BLOCK_STREAMER_RESERVE; #include "XAssets/FootstepFXTableDef.txt" #include "XAssets/ZBarrierDef.txt" -// EOF \ No newline at end of file diff --git a/src/ZoneCodeGeneratorLib/Domain/Computations/StructureComputations.cpp b/src/ZoneCodeGeneratorLib/Domain/Computations/StructureComputations.cpp index 60dae011..2d732aaf 100644 --- a/src/ZoneCodeGeneratorLib/Domain/Computations/StructureComputations.cpp +++ b/src/ZoneCodeGeneratorLib/Domain/Computations/StructureComputations.cpp @@ -12,7 +12,7 @@ StructureComputations::StructureComputations(const StructureInformation* structu bool StructureComputations::IsAsset() const { - return m_info->m_asset_enum_entry != nullptr; + return !m_info->m_asset_name.empty(); } MemberInformation* StructureComputations::GetDynamicMember() const diff --git a/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.cpp b/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.cpp index da546082..9959c1be 100644 --- a/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.cpp +++ b/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.cpp @@ -2,7 +2,6 @@ StructureInformation::StructureInformation(DefinitionWithMembers* definition) : m_definition(definition), - m_asset_enum_entry(nullptr), m_is_leaf(false), m_requires_marking(false), m_has_matching_cross_platform_structure(false), diff --git a/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.h b/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.h index 2abb0b76..5761e3d2 100644 --- a/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.h +++ b/src/ZoneCodeGeneratorLib/Domain/Information/StructureInformation.h @@ -16,8 +16,8 @@ class StructureInformation public: explicit StructureInformation(DefinitionWithMembers* definition); - DefinitionWithMembers* const m_definition; - EnumMember* m_asset_enum_entry; + DefinitionWithMembers* m_definition; + std::string m_asset_name; std::vector m_usages; std::vector> m_ordered_members; diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index 6493a0cd..90d48527 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -262,7 +262,7 @@ namespace LINEF("{0}::{0}(Zone* zone, IZoneInputStream* stream)", LoaderClassName(m_env.m_asset)) m_intendation++; - LINE_STARTF(": AssetLoader({0}, zone, stream)", m_env.m_asset->m_asset_enum_entry->m_name) + LINE_STARTF(": AssetLoader({0}::EnumEntry, zone, stream)", m_env.m_asset->m_asset_name) if (m_env.m_has_actions) { LINE_MIDDLE(", m_actions(zone)") diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp index 688c44ee..28d4d21d 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp @@ -245,7 +245,7 @@ namespace LINEF("{0}::{0}(Zone* zone)", MarkerClassName(m_env.m_asset)) m_intendation++; - LINEF(": AssetMarker({0}, zone)", m_env.m_asset->m_asset_enum_entry->m_name) + LINEF(": AssetMarker({0}::EnumEntry, zone)", m_env.m_asset->m_asset_name) m_intendation--; LINE("{") diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp index 0cc2a1cf..96155c89 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp @@ -261,7 +261,7 @@ namespace "{0}::{0}({1}* asset, const Zone& zone, IZoneOutputStream& stream)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName()) m_intendation++; - LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}, GetAssetName(asset)), zone, stream)", m_env.m_asset->m_asset_enum_entry->m_name) + LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, GetAssetName(asset)), zone, stream)", m_env.m_asset->m_asset_name) m_intendation--; LINE("{") diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp index ae856fca..84e78363 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAsset.cpp @@ -6,7 +6,7 @@ namespace { static constexpr auto CAPTURE_TYPE = 1; - static constexpr auto CAPTURE_ENUM_ENTRY = 2; + static constexpr auto CAPTURE_ASSET_NAME = 2; } // namespace SequenceAsset::SequenceAsset() @@ -17,7 +17,7 @@ SequenceAsset::SequenceAsset() AddMatchers({ create.Keyword("asset"), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), - create.Identifier().Capture(CAPTURE_ENUM_ENTRY), + create.Identifier().Capture(CAPTURE_ASSET_NAME), create.Char(';'), }); } @@ -25,7 +25,7 @@ SequenceAsset::SequenceAsset() void SequenceAsset::ProcessMatch(CommandsParserState* state, SequenceResult& result) const { const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE); - const auto& enumEntryToken = result.NextCapture(CAPTURE_ENUM_ENTRY); + const auto& assetNameToken = result.NextCapture(CAPTURE_ASSET_NAME); auto* definition = state->GetRepository()->GetDataDefinitionByName(typeNameToken.TypeNameValue()); if (definition == nullptr) @@ -39,9 +39,7 @@ void SequenceAsset::ProcessMatch(CommandsParserState* state, SequenceResultGetRepository()->GetEnumMemberByName(enumEntryToken.IdentifierValue()); - if (enumMember == nullptr) - throw ParsingException(enumEntryToken.GetPos(), "Unknown enum entry"); - - information->m_asset_enum_entry = enumMember; + information->m_asset_name = assetNameToken.IdentifierValue(); + if (information->m_asset_name.empty()) + throw ParsingException(assetNameToken.GetPos(), "Asset name is empty"); } diff --git a/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/MarkingRequiredPostProcessor.cpp b/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/MarkingRequiredPostProcessor.cpp index 1c964928..137beb7a 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/MarkingRequiredPostProcessor.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/PostProcessing/MarkingRequiredPostProcessor.cpp @@ -10,12 +10,12 @@ namespace { bool CalculateRequiresMarking(std::unordered_set& visitedStructures, StructureInformation* info) { - if (visitedStructures.find(info) != visitedStructures.end()) + if (visitedStructures.contains(info)) return info->m_requires_marking; visitedStructures.emplace(info); - if (info->m_asset_enum_entry) + if (StructureComputations(info).IsAsset()) { info->m_requires_marking = true; return true; @@ -47,7 +47,7 @@ namespace continue; // Any script strings, asset refs and assets need to be processed. - if (member->m_is_script_string || member->m_asset_ref || member->m_type && member->m_type->m_asset_enum_entry) + if (member->m_is_script_string || member->m_asset_ref || member->m_type && StructureComputations(member->m_type).IsAsset()) { info->m_requires_marking = true; return true; From 547da3fdf9a94fe80b43229f226ec0aeb49c66be Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 28 Apr 2025 12:50:51 +0100 Subject: [PATCH 5/5] refactor: remove GetName method of ZoneWrite zcg template --- .../Templates/ZoneWriteTemplate.cpp | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp index 96155c89..41ccf831 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp @@ -97,7 +97,6 @@ namespace m_intendation++; PrintHeaderConstructor(); PrintHeaderMainWriteMethodDeclaration(m_env.m_asset); - PrintHeaderGetNameMethodDeclaration(m_env.m_asset); m_intendation--; LINE("};") @@ -160,8 +159,6 @@ namespace PrintWritePtrMethod(m_env.m_asset); LINE("") PrintMainWriteMethod(); - LINE("") - PrintGetNameMethod(); } private: @@ -220,11 +217,6 @@ namespace LINEF("void WritePtr_{0}(bool atStreamStart);", MakeSafeTypeName(info->m_definition)) } - void PrintHeaderGetNameMethodDeclaration(const StructureInformation* info) const - { - LINEF("static std::string GetAssetName({0}* pAsset);", info->m_definition->GetFullName()) - } - void PrintHeaderMainWriteMethodDeclaration(const StructureInformation* info) const { LINEF("void Write({0}** pAsset);", info->m_definition->GetFullName()) @@ -261,7 +253,8 @@ namespace "{0}::{0}({1}* asset, const Zone& zone, IZoneOutputStream& stream)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName()) m_intendation++; - LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, GetAssetName(asset)), zone, stream)", m_env.m_asset->m_asset_name) + LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, AssetNameAccessor<{0}>()(*asset)), zone, stream)", + m_env.m_asset->m_asset_name) m_intendation--; LINE("{") @@ -1102,40 +1095,6 @@ namespace LINE("}") } - void PrintGetNameMethod() - { - LINEF("std::string {0}::GetAssetName({1}* pAsset)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName()) - LINE("{") - m_intendation++; - - if (!m_env.m_asset->m_name_chain.empty()) - { - LINE_START("return pAsset") - - auto first = true; - for (const auto* member : m_env.m_asset->m_name_chain) - { - if (first) - { - first = false; - LINE_MIDDLEF("->{0}", member->m_member->m_name) - } - else - { - LINE_MIDDLEF(".{0}", member->m_member->m_name) - } - } - LINE_END(";") - } - else - { - LINEF("return \"{0}\";", m_env.m_asset->m_definition->m_name) - } - - m_intendation--; - LINE("}") - } - void PrintWritePtrArrayMethod_Loading(const DataDefinition* def, const StructureInformation* info, const bool reusable) const { LINEF("m_stream->Align({0});", def->GetAlignment())