Skip to content

Commit 084b687

Browse files
hopefully added recursive var resolving to the api
1 parent 9b9aa57 commit 084b687

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed

ReCT/CodeAnalysis/Binding/Binder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public static BoundProgram BindProgram(bool isScript, BoundProgram previous, Bou
209209
var loweredBody = Lowerer.Lower(fs, body);
210210

211211
fs.scope = ((BoundBlockStatement)body).Scope;
212+
fs.block = (BoundBlockStatement)body;
212213

213214
if (fs.Type != TypeSymbol.Void && !ControlFlowGraph.AllPathsReturn(loweredBody))
214215
Binder._diagnostics.ReportAllPathsMustReturn(fs.Declaration.Identifier.Location);
@@ -226,6 +227,7 @@ public static BoundProgram BindProgram(bool isScript, BoundProgram previous, Bou
226227
var loweredBody = Lowerer.Lower(function, body);
227228

228229
function.scope = ((BoundBlockStatement)body).Scope;
230+
function.block = (BoundBlockStatement)body;
229231

230232
if (function.Type != TypeSymbol.Void && !ControlFlowGraph.AllPathsReturn(loweredBody))
231233
Binder._diagnostics.ReportAllPathsMustReturn(function.Declaration.Identifier.Location);
@@ -242,6 +244,7 @@ public static BoundProgram BindProgram(bool isScript, BoundProgram previous, Bou
242244
var loweredBody = Lowerer.Lower(function, body);
243245

244246
function.scope = ((BoundBlockStatement)body).Scope;
247+
function.block = (BoundBlockStatement)body;
245248

246249
if (function.Type != TypeSymbol.Void && !ControlFlowGraph.AllPathsReturn(loweredBody))
247250
Binder._diagnostics.ReportAllPathsMustReturn(function.Declaration.Identifier.Location);

ReCT/CodeAnalysis/Binding/BoundBlockStatement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace ReCT.CodeAnalysis.Binding
55
{
6-
internal sealed class BoundBlockStatement : BoundStatement
6+
public sealed class BoundBlockStatement : BoundStatement
77
{
88
public BoundBlockStatement(ImmutableArray<BoundStatement> statements, BoundScope scope = null)
99
{

ReCT/CodeAnalysis/Binding/BoundNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ReCT.CodeAnalysis.Binding
44
{
5-
internal abstract class BoundNode
5+
public abstract class BoundNode
66
{
77
public abstract BoundNodeKind Kind { get; }
88

ReCT/CodeAnalysis/Binding/BoundNodeKind.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace ReCT.CodeAnalysis.Binding
22
{
3-
internal enum BoundNodeKind
3+
public enum BoundNodeKind
44
{
55
// Statements
66
BlockStatement,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace ReCT.CodeAnalysis.Binding
22
{
3-
internal abstract class BoundStatement : BoundNode
3+
public abstract class BoundStatement : BoundNode
44
{
55
}
66
}

ReCT/CodeAnalysis/Symbols/FunctionSymbol.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ public sealed class FunctionSymbol : Symbol
2626
public ImmutableArray<ParameterSymbol> Parameters { get; }
2727
public TypeSymbol Type { get; }
2828
public ReCT.CodeAnalysis.Binding.BoundScope scope;
29+
public ReCT.CodeAnalysis.Binding.BoundBlockStatement block;
2930
}
3031
}

rctc/Program.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,15 @@ static void CollectFunctionData(ref List<ReCTFunction> functions, ref List<ReCTG
703703
List<ReCTVariable> variables = new List<ReCTVariable>();
704704
List<ReCTVariable> parameters = new List<ReCTVariable>();
705705

706-
if (fnc.scope != null)
706+
//if (fnc.scope != null)
707+
//{
708+
// foreach(var vr in fnc.scope.GetDeclaredVariables())
709+
// CollectVariableData(ref variables, ref globals, vr);
710+
//}
711+
712+
if (fnc.block != null)
707713
{
708-
foreach(var vr in fnc.scope.GetDeclaredVariables())
709-
CollectVariableData(ref variables, ref globals, vr);
714+
variables.AddRange(CollectVariablesInBlockRecursively(fnc.block, ref globals));
710715
}
711716

712717
foreach(var param in fnc.Parameters)
@@ -718,6 +723,23 @@ static void CollectFunctionData(ref List<ReCTFunction> functions, ref List<ReCTG
718723
function.Parameters = parameters.ToArray();
719724
functions.Add(function);
720725
}
726+
static List<ReCTVariable> CollectVariablesInBlockRecursively(BoundBlockStatement block, ref List<ReCTGlobal> globals)
727+
{
728+
List<ReCTVariable> variables = new List<ReCTVariable>();
729+
730+
if (block.Scope == null) return variables;
731+
732+
foreach(var vr in block.Scope.GetDeclaredVariables())
733+
CollectVariableData(ref variables, ref globals, vr);
734+
735+
foreach(var statement in block.Statements)
736+
if (statement is BoundBlockStatement newBlock)
737+
{
738+
variables.AddRange(CollectVariablesInBlockRecursively(newBlock, ref globals));
739+
}
740+
741+
return variables;
742+
}
721743

722744
static void CollectClassData(ref List<ReCTClass> classes, ref List<ReCTGlobal> globals, ClassSymbol cls)
723745
{

0 commit comments

Comments
 (0)