-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Исправление бага по разрешению ссылок (#8)
* Скелет исправления бага через паттерн "Посетитель" * Реализация некоторых посещений, удаление неактуального функционала, доработка тестов * Доработка функционала: - если мы определяем посещение компонента виртуальным методом, то переопределять его надо только в том наследнике компонента, для которого существует специальная логика посещения - доработка тестов
- Loading branch information
Showing
7 changed files
with
138 additions
and
106 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
70 changes: 70 additions & 0 deletions
70
Interpreter.Lib/Semantic/Types/Visitors/ReferenceResolver.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,70 @@ | ||
using Visitor.NET.Lib.Core; | ||
|
||
namespace Interpreter.Lib.Semantic.Types.Visitors | ||
{ | ||
public class ReferenceResolver : | ||
IVisitor<Type, Unit>, | ||
IVisitor<ArrayType, Unit>, | ||
IVisitor<FunctionType, Unit>, | ||
IVisitor<NullableType, Unit>, | ||
IVisitor<ObjectType, Unit> | ||
{ | ||
private readonly ObjectType _reference; | ||
private readonly string _refId; | ||
|
||
public ReferenceResolver(ObjectType reference, string refId) | ||
{ | ||
_reference = reference; | ||
_refId = refId; | ||
} | ||
|
||
public Unit Visit(ObjectType visitable) | ||
{ | ||
foreach (var key in visitable.Keys) | ||
if (_refId == visitable[key]) | ||
visitable[key] = _reference; | ||
else | ||
visitable[key].Accept(this); | ||
return default; | ||
} | ||
|
||
public Unit Visit(Type visitable) => default; | ||
|
||
public Unit Visit(ArrayType visitable) | ||
{ | ||
if (visitable.Type == _refId) | ||
visitable.Type = _reference; | ||
else | ||
visitable.Type.Accept(this); | ||
return default; | ||
} | ||
|
||
public Unit Visit(FunctionType visitable) | ||
{ | ||
if (visitable.ReturnType == _refId) | ||
visitable.ReturnType = _reference; | ||
else | ||
visitable.ReturnType.Accept(this); | ||
|
||
for (var i = 0; i < visitable.Arguments.Count; i++) | ||
{ | ||
var argType = visitable.Arguments[i]; | ||
if (argType == _refId) | ||
visitable.Arguments[i] = _reference; | ||
else | ||
argType.Accept(this); | ||
} | ||
|
||
return default; | ||
} | ||
|
||
public Unit Visit(NullableType visitable) | ||
{ | ||
if (visitable.Type == _refId) | ||
visitable.Type = _reference; | ||
else | ||
visitable.Type.Accept(this); | ||
return default; | ||
} | ||
} | ||
} |
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