public EocConstantInfo GetEocConstantInfo(int libraryId, int id) { switch (libraryId) { case -2: return(GetEocConstantInfo(id)); default: var name = Libs[libraryId].Constant[id].Name; EocConstantInfo result; try { result = EocLibs[libraryId].Constant[name]; } catch (Exception) { result = new EocConstantInfo() { Value = Libs[libraryId].Constant[id].Value }; if (result.Value is long longValue) { if ((int)longValue == longValue) { result.Value = (int)longValue; } } result.DataType = EocDataTypes.GetConstValueType(result.Value); } return(result); } }
public EocConstantInfo GetEocConstantInfo(EmnuConstantExpression expr) { var dataTypeInfo = Libs[expr.LibraryId].DataType[expr.StructId]; var memberInfo = dataTypeInfo.Member[expr.MemberId]; EocConstantInfo result; try { result = EocLibs[expr.LibraryId].Enum[dataTypeInfo.Name][memberInfo.Name]; } catch (Exception) { result = new EocConstantInfo() { Value = memberInfo.Default }; if (result.Value is long longValue) { if ((int)longValue == longValue) { result.Value = (int)longValue; } } result.DataType = EocDataTypes.GetConstValueType(result.Value); } return(result); }
public EocConstant(ProjectConverter p, string name, EocConstantInfo info) { P = p ?? throw new ArgumentNullException(nameof(p)); Name = name ?? throw new ArgumentNullException(nameof(name)); Info = info; }
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)); }