Skip to content

Commit

Permalink
some pr feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuinox committed Oct 28, 2024
1 parent 0922f74 commit 5fe55ad
Show file tree
Hide file tree
Showing 26 changed files with 141 additions and 179 deletions.
4 changes: 2 additions & 2 deletions src/Draco.Compiler.Tests/Semantics/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void AttributeIsWrittenIntoMetadata()
FunctionDeclaration(
[Attribute(NameType("ObsoleteAttribute"), StringExpression("do not use this function"))],
"foo",
ParameterList(Parameter([Attribute(NameType("AllowNullAttribute"))], "arg", NameType("object"))),
ParameterList(NormalParameter([Attribute(NameType("AllowNullAttribute"))], "arg", NameType("object"))),
null,
BlockFunctionBody())));

Expand Down Expand Up @@ -132,7 +132,7 @@ public void AttributeReferencesTheSymbol()
FunctionDeclaration(
[Attribute(NameType("ObsoleteAttribute"), StringExpression("do not use this function"))],
"foo",
ParameterList(Parameter([Attribute(NameType("AllowNullAttribute"))], "arg", NameType("object"))),
ParameterList(NormalParameter([Attribute(NameType("AllowNullAttribute"))], "arg", NameType("object"))),
null,
BlockFunctionBody())));

Expand Down
18 changes: 9 additions & 9 deletions src/Draco.Compiler.Tests/Semantics/ControlFlowGraphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task IfElse()
var program = SyntaxTree.Create(CompilationUnit(
FunctionDeclaration(
"main",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
ExpressionStatement(IfExpression(
Expand Down Expand Up @@ -149,7 +149,7 @@ public async Task EarlyReturn()
var program = SyntaxTree.Create(CompilationUnit(
FunctionDeclaration(
"main",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
ExpressionStatement(CallExpression(NameExpression("bar"))),
Expand Down Expand Up @@ -181,7 +181,7 @@ public async Task ConditionalGotoInAssignment()
var program = SyntaxTree.Create(CompilationUnit(
FunctionDeclaration(
"main",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(VariableDeclaration(true, "x", null, IfExpression(
Expand Down Expand Up @@ -211,14 +211,14 @@ public async Task ForLoop()
var program = SyntaxTree.Create(CompilationUnit(
FunctionDeclaration(
"main",
ParameterList(Parameter("s", GenericType(NameType("Array"), NameType("int32")))),
ParameterList(NormalParameter("s", GenericType(NameType("Array"), NameType("int32")))),
null,
BlockFunctionBody(
ExpressionStatement(ForExpression(
"i",
NameExpression("s"),
CallExpression(NameExpression("bar"), NameExpression("i")))))),
FunctionDeclaration("bar", ParameterList(Parameter("x", NameType("int32"))), null, BlockFunctionBody())));
FunctionDeclaration("bar", ParameterList(NormalParameter("x", NameType("int32"))), null, BlockFunctionBody())));

// Act
var cfg = FunctionToCfg(program);
Expand All @@ -243,10 +243,10 @@ public async Task ChainedComparison()
FunctionDeclaration(
"foo",
ParameterList(
Parameter("a", NameType("int32")),
Parameter("b", NameType("int32")),
Parameter("c", NameType("int32")),
Parameter("d", NameType("int32"))),
NormalParameter("a", NameType("int32")),
NormalParameter("b", NameType("int32")),
NormalParameter("c", NameType("int32")),
NormalParameter("d", NameType("int32"))),
null,
InlineFunctionBody(RelationalExpression(
BlockExpression([ExpressionStatement(CallExpression(NameExpression("bar")))], NameExpression("a")),
Expand Down
8 changes: 4 additions & 4 deletions src/Draco.Compiler.Tests/Semantics/DefiniteAssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void UseOfConditionallyAssignedVariable()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(VariableDeclaration(true, "x", NameType("int32"))),
Expand Down Expand Up @@ -100,7 +100,7 @@ public void UseOfConditionallyAssignedVariableOnBothBranches()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(VariableDeclaration(true, "x", NameType("int32"))),
Expand Down Expand Up @@ -130,7 +130,7 @@ public void JumpingMidAssignment()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(VariableDeclaration(true, "x", NameType("int32"), IfExpression(
Expand Down Expand Up @@ -189,7 +189,7 @@ public void UseVariableAssignedLater()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
ExpressionStatement(WhileExpression(
Expand Down
12 changes: 6 additions & 6 deletions src/Draco.Compiler.Tests/Semantics/LocalFunctionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public void ParameterRedefinitionError()
BlockFunctionBody(DeclarationStatement(FunctionDeclaration(
"bar",
ParameterList(
Parameter("x", NameType("int32")),
Parameter("x", NameType("int32"))),
NormalParameter("x", NameType("int32")),
NormalParameter("x", NameType("int32"))),
null,
BlockFunctionBody()))))));

var x1Decl = tree.GetNode<ParameterSyntax>(0);
var x2Decl = tree.GetNode<ParameterSyntax>(1);
var x1Decl = tree.GetNode<NormalParameterSyntax>(0);
var x2Decl = tree.GetNode<NormalParameterSyntax>(1);

// Act
var compilation = CreateCompilation(tree);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void LocalFunctionContributesToOverloading()
var tree = SyntaxTree.Create(CompilationUnit(
FunctionDeclaration(
name: "foo",
parameters: ParameterList(Parameter("x", NameType("int32"))),
parameters: ParameterList(NormalParameter("x", NameType("int32"))),
returnType: null,
body: BlockFunctionBody()),
FunctionDeclaration(
Expand All @@ -200,7 +200,7 @@ public void LocalFunctionContributesToOverloading()
body: BlockFunctionBody(
DeclarationStatement(FunctionDeclaration(
name: "foo",
parameters: ParameterList(Parameter("x", NameType("string"))),
parameters: ParameterList(NormalParameter("x", NameType("string"))),
returnType: null,
body: BlockFunctionBody())),
ExpressionStatement(CallExpression(NameExpression("foo"), LiteralExpression(0))),
Expand Down
12 changes: 6 additions & 6 deletions src/Draco.Compiler.Tests/Semantics/OverloadingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ public sealed class OverloadingTests
private static IEnumerable<DeclarationSyntax> GetGenericListOverloads() => [
FunctionDeclaration(
"foo",
ParameterList(Parameter("l", GenericType(NameType("List"), NameType("int32")))),
ParameterList(NormalParameter("l", GenericType(NameType("List"), NameType("int32")))),
null,
BlockFunctionBody()),
FunctionDeclaration(
"foo",
ParameterList(Parameter("l", GenericType(NameType("List"), NameType("string")))),
ParameterList(NormalParameter("l", GenericType(NameType("List"), NameType("string")))),
null,
BlockFunctionBody()),
FunctionDeclaration(
"foo",
GenericParameterList(GenericParameter("T")),
ParameterList(Parameter("l", GenericType(NameType("List"), NameType("T")))),
ParameterList(NormalParameter("l", GenericType(NameType("List"), NameType("T")))),
null,
BlockFunctionBody()),
FunctionDeclaration(
"foo",
ParameterList(Parameter("l", GenericType(NameType("IEnumerable"), NameType("int32")))),
ParameterList(NormalParameter("l", GenericType(NameType("IEnumerable"), NameType("int32")))),
null,
BlockFunctionBody()),
FunctionDeclaration(
"foo",
ParameterList(Parameter("l", GenericType(NameType("IEnumerable"), NameType("string")))),
ParameterList(NormalParameter("l", GenericType(NameType("IEnumerable"), NameType("string")))),
null,
BlockFunctionBody()),
FunctionDeclaration(
"foo",
GenericParameterList(GenericParameter("T")),
ParameterList(Parameter("l", GenericType(NameType("IEnumerable"), NameType("T")))),
ParameterList(NormalParameter("l", GenericType(NameType("IEnumerable"), NameType("T")))),
null,
BlockFunctionBody()),
];
Expand Down
8 changes: 4 additions & 4 deletions src/Draco.Compiler.Tests/Semantics/ReturnsOnAllPathsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void NonUnitMethodReturnsConditionally()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
NameType("int32"),
BlockFunctionBody(
ExpressionStatement(IfExpression(
Expand All @@ -124,7 +124,7 @@ public void NonUnitMethodReturnsConditionallyOnBothBranches()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
NameType("int32"),
BlockFunctionBody(
ExpressionStatement(IfExpression(
Expand All @@ -151,7 +151,7 @@ public void NonUnitMethodReturnsConditionallyButThenUnconditionally()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
NameType("int32"),
BlockFunctionBody(
ExpressionStatement(IfExpression(
Expand All @@ -177,7 +177,7 @@ public void NonUnitMethodReturnsInConditionalLoop()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
NameType("int32"),
BlockFunctionBody(
ExpressionStatement(WhileExpression(
Expand Down
6 changes: 3 additions & 3 deletions src/Draco.Compiler.Tests/Semantics/SingleAssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void AssignImmutableInMutuallyExclusiveBranches()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(ImmutableVariableDeclaration(true, "x", NameType("int32"))),
Expand Down Expand Up @@ -95,7 +95,7 @@ public void ConditionallyAndThenUnconditionallyAssignImmutable()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(ImmutableVariableDeclaration(true, "x", NameType("int32"))),
Expand Down Expand Up @@ -124,7 +124,7 @@ public void AssignImmutableInLoop()
// }
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("b", NameType("bool"))),
ParameterList(NormalParameter("b", NameType("bool"))),
null,
BlockFunctionBody(
DeclarationStatement(ImmutableVariableDeclaration(true, "x", NameType("int32"))),
Expand Down
26 changes: 13 additions & 13 deletions src/Draco.Compiler.Tests/Semantics/SymbolResolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void BasicScopeTree()
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(
Parameter("n", NameType("int32"))),
NormalParameter("n", NameType("int32"))),
null,
BlockFunctionBody(
DeclarationStatement(VariableDeclaration(true, "x1")),
Expand All @@ -53,7 +53,7 @@ public void BasicScopeTree()
ExpressionStatement(BlockExpression(DeclarationStatement(VariableDeclaration(true, "x6"))))))))));

var foo = tree.GetNode<FunctionDeclarationSyntax>();
var n = tree.GetNode<ParameterSyntax>();
var n = tree.GetNode<NormalParameterSyntax>();
var x1 = tree.GetNode<VariableDeclarationSyntax>(0);
var x2 = tree.GetNode<VariableDeclarationSyntax>(1);
var x3 = tree.GetNode<VariableDeclarationSyntax>(2);
Expand Down Expand Up @@ -327,13 +327,13 @@ public void ParameterRedefinitionError()
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(
Parameter("x", NameType("int32")),
Parameter("x", NameType("int32"))),
NormalParameter("x", NameType("int32")),
NormalParameter("x", NameType("int32"))),
null,
BlockFunctionBody())));

var x1Decl = tree.GetNode<ParameterSyntax>(0);
var x2Decl = tree.GetNode<ParameterSyntax>(1);
var x1Decl = tree.GetNode<NormalParameterSyntax>(0);
var x2Decl = tree.GetNode<NormalParameterSyntax>(1);

// Act
var compilation = CreateCompilation(tree);
Expand Down Expand Up @@ -361,14 +361,14 @@ public void RedefinedParameterReference()
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(
Parameter("x", NameType("int32")),
Parameter("x", NameType("int32"))),
NormalParameter("x", NameType("int32")),
NormalParameter("x", NameType("int32"))),
null,
BlockFunctionBody(
DeclarationStatement(VariableDeclaration(true, "y", null, NameExpression("x")))))));

var x1Decl = tree.GetNode<ParameterSyntax>(0);
var x2Decl = tree.GetNode<ParameterSyntax>(1);
var x1Decl = tree.GetNode<NormalParameterSyntax>(0);
var x2Decl = tree.GetNode<NormalParameterSyntax>(1);
var xRef = tree.GetNode<NameExpressionSyntax>(0);

// Act
Expand Down Expand Up @@ -418,7 +418,7 @@ public void FuncOverloadsGlobalVar()
VariableDeclaration(true, "b", NameType("int32")),
FunctionDeclaration(
"b",
ParameterList(Parameter("b", NameType("int32"))),
ParameterList(NormalParameter("b", NameType("int32"))),
NameType("int32"),
InlineFunctionBody(NameExpression("b")))));

Expand Down Expand Up @@ -1664,7 +1664,7 @@ public void UndefinedTypeInParameterType()
// Arrange
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
ParameterList(Parameter("x", NameType("unknown"))),
ParameterList(NormalParameter("x", NameType("unknown"))),
null,
BlockFunctionBody())));

Expand Down Expand Up @@ -3246,7 +3246,7 @@ public void GenericFunction()
var tree = SyntaxTree.Create(CompilationUnit(FunctionDeclaration(
"foo",
GenericParameterList(GenericParameter("T")),
ParameterList(Parameter("x", NameType("T"))),
ParameterList(NormalParameter("x", NameType("T"))),
NameType("T"),
InlineFunctionBody(NameExpression("x")))));

Expand Down
Loading

0 comments on commit 5fe55ad

Please sign in to comment.