EP 0.1.1
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public readonly struct FunctionSymbol
|
public readonly struct FunctionSymbol
|
||||||
{
|
{
|
||||||
public readonly string SymbolName;
|
public readonly string FunctionName;
|
||||||
public readonly Type ReturnType;
|
public readonly Type ReturnType;
|
||||||
public readonly Type[] ParameterTypes;
|
public readonly Type[] ParameterTypes;
|
||||||
public readonly Modification[] Modifiers;
|
public readonly Modification[] Modifiers;
|
||||||
@@ -26,7 +26,7 @@ namespace Convention.Symbolization.Internal
|
|||||||
|
|
||||||
public FunctionSymbol(string symbolName, Type returnType, Type[] parameterTypes, Modification[] modifiers)
|
public FunctionSymbol(string symbolName, Type returnType, Type[] parameterTypes, Modification[] modifiers)
|
||||||
{
|
{
|
||||||
this.SymbolName = symbolName;
|
this.FunctionName = symbolName;
|
||||||
this.ReturnType = returnType;
|
this.ReturnType = returnType;
|
||||||
this.ParameterTypes = parameterTypes;
|
this.ParameterTypes = parameterTypes;
|
||||||
this.Modifiers = modifiers;
|
this.Modifiers = modifiers;
|
||||||
|
@@ -1,29 +1,85 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Convention.Symbolization.Internal
|
namespace Convention.Symbolization.Internal
|
||||||
{
|
{
|
||||||
internal sealed class NamespaceModel
|
public sealed class Namespace : Variable<Namespace>
|
||||||
{
|
{
|
||||||
|
public Dictionary<string, Namespace> SubNamespaces = new();
|
||||||
|
public Dictionary<FunctionSymbol, Function> Functions = new();
|
||||||
|
public Dictionary<string, Structure> Structures = new();
|
||||||
|
|
||||||
}
|
private readonly Dictionary<string, int> SymbolCounter = new();
|
||||||
|
private readonly Dictionary<string, List<Variable>> Symbol2Variable = new();
|
||||||
|
|
||||||
public sealed class Namespace : Variable
|
public void Refresh()
|
||||||
{
|
{
|
||||||
private NamespaceModel Data;
|
// Refresh SymbolCounter
|
||||||
|
SymbolCounter.Clear();
|
||||||
public override object Clone()
|
foreach (var ns in SubNamespaces)
|
||||||
{
|
{
|
||||||
Namespace result = new()
|
ns.Value.Refresh();
|
||||||
|
foreach (var symbol in ns.Value.SymbolCounter)
|
||||||
{
|
{
|
||||||
Data = Data
|
if (SymbolCounter.ContainsKey(symbol.Key))
|
||||||
};
|
SymbolCounter[symbol.Key] += symbol.Value;
|
||||||
return result;
|
else
|
||||||
}
|
SymbolCounter[symbol.Key] = symbol.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var func in Functions)
|
||||||
|
{
|
||||||
|
if (SymbolCounter.ContainsKey(func.Key.FunctionName))
|
||||||
|
SymbolCounter[func.Key.FunctionName]++;
|
||||||
|
else
|
||||||
|
SymbolCounter[func.Key.FunctionName] = 1;
|
||||||
|
}
|
||||||
|
foreach (var @struct in Structures)
|
||||||
|
{
|
||||||
|
if (SymbolCounter.ContainsKey(@struct.Key))
|
||||||
|
SymbolCounter[@struct.Key]++;
|
||||||
|
else
|
||||||
|
SymbolCounter[@struct.Key] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Namespace CreateOrGetSubNamespace(string namespaceName, Namespace parent)
|
||||||
|
{
|
||||||
|
if (parent.SubNamespaces.TryGetValue(namespaceName, out var sub))
|
||||||
|
return sub;
|
||||||
|
parent.SubNamespaces[namespaceName] = new(namespaceName);
|
||||||
|
return parent.SubNamespaces[namespaceName];
|
||||||
|
}
|
||||||
|
public static Namespace CreateRootNamespace()
|
||||||
|
{
|
||||||
|
return new("global");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Namespace(string symbolName) : base(symbolName) { }
|
||||||
|
|
||||||
|
public override bool Equals(Namespace other)
|
||||||
|
{
|
||||||
|
return this == other;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetNamespaceName() => this.SymbolInfo.SymbolName;
|
||||||
|
|
||||||
|
public bool ContainsSymbol(string symbolName)
|
||||||
|
{
|
||||||
|
return SymbolCounter.ContainsKey(symbolName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CountSymbol(string symbolName)
|
||||||
|
{
|
||||||
|
return SymbolCounter.TryGetValue(symbolName, out var count) ? count : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Variable[] Find(string symbolName)
|
||||||
|
{
|
||||||
|
if (!Symbol2Variable.TryGetValue(symbolName,out var result))
|
||||||
|
return Array.Empty<Variable>();
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,36 +1,49 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Convention.Symbolization.Internal
|
namespace Convention.Symbolization.Internal
|
||||||
{
|
{
|
||||||
public abstract class Variable : ICloneable, IEquatable<Variable>
|
public abstract class Variable : IEquatable<Variable>
|
||||||
{
|
{
|
||||||
public readonly VariableSymbol SymbolInfo;
|
public readonly VariableSymbol SymbolInfo;
|
||||||
|
|
||||||
/// <summary>
|
protected Variable(VariableSymbol symbolInfo)
|
||||||
/// for construct
|
|
||||||
/// </summary>
|
|
||||||
protected Variable(string symbolName, Type variableType)
|
|
||||||
{
|
{
|
||||||
SymbolInfo = new VariableSymbol(symbolName, variableType);
|
this.SymbolInfo = symbolInfo;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// for clone
|
|
||||||
/// </summary>
|
|
||||||
protected Variable(string symbolName, Variable variable) : this(symbolName, variable.SymbolInfo.VariableType) { }
|
|
||||||
|
|
||||||
public abstract object Clone();
|
|
||||||
public abstract bool Equals(Variable other);
|
public abstract bool Equals(Variable other);
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
return obj is Variable variable && Equals(variable);
|
return Equals(obj as Variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int GetVariableHashCode();
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return base.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class Variable<T> : Variable, IEquatable<T>
|
||||||
|
{
|
||||||
|
protected Variable(string symbolName) : base(new VariableSymbol(symbolName, typeof(T))) { }
|
||||||
|
public abstract bool Equals(T other);
|
||||||
|
|
||||||
|
public override bool Equals(Variable other)
|
||||||
|
{
|
||||||
|
return other is T variable && Equals(variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return obj is T variable && Equals(variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual int GetVariableHashCode()
|
||||||
|
{
|
||||||
|
return base.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
public override sealed int GetHashCode()
|
public override sealed int GetHashCode()
|
||||||
{
|
{
|
||||||
@@ -38,6 +51,22 @@ namespace Convention.Symbolization.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract class CloneableVariable<T> : Variable<T>, ICloneable
|
||||||
|
{
|
||||||
|
protected CloneableVariable(string symbolName, Type variableType) : base(symbolName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CloneableVariable(string symbolName, CloneableVariable<T> variable) : base(symbolName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Clone() => CloneVariable();
|
||||||
|
|
||||||
|
public abstract T CloneVariable();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public readonly struct VariableSymbol
|
public readonly struct VariableSymbol
|
||||||
{
|
{
|
||||||
public readonly string SymbolName;
|
public readonly string SymbolName;
|
||||||
@@ -59,9 +88,4 @@ namespace Convention.Symbolization.Internal
|
|||||||
return new Tuple<string, Type>(SymbolName, VariableType).GetHashCode();
|
return new Tuple<string, Type>(SymbolName, VariableType).GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VariableContext
|
|
||||||
{
|
|
||||||
public Dictionary<VariableSymbol, Variable> Variables = new();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user