rebuild with refl_impl

This commit is contained in:
ouczbs 2024-06-20 22:32:20 +08:00
parent e3f111ec3c
commit e4bba053cc
11 changed files with 329 additions and 208 deletions

View File

@ -98,7 +98,7 @@ namespace refl
{ {
cls_meta.Fields.Add(key, new FieldMeta()); cls_meta.Fields.Add(key, new FieldMeta());
} }
List<string> nameList = new List<string>{ cppClass.Name }; List<string> nameList = new List<string>{ "T" };
foreach (var parm in func.Parameters) foreach (var parm in func.Parameters)
{ {
nameList.Add(parm.Type.FullName); nameList.Add(parm.Type.FullName);
@ -137,7 +137,10 @@ namespace refl
foreach (var spaces in cpp.Namespaces) foreach (var spaces in cpp.Namespaces)
{ {
var child = ParseCppNamespaces(spaces); var child = ParseCppNamespaces(spaces);
module.ChildList.Add(child); if(child.ClassList.Count > 0 || child.ChildList.Count > 0)
{
module.ChildList.Add(child);
}
} }
return module; return module;
} }
@ -147,7 +150,10 @@ namespace refl
foreach (var cppClass in cpp.Classes) foreach (var cppClass in cpp.Classes)
{ {
var cls_meta = ParseCppClass(cppClass); var cls_meta = ParseCppClass(cppClass);
module.ClassList.Add(cls_meta); if(cls_meta.Fields.Count > 0)
{
module.ClassList.Add(cls_meta);
}
} }
foreach(var spaces in cpp.Namespaces) foreach(var spaces in cpp.Namespaces)
{ {

View File

@ -1,4 +1,6 @@
using Fluid; using Fluid;
using Microsoft.Extensions.Primitives;
using System.IO;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
@ -7,18 +9,29 @@ namespace refl
internal class Gen internal class Gen
{ {
public static Dictionary<string, StringBuilder> FileList = new Dictionary<string, StringBuilder>(); public static Dictionary<string, StringBuilder> FileList = new Dictionary<string, StringBuilder>();
public static StringBuilder Meta = new StringBuilder();
public static StringBuilder Output = new StringBuilder(); public static StringBuilder Output = new StringBuilder();
private ClassMetaData data = new ClassMetaData();
private GenMeta meta = new GenMeta(); private GenMeta meta = new GenMeta();
private GenMetaImpl metaImpl = new GenMetaImpl();
private GenMultyMeta multyMeta = new GenMultyMeta(); private GenMultyMeta multyMeta = new GenMultyMeta();
private Stack<string> nameSpaces = new Stack<string>();
public Gen() { } public Gen() { }
public static string PreprocessTemplate(string template, string indent, string newline)
{
// 替换占位符
return template.Replace("{{ Indent }}", indent);
}
public static bool InitTemplate(string dir) public static bool InitTemplate(string dir)
{ {
string meta_file = Path.Combine(dir, "meta.liquid"); string meta_file = Path.Combine(dir, "meta.liquid");
string meta_impl_file = Path.Combine(dir, "meta_impl.liquid");
string multy_meta_file = Path.Combine(dir, "multy_meta.liquid"); string multy_meta_file = Path.Combine(dir, "multy_meta.liquid");
var parser = new FluidParser(); var parser = new FluidParser();
return GenMeta.InitTemplate(meta_file, parser) && GenMultyMeta.InitTemplate(multy_meta_file, parser); return GenMeta.InitTemplate(meta_file, parser)
&& GenMetaImpl.InitTemplate(meta_impl_file, parser)
&& GenMultyMeta.InitTemplate(multy_meta_file, parser);
} }
public void CheckDir(string? dir) public void CheckDir(string? dir)
{ {
@ -29,17 +42,14 @@ namespace refl
} }
public void InitFile(string file_name) public void InitFile(string file_name)
{ {
Output.AppendLine("#pragma once"); Meta.AppendLine("#pragma once");
Meta.AppendLine("namespace refl_impl{");
foreach (var name in ModuleMeta.NameSet) foreach (var name in ModuleMeta.NameSet)
{ {
var build = new StringBuilder(); var build = new StringBuilder();
build.AppendLine("#pragma once"); build.AppendLine("#pragma once");
build.AppendLine("namespace refl_impl{");
FileList.Add(name, build); FileList.Add(name, build);
if (name == "Meta")
{
string path = $"Meta_{file_name}".ToLower();
Output.AppendLine($"#include \"{path}\"");
}
} }
} }
public void GenCppMeta(ModuleMeta module, string target) public void GenCppMeta(ModuleMeta module, string target)
@ -53,6 +63,8 @@ namespace refl
} }
public void OutFile(string file_name, string? dir,string target) public void OutFile(string file_name, string? dir,string target)
{ {
Meta.AppendLine("\r\n");
Output.AppendLine("}\r\n");
foreach (var pair in FileList) foreach (var pair in FileList)
{ {
string path = $"{pair.Key}_{file_name}".ToLower(); string path = $"{pair.Key}_{file_name}".ToLower();
@ -60,9 +72,20 @@ namespace refl
{ {
path = Path.Combine(dir, path); path = Path.Combine(dir, path);
} }
pair.Value.AppendLine("}\r\n");
File.WriteAllText(path, pair.Value.ToString()); File.WriteAllText(path, pair.Value.ToString());
if (pair.Key == "Meta")
{
path = $"Meta_{file_name}".ToLower();
Output.AppendLine($"#include \"{path}\"");
}
} }
File.WriteAllText(target, Output.ToString()); using (StreamWriter writer = new StreamWriter(target, false, Encoding.UTF8))
{
writer.Write(Meta.ToString());
writer.Write(Output.ToString());
}
} }
public void GenModuleMeta(ModuleMeta module, string? prefix) public void GenModuleMeta(ModuleMeta module, string? prefix)
{ {
@ -70,10 +93,9 @@ namespace refl
{ {
return; return;
} }
var data = new ClassMetaData(prefix + "", module.NameSpace);
if (prefix != null) if (prefix != null)
{ {
GenNamespaceBegin(data.Indent, data.NameSpace); nameSpaces.Push(module.NameSpace);
} }
foreach (var cls in module.ClassList) foreach (var cls in module.ClassList)
{ {
@ -86,38 +108,30 @@ namespace refl
} }
if (prefix != null) if (prefix != null)
{ {
GenNamespaceEnd(data.Indent); nameSpaces.Pop();
} }
} }
public string GenPrefix()
{
if (nameSpaces.Count > 0)
{
return string.Join("::", nameSpaces) + "::";
}
return "";
}
public void GenClassMeta(ClassMeta cls, ClassMetaData data) public void GenClassMeta(ClassMeta cls, ClassMetaData data)
{ {
if (meta.GenClassMeta(cls, data)) string fullName = GenPrefix() + cls.Name;
data.FullName = fullName;
bool isMulty = meta.GenClassMeta(cls, data);
Meta.Append(metaImpl.GenClassMeta(cls, fullName, isMulty));
Meta.AppendLine("");
if (isMulty)
{ {
var res = multyMeta.GenClassMeta(cls, data.Indent2); var res = multyMeta.GenClassMeta(cls, fullName);
Output.Append(res); Output.Append(res);
Output.AppendLine("");
} }
} }
public static void GenNamespaceBegin(string indent, string name_space)
{
string line = $"{indent}namespace {name_space} {{";
foreach (var name in ModuleMeta.NameSet)
{
FileList[name].AppendLine(line);
}
Output.AppendLine(line);
}
public static void GenNamespaceEnd(string indent)
{
string line = $"{indent}}}";
foreach (var name in ModuleMeta.NameSet)
{
FileList[name].AppendLine(line);
}
Output.AppendLine(line);
}
public static void Append(string name, string res)
{
FileList[name].Append(res);
}
} }
} }

View File

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Xml.Linq;
using Fluid; using Fluid;
namespace refl namespace refl
@ -20,30 +21,14 @@ namespace refl
internal class ClassMetaData internal class ClassMetaData
{ {
public string Name { get; set; } = ""; public string Name { get; set; } = "";
public string NameSpace { get; set; } = "";
public string ParentName { get; set; } = ""; public string ParentName { get; set; } = "";
public string Indent { get; set; } = ""; public string FullName { get; set; } = "";
public string Indent2 { get; set; } = "";
public string MetaName { get; set; } = ""; public string MetaName { get; set; } = "";
public bool IsMultyMeta { get; set; } = false; public bool IsMultyMeta { get; set; } = false;
public int MemberCount { get; set; } = 0; public int MemberCount { get; set; } = 0;
public int CtorCount { get; set; } = 0; public int CtorCount { get; set; } = 0;
public List<FieldMetaData> FieldList = new List<FieldMetaData>(); public List<FieldMetaData> FieldList = new List<FieldMetaData>();
public ClassMetaData(string indent, string nameSpace)
{
Indent = indent;
NameSpace = nameSpace;
if (string.IsNullOrEmpty(nameSpace))
{
Indent2 = indent;
}
else
{
Indent2 = indent + "\t";
}
}
} }
internal class GenMeta internal class GenMeta
@ -53,6 +38,7 @@ namespace refl
public static bool InitTemplate(string path, FluidParser parser) public static bool InitTemplate(string path, FluidParser parser)
{ {
var meta_string = File.ReadAllText(path); var meta_string = File.ReadAllText(path);
meta_string = Gen.PreprocessTemplate(meta_string, "\t", "\r\n");
parser.TryParse(meta_string, out template, out var error); parser.TryParse(meta_string, out template, out var error);
options.MemberAccessStrategy.Register<FieldMetaData>(); options.MemberAccessStrategy.Register<FieldMetaData>();
if (!string.IsNullOrEmpty(error)) if (!string.IsNullOrEmpty(error))
@ -89,7 +75,8 @@ namespace refl
isMulty = isMulty || data.IsMultyMeta; isMulty = isMulty || data.IsMultyMeta;
var context = new TemplateContext(data, options); var context = new TemplateContext(data, options);
var res = template.Render(context); var res = template.Render(context);
Gen.Append(pair.Key, res); Gen.FileList[pair.Key].Append(res);
Gen.FileList[pair.Key].AppendLine("");
} }
return isMulty; return isMulty;
} }

44
src/refl/GenMetaImpl.cs Normal file
View File

@ -0,0 +1,44 @@
using Fluid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace refl
{
internal class MetaImplClassData
{
public string Name { get; set; } = "";
public string FullName { get; set; } = "";
public bool IsMultyMeta { get; set; } = false;
}
internal class GenMetaImpl
{
private static IFluidTemplate? template;
private static TemplateOptions options = new TemplateOptions();
private MetaImplClassData impl = new MetaImplClassData();
public static bool InitTemplate(string path, FluidParser parser)
{
var meta_string = File.ReadAllText(path);
meta_string = Gen.PreprocessTemplate(meta_string, "\t", "\r\n");
parser.TryParse(meta_string, out template, out var error);
if (!string.IsNullOrEmpty(error))
{
Console.WriteLine(error);
return false;
}
return true;
}
public string GenClassMeta(ClassMeta cls,string fullName, bool isMulty)
{
impl.Name = cls.Name;
impl.FullName = fullName;
impl.IsMultyMeta = isMulty;
var context = new TemplateContext(impl, options);
return template.Render(context);
}
}
}

View File

@ -10,7 +10,7 @@ namespace refl
internal class MultyMetaClassData internal class MultyMetaClassData
{ {
public string Name { get; set; } = ""; public string Name { get; set; } = "";
public string Indent2 { get; set; } = ""; public string FullName { get; set; } = "";
public bool HasMeta { get; set; } = false; public bool HasMeta { get; set; } = false;
public List<string> MetaList = new List<string>(); public List<string> MetaList = new List<string>();
@ -22,6 +22,7 @@ namespace refl
public static bool InitTemplate(string path, FluidParser parser) public static bool InitTemplate(string path, FluidParser parser)
{ {
var meta_string = File.ReadAllText(path); var meta_string = File.ReadAllText(path);
meta_string = Gen.PreprocessTemplate(meta_string, "\t", "\r\n");
parser.TryParse(meta_string, out template, out var error); parser.TryParse(meta_string, out template, out var error);
if (!string.IsNullOrEmpty(error)) if (!string.IsNullOrEmpty(error))
{ {
@ -30,11 +31,11 @@ namespace refl
} }
return true; return true;
} }
public string GenClassMeta(ClassMeta cls, string indent) public string GenClassMeta(ClassMeta cls, string fullName)
{ {
MultyMetaClassData data = new MultyMetaClassData(); MultyMetaClassData data = new MultyMetaClassData();
data.Name = cls.Name; data.Name = cls.Name;
data.Indent2 = indent; data.FullName = fullName;
foreach (var pair in cls.Fields) foreach (var pair in cls.Fields)
{ {
if (pair.Key.Equals("Meta")) if (pair.Key.Equals("Meta"))

View File

@ -1,14 +1,33 @@
#pragma once #pragma once
#if !defined(__cppast)
#define __cppast(...)
#endif
#define __Meta(...) __cppast(Meta,__VA_ARGS__) #define __Meta(...) __cppast(Meta,__VA_ARGS__)
#define UPROPERTY(...) __Meta(__VA_ARGS__) #define UPROPERTY(...) __Meta(__VA_ARGS__)
#define UFUNCTION(...) __Meta(__VA_ARGS__) #define UFUNCTION(...) __Meta(__VA_ARGS__)
#define __vkMeta(...) __cppast(vkMeta,__VA_ARGS__) #define __vkMeta(...) __cppast(vkMeta,__VA_ARGS__)
#define UPROPERTY_vk(...) __vkMeta(__VA_ARGS__) #define UPROPERTY_vk(...) __vkMeta(__VA_ARGS__)
#define UFUNCTION_vk(...) __vkMeta(__VA_ARGS__) #define UFUNCTION_vk(...) __vkMeta(__VA_ARGS__)
#define __dxMeta(...) __cppast(dxMeta,__VA_ARGS__) #define __dxMeta(...) __cppast(dxMeta,__VA_ARGS__)
#define UPROPERTY_dx(...) __dxMeta(__VA_ARGS__) #define UPROPERTY_dx(...) __dxMeta(__VA_ARGS__)
#define UFUNCTION_dx(...) __dxMeta(__VA_ARGS__) #define UFUNCTION_dx(...) __dxMeta(__VA_ARGS__)
// 辅助宏,用于实际拼接
#define CONCATENATE(arg1, arg2) CONCATENATE_IMPL(arg1, arg2)
#define CONCATENATE_IMPL(arg1, arg2) arg1##arg2
#define UNIQUE_NAME(base) CONCATENATE(base, __LINE__)
#define OVERLOAD_CTOR_IMPL(Class, ...) using UNIQUE_NAME(__Ctor) = Class(*)(__VA_ARGS__);
#define OVERLOAD_FUNC_IMPL(Func, R, ...) using UNIQUE_NAME(__Func) = R(*)(__VA_ARGS__);
#define OVERLOAD_CTOR(Class, ...) OVERLOAD_CTOR_IMPL(Class, __VA_ARGS__);Class(__VA_ARGS__)
#define OVERLOAD_FUNC(Func, R, ...) OVERLOAD_FUNC_IMPL(Func, R, __VA_ARGS__);R Func(__VA_ARGS__)
namespace refl_impl {
struct Meta {};
struct vkMeta {};
struct dxMeta {};
}

View File

@ -1,75 +1,114 @@
#include <iostream>
#include "refl/refl.h" #include "refl/refl.h"
using namespace std; #include <objbase.h>
using namespace refl; using std::string_view;
struct vec3_parent { namespace engineapi {
virtual int norm(int x1, int& x2) { namespace test {
x2 = x1 * x2; struct vec1 {
return x2; UPROPERTY({})
//cout << x2 << "vec3_parent::norm" << endl; int x;
UPROPERTY({})
int y;
};
} }
}; struct Guid
struct vec3 : public vec3_parent { {
using MyMeta = class vec3_Meta; UPROPERTY_vk({})
UPROPERTY_vk({ 1.f }) UPROPERTY({})
float x = 1; unsigned int Data1;
UPROPERTY_dx({ 2.f }) UPROPERTY_vk({})
float y = 2; UPROPERTY({})
UPROPERTY({ 5.f }) unsigned short Data2;
float z = 3; UPROPERTY({})
UPROPERTY({ "hello meta" }) unsigned short Data3;
string name = "???"; UPROPERTY({})
UPROPERTY_vk({ 1.f }) unsigned char Data4[8];
UFUNCTION({}) constexpr Guid() noexcept
vec3() { : Data1{ 0 }, Data2{ 0 }, Data3{ 0 }, Data4{ 0,0,0,0,0,0,0,0 }
{}
UFUNCTION({})
Guid(const string_view& str) noexcept
: Guid{}
{
sscanf_s(str.data(),
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
&Data1, &Data2, &Data3,
&Data4[0], &Data4[1], &Data4[2], &Data4[3],
&Data4[4], &Data4[5], &Data4[6], &Data4[7]);
}
constexpr Guid(unsigned int a, unsigned short b, unsigned short c, unsigned long long d)
: Data1{ a }
, Data2{ b }
, Data3{ c }
, Data4{
(unsigned char)(d >> 56 & 0xFF)
, (unsigned char)(d >> 48 & 0xFF)
, (unsigned char)(d >> 40 & 0xFF)
, (unsigned char)(d >> 32 & 0xFF)
, (unsigned char)(d >> 24 & 0xFF)
, (unsigned char)(d >> 16 & 0xFF)
, (unsigned char)(d >> 8 & 0xFF)
, (unsigned char)(d >> 0 & 0xFF)
}
{};
auto operator<=>(const Guid&) const noexcept = default;
operator bool() const noexcept
{
return *reinterpret_cast<const GUID*>(this) != GUID_NULL;
}
operator string() const
{
return ToString();
}
UFUNCTION({})
string ToString() const
{
char guid_cstr[39];
snprintf(guid_cstr, sizeof(guid_cstr),
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
Data1, Data2, Data3,
Data4[0], Data4[1], Data4[2], Data4[3],
Data4[4], Data4[5], Data4[6], Data4[7]);
return string{ guid_cstr };
}
UFUNCTION({})
static Guid Make()
{
Guid guid;
const auto res = CoCreateGuid((GUID*)&guid);
return guid;
}
};
}
namespace work {
#include <iostream>
#include <string_view>
struct Guid2 {
};
struct Guid {
using __Ctor_1 = Guid (*)(const std::string_view, Guid2);
Guid(const std::string_view& str, Guid2) {
// Construct Guid from string_view (implementation to be added)
std::cout << "Guid constructed with: " << str << std::endl;
}
};
}
namespace meta {
template<typename T, typename... Args>
static T Ctor(Args... args) {
T obj(args...); // Construct object of type T (in this case, Guid)
return obj
} }
UPROPERTY_vk({ 1.f }) template<typename T, typename... Args>
UFUNCTION({}) static T(*)(Args...) CtorField() {
vec3(float x1) { return &Ctor<T, Args...>;
x = x1;
} }
UPROPERTY_dx({ 2.f }) void create_guid() {
UFUNCTION({}) using work::Guid;
vec3(float x1, float y1) { Guid::__Ctor_1* c1 = CtorField<Guid::__Ctor_1>();
x = x1; //...其他逻辑
y = y1;
} }
UFUNCTION({}) }
vec3(float x1, float y1, float z1) {
x = x1;
y = y1;
z = z1;
}
UFUNCTION({})
vec3(float x1, float y1, float z1, float w1) {
x = x1;
y = y1;
z = z1;
}
UFUNCTION({ {3,4} })
int norm(int x1, int& x2)override {
int tmp = x1 * 2 + 1;
x1 = x2;
x2 = tmp;
return x2;
//cout << x2 << "vec3::norm" << endl;
}
UFUNCTION({})
virtual float norm1(int& x1) {
x1 = x1 * x * y * z;
x = x1;
y = x1 - 1;
//z = x1 - 10;
//cout << x1 << "::norm1" << endl;
return x1;
}
UFUNCTION({})
static void norm2(int x1 = 10) {
cout << x1 << "::norm2" << endl;
}
UFUNCTION({})
static void norm3(int x1 = 10) {
x1 = x1 * 10;
cout << x1 << "::norm3" << endl;
}
};

View File

@ -20,4 +20,8 @@
<ProjectReference Include="..\CppAst\CppAst.csproj" /> <ProjectReference Include="..\CppAst\CppAst.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="cpp\gen\" />
</ItemGroup>
</Project> </Project>

View File

@ -1,56 +1,57 @@
{%- assign NewLine = newline_to_br -%} {{ Indent }}template<> struct _Static<{{FullName}},{{MetaName}}> {
{{ Indent2 }}struct {{ Name }}_Static_{{MetaName}} { {{ Indent }} using T = class {{FullName}};
{{ Indent2 }} consteval static auto __MakeStaticFields() { {{ Indent }} consteval static auto __MakeStaticFields() {
{{ Indent2 }} return std::array{ {{ Indent }} return std::array{
{{ NewLine }} {%- for field in FieldList -%} {{ Indent }} {%- for field in FieldList %}
{{ NewLine }} {%- if field.Type == 1 -%} {{ Indent }} {%- if field.Type == 1 %}
{{ Indent2 }} refl::StaticMemberField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"), {{field.Meta}}), {{ Indent }} refl::StaticMemberField(&T::{{field.Name}}, FName("{{field.Name}}"), {{field.Meta}}),
{{ NewLine }} {%- elsif field.Type == 2 -%} {{ Indent }} {%- elsif field.Type == 2 %}
{{ Indent2 }} refl::StaticCtorField<{{field.Name}}>({{field.Meta}}), {{ Indent }} refl::StaticCtorField<{{field.Name}}>({{field.Meta}}),
{{ NewLine }} {%- else -%} {{ Indent }} {%- else %}
{{ Indent2 }} refl::StaticMethodField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"), {{field.Meta}}), {{ Indent }} refl::StaticMethodField(&T::{{field.Name}}, FName("{{field.Name}}"), {{field.Meta}}),
{{ NewLine }} {%- endif -%} {{ Indent }} {%- endif %}
{{ NewLine }} {%- endfor -%} {{ Indent }} {%- endfor %}
{{ Indent2 }} }; {{ Indent }} };
{{ Indent2 }} }; {{ Indent }} };
{{ NewLine }} {{ Indent }}
{{ Indent2 }} consteval static int Size() { {{ Indent }} consteval static int Size() {
{{ Indent2 }} return refl::fetch_meta_size<{{ Name }}_Static_{{MetaName}}>(); {{ Indent }} return refl::fetch_meta_size<_Static<T,{{MetaName}}>>();
{{ Indent2 }} }; {{ Indent }} };
{{ Indent2 }} consteval static int MemberCount() { {{ Indent }} consteval static int MemberCount() {
{{ Indent2 }} return {{MemberCount}}; {{ Indent }} return {{MemberCount}};
{{ Indent2 }} }; {{ Indent }} };
{{ Indent2 }} consteval static int CtorCount() { {{ Indent }} consteval static int CtorCount() {
{{ Indent2 }} return {{CtorCount}}; {{ Indent }} return {{CtorCount}};
{{ Indent2 }} }; {{ Indent }} };
{{ Indent2 }}}; {{ Indent }}};
{{ NewLine }} {{ Indent }}
{{ Indent2 }}struct {{ Name }}_{{MetaName}} : public refl::Meta { {{ Indent }}template<> struct _Meta<{{FullName}},{{MetaName}}> : public refl::MetaHelp {
{{ Indent2 }} using MyUClass = refl::UClass_Meta<{{ Name }}, {{ ParentName }}>; {{ Indent }} using T = class {{FullName}};
{{ Indent2 }} using MyStatic = {{ Name }}_Static_{{MetaName}}; {{ Indent }} using MyParent = {{ ParentName }};
{{ NewLine }} {%-if IsMultyMeta -%} {{ Indent }} using MyStatic = _Static<T,{{MetaName}}>;
{{ Indent2 }} using MyMetas = class {{Name}}_MulytMeta; {{ Indent }} {%-if IsMultyMeta %}
{{ NewLine }} {%- endif -%} {{ Indent }} using MyMetas = class _Multy<T>;
{{ Indent2 }} inline static char s_data[MyStatic::Size()]{}; {{ Indent }} {%- endif %}
{{ Indent2 }} static auto __MakeFields() { {{ Indent }} inline static char s_data[MyStatic::Size()]{};
{{ Indent2 }} char* memory = &s_data[0]; {{ Indent }} static auto __MakeFields() {
{{ Indent2 }} return std::array{ {{ Indent }} char* memory = &s_data[0];
{{ NewLine }} {%- for field in FieldList -%} {{ Indent }} return std::array{
{{ NewLine }} {%- if field.Type == 1 -%} {{ Indent }} {%- for field in FieldList %}
{{ Indent2 }} MemberField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"), memory, {{field.Meta}}), {{ Indent }} {%- if field.Type == 1 %}
{{ NewLine }} {%- elsif field.Type == 2 -%} {{ Indent }} MemberField(&T::{{field.Name}}, FName("{{field.Name}}"), memory, {{field.Meta}}),
{{ Indent2 }} CtorField<{{field.Name}}>(memory, {{field.Meta}}), {{ Indent }} {%- elsif field.Type == 2 %}
{{ NewLine }} {%- else -%} {{ Indent }} CtorField<{{field.Name}}>(memory, {{field.Meta}}),
{{ Indent2 }} MethodField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"), memory, {{field.Meta}}), {{ Indent }} {%- else %}
{{ NewLine }} {%- endif -%} {{ Indent }} MethodField(&T::{{field.Name}}, FName("{{field.Name}}"), memory, {{field.Meta}}),
{{ NewLine }} {%- endfor -%} {{ Indent }} {%- endif %}
{{ Indent2 }} }; {{ Indent }} {%- endfor %}
{{ Indent2 }} }; {{ Indent }} };
{{ Indent2 }}}; {{ Indent }} };
{{ NewLine }}{%- if IsMultyMeta -%} {{ Indent }}};
{{ Indent2 }}const refl::UClass* {{Name}}_MulytMeta::{{ MetaName }}() {{ Indent }}{%- if IsMultyMeta %}
{{ Indent2 }}{ {{ Indent }}template<> const refl::UClass* _Multy<{{FullName}}>::{{ MetaName }}()
{{ Indent2 }} static const auto s_cls = {{ Name }}_{{MetaName}}::MyUClass(); {{ Indent }}{
{{ Indent2 }} return &s_cls; {{ Indent }} static const auto s_cls = refl::UClass_Meta<T, _Meta<T,{{ MetaName }}>>::BuildClass();
{{ Indent2 }}}; {{ Indent }} return &s_cls;
{{ NewLine }}{%- endif -%} {{ Indent }}};
{{ Indent }}{%- endif %}

View File

@ -0,0 +1,7 @@
{{ Indent }}template<> struct MetaImpl<{{FullName}}>{
{{ Indent }} using T = class {{FullName}};
{{ Indent }} using MyMeta = _Meta<T, Meta>;
{{ Indent }}{%- if IsMultyMeta %}
{{ Indent }} using MyMetas = _Multy<T>;
{{ Indent }}{%- endif %}
{{ Indent }}};

View File

@ -1,20 +1,19 @@
{%- assign NewLine = newline_to_br -%} {{ Indent }}template<> struct _Multy<{{FullName}}>{
{{ Indent2 }}struct {{Name}}_MulytMeta { {{ Indent }} using T = class {{FullName}};
{{ NewLine }}{%- for Meta in MetaList -%} {{ Indent }}{%- for Meta in MetaList %}
{{ Indent2 }} static const refl::UClass* {{Meta}}(); {{ Indent }} static const refl::UClass* {{Meta}}();
{{ NewLine }}{%- endfor -%} {{ Indent }}{%- endfor %}
{{ Indent2 }} static const refl::UClass* GetMeta(const Name& name) { {{ Indent }} static const refl::UClass* GetMeta(const Name& name) {
{{ NewLine }}{%- for Meta in MetaList -%} {{ Indent }}{%- for Meta in MetaList %}
{{ Indent2 }} if (name == FName("{{Meta}}")) { {{ Indent }} if (name == FName("{{Meta}}")) {
{{ Indent2 }} return {{Meta}}(); {{ Indent }} return {{Meta}}();
{{ Indent2 }} } {{ Indent }} }
{{ NewLine }}{%- endfor -%} {{ Indent }}{%- endfor %}
{{ NewLine }}{%- if HasMeta -%} {{ Indent }}{%- if HasMeta %}
{{ Indent2 }} if (name == FName("Meta")) { {{ Indent }} if (name == FName("Meta")) {
{{ Indent2 }} return &refl::TypeInfo<{{Name}}>::StaticClass; {{ Indent }} return &refl::TypeInfo<T>::StaticClass;
{{ Indent2 }} } {{ Indent }} }
{{ NewLine }}{%- endif -%} {{ Indent }}{%- endif %}
{{ Indent2 }} return nullptr; {{ Indent }} return nullptr;
{{ Indent2 }} } {{ Indent }} }
{{ Indent2 }}}; {{ Indent }}};
{{ NewLine }}