From 19ca675bf14b075d6cd84ef44f3783977018ce26 Mon Sep 17 00:00:00 2001 From: ouczbs Date: Tue, 25 Jun 2024 20:26:25 +0800 Subject: [PATCH] bugfix --- src/refl/GenMeta.cs | 11 +++++++---- src/refl/GenMetaImpl.cs | 11 ++++++++++- src/refl/GenMultyMeta.cs | 10 +--------- src/refl/template/meta.liquid | 23 ++++++++++++++--------- src/refl/template/meta_impl.liquid | 4 +++- src/refl/template/multy_meta.liquid | 11 +++-------- 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/refl/GenMeta.cs b/src/refl/GenMeta.cs index fc4903e..4bf167b 100644 --- a/src/refl/GenMeta.cs +++ b/src/refl/GenMeta.cs @@ -26,7 +26,7 @@ namespace refl public string ParentName { get; set; } = ""; public string FullName { get; set; } = ""; public string MetaName { get; set; } = ""; - public bool IsMultyMeta { get; set; } = false; + public int MetaType { get; set; } = 0; public int MemberCount { get; set; } = 0; public int CtorCount { get; set; } = 0; @@ -54,7 +54,7 @@ namespace refl { data.Name = cls.Name; data.ParentName = cls.ParentName; - bool isMulty = false; + bool isMulty = cls.Fields.Count > 0; foreach (var pair in cls.Fields) { data.FieldList.Clear(); @@ -73,9 +73,12 @@ namespace refl } data.MemberCount = pair.Value.MemberList.Count; data.CtorCount = pair.Value.CtorList.Count; - data.IsMultyMeta = !pair.Key.Equals("Meta"); + data.MetaType = isMulty ? 1 : 0; + if (pair.Key.Equals("Meta")) + { + data.MetaType = 2; + } data.MetaName = pair.Key; - isMulty = isMulty || data.IsMultyMeta; var context = new TemplateContext(data, options); var res = template.Render(context); Gen.FileList[pair.Key].Append(res); diff --git a/src/refl/GenMetaImpl.cs b/src/refl/GenMetaImpl.cs index 8da37f3..8669b95 100644 --- a/src/refl/GenMetaImpl.cs +++ b/src/refl/GenMetaImpl.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace refl { @@ -12,8 +13,8 @@ namespace refl public string Name { get; set; } = ""; public string FullName { get; set; } = ""; - public bool IsMultyMeta { get; set; } = false; + public bool HasMeta { get; set; } = false; } internal class GenMetaImpl { @@ -37,6 +38,14 @@ namespace refl impl.Name = cls.Name; impl.FullName = fullName; impl.IsMultyMeta = isMulty; + impl.HasMeta = false; + foreach (var pair in cls.Fields) + { + if (pair.Key.Equals("Meta")) + { + impl.HasMeta = true; + } + } var context = new TemplateContext(impl, options); return template.Render(context); } diff --git a/src/refl/GenMultyMeta.cs b/src/refl/GenMultyMeta.cs index 3de7ea0..73451e8 100644 --- a/src/refl/GenMultyMeta.cs +++ b/src/refl/GenMultyMeta.cs @@ -11,7 +11,6 @@ namespace refl { public string Name { get; set; } = ""; public string FullName { get; set; } = ""; - public bool HasMeta { get; set; } = false; public List MetaList = new List(); } @@ -38,14 +37,7 @@ namespace refl data.FullName = fullName; foreach (var pair in cls.Fields) { - if (pair.Key.Equals("Meta")) - { - data.HasMeta = true; - } - else - { - data.MetaList.Add(pair.Key); - } + data.MetaList.Add(pair.Key); } var context = new TemplateContext(data, options); return template.Render(context); diff --git a/src/refl/template/meta.liquid b/src/refl/template/meta.liquid index b2eeb91..7c96ae1 100644 --- a/src/refl/template/meta.liquid +++ b/src/refl/template/meta.liquid @@ -1,12 +1,12 @@ {{ Indent }}template<> struct _Static<{{FullName}},{{MetaName}}> { -{{ Indent }} using T = class {{FullName}}; +{{ Indent }} using T = {{FullName}}; {{ Indent }} consteval static auto __MakeStaticFields() { {{ Indent }} return std::array{ {{ Indent }} {%- for field in FieldList %} {{ Indent }} {%- if field.Type == 1 %} {{ Indent }} refl::StaticMemberField(&T::{{field.Name}}, FName("{{field.Name}}"), {{field.Meta}}), {{ Indent }} {%- elsif field.Type == 2 %} -{{ Indent }} refl::StaticCtorField({{field.Meta}}), +{{ Indent }} refl::StaticCtorField((T::{{field.Ref}})nullptr,{{field.Meta}}), {{ Indent }} {%- elsif field.Type == 3 %} {{ Indent }} refl::StaticMethodField(&T::{{field.Name}}, FName("{{field.Name}}"), {{field.Meta}}), {{ Indent }} {%- else %} @@ -28,12 +28,12 @@ {{ Indent }}}; {{ Indent }} {{ Indent }}template<> struct _Meta<{{FullName}},{{MetaName}}> : public refl::MetaHelp { -{{ Indent }} using T = class {{FullName}}; +{{ Indent }} using T = {{FullName}}; {{ Indent }} using MyParent = {{ ParentName }}; {{ Indent }} using MyStatic = _Static; -{{ Indent }} {%-if IsMultyMeta %} +{{ Indent }}{%-if IsMultyMeta %} {{ Indent }} using MyMetas = class _Multy; -{{ Indent }} {%- endif %} +{{ Indent }}{%- endif %} {{ Indent }} inline static char s_data[MyStatic::Size()]{}; {{ Indent }} static auto __MakeFields() { {{ Indent }} char* memory = &s_data[0]; @@ -42,7 +42,7 @@ {{ Indent }} {%- if field.Type == 1 %} {{ Indent }} MemberField(&T::{{field.Name}}, FName("{{field.Name}}"), memory, {{field.Meta}}), {{ Indent }} {%- elsif field.Type == 2 %} -{{ Indent }} CtorField(memory, {{field.Meta}}), +{{ Indent }} CtorField((T::{{field.Ref}})nullptr, memory, {{field.Meta}}), {{ Indent }} {%- elsif field.Type == 3 %} {{ Indent }} MethodField(&T::{{field.Name}}, FName("{{field.Name}}"), memory, {{field.Meta}}), {{ Indent }} {%- else %} @@ -52,10 +52,15 @@ {{ Indent }} }; {{ Indent }} }; {{ Indent }}}; -{{ Indent }}{%- if IsMultyMeta %} -{{ Indent }}template<> const refl::UClass* _Multy<{{FullName}}>::{{ MetaName }}() +{{ Indent }}{%- if MetaType == 1 %} +{{ Indent }}const refl::UClass* _Multy<{{FullName}}>::get_{{ MetaName }}() {{ Indent }}{ -{{ Indent }} static const auto s_cls = refl::UClass_Meta>::BuildClass(); +{{ Indent }} static const auto s_cls = refl::UClass_Meta>(); {{ Indent }} return &s_cls; {{ Indent }}}; +{{ Indent }}{%- else %} +{{ Indent }}inline const refl::UClass* _Multy<{{FullName}}>::get_{{ MetaName }}() +{{ Indent }}{ +{{ Indent }} return &refl::TypeInfo::StaticClass; +{{ Indent }}}; {{ Indent }}{%- endif %} \ No newline at end of file diff --git a/src/refl/template/meta_impl.liquid b/src/refl/template/meta_impl.liquid index 47092a2..d808ab1 100644 --- a/src/refl/template/meta_impl.liquid +++ b/src/refl/template/meta_impl.liquid @@ -1,6 +1,8 @@ {{ Indent }}template<> struct MetaImpl<{{FullName}}>{ -{{ Indent }} using T = class {{FullName}}; +{{ Indent }} using T = {{FullName}}; +{{ Indent }}{%- if HasMeta %} {{ Indent }} using MyMeta = _Meta; +{{ Indent }}{%- endif %} {{ Indent }}{%- if IsMultyMeta %} {{ Indent }} using MyMetas = _Multy; {{ Indent }}{%- endif %} diff --git a/src/refl/template/multy_meta.liquid b/src/refl/template/multy_meta.liquid index 7372587..df111ea 100644 --- a/src/refl/template/multy_meta.liquid +++ b/src/refl/template/multy_meta.liquid @@ -1,19 +1,14 @@ {{ Indent }}template<> struct _Multy<{{FullName}}>{ -{{ Indent }} using T = class {{FullName}}; +{{ Indent }} using T = {{FullName}}; {{ Indent }}{%- for Meta in MetaList %} -{{ Indent }} static const refl::UClass* {{Meta}}(); +{{ Indent }} static const refl::UClass* get_{{Meta}}(); {{ Indent }}{%- endfor %} {{ Indent }} static const refl::UClass* GetMeta(const Name& name) { {{ Indent }}{%- for Meta in MetaList %} {{ Indent }} if (name == FName("{{Meta}}")) { -{{ Indent }} return {{Meta}}(); +{{ Indent }} return get_{{Meta}}(); {{ Indent }} } {{ Indent }}{%- endfor %} -{{ Indent }}{%- if HasMeta %} -{{ Indent }} if (name == FName("Meta")) { -{{ Indent }} return &refl::TypeInfo::StaticClass; -{{ Indent }} } -{{ Indent }}{%- endif %} {{ Indent }} return nullptr; {{ Indent }} } {{ Indent }}}; \ No newline at end of file