【调整】调整cfg c++的生成代码,允许在CommonMacros.h里重新定义所有内置类型

main
walon 2021-08-12 10:38:06 +08:00
parent 73e98662ab
commit 901441e9c2
7 changed files with 42 additions and 51 deletions

View File

@ -477,11 +477,10 @@ namespace Luban.Job.Cfg
ctx.Lan = GetLanguage(genType); ctx.Lan = GetLanguage(genType);
foreach (var c in ctx.ExportTypes) foreach (var c in ctx.ExportTypes)
{ {
var t = c;
ctx.Tasks.Add(Task.Run(() => ctx.Tasks.Add(Task.Run(() =>
{ {
var content = FileHeaderUtil.ConcatAutoGenerationHeader(ctx.Render.RenderAny(t), ctx.Lan); var content = FileHeaderUtil.ConcatAutoGenerationHeader(ctx.Render.RenderAny(c), ctx.Lan);
var file = RenderFileUtil.GetDefTypePath(t.FullName, ctx.Lan); var file = RenderFileUtil.GetDefTypePath(c.FullName, ctx.Lan);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
})); }));
@ -715,11 +714,10 @@ namespace {ctx.TopModule}
foreach (var c in renderTypes) foreach (var c in renderTypes)
{ {
var table = c;
ctx.Tasks.Add(Task.Run(() => ctx.Tasks.Add(Task.Run(() =>
{ {
var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(table), ELanguage.CPP); var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CPP);
var file = "editor_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(table.FullName); var file = "editor_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(c.FullName);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
})); }));
@ -748,11 +746,10 @@ namespace {ctx.TopModule}
var render = new EditorCsRender(); var render = new EditorCsRender();
foreach (var c in ctx.Assembly.Types.Values) foreach (var c in ctx.Assembly.Types.Values)
{ {
var type = c;
ctx.Tasks.Add(Task.Run(() => ctx.Tasks.Add(Task.Run(() =>
{ {
var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(type), ELanguage.CS); var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CS);
var file = RenderFileUtil.GetDefTypePath(type.FullName, ELanguage.CS); var file = RenderFileUtil.GetDefTypePath(c.FullName, ELanguage.CS);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
})); }));
@ -764,16 +761,15 @@ namespace {ctx.TopModule}
var render = new UE4BpCppRender(); var render = new UE4BpCppRender();
foreach (var c in ctx.ExportTypes) foreach (var c in ctx.ExportTypes)
{ {
var type = c; if (!(c is DefEnum || c is DefBean))
if (!(type is DefEnum || type is DefBean))
{ {
continue; continue;
} }
ctx.Tasks.Add(Task.Run(() => ctx.Tasks.Add(Task.Run(() =>
{ {
var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(type), ELanguage.CPP); var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CPP);
var file = "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(type.FullName); var file = "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(c.FullName);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
})); }));
@ -783,9 +779,8 @@ namespace {ctx.TopModule}
private void GenDataScatter(GenContext ctx) private void GenDataScatter(GenContext ctx)
{ {
string genType = ctx.GenType; string genType = ctx.GenType;
foreach (var c in ctx.ExportTables) foreach (var table in ctx.ExportTables)
{ {
var table = c;
ctx.Tasks.Add(Task.Run(() => ctx.Tasks.Add(Task.Run(() =>
{ {
var file = GetOutputFileName(genType, table.OutputDataFile); var file = GetOutputFileName(genType, table.OutputDataFile);
@ -807,10 +802,9 @@ namespace {ctx.TopModule}
var allJsonTask = new List<Task<string>>(); var allJsonTask = new List<Task<string>>();
foreach (var c in exportTables) foreach (var c in exportTables)
{ {
var table = c;
allJsonTask.Add(Task.Run(() => allJsonTask.Add(Task.Run(() =>
{ {
return (string)DataExporterUtil.ToOutputData(table, ctx.Assembly.GetTableExportDataList(table), "data_json"); return (string)DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json");
})); }));
} }
@ -839,10 +833,9 @@ namespace {ctx.TopModule}
var genDataTasks = new List<Task<List<ResourceInfo>>>(); var genDataTasks = new List<Task<List<ResourceInfo>>>();
foreach (var c in ctx.ExportTables) foreach (var c in ctx.ExportTables)
{ {
var table = c;
genDataTasks.Add(Task.Run(() => genDataTasks.Add(Task.Run(() =>
{ {
return DataExporterUtil.ExportResourceList(ctx.Assembly.GetTableExportDataList(table)); return DataExporterUtil.ExportResourceList(ctx.Assembly.GetTableExportDataList(c));
})); }));
} }

View File

@ -84,22 +84,22 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TArray type, string bufName, string fieldName) public string Accept(TArray type, string bufName, string fieldName)
{ {
return $"{{int32_t n; if(!{bufName}.readSize(n)) return false; n = std::min(n, {bufName}.size());{fieldName}.reserve(n);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CppDefineTypeName.Ins)} _e;{type.ElementType.Apply(this, bufName, "_e")} {fieldName}.push_back(_e);}}}}"; return $"{{::bright::int32 n; if(!{bufName}.readSize(n)) return false; n = std::min(n, ::bright::int32({bufName}.size()));{fieldName}.reserve(n);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CppDefineTypeName.Ins)} _e;{type.ElementType.Apply(this, bufName, "_e")} {fieldName}.push_back(_e);}}}}";
} }
public string Accept(TList type, string bufName, string fieldName) public string Accept(TList type, string bufName, string fieldName)
{ {
return $"{{int32_t n; if(!{bufName}.readSize(n)) return false; n = std::min(n, {bufName}.size()); {fieldName}.reserve(n);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CppDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.push_back(_e);}}}}"; return $"{{::bright::int32 n; if(!{bufName}.readSize(n)) return false; n = std::min(n, ::bright::int32({bufName}.size())); {fieldName}.reserve(n);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CppDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.push_back(_e);}}}}";
} }
public string Accept(TSet type, string bufName, string fieldName) public string Accept(TSet type, string bufName, string fieldName)
{ {
return $"{{int32_t n; if(!{bufName}.readSize(n)) return false; n = std::min(n, {bufName}.size()); {fieldName}.reserve(n * 3 / 2);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CppDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.insert(_e);}}}}"; return $"{{::bright::int32 n; if(!{bufName}.readSize(n)) return false; n = std::min(n, ::bright::int32({bufName}.size())); {fieldName}.reserve(n * 3 / 2);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CppDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.insert(_e);}}}}";
} }
public string Accept(TMap type, string bufName, string fieldName) public string Accept(TMap type, string bufName, string fieldName)
{ {
return $"{{int32_t n; if(!{bufName}.readSize(n)) return false; n = std::min(n, {bufName}.size()); {fieldName}.reserve(n * 3 / 2);for(int i = 0 ; i < n ; i++) {{ {type.KeyType.Apply(CppDefineTypeName.Ins)} _k; {type.KeyType.Apply(this, bufName, "_k")} {type.ValueType.Apply(CppDefineTypeName.Ins)} _v; {type.ValueType.Apply(this, bufName, "_v")} {fieldName}[_k] = _v;}}}}"; return $"{{::bright::int32 n; if(!{bufName}.readSize(n)) return false; n = std::min(n, (::bright::int32){bufName}.size()); {fieldName}.reserve(n * 3 / 2);for(int i = 0 ; i < n ; i++) {{ {type.KeyType.Apply(CppDefineTypeName.Ins)} _k; {type.KeyType.Apply(this, bufName, "_k")} {type.ValueType.Apply(CppDefineTypeName.Ins)} _v; {type.ValueType.Apply(this, bufName, "_v")} {fieldName}[_k] = _v;}}}}";
} }

View File

@ -9,7 +9,7 @@ namespace Luban.Job.Common.TypeVisitors
public override string DoAccept(TType type) public override string DoAccept(TType type)
{ {
//return type.IsNullable ? $"std::optional<{type.Apply(CppUnderingDefineTypeName.Ins)}>" : type.Apply(CppUnderingDefineTypeName.Ins); //return type.IsNullable ? $"std::optional<{type.Apply(CppUnderingDefineTypeName.Ins)}>" : type.Apply(CppUnderingDefineTypeName.Ins);
return type.IsNullable ? $"std::shared_ptr<{type.Apply(CppSharedPtrUnderingDefineTypeName.Ins)}>" : type.Apply(CppSharedPtrUnderingDefineTypeName.Ins); return type.IsNullable ? $"::bright::SharedPtr<{type.Apply(CppSharedPtrUnderingDefineTypeName.Ins)}>" : type.Apply(CppSharedPtrUnderingDefineTypeName.Ins);
} }
public override string Accept(TBean type) public override string Accept(TBean type)

View File

@ -13,47 +13,47 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TByte type) public string Accept(TByte type)
{ {
return "uint8_t"; return "::bright::byte";
} }
public string Accept(TShort type) public string Accept(TShort type)
{ {
return "int16_t"; return "::bright::int16";
} }
public string Accept(TFshort type) public string Accept(TFshort type)
{ {
return "int16_t"; return "::bright::int16";
} }
public string Accept(TInt type) public string Accept(TInt type)
{ {
return "int32_t"; return "::bright::int32";
} }
public string Accept(TFint type) public string Accept(TFint type)
{ {
return "int32_t"; return "::bright::int32";
} }
public string Accept(TLong type) public string Accept(TLong type)
{ {
return "int64_t"; return "::bright::int64";
} }
public string Accept(TFlong type) public string Accept(TFlong type)
{ {
return "int64_t"; return "::bright::int64";
} }
public string Accept(TFloat type) public string Accept(TFloat type)
{ {
return "float"; return "::bright::float32";
} }
public string Accept(TDouble type) public string Accept(TDouble type)
{ {
return "double"; return "::bright::float64";
} }
public string Accept(TEnum type) public string Accept(TEnum type)
@ -63,17 +63,17 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TString type) public string Accept(TString type)
{ {
return "std::string"; return "::bright::String";
} }
public string Accept(TBytes type) public string Accept(TBytes type)
{ {
return "bright::Bytes"; return "::bright::Bytes";
} }
public string Accept(TText type) public string Accept(TText type)
{ {
return "std::string"; return "::bright::String";
} }
public virtual string Accept(TBean type) public virtual string Accept(TBean type)
@ -83,42 +83,42 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TArray type) public string Accept(TArray type)
{ {
return $"std::vector<{type.ElementType.Apply(this)}>"; return $"::bright::Vector<{type.ElementType.Apply(this)}>";
} }
public string Accept(TList type) public string Accept(TList type)
{ {
return $"std::vector<{type.ElementType.Apply(this)}>"; return $"::bright::Vector<{type.ElementType.Apply(this)}>";
} }
public string Accept(TSet type) public string Accept(TSet type)
{ {
return $"std::unordered_set<{type.ElementType.Apply(this)}>"; return $"::bright::HashSet<{type.ElementType.Apply(this)}>";
} }
public string Accept(TMap type) public string Accept(TMap type)
{ {
return $"std::unordered_map<{type.KeyType.Apply(this)}, {type.ValueType.Apply(this)}>"; return $"::bright::HashMap<{type.KeyType.Apply(this)}, {type.ValueType.Apply(this)}>";
} }
public string Accept(TVector2 type) public string Accept(TVector2 type)
{ {
return "bright::math::Vector2"; return "::bright::Vector2";
} }
public string Accept(TVector3 type) public string Accept(TVector3 type)
{ {
return "bright::math::Vector3"; return "::bright::Vector3";
} }
public string Accept(TVector4 type) public string Accept(TVector4 type)
{ {
return "bright::math::Vector4"; return "::bright::Vector4";
} }
public string Accept(TDateTime type) public string Accept(TDateTime type)
{ {
return "int32_t"; return "::bright::datetime_t";
} }
} }
} }

View File

@ -8,7 +8,7 @@ namespace Luban.Job.Common.TypeVisitors
public override string Accept(TBean type) public override string Accept(TBean type)
{ {
return $"std::shared_ptr<{type.Bean.CppFullName}>"; return $"::bright::SharedPtr<{type.Bean.CppFullName}>";
} }
} }
} }

View File

@ -105,11 +105,10 @@ namespace Luban.Job.Db
var render = new AsyncCsRender(); var render = new AsyncCsRender();
foreach (var c in ass.Types.Values) foreach (var c in ass.Types.Values)
{ {
var type = c;
tasks.Add(Task.Run(() => tasks.Add(Task.Run(() =>
{ {
var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(type), Common.ELanguage.CS); var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), Common.ELanguage.CS);
var file = RenderFileUtil.GetDefTypePath(type.FullName, Common.ELanguage.CS); var file = RenderFileUtil.GetDefTypePath(c.FullName, Common.ELanguage.CS);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
genCodeFiles.Add(new FileInfo() { FilePath = file, MD5 = md5 }); genCodeFiles.Add(new FileInfo() { FilePath = file, MD5 = md5 });
})); }));

View File

@ -116,11 +116,10 @@ namespace Luban.Job.Proto
var render = new CsRender(); var render = new CsRender();
foreach (var c in ass.Types.Values) foreach (var c in ass.Types.Values)
{ {
var type = c;
tasks.Add(Task.Run(() => tasks.Add(Task.Run(() =>
{ {
var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(type), Common.ELanguage.CS); var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), Common.ELanguage.CS);
var file = RenderFileUtil.GetDefTypePath(type.FullName, Common.ELanguage.CS); var file = RenderFileUtil.GetDefTypePath(c.FullName, Common.ELanguage.CS);
var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); var md5 = CacheFileUtil.GenMd5AndAddCache(file, content);
genCodeFiles.Add(new FileInfo() { FilePath = file, MD5 = md5 }); genCodeFiles.Add(new FileInfo() { FilePath = file, MD5 = md5 });
})); }));