-
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.
Исправление процесса сериализации типов объектов (ObjectType) (#2)
* идея переработки сериализации в строку ObjectType.cs * remove unnecessary formatting * some work on it * Добавил пакет с контрактом паттерна "Посетитель", на который переведу AST * тест, который отражает суть бага, исправляемого в рамках #8 * Исправление бага по разрешению ссылок (#8) * Скелет исправления бага через паттерн "Посетитель" * Реализация некоторых посещений, удаление неактуального функционала, доработка тестов * Доработка функционала: - если мы определяем посещение компонента виртуальным методом, то переопределять его надо только в том наследнике компонента, для которого существует специальная логика посещения - доработка тестов * Печать объектного типа с помощью паттерна "Посетитель"
- Loading branch information
Showing
9 changed files
with
258 additions
and
115 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
75 changes: 75 additions & 0 deletions
75
Interpreter.Lib/Semantic/Types/Visitors/ObjectTypePrinter.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,75 @@ | ||
using System.Linq; | ||
using System.Text; | ||
using Visitor.NET.Lib.Core; | ||
|
||
namespace Interpreter.Lib.Semantic.Types.Visitors | ||
{ | ||
public class ObjectTypePrinter : | ||
IVisitor<Type, string>, | ||
IVisitor<ObjectType, string>, | ||
IVisitor<ArrayType, string>, | ||
IVisitor<NullableType, string>, | ||
IVisitor<FunctionType, string> | ||
{ | ||
private readonly ObjectType _reference; | ||
|
||
public ObjectTypePrinter(ObjectType reference) => | ||
_reference = reference; | ||
|
||
public string Visit(Type visitable) => | ||
visitable.ToString(); | ||
|
||
public string Visit(ObjectType visitable) | ||
{ | ||
var sb = new StringBuilder("{"); | ||
foreach (var key in visitable.Keys) | ||
{ | ||
var type = visitable[key]; | ||
var prop = $"{key}: "; | ||
prop += type.Equals(_reference) | ||
? "@this" | ||
: type.Accept(this); | ||
sb.Append(prop).Append(';'); | ||
} | ||
|
||
return sb.Append('}').ToString(); | ||
} | ||
|
||
public string Visit(ArrayType visitable) | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append(visitable.Type.Equals(_reference) | ||
? "@this" | ||
: visitable.Type.Accept(this) | ||
); | ||
|
||
return sb.Append("[]").ToString(); | ||
} | ||
|
||
public string Visit(NullableType visitable) | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append(visitable.Type.Equals(_reference) | ||
? "@this" | ||
: visitable.Type.Accept(this) | ||
); | ||
|
||
return sb.Append('?').ToString(); | ||
} | ||
|
||
public string Visit(FunctionType visitable) | ||
{ | ||
var sb = new StringBuilder("("); | ||
sb.AppendJoin(", ", visitable.Arguments.Select(x => x.Equals(_reference) | ||
? "@this" | ||
: x.Accept(this) | ||
)).Append(") => "); | ||
sb.Append(visitable.ReturnType.Equals(_reference) | ||
? "@this" | ||
: visitable.ReturnType.Accept(this) | ||
); | ||
|
||
return sb.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.