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 left,
30 BadExpression[] args,
31 BadSourcePosition position,
32 bool nullChecked = false) : base(
33 false,
34 position
35 )
36 {
37 Left = left;
38 m_Arguments = args;
39 NullChecked = nullChecked;
40 }
41
45 public IEnumerable<BadExpression> Arguments => m_Arguments;
46
50 public int ArgumentCount => m_Arguments.Length;
51
55 public BadExpression Left { get; set; }
56
60 public bool NullChecked { get; }
61
62
64 public override IEnumerable<BadExpression> GetDescendants()
65 {
66 foreach (BadExpression expression in Left.GetDescendantsAndSelf())
67 {
68 yield return expression;
69 }
70
71 foreach (BadExpression expression in m_Arguments)
72 {
73 foreach (BadExpression descendant in expression.GetDescendantsAndSelf())
74 {
75 yield return descendant;
76 }
77 }
78 }
79
80
82 public override void Optimize()
83 {
85
86 for (int i = 0; i < m_Arguments.Length; i++)
87 {
89 }
90 }
91
101 public static IEnumerable<BadObject> Access(
102 BadExecutionContext context,
103 BadObject left,
104 IEnumerable<BadObject> args,
105 BadSourcePosition position)
106 {
107 //Can be null when evaluated as an optimization step
108 // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
110 {
112 .Dereference() is not BadFunction func)
113 {
114 throw new BadRuntimeException("Array access reverse operator is not a function", position);
115 }
116
118
119 foreach (BadObject o in func.Invoke(args.ToArray(), context!))
120 {
121 yield return o;
122
123 r = o;
124 }
125
126 yield return r;
127 }
128 else
129 {
130 throw new BadRuntimeException("Array access reverse operator is not defined", position);
131 }
132 }
133
135 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
136 {
137 BadObject left = BadObject.Null;
138
139 foreach (BadObject o in Left.Execute(context))
140 {
141 left = o;
142
143 yield return o;
144 }
145
146 left = left.Dereference();
147
148 if (NullChecked && left == BadObject.Null)
149 {
150 yield return left;
151
152 yield break;
153 }
154
155 List<BadObject> args = new List<BadObject>();
156
157 foreach (BadExpression argExpr in m_Arguments)
158 {
159 BadObject argObj = BadObject.Null;
160
161 foreach (BadObject arg in argExpr.Execute(context))
162 {
163 argObj = arg;
164
165 yield return arg;
166 }
167
168 args.Add(argObj.Dereference());
169 }
170
171 foreach (BadObject o in Access(context, left, args.ToArray(), Position))
172 {
173 yield return o;
174 }
175 }
176}
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:129
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:118
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.