BadScript 2
Loading...
Searching...
No Matches
BadInterfaceFunctionConstraint.cs
Go to the documentation of this file.
7
9
15{
19 private readonly BadClassPrototype? m_Prototype;
20
24 public readonly string Name;
25
30
34 public readonly BadExpression? Return;
35
42 public BadInterfaceFunctionConstraint(string name, BadExpression? @return, BadFunctionParameter[] parameters)
43 {
44 Name = name;
45 Return = @return;
46 Parameters = parameters;
47 }
48
49
58 BadExpression? @return,
59 BadClassPrototype returnProto,
60 BadFunctionParameter[] parameters)
61 {
62 Name = name;
63 Return = @return;
64 Parameters = parameters;
65 m_Prototype = returnProto;
66 }
67
68
70 public override string ToString()
71 {
72 return "FunctionConstraint";
73 }
74
76 public override void Validate(BadClass obj, List<BadInterfaceValidatorError> errors)
77 {
78 if (Return != null && m_Prototype == null)
79 {
80 throw new BadRuntimeException("Return Type was not Evaluated.");
81 }
82
83 if (!obj.HasProperty(Name, obj.Scope))
84 {
85 errors.Add(new BadInterfaceValidatorError($"Missing Property. Expected {Name}", this));
86
87 return;
88 }
89
91 .Dereference(null);
92
93 if (o is not BadFunction f)
94 {
95 errors.Add(new BadInterfaceValidatorError($"Property {Name} is not a function", this));
96
97 return;
98 }
99
100 if (m_Prototype != null && !m_Prototype.IsSuperClassOf(f.ReturnType))
101 {
102 errors.Add(new
103 BadInterfaceValidatorError($"Return Type Mismatch. Expected {m_Prototype} but got {f.ReturnType} in {f}",
104 this
105 )
106 );
107 }
108
109 if (f.Parameters.Length != Parameters.Length)
110 {
111 errors.Add(new
112 BadInterfaceValidatorError($"Parameter Count Mismatch. Expected {Parameters.Length} but got {f.Parameters.Length} in {f}",
113 this
114 )
115 );
116
117 return;
118 }
119
120 for (int i = 0; i < Parameters.Length; i++)
121 {
122 BadFunctionParameter actual = f.Parameters[i];
123 BadFunctionParameter expected = Parameters[i];
124
125 if (actual.IsOptional != expected.IsOptional)
126 {
127 errors.Add(new
128 BadInterfaceValidatorError($"{f}: Parameter Optional Flags are not equal. Implementation: {actual}, Expectation: {expected}",
129 this
130 )
131 );
132
133 return;
134 }
135
136 if (actual.IsNullChecked != expected.IsNullChecked)
137 {
138 errors.Add(new
139 BadInterfaceValidatorError($"{f}: Parameter Null Check Flags are not equal. Implementation: {actual}, Expectation: {expected}",
140 this
141 )
142 );
143
144 return;
145 }
146
147 if (actual.IsRestArgs != expected.IsRestArgs)
148 {
149 errors.Add(new
150 BadInterfaceValidatorError($"{f}: Parameter Rest Args Flags are not equal. Implementation: {actual}, Expectation: {expected}",
151 this
152 )
153 );
154
155 return;
156 }
157
158 if (actual.TypeExpr == null)
159 {
160 continue;
161 }
162
163 if (expected.Type == null || actual.Type == expected.Type)
164 {
165 continue;
166 }
167
168 errors.Add(new
169 BadInterfaceValidatorError($"{f}: Parameter Types not equal. Implementation: {actual}, Expectation: {expected}",
170 this
171 )
172 );
173
174 return;
175 }
176 }
177
178 public override bool Equals(BadInterfaceConstraint? other)
179 {
180 return other is BadInterfaceFunctionConstraint c &&
181 c.Name == Name &&
182 c.Return == Return &&
183 c.Parameters.Length == Parameters.Length &&
184 c.Parameters.Zip(Parameters, (x, y) => (x, y))
185 .All(z => z.x.Equals(z.y));
186 }
187
188 protected override int GetConstraintHash()
189 {
191 }
192}
Base Implementation for all Expressions used inside the Script.
Implements a Function Constraint for an Interface The Constraints specifies how a specific function s...
BadInterfaceFunctionConstraint(string name, BadExpression? @return, BadFunctionParameter[] parameters)
Creates a new Function Constraint.
BadInterfaceFunctionConstraint(string name, BadExpression? @return, BadClassPrototype returnProto, BadFunctionParameter[] parameters)
Creates a new Function Constraint.
readonly BadFunctionParameter[] Parameters
The Parameters of the Function.
readonly? BadClassPrototype m_Prototype
The Return Type Prototype.
override void Validate(BadClass obj, List< BadInterfaceValidatorError > errors)
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements a function that can be called from the script.
bool IsOptional
Indicates if this parameter is optional.
BadExpression? TypeExpr
The Expression that returns the type of the parameter if evaluated.
BadClassPrototype? Type
The Class Prototype of the Parameter.
bool IsRestArgs
Indicates if this parameter is the rest parameter of the function.
bool IsNullChecked
Indicates if this parameter is null checked by the runtime.
Implements a Type Instance in the BadScript Language.
Definition BadClass.cs:11
BadObjectReference GetProperty(string propName, BadPropertyVisibility visibility, BadScope? caller=null)
Gets a property from this class or any of its base classes.
Definition BadClass.cs:120
BadScope Scope
Table of all members of this type(excluding base class members)
Definition BadClass.cs:35
override 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 BadClass.cs:95
Implements a Class Prototype for the BadScript Language.
virtual bool IsSuperClassOf(BadClassPrototype proto)
Returns true if the Class is a Subclass of the given Class.
Implements Combination of HashCode Functions Taken from decompiled source of System....
Contains the Type Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Function Objects.
Contains Runtime Interface Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains Utility Functions and Classes.
Definition BadEnum.cs:5