BadScript 2
Loading...
Searching...
No Matches
BadArrayAccessReverseExpression.cs
Go to the documentation of this file.
7
9
15{
19 private readonly BadExpression[] m_Arguments;
20
29 BadExpression[] args,
30 BadSourcePosition position,
31 bool nullChecked = false) : base(false,
32 position
33 )
34 {
35 Left = left;
36 m_Arguments = args;
37 NullChecked = nullChecked;
38 }
39
43 public IEnumerable<BadExpression> Arguments => m_Arguments;
44
48 public int ArgumentCount => m_Arguments.Length;
49
53 public BadExpression Left { get; set; }
54
55#region IBadAccessExpression Members
56
60 public bool NullChecked { get; }
61
62#endregion
63
64
66 public override IEnumerable<BadExpression> GetDescendants()
67 {
68 foreach (BadExpression expression in Left.GetDescendantsAndSelf())
69 {
70 yield return expression;
71 }
72
73 foreach (BadExpression expression in m_Arguments)
74 {
75 foreach (BadExpression descendant in expression.GetDescendantsAndSelf())
76 {
77 yield return descendant;
78 }
79 }
80 }
81
82
84 public override void Optimize()
85 {
87
88 for (int i = 0; i < m_Arguments.Length; i++)
89 {
91 }
92 }
93
103 public static IEnumerable<BadObject> Access(BadExecutionContext context,
104 BadObject left,
105 IEnumerable<BadObject> args,
106 BadSourcePosition position)
107 {
108 //Can be null when evaluated as an optimization step
109 // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
111 {
113 .Dereference(position) is not BadFunction func)
114 {
115 throw new BadRuntimeException("Array access reverse operator is not a function", position);
116 }
117
119
120 foreach (BadObject o in func.Invoke(args.ToArray(), context!))
121 {
122 yield return o;
123
124 r = o;
125 }
126
127 yield return r;
128 }
129 else
130 {
131 throw new BadRuntimeException("Array access reverse operator is not defined", position);
132 }
133 }
134
136 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
137 {
138 BadObject left = BadObject.Null;
139
140 foreach (BadObject o in Left.Execute(context))
141 {
142 left = o;
143
144 yield return o;
145 }
146
147 left = left.Dereference(Position);
148
149 if (NullChecked && left == BadObject.Null)
150 {
151 yield return left;
152
153 yield break;
154 }
155
156 List<BadObject> args = new List<BadObject>();
157
158 foreach (BadExpression argExpr in m_Arguments)
159 {
160 BadObject argObj = BadObject.Null;
161
162 foreach (BadObject arg in argExpr.Execute(context))
163 {
164 argObj = arg;
165
166 yield return arg;
167 }
168
169 args.Add(argObj.Dereference(Position));
170 }
171
172 foreach (BadObject o in Access(context, left, args.ToArray(), Position))
173 {
174 yield return o;
175 }
176 }
177}
Describes a specific position inside a source file.
Contains Static Data for the BadScript Language.
const string ARRAY_ACCESS_REVERSE_OPERATOR_NAME
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Implements the Reverse Array Access to set or get properties from an object. LEFT[^RIGHT].
static IEnumerable< BadObject > Access(BadExecutionContext context, BadObject left, IEnumerable< BadObject > args, BadSourcePosition position)
Executes the Array Access Expression.
bool NullChecked
Indicates if the expression will be null-checked by the runtime.
IEnumerable< BadExpression > Arguments
The Arguments of the Array Access.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadArrayAccessReverseExpression(BadExpression left, BadExpression[] args, BadSourcePosition position, bool nullChecked=false)
Constructor of the Array Access Expression.
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
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.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadObject.cs:141
virtual bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Definition BadObject.cs:130
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a function that can be called from the script.
Defines the interface for BadScript Access Expressions.
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 Runtime Function Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.