2024-04-29 01:07:26 +08:00
|
|
|
|
using Fluid;
|
|
|
|
|
|
using System.Text;
|
2024-04-29 14:58:45 +08:00
|
|
|
|
using System.Xml.Linq;
|
2024-04-29 01:07:26 +08:00
|
|
|
|
|
|
|
|
|
|
namespace refl
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class Gen
|
|
|
|
|
|
{
|
|
|
|
|
|
public static Dictionary<string, StringBuilder> FileList = new Dictionary<string, StringBuilder>();
|
|
|
|
|
|
public static StringBuilder Output = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
private GenMeta meta = new GenMeta();
|
|
|
|
|
|
private GenMultyMeta multyMeta = new GenMultyMeta();
|
|
|
|
|
|
public Gen() { }
|
|
|
|
|
|
|
|
|
|
|
|
public static bool InitTemplate(string dir)
|
|
|
|
|
|
{
|
|
|
|
|
|
string meta_file = Path.Combine(dir, "meta.liquid");
|
2024-04-29 14:58:45 +08:00
|
|
|
|
string multy_meta_file = Path.Combine(dir, "multy_meta.liquid");
|
2024-04-29 01:07:26 +08:00
|
|
|
|
var parser = new FluidParser();
|
|
|
|
|
|
return GenMeta.InitTemplate(meta_file, parser) && GenMultyMeta.InitTemplate(multy_meta_file, parser);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void CheckDir(string? dir)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dir != null && !Directory.Exists(dir))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void InitFile(string file_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
Output.AppendLine("#pragma once");
|
|
|
|
|
|
foreach (var name in ModuleMeta.NameSet)
|
|
|
|
|
|
{
|
|
|
|
|
|
var build = new StringBuilder();
|
|
|
|
|
|
build.AppendLine("#pragma once");
|
|
|
|
|
|
FileList.Add(name, build);
|
|
|
|
|
|
if (name == "Meta")
|
|
|
|
|
|
{
|
|
|
|
|
|
string path = $"Meta_{file_name}".ToLower();
|
|
|
|
|
|
Output.AppendLine($"#include \"{path}\"");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void GenCppMeta(ModuleMeta module, string target)
|
|
|
|
|
|
{
|
|
|
|
|
|
string file_name = Path.GetFileName(target);
|
|
|
|
|
|
string? dir = Path.GetDirectoryName(target);
|
|
|
|
|
|
CheckDir(dir);
|
|
|
|
|
|
InitFile(file_name);
|
|
|
|
|
|
GenModuleMeta(module, null);
|
|
|
|
|
|
OutFile(file_name, dir, target);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OutFile(string file_name, string? dir,string target)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var pair in FileList)
|
|
|
|
|
|
{
|
|
|
|
|
|
string path = $"{pair.Key}_{file_name}".ToLower();
|
|
|
|
|
|
if (dir != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
path = Path.Combine(dir, path);
|
|
|
|
|
|
}
|
|
|
|
|
|
File.WriteAllText(path, pair.Value.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
File.WriteAllText(target, Output.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
public void GenModuleMeta(ModuleMeta module, string? prefix)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!module.HasMeta())
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var data = new ClassMetaData(prefix + "", module.NameSpace);
|
|
|
|
|
|
if (prefix != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
GenNamespaceBegin(data.Indent, data.NameSpace);
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var cls in module.ClassList)
|
|
|
|
|
|
{
|
|
|
|
|
|
GenClassMeta(cls, data);
|
|
|
|
|
|
}
|
|
|
|
|
|
string new_prefix = prefix == null ? "" : "\t";
|
|
|
|
|
|
foreach (var child in module.ChildList)
|
|
|
|
|
|
{
|
|
|
|
|
|
GenModuleMeta(child, new_prefix);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (prefix != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
GenNamespaceEnd(data.Indent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void GenClassMeta(ClassMeta cls, ClassMetaData data)
|
|
|
|
|
|
{
|
2024-04-29 14:58:45 +08:00
|
|
|
|
if (meta.GenClassMeta(cls, data))
|
2024-04-29 01:07:26 +08:00
|
|
|
|
{
|
2024-04-29 14:58:45 +08:00
|
|
|
|
var res = multyMeta.GenClassMeta(cls, data.Indent2);
|
|
|
|
|
|
Output.Append(res);
|
2024-04-29 01:07:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void GenNamespaceBegin(string indent, string name_space)
|
|
|
|
|
|
{
|
2024-04-29 14:58:45 +08:00
|
|
|
|
string line = $"{indent}namespace {name_space} {{";
|
2024-04-29 01:07:26 +08:00
|
|
|
|
foreach (var name in ModuleMeta.NameSet)
|
|
|
|
|
|
{
|
|
|
|
|
|
FileList[name].AppendLine(line);
|
|
|
|
|
|
}
|
2024-04-29 14:58:45 +08:00
|
|
|
|
Output.AppendLine(line);
|
2024-04-29 01:07:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
public static void GenNamespaceEnd(string indent)
|
|
|
|
|
|
{
|
2024-04-29 14:58:45 +08:00
|
|
|
|
string line = $"{indent}}}";
|
2024-04-29 01:07:26 +08:00
|
|
|
|
foreach (var name in ModuleMeta.NameSet)
|
|
|
|
|
|
{
|
2024-04-29 14:58:45 +08:00
|
|
|
|
FileList[name].AppendLine(line);
|
2024-04-29 01:07:26 +08:00
|
|
|
|
}
|
2024-04-29 14:58:45 +08:00
|
|
|
|
Output.AppendLine(line);
|
2024-04-29 01:07:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
public static void Append(string name, string res)
|
|
|
|
|
|
{
|
|
|
|
|
|
FileList[name].Append(res);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|