2025-10-08 10:14:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2025-10-08 09:49:37 +08:00
|
|
|
|
using Flee.InternalTypes;
|
|
|
|
|
using Flee.PublicTypes;
|
|
|
|
|
|
|
|
|
|
namespace Flee.ExpressionElements.Base
|
|
|
|
|
{
|
|
|
|
|
internal abstract class ExpressionElement
|
|
|
|
|
{
|
|
|
|
|
internal ExpressionElement()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// // All expression elements must be able to emit their IL
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ilg"></param>
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
public abstract void Emit(FleeILGenerator ilg, IServiceProvider services);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// All expression elements must expose the Type they evaluate to
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract Type ResultType { get; }
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return this.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ThrowCompileException(string messageKey, CompileExceptionReason reason, params object[] arguments)
|
|
|
|
|
{
|
2025-10-08 12:00:42 +08:00
|
|
|
|
//string messageTemplate = FleeResourceManager.Instance.GetCompileErrorString(messageKey);
|
|
|
|
|
//string message = string.Format(messageTemplate, arguments);
|
|
|
|
|
string message = $"[{messageKey}]{string.Join(',', arguments)}";
|
2025-10-08 09:49:37 +08:00
|
|
|
|
message = string.Concat(this.Name, ": ", message);
|
|
|
|
|
throw new ExpressionCompileException(message, reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ThrowAmbiguousCallException(Type leftType, Type rightType, object operation)
|
|
|
|
|
{
|
2025-10-08 12:00:42 +08:00
|
|
|
|
this.ThrowCompileException("AmbiguousOverloadedOperator", CompileExceptionReason.AmbiguousMatch, leftType.Name, rightType.Name, operation);
|
2025-10-08 09:49:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
string key = this.GetType().Name;
|
2025-10-08 12:00:42 +08:00
|
|
|
|
string value = $"{key}";
|
2025-10-08 09:49:37 +08:00
|
|
|
|
Debug.Assert(value != null, $"Element name for '{key}' not in resource file");
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|