2025-06-30 20:20:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Convention.Symbolization.Internal
|
|
|
|
|
{
|
2025-07-01 20:34:09 +08:00
|
|
|
|
public abstract class Variable : ICloneable, IEquatable<Variable>
|
2025-06-30 20:20:26 +08:00
|
|
|
|
{
|
2025-07-01 20:34:09 +08:00
|
|
|
|
public readonly VariableSymbol SymbolInfo;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// for construct
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected Variable(string symbolName, Type variableType)
|
|
|
|
|
{
|
|
|
|
|
SymbolInfo = new VariableSymbol(symbolName, variableType);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// for clone
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected Variable(string symbolName, Variable variable) : this(symbolName, variable.SymbolInfo.VariableType) { }
|
|
|
|
|
|
2025-06-30 21:49:33 +08:00
|
|
|
|
public abstract object Clone();
|
2025-07-01 20:34:09 +08:00
|
|
|
|
public abstract bool Equals(Variable other);
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
return obj is Variable variable && Equals(variable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract int GetVariableHashCode();
|
|
|
|
|
|
|
|
|
|
public override sealed int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return GetVariableHashCode();
|
|
|
|
|
}
|
2025-06-30 20:20:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public readonly struct VariableSymbol
|
|
|
|
|
{
|
|
|
|
|
public readonly string SymbolName;
|
|
|
|
|
public readonly Type VariableType;
|
|
|
|
|
|
|
|
|
|
public VariableSymbol(string symbolName, Type variableType)
|
|
|
|
|
{
|
|
|
|
|
this.SymbolName = symbolName;
|
|
|
|
|
this.VariableType = variableType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Equals(VariableSymbol other)
|
|
|
|
|
{
|
|
|
|
|
return other.SymbolName.Equals(SymbolName) && other.VariableType.Equals(VariableType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return new Tuple<string, Type>(SymbolName, VariableType).GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class VariableContext
|
|
|
|
|
{
|
|
|
|
|
public Dictionary<VariableSymbol, Variable> Variables = new();
|
|
|
|
|
}
|
|
|
|
|
}
|