BadScript 2
Loading...
Searching...
No Matches
BadFunctionParameter.cs
Go to the documentation of this file.
4
6
11{
19 public BadFunctionParameter(string name,
20 bool isOptional,
21 bool isNullChecked,
22 bool isRestArgs)
23 {
24 Name = name;
25 IsOptional = isOptional;
26 IsNullChecked = isNullChecked;
27 IsRestArgs = isRestArgs;
28 TypeExpr = null;
30 }
31
41 public BadFunctionParameter(string name,
42 bool isOptional,
43 bool isNullChecked,
44 bool isRestArgs,
45 BadExpression? typeExpr,
46 BadClassPrototype? type = null)
47 {
48 Name = name;
49 IsOptional = isOptional;
50 IsNullChecked = isNullChecked;
51 IsRestArgs = isRestArgs;
52 TypeExpr = typeExpr;
53 Type = type;
54
55 if (type == null && typeExpr == null)
56 {
58 }
59 }
60
64 public BadClassPrototype? Type { get; }
65
69 public BadExpression? TypeExpr { get; }
70
74 public string Name { get; }
75
79 public bool IsOptional { get; }
80
84 public bool IsNullChecked { get; }
85
89 public bool IsRestArgs { get; }
90
101 {
102 BadClassPrototype? type = Type;
103
104 if (TypeExpr == null)
105 {
107 }
108
110
111 foreach (BadObject o in TypeExpr.Execute(context))
112 {
113 obj = o;
114 }
115
116 obj = obj.Dereference(TypeExpr.Position);
117
118 if (obj is not BadClassPrototype proto)
119 {
120 throw new BadRuntimeException("Type expression must return a class prototype.");
121 }
122
123 if (proto == BadVoidPrototype.Instance)
124 {
125 throw BadRuntimeException.Create(context.Scope, $"Parameter '{Name}' Type cannot be 'void'.");
126 }
127
128 type = proto;
129
131 }
132
133
139 public static implicit operator BadFunctionParameter(string s)
140 {
141 return new BadFunctionParameter(s, false, false, false, null);
142 }
143
148 public override string ToString()
149 {
150 return Type == null
151 ? $"{Name}{(IsOptional ? "?" : "")}{(IsNullChecked ? "!" : "")}{(IsRestArgs ? "*" : "")}"
152 : $"{Type.Name} {Name}{(IsOptional ? "?" : "")}{(IsNullChecked ? "!" : "")}{(IsRestArgs ? "*" : "")}";
153 }
154}
Base Implementation for all Expressions used inside the Script.
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....
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.