Skip to content

Commit

Permalink
code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
vddCore committed Aug 6, 2024
1 parent a13b76d commit 8b3f930
Show file tree
Hide file tree
Showing 308 changed files with 18,169 additions and 18,446 deletions.
31 changes: 15 additions & 16 deletions Core/EVIL.CommonTypes/TypeSystem/DynamicValueType.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
namespace EVIL.CommonTypes.TypeSystem
namespace EVIL.CommonTypes.TypeSystem;

public enum DynamicValueType
{
public enum DynamicValueType
{
Nil,
Number,
String,
Boolean,
Table,
Array,
Fiber,
Chunk,
Error,
TypeCode,
NativeFunction,
NativeObject
}
Nil,
Number,
String,
Boolean,
Table,
Array,
Fiber,
Chunk,
Error,
TypeCode,
NativeFunction,
NativeObject
}
47 changes: 23 additions & 24 deletions Core/EVIL.Grammar/AST/Base/AstNode.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
using System.Collections.Generic;
namespace EVIL.Grammar.AST.Base;

using System.Collections.Generic;
using System.Linq;

namespace EVIL.Grammar.AST.Base
public abstract class AstNode
{
public abstract class AstNode
{
public int Line { get; set; }
public int Column { get; set; }
public int Line { get; set; }
public int Column { get; set; }

public AstNode? Parent { get; set; }
public AstNode? Parent { get; set; }

public bool IsConstant => this is ConstantExpression;
public bool IsConstant => this is ConstantExpression;

internal T CopyMetadata<T>(AstNode from) where T : AstNode
{
Line = from.Line;
Column = from.Column;
Parent = from.Parent;
internal T CopyMetadata<T>(AstNode from) where T : AstNode
{
Line = from.Line;
Column = from.Column;
Parent = from.Parent;

return (this as T)!;
}
return (this as T)!;
}

protected void Reparent(params AstNode?[] nodes)
protected void Reparent(params AstNode?[] nodes)
{
for (var i = 0; i < nodes.Length; i++)
{
for (var i = 0; i < nodes.Length; i++)
if (nodes[i] != null)
{
if (nodes[i] != null)
{
nodes[i]!.Parent = this;
}
nodes[i]!.Parent = this;
}
}

protected void Reparent(IEnumerable<AstNode?> nodes)
=> Reparent(nodes.ToArray());
}

protected void Reparent(IEnumerable<AstNode?> nodes)
=> Reparent(nodes.ToArray());
}
7 changes: 3 additions & 4 deletions Core/EVIL.Grammar/AST/Base/ConstantExpression.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace EVIL.Grammar.AST.Base
namespace EVIL.Grammar.AST.Base;

public abstract class ConstantExpression : Expression
{
public abstract class ConstantExpression : Expression
{
}
}
23 changes: 11 additions & 12 deletions Core/EVIL.Grammar/AST/Base/Expression.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
namespace EVIL.Grammar.AST.Base;

using EVIL.Grammar.AST.Expressions;

namespace EVIL.Grammar.AST.Base
public abstract class Expression : AstNode
{
public abstract class Expression : AstNode
{
public bool IsValidExpressionStatement
=> this is AssignmentExpression
or InvocationExpression
or SelfInvocationExpression
or IncrementationExpression
or DecrementationExpression
or YieldExpression;
public bool IsValidExpressionStatement
=> this is AssignmentExpression
or InvocationExpression
or SelfInvocationExpression
or IncrementationExpression
or DecrementationExpression
or YieldExpression;

public virtual Expression Reduce() => this;
}
public virtual Expression Reduce() => this;
}
7 changes: 3 additions & 4 deletions Core/EVIL.Grammar/AST/Base/Statement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace EVIL.Grammar.AST.Base
namespace EVIL.Grammar.AST.Base;

public abstract class Statement : AstNode
{
public abstract class Statement : AstNode
{
}
}
15 changes: 7 additions & 8 deletions Core/EVIL.Grammar/AST/Constants/BooleanConstant.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace EVIL.Grammar.AST.Constants;

using EVIL.Grammar.AST.Base;

namespace EVIL.Grammar.AST.Constants
public sealed class BooleanConstant : ConstantExpression
{
public sealed class BooleanConstant : ConstantExpression
{
public bool Value { get; }
public bool Value { get; }

public BooleanConstant(bool value)
{
Value = value;
}
public BooleanConstant(bool value)
{
Value = value;
}
}
7 changes: 3 additions & 4 deletions Core/EVIL.Grammar/AST/Constants/NilConstant.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace EVIL.Grammar.AST.Constants;

using EVIL.Grammar.AST.Base;

namespace EVIL.Grammar.AST.Constants
public sealed class NilConstant : ConstantExpression
{
public sealed class NilConstant : ConstantExpression
{
}
}
17 changes: 8 additions & 9 deletions Core/EVIL.Grammar/AST/Constants/NumberConstant.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using EVIL.Grammar.AST.Base;
namespace EVIL.Grammar.AST.Constants;

namespace EVIL.Grammar.AST.Constants
using EVIL.Grammar.AST.Base;

public sealed class NumberConstant : ConstantExpression
{
public sealed class NumberConstant : ConstantExpression
{
public double Value { get; }
public double Value { get; }

public NumberConstant(double value)
{
Value = value;
}
public NumberConstant(double value)
{
Value = value;
}
}
21 changes: 10 additions & 11 deletions Core/EVIL.Grammar/AST/Constants/StringConstant.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using EVIL.Grammar.AST.Base;
namespace EVIL.Grammar.AST.Constants;

namespace EVIL.Grammar.AST.Constants
using EVIL.Grammar.AST.Base;

public sealed class StringConstant : ConstantExpression
{
public sealed class StringConstant : ConstantExpression
{
public string Value { get; }
public bool IsInterpolated { get; }
public string Value { get; }
public bool IsInterpolated { get; }

public StringConstant(string value, bool isInterpolated)
{
Value = value;
IsInterpolated = isInterpolated;
}
public StringConstant(string value, bool isInterpolated)
{
Value = value;
IsInterpolated = isInterpolated;
}
}
15 changes: 7 additions & 8 deletions Core/EVIL.Grammar/AST/Constants/TypeCodeConstant.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
namespace EVIL.Grammar.AST.Constants;

using EVIL.CommonTypes.TypeSystem;
using EVIL.Grammar.AST.Base;

namespace EVIL.Grammar.AST.Constants
public class TypeCodeConstant : ConstantExpression
{
public class TypeCodeConstant : ConstantExpression
{
public DynamicValueType Value { get; }
public DynamicValueType Value { get; }

public TypeCodeConstant(DynamicValueType value)
{
Value = value;
}
public TypeCodeConstant(DynamicValueType value)
{
Value = value;
}
}
23 changes: 11 additions & 12 deletions Core/EVIL.Grammar/AST/Expressions/ArrayExpression.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
namespace EVIL.Grammar.AST.Expressions;

using System.Collections.Generic;
using EVIL.Grammar.AST.Base;

namespace EVIL.Grammar.AST.Expressions
public sealed class ArrayExpression : Expression
{
public class ArrayExpression : Expression
{
public Expression? SizeExpression { get; }
public List<Expression> Initializers { get; }
public Expression? SizeExpression { get; }
public List<Expression> Initializers { get; }

public ArrayExpression(Expression? sizeExpression, List<Expression> initializers)
{
SizeExpression = sizeExpression;
Initializers = initializers;
public ArrayExpression(Expression? sizeExpression, List<Expression> initializers)
{
SizeExpression = sizeExpression;
Initializers = initializers;

Reparent(SizeExpression);
Reparent(Initializers);
}
Reparent(SizeExpression);
Reparent(Initializers);
}
}
27 changes: 13 additions & 14 deletions Core/EVIL.Grammar/AST/Expressions/AssignmentExpression.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using EVIL.Grammar.AST.Base;
namespace EVIL.Grammar.AST.Expressions;

namespace EVIL.Grammar.AST.Expressions
using EVIL.Grammar.AST.Base;

public sealed class AssignmentExpression : Expression
{
public sealed class AssignmentExpression : Expression
{
public Expression Left { get; }
public Expression Right { get; }
public Expression Left { get; }
public Expression Right { get; }

public AssignmentOperationType OperationType { get; }
public AssignmentOperationType OperationType { get; }

public AssignmentExpression(Expression left, Expression right, AssignmentOperationType operationType)
{
Left = left;
Right = right;
public AssignmentExpression(Expression left, Expression right, AssignmentOperationType operationType)
{
Left = left;
Right = right;

OperationType = operationType;
OperationType = operationType;

Reparent(Left, Right);
}
Reparent(Left, Right);
}
}
Loading

0 comments on commit 8b3f930

Please sign in to comment.