update fluid
This commit is contained in:
parent
35fcd147d8
commit
b4fa0405fc
@ -428,7 +428,7 @@ namespace CppAst
|
||||
// Don't emit warning
|
||||
break;
|
||||
default:
|
||||
WarningUnhandled(cursor, parent);
|
||||
//WarningUnhandled(cursor, parent);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1879,7 +1879,7 @@ namespace CppAst
|
||||
case CXTypeKind.CXType_DependentSizedArray:
|
||||
{
|
||||
// TODO: this is not yet supported
|
||||
RootCompilation.Diagnostics.Warning($"Dependent sized arrays `{type}` from `{parent}` is not supported", GetSourceLocation(parent.Location));
|
||||
//RootCompilation.Diagnostics.Warning($"Dependent sized arrays `{type}` from `{parent}` is not supported", GetSourceLocation(parent.Location));
|
||||
var elementType = GetCppType(type.ArrayElementType.Declaration, type.ArrayElementType, parent, data);
|
||||
return new CppArrayType(elementType, (int)type.ArraySize);
|
||||
}
|
||||
@ -1910,7 +1910,7 @@ namespace CppAst
|
||||
|
||||
default:
|
||||
{
|
||||
WarningUnhandled(cursor, parent, type);
|
||||
//WarningUnhandled(cursor, parent, type);
|
||||
return new CppUnexposedType(type.ToString()) { SizeOf = (int)type.SizeOf };
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,18 +8,22 @@ namespace refl
|
||||
[Value(0, MetaName = "", Required = true, Min = 2, HelpText = "Input file(s) for parsing.")]
|
||||
public IEnumerable<string>? InputFiles { get; set; }
|
||||
|
||||
[Option('o', "output", Required = false, HelpText = "Output file for generated code.")]
|
||||
public string OutputFile { get; set; } = "";
|
||||
[Option('o', "output", Required = true, HelpText = "Output file for generated code.")]
|
||||
public string Output { get; set; } = "";
|
||||
|
||||
[Option('t', "type", Required = false, HelpText = "Type of code to generate.")]
|
||||
public string CodeType { get; set; } = "";
|
||||
[Option('t', "template", Required = true, HelpText = "the code template need to render")]
|
||||
public string Template { get; set; } = "";
|
||||
|
||||
[Option('i', "include", Required = false, HelpText = "link to the include dir")]
|
||||
public string IncludeDir { get; set; } = "";
|
||||
|
||||
[Option('l', "link", Required = false, HelpText = "link to the include dir")]
|
||||
public string Link { get; set; } = "";
|
||||
|
||||
[Option('d', "define", Required = false, HelpText = "define a macro on the command line")]
|
||||
public string Define { get; set; } = "";
|
||||
|
||||
[Option('v', "verbose", Required = false, HelpText = "output compile info")]
|
||||
public bool Verbose { get; set; } = false;
|
||||
|
||||
[Option('h', "help", HelpText = "Display this help message.")]
|
||||
public bool Help { get; set; } = false;
|
||||
|
||||
@ -39,9 +43,9 @@ namespace refl
|
||||
parse.Defines.Add(def);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(opt.Link))
|
||||
if (!string.IsNullOrWhiteSpace(opt.IncludeDir))
|
||||
{
|
||||
var links = opt.Link.Split(";");
|
||||
var links = opt.IncludeDir.Split(";");
|
||||
foreach (var ink in links)
|
||||
{
|
||||
parse.IncludeFolders.Add(ink);
|
||||
@ -51,19 +55,25 @@ namespace refl
|
||||
}
|
||||
public static int CMD_CheckBuildOption(CmdBuildOption opt)
|
||||
{
|
||||
if(opt.InputFiles == null)
|
||||
if(opt.InputFiles == null || !ClassMetaGen.InitTemplate(opt.Template))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var parse_opt = MakeParserOptions(opt);
|
||||
var compilation = CppAst.CppParser.ParseFiles(opt.InputFiles.Skip(1).ToList(), parse_opt);
|
||||
// Print diagnostic messages
|
||||
foreach (var message in compilation.Diagnostics.Messages)
|
||||
if(message.Type.Equals(CppLogMessageType.Error))
|
||||
Console.WriteLine(message);
|
||||
if (opt.Verbose)
|
||||
{
|
||||
// Print diagnostic messages
|
||||
foreach (var message in compilation.Diagnostics.Messages)
|
||||
if (message.Type.Equals(CppLogMessageType.Error))
|
||||
Console.WriteLine(message);
|
||||
}
|
||||
var module = ModuleMeta.ParseCompileInfo(compilation);
|
||||
ClassMetaGen.GenNameMeta();
|
||||
ClassMetaGen.GenCppMeta(module);
|
||||
ClassMetaGen.GenCppMeta(module, opt.Output.ToLower());
|
||||
if (opt.Verbose)
|
||||
{
|
||||
Console.WriteLine("gen success!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ namespace refl
|
||||
}
|
||||
internal class ModuleMeta
|
||||
{
|
||||
public static Dictionary<string, HashSet<string>> NameMaps = new Dictionary<string, HashSet<string>>();
|
||||
public static HashSet<string> NameSet = new HashSet<string>();
|
||||
public string NameSpace { get; set; }
|
||||
public List<ClassMeta> ClassList;
|
||||
public List<ModuleMeta> ChildList;
|
||||
@ -133,41 +133,26 @@ namespace refl
|
||||
var child = ParseCppNamespaces(spaces);
|
||||
module.ChildList.Add(child);
|
||||
}
|
||||
ParseNameMap(module);
|
||||
ParseMetaName(module);
|
||||
return module;
|
||||
}
|
||||
public static void ParseNameMap(ModuleMeta module)
|
||||
public static void ParseMetaName(ModuleMeta module)
|
||||
{
|
||||
ParseClassNameMap(module);
|
||||
ParseClassMetaName(module);
|
||||
foreach(var child in module.ChildList)
|
||||
{
|
||||
ParseNameMap(child);
|
||||
ParseMetaName(child);
|
||||
}
|
||||
}
|
||||
public static void ParseClassNameMap(ModuleMeta module)
|
||||
public static void ParseClassMetaName(ModuleMeta module)
|
||||
{
|
||||
foreach(var cls in module.ClassList)
|
||||
{
|
||||
foreach(var field in cls.Fields)
|
||||
{
|
||||
if (!NameMaps.ContainsKey(field.Key))
|
||||
if (!NameSet.Contains(field.Key))
|
||||
{
|
||||
NameMaps.Add(field.Key, new HashSet<string>());
|
||||
}
|
||||
var nameList = NameMaps[field.Key];
|
||||
foreach(var member in field.Value.MemberList)
|
||||
{
|
||||
if (!nameList.Contains(member.Name))
|
||||
{
|
||||
nameList.Add(member.Name);
|
||||
}
|
||||
}
|
||||
foreach (var method in field.Value.MethodList)
|
||||
{
|
||||
if (!nameList.Contains(method.Name))
|
||||
{
|
||||
nameList.Add(method.Name);
|
||||
}
|
||||
NameSet.Add(field.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Fluid;
|
||||
|
||||
namespace refl
|
||||
@ -37,45 +38,40 @@ namespace refl
|
||||
public static Dictionary<string, StringBuilder> FileList = new Dictionary<string, StringBuilder>();
|
||||
public static Fluid.IFluidTemplate? GenTemplate;
|
||||
public static TemplateOptions GenOptions = new TemplateOptions();
|
||||
public static void GenNameMeta()
|
||||
public static bool InitTemplate(string path)
|
||||
{
|
||||
foreach (var pair in ModuleMeta.NameMaps)
|
||||
{
|
||||
var build = new StringBuilder();
|
||||
build.Append("namespace ");
|
||||
build.Append(pair.Key);
|
||||
build.Append("_Name {\n");
|
||||
foreach(var kv in pair.Value)
|
||||
{
|
||||
build.Append(" constexpr const Name ");
|
||||
build.Append(kv);
|
||||
build.Append("=\"");
|
||||
build.Append(kv);
|
||||
build.Append("\";\n");
|
||||
}
|
||||
build.Append("}\n");
|
||||
Console.WriteLine(build.ToString());
|
||||
build.Clear();
|
||||
FileList.Add(pair.Key, build);
|
||||
}
|
||||
}
|
||||
public static void GenCppMeta(ModuleMeta module)
|
||||
{
|
||||
var template_string = File.ReadAllText("template/refl.liquid");
|
||||
var template_string = File.ReadAllText(path);
|
||||
var parser = new FluidParser();
|
||||
parser.TryParse(template_string, out GenTemplate, out var error);
|
||||
GenOptions.MemberAccessStrategy.Register<FieldMetaGenData>();
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
Console.WriteLine(error);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static void GenCppMeta(ModuleMeta module, string target)
|
||||
{
|
||||
foreach (var name in ModuleMeta.NameSet)
|
||||
{
|
||||
FileList.Add(name, new StringBuilder());
|
||||
}
|
||||
GenModuleMeta(module, null);
|
||||
string file_name = Path.GetFileName(target);
|
||||
string? dir = Path.GetDirectoryName(target);
|
||||
var output = new StringBuilder();
|
||||
foreach (var pair in FileList)
|
||||
{
|
||||
Console.WriteLine(pair.Key);
|
||||
Console.WriteLine(pair.Value.ToString());
|
||||
string path = $"{pair.Key}_{file_name}".ToLower();
|
||||
output.AppendLine($"#include \"{path}\"");
|
||||
if (dir != null)
|
||||
{
|
||||
path = Path.Combine(dir, path);
|
||||
}
|
||||
File.WriteAllText(path, pair.Value.ToString());
|
||||
}
|
||||
File.WriteAllText(target, output.ToString());
|
||||
}
|
||||
public static void GenModuleMeta(ModuleMeta module, string? prefix)
|
||||
{
|
||||
|
||||
@ -2,8 +2,7 @@
|
||||
"profiles": {
|
||||
"refl": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "build D:\\csharp\\cppast\\src\\refl\\cpp\\vertex.h ",
|
||||
"workingDirectory": "D:\\csharp\\cppast\\src\\refl"
|
||||
"commandLineArgs": "build F:\\csharp\\CppAst.NET\\src\\refl\\cpp\\vertex.h -o F:\\csharp\\CppAst.NET\\src\\refl\\cpp\\vertex_gen.inl -t F:\\csharp\\CppAst.NET\\src\\refl\\template\\refl.liquid -v"
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/refl/cpp/meta_vertex_gen.inl
Normal file
34
src/refl/cpp/meta_vertex_gen.inl
Normal file
@ -0,0 +1,34 @@
|
||||
struct vec3_Static_Meta {
|
||||
consteval static auto __StaticFields() {
|
||||
return std::make_tuple(&vec3::x, &vec3::y, &vec3::z, &vec3::norm);
|
||||
};
|
||||
|
||||
consteval static auto __MakeStaticFields() {
|
||||
return std::array{
|
||||
StaticMemberField(&vec3::x, FName("x"), { 0.f}),
|
||||
StaticMemberField(&vec3::y, FName("y"), { 0.f}),
|
||||
StaticMemberField(&vec3::z, FName("z"), { 0.f}),
|
||||
StaticMethodField(&vec3::norm, FName("norm"), { {3,4} }),
|
||||
};
|
||||
};
|
||||
|
||||
consteval static int Size() {
|
||||
return fetch_meta_size<vec3_Static_Meta>();
|
||||
};
|
||||
};
|
||||
|
||||
struct vec3_Meta : public Meta {
|
||||
using MyStatic = vec3_Static_Meta;
|
||||
using MyUClass = UClass_Meta<vec3, vec3_parent>;;
|
||||
inline static char s_data[MyStatic::Size()]{};
|
||||
static auto __MakeFields() {
|
||||
char* memory = &s_data[0];
|
||||
return std::array{
|
||||
StaticMemberField(&vec3::x, FName("x"), { 0.f}),
|
||||
StaticMemberField(&vec3::y, FName("y"), { 0.f}),
|
||||
StaticMemberField(&vec3::z, FName("z"), { 0.f}),
|
||||
StaticMethodField(&vec3::norm, FName("norm"), { {3,4} }),
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
28
src/refl/cpp/uimeta_vertex_gen.inl
Normal file
28
src/refl/cpp/uimeta_vertex_gen.inl
Normal file
@ -0,0 +1,28 @@
|
||||
struct vec3_Static_UIMeta {
|
||||
consteval static auto __StaticFields() {
|
||||
return std::make_tuple(&vec3::x);
|
||||
};
|
||||
|
||||
consteval static auto __MakeStaticFields() {
|
||||
return std::array{
|
||||
StaticMemberField(&vec3::x, FName("x"), {1.f}),
|
||||
};
|
||||
};
|
||||
|
||||
consteval static int Size() {
|
||||
return fetch_meta_size<vec3_Static_UIMeta>();
|
||||
};
|
||||
};
|
||||
|
||||
struct vec3_UIMeta : public Meta {
|
||||
using MyStatic = vec3_Static_UIMeta;
|
||||
using MyUClass = UClass_Meta<vec3, vec3_parent>;;
|
||||
inline static char s_data[MyStatic::Size()]{};
|
||||
static auto __MakeFields() {
|
||||
char* memory = &s_data[0];
|
||||
return std::array{
|
||||
StaticMemberField(&vec3::x, FName("x"), {1.f}),
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
2
src/refl/cpp/vertex_gen.inl
Normal file
2
src/refl/cpp/vertex_gen.inl
Normal file
@ -0,0 +1,2 @@
|
||||
#include "meta_vertex_gen.inl"
|
||||
#include "uimeta_vertex_gen.inl"
|
||||
@ -1,37 +0,0 @@
|
||||
#include "vertex.h"
|
||||
|
||||
struct vec3_Static_Meta {
|
||||
//这里好像不需要
|
||||
consteval static auto __StaticFields() {
|
||||
return std::make_tuple(&vec3::x, &vec3::y, &vec3::z, &vec3::norm, &vec3::norm1, &vec3::norm2);
|
||||
};
|
||||
consteval static auto __MakeStaticFields() {
|
||||
return std::array{
|
||||
StaticMemberField(&vec3::x, "x",10.f),
|
||||
StaticMemberField(&vec3::y, "y",7.f),
|
||||
StaticMemberField(&vec3::z, "z",10.f),
|
||||
StaticMethodField(&vec3::norm, "norm", { 10,9 }),
|
||||
StaticMethodField(&vec3::norm1, "norm1", { 10 }),
|
||||
StaticMethodField(&vec3::norm2, "norm2", { 10 }),
|
||||
};
|
||||
}
|
||||
consteval static int Size() {
|
||||
return fetch_meta_size<vec3_Static_Meta>();
|
||||
}
|
||||
};
|
||||
struct vec3_Meta : public Meta{
|
||||
using MyStatic = vec3_Static_Meta;
|
||||
using MyUClass = UClass_Meta<vec3, vec3_parent>;
|
||||
inline static char s_data[MyStatic::Size()]{};
|
||||
static auto __MakeFields() {
|
||||
char* memory = &s_data[0];
|
||||
return std::array{
|
||||
MemberField(&vec3::x, "x",{}, memory, 10.f),
|
||||
MemberField(&vec3::y, "y",{}, memory, 7.f),
|
||||
MemberField(&vec3::z, "z",{}, memory, 6.f),
|
||||
MethodField(&vec3::norm, "norm", {}, memory, {10,9}),
|
||||
MethodField(&vec3::norm1, "norm1",{},memory, {10}),
|
||||
MethodField(&vec3::norm2, "norm2",{},memory, {10}),
|
||||
};
|
||||
};
|
||||
};
|
||||
@ -1 +0,0 @@
|
||||
struct vec3_Meta;
|
||||
@ -13,9 +13,9 @@
|
||||
{{ indent }} return std::array{
|
||||
{{ indent }} {%- for field in FieldList -%}
|
||||
{{ indent }} {%- if field.IsMethod -%}
|
||||
{{ indent }} StaticMethodField(&{{Name}}::{{field.Name}}, {{MetaName}}_Name::{{field.Name}}{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} StaticMethodField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"){% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {%- else -%}
|
||||
{{ indent }} StaticMemberField(&{{Name}}::{{field.Name}}, {{MetaName}}_Name::{{field.Name}}{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} StaticMemberField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"){% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {%- endif -%}
|
||||
{{ indent }} {%- endfor -%}
|
||||
{{ indent }} };
|
||||
@ -35,9 +35,9 @@
|
||||
{{ indent }} return std::array{
|
||||
{{ indent }} {%- for field in FieldList -%}
|
||||
{{ indent }} {%- if field.IsMethod -%}
|
||||
{{ indent }} StaticMethodField(&{{Name}}::{{field.Name}}, {{MetaName}}_Name::{{field.Name}}{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} StaticMethodField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"){% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {%- else -%}
|
||||
{{ indent }} StaticMemberField(&{{Name}}::{{field.Name}}, {{MetaName}}_Name::{{field.Name}}{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} StaticMemberField(&{{Name}}::{{field.Name}}, FName("{{field.Name}}"){% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {%- endif -%}
|
||||
{{ indent }} {%- endfor -%}
|
||||
{{ indent }} };
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
{% assign indent = Indent %}
|
||||
{% if NameSpace %}
|
||||
{{ indent }}namespace {{ NameSpace }} {
|
||||
{% capture newIndent %}{{ indent }} {% endcapture %}
|
||||
{% assign indent = newIndent %}
|
||||
{% endif %}
|
||||
{{ indent }}struct {{ Name }}_Static_{{MetaName}} {
|
||||
{{ indent }} consteval static auto __StaticFields() {
|
||||
{{ indent }} return std::make_tuple({% for field in FieldList %}&{{Name}}::{{field.Name}}{% unless forloop.last %}, {% endunless %}{% endfor %});
|
||||
{{ indent }} };
|
||||
|
||||
{{ indent }} consteval static auto __MakeStaticFields() {
|
||||
{{ indent }} return std::array{
|
||||
{{ indent }} {% for field in FieldList %}
|
||||
{{ indent }} {% if field.IsMethod %}
|
||||
{{ indent }} StaticMethodField(&{{field.Name}}, "{{field.Name}}"{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {% else %}
|
||||
{{ indent }} StaticMemberField(&{{field.Name}}, "{{field.Name}}"{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {% endif %}
|
||||
{{ indent }} {% endfor %}
|
||||
{{ indent }} };
|
||||
{{ indent }} };
|
||||
|
||||
{{ indent }} consteval static int Size() {
|
||||
{{ indent }} return fetch_meta_size<{{ staticMetaStructName }}>();
|
||||
{{ indent }} };
|
||||
{{ indent }}};
|
||||
|
||||
{{ indent }}struct {{ Name }}_{{MetaName}} : public Meta {
|
||||
{{ indent }} using MyStatic = {{ Name }}_Static_{{MetaName}};
|
||||
{{ indent }} using MyUClass = UClass_Meta<{{ Name }}, {{ ParentName }}>;;
|
||||
{{ indent }} inline static char s_data[MyStatic::Size()]{};
|
||||
{{ indent }} static auto __MakeFields() {
|
||||
{{ indent }} char* memory = &s_data[0];
|
||||
{{ indent }} return std::array{
|
||||
{{ indent }} {% for field in FieldList %}
|
||||
{{ indent }} {% if field.IsMethod %}
|
||||
{{ indent }} StaticMethodField(&{{field.Name}}, "{{field.Name}}"{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {% else %}
|
||||
{{ indent }} StaticMemberField(&{{field.Name}}, "{{field.Name}}"{% if field.Meta %}, {{field.Meta}}{% endif %}),
|
||||
{{ indent }} {% endif %}
|
||||
{{ indent }} {% endfor %}
|
||||
{{ indent }} };
|
||||
{{ indent }} };
|
||||
{{ indent }}};
|
||||
{% if namespace %}
|
||||
{% for ns in namespace %}
|
||||
{{ indent }}}
|
||||
{% capture newIndent %}{{ indent | slice: 0, -4 }}{% endcapture %}
|
||||
{% assign indent = newIndent %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
Loading…
Reference in New Issue
Block a user