public static int?GetPrimitiveSize(this MosaType type, int nativeSize) { if (type.IsEnum) { return(type.GetEnumUnderlyingType().GetPrimitiveSize(nativeSize)); } if (type.IsPointer || type.IsN) { return(nativeSize); } else if (type.IsUI1 || type.IsBoolean) { return(1); } else if (type.IsUI2 || type.IsChar) { return(2); } else if (type.IsUI4 || type.IsR4) { return(4); } else if (type.IsUI8 || type.IsR8) { return(8); } else { return(null); } }
/// <summary> /// Gets the type on the stack. /// </summary> /// <param name="type">The type.</param> /// <returns> /// The equivalent stack type code. /// </returns> /// <exception cref="CompilerException"></exception> public static StackTypeCode GetStackTypeCode(this MosaType type) { switch (type.IsEnum ? type.GetEnumUnderlyingType().TypeCode : type.TypeCode) { case MosaTypeCode.Boolean: case MosaTypeCode.Char: case MosaTypeCode.I1: case MosaTypeCode.U1: case MosaTypeCode.I2: case MosaTypeCode.U2: case MosaTypeCode.I4: case MosaTypeCode.U4: return(StackTypeCode.Int32); case MosaTypeCode.I8: case MosaTypeCode.U8: return(StackTypeCode.Int64); case MosaTypeCode.R4: case MosaTypeCode.R8: return(StackTypeCode.F); case MosaTypeCode.I: case MosaTypeCode.U: return(StackTypeCode.N); case MosaTypeCode.ManagedPointer: return(StackTypeCode.ManagedPointer); case MosaTypeCode.UnmanagedPointer: case MosaTypeCode.FunctionPointer: return(StackTypeCode.UnmanagedPointer); case MosaTypeCode.String: case MosaTypeCode.ValueType: case MosaTypeCode.ReferenceType: case MosaTypeCode.Array: case MosaTypeCode.Object: case MosaTypeCode.SZArray: case MosaTypeCode.Var: case MosaTypeCode.MVar: return(StackTypeCode.O); case MosaTypeCode.Void: return(StackTypeCode.Unknown); } throw new CompilerException(string.Format("Can't transform Type {0} to StackTypeCode.", type)); }