Skip to content

Commit bbe2292

Browse files
author
Минин Степан Александрович
committed
revert(AST): Clone
Leave Expression the only cloning nodes
1 parent ba5ce24 commit bbe2292

16 files changed

Lines changed: 4 additions & 69 deletions

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/AbstractSyntaxTreeNode.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ IEnumerator IEnumerable.GetEnumerator() =>
3636
public IReadOnlyList<IAbstractSyntaxTreeNode> GetAllNodes() =>
3737
new TraverseEnumerator(this).AsValueEnumerable().ToArray();
3838

39-
public abstract IAbstractSyntaxTreeNode Clone();
40-
4139
/// <summary>
4240
/// Метод возвращает <c>true</c>, если узел - потомок заданного типа и выполняется заданное условие.<br/>
4341
/// В случае, когда условие не задано, проверяется просто соответствие типов.

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/AfterTypesAreLoaded/FunctionDeclaration.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,4 @@ public override void InitScope(Scope? scope = null)
5656

5757
protected override string NodeRepresentation() =>
5858
ZString.Concat<string, char, string>("function", ' ', Name);
59-
60-
public override FunctionDeclaration Clone() =>
61-
new(
62-
Name.Clone(),
63-
ReturnTypeValue.DeepClone(),
64-
_arguments.Select(x => x.DeepClone()).ToList(),
65-
Statements.Clone(),
66-
IndexOfFirstDefaultArgument);
6759
}

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/AfterTypesAreLoaded/IFunctionArgument.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public interface IFunctionArgument
99
public TypeValue TypeValue { get; }
1010

1111
public ValueDto Info { get; }
12-
13-
public IFunctionArgument DeepClone();
1412
}
1513

1614
public record NamedArgument(
@@ -21,11 +19,6 @@ public override string ToString() =>
2119
$"{Name}: {TypeValue}";
2220

2321
public ValueDto Info { get; } = ValueDto.NameDto(Name);
24-
25-
public IFunctionArgument DeepClone() => this with
26-
{
27-
TypeValue = TypeValue.DeepClone()
28-
};
2922
}
3023

3124
public record DefaultValueArgument : IFunctionArgument
@@ -43,11 +36,6 @@ public DefaultValueArgument(string name, Literal literal)
4336

4437
public ValueDto Info { get; }
4538

46-
public IFunctionArgument DeepClone() =>
47-
new DefaultValueArgument(
48-
Name,
49-
new Literal(TypeValue.DeepClone(), Info.Value, label: Info.Label));
50-
5139
public override string ToString() =>
5240
$"{Name} = {Info.Label}";
5341
}

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/AfterTypesAreLoaded/LexicalDeclaration.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,4 @@ public void AddAssignment(AssignmentExpression assignment)
2121

2222
protected override string NodeRepresentation() =>
2323
ReadOnly ? "const" : "let";
24-
25-
public override LexicalDeclaration Clone()
26-
{
27-
var clone = new LexicalDeclaration(ReadOnly);
28-
for (var i = 0; i < _assignments.Count; i++)
29-
{
30-
clone.AddAssignment(_assignments[i].Clone());
31-
}
32-
33-
return clone;
34-
}
3524
}

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/TypeDeclaration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ public override void InitScope(Scope? scope = null)
1717

1818
protected override string NodeRepresentation() =>
1919
$"type {TypeId.Name} = {TypeValue}";
20-
21-
public override TypeDeclaration Clone() => new(TypeId.Clone(), TypeValue.DeepClone());
2220
}

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/Expression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions;
22

33
public abstract class Expression : AbstractSyntaxTreeNode
44
{
5-
public abstract override Expression Clone();
5+
public abstract Expression Clone();
66

77
public abstract override TReturn Accept<TReturn>(
88
IVisitor<IAbstractSyntaxTreeNode, TReturn> visitor);

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/ScriptBody.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@ public override void InitScope(Scope? scope = null)
2323
}
2424

2525
protected override string NodeRepresentation() => "Script";
26-
27-
public override ScriptBody Clone() =>
28-
new(_statementList.Select(x => x.Clone()).ToList());
2926
}
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes;
22

33
public abstract class StatementListItem :
4-
AbstractSyntaxTreeNode
5-
{
6-
public abstract override StatementListItem Clone();
7-
}
4+
AbstractSyntaxTreeNode;
85

96
public abstract class Statement :
10-
StatementListItem
11-
{
12-
public abstract override Statement Clone();
13-
}
7+
StatementListItem;
148

159
public abstract class Declaration :
16-
StatementListItem
17-
{
18-
public abstract override Declaration Clone();
19-
}
10+
StatementListItem;

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Statements/BlockStatement.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@ public override void InitScope(Scope? scope = null)
2424
}
2525

2626
protected override string NodeRepresentation() => "{}";
27-
28-
public override BlockStatement Clone() =>
29-
new(_statementList.Select(x => x.Clone()).ToList());
3027
}

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Statements/ExpressionStatement.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ public ExpressionStatement(Expression expression)
1616
}
1717

1818
protected override string NodeRepresentation() => nameof(ExpressionStatement);
19-
20-
public override ExpressionStatement Clone() => new(Expression.Clone());
2119
}

0 commit comments

Comments
 (0)