1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
|
#pragma once
#include "Expr.h"
#include "Var.h"
#include "Actuals.h"
#include "Compiler/Function.h"
#include "Compiler/NamedThread.h"
#include "Variable.h"
namespace storm {
namespace bs {
STORM_PKG(lang.bs);
class UnresolvedName;
/**
* Execute a function.
*/
class FnCall : public Expr {
STORM_CLASS;
friend class AsyncFnCall;
public:
// if '!lookup', then the lookup functionality (such as vtables) will not be used.
STORM_CTOR FnCall(SrcPos pos, Scope scope, Function *toExecute, Actuals *params);
STORM_CTOR FnCall(SrcPos pos, Scope scope, Function *toExecute, Actuals *params, Bool lookup);
STORM_CTOR FnCall(SrcPos pos, Scope scope, Function *toExecute, Actuals *params, Bool lookup, Bool firstImplicit);
// Create a UnresolvedName object describing how to find this function.
UnresolvedName *STORM_FN name();
// Get the function we are going to call.
inline Function *STORM_FN function() const { return toExecute; }
// Result type.
virtual ExprResult STORM_FN result();
// Get parameters.
inline Actuals *STORM_FN parameters() const { return params; }
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Location.
virtual SrcPos STORM_FN largePos();
// Was the first parameter implicit?
Bool STORM_FN implicitMember() const { return firstImplicit; }
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
public:
// Function to run.
Function *toExecute;
// Parameters.
Actuals *params;
// Scope this function is called within.
Scope scope;
// Use lookup?
Bool lookup;
// Was the first parameter implicit? Used to determine when to replace in weak casts.
Bool firstImplicit;
};
/**
* Explicitly async function call.
*/
class AsyncFnCall : public FnCall {
STORM_CLASS;
public:
// Create from a FnCall. Make it async without specifying a thread explicitly.
STORM_CTOR AsyncFnCall(FnCall *original);
// Create from a FnCall, the thread was specified explicitly.
STORM_CTOR AsyncFnCall(FnCall *original, Expr *thread);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
private:
// The thread specified, if any.
Expr *thread;
};
/**
* Execute a constructor.
*/
class CtorCall : public Expr {
STORM_CLASS;
public:
// Call a constructor.
STORM_CTOR CtorCall(SrcPos pos, Scope scope, Function *ctor, Actuals *params);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Location.
virtual SrcPos STORM_FN largePos();
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
private:
// Type to create.
Value toCreate;
// Constructor to run.
Function *ctor;
// Parameters.
Actuals *params;
// Scope we're being executed in.
Scope scope;
// Create a value.
void createValue(CodeGen *s, CodeResult *to);
// Create a class.
void createClass(CodeGen *s, CodeResult *to);
};
// Call the default constructor for T.
CtorCall *STORM_FN defaultCtor(const SrcPos &pos, Scope scope, Type *t);
// Call the copy-constructor for T.
CtorCall *STORM_FN copyCtor(const SrcPos &pos, Scope scope, Type *t, Expr *src);
/**
* Get a local variable.
*/
class LocalVarAccess : public Expr {
STORM_CLASS;
public:
STORM_CTOR LocalVarAccess(SrcPos pos, LocalVar *var);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Variable to access.
LocalVar *var;
// Is this a known "this"-variable?
Bool STORM_FN thisVariable() const {
return var->thisVariable();
}
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Get a local variable (bare-bones wrapper for interfacing with other languages).
*/
class BareVarAccess : public Expr {
STORM_CLASS;
public:
STORM_CTOR BareVarAccess(SrcPos pos, Value type, code::Var var);
// Result.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Type and variable.
Value type;
code::Var var;
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Read a type variable.
*/
class MemberVarAccess : public Expr {
STORM_CLASS;
public:
// Standard creation if you don't need to take the case where "member" might not have
// been specified by the user into account (e.g. when you generate code internally).
STORM_CTOR MemberVarAccess(SrcPos pos, Expr *member, MemberVar *var);
// If "implicitMember" is true, then the expression "member" was implicitly
// generated. This mostly affects the decision of whether or not this is a "plain"
// variable in weak casts.
STORM_CTOR MemberVarAccess(SrcPos pos, Expr *member, MemberVar *var, Bool implicitMember);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Notify that we will try to assign to this variable. This will not affect the
// correctness of this note, but failing to call 'assignTarget' when other code will
// attempt to modify the returned reference will result in no error message to the user.
void STORM_FN assignResult();
// Variable to access.
MemberVar *var;
// Location.
virtual SrcPos STORM_FN largePos();
// Is 'member' the implicit 'this' pointer?
Bool implicitMember() const { return implicit; }
// Output.
virtual void STORM_FN toS(StrBuf *to) const;
private:
// Member in which the variable is.
Expr *member;
// Will we be part of an assignment? This is only used to generate better error
// messages. Nothing else.
Bool assignTo;
// Did "member" get specified implicitly?
Bool implicit;
// Generate code for a value access.
void valueCode(CodeGen *s, CodeResult *to);
// Generate code for a class access.
void classCode(CodeGen *s, CodeResult *to);
// Extract the value itself from 'ptrA'
void extractCode(CodeGen *s, CodeResult *to);
// Extract the value, assuming we don't need a deep copy.
void extractPlainCode(CodeGen *s, CodeResult *to);
// Extract the value, assuming we need a deep copy.
void extractCopyCode(CodeGen *s, CodeResult *to);
};
/**
* Read a global variable.
*/
class GlobalVarAccess : public Expr {
STORM_CLASS;
public:
STORM_CTOR GlobalVarAccess(SrcPos pos, GlobalVar *var);
// Member to access.
GlobalVar *var;
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Read a named thread variable.
*/
class NamedThreadAccess : public Expr {
STORM_CLASS;
public:
// Create.
STORM_CTOR NamedThreadAccess(SrcPos pos, NamedThread *thread);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Output.
virtual void STORM_FN toS(StrBuf *to) const;
private:
// Which thread?
NamedThread *thread;
};
/**
* Default assignment operator.
*/
class ClassAssign : public Expr {
STORM_CLASS;
public:
STORM_CTOR ClassAssign(Expr *to, Expr *value, Scope scope);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Output.
virtual void STORM_FN toS(StrBuf *to) const;
private:
Expr *to;
Expr *value;
};
/**
* Default compare for classes.
*/
class ClassCompare : public Expr {
STORM_CLASS;
public:
// Create. Optionally negate the result (for !=).
STORM_CTOR ClassCompare(SrcPos pos, Expr *lhs, Expr *rhs, Bool negate);
// Result type.
virtual ExprResult STORM_FN result();
// Generate code.
virtual void STORM_FN code(CodeGen *s, CodeResult *to);
// Output.
virtual void STORM_FN toS(StrBuf *to) const;
private:
Expr *lhs;
Expr *rhs;
Bool negate;
};
// Make a regular function call return a future to the result instead of waiting for the result
// directly. Syntactically, this is made by adding 'spawn' to it.
Expr *STORM_FN spawnExpr(Expr *expr);
// Make a regular function call return a future to the result instead of waiting for the
// result directly. Additionally, attempt to execute it on the specified thread.
Expr *STORM_FN spawnOnExpr(Expr *thread, Expr *expr);
}
}
|