private static void EmitLiteral(FieldInfo fi, FleeIlGenerator ilg, IServiceProvider services) { var value = RuntimeHelpers.GetObjectValue(fi.GetValue(null)); var t = value.GetType(); LiteralElement elem; switch (Type.GetTypeCode(t)) { case TypeCode.Boolean: elem = new BooleanLiteralElement((bool)value); goto IL_F4; case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: elem = new Int32LiteralElement(Convert.ToInt32(RuntimeHelpers.GetObjectValue(value))); goto IL_F4; case TypeCode.UInt32: elem = new UInt32LiteralElement((uint)value); goto IL_F4; case TypeCode.Int64: elem = new Int64LiteralElement((long)value); goto IL_F4; case TypeCode.UInt64: elem = new UInt64LiteralElement((ulong)value); goto IL_F4; case TypeCode.Single: elem = new SingleLiteralElement((float)value); goto IL_F4; case TypeCode.Double: elem = new DoubleLiteralElement((double)value); goto IL_F4; case TypeCode.String: elem = new StringLiteralElement((string)value); goto IL_F4; } elem = null; Debug.Fail("Unsupported constant type"); IL_F4: elem.Emit(ilg, services); }
public static Int32LiteralElement TryCreate(string image, bool isHex, bool negated) { var flag = negated & (Operators.CompareString(image, "2147483648", false) == 0); Int32LiteralElement tryCreate; if (flag) { tryCreate = new Int32LiteralElement(); } else if (isHex) { int value; var flag2 = !int.TryParse(image, NumberStyles.AllowHexSpecifier, null, out value); if (flag2) { tryCreate = null; } else { var flag3 = (value >= 0) & true; if (flag3) { tryCreate = new Int32LiteralElement(value); } else { tryCreate = null; } } } else { int value2; var flag4 = int.TryParse(image, out value2); if (flag4) { tryCreate = new Int32LiteralElement(value2); } else { tryCreate = null; } } return(tryCreate); }
private static void EmitStringEquality(FleeIlGenerator ilg, LogicalCompareOperation op, IServiceProvider services) { var options = (ExpressionOptions)services.GetService(typeof(ExpressionOptions)); var ic = new Int32LiteralElement((int)options.StringComparison); ic.Emit(ilg, services); var mi = typeof(string).GetMethod("Equals", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string), typeof(string), typeof(StringComparison) }, null); ilg.Emit(OpCodes.Call, mi); var flag = op == LogicalCompareOperation.NotEqual; if (flag) { ilg.Emit(OpCodes.Ldc_I4_0); ilg.Emit(OpCodes.Ceq); } }
public static LiteralElement Create(string image, bool isHex, bool negated, IServiceProvider services) { var comparison = StringComparison.OrdinalIgnoreCase; var flag = !isHex; LiteralElement Create; if (flag) { var realElement = RealLiteralElement.CreateFromInteger(image, services); var flag2 = realElement != null; if (flag2) { Create = realElement; return(Create); } } var hasUSuffix = image.EndsWith("u", comparison) & !image.EndsWith("lu", comparison); var hasLSuffix = image.EndsWith("l", comparison) & !image.EndsWith("ul", comparison); var hasULSuffix = image.EndsWith("ul", comparison) | image.EndsWith("lu", comparison); var hasSuffix = hasUSuffix | hasLSuffix | hasULSuffix; var numStyles = NumberStyles.Integer; if (isHex) { numStyles = NumberStyles.AllowHexSpecifier; image = image.Remove(0, 2); } var flag3 = !hasSuffix; if (flag3) { LiteralElement constant = Int32LiteralElement.TryCreate(image, isHex, negated); var flag4 = constant != null; if (flag4) { Create = constant; } else { constant = UInt32LiteralElement.TryCreate(image, numStyles); var flag5 = constant != null; if (flag5) { Create = constant; } else { constant = Int64LiteralElement.TryCreate(image, isHex, negated); var flag6 = constant != null; if (flag6) { Create = constant; } else { Create = new UInt64LiteralElement(image, numStyles); } } } } else { var flag7 = hasUSuffix; if (flag7) { image = image.Remove(image.Length - 1); LiteralElement constant = UInt32LiteralElement.TryCreate(image, numStyles); var flag8 = constant != null; if (flag8) { Create = constant; } else { Create = new UInt64LiteralElement(image, numStyles); } } else { var flag9 = hasLSuffix; if (flag9) { image = image.Remove(image.Length - 1); LiteralElement constant = Int64LiteralElement.TryCreate(image, isHex, negated); var flag10 = constant != null; if (flag10) { Create = constant; } else { Create = new UInt64LiteralElement(image, numStyles); } } else { Debug.Assert(hasULSuffix, "expecting ul suffix"); image = image.Remove(image.Length - 2); Create = new UInt64LiteralElement(image, numStyles); } } } return(Create); }