BadScript 2
Loading...
Searching...
No Matches
BadTernaryExpression.cs
Go to the documentation of this file.
7
9
15{
24 BadExpression left,
25 BadExpression trueRet,
26 BadExpression falseRet,
27 BadSourcePosition position) : base(left.IsConstant, position)
28 {
29 Left = left;
30 TrueRet = trueRet;
31 FalseRet = falseRet;
32 }
33
37 public BadExpression FalseRet { get; private set; }
38
42 public BadExpression Left { get; private set; }
43
47 public BadExpression TrueRet { get; private set; }
48
49 public override IEnumerable<BadExpression> GetDescendants()
50 {
51 foreach (BadExpression expression in Left.GetDescendantsAndSelf())
52 {
53 yield return expression;
54 }
55
56 foreach (BadExpression expression in TrueRet.GetDescendantsAndSelf())
57 {
58 yield return expression;
59 }
60
61 foreach (BadExpression expression in FalseRet.GetDescendantsAndSelf())
62 {
63 yield return expression;
64 }
65 }
66
73
74 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
75 {
77
78 foreach (BadObject o in Left.Execute(context))
79 {
80 left = o;
81 }
82
83 left = left.Dereference();
84
85 if (left is not IBadBoolean lBool)
86 {
87 throw new BadRuntimeException("Ternary operator requires a boolean value on the left side.", Position);
88 }
89
90 if (lBool.Value)
91 {
92 foreach (BadObject o in TrueRet.Execute(context))
93 {
94 yield return o;
95 }
96 }
97 else
98 {
99 foreach (BadObject o in FalseRet.Execute(context))
100 {
101 yield return o;
102 }
103 }
104 }
105
106 public override string ToString()
107 {
108 return $"({Left} ? {TrueRet} : {FalseRet})";
109 }
110}
Describes a specific position inside a source file.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Implements the Ternary Expression LEFT ? TRUE_RET : FALSE_RET.
BadExpression Left
Left side that will be evaluated.
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
BadTernaryExpression(BadExpression left, BadExpression trueRet, BadExpression falseRet, BadSourcePosition position)
Constructor for the Ternary Expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadExpression FalseRet
Expression that is executed if left evaluates to false.
BadExpression TrueRet
Expression that is executed if left evaluates to true.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
bool IsConstant
Indicates if the expression stays constant at all times.
The Execution Context. Every execution of a script needs a context the script is running in....
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Contains Shared Data Structures and Functionality.
Contains the BadScript2 Constant Folding Optimizations.
Contains the Access Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.