44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System.Reflection;
|
|
using System.Reflection.Emit;
|
|
using System.Globalization;
|
|
using Flee.ExpressionElements.Base.Literals;
|
|
|
|
using Flee.InternalTypes;
|
|
using Flee.PublicTypes;
|
|
using Flee.Resources;
|
|
using System;
|
|
|
|
namespace Flee.ExpressionElements.Literals
|
|
{
|
|
internal class DateTimeLiteralElement : LiteralElement
|
|
{
|
|
private DateTime _myValue;
|
|
public DateTimeLiteralElement(string image, ExpressionContext context)
|
|
{
|
|
ExpressionParserOptions options = context.ParserOptions;
|
|
|
|
if (DateTime.TryParseExact(image, options.DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out _myValue) == false)
|
|
{
|
|
base.ThrowCompileException(CompileErrorResourceKeys.CannotParseType, CompileExceptionReason.InvalidFormat, typeof(DateTime).Name);
|
|
}
|
|
}
|
|
|
|
public override void Emit(FleeILGenerator ilg, IServiceProvider services)
|
|
{
|
|
int index = ilg.GetTempLocalIndex(typeof(DateTime));
|
|
|
|
Utility.EmitLoadLocalAddress(ilg, index);
|
|
|
|
LiteralElement.EmitLoad(_myValue.Ticks, ilg);
|
|
|
|
ConstructorInfo ci = typeof(DateTime).GetConstructor(new Type[] { typeof(long) });
|
|
|
|
ilg.Emit(OpCodes.Call, ci);
|
|
|
|
Utility.EmitLoadLocal(ilg, index);
|
|
}
|
|
|
|
public override System.Type ResultType => typeof(DateTime);
|
|
}
|
|
}
|