Skip to content

Commit

Permalink
refactor: NoTypeName should be only one instance
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Feb 6, 2025
1 parent 1deec1b commit 4f14eaf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion NewSource/Socordia.CodeAnalysis/AST/TypeNames/NoTypeName.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
namespace Socordia.CodeAnalysis.AST.TypeNames;

public class NoTypeName : TypeName;
public class NoTypeName : TypeName
{
public static readonly NoTypeName Instance { get; } = new NoTypeName();

private NoTypeName() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser)
var keywordToken = iterator.Prev;

var isMutable = false;
TypeName? type = new NoTypeName();
TypeName? type = NoTypeName.Instance;

Token mutableToken = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static TypeName Parse(Parser parser)
parser.AddError("Expected Identifier, TupleType or Function-Signature as TypeLiteral, but got " +
TokenIterator.GetTokenRepresentation(iterator.Current.Type));

typeNode = new NoTypeName();
typeNode = NoTypeName.Instance;
iterator.NextToken();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SwapLowerer : Replacer<AstNode, BinaryOperatorExpression>

//todo: implement a swap by introducting a new temp variable and test it
var tmpName = Utils.GenerateIdentifier();
var tmp = new VariableStatement(tmpName, new NoTypeName(), new Identifier(leftId.Name), false);
var tmp = new VariableStatement(tmpName, NoTypeName.Instance, new Identifier(leftId.Name), false);

var left = new BinaryOperatorExpression("=", new Identifier(leftId.Name), new Identifier(rightId.Name));
var right = new BinaryOperatorExpression("=", new Identifier(rightId.Name), new Identifier(tmpName));
Expand Down

0 comments on commit 4f14eaf

Please sign in to comment.