public static string GetInitParameter(CppTypeName dataType, List <int> uBound = null) { if (dataType.Name == "e::system::array") { if (uBound != null && uBound.Count != 0 && uBound[0] != 0) { return(string.Join(", ", uBound.Select(x => x + "u"))); } } if (dataType == Bool) { return("false"); } if (IsArithmeticType(dataType)) { return("0"); } if (dataType == DateTime) { return("0"); } if (dataType == MethodPtr) { return("nullptr"); } return($"e::system::default_value<{dataType}>::value()"); }
public static bool IsFloatNumberType(CppTypeName dataType) { if (dataType == Float || dataType == Double) { return(true); } else { return(false); } }
public static bool IsValueType(CppTypeName dataType) { if (dataType == Bool || dataType == DateTime || dataType == MethodPtr || IsArithmeticType(dataType)) { return(true); } else { return(false); } }
public static bool IsIntNumberType(CppTypeName dataType) { if (dataType == Byte || dataType == Short || dataType == Int || dataType == Long) { return(true); } else { return(false); } }
public bool IsIntNumberType(CppTypeName dataType) { if (dataType == CppTypeName_Byte || dataType == CppTypeName_Short || dataType == CppTypeName_Int || dataType == CppTypeName_Long) { return(true); } else { return(false); } }
/// <summary> /// 不保证与字节数相等,只保证数值大的类型大 /// </summary> /// <param name="dataType"></param> /// <returns></returns> public static int GetFloatNumberTypeSize(CppTypeName dataType) { if (dataType == Float) { return(4); } else if (dataType == Double) { return(8); } else { throw new ArgumentException(); } }
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 CppTypeName GetCppTypeName(int id, bool isArray = false) { id = TranslateDataTypeId(id); if (id == DataTypeId_IntPtr) { return(CppTypeName_IntPtr); } if (!BasicCppTypeNameMap.TryGetValue(id, out var result)) { if (EplSystemId.GetType(id) == EplSystemId.Type_Class || EplSystemId.GetType(id) == EplSystemId.Type_Struct) { result = new CppTypeName(false, TypeNamespace + "::" + GetUserDefinedName_SimpleCppName(id)); } else { EplSystemId.DecomposeLibDataTypeId(id, out var libId, out var typeId); if (Libs[libId] == null) { return(EocErrorType); } if (typeId >= Libs[libId].DataType.Length) { return(EocErrorType); } var name = Libs[libId].DataType[typeId].Name; if (EocLibs[libId] == null) { return(EocErrorType); } if (!EocLibs[libId].Type.ContainsKey(name)) { return(EocErrorType); } result = EocLibs[libId].Type[name].CppName; } } if (isArray) { result = new CppTypeName(false, "e::system::array", new[] { result }); } return(result); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } CppTypeName data; if (reader.TokenType == JsonToken.String) { string encodedData = reader.Value.ToString(); data = CppTypeName.Parse(encodedData); } else { throw new Exception(); } return(data); }
public bool IsValueType(CppTypeName dataType) { if (dataType == CppTypeName_Bool || dataType == CppTypeName_Byte || dataType == CppTypeName_Short || dataType == CppTypeName_Int || dataType == CppTypeName_Long || dataType == CppTypeName_Float || dataType == CppTypeName_Double || dataType == CppTypeName_DateTime || dataType == CppTypeName_MethodPtr || dataType == CppTypeName_IntPtr) { return(true); } else { return(false); } }
/// <summary> /// 不保证与字节数相等,只保证数值大的类型大 /// </summary> /// <param name="dataType"></param> /// <returns></returns> public static int GetIntNumberTypeSize(CppTypeName dataType) { if (dataType == Byte) { return(1); } else if (dataType == Short) { return(2); } else if (dataType == Int) { return(4); } else if (dataType == Long) { return(8); } else { throw new ArgumentException(); } }
public static CppTypeName ArrayOf(CppTypeName elemType) { return(new CppTypeName(false, "e::system::array", new[] { elemType })); }
public static bool IsArithmeticType(CppTypeName dataType) { return(IsIntNumberType(dataType) || IsFloatNumberType(dataType) || dataType == IntPtr); }
public void AnalyzeDependencies(AdjacencyGraph <string, IEdge <string> > graph, string a, CppTypeName b) { if (b == null) { return; } graph.AddVerticesAndEdge(new Edge <string>(a, b.Name)); if (b.TypeParam == null) { return; } foreach (var item in b.TypeParam) { AnalyzeDependencies(graph, a, item); } }