public static EocDll Translate(ProjectConverter P, DllDeclareInfo rawInfo) { var libraryName = rawInfo.LibraryName; var entryPoint = rawInfo.EntryPoint; if (string.IsNullOrEmpty(entryPoint)) { entryPoint = P.IdToNameMap.GetUserDefinedName(rawInfo.Id); } var name = P.GetUserDefinedName_SimpleCppName(rawInfo.Id); var info = new EocCmdInfo() { ReturnDataType = rawInfo.ReturnDataType == 0 ? null : EocDataTypes.Translate(P, rawInfo.ReturnDataType), CppName = $"{P.DllNamespace}::{name}", Parameters = rawInfo.Parameters.Select((x) => { var dataType = EocDataTypes.Translate(P, x.DataType, x.ArrayParameter); return(new EocParameterInfo() { ByRef = x.ByRef || x.ArrayParameter || !EocDataTypes.IsValueType(dataType), Optional = false, VarArgs = false, DataType = dataType, CppName = P.GetUserDefinedName_SimpleCppName(x.Id) }); }).ToList() }; return(new EocDll(P, name, info, libraryName, entryPoint)); }
public static EocGlobalVariable Translate(ProjectConverter P, GlobalVariableInfo x) { return new EocGlobalVariable(P, new EocVariableInfo() { CppName = $"{P.GlobalNamespace}::{P.GetUserDefinedName_SimpleCppName(x.Id)}", DataType = EocDataTypes.Translate(P, x.DataType, x.UBound), UBound = x.UBound.ToList() }); }
public static EocDll Translate(ProjectConverter P, DllDeclareInfo dllDeclare) { var libraryName = dllDeclare.LibraryName; var entryPoint = dllDeclare.EntryPoint; if (string.IsNullOrEmpty(entryPoint)) { entryPoint = P.IdToNameMap.GetUserDefinedName(dllDeclare.Id); } return(new EocDll(P, P.GetUserDefinedName_SimpleCppName(dllDeclare.Id), P.GetEocCmdInfo(dllDeclare), libraryName, entryPoint)); }
public static CppTypeName Translate(ProjectConverter P, int id, bool isArray = false) { id = NormalizeDataTypeId(P, id); if (id == P.DataTypeId_IntPtr) { return(IntPtr); } if (!BasicTypeMap.TryGetValue(id, out var result)) { if (EplSystemId.GetType(id) == EplSystemId.Type_Class || EplSystemId.GetType(id) == EplSystemId.Type_Struct) { result = new CppTypeName(false, P.TypeNamespace + "::" + P.GetUserDefinedName_SimpleCppName(id)); } else { EplSystemId.DecomposeLibDataTypeId(id, out var libId, out var typeId); if (P.Libs[libId] == null) { return(ErrorType); } if (typeId >= P.Libs[libId].DataType.Length) { return(ErrorType); } var name = P.Libs[libId].DataType[typeId].Name; if (P.EocLibs[libId] == null) { return(ErrorType); } if (!P.EocLibs[libId].Type.ContainsKey(name)) { return(ErrorType); } result = P.EocLibs[libId].Type[name].CppName; } } if (isArray) { result = new CppTypeName(false, "e::system::array", new[] { result }); } return(result); }
public static EocConstant Translate(ProjectConverter P, ConstantInfo constantInfo) { return(new EocConstant(P, P.GetUserDefinedName_SimpleCppName(constantInfo.Id), P.GetEocConstantInfo(constantInfo.Id))); }
public static EocDll Translate(ProjectConverter P, DllDeclareInfo dllDeclare) { return(new EocDll(P, P.GetUserDefinedName_SimpleCppName(dllDeclare.Id), P.GetEocCmdInfo(dllDeclare), dllDeclare.LibraryName, dllDeclare.EntryPoint)); }
public static EocConstant Translate(ProjectConverter P, ConstantInfo rawInfo) { var name = P.GetUserDefinedName_SimpleCppName(rawInfo.Id); var cppName = $"{P.ConstantNamespace}::{name}"; string getter = null; CppTypeName dataType; switch (rawInfo.Value) { case double v: if ((int)v == v) { dataType = EocDataTypes.Int; } else if ((long)v == v) { dataType = EocDataTypes.Long; } else { dataType = EocDataTypes.Double; } break; case bool _: dataType = EocDataTypes.Bool; break; case DateTime _: dataType = EocDataTypes.DateTime; break; case string _: dataType = EocDataTypes.String; getter = cppName; cppName = null; break; case byte[] _: dataType = EocDataTypes.Bin; getter = cppName; cppName = null; break; case null: return(null); default: throw new Exception(); } var info = new EocConstantInfo() { CppName = cppName, Getter = getter, DataType = dataType, Value = rawInfo.Value }; return(new EocConstant(P, name, info)); }
private static EocCmdInfo InferEocCmdInfo(ProjectConverter P, MethodInfo rawInfo, StatementBlock rawStatementBlock) { var autoParam = new HashSet <int>(); for (int i = 0; i < rawStatementBlock.Count;) { if (rawStatementBlock[i] is ExpressionStatement exprStat) { var callExpr = exprStat.Expression; if (callExpr != null && callExpr.LibraryId == P.EocHelperLibId) { var cmdName = P.IdToNameMap.GetLibCmdName(callExpr.LibraryId, callExpr.MethodId); switch (cmdName) { case "EOC标记_自适应参数": if (callExpr.ParamList.FirstOrDefault() is VariableExpression varExpr) { autoParam.Add(varExpr.Id); } rawStatementBlock.RemoveAt(i); continue; } } } i++; } var name = P.GetUserDefinedName_SimpleCppName(rawInfo.Id); string cppName; if (EplSystemId.GetType(P.MethodIdToClassMap[rawInfo.Id].Id) == EplSystemId.Type_Class) { cppName = name; } else { cppName = $"{P.CmdNamespace}::{name}"; } return(new EocCmdInfo() { ReturnDataType = rawInfo.ReturnDataType == 0 ? null : EocDataTypes.Translate(P, rawInfo.ReturnDataType), CppName = cppName, Parameters = rawInfo.Parameters.Select((x) => { CppTypeName dataType; if (autoParam.Contains(x.Id)) { dataType = x.ArrayParameter ? EocDataTypes.ArrayOf(EocDataTypes.Auto) : EocDataTypes.Auto; } else { dataType = EocDataTypes.Translate(P, x.DataType, x.ArrayParameter); } if (dataType == EocDataTypes.Any && !x.ByRef) { //考虑到可空、参考(非基本类型强制参考、基本类型非参考)等问题,实现起来过于麻烦,暂时搁置 throw new NotImplementedException("暂不支持非参考自适应参数,请勾选 参考 或 贡献代码实现相应功能"); } return new EocParameterInfo() { ByRef = x.ByRef || x.ArrayParameter || (!EocDataTypes.IsValueType(dataType) && dataType != EocDataTypes.Any), Optional = x.OptionalParameter, VarArgs = false, DataType = dataType, CppName = P.GetUserDefinedName_SimpleCppName(x.Id) }; }).ToList() }); }