Skip to content

Commit

Permalink
A little bit of cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
vddCore committed May 9, 2024
1 parent 9814c86 commit 31eec2c
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Core/EVIL.Grammar/AST/Base/AstNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void Reparent(params AstNode?[] nodes)
}
}

protected void Reparent(IEnumerable<AstNode> nodes)
protected void Reparent(IEnumerable<AstNode?> nodes)
=> Reparent(nodes.ToArray());
}
}
3 changes: 2 additions & 1 deletion Core/EVIL.Grammar/AST/Expressions/ArrayExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public ArrayExpression(Expression? sizeExpression, List<Expression> initializers
SizeExpression = sizeExpression;
Initializers = initializers;

Reparent(initializers);
Reparent(SizeExpression);
Reparent(Initializers);
}
}
}
7 changes: 1 addition & 6 deletions Core/EVIL.Grammar/AST/Expressions/ByExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace EVIL.Grammar.AST.Expressions
public class ByExpression : Expression
{
public Expression Qualifier { get; }

public List<ByArmNode> Arms { get; }
public AstNode? ElseArm { get; }

Expand All @@ -19,11 +18,7 @@ public ByExpression(Expression qualifier, List<ByArmNode> arms, AstNode? elseArm

Reparent(Qualifier);
Reparent(Arms);

if (ElseArm != null)
{
Reparent(ElseArm);
}
Reparent(ElseArm);
}
}
}
11 changes: 2 additions & 9 deletions Core/EVIL.Grammar/AST/Expressions/ErrorExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ public ErrorExpression(StringConstant? implicitMessageConstant, TableExpression?
ImplicitMessageConstant = implicitMessageConstant;
UserDataTable = userDataTable;

if (ImplicitMessageConstant != null)
{
Reparent(ImplicitMessageConstant);
}

if (UserDataTable != null)
{
Reparent(UserDataTable);
}
Reparent(ImplicitMessageConstant);
Reparent(UserDataTable);
}
}
}
6 changes: 1 addition & 5 deletions Core/EVIL.Grammar/AST/Expressions/FnExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ public FnExpression(
ParameterList = parameterList;
Statement = statement;

if (ParameterList != null)
{
Reparent(ParameterList);
}

Reparent(ParameterList);
Reparent(Statement);
}
}
Expand Down
8 changes: 2 additions & 6 deletions Core/EVIL.Grammar/AST/Expressions/SelfFnExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ public SelfFnExpression(
{
ParameterList = parameterList;
Statement = statement;

if (ParameterList != null)
{
Reparent(ParameterList);
}


Reparent(ParameterList);
Reparent(Statement);
}
}
Expand Down
3 changes: 1 addition & 2 deletions Core/EVIL.Grammar/AST/Expressions/TableExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public TableExpression(List<Expression> initializers, bool keyed)
Initializers = initializers;
Keyed = keyed;

for (var i = 0; i < Initializers.Count; i++)
Reparent(Initializers[i]);
Reparent(Initializers);
}
}
}
2 changes: 1 addition & 1 deletion Core/EVIL.Grammar/AST/Miscellaneous/AttributeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public AttributeNode(
Properties = properties;

Reparent(Identifier);
Reparent(values);
Reparent(Values);
Reparent(Properties.Keys);
Reparent(Properties.Values);
}
Expand Down
4 changes: 1 addition & 3 deletions Core/EVIL.Grammar/AST/Miscellaneous/ParameterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public ParameterNode(IdentifierNode identifier, bool readWrite, ConstantExpressi
Initializer = initializer;

Reparent(Identifier);

if (Initializer != null)
Reparent(Initializer);
Reparent(Initializer);
}
}
}
6 changes: 1 addition & 5 deletions Core/EVIL.Grammar/AST/Statements/BlockStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ public sealed class BlockStatement : Statement
public BlockStatement(List<Statement> statements)
{
Statements = statements;

for (var i = 0; i < statements.Count; i++)
{
Reparent(statements[i]);
}
Reparent(Statements);
}
}
}
5 changes: 1 addition & 4 deletions Core/EVIL.Grammar/AST/Statements/EachStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public EachStatement(
Statement = statement;

Reparent(KeyIdentifier);

if (ValueIdentifier != null)
Reparent(ValueIdentifier);

Reparent(ValueIdentifier);
Reparent(Iterable, Statement);
}
}
Expand Down
7 changes: 1 addition & 6 deletions Core/EVIL.Grammar/AST/Statements/FnStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ public FnStatement(
IsLocalDefintion = isLocalDefintion;

Reparent(Identifier);

if (ParameterList != null)
{
Reparent(ParameterList);
}

Reparent(ParameterList);
Reparent(Statement);
Reparent(Attributes);
}
Expand Down
8 changes: 2 additions & 6 deletions Core/EVIL.Grammar/AST/Statements/FnTargetedStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class FnTargetedStatement : Statement
public ParameterList? ParameterList { get; }
public Statement Statement { get; }
public List<AttributeNode> Attributes { get; }

public bool IsSelfTargeting => PrimaryTarget is SelfExpression;

public FnTargetedStatement(
Expand All @@ -29,12 +30,7 @@ public FnTargetedStatement(

Reparent(PrimaryTarget);
Reparent(SecondaryIdentifier);

if (ParameterList != null)
{
Reparent(ParameterList);
}

Reparent(ParameterList);
Reparent(Statement);
Reparent(Attributes);
}
Expand Down
7 changes: 1 addition & 6 deletions Core/EVIL.Grammar/AST/Statements/OverrideStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ Statement statement
Statement = statement;

Reparent(Target);

if (ParameterList != null)
{
Reparent(ParameterList);
}

Reparent(ParameterList);
Reparent(Statement);
}
}
Expand Down
6 changes: 1 addition & 5 deletions Core/EVIL.Grammar/AST/Statements/RetStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ public sealed class RetStatement : Statement
public RetStatement(Expression? expression)
{
Expression = expression;

if (Expression != null)
{
Reparent(Expression);
}
Reparent(Expression);
}
}
}
1 change: 0 additions & 1 deletion Core/EVIL.Grammar/AST/Statements/TryStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace EVIL.Grammar.AST.Statements
public class TryStatement : Statement
{
public Statement InnerStatement { get; }

public IdentifierNode? HandlerExceptionLocal { get; }
public Statement HandlerStatement { get; }

Expand Down
7 changes: 1 addition & 6 deletions Core/EVIL.Grammar/AST/Statements/ValStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ public ValStatement(
ReadWrite = readWrite;

Reparent(Definitions.Keys);

foreach (var kvp in Definitions)
{
if (kvp.Value != null)
Reparent(kvp.Value);
}
Reparent(Definitions.Values);
}
}
}
2 changes: 1 addition & 1 deletion VirtualMachine/Tests/Ceres.LanguageTests/tests/023_try.vil
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn try_error_implicit_message_and_userdata {
assert.equal(result2, "meow");
}

#[test;disasm("always")]
#[test]
fn try_no_local() {
rw val caught = false;

Expand Down

0 comments on commit 31eec2c

Please sign in to comment.