-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new visitor * контракт взаимодействия * исправление бага * new visitor for ObjectType's hashcode computing * visitor integration * tests * version * tests adjustment * coverage
- Loading branch information
Showing
13 changed files
with
187 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Interpreter.Lib/IR/CheckSemantics/Types/Visitors/ObjectTypeHasher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Linq; | ||
using Visitor.NET.Lib.Core; | ||
|
||
namespace Interpreter.Lib.IR.CheckSemantics.Types.Visitors | ||
{ | ||
public class ObjectTypeHasher : | ||
IVisitor<Type, int>, | ||
IVisitor<ObjectType, int>, | ||
IVisitor<ArrayType, int>, | ||
IVisitor<NullableType, int>, | ||
IVisitor<FunctionType, int> | ||
{ | ||
private readonly ObjectType _reference; | ||
|
||
public ObjectTypeHasher(ObjectType reference) => | ||
_reference = reference; | ||
|
||
public int Visit(Type visitable) => | ||
visitable.GetHashCode(); | ||
|
||
public int Visit(ObjectType visitable) => | ||
visitable.Keys.Select(key => HashCode.Combine(key, | ||
visitable[key].Equals(_reference) | ||
? "@this".GetHashCode() | ||
: visitable[key].Recursive | ||
? key.GetHashCode() | ||
: visitable[key].Accept(this)) | ||
).Aggregate(36, HashCode.Combine); | ||
|
||
public int Visit(ArrayType visitable) => | ||
visitable.Type.Equals(_reference) | ||
? "@this".GetHashCode() | ||
: visitable.Type.Accept(this); | ||
|
||
public int Visit(NullableType visitable) => | ||
visitable.Type.Equals(_reference) | ||
? "@this".GetHashCode() | ||
: visitable.Type.Accept(this); | ||
|
||
public int Visit(FunctionType visitable) => | ||
HashCode.Combine( | ||
visitable.ReturnType.Equals(_reference) | ||
? "@this".GetHashCode() | ||
: visitable.ReturnType.Accept(this), | ||
visitable.Arguments.Select(arg => | ||
arg.Equals(_reference) | ||
? "@this".GetHashCode() | ||
: arg.Accept(this) | ||
).Aggregate(36, HashCode.Combine)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.