This commit is contained in:
2025-10-08 09:49:37 +08:00
commit 284e764345
99 changed files with 21742 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
using System.Globalization;
using Flee.ExpressionElements.Base.Literals;
using Flee.InternalTypes;
namespace Flee.ExpressionElements.Literals.Integral
{
internal class Int32LiteralElement : IntegralLiteralElement
{
private Int32 _myValue;
private const string MinValue = "2147483648";
private readonly bool _myIsMinValue;
public Int32LiteralElement(Int32 value)
{
_myValue = value;
}
private Int32LiteralElement()
{
_myIsMinValue = true;
}
public static Int32LiteralElement TryCreate(string image, bool isHex, bool negated)
{
if (negated == true & image == MinValue)
{
return new Int32LiteralElement();
}
else if (isHex == true)
{
Int32 value = default(Int32);
// Since Int32.TryParse will succeed for a string like 0xFFFFFFFF we have to do some special handling
if (Int32.TryParse(image, NumberStyles.AllowHexSpecifier, null, out value) == false)
{
return null;
}
else if (value >= 0 & value <= Int32.MaxValue)
{
return new Int32LiteralElement(value);
}
else
{
return null;
}
}
else
{
Int32 value = default(Int32);
if (Int32.TryParse(image,out value) == true)
{
return new Int32LiteralElement(value);
}
else
{
return null;
}
}
}
public void Negate()
{
if (_myIsMinValue == true)
{
_myValue = Int32.MinValue;
}
else
{
_myValue = -_myValue;
}
}
public override void Emit(FleeILGenerator ilg, IServiceProvider services)
{
EmitLoad(_myValue, ilg);
}
public override System.Type ResultType => typeof(Int32);
public int Value => _myValue;
}
}

View File

@@ -0,0 +1,82 @@
using System.Globalization;
using Flee.ExpressionElements.Base.Literals;
using Flee.InternalTypes;
namespace Flee.ExpressionElements.Literals.Integral
{
internal class Int64LiteralElement : IntegralLiteralElement
{
private Int64 _myValue;
private const string MinValue = "9223372036854775808";
private readonly bool _myIsMinValue;
public Int64LiteralElement(Int64 value)
{
_myValue = value;
}
private Int64LiteralElement()
{
_myIsMinValue = true;
}
public static Int64LiteralElement TryCreate(string image, bool isHex, bool negated)
{
if (negated == true & image == MinValue)
{
return new Int64LiteralElement();
}
else if (isHex == true)
{
Int64 value = default(Int64);
if (Int64.TryParse(image, NumberStyles.AllowHexSpecifier, null, out value) == false)
{
return null;
}
else if (value >= 0 & value <= Int64.MaxValue)
{
return new Int64LiteralElement(value);
}
else
{
return null;
}
}
else
{
Int64 value = default(Int64);
if (Int64.TryParse(image, out value) == true)
{
return new Int64LiteralElement(value);
}
else
{
return null;
}
}
}
public override void Emit(FleeILGenerator ilg, IServiceProvider services)
{
EmitLoad(_myValue, ilg);
}
public void Negate()
{
if (_myIsMinValue == true)
{
_myValue = Int64.MinValue;
}
else
{
_myValue = -_myValue;
}
}
public override System.Type ResultType => typeof(Int64);
}
}

View File

@@ -0,0 +1,34 @@
using Flee.ExpressionElements.Base.Literals;
using Flee.InternalTypes;
namespace Flee.ExpressionElements.Literals.Integral
{
internal class UInt32LiteralElement : IntegralLiteralElement
{
private readonly UInt32 _myValue;
public UInt32LiteralElement(UInt32 value)
{
_myValue = value;
}
public static UInt32LiteralElement TryCreate(string image, System.Globalization.NumberStyles ns)
{
UInt32 value = default(UInt32);
if (UInt32.TryParse(image, ns, null, out value) == true)
{
return new UInt32LiteralElement(value);
}
else
{
return null;
}
}
public override void Emit(FleeILGenerator ilg, IServiceProvider services)
{
EmitLoad(Convert.ToInt32(_myValue), ilg);
}
public override System.Type ResultType => typeof(UInt32);
}
}

View File

@@ -0,0 +1,34 @@
using Flee.ExpressionElements.Base.Literals;
using Flee.InternalTypes;
namespace Flee.ExpressionElements.Literals.Integral
{
internal class UInt64LiteralElement : IntegralLiteralElement
{
private readonly UInt64 _myValue;
public UInt64LiteralElement(string image, System.Globalization.NumberStyles ns)
{
try
{
_myValue = UInt64.Parse(image, ns);
}
catch (OverflowException ex)
{
base.OnParseOverflow(image);
}
}
public UInt64LiteralElement(UInt64 value)
{
_myValue = value;
}
public override void Emit(FleeILGenerator ilg, IServiceProvider services)
{
EmitLoad(Convert.ToInt64(_myValue), ilg);
}
public override System.Type ResultType => typeof(UInt64);
}
}