From 1e7fc7629e8626b202ee213eb4f8a76573cf681e Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 17 Jan 2019 13:56:53 +0100 Subject: [PATCH] Adds GetChildren method for boundNodes --- .../BoundExpressions/BoundBinaryExpression.cs | 6 ++++++ .../BoundExpressions/BoundFunctionCallExpression.cs | 9 +++++++++ .../BoundExpressions/BoundFunctionExpression.cs | 12 +++++++++++- .../Binder/BoundExpressions/BoundIndexExpression.cs | 11 +++++++++++ .../BoundExpressions/BoundLiteralExpression.cs | 5 +++++ .../Binder/BoundExpressions/BoundTableExpression.cs | 8 +++++++- .../Binder/BoundExpressions/BoundUnaryExpression.cs | 5 +++++ .../BoundExpressions/BoundVariableExpression.cs | 5 +++++ Upsilon/Binder/BoundNode.cs | 1 + .../Binder/BoundStatements/BoundBlockStatement.cs | 5 +++++ .../Binder/BoundStatements/BoundBreakStatement.cs | 5 +++++ .../BoundStatements/BoundExpressionStatement.cs | 5 +++++ .../BoundFunctionAssignmentStatement.cs | 5 +++++ .../BoundStatements/BoundGenericForStatement.cs | 6 ++++++ Upsilon/Binder/BoundStatements/BoundIfStatement.cs | 13 +++++++++++++ .../BoundMultiAssignmentStatement.cs | 5 +++++ .../BoundStatements/BoundNumericForStatement.cs | 8 ++++++++ .../Binder/BoundStatements/BoundReturnStatement.cs | 5 +++++ Upsilon/Binder/BoundStatements/BoundScript.cs | 5 +++++ .../BoundStatements/BoundTableAssigmentStatement.cs | 6 ++++++ .../BoundStatements/BoundVariableAssignment.cs | 5 +++++ .../Binder/BoundStatements/BoundWhileStatement.cs | 6 ++++++ Upsilon/Binder/BoundVariableSymbol.cs | 5 +++++ 23 files changed, 144 insertions(+), 2 deletions(-) diff --git a/Upsilon/Binder/BoundExpressions/BoundBinaryExpression.cs b/Upsilon/Binder/BoundExpressions/BoundBinaryExpression.cs index 1aecadb..588628a 100644 --- a/Upsilon/Binder/BoundExpressions/BoundBinaryExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundBinaryExpression.cs @@ -36,6 +36,12 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield return LeftExpression; + yield return RightExpression; + } + public override Type Type { get; } public BoundBinaryOperator Operator { get; } diff --git a/Upsilon/Binder/BoundExpressions/BoundFunctionCallExpression.cs b/Upsilon/Binder/BoundExpressions/BoundFunctionCallExpression.cs index 338ae2f..5ca4684 100644 --- a/Upsilon/Binder/BoundExpressions/BoundFunctionCallExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundFunctionCallExpression.cs @@ -43,6 +43,15 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield return Identifier; + foreach (var parameter in Parameters) + { + yield return parameter; + } + } + public override Type Type { get; } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundExpressions/BoundFunctionExpression.cs b/Upsilon/Binder/BoundExpressions/BoundFunctionExpression.cs index 17c62b5..10fecd2 100644 --- a/Upsilon/Binder/BoundExpressions/BoundFunctionExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundFunctionExpression.cs @@ -1,7 +1,8 @@ +using System; using System.Collections.Generic; using System.Collections.Immutable; -using Upsilon.BaseTypes; using Upsilon.Text; +using Type = Upsilon.BaseTypes.Type; namespace Upsilon.Binder { @@ -38,6 +39,15 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + foreach (var parameter in Parameters) + { + yield return parameter; + } + yield return Block; + } + public override Type Type => Type.Function; public BoundScope Scope { get; set; } public Type ReturnType { get; } diff --git a/Upsilon/Binder/BoundExpressions/BoundIndexExpression.cs b/Upsilon/Binder/BoundExpressions/BoundIndexExpression.cs index dc9ddac..c2057ea 100644 --- a/Upsilon/Binder/BoundExpressions/BoundIndexExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundIndexExpression.cs @@ -33,6 +33,12 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield return Identifier; + yield return Index; + } + public override Type Type { get; } } @@ -61,6 +67,11 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield return Expression; + } + public override Type Type { get; } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundExpressions/BoundLiteralExpression.cs b/Upsilon/Binder/BoundExpressions/BoundLiteralExpression.cs index c4ca7ae..9452bea 100644 --- a/Upsilon/Binder/BoundExpressions/BoundLiteralExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundLiteralExpression.cs @@ -17,6 +17,11 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield break; + } + public override Type Type => Value.Type; public ScriptType Value { get; } } diff --git a/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs b/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs index 1865807..a91604a 100644 --- a/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundTableExpression.cs @@ -1,8 +1,9 @@ +using System; using System.Collections.Generic; using System.Collections.Immutable; -using Upsilon.BaseTypes; using Upsilon.Binder.VariableSymbols; using Upsilon.Text; +using Type = Upsilon.BaseTypes.Type; namespace Upsilon.Binder { @@ -29,6 +30,11 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + return Statements; + } + public override Type Type => Type.Table; diff --git a/Upsilon/Binder/BoundExpressions/BoundUnaryExpression.cs b/Upsilon/Binder/BoundExpressions/BoundUnaryExpression.cs index 168e6fe..eb97626 100644 --- a/Upsilon/Binder/BoundExpressions/BoundUnaryExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundUnaryExpression.cs @@ -17,6 +17,11 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield return InExpression; + } + public override Type Type { get; } public BoundUnaryExpression(BoundUnaryOperator op, BoundExpression inExpression, Type type, TextSpan span) : base(span) diff --git a/Upsilon/Binder/BoundExpressions/BoundVariableExpression.cs b/Upsilon/Binder/BoundExpressions/BoundVariableExpression.cs index 551e39c..b792e57 100644 --- a/Upsilon/Binder/BoundExpressions/BoundVariableExpression.cs +++ b/Upsilon/Binder/BoundExpressions/BoundVariableExpression.cs @@ -19,6 +19,11 @@ namespace Upsilon.Binder yield return Variable; } + public override IEnumerable GetChildren() + { + yield break; + } + public override Type Type => Variable.Type; } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundNode.cs b/Upsilon/Binder/BoundNode.cs index 41ec278..1978b24 100644 --- a/Upsilon/Binder/BoundNode.cs +++ b/Upsilon/Binder/BoundNode.cs @@ -14,5 +14,6 @@ namespace Upsilon.Binder public TextSpan Span { get; } public abstract IEnumerable GetNodeAtPosition(int linePosition, int characterPosition); + public abstract IEnumerable GetChildren(); } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundBlockStatement.cs b/Upsilon/Binder/BoundStatements/BoundBlockStatement.cs index 1b05f0c..c8dfbf1 100644 --- a/Upsilon/Binder/BoundStatements/BoundBlockStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundBlockStatement.cs @@ -28,6 +28,11 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + return Statements; + } + public ImmutableArray Statements { get; } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundBreakStatement.cs b/Upsilon/Binder/BoundStatements/BoundBreakStatement.cs index 6e27655..ec9ba87 100644 --- a/Upsilon/Binder/BoundStatements/BoundBreakStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundBreakStatement.cs @@ -14,5 +14,10 @@ namespace Upsilon.Binder { yield return this; } + + public override IEnumerable GetChildren() + { + yield break; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundExpressionStatement.cs b/Upsilon/Binder/BoundStatements/BoundExpressionStatement.cs index 62b9d42..afd175c 100644 --- a/Upsilon/Binder/BoundStatements/BoundExpressionStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundExpressionStatement.cs @@ -14,6 +14,11 @@ namespace Upsilon.Binder } + public override IEnumerable GetChildren() + { + yield return Expression; + } + public BoundExpressionStatement(BoundExpression expression, TextSpan span):base(span) { Expression = expression; diff --git a/Upsilon/Binder/BoundStatements/BoundFunctionAssignmentStatement.cs b/Upsilon/Binder/BoundStatements/BoundFunctionAssignmentStatement.cs index 9f09359..de57fc9 100644 --- a/Upsilon/Binder/BoundStatements/BoundFunctionAssignmentStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundFunctionAssignmentStatement.cs @@ -24,5 +24,10 @@ namespace Upsilon.Binder yield return this; } + + public override IEnumerable GetChildren() + { + yield return Func; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundGenericForStatement.cs b/Upsilon/Binder/BoundStatements/BoundGenericForStatement.cs index 60b0550..f175efd 100644 --- a/Upsilon/Binder/BoundStatements/BoundGenericForStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundGenericForStatement.cs @@ -34,5 +34,11 @@ namespace Upsilon.Binder } yield return this; } + + public override IEnumerable GetChildren() + { + yield return BoundEnumerableExpression; + yield return Block; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundIfStatement.cs b/Upsilon/Binder/BoundStatements/BoundIfStatement.cs index 2cd3ccd..f8e5306 100644 --- a/Upsilon/Binder/BoundStatements/BoundIfStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundIfStatement.cs @@ -50,6 +50,14 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield return Condition; + yield return Block; + if (NextElseIf != null) yield return NextElseIf; + if (ElseStatement != null) yield return ElseStatement; + } + public BoundExpressionStatement Condition { get; } public BoundBlockStatement Block { get; } public BoundIfStatement NextElseIf { get; } @@ -75,5 +83,10 @@ namespace Upsilon.Binder } yield return this; } + + public override IEnumerable GetChildren() + { + yield return Block; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundMultiAssignmentStatement.cs b/Upsilon/Binder/BoundStatements/BoundMultiAssignmentStatement.cs index 1fb1a25..3d97f66 100644 --- a/Upsilon/Binder/BoundStatements/BoundMultiAssignmentStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundMultiAssignmentStatement.cs @@ -26,5 +26,10 @@ namespace Upsilon.Binder yield return this; } + + public override IEnumerable GetChildren() + { + yield return Assignment; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundNumericForStatement.cs b/Upsilon/Binder/BoundStatements/BoundNumericForStatement.cs index 147d2d0..489f278 100644 --- a/Upsilon/Binder/BoundStatements/BoundNumericForStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundNumericForStatement.cs @@ -39,5 +39,13 @@ namespace Upsilon.Binder yield return boundNode; yield return this; } + + public override IEnumerable GetChildren() + { + yield return BoundStart; + yield return BoundStop; + yield return BoundStep; + yield return Block; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundReturnStatement.cs b/Upsilon/Binder/BoundStatements/BoundReturnStatement.cs index cd62c5c..2121f69 100644 --- a/Upsilon/Binder/BoundStatements/BoundReturnStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundReturnStatement.cs @@ -19,5 +19,10 @@ namespace Upsilon.Binder yield return boundNode; yield return this; } + + public override IEnumerable GetChildren() + { + yield return Expression; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundScript.cs b/Upsilon/Binder/BoundStatements/BoundScript.cs index 9f6448f..75644a8 100644 --- a/Upsilon/Binder/BoundStatements/BoundScript.cs +++ b/Upsilon/Binder/BoundStatements/BoundScript.cs @@ -23,6 +23,11 @@ namespace Upsilon.Binder foreach (var boundNode in Statement.GetNodeAtPosition(linePosition, characterPosition)) yield return boundNode; } + public override IEnumerable GetChildren() + { + yield return Statement; + } + public BoundBlockStatement Statement { get; } public BoundScope Scope { get; } } diff --git a/Upsilon/Binder/BoundStatements/BoundTableAssigmentStatement.cs b/Upsilon/Binder/BoundStatements/BoundTableAssigmentStatement.cs index 7988f45..0f427ff 100644 --- a/Upsilon/Binder/BoundStatements/BoundTableAssigmentStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundTableAssigmentStatement.cs @@ -26,5 +26,11 @@ namespace Upsilon.Binder yield return boundNode; yield return this; } + + public override IEnumerable GetChildren() + { + yield return TableIndexExpression; + yield return Value; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundVariableAssignment.cs b/Upsilon/Binder/BoundStatements/BoundVariableAssignment.cs index 14b2d9b..3ab0e94 100644 --- a/Upsilon/Binder/BoundStatements/BoundVariableAssignment.cs +++ b/Upsilon/Binder/BoundStatements/BoundVariableAssignment.cs @@ -28,5 +28,10 @@ namespace Upsilon.Binder yield return this; } + + public override IEnumerable GetChildren() + { + yield return BoundExpression; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundStatements/BoundWhileStatement.cs b/Upsilon/Binder/BoundStatements/BoundWhileStatement.cs index 3e2fd68..e5e6a38 100644 --- a/Upsilon/Binder/BoundStatements/BoundWhileStatement.cs +++ b/Upsilon/Binder/BoundStatements/BoundWhileStatement.cs @@ -27,5 +27,11 @@ namespace Upsilon.Binder yield return boundNode; yield return this; } + + public override IEnumerable GetChildren() + { + yield return Condition; + yield return Block; + } } } \ No newline at end of file diff --git a/Upsilon/Binder/BoundVariableSymbol.cs b/Upsilon/Binder/BoundVariableSymbol.cs index cae6dbb..dab8704 100644 --- a/Upsilon/Binder/BoundVariableSymbol.cs +++ b/Upsilon/Binder/BoundVariableSymbol.cs @@ -22,6 +22,11 @@ namespace Upsilon.Binder yield return this; } + public override IEnumerable GetChildren() + { + yield break; + } + public override Type Type => VariableSymbol.Type; } } \ No newline at end of file