88
99namespace Kaleidoscope . Grammar . AST
1010{
11+ /// <summary>AST node for a conditional expression</summary>
12+ /// <remarks>
13+ /// A conditional expression is the language equivalent of a conditional operator in most "C" like languages (ternary operator).
14+ /// </remarks>
1115 public sealed class ConditionalExpression
1216 : AstNode
1317 , IExpression
1418 {
19+ /// <summary>Initializes a new instance of the <see cref="ConditionalExpression"/> class.</summary>
20+ /// <param name="location">Location of the expression in the source input</param>
21+ /// <param name="condition">Expression for the condition</param>
22+ /// <param name="thenExpression">Expression for the `then` clause of the conditional expression</param>
23+ /// <param name="elseExpression">Expression for the `else` clause of the conditional expression</param>
24+ /// <param name="resultVar"><see cref="LocalVariableDeclaration"/> to represent the results of the expression</param>
1525 public ConditionalExpression ( SourceRange location
1626 , IExpression condition
1727 , IExpression thenExpression
@@ -26,19 +36,26 @@ public ConditionalExpression( SourceRange location
2636 ResultVariable = resultVar ;
2737 }
2838
39+ /// <summary>Gets the expression for the condition</summary>
2940 public IExpression Condition { get ; }
3041
42+ /// <summary>Gets the expression for the `then` clause</summary>
3143 public IExpression ThenExpression { get ; }
3244
45+ /// <summary>Gets the expression for the `else` clause</summary>
3346 public IExpression ElseExpression { get ; }
3447
35- // Compiler generated result variable supports building conditional
36- // expressions without the need for SSA form in the AST/Code generation
37- // by using mutable variables. The result is assigned a value from both
38- // sides of the branch. In pure SSA form this isn't needed as a PHI node
39- // would be used instead.
48+ /// <summary>Gets the result of the expression as a <see cref="LocalVariableDeclaration"/></summary>
49+ /// <remarks>
50+ /// Compiler generated result variable supports building conditional
51+ /// expressions without the need for SSA form in the AST/Code generation
52+ /// by using mutable variables. The result is assigned a value from both
53+ /// sides of the branch. In pure SSA form this isn't needed as a PHI node
54+ /// would be used instead.
55+ /// </remarks>
4056 public LocalVariableDeclaration ResultVariable { get ; }
4157
58+ /// <inheritdoc cref="BinaryOperatorExpression.Accept{TResult}(IAstVisitor{TResult})"/>
4259 public override TResult ? Accept < TResult > ( IAstVisitor < TResult > visitor )
4360 where TResult : default
4461 {
@@ -47,6 +64,7 @@ public ConditionalExpression( SourceRange location
4764 : visitor . Visit ( this ) ;
4865 }
4966
67+ /// <inheritdoc cref="BinaryOperatorExpression.Accept{TResult, TArg}(IAstVisitor{TResult, TArg}, ref readonly TArg)"/>
5068 public override TResult ? Accept < TResult , TArg > ( IAstVisitor < TResult , TArg > visitor , ref readonly TArg arg )
5169 where TResult : default
5270 {
@@ -55,6 +73,7 @@ public ConditionalExpression( SourceRange location
5573 : visitor . Visit ( this , in arg ) ;
5674 }
5775
76+ /// <inheritdoc/>
5877 public override IEnumerable < IAstNode > Children
5978 {
6079 get
@@ -65,6 +84,7 @@ public override IEnumerable<IAstNode> Children
6584 }
6685 }
6786
87+ /// <inheritdoc/>
6888 public override string ToString ( )
6989 {
7090 return $ "Conditional({ Condition } , { ThenExpression } , { ElseExpression } )";
0 commit comments