Skip to content

Commit

Permalink
рефакторинг объектного типа
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepami committed Dec 8, 2023
1 parent eda24ac commit c7a3000
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions Interpreter.Lib/IR/CheckSemantics/Types/ObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,20 @@ public ObjectType(IEnumerable<PropertyType> properties)

public Type this[string id]
{
get => _properties.TryGetValue(id, out var type)
? type
: null;
get => _properties.GetValueOrDefault(id);
private set => _properties[id] = value;
}

public IEnumerable<string> Keys =>
_properties.Keys;

public override void ResolveReference(
Type reference,
string refId,
ISet<Type> visited = null)
{
visited ??= new HashSet<Type>();
if (visited.Contains(this))
if (!visited.Add(this))
return;

visited.Add(this);

foreach (var key in Keys)
foreach (var key in _properties.Keys)
if (refId == this[key])
this[key] = reference;
else
Expand Down Expand Up @@ -93,7 +86,7 @@ public ObjectTypeHasher(ObjectType reference) =>
};

public int HashObjectType(ObjectType objectType) =>
objectType.Keys.Select(key => HashCode.Combine(
objectType._properties.Keys.Select(key => HashCode.Combine(
key,
objectType[key].Equals(_reference)
? "@this".GetHashCode()
Expand Down Expand Up @@ -154,7 +147,7 @@ public string PrintObjectType(ObjectType objectType)
}

var sb = new StringBuilder("{");
foreach (var key in objectType.Keys)
foreach (var key in objectType._properties.Keys)
{
var type = objectType[key];
var prop = $"{key}: ";
Expand Down

0 comments on commit c7a3000

Please sign in to comment.