BadScript 2
Loading...
Searching...
No Matches
BadFunctionParameter.cs
Go to the documentation of this file.
4
6
11{
20 string name,
21 bool isOptional,
22 bool isNullChecked,
23 bool isRestArgs)
24 {
25 Name = name;
26 IsOptional = isOptional;
27 IsNullChecked = isNullChecked;
28 IsRestArgs = isRestArgs;
29 TypeExpr = null;
31 }
32
43 string name,
44 bool isOptional,
45 bool isNullChecked,
46 bool isRestArgs,
47 BadExpression? typeExpr,
48 BadClassPrototype? type = null)
49 {
50 Name = name;
51 IsOptional = isOptional;
52 IsNullChecked = isNullChecked;
53 IsRestArgs = isRestArgs;
54 TypeExpr = typeExpr;
55 Type = type;
56
57 if (type == null && typeExpr == null)
58 {
60 }
61 }
62
66 public BadClassPrototype? Type { get; }
67
71 public BadExpression? TypeExpr { get; }
72
76 public string Name { get; }
77
81 public bool IsOptional { get; }
82
86 public bool IsNullChecked { get; }
87
91 public bool IsRestArgs { get; }
92
103 {
104 BadClassPrototype? type = Type;
105
106 if (TypeExpr == null)
107 {
109 }
110
112
113 foreach (BadObject o in TypeExpr.Execute(context))
114 {
115 obj = o;
116 }
117
118 obj = obj.Dereference();
119
120 if (obj is not BadClassPrototype proto)
121 {
122 throw new BadRuntimeException("Type expression must return a class prototype.");
123 }
124
125 if (proto == BadVoidPrototype.Instance)
126 {
127 throw BadRuntimeException.Create(context.Scope, $"Parameter '{Name}' Type cannot be 'void'.");
128 }
129
130 type = proto;
131
133 }
134
135
141 public static implicit operator BadFunctionParameter(string s)
142 {
143 return new BadFunctionParameter(s, false, false, false, null);
144 }
145
150 public override string ToString()
151 {
152 return Type == null
153 ? $"{Name}{(IsOptional ? "?" : "")}{(IsNullChecked ? "!" : "")}{(IsRestArgs ? "*" : "")}"
154 : $"{Type.Name} {Name}{(IsOptional ? "?" : "")}{(IsNullChecked ? "!" : "")}{(IsRestArgs ? "*" : "")}";
155 }
156}
Base Implementation for all Expressions used inside the Script.
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....
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
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
override string ToString()
Returns the string representation of the Function Parameter.
bool IsOptional
Indicates if this parameter is optional.
BadFunctionParameter(string name, bool isOptional, bool isNullChecked, bool isRestArgs)
Creates a new Function Parameter Info.
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.
BadFunctionParameter Initialize(BadExecutionContext context)
Initializes the Function Parameter.
BadFunctionParameter(string name, bool isOptional, bool isNullChecked, bool isRestArgs, BadExpression? typeExpr, BadClassPrototype? type=null)
Creates a new Function Parameter Info.
bool IsNullChecked
Indicates if this parameter is null checked by the runtime.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Class Prototype for the BadScript Language.
The Void Prototype, can be assigned to nothing, can not be inherited from, can not be instantiated....
static BadVoidPrototype Instance
The Instance of the BadVoidPrototype.
Contains the Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Function Objects.