diff --git a/src/refl/BuildOption.cs b/src/refl/BuildOption.cs index 1c3f578..8e3b8ec 100644 --- a/src/refl/BuildOption.cs +++ b/src/refl/BuildOption.cs @@ -1,6 +1,8 @@ using CommandLine; using CppAst; using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; namespace refl { [Verb("build",HelpText = "Generate custom code based on the parsed AST.")] @@ -30,6 +32,7 @@ namespace refl [Option('h', "help", HelpText = "Display this help message.")] public bool Help { get; set; } = false; + static string InputFile = "cpp_input.h"; static CppParserOptions MakeParserOptions(CmdBuildOption opt) { var parse = new CppParserOptions @@ -56,6 +59,19 @@ namespace refl } return parse; } + public static List PrepareFileList(List file_list) + { + StringBuilder code = new StringBuilder(); + foreach (var file in file_list) + { + string fileContent = File.ReadAllText(file); + code.AppendLine(fileContent.Replace("#include", "//#include")); + } + file_list.Clear(); + file_list.Add(InputFile); + File.WriteAllText(InputFile, code.ToString()); + return file_list; + } public static int CMD_CheckBuildOption(CmdBuildOption opt) { if(opt.InputFiles == null || !Gen.InitTemplate(opt.Template)) @@ -73,7 +89,7 @@ namespace refl { file_list = opt.InputFiles.Skip(1).ToList(); } - var compilation = CppAst.CppParser.ParseFiles(file_list, parse_opt); + var compilation = CppAst.CppParser.ParseFiles(PrepareFileList(file_list), parse_opt); if (opt.Verbose) { // Print diagnostic messages diff --git a/src/refl/Gen.cs b/src/refl/Gen.cs index 0501dc2..b087c1c 100644 --- a/src/refl/Gen.cs +++ b/src/refl/Gen.cs @@ -63,8 +63,8 @@ namespace refl } public void OutFile(string file_name, string? dir,string target) { - Meta.AppendLine("\r\n"); - Output.AppendLine("}\r\n"); + Meta.AppendLine(""); + Output.AppendLine("}"); foreach (var pair in FileList) { string path = $"{pair.Key}_{file_name}".ToLower(); @@ -72,7 +72,7 @@ namespace refl { path = Path.Combine(dir, path); } - pair.Value.AppendLine("}\r\n"); + pair.Value.AppendLine("}"); File.WriteAllText(path, pair.Value.ToString()); if (pair.Key == "Meta") { diff --git a/src/refl/GenMeta.cs b/src/refl/GenMeta.cs index 4bf167b..8012eab 100644 --- a/src/refl/GenMeta.cs +++ b/src/refl/GenMeta.cs @@ -54,7 +54,7 @@ namespace refl { data.Name = cls.Name; data.ParentName = cls.ParentName; - bool isMulty = cls.Fields.Count > 0; + bool isMulty = cls.Fields.Count > 1; foreach (var pair in cls.Fields) { data.FieldList.Clear(); @@ -74,7 +74,7 @@ namespace refl data.MemberCount = pair.Value.MemberList.Count; data.CtorCount = pair.Value.CtorList.Count; data.MetaType = isMulty ? 1 : 0; - if (pair.Key.Equals("Meta")) + if (isMulty && pair.Key.Equals("Meta")) { data.MetaType = 2; } diff --git a/src/refl/cpp/vertex.h b/src/refl/cpp/vertex.h index d1c58c5..88ae6d2 100644 --- a/src/refl/cpp/vertex.h +++ b/src/refl/cpp/vertex.h @@ -1,86 +1,32 @@ -#include "refl/refl.h" -#include -#include -#include -using std::string; -using std::vector; - -using std::string_view; -namespace test { - struct Guid +#pragma once +#include "type.h" +#include "guid.h" +#include "resource_bundle.h" +namespace engineapi +{ + struct SerializedMeta { UPROPERTY({}) - unsigned int Data1; + Guid guid; UPROPERTY({}) - unsigned short Data2; + string name; UPROPERTY({}) - unsigned short Data3; + string t_hash{}; UPROPERTY({}) - unsigned char Data4[8]; - constexpr Guid() noexcept - : Data1{ 0 }, Data2{ 0 }, Data3{ 0 }, Data4{ 0,0,0,0,0,0,0,0 } - {} + string metadata; + }; + struct ResourceBundle; - USING_OVERLOAD_CTOR(Guid, const string_view&) - UFUNCTION({}, ref = USING_CTOR_NAME) - Guid(const std::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]); + struct MetaBundle + { + UPROPERTY({}) + vector metadatas; - } - 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(this) != GUID_NULL; - } - USING_OVERLOAD_CLASS_FUNC(void, Guid, int) - UFUNCTION({}, ref = USING_FUNC_NAME) - void test(int x) { - - } - USING_OVERLOAD_FUNC(void, Guid, float) - UFUNCTION({}, ref = USING_FUNC_NAME) - void test(float x) { - - } - operator std::string() 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 std::string{ guid_cstr }; - } - static Guid Make() - { - Guid guid; - const auto res = CoCreateGuid((GUID*)&guid); - return guid; - } + MetaBundle() = default; + template + const SerializedMeta* FetchMeta() const; }; } - -#include "guid_gen.inl" \ No newline at end of file +#include "meta_bundle.inl" +#include "meta_bundle_gen.inl" \ No newline at end of file diff --git a/src/refl/refl.csproj b/src/refl/refl.csproj index 12fbd9b..35afad8 100644 --- a/src/refl/refl.csproj +++ b/src/refl/refl.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/src/refl/template/meta.liquid b/src/refl/template/meta.liquid index 7c96ae1..75a5429 100644 --- a/src/refl/template/meta.liquid +++ b/src/refl/template/meta.liquid @@ -58,7 +58,7 @@ {{ Indent }} static const auto s_cls = refl::UClass_Meta>(); {{ Indent }} return &s_cls; {{ Indent }}}; -{{ Indent }}{%- else %} +{{ Indent }}{%- elsif MetaType == 2 %} {{ Indent }}inline const refl::UClass* _Multy<{{FullName}}>::get_{{ MetaName }}() {{ Indent }}{ {{ Indent }} return &refl::TypeInfo::StaticClass;