BadScript 2
Loading...
Searching...
No Matches
BadMemberAccessExpression.cs
Go to the documentation of this file.
9
11
17{
18 public IReadOnlyList<BadExpression> GenericArguments { get; }
30 BadExpression left,
31 BadWordToken right,
32 BadSourcePosition position,
33 List<BadExpression> genericArguments,
34 bool nullChecked = false) : base(
35 false,
36 position
37 )
38 {
39 Left = left;
40 Right = right;
41 GenericArguments = genericArguments;
42 NullChecked = nullChecked;
43 }
44
48 public BadExpression Left { get; private set; }
49
53 public BadWordToken Right { get; }
54
58 public bool NullChecked { get; }
59
60 public override IEnumerable<BadExpression> GetDescendants()
61 {
63 }
64
65 public override void Optimize()
66 {
68 }
69
70 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
71 {
73
74 foreach (BadObject o in Left.Execute(context))
75 {
76 left = o;
77
78 yield return o;
79 }
80
81 left = left.Dereference();
82
83 if (NullChecked && !left.HasProperty(Right.Text, context.Scope))
84 {
85 yield return BadObject.Null;
86 }
87 else
88 {
89 BadObject ret = left.GetProperty(Right.Text, context.Scope);
90
91 if (GenericArguments.Count != 0)
92 {
93 ret = ret.Dereference();
94 if (ret is not IBadGenericObject genType)
95 {
97 context.Scope,
98 $"Object {ret} does not support generic arguments",
100 );
101 }
102 BadObject[] genParams = new BadObject[GenericArguments.Count];
103 for (int i = 0; i < GenericArguments.Count; i++)
104 {
105 foreach (BadObject? o in GenericArguments[i].Execute(context))
106 {
107 genParams[i] = o;
108 }
109
110 genParams[i] = genParams[i].Dereference();
111 }
112
113 yield return genType.CreateGeneric(genParams);
114 }
115 else{
116 yield return ret;
117 }
118 }
119 }
120
121
122 public override string ToString()
123 {
124 return $"({Left}{(NullChecked ? "?" : "")}.{Right})";
125 }
126}
Describes a specific position inside a source file.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Implements the Member Access to set or get properties from an object. LEFT.RIGHT.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
bool NullChecked
Property that indicates if the result of the left side of the expression should be null-checked.
BadMemberAccessExpression(BadExpression left, BadWordToken right, BadSourcePosition position, List< BadExpression > genericArguments, bool nullChecked=false)
Constructor for the Member Access 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.
string Text
The Text Representation of the Token.
Definition BadToken.cs:27
The Execution Context. Every execution of a script needs a context the script is running in....
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
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
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
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 Reader Tokens for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Interface Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.