Skip to content

Commit c02d288

Browse files
committed
#54 - move AllCodePathsEndedWithReturn from FunctionSymbol to FunctionDeclaration
1 parent ce73017 commit c02d288

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

src/Application/HydraScript.Application.StaticAnalysis/Visitors/DeclarationVisitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public VisitUnit Visit(FunctionDeclaration visitable)
7676
{
7777
var returnAnalyzerResult = visitable.Accept(_returnAnalyzer);
7878
visitable.ReturnStatements = returnAnalyzerResult.ReturnStatements;
79+
visitable.AllCodePathsEndedWithReturn = returnAnalyzerResult.CodePathEndedWithReturn;
7980

8081
var parentTable = _symbolTables[visitable.Parent.Scope];
8182
var indexOfFirstDefaultArgument = visitable.Arguments.AsValueEnumerable()
@@ -94,8 +95,7 @@ public VisitUnit Visit(FunctionDeclaration visitable)
9495
visitable.Name,
9596
parameters,
9697
visitable.ReturnTypeValue.Accept(_typeBuilder),
97-
visitable.IsEmpty,
98-
returnAnalyzerResult.CodePathEndedWithReturn);
98+
visitable.IsEmpty);
9999
if (functionSymbolId.Equals(parentTable.FindSymbol(functionSymbolId)?.Id))
100100
throw new OverloadAlreadyExists(visitable.Name, functionSymbolId);
101101

src/Application/HydraScript.Application.StaticAnalysis/Visitors/SemanticChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public Type Visit(FunctionDeclaration visitable)
510510
symbol.DefineReturnType(returnTypes.Single());
511511

512512
Type @void = "void";
513-
if (!symbol.Type.Equals(@void) && !symbol.AllCodePathsEndedWithReturn)
513+
if (!symbol.Type.Equals(@void) && !visitable.AllCodePathsEndedWithReturn)
514514
throw new FunctionWithoutReturnStatement(visitable.Segment);
515515

516516
if (symbol.Type is NullType)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public partial class FunctionDeclaration : AfterTypesAreLoadedDeclaration
2020

2121
public IReadOnlyList<ReturnStatement> ReturnStatements { get; set; } = [];
2222
public bool HasReturnStatement => ReturnStatements.Count > 0;
23+
public bool AllCodePathsEndedWithReturn { get; set; }
2324

2425
public string ComputedFunctionAddress { get; set; } = string.Empty;
2526

src/Domain/HydraScript.Domain.IR/Impl/Symbols/FunctionSymbol.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public class FunctionSymbol(
88
string name,
99
IReadOnlyList<ISymbol> parameters,
1010
Type type,
11-
bool isEmpty,
12-
bool allCodePathsEndedWithReturn) : Symbol(name, type)
11+
bool isEmpty) : Symbol(name, type)
1312
{
1413
private Type _returnType = type;
1514
/// <summary>Тип возврата функции</summary>
@@ -22,7 +21,6 @@ public class FunctionSymbol(
2221

2322
public IReadOnlyList<ISymbol> Parameters { get; } = parameters;
2423
public bool IsEmpty { get; } = isEmpty;
25-
public bool AllCodePathsEndedWithReturn { get; } = allCodePathsEndedWithReturn;
2624

2725
public void DefineReturnType(Type returnType) =>
2826
_returnType = returnType;

tests/HydraScript.UnitTests/Application/FunctionWithUndefinedReturnStorageTests.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public void StorageIsEmptyAfterFlushTest()
2121
name: FunctionName,
2222
parameters: [],
2323
"undefined",
24-
isEmpty: false,
25-
allCodePathsEndedWithReturn: false);
24+
isEmpty: false);
2625

2726
var decl = new FunctionDeclaration(
2827
name: new IdentifierReference(FunctionName),
@@ -71,31 +70,27 @@ public void StorageIsCorrectOrderTest()
7170
name: "key2",
7271
parameters: [],
7372
"undefined",
74-
isEmpty: false,
75-
allCodePathsEndedWithReturn: false);
73+
isEmpty: false);
7674

7775
storage.Save(new FunctionSymbol(
7876
name: "key1",
7977
parameters: [],
8078
"undefined",
81-
isEmpty: false,
82-
allCodePathsEndedWithReturn: false), declaration: declarations[0]);
79+
isEmpty: false), declaration: declarations[0]);
8380

8481
storage.Save(removable, declaration: declarations[1]);
8582

8683
storage.Save(new FunctionSymbol(
8784
name: "key3",
8885
parameters: [],
8986
"undefined",
90-
isEmpty: false,
91-
allCodePathsEndedWithReturn: false), declaration: declarations[2]);
87+
isEmpty: false), declaration: declarations[2]);
9288

9389
storage.Save(new FunctionSymbol(
9490
name: "key4",
9591
parameters: [],
9692
"undefined",
97-
isEmpty: false,
98-
allCodePathsEndedWithReturn: false), declaration: declarations[3]);
93+
isEmpty: false), declaration: declarations[3]);
9994

10095
storage.RemoveIfPresent(removable);
10196

0 commit comments

Comments
 (0)