【修复】修复 cfg java bin 代码生成的bug(上次修复cpp生成时失误改错了)

【优化】优化 cfg typescript bin代码,删除多余的分号';'
main
walon 2021-08-14 14:24:26 +08:00
parent 31df88bf48
commit ef10cf0a84
3 changed files with 20 additions and 44 deletions

View File

@ -71,11 +71,11 @@ namespace Luban.Job.Cfg.Defs
var table = field.Assembly.GetCfgTable(field.Ref.FirstTable); var table = field.Assembly.GetCfgTable(field.Ref.FirstTable);
if (field.IsNullable) if (field.IsNullable)
{ {
return $"this.{refVarName} = this.{name} != null ? (({table.CppFullName})_tables.get(\"{tableName}\")).get({name}) : null;"; return $"this.{refVarName} = this.{name} != null ? (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name}) : null;";
} }
else else
{ {
return $"this.{refVarName} = (({table.CppFullName})_tables.get(\"{tableName}\")).get({name});"; return $"this.{refVarName} = (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name});";
} }
} }
@ -179,31 +179,5 @@ namespace Luban.Job.Cfg.Defs
return type.Apply(PyUnderingDeserializeVisitor.Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName); return type.Apply(PyUnderingDeserializeVisitor.Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName);
} }
} }
/*
public static string Py27DeserializeValue(string fieldName, string jsonVarName, TType type)
{
if (type.IsNullable)
{
return $"if {jsonVarName} != None: {type.Apply(PyUnderingDeserializeVisitor.Py27Ins, jsonVarName, fieldName)}";
}
else
{
return type.Apply(PyUnderingDeserializeVisitor.Py3Ins, jsonVarName, fieldName);
}
}
public static string Py27DeserializeField(string fieldName, string jsonVarName, string jsonFieldName, TType type)
{
if (type.IsNullable)
{
return $"if {jsonVarName}.get('{jsonFieldName}') != None: {type.Apply(PyUnderingDeserializeVisitor.Py3Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName)}";
}
else
{
return type.Apply(PyUnderingDeserializeVisitor.Py27Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName);
}
}
*/
} }
} }

View File

@ -23,6 +23,8 @@ namespace Luban.Job.Common.Defs
public string FullNameWithTopModule => TypeUtil.MakeFullName(AssemblyBase.TopModule, FullName); public string FullNameWithTopModule => TypeUtil.MakeFullName(AssemblyBase.TopModule, FullName);
public string JavaFullName => TypeUtil.MakeFullName(Namespace, Name);
public string GoFullName => TypeUtil.MakeGoFullName(Namespace, Name); public string GoFullName => TypeUtil.MakeGoFullName(Namespace, Name);
public string GoPkgName => TypeUtil.MakeGoPkgName(Namespace); public string GoPkgName => TypeUtil.MakeGoPkgName(Namespace);

View File

@ -7,72 +7,72 @@ namespace Luban.Job.Common.TypeVisitors
{ {
public string Accept(TBool type, string bufName, string fieldName) public string Accept(TBool type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadBool();"; return $"{fieldName} = {bufName}.ReadBool()";
} }
public string Accept(TByte type, string bufName, string fieldName) public string Accept(TByte type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadByte();"; return $"{fieldName} = {bufName}.ReadByte()";
} }
public string Accept(TShort type, string bufName, string fieldName) public string Accept(TShort type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadShort();"; return $"{fieldName} = {bufName}.ReadShort()";
} }
public string Accept(TFshort type, string bufName, string fieldName) public string Accept(TFshort type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadFshort();"; return $"{fieldName} = {bufName}.ReadFshort()";
} }
public string Accept(TInt type, string bufName, string fieldName) public string Accept(TInt type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadInt();"; return $"{fieldName} = {bufName}.ReadInt()";
} }
public string Accept(TFint type, string bufName, string fieldName) public string Accept(TFint type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadFint();"; return $"{fieldName} = {bufName}.ReadFint()";
} }
public string Accept(TLong type, string bufName, string fieldName) public string Accept(TLong type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.{(type.IsBigInt ? "ReadLong" : "ReadLongAsNumber")}();"; return $"{fieldName} = {bufName}.{(type.IsBigInt ? "ReadLong" : "ReadLongAsNumber")}()";
} }
public string Accept(TFlong type, string bufName, string fieldName) public string Accept(TFlong type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadFlong();"; return $"{fieldName} = {bufName}.ReadFlong()";
} }
public string Accept(TFloat type, string bufName, string fieldName) public string Accept(TFloat type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadFloat();"; return $"{fieldName} = {bufName}.ReadFloat()";
} }
public string Accept(TDouble type, string bufName, string fieldName) public string Accept(TDouble type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadDouble();"; return $"{fieldName} = {bufName}.ReadDouble()";
} }
public string Accept(TEnum type, string bufName, string fieldName) public string Accept(TEnum type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadInt();"; return $"{fieldName} = {bufName}.ReadInt()";
} }
public string Accept(TString type, string bufName, string fieldName) public string Accept(TString type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadString();"; return $"{fieldName} = {bufName}.ReadString()";
} }
public string Accept(TBytes type, string bufName, string fieldName) public string Accept(TBytes type, string bufName, string fieldName)
{ {
return $"{fieldName} = new Uint8Array({bufName}.ReadArrayBuffer());"; return $"{fieldName} = new Uint8Array({bufName}.ReadArrayBuffer())";
} }
public string Accept(TText type, string bufName, string fieldName) public string Accept(TText type, string bufName, string fieldName)
{ {
return $"{fieldName} = {bufName}.ReadString();"; return $"{fieldName} = {bufName}.ReadString()";
} }
public abstract string Accept(TBean type, string bufVarName, string fieldName); public abstract string Accept(TBean type, string bufVarName, string fieldName);
@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public virtual string Accept(TList type, string bufVarName, string fieldName) public virtual string Accept(TList type, string bufVarName, string fieldName)
{ {
return $"{{ {fieldName} = []; for(let i = 0, n = {bufVarName}.ReadSize() ; i < n ; i++) {{ let _e :{type.ElementType.Apply(TypescriptDefineTypeNameVisitor.Ins)};{type.ElementType.Apply(this, bufVarName, "_e")}; {fieldName}.push(_e) }} }}"; return $"{{ {fieldName} = []; for(let i = 0, n = {bufVarName}.ReadSize() ; i < n ; i++) {{ let _e :{type.ElementType.Apply(TypescriptDefineTypeNameVisitor.Ins)}; {type.ElementType.Apply(this, bufVarName, "_e")}; {fieldName}.push(_e) }} }}";
} }
public virtual string Accept(TSet type, string bufVarName, string fieldName) public virtual string Accept(TSet type, string bufVarName, string fieldName)
@ -148,7 +148,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufVarName, string fieldName) public string Accept(TDateTime type, string bufVarName, string fieldName)
{ {
return $"{fieldName} = {bufVarName}.ReadInt();"; return $"{fieldName} = {bufVarName}.ReadInt()";
} }
} }
} }