| 1 |
/** |
| 2 |
* Defines AST nodes for statements. |
| 3 |
* |
| 4 |
* Specification: $(LINK2 https://dlang.org/spec/statement.html, Statements) |
| 5 |
* |
| 6 |
* Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 7 |
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright) |
| 8 |
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) |
| 9 |
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/statement.d, _statement.d) |
| 10 |
* Documentation: https://dlang.org/phobos/dmd_statement.html |
| 11 |
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/statement.d |
| 12 |
*/ |
| 13 |
|
| 14 |
module dmd.statement; |
| 15 |
|
| 16 |
import core.stdc.stdarg; |
| 17 |
import core.stdc.stdio; |
| 18 |
|
| 19 |
import dmd.arraytypes; |
| 20 |
import dmd.astenums; |
| 21 |
import dmd.ast_node; |
| 22 |
import dmd.cond; |
| 23 |
import dmd.declaration; |
| 24 |
import dmd.dsymbol; |
| 25 |
import dmd.expression; |
| 26 |
import dmd.func; |
| 27 |
import dmd.id; |
| 28 |
import dmd.identifier; |
| 29 |
import dmd.location; |
| 30 |
import dmd.mtype; |
| 31 |
import dmd.rootobject; |
| 32 |
import dmd.staticassert; |
| 33 |
import dmd.tokens; |
| 34 |
import dmd.visitor; |
| 35 |
import dmd.visitor.postorder; |
| 36 |
|
| 37 |
/*********************************************************** |
| 38 |
* Specification: https://dlang.org/spec/statement.html |
| 39 |
*/ |
| 40 |
extern (C++) abstract class Statement : ASTNode |
| 41 |
{ |
| 42 |
const Loc loc; |
| 43 |
const STMT stmt; |
| 44 |
|
| 45 |
override final DYNCAST dyncast() const |
| 46 |
{ |
| 47 |
return DYNCAST.statement; |
| 48 |
} |
| 49 |
|
| 50 |
final extern (D) this(Loc loc, STMT stmt) @safe |
| 51 |
{ |
| 52 |
this.loc = loc; |
| 53 |
this.stmt = stmt; |
| 54 |
// If this is an in{} contract scope statement (skip for determining |
| 55 |
// inlineStatus of a function body for header content) |
| 56 |
} |
| 57 |
|
| 58 |
Statement syntaxCopy() |
| 59 |
{ |
| 60 |
assert(0); |
| 61 |
} |
| 62 |
|
| 63 |
/************************************* |
| 64 |
* Do syntax copy of an array of Statement's. |
| 65 |
*/ |
| 66 |
static Statements* arraySyntaxCopy(Statements* a) |
| 67 |
{ |
| 68 |
Statements* b = null; |
| 69 |
if (a) |
| 70 |
{ |
| 71 |
b = a.copy(); |
| 72 |
foreach (i, s; *a) |
| 73 |
{ |
| 74 |
(*b)[i] = s ? s.syntaxCopy() : null; |
| 75 |
} |
| 76 |
} |
| 77 |
return b; |
| 78 |
} |
| 79 |
|
| 80 |
Statement getRelatedLabeled() |
| 81 |
{ |
| 82 |
return this; |
| 83 |
} |
| 84 |
|
| 85 |
/**************************** |
| 86 |
* Determine if an enclosed `break` would apply to this |
| 87 |
* statement, such as if it is a loop or switch statement. |
| 88 |
* Returns: |
| 89 |
* `true` if it does |
| 90 |
*/ |
| 91 |
bool hasBreak() const pure nothrow |
| 92 |
{ |
| 93 |
//printf("Statement::hasBreak()\n"); |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
/**************************** |
| 98 |
* Determine if an enclosed `continue` would apply to this |
| 99 |
* statement, such as if it is a loop statement. |
| 100 |
* Returns: |
| 101 |
* `true` if it does |
| 102 |
*/ |
| 103 |
bool hasContinue() const pure nothrow |
| 104 |
{ |
| 105 |
return false; |
| 106 |
} |
| 107 |
|
| 108 |
/********************************** |
| 109 |
* Returns: |
| 110 |
* `true` if statement uses exception handling |
| 111 |
*/ |
| 112 |
extern (D) final bool usesEH() |
| 113 |
{ |
| 114 |
extern (C++) final class UsesEH : StoppableVisitor |
| 115 |
{ |
| 116 |
alias visit = typeof(super).visit; |
| 117 |
public: |
| 118 |
override void visit(Statement s) |
| 119 |
{ |
| 120 |
} |
| 121 |
|
| 122 |
override void visit(TryCatchStatement s) |
| 123 |
{ |
| 124 |
stop = true; |
| 125 |
} |
| 126 |
|
| 127 |
override void visit(TryFinallyStatement s) |
| 128 |
{ |
| 129 |
stop = true; |
| 130 |
} |
| 131 |
|
| 132 |
override void visit(ScopeGuardStatement s) |
| 133 |
{ |
| 134 |
stop = true; |
| 135 |
} |
| 136 |
|
| 137 |
override void visit(SynchronizedStatement s) |
| 138 |
{ |
| 139 |
stop = true; |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
scope UsesEH ueh = new UsesEH(); |
| 144 |
return walkPostorder(this, ueh); |
| 145 |
} |
| 146 |
|
| 147 |
/********************************** |
| 148 |
* Returns: |
| 149 |
* `true` if statement 'comes from' somewhere else, like a goto |
| 150 |
*/ |
| 151 |
extern (D) final bool comeFrom() |
| 152 |
{ |
| 153 |
extern (C++) final class ComeFrom : StoppableVisitor |
| 154 |
{ |
| 155 |
alias visit = typeof(super).visit; |
| 156 |
public: |
| 157 |
override void visit(Statement s) |
| 158 |
{ |
| 159 |
} |
| 160 |
|
| 161 |
override void visit(CaseStatement s) |
| 162 |
{ |
| 163 |
stop = true; |
| 164 |
} |
| 165 |
|
| 166 |
override void visit(DefaultStatement s) |
| 167 |
{ |
| 168 |
stop = true; |
| 169 |
} |
| 170 |
|
| 171 |
override void visit(LabelStatement s) |
| 172 |
{ |
| 173 |
stop = true; |
| 174 |
} |
| 175 |
|
| 176 |
override void visit(AsmStatement s) |
| 177 |
{ |
| 178 |
stop = true; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
scope ComeFrom cf = new ComeFrom(); |
| 183 |
return walkPostorder(this, cf); |
| 184 |
} |
| 185 |
|
| 186 |
/********************************** |
| 187 |
* Returns: |
| 188 |
* `true` if statement has executable code. |
| 189 |
*/ |
| 190 |
extern (D) final bool hasCode() |
| 191 |
{ |
| 192 |
extern (C++) final class HasCode : StoppableVisitor |
| 193 |
{ |
| 194 |
alias visit = typeof(super).visit; |
| 195 |
public: |
| 196 |
override void visit(Statement s) |
| 197 |
{ |
| 198 |
stop = true; |
| 199 |
} |
| 200 |
|
| 201 |
override void visit(ExpStatement s) |
| 202 |
{ |
| 203 |
if (s.exp !is null) |
| 204 |
{ |
| 205 |
stop = s.exp.hasCode(); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
override void visit(CompoundStatement s) |
| 210 |
{ |
| 211 |
} |
| 212 |
|
| 213 |
override void visit(ScopeStatement s) |
| 214 |
{ |
| 215 |
} |
| 216 |
|
| 217 |
override void visit(ImportStatement s) |
| 218 |
{ |
| 219 |
} |
| 220 |
|
| 221 |
override void visit(CaseStatement s) |
| 222 |
{ |
| 223 |
} |
| 224 |
|
| 225 |
override void visit(DefaultStatement s) |
| 226 |
{ |
| 227 |
} |
| 228 |
|
| 229 |
override void visit(LabelStatement s) |
| 230 |
{ |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
scope HasCode hc = new HasCode(); |
| 235 |
return walkPostorder(this, hc); |
| 236 |
} |
| 237 |
|
| 238 |
/******************************* |
| 239 |
* Find last statement in a sequence of statements. |
| 240 |
* Returns: |
| 241 |
* the last statement, or `null` if there isn't one |
| 242 |
*/ |
| 243 |
inout(Statement) last() inout nothrow pure |
| 244 |
{ |
| 245 |
return this; |
| 246 |
} |
| 247 |
|
| 248 |
/************************** |
| 249 |
* Support Visitor Pattern |
| 250 |
* Params: |
| 251 |
* v = visitor |
| 252 |
*/ |
| 253 |
override void accept(Visitor v) |
| 254 |
{ |
| 255 |
v.visit(this); |
| 256 |
} |
| 257 |
|
| 258 |
/************************************ |
| 259 |
* Does this statement end with a return statement? |
| 260 |
* |
| 261 |
* I.e. is it a single return statement or some compound statement |
| 262 |
* that unconditionally hits a return statement. |
| 263 |
* Returns: |
| 264 |
* return statement it ends with, otherwise null |
| 265 |
*/ |
| 266 |
pure nothrow @nogc |
| 267 |
inout(ReturnStatement) endsWithReturnStatement() inout { return null; } |
| 268 |
|
| 269 |
final pure inout nothrow @nogc @trusted |
| 270 |
{ |
| 271 |
/******************** |
| 272 |
* A cheaper method of doing downcasting of Statements. |
| 273 |
* Returns: |
| 274 |
* the downcast statement if it can be downcasted, otherwise `null` |
| 275 |
*/ |
| 276 |
inout(ErrorStatement) isErrorStatement() { return stmt == STMT.Error ? cast(typeof(return))this : null; } |
| 277 |
inout(PeelStatement) isPeelStatement() { return stmt == STMT.Peel ? cast(typeof(return))this : null; } |
| 278 |
inout(ScopeStatement) isScopeStatement() { return stmt == STMT.Scope ? cast(typeof(return))this : null; } |
| 279 |
inout(ExpStatement) isExpStatement() { return stmt == STMT.Exp ? cast(typeof(return))this : null; } |
| 280 |
inout(CompoundStatement) isCompoundStatement() { return stmt == STMT.Compound ? cast(typeof(return))this : null; } |
| 281 |
inout(ReturnStatement) isReturnStatement() { return stmt == STMT.Return ? cast(typeof(return))this : null; } |
| 282 |
inout(IfStatement) isIfStatement() { return stmt == STMT.If ? cast(typeof(return))this : null; } |
| 283 |
inout(ConditionalStatement) isConditionalStatement() { return stmt == STMT.Conditional ? cast(typeof(return))this : null; } |
| 284 |
inout(StaticForeachStatement) isStaticForeachStatement() { return stmt == STMT.StaticForeach ? cast(typeof(return))this : null; } |
| 285 |
inout(CaseStatement) isCaseStatement() { return stmt == STMT.Case ? cast(typeof(return))this : null; } |
| 286 |
inout(DefaultStatement) isDefaultStatement() { return stmt == STMT.Default ? cast(typeof(return))this : null; } |
| 287 |
inout(LabelStatement) isLabelStatement() { return stmt == STMT.Label ? cast(typeof(return))this : null; } |
| 288 |
inout(GotoStatement) isGotoStatement() { return stmt == STMT.Goto ? cast(typeof(return))this : null; } |
| 289 |
inout(GotoDefaultStatement) isGotoDefaultStatement() { return stmt == STMT.GotoDefault ? cast(typeof(return))this : null; } |
| 290 |
inout(GotoCaseStatement) isGotoCaseStatement() { return stmt == STMT.GotoCase ? cast(typeof(return))this : null; } |
| 291 |
inout(BreakStatement) isBreakStatement() { return stmt == STMT.Break ? cast(typeof(return))this : null; } |
| 292 |
inout(DtorExpStatement) isDtorExpStatement() { return stmt == STMT.DtorExp ? cast(typeof(return))this : null; } |
| 293 |
inout(MixinStatement) isMixinStatement() { return stmt == STMT.Mixin ? cast(typeof(return))this : null; } |
| 294 |
inout(ForwardingStatement) isForwardingStatement() { return stmt == STMT.Forwarding ? cast(typeof(return))this : null; } |
| 295 |
inout(DoStatement) isDoStatement() { return stmt == STMT.Do ? cast(typeof(return))this : null; } |
| 296 |
inout(WhileStatement) isWhileStatement() { return stmt == STMT.While ? cast(typeof(return))this : null; } |
| 297 |
inout(ForStatement) isForStatement() { return stmt == STMT.For ? cast(typeof(return))this : null; } |
| 298 |
inout(ForeachStatement) isForeachStatement() { return stmt == STMT.Foreach ? cast(typeof(return))this : null; } |
| 299 |
inout(SwitchStatement) isSwitchStatement() { return stmt == STMT.Switch ? cast(typeof(return))this : null; } |
| 300 |
inout(ContinueStatement) isContinueStatement() { return stmt == STMT.Continue ? cast(typeof(return))this : null; } |
| 301 |
inout(WithStatement) isWithStatement() { return stmt == STMT.With ? cast(typeof(return))this : null; } |
| 302 |
inout(TryCatchStatement) isTryCatchStatement() { return stmt == STMT.TryCatch ? cast(typeof(return))this : null; } |
| 303 |
inout(ThrowStatement) isThrowStatement() { return stmt == STMT.Throw ? cast(typeof(return))this : null; } |
| 304 |
inout(DebugStatement) isDebugStatement() { return stmt == STMT.Debug ? cast(typeof(return))this : null; } |
| 305 |
inout(TryFinallyStatement) isTryFinallyStatement() { return stmt == STMT.TryFinally ? cast(typeof(return))this : null; } |
| 306 |
inout(ScopeGuardStatement) isScopeGuardStatement() { return stmt == STMT.ScopeGuard ? cast(typeof(return))this : null; } |
| 307 |
inout(SwitchErrorStatement) isSwitchErrorStatement() { return stmt == STMT.SwitchError ? cast(typeof(return))this : null; } |
| 308 |
inout(UnrolledLoopStatement) isUnrolledLoopStatement() { return stmt == STMT.UnrolledLoop ? cast(typeof(return))this : null; } |
| 309 |
inout(ForeachRangeStatement) isForeachRangeStatement() { return stmt == STMT.ForeachRange ? cast(typeof(return))this : null; } |
| 310 |
inout(CompoundDeclarationStatement) isCompoundDeclarationStatement() { return stmt == STMT.CompoundDeclaration ? cast(typeof(return))this : null; } |
| 311 |
inout(CompoundAsmStatement) isCompoundAsmStatement() { return stmt == STMT.CompoundAsm ? cast(typeof(return))this : null; } |
| 312 |
inout(PragmaStatement) isPragmaStatement() { return stmt == STMT.Pragma ? cast(typeof(return))this : null; } |
| 313 |
inout(StaticAssertStatement) isStaticAssertStatement() { return stmt == STMT.StaticAssert ? cast(typeof(return))this : null; } |
| 314 |
inout(CaseRangeStatement) isCaseRangeStatement() { return stmt == STMT.CaseRange ? cast(typeof(return))this : null; } |
| 315 |
inout(SynchronizedStatement) isSynchronizedStatement() { return stmt == STMT.Synchronized ? cast(typeof(return))this : null; } |
| 316 |
inout(AsmStatement) isAsmStatement() { return stmt == STMT.Asm ? cast(typeof(return))this : null; } |
| 317 |
inout(InlineAsmStatement) isInlineAsmStatement() { return stmt == STMT.InlineAsm ? cast(typeof(return))this : null; } |
| 318 |
inout(GccAsmStatement) isGccAsmStatement() { return stmt == STMT.GccAsm ? cast(typeof(return))this : null; } |
| 319 |
inout(ImportStatement) isImportStatement() { return stmt == STMT.Import ? cast(typeof(return))this : null; } |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
/*********************************************************** |
| 324 |
* Any Statement that fails semantic() or has a component that is an ErrorExp or |
| 325 |
* a TypeError should return an ErrorStatement from semantic(). |
| 326 |
*/ |
| 327 |
extern (C++) final class ErrorStatement : Statement |
| 328 |
{ |
| 329 |
extern (D) this() |
| 330 |
{ |
| 331 |
super(Loc.initial, STMT.Error); |
| 332 |
|
| 333 |
import dmd.globals; |
| 334 |
assert(global.gaggedErrors || global.errors); |
| 335 |
} |
| 336 |
|
| 337 |
override ErrorStatement syntaxCopy() |
| 338 |
{ |
| 339 |
return this; |
| 340 |
} |
| 341 |
|
| 342 |
override void accept(Visitor v) |
| 343 |
{ |
| 344 |
v.visit(this); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
/*********************************************************** |
| 349 |
*/ |
| 350 |
extern (C++) final class PeelStatement : Statement |
| 351 |
{ |
| 352 |
Statement s; |
| 353 |
|
| 354 |
extern (D) this(Statement s) @safe |
| 355 |
{ |
| 356 |
super(s.loc, STMT.Peel); |
| 357 |
this.s = s; |
| 358 |
} |
| 359 |
|
| 360 |
override void accept(Visitor v) |
| 361 |
{ |
| 362 |
v.visit(this); |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
/*********************************************************** |
| 368 |
* https://dlang.org/spec/statement.html#ExpressionStatement |
| 369 |
*/ |
| 370 |
extern (C++) class ExpStatement : Statement |
| 371 |
{ |
| 372 |
Expression exp; |
| 373 |
|
| 374 |
final extern (D) this(Loc loc, Expression exp) @safe |
| 375 |
{ |
| 376 |
super(loc, STMT.Exp); |
| 377 |
this.exp = exp; |
| 378 |
} |
| 379 |
|
| 380 |
final extern (D) this(Loc loc, Expression exp, STMT stmt) @safe |
| 381 |
{ |
| 382 |
super(loc, stmt); |
| 383 |
this.exp = exp; |
| 384 |
} |
| 385 |
|
| 386 |
final extern (D) this(Loc loc, Dsymbol declaration) @safe |
| 387 |
{ |
| 388 |
super(loc, STMT.Exp); |
| 389 |
this.exp = new DeclarationExp(loc, declaration); |
| 390 |
} |
| 391 |
|
| 392 |
static ExpStatement create(Loc loc, Expression exp) @safe |
| 393 |
{ |
| 394 |
return new ExpStatement(loc, exp); |
| 395 |
} |
| 396 |
|
| 397 |
override ExpStatement syntaxCopy() |
| 398 |
{ |
| 399 |
return new ExpStatement(loc, exp ? exp.syntaxCopy() : null); |
| 400 |
} |
| 401 |
|
| 402 |
override void accept(Visitor v) |
| 403 |
{ |
| 404 |
v.visit(this); |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
/*********************************************************** |
| 409 |
*/ |
| 410 |
extern (C++) final class DtorExpStatement : ExpStatement |
| 411 |
{ |
| 412 |
// Wraps an expression that is the destruction of 'var' |
| 413 |
VarDeclaration var; |
| 414 |
|
| 415 |
extern (D) this(Loc loc, Expression exp, VarDeclaration var) @safe |
| 416 |
{ |
| 417 |
super(loc, exp, STMT.DtorExp); |
| 418 |
this.var = var; |
| 419 |
} |
| 420 |
|
| 421 |
override DtorExpStatement syntaxCopy() |
| 422 |
{ |
| 423 |
return new DtorExpStatement(loc, exp ? exp.syntaxCopy() : null, var); |
| 424 |
} |
| 425 |
|
| 426 |
override void accept(Visitor v) |
| 427 |
{ |
| 428 |
v.visit(this); |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
/*********************************************************** |
| 433 |
* https://dlang.org/spec/statement.html#mixin-statement |
| 434 |
*/ |
| 435 |
// Note: was called CompileStatement |
| 436 |
extern (C++) final class MixinStatement : Statement |
| 437 |
{ |
| 438 |
Expressions* exps; |
| 439 |
|
| 440 |
extern (D) this(Loc loc, Expression exp) |
| 441 |
{ |
| 442 |
Expressions* exps = new Expressions(); |
| 443 |
exps.push(exp); |
| 444 |
this(loc, exps); |
| 445 |
} |
| 446 |
|
| 447 |
extern (D) this(Loc loc, Expressions* exps) @safe |
| 448 |
{ |
| 449 |
super(loc, STMT.Mixin); |
| 450 |
this.exps = exps; |
| 451 |
} |
| 452 |
|
| 453 |
override MixinStatement syntaxCopy() |
| 454 |
{ |
| 455 |
return new MixinStatement(loc, Expression.arraySyntaxCopy(exps)); |
| 456 |
} |
| 457 |
|
| 458 |
override void accept(Visitor v) |
| 459 |
{ |
| 460 |
v.visit(this); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
/*********************************************************** |
| 465 |
*/ |
| 466 |
extern (C++) class CompoundStatement : Statement |
| 467 |
{ |
| 468 |
Statements* statements; |
| 469 |
|
| 470 |
/** |
| 471 |
* Construct a `CompoundStatement` using an already existing |
| 472 |
* array of `Statement`s |
| 473 |
* |
| 474 |
* Params: |
| 475 |
* loc = Instantiation information |
| 476 |
* statements = An array of `Statement`s, that will referenced by this class |
| 477 |
*/ |
| 478 |
final extern (D) this(Loc loc, Statements* statements) @safe |
| 479 |
{ |
| 480 |
super(loc, STMT.Compound); |
| 481 |
this.statements = statements; |
| 482 |
} |
| 483 |
|
| 484 |
final extern (D) this(Loc loc, Statements* statements, STMT stmt) @safe |
| 485 |
{ |
| 486 |
super(loc, stmt); |
| 487 |
this.statements = statements; |
| 488 |
} |
| 489 |
|
| 490 |
/** |
| 491 |
* Construct a `CompoundStatement` from an array of `Statement`s |
| 492 |
* |
| 493 |
* Params: |
| 494 |
* loc = Instantiation information |
| 495 |
* sts = A variadic array of `Statement`s, that will copied in this class |
| 496 |
* The entries themselves will not be copied. |
| 497 |
*/ |
| 498 |
final extern (D) this(Loc loc, Statement[] sts...) |
| 499 |
{ |
| 500 |
super(loc, STMT.Compound); |
| 501 |
statements = new Statements(); |
| 502 |
statements.reserve(sts.length); |
| 503 |
foreach (s; sts) |
| 504 |
statements.push(s); |
| 505 |
} |
| 506 |
|
| 507 |
static CompoundStatement create(Loc loc, Statement s1, Statement s2) |
| 508 |
{ |
| 509 |
return new CompoundStatement(loc, s1, s2); |
| 510 |
} |
| 511 |
|
| 512 |
override CompoundStatement syntaxCopy() |
| 513 |
{ |
| 514 |
return new CompoundStatement(loc, Statement.arraySyntaxCopy(statements)); |
| 515 |
} |
| 516 |
|
| 517 |
override final inout(ReturnStatement) endsWithReturnStatement() inout nothrow pure |
| 518 |
{ |
| 519 |
foreach (s; *statements) |
| 520 |
{ |
| 521 |
if (s) |
| 522 |
{ |
| 523 |
if (inout rs = s.endsWithReturnStatement()) |
| 524 |
return rs; |
| 525 |
} |
| 526 |
} |
| 527 |
return null; |
| 528 |
} |
| 529 |
|
| 530 |
override final inout(Statement) last() inout nothrow pure |
| 531 |
{ |
| 532 |
Statement s = null; |
| 533 |
for (size_t i = statements.length; i; --i) |
| 534 |
{ |
| 535 |
s = cast(Statement)(*statements)[i - 1]; |
| 536 |
if (s) |
| 537 |
{ |
| 538 |
s = cast(Statement)s.last(); |
| 539 |
if (s) |
| 540 |
break; |
| 541 |
} |
| 542 |
} |
| 543 |
return cast(inout)s; |
| 544 |
} |
| 545 |
|
| 546 |
override void accept(Visitor v) |
| 547 |
{ |
| 548 |
v.visit(this); |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
/*********************************************************** |
| 553 |
*/ |
| 554 |
extern (C++) final class CompoundDeclarationStatement : CompoundStatement |
| 555 |
{ |
| 556 |
extern (D) this(Loc loc, Statements* statements) @safe |
| 557 |
{ |
| 558 |
super(loc, statements, STMT.CompoundDeclaration); |
| 559 |
} |
| 560 |
|
| 561 |
override CompoundDeclarationStatement syntaxCopy() |
| 562 |
{ |
| 563 |
return new CompoundDeclarationStatement(loc, Statement.arraySyntaxCopy(statements)); |
| 564 |
} |
| 565 |
|
| 566 |
override void accept(Visitor v) |
| 567 |
{ |
| 568 |
v.visit(this); |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
/*********************************************************** |
| 573 |
* The purpose of this is so that continue will go to the next |
| 574 |
* of the statements, and break will go to the end of the statements. |
| 575 |
*/ |
| 576 |
extern (C++) final class UnrolledLoopStatement : Statement |
| 577 |
{ |
| 578 |
Statements* statements; |
| 579 |
|
| 580 |
extern (D) this(Loc loc, Statements* statements) @safe |
| 581 |
{ |
| 582 |
super(loc, STMT.UnrolledLoop); |
| 583 |
this.statements = statements; |
| 584 |
} |
| 585 |
|
| 586 |
override UnrolledLoopStatement syntaxCopy() |
| 587 |
{ |
| 588 |
return new UnrolledLoopStatement(loc, Statement.arraySyntaxCopy(statements)); |
| 589 |
} |
| 590 |
|
| 591 |
override bool hasBreak() const pure nothrow |
| 592 |
{ |
| 593 |
return true; |
| 594 |
} |
| 595 |
|
| 596 |
override bool hasContinue() const pure nothrow |
| 597 |
{ |
| 598 |
return true; |
| 599 |
} |
| 600 |
|
| 601 |
override void accept(Visitor v) |
| 602 |
{ |
| 603 |
v.visit(this); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
/*********************************************************** |
| 608 |
*/ |
| 609 |
extern (C++) final class ScopeStatement : Statement |
| 610 |
{ |
| 611 |
Statement statement; |
| 612 |
Loc endloc; // location of closing curly bracket |
| 613 |
|
| 614 |
extern (D) this(Loc loc, Statement statement, Loc endloc) @safe |
| 615 |
{ |
| 616 |
super(loc, STMT.Scope); |
| 617 |
this.statement = statement; |
| 618 |
this.endloc = endloc; |
| 619 |
} |
| 620 |
|
| 621 |
override ScopeStatement syntaxCopy() |
| 622 |
{ |
| 623 |
return new ScopeStatement(loc, statement ? statement.syntaxCopy() : null, endloc); |
| 624 |
} |
| 625 |
|
| 626 |
override inout(ReturnStatement) endsWithReturnStatement() inout nothrow pure |
| 627 |
{ |
| 628 |
if (statement) |
| 629 |
return statement.endsWithReturnStatement(); |
| 630 |
return null; |
| 631 |
} |
| 632 |
|
| 633 |
override bool hasBreak() const pure nothrow |
| 634 |
{ |
| 635 |
//printf("ScopeStatement::hasBreak() %s\n", toChars()); |
| 636 |
return statement ? statement.hasBreak() : false; |
| 637 |
} |
| 638 |
|
| 639 |
override bool hasContinue() const pure nothrow |
| 640 |
{ |
| 641 |
return statement ? statement.hasContinue() : false; |
| 642 |
} |
| 643 |
|
| 644 |
override void accept(Visitor v) |
| 645 |
{ |
| 646 |
v.visit(this); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
/*********************************************************** |
| 651 |
* Statement whose symbol table contains foreach index variables in a |
| 652 |
* local scope and forwards other members to the parent scope. This |
| 653 |
* wraps a statement. |
| 654 |
* |
| 655 |
* Also see: `dmd.attrib.ForwardingAttribDeclaration` |
| 656 |
*/ |
| 657 |
extern (C++) final class ForwardingStatement : Statement |
| 658 |
{ |
| 659 |
/// The symbol containing the `static foreach` variables. |
| 660 |
ForwardingScopeDsymbol sym = null; |
| 661 |
/// The wrapped statement. |
| 662 |
Statement statement; |
| 663 |
|
| 664 |
extern (D) this(Loc loc, ForwardingScopeDsymbol sym, Statement statement) @safe |
| 665 |
{ |
| 666 |
super(loc, STMT.Forwarding); |
| 667 |
this.sym = sym; |
| 668 |
assert(statement); |
| 669 |
this.statement = statement; |
| 670 |
} |
| 671 |
|
| 672 |
extern (D) this(Loc loc, Statement statement) @safe |
| 673 |
{ |
| 674 |
auto sym = new ForwardingScopeDsymbol(); |
| 675 |
sym.symtab = new DsymbolTable(); |
| 676 |
this(loc, sym, statement); |
| 677 |
} |
| 678 |
|
| 679 |
override ForwardingStatement syntaxCopy() |
| 680 |
{ |
| 681 |
return new ForwardingStatement(loc, statement.syntaxCopy()); |
| 682 |
} |
| 683 |
|
| 684 |
override void accept(Visitor v) |
| 685 |
{ |
| 686 |
v.visit(this); |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
/*********************************************************** |
| 692 |
* https://dlang.org/spec/statement.html#while-statement |
| 693 |
*/ |
| 694 |
extern (C++) final class WhileStatement : Statement |
| 695 |
{ |
| 696 |
Parameter param; |
| 697 |
Expression condition; |
| 698 |
Statement _body; |
| 699 |
Loc endloc; // location of closing curly bracket |
| 700 |
|
| 701 |
extern (D) this(Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null) @safe |
| 702 |
{ |
| 703 |
super(loc, STMT.While); |
| 704 |
this.condition = condition; |
| 705 |
this._body = _body; |
| 706 |
this.endloc = endloc; |
| 707 |
this.param = param; |
| 708 |
} |
| 709 |
|
| 710 |
override WhileStatement syntaxCopy() |
| 711 |
{ |
| 712 |
return new WhileStatement(loc, |
| 713 |
condition.syntaxCopy(), |
| 714 |
_body ? _body.syntaxCopy() : null, |
| 715 |
endloc, param ? param.syntaxCopy() : null); |
| 716 |
} |
| 717 |
|
| 718 |
override bool hasBreak() const pure nothrow |
| 719 |
{ |
| 720 |
return true; |
| 721 |
} |
| 722 |
|
| 723 |
override bool hasContinue() const pure nothrow |
| 724 |
{ |
| 725 |
return true; |
| 726 |
} |
| 727 |
|
| 728 |
override void accept(Visitor v) |
| 729 |
{ |
| 730 |
v.visit(this); |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
/*********************************************************** |
| 735 |
* https://dlang.org/spec/statement.html#do-statement |
| 736 |
*/ |
| 737 |
extern (C++) final class DoStatement : Statement |
| 738 |
{ |
| 739 |
Statement _body; |
| 740 |
Expression condition; |
| 741 |
Loc endloc; // location of ';' after while |
| 742 |
|
| 743 |
extern (D) this(Loc loc, Statement _body, Expression condition, Loc endloc) @safe |
| 744 |
{ |
| 745 |
super(loc, STMT.Do); |
| 746 |
this._body = _body; |
| 747 |
this.condition = condition; |
| 748 |
this.endloc = endloc; |
| 749 |
} |
| 750 |
|
| 751 |
override DoStatement syntaxCopy() |
| 752 |
{ |
| 753 |
return new DoStatement(loc, |
| 754 |
_body ? _body.syntaxCopy() : null, |
| 755 |
condition.syntaxCopy(), |
| 756 |
endloc); |
| 757 |
} |
| 758 |
|
| 759 |
override bool hasBreak() const pure nothrow |
| 760 |
{ |
| 761 |
return true; |
| 762 |
} |
| 763 |
|
| 764 |
override bool hasContinue() const pure nothrow |
| 765 |
{ |
| 766 |
return true; |
| 767 |
} |
| 768 |
|
| 769 |
override void accept(Visitor v) |
| 770 |
{ |
| 771 |
v.visit(this); |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
/*********************************************************** |
| 776 |
* https://dlang.org/spec/statement.html#for-statement |
| 777 |
*/ |
| 778 |
extern (C++) final class ForStatement : Statement |
| 779 |
{ |
| 780 |
Statement _init; |
| 781 |
Expression condition; |
| 782 |
Expression increment; |
| 783 |
Statement _body; |
| 784 |
Loc endloc; // location of closing curly bracket |
| 785 |
|
| 786 |
// When wrapped in try/finally clauses, this points to the outermost one, |
| 787 |
// which may have an associated label. Internal break/continue statements |
| 788 |
// treat that label as referring to this loop. |
| 789 |
Statement relatedLabeled; |
| 790 |
|
| 791 |
extern (D) this(Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc) @safe |
| 792 |
{ |
| 793 |
super(loc, STMT.For); |
| 794 |
this._init = _init; |
| 795 |
this.condition = condition; |
| 796 |
this.increment = increment; |
| 797 |
this._body = _body; |
| 798 |
this.endloc = endloc; |
| 799 |
} |
| 800 |
|
| 801 |
override ForStatement syntaxCopy() |
| 802 |
{ |
| 803 |
return new ForStatement(loc, |
| 804 |
_init ? _init.syntaxCopy() : null, |
| 805 |
condition ? condition.syntaxCopy() : null, |
| 806 |
increment ? increment.syntaxCopy() : null, |
| 807 |
_body.syntaxCopy(), |
| 808 |
endloc); |
| 809 |
} |
| 810 |
|
| 811 |
override Statement getRelatedLabeled() |
| 812 |
{ |
| 813 |
return relatedLabeled ? relatedLabeled : this; |
| 814 |
} |
| 815 |
|
| 816 |
override bool hasBreak() const pure nothrow |
| 817 |
{ |
| 818 |
//printf("ForStatement::hasBreak()\n"); |
| 819 |
return true; |
| 820 |
} |
| 821 |
|
| 822 |
override bool hasContinue() const pure nothrow |
| 823 |
{ |
| 824 |
return true; |
| 825 |
} |
| 826 |
|
| 827 |
override void accept(Visitor v) |
| 828 |
{ |
| 829 |
v.visit(this); |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
/*********************************************************** |
| 834 |
* https://dlang.org/spec/statement.html#foreach-statement |
| 835 |
*/ |
| 836 |
extern (C++) final class ForeachStatement : Statement |
| 837 |
{ |
| 838 |
TOK op; // TOK.foreach_ or TOK.foreach_reverse_ |
| 839 |
Parameters* parameters; // array of Parameters, one for each ForeachType |
| 840 |
Expression aggr; // ForeachAggregate |
| 841 |
Statement _body; // NoScopeNonEmptyStatement |
| 842 |
Loc endloc; // location of closing curly bracket |
| 843 |
|
| 844 |
VarDeclaration key; |
| 845 |
VarDeclaration value; |
| 846 |
|
| 847 |
FuncDeclaration func; // function we're lexically in |
| 848 |
|
| 849 |
Statements* cases; // put breaks, continues, gotos and returns here |
| 850 |
ScopeStatements* gotos; // forward referenced goto's go here |
| 851 |
|
| 852 |
extern (D) this(Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc) @safe |
| 853 |
{ |
| 854 |
super(loc, STMT.Foreach); |
| 855 |
this.op = op; |
| 856 |
this.parameters = parameters; |
| 857 |
this.aggr = aggr; |
| 858 |
this._body = _body; |
| 859 |
this.endloc = endloc; |
| 860 |
} |
| 861 |
|
| 862 |
override ForeachStatement syntaxCopy() |
| 863 |
{ |
| 864 |
return new ForeachStatement(loc, op, |
| 865 |
Parameter.arraySyntaxCopy(parameters), |
| 866 |
aggr.syntaxCopy(), |
| 867 |
_body ? _body.syntaxCopy() : null, |
| 868 |
endloc); |
| 869 |
} |
| 870 |
|
| 871 |
override bool hasBreak() const pure nothrow |
| 872 |
{ |
| 873 |
return true; |
| 874 |
} |
| 875 |
|
| 876 |
override bool hasContinue() const pure nothrow |
| 877 |
{ |
| 878 |
return true; |
| 879 |
} |
| 880 |
|
| 881 |
override void accept(Visitor v) |
| 882 |
{ |
| 883 |
v.visit(this); |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
/*********************************************************** |
| 888 |
* https://dlang.org/spec/statement.html#foreach-range-statement |
| 889 |
*/ |
| 890 |
extern (C++) final class ForeachRangeStatement : Statement |
| 891 |
{ |
| 892 |
TOK op; // TOK.foreach_ or TOK.foreach_reverse_ |
| 893 |
Parameter param; // loop index variable |
| 894 |
Expression lwr; |
| 895 |
Expression upr; |
| 896 |
Statement _body; |
| 897 |
Loc endloc; // location of closing curly bracket |
| 898 |
|
| 899 |
VarDeclaration key; |
| 900 |
|
| 901 |
extern (D) this(Loc loc, TOK op, Parameter param, Expression lwr, Expression upr, Statement _body, Loc endloc) @safe |
| 902 |
{ |
| 903 |
super(loc, STMT.ForeachRange); |
| 904 |
this.op = op; |
| 905 |
this.param = param; |
| 906 |
this.lwr = lwr; |
| 907 |
this.upr = upr; |
| 908 |
this._body = _body; |
| 909 |
this.endloc = endloc; |
| 910 |
} |
| 911 |
|
| 912 |
override ForeachRangeStatement syntaxCopy() |
| 913 |
{ |
| 914 |
return new ForeachRangeStatement(loc, op, param.syntaxCopy(), lwr.syntaxCopy(), upr.syntaxCopy(), _body ? _body.syntaxCopy() : null, endloc); |
| 915 |
} |
| 916 |
|
| 917 |
override bool hasBreak() const pure nothrow |
| 918 |
{ |
| 919 |
return true; |
| 920 |
} |
| 921 |
|
| 922 |
override bool hasContinue() const pure nothrow |
| 923 |
{ |
| 924 |
return true; |
| 925 |
} |
| 926 |
|
| 927 |
override void accept(Visitor v) |
| 928 |
{ |
| 929 |
v.visit(this); |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
/*********************************************************** |
| 934 |
* https://dlang.org/spec/statement.html#if-statement |
| 935 |
*/ |
| 936 |
extern (C++) final class IfStatement : Statement |
| 937 |
{ |
| 938 |
Parameter param; |
| 939 |
Expression condition; |
| 940 |
Statement ifbody; |
| 941 |
Statement elsebody; |
| 942 |
VarDeclaration match; // for MatchExpression results |
| 943 |
Loc endloc; // location of closing curly bracket |
| 944 |
|
| 945 |
extern (D) this(Loc loc, Parameter param, Expression condition, Statement ifbody, Statement elsebody, Loc endloc) @safe |
| 946 |
{ |
| 947 |
super(loc, STMT.If); |
| 948 |
this.param = param; |
| 949 |
this.condition = condition; |
| 950 |
this.ifbody = ifbody; |
| 951 |
this.elsebody = elsebody; |
| 952 |
this.endloc = endloc; |
| 953 |
} |
| 954 |
|
| 955 |
override IfStatement syntaxCopy() |
| 956 |
{ |
| 957 |
return new IfStatement(loc, |
| 958 |
param ? param.syntaxCopy() : null, |
| 959 |
condition.syntaxCopy(), |
| 960 |
ifbody ? ifbody.syntaxCopy() : null, |
| 961 |
elsebody ? elsebody.syntaxCopy() : null, |
| 962 |
endloc); |
| 963 |
} |
| 964 |
|
| 965 |
override void accept(Visitor v) |
| 966 |
{ |
| 967 |
v.visit(this); |
| 968 |
} |
| 969 |
|
| 970 |
/****** |
| 971 |
* Returns: true if `if (__ctfe)` |
| 972 |
*/ |
| 973 |
bool isIfCtfeBlock() |
| 974 |
{ |
| 975 |
if (auto cv = condition.isVarExp()) |
| 976 |
return cv.var.ident == Id.ctfe; |
| 977 |
return false; |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
/*********************************************************** |
| 982 |
* https://dlang.org/spec/version.html#ConditionalStatement |
| 983 |
*/ |
| 984 |
extern (C++) final class ConditionalStatement : Statement |
| 985 |
{ |
| 986 |
Condition condition; |
| 987 |
Statement ifbody; |
| 988 |
Statement elsebody; |
| 989 |
|
| 990 |
extern (D) this(Loc loc, Condition condition, Statement ifbody, Statement elsebody) @safe |
| 991 |
{ |
| 992 |
super(loc, STMT.Conditional); |
| 993 |
this.condition = condition; |
| 994 |
this.ifbody = ifbody; |
| 995 |
this.elsebody = elsebody; |
| 996 |
} |
| 997 |
|
| 998 |
override ConditionalStatement syntaxCopy() |
| 999 |
{ |
| 1000 |
return new ConditionalStatement(loc, condition.syntaxCopy(), ifbody.syntaxCopy(), elsebody ? elsebody.syntaxCopy() : null); |
| 1001 |
} |
| 1002 |
|
| 1003 |
override void accept(Visitor v) |
| 1004 |
{ |
| 1005 |
v.visit(this); |
| 1006 |
} |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
/*********************************************************** |
| 1011 |
* https://dlang.org/spec/version.html#StaticForeachStatement |
| 1012 |
* Static foreach statements, like: |
| 1013 |
* void main() |
| 1014 |
* { |
| 1015 |
* static foreach(i; 0 .. 10) |
| 1016 |
* { |
| 1017 |
* pragma(msg, i); |
| 1018 |
* } |
| 1019 |
* } |
| 1020 |
*/ |
| 1021 |
extern (C++) final class StaticForeachStatement : Statement |
| 1022 |
{ |
| 1023 |
StaticForeach sfe; |
| 1024 |
|
| 1025 |
extern (D) this(Loc loc, StaticForeach sfe) @safe |
| 1026 |
{ |
| 1027 |
super(loc, STMT.StaticForeach); |
| 1028 |
this.sfe = sfe; |
| 1029 |
} |
| 1030 |
|
| 1031 |
override StaticForeachStatement syntaxCopy() |
| 1032 |
{ |
| 1033 |
return new StaticForeachStatement(loc, sfe.syntaxCopy()); |
| 1034 |
} |
| 1035 |
|
| 1036 |
override void accept(Visitor v) |
| 1037 |
{ |
| 1038 |
v.visit(this); |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
/*********************************************************** |
| 1043 |
* https://dlang.org/spec/statement.html#pragma-statement |
| 1044 |
*/ |
| 1045 |
extern (C++) final class PragmaStatement : Statement |
| 1046 |
{ |
| 1047 |
const Identifier ident; |
| 1048 |
Expressions* args; // array of Expression's |
| 1049 |
Statement _body; |
| 1050 |
|
| 1051 |
extern (D) this(Loc loc, const Identifier ident, Expressions* args, Statement _body) @safe |
| 1052 |
{ |
| 1053 |
super(loc, STMT.Pragma); |
| 1054 |
this.ident = ident; |
| 1055 |
this.args = args; |
| 1056 |
this._body = _body; |
| 1057 |
} |
| 1058 |
|
| 1059 |
override PragmaStatement syntaxCopy() |
| 1060 |
{ |
| 1061 |
return new PragmaStatement(loc, ident, Expression.arraySyntaxCopy(args), _body ? _body.syntaxCopy() : null); |
| 1062 |
} |
| 1063 |
|
| 1064 |
override void accept(Visitor v) |
| 1065 |
{ |
| 1066 |
v.visit(this); |
| 1067 |
} |
| 1068 |
} |
| 1069 |
|
| 1070 |
/*********************************************************** |
| 1071 |
* https://dlang.org/spec/version.html#StaticAssert |
| 1072 |
*/ |
| 1073 |
extern (C++) final class StaticAssertStatement : Statement |
| 1074 |
{ |
| 1075 |
StaticAssert sa; |
| 1076 |
|
| 1077 |
extern (D) this(StaticAssert sa) @safe |
| 1078 |
{ |
| 1079 |
super(sa.loc, STMT.StaticAssert); |
| 1080 |
this.sa = sa; |
| 1081 |
} |
| 1082 |
|
| 1083 |
override StaticAssertStatement syntaxCopy() |
| 1084 |
{ |
| 1085 |
return new StaticAssertStatement(sa.syntaxCopy(null)); |
| 1086 |
} |
| 1087 |
|
| 1088 |
override void accept(Visitor v) |
| 1089 |
{ |
| 1090 |
v.visit(this); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
/*********************************************************** |
| 1095 |
* https://dlang.org/spec/statement.html#switch-statement |
| 1096 |
*/ |
| 1097 |
extern (C++) final class SwitchStatement : Statement |
| 1098 |
{ |
| 1099 |
Parameter param; |
| 1100 |
Expression condition; /// switch(condition) |
| 1101 |
Statement _body; /// |
| 1102 |
bool isFinal; /// https://dlang.org/spec/statement.html#final-switch-statement |
| 1103 |
Loc endloc; |
| 1104 |
|
| 1105 |
bool hasDefault; /// true if has default statement |
| 1106 |
bool hasVars; /// true if has variable case values |
| 1107 |
DefaultStatement sdefault; /// default: |
| 1108 |
Statement tryBody; /// set to TryCatchStatement or TryFinallyStatement if in _body portion |
| 1109 |
TryFinallyStatement tryFinally; /// set if in the 'finally' block of a TryFinallyStatement |
| 1110 |
GotoCaseStatements gotoCases; /// array of unresolved GotoCaseStatement's |
| 1111 |
CaseStatements* cases; /// array of CaseStatement's |
| 1112 |
VarDeclaration lastVar; /// last observed variable declaration in this statement |
| 1113 |
|
| 1114 |
extern (D) this(Loc loc, Parameter param, Expression condition, Statement _body, bool isFinal, Loc endloc) |
| 1115 |
{ |
| 1116 |
super(loc, STMT.Switch); |
| 1117 |
this.param = param; |
| 1118 |
this.condition = condition; |
| 1119 |
this._body = _body; |
| 1120 |
this.isFinal = isFinal; |
| 1121 |
this.endloc = endloc; |
| 1122 |
} |
| 1123 |
|
| 1124 |
override SwitchStatement syntaxCopy() |
| 1125 |
{ |
| 1126 |
return new SwitchStatement(loc, |
| 1127 |
param ? param.syntaxCopy() : null, |
| 1128 |
condition.syntaxCopy(), |
| 1129 |
_body.syntaxCopy(), |
| 1130 |
isFinal, |
| 1131 |
endloc); |
| 1132 |
} |
| 1133 |
|
| 1134 |
override bool hasBreak() const pure nothrow |
| 1135 |
{ |
| 1136 |
return true; |
| 1137 |
} |
| 1138 |
|
| 1139 |
override void accept(Visitor v) |
| 1140 |
{ |
| 1141 |
v.visit(this); |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
/*********************************************************** |
| 1146 |
* https://dlang.org/spec/statement.html#CaseStatement |
| 1147 |
*/ |
| 1148 |
extern (C++) final class CaseStatement : Statement |
| 1149 |
{ |
| 1150 |
Expression exp; |
| 1151 |
Statement statement; |
| 1152 |
|
| 1153 |
int index; // which case it is (since we sort this) |
| 1154 |
VarDeclaration lastVar; |
| 1155 |
void* extra; // for use by Statement_toIR() |
| 1156 |
|
| 1157 |
extern (D) this(Loc loc, Expression exp, Statement statement) @safe |
| 1158 |
{ |
| 1159 |
super(loc, STMT.Case); |
| 1160 |
this.exp = exp; |
| 1161 |
this.statement = statement; |
| 1162 |
} |
| 1163 |
|
| 1164 |
override CaseStatement syntaxCopy() |
| 1165 |
{ |
| 1166 |
return new CaseStatement(loc, exp.syntaxCopy(), statement.syntaxCopy()); |
| 1167 |
} |
| 1168 |
|
| 1169 |
override void accept(Visitor v) |
| 1170 |
{ |
| 1171 |
v.visit(this); |
| 1172 |
} |
| 1173 |
} |
| 1174 |
|
| 1175 |
/*********************************************************** |
| 1176 |
* https://dlang.org/spec/statement.html#CaseRangeStatement |
| 1177 |
*/ |
| 1178 |
extern (C++) final class CaseRangeStatement : Statement |
| 1179 |
{ |
| 1180 |
Expression first; |
| 1181 |
Expression last; |
| 1182 |
Statement statement; |
| 1183 |
|
| 1184 |
extern (D) this(Loc loc, Expression first, Expression last, Statement statement) @safe |
| 1185 |
{ |
| 1186 |
super(loc, STMT.CaseRange); |
| 1187 |
this.first = first; |
| 1188 |
this.last = last; |
| 1189 |
this.statement = statement; |
| 1190 |
} |
| 1191 |
|
| 1192 |
override CaseRangeStatement syntaxCopy() |
| 1193 |
{ |
| 1194 |
return new CaseRangeStatement(loc, first.syntaxCopy(), last.syntaxCopy(), statement.syntaxCopy()); |
| 1195 |
} |
| 1196 |
|
| 1197 |
override void accept(Visitor v) |
| 1198 |
{ |
| 1199 |
v.visit(this); |
| 1200 |
} |
| 1201 |
} |
| 1202 |
|
| 1203 |
/*********************************************************** |
| 1204 |
* https://dlang.org/spec/statement.html#DefaultStatement |
| 1205 |
*/ |
| 1206 |
extern (C++) final class DefaultStatement : Statement |
| 1207 |
{ |
| 1208 |
Statement statement; |
| 1209 |
|
| 1210 |
VarDeclaration lastVar; |
| 1211 |
|
| 1212 |
extern (D) this(Loc loc, Statement statement) @safe |
| 1213 |
{ |
| 1214 |
super(loc, STMT.Default); |
| 1215 |
this.statement = statement; |
| 1216 |
} |
| 1217 |
|
| 1218 |
override DefaultStatement syntaxCopy() |
| 1219 |
{ |
| 1220 |
return new DefaultStatement(loc, statement.syntaxCopy()); |
| 1221 |
} |
| 1222 |
|
| 1223 |
override void accept(Visitor v) |
| 1224 |
{ |
| 1225 |
v.visit(this); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
/*********************************************************** |
| 1230 |
* https://dlang.org/spec/statement.html#GotoStatement |
| 1231 |
*/ |
| 1232 |
extern (C++) final class GotoDefaultStatement : Statement |
| 1233 |
{ |
| 1234 |
SwitchStatement sw; |
| 1235 |
|
| 1236 |
extern (D) this(Loc loc) @safe |
| 1237 |
{ |
| 1238 |
super(loc, STMT.GotoDefault); |
| 1239 |
} |
| 1240 |
|
| 1241 |
override GotoDefaultStatement syntaxCopy() |
| 1242 |
{ |
| 1243 |
return new GotoDefaultStatement(loc); |
| 1244 |
} |
| 1245 |
|
| 1246 |
override void accept(Visitor v) |
| 1247 |
{ |
| 1248 |
v.visit(this); |
| 1249 |
} |
| 1250 |
} |
| 1251 |
|
| 1252 |
/*********************************************************** |
| 1253 |
* https://dlang.org/spec/statement.html#GotoStatement |
| 1254 |
*/ |
| 1255 |
extern (C++) final class GotoCaseStatement : Statement |
| 1256 |
{ |
| 1257 |
Expression exp; // null, or which case to goto |
| 1258 |
|
| 1259 |
CaseStatement cs; // case statement it resolves to |
| 1260 |
|
| 1261 |
extern (D) this(Loc loc, Expression exp) @safe |
| 1262 |
{ |
| 1263 |
super(loc, STMT.GotoCase); |
| 1264 |
this.exp = exp; |
| 1265 |
} |
| 1266 |
|
| 1267 |
override GotoCaseStatement syntaxCopy() |
| 1268 |
{ |
| 1269 |
return new GotoCaseStatement(loc, exp ? exp.syntaxCopy() : null); |
| 1270 |
} |
| 1271 |
|
| 1272 |
override void accept(Visitor v) |
| 1273 |
{ |
| 1274 |
v.visit(this); |
| 1275 |
} |
| 1276 |
} |
| 1277 |
|
| 1278 |
/*********************************************************** |
| 1279 |
*/ |
| 1280 |
extern (C++) final class SwitchErrorStatement : Statement |
| 1281 |
{ |
| 1282 |
Expression exp; |
| 1283 |
|
| 1284 |
extern (D) this(Loc loc) @safe |
| 1285 |
{ |
| 1286 |
super(loc, STMT.SwitchError); |
| 1287 |
} |
| 1288 |
|
| 1289 |
final extern (D) this(Loc loc, Expression exp) @safe |
| 1290 |
{ |
| 1291 |
super(loc, STMT.SwitchError); |
| 1292 |
this.exp = exp; |
| 1293 |
} |
| 1294 |
|
| 1295 |
override void accept(Visitor v) |
| 1296 |
{ |
| 1297 |
v.visit(this); |
| 1298 |
} |
| 1299 |
} |
| 1300 |
|
| 1301 |
/*********************************************************** |
| 1302 |
* https://dlang.org/spec/statement.html#return-statement |
| 1303 |
*/ |
| 1304 |
extern (C++) final class ReturnStatement : Statement |
| 1305 |
{ |
| 1306 |
Expression exp; |
| 1307 |
size_t caseDim; |
| 1308 |
|
| 1309 |
extern (D) this(Loc loc, Expression exp) @safe |
| 1310 |
{ |
| 1311 |
super(loc, STMT.Return); |
| 1312 |
this.exp = exp; |
| 1313 |
} |
| 1314 |
|
| 1315 |
override ReturnStatement syntaxCopy() |
| 1316 |
{ |
| 1317 |
return new ReturnStatement(loc, exp ? exp.syntaxCopy() : null); |
| 1318 |
} |
| 1319 |
|
| 1320 |
override inout(ReturnStatement) endsWithReturnStatement() inout nothrow pure |
| 1321 |
{ |
| 1322 |
return this; |
| 1323 |
} |
| 1324 |
|
| 1325 |
override void accept(Visitor v) |
| 1326 |
{ |
| 1327 |
v.visit(this); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
/*********************************************************** |
| 1332 |
* https://dlang.org/spec/statement.html#break-statement |
| 1333 |
*/ |
| 1334 |
extern (C++) final class BreakStatement : Statement |
| 1335 |
{ |
| 1336 |
Identifier ident; |
| 1337 |
|
| 1338 |
extern (D) this(Loc loc, Identifier ident) @safe |
| 1339 |
{ |
| 1340 |
super(loc, STMT.Break); |
| 1341 |
this.ident = ident; |
| 1342 |
} |
| 1343 |
|
| 1344 |
override BreakStatement syntaxCopy() |
| 1345 |
{ |
| 1346 |
return new BreakStatement(loc, ident); |
| 1347 |
} |
| 1348 |
|
| 1349 |
override void accept(Visitor v) |
| 1350 |
{ |
| 1351 |
v.visit(this); |
| 1352 |
} |
| 1353 |
} |
| 1354 |
|
| 1355 |
/*********************************************************** |
| 1356 |
* https://dlang.org/spec/statement.html#continue-statement |
| 1357 |
*/ |
| 1358 |
extern (C++) final class ContinueStatement : Statement |
| 1359 |
{ |
| 1360 |
Identifier ident; |
| 1361 |
|
| 1362 |
extern (D) this(Loc loc, Identifier ident) @safe |
| 1363 |
{ |
| 1364 |
super(loc, STMT.Continue); |
| 1365 |
this.ident = ident; |
| 1366 |
} |
| 1367 |
|
| 1368 |
override ContinueStatement syntaxCopy() |
| 1369 |
{ |
| 1370 |
return new ContinueStatement(loc, ident); |
| 1371 |
} |
| 1372 |
|
| 1373 |
override void accept(Visitor v) |
| 1374 |
{ |
| 1375 |
v.visit(this); |
| 1376 |
} |
| 1377 |
} |
| 1378 |
|
| 1379 |
/*********************************************************** |
| 1380 |
* https://dlang.org/spec/statement.html#SynchronizedStatement |
| 1381 |
*/ |
| 1382 |
extern (C++) final class SynchronizedStatement : Statement |
| 1383 |
{ |
| 1384 |
Expression exp; |
| 1385 |
Statement _body; |
| 1386 |
|
| 1387 |
extern (D) this(Loc loc, Expression exp, Statement _body) @safe |
| 1388 |
{ |
| 1389 |
super(loc, STMT.Synchronized); |
| 1390 |
this.exp = exp; |
| 1391 |
this._body = _body; |
| 1392 |
} |
| 1393 |
|
| 1394 |
override SynchronizedStatement syntaxCopy() |
| 1395 |
{ |
| 1396 |
return new SynchronizedStatement(loc, exp ? exp.syntaxCopy() : null, _body ? _body.syntaxCopy() : null); |
| 1397 |
} |
| 1398 |
|
| 1399 |
override bool hasBreak() const pure nothrow |
| 1400 |
{ |
| 1401 |
return false; //true; |
| 1402 |
} |
| 1403 |
|
| 1404 |
override bool hasContinue() const pure nothrow |
| 1405 |
{ |
| 1406 |
return false; //true; |
| 1407 |
} |
| 1408 |
|
| 1409 |
override void accept(Visitor v) |
| 1410 |
{ |
| 1411 |
v.visit(this); |
| 1412 |
} |
| 1413 |
} |
| 1414 |
|
| 1415 |
/*********************************************************** |
| 1416 |
* https://dlang.org/spec/statement.html#with-statement |
| 1417 |
*/ |
| 1418 |
extern (C++) final class WithStatement : Statement |
| 1419 |
{ |
| 1420 |
Expression exp; |
| 1421 |
Statement _body; |
| 1422 |
VarDeclaration wthis; |
| 1423 |
Loc endloc; |
| 1424 |
|
| 1425 |
extern (D) this(Loc loc, Expression exp, Statement _body, Loc endloc) @safe |
| 1426 |
{ |
| 1427 |
super(loc, STMT.With); |
| 1428 |
this.exp = exp; |
| 1429 |
this._body = _body; |
| 1430 |
this.endloc = endloc; |
| 1431 |
} |
| 1432 |
|
| 1433 |
override WithStatement syntaxCopy() |
| 1434 |
{ |
| 1435 |
return new WithStatement(loc, exp.syntaxCopy(), _body ? _body.syntaxCopy() : null, endloc); |
| 1436 |
} |
| 1437 |
|
| 1438 |
override void accept(Visitor v) |
| 1439 |
{ |
| 1440 |
v.visit(this); |
| 1441 |
} |
| 1442 |
} |
| 1443 |
|
| 1444 |
/*********************************************************** |
| 1445 |
* https://dlang.org/spec/statement.html#try-statement |
| 1446 |
*/ |
| 1447 |
extern (C++) final class TryCatchStatement : Statement |
| 1448 |
{ |
| 1449 |
Statement _body; |
| 1450 |
Catches* catches; |
| 1451 |
|
| 1452 |
Statement tryBody; /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion |
| 1453 |
|
| 1454 |
extern (D) this(Loc loc, Statement _body, Catches* catches) @safe |
| 1455 |
{ |
| 1456 |
super(loc, STMT.TryCatch); |
| 1457 |
this._body = _body; |
| 1458 |
this.catches = catches; |
| 1459 |
} |
| 1460 |
|
| 1461 |
override TryCatchStatement syntaxCopy() |
| 1462 |
{ |
| 1463 |
auto a = new Catches(catches.length); |
| 1464 |
foreach (i, c; *catches) |
| 1465 |
{ |
| 1466 |
(*a)[i] = c.syntaxCopy(); |
| 1467 |
} |
| 1468 |
return new TryCatchStatement(loc, _body.syntaxCopy(), a); |
| 1469 |
} |
| 1470 |
|
| 1471 |
override bool hasBreak() const pure nothrow |
| 1472 |
{ |
| 1473 |
return false; |
| 1474 |
} |
| 1475 |
|
| 1476 |
override void accept(Visitor v) |
| 1477 |
{ |
| 1478 |
v.visit(this); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
/*********************************************************** |
| 1483 |
* https://dlang.org/spec/statement.html#Catch |
| 1484 |
*/ |
| 1485 |
extern (C++) final class Catch : RootObject |
| 1486 |
{ |
| 1487 |
const Loc loc; |
| 1488 |
Type type; |
| 1489 |
Identifier ident; |
| 1490 |
Statement handler; |
| 1491 |
|
| 1492 |
VarDeclaration var; |
| 1493 |
bool errors; // set if semantic processing errors |
| 1494 |
|
| 1495 |
// was generated by the compiler, wasn't present in source code |
| 1496 |
bool internalCatch; |
| 1497 |
|
| 1498 |
extern (D) this(Loc loc, Type type, Identifier ident, Statement handler) @safe |
| 1499 |
{ |
| 1500 |
//printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars()); |
| 1501 |
this.loc = loc; |
| 1502 |
this.type = type; |
| 1503 |
this.ident = ident; |
| 1504 |
this.handler = handler; |
| 1505 |
} |
| 1506 |
|
| 1507 |
Catch syntaxCopy() |
| 1508 |
{ |
| 1509 |
auto c = new Catch(loc, type ? type.syntaxCopy() : getThrowable(), ident, (handler ? handler.syntaxCopy() : null)); |
| 1510 |
c.internalCatch = internalCatch; |
| 1511 |
return c; |
| 1512 |
} |
| 1513 |
} |
| 1514 |
|
| 1515 |
/*********************************************************** |
| 1516 |
* https://dlang.org/spec/statement.html#try-statement |
| 1517 |
*/ |
| 1518 |
extern (C++) final class TryFinallyStatement : Statement |
| 1519 |
{ |
| 1520 |
Statement _body; |
| 1521 |
Statement finalbody; |
| 1522 |
|
| 1523 |
Statement tryBody; /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion |
| 1524 |
bool bodyFallsThru; /// true if _body falls through to finally |
| 1525 |
|
| 1526 |
extern (D) this(Loc loc, Statement _body, Statement finalbody) @safe |
| 1527 |
{ |
| 1528 |
super(loc, STMT.TryFinally); |
| 1529 |
this._body = _body; |
| 1530 |
this.finalbody = finalbody; |
| 1531 |
this.bodyFallsThru = true; // assume true until statementSemantic() |
| 1532 |
} |
| 1533 |
|
| 1534 |
static TryFinallyStatement create(Loc loc, Statement _body, Statement finalbody) @safe |
| 1535 |
{ |
| 1536 |
return new TryFinallyStatement(loc, _body, finalbody); |
| 1537 |
} |
| 1538 |
|
| 1539 |
override TryFinallyStatement syntaxCopy() |
| 1540 |
{ |
| 1541 |
return new TryFinallyStatement(loc, _body.syntaxCopy(), finalbody.syntaxCopy()); |
| 1542 |
} |
| 1543 |
|
| 1544 |
override bool hasBreak() const pure nothrow |
| 1545 |
{ |
| 1546 |
return false; //true; |
| 1547 |
} |
| 1548 |
|
| 1549 |
override bool hasContinue() const pure nothrow |
| 1550 |
{ |
| 1551 |
return false; //true; |
| 1552 |
} |
| 1553 |
|
| 1554 |
override void accept(Visitor v) |
| 1555 |
{ |
| 1556 |
v.visit(this); |
| 1557 |
} |
| 1558 |
} |
| 1559 |
|
| 1560 |
/*********************************************************** |
| 1561 |
* https://dlang.org/spec/statement.html#scope-guard-statement |
| 1562 |
*/ |
| 1563 |
extern (C++) final class ScopeGuardStatement : Statement |
| 1564 |
{ |
| 1565 |
TOK tok; |
| 1566 |
Statement statement; |
| 1567 |
|
| 1568 |
extern (D) this(Loc loc, TOK tok, Statement statement) @safe |
| 1569 |
{ |
| 1570 |
super(loc, STMT.ScopeGuard); |
| 1571 |
this.tok = tok; |
| 1572 |
this.statement = statement; |
| 1573 |
} |
| 1574 |
|
| 1575 |
override ScopeGuardStatement syntaxCopy() |
| 1576 |
{ |
| 1577 |
return new ScopeGuardStatement(loc, tok, statement.syntaxCopy()); |
| 1578 |
} |
| 1579 |
|
| 1580 |
override void accept(Visitor v) |
| 1581 |
{ |
| 1582 |
v.visit(this); |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
/*********************************************************** |
| 1587 |
* https://dlang.org/spec/statement.html#throw-statement |
| 1588 |
*/ |
| 1589 |
extern (C++) final class ThrowStatement : Statement |
| 1590 |
{ |
| 1591 |
Expression exp; |
| 1592 |
|
| 1593 |
// was generated by the compiler, wasn't present in source code |
| 1594 |
bool internalThrow; |
| 1595 |
|
| 1596 |
extern (D) this(Loc loc, Expression exp) @safe |
| 1597 |
{ |
| 1598 |
super(loc, STMT.Throw); |
| 1599 |
this.exp = exp; |
| 1600 |
} |
| 1601 |
|
| 1602 |
override ThrowStatement syntaxCopy() |
| 1603 |
{ |
| 1604 |
auto s = new ThrowStatement(loc, exp.syntaxCopy()); |
| 1605 |
s.internalThrow = internalThrow; |
| 1606 |
return s; |
| 1607 |
} |
| 1608 |
|
| 1609 |
override void accept(Visitor v) |
| 1610 |
{ |
| 1611 |
v.visit(this); |
| 1612 |
} |
| 1613 |
} |
| 1614 |
|
| 1615 |
/*********************************************************** |
| 1616 |
*/ |
| 1617 |
extern (C++) final class DebugStatement : Statement |
| 1618 |
{ |
| 1619 |
Statement statement; |
| 1620 |
|
| 1621 |
extern (D) this(Loc loc, Statement statement) @safe |
| 1622 |
{ |
| 1623 |
super(loc, STMT.Debug); |
| 1624 |
this.statement = statement; |
| 1625 |
} |
| 1626 |
|
| 1627 |
override DebugStatement syntaxCopy() |
| 1628 |
{ |
| 1629 |
return new DebugStatement(loc, statement ? statement.syntaxCopy() : null); |
| 1630 |
} |
| 1631 |
|
| 1632 |
override void accept(Visitor v) |
| 1633 |
{ |
| 1634 |
v.visit(this); |
| 1635 |
} |
| 1636 |
} |
| 1637 |
|
| 1638 |
/*********************************************************** |
| 1639 |
* https://dlang.org/spec/statement.html#goto-statement |
| 1640 |
*/ |
| 1641 |
extern (C++) final class GotoStatement : Statement |
| 1642 |
{ |
| 1643 |
Identifier ident; |
| 1644 |
LabelDsymbol label; |
| 1645 |
Statement tryBody; /// set to TryCatchStatement or TryFinallyStatement if in _body portion |
| 1646 |
TryFinallyStatement tf; |
| 1647 |
ScopeGuardStatement os; |
| 1648 |
VarDeclaration lastVar; |
| 1649 |
bool inCtfeBlock; /// set if goto is inside an `if (__ctfe)` block |
| 1650 |
|
| 1651 |
extern (D) this(Loc loc, Identifier ident) @safe |
| 1652 |
{ |
| 1653 |
super(loc, STMT.Goto); |
| 1654 |
this.ident = ident; |
| 1655 |
} |
| 1656 |
|
| 1657 |
override GotoStatement syntaxCopy() |
| 1658 |
{ |
| 1659 |
return new GotoStatement(loc, ident); |
| 1660 |
} |
| 1661 |
|
| 1662 |
override void accept(Visitor v) |
| 1663 |
{ |
| 1664 |
v.visit(this); |
| 1665 |
} |
| 1666 |
} |
| 1667 |
|
| 1668 |
/*********************************************************** |
| 1669 |
* https://dlang.org/spec/statement.html#LabeledStatement |
| 1670 |
*/ |
| 1671 |
extern (C++) final class LabelStatement : Statement |
| 1672 |
{ |
| 1673 |
Identifier ident; |
| 1674 |
Statement statement; |
| 1675 |
|
| 1676 |
Statement tryBody; /// set to TryCatchStatement or TryFinallyStatement if in _body portion |
| 1677 |
TryFinallyStatement tf; |
| 1678 |
ScopeGuardStatement os; |
| 1679 |
VarDeclaration lastVar; |
| 1680 |
Statement gotoTarget; // interpret |
| 1681 |
void* extra; // used by Statement_toIR() |
| 1682 |
bool breaks; // someone did a 'break ident' |
| 1683 |
bool inCtfeBlock; // inside a block dominated by `if (__ctfe)` |
| 1684 |
|
| 1685 |
extern (D) this(Loc loc, Identifier ident, Statement statement) @safe |
| 1686 |
{ |
| 1687 |
super(loc, STMT.Label); |
| 1688 |
this.ident = ident; |
| 1689 |
this.statement = statement; |
| 1690 |
} |
| 1691 |
|
| 1692 |
override LabelStatement syntaxCopy() |
| 1693 |
{ |
| 1694 |
return new LabelStatement(loc, ident, statement ? statement.syntaxCopy() : null); |
| 1695 |
} |
| 1696 |
|
| 1697 |
override void accept(Visitor v) |
| 1698 |
{ |
| 1699 |
v.visit(this); |
| 1700 |
} |
| 1701 |
} |
| 1702 |
|
| 1703 |
/*********************************************************** |
| 1704 |
*/ |
| 1705 |
extern (C++) final class LabelDsymbol : Dsymbol |
| 1706 |
{ |
| 1707 |
LabelStatement statement; |
| 1708 |
|
| 1709 |
bool deleted; // set if rewritten to return in foreach delegate |
| 1710 |
bool iasm; // set if used by inline assembler |
| 1711 |
|
| 1712 |
// set if label was defined multiple times, to avoid duplicate errors |
| 1713 |
// can be removed if generic error message deduplication is implemented |
| 1714 |
bool duplicated; |
| 1715 |
|
| 1716 |
extern (D) this(Identifier ident, Loc loc = Loc.initial) @safe |
| 1717 |
{ |
| 1718 |
super(DSYM.labelDsymbol, loc, ident); |
| 1719 |
} |
| 1720 |
|
| 1721 |
static LabelDsymbol create(Identifier ident) @safe |
| 1722 |
{ |
| 1723 |
return new LabelDsymbol(ident); |
| 1724 |
} |
| 1725 |
|
| 1726 |
// is this a LabelDsymbol()? |
| 1727 |
override LabelDsymbol isLabel() |
| 1728 |
{ |
| 1729 |
return this; |
| 1730 |
} |
| 1731 |
|
| 1732 |
override void accept(Visitor v) |
| 1733 |
{ |
| 1734 |
v.visit(this); |
| 1735 |
} |
| 1736 |
} |
| 1737 |
|
| 1738 |
/*********************************************************** |
| 1739 |
* https://dlang.org/spec/statement.html#asm |
| 1740 |
*/ |
| 1741 |
extern (C++) class AsmStatement : Statement |
| 1742 |
{ |
| 1743 |
Token* tokens; |
| 1744 |
bool caseSensitive; // for register names |
| 1745 |
|
| 1746 |
extern (D) this(Loc loc, Token* tokens) @safe |
| 1747 |
{ |
| 1748 |
super(loc, STMT.Asm); |
| 1749 |
this.tokens = tokens; |
| 1750 |
} |
| 1751 |
|
| 1752 |
extern (D) this(Loc loc, Token* tokens, STMT stmt) @safe |
| 1753 |
{ |
| 1754 |
super(loc, stmt); |
| 1755 |
this.tokens = tokens; |
| 1756 |
} |
| 1757 |
|
| 1758 |
override AsmStatement syntaxCopy() |
| 1759 |
{ |
| 1760 |
return new AsmStatement(loc, tokens); |
| 1761 |
} |
| 1762 |
|
| 1763 |
override void accept(Visitor v) |
| 1764 |
{ |
| 1765 |
v.visit(this); |
| 1766 |
} |
| 1767 |
} |
| 1768 |
|
| 1769 |
/*********************************************************** |
| 1770 |
* https://dlang.org/spec/iasm.html |
| 1771 |
*/ |
| 1772 |
extern (C++) final class InlineAsmStatement : AsmStatement |
| 1773 |
{ |
| 1774 |
void* asmcode; |
| 1775 |
uint asmalign; // alignment of this statement |
| 1776 |
uint regs; // mask of registers modified (must match regm_t in back end) |
| 1777 |
bool refparam; // true if function parameter is referenced |
| 1778 |
bool naked; // true if function is to be naked |
| 1779 |
|
| 1780 |
extern (D) this(Loc loc, Token* tokens) @safe |
| 1781 |
{ |
| 1782 |
super(loc, tokens, STMT.InlineAsm); |
| 1783 |
} |
| 1784 |
|
| 1785 |
override InlineAsmStatement syntaxCopy() |
| 1786 |
{ |
| 1787 |
return new InlineAsmStatement(loc, tokens); |
| 1788 |
} |
| 1789 |
|
| 1790 |
override void accept(Visitor v) |
| 1791 |
{ |
| 1792 |
v.visit(this); |
| 1793 |
} |
| 1794 |
} |
| 1795 |
|
| 1796 |
/*********************************************************** |
| 1797 |
* https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html |
| 1798 |
* Assembler instructions with D expression operands. |
| 1799 |
*/ |
| 1800 |
extern (C++) final class GccAsmStatement : AsmStatement |
| 1801 |
{ |
| 1802 |
STC stc; // attributes of the asm {} block |
| 1803 |
Expression insn; // string expression that is the template for assembler code |
| 1804 |
Expressions* args; // input and output operands of the statement |
| 1805 |
uint outputargs; // of the operands in 'args', the number of output operands |
| 1806 |
Identifiers* names; // list of symbolic names for the operands |
| 1807 |
Expressions* constraints; // list of string constants specifying constraints on operands |
| 1808 |
Expressions* clobbers; // list of string constants specifying clobbers and scratch registers |
| 1809 |
Identifiers* labels; // list of goto labels |
| 1810 |
GotoStatements* gotos; // of the goto labels, the equivalent statements they represent |
| 1811 |
|
| 1812 |
extern (D) this(Loc loc, Token* tokens) @safe |
| 1813 |
{ |
| 1814 |
super(loc, tokens, STMT.GccAsm); |
| 1815 |
} |
| 1816 |
|
| 1817 |
override GccAsmStatement syntaxCopy() |
| 1818 |
{ |
| 1819 |
return new GccAsmStatement(loc, tokens); |
| 1820 |
} |
| 1821 |
|
| 1822 |
override void accept(Visitor v) |
| 1823 |
{ |
| 1824 |
v.visit(this); |
| 1825 |
} |
| 1826 |
} |
| 1827 |
|
| 1828 |
/*********************************************************** |
| 1829 |
* a complete asm {} block |
| 1830 |
*/ |
| 1831 |
extern (C++) final class CompoundAsmStatement : CompoundStatement |
| 1832 |
{ |
| 1833 |
STC stc; // postfix attributes like nothrow/pure/@trusted |
| 1834 |
|
| 1835 |
extern (D) this(Loc loc, Statements* statements, STC stc) @safe |
| 1836 |
{ |
| 1837 |
super(loc, statements, STMT.CompoundAsm); |
| 1838 |
this.stc = stc; |
| 1839 |
} |
| 1840 |
|
| 1841 |
override CompoundAsmStatement syntaxCopy() |
| 1842 |
{ |
| 1843 |
return new CompoundAsmStatement(loc, Statement.arraySyntaxCopy(statements), stc); |
| 1844 |
} |
| 1845 |
|
| 1846 |
override void accept(Visitor v) |
| 1847 |
{ |
| 1848 |
v.visit(this); |
| 1849 |
} |
| 1850 |
} |
| 1851 |
|
| 1852 |
/*********************************************************** |
| 1853 |
* https://dlang.org/spec/module.html#ImportDeclaration |
| 1854 |
*/ |
| 1855 |
extern (C++) final class ImportStatement : Statement |
| 1856 |
{ |
| 1857 |
Dsymbols* imports; // Array of Import's |
| 1858 |
|
| 1859 |
extern (D) this(Loc loc, Dsymbols* imports) @safe |
| 1860 |
{ |
| 1861 |
super(loc, STMT.Import); |
| 1862 |
this.imports = imports; |
| 1863 |
} |
| 1864 |
|
| 1865 |
override ImportStatement syntaxCopy() |
| 1866 |
{ |
| 1867 |
auto m = new Dsymbols(imports.length); |
| 1868 |
foreach (i, s; *imports) |
| 1869 |
{ |
| 1870 |
(*m)[i] = s.syntaxCopy(null); |
| 1871 |
} |
| 1872 |
return new ImportStatement(loc, m); |
| 1873 |
} |
| 1874 |
|
| 1875 |
override void accept(Visitor v) |
| 1876 |
{ |
| 1877 |
v.visit(this); |
| 1878 |
} |
| 1879 |
} |
| 1880 |
|
| 1881 |
|
| 1882 |
mixin template VisitStatement(Result) |
| 1883 |
{ |
| 1884 |
Result VisitStatement(Statement s) |
| 1885 |
{ |
| 1886 |
final switch (s.stmt) |
| 1887 |
{ |
| 1888 |
case STMT.Error: mixin(visitStmtCase("Error")); |
| 1889 |
case STMT.Scope: mixin(visitStmtCase("Scope")); |
| 1890 |
case STMT.Exp: mixin(visitStmtCase("Exp")); |
| 1891 |
case STMT.Compound: mixin(visitStmtCase("Compound")); |
| 1892 |
case STMT.Return: mixin(visitStmtCase("Return")); |
| 1893 |
case STMT.If: mixin(visitStmtCase("If")); |
| 1894 |
case STMT.Conditional: mixin(visitStmtCase("Conditional")); |
| 1895 |
case STMT.StaticForeach: mixin(visitStmtCase("StaticForeach")); |
| 1896 |
case STMT.Case: mixin(visitStmtCase("Case")); |
| 1897 |
case STMT.Default: mixin(visitStmtCase("Default")); |
| 1898 |
case STMT.Label: mixin(visitStmtCase("Label")); |
| 1899 |
case STMT.Goto: mixin(visitStmtCase("Goto")); |
| 1900 |
case STMT.GotoDefault: mixin(visitStmtCase("GotoDefault")); |
| 1901 |
case STMT.GotoCase: mixin(visitStmtCase("GotoCase")); |
| 1902 |
case STMT.Break: mixin(visitStmtCase("Break")); |
| 1903 |
case STMT.DtorExp: mixin(visitStmtCase("DtorExp")); |
| 1904 |
case STMT.Mixin: mixin(visitStmtCase("Mixin")); |
| 1905 |
case STMT.Forwarding: mixin(visitStmtCase("Forwarding")); |
| 1906 |
case STMT.Do: mixin(visitStmtCase("Do")); |
| 1907 |
case STMT.While: mixin(visitStmtCase("While")); |
| 1908 |
case STMT.For: mixin(visitStmtCase("For")); |
| 1909 |
case STMT.Foreach: mixin(visitStmtCase("Foreach")); |
| 1910 |
case STMT.Switch: mixin(visitStmtCase("Switch")); |
| 1911 |
case STMT.Continue: mixin(visitStmtCase("Continue")); |
| 1912 |
case STMT.With: mixin(visitStmtCase("With")); |
| 1913 |
case STMT.TryCatch: mixin(visitStmtCase("TryCatch")); |
| 1914 |
case STMT.Throw: mixin(visitStmtCase("Throw")); |
| 1915 |
case STMT.Debug: mixin(visitStmtCase("Debug")); |
| 1916 |
case STMT.TryFinally: mixin(visitStmtCase("TryFinally")); |
| 1917 |
case STMT.ScopeGuard: mixin(visitStmtCase("ScopeGuard")); |
| 1918 |
case STMT.SwitchError: mixin(visitStmtCase("SwitchError")); |
| 1919 |
case STMT.UnrolledLoop: mixin(visitStmtCase("UnrolledLoop")); |
| 1920 |
case STMT.ForeachRange: mixin(visitStmtCase("ForeachRange")); |
| 1921 |
case STMT.CompoundDeclaration: mixin(visitStmtCase("CompoundDeclaration")); |
| 1922 |
case STMT.Peel: mixin(visitStmtCase("Peel")); |
| 1923 |
case STMT.CompoundAsm: mixin(visitStmtCase("CompoundAsm")); |
| 1924 |
case STMT.Pragma: mixin(visitStmtCase("Pragma")); |
| 1925 |
case STMT.StaticAssert: mixin(visitStmtCase("StaticAssert")); |
| 1926 |
case STMT.CaseRange: mixin(visitStmtCase("CaseRange")); |
| 1927 |
case STMT.Synchronized: mixin(visitStmtCase("Synchronized")); |
| 1928 |
case STMT.Asm: mixin(visitStmtCase("Asm")); |
| 1929 |
case STMT.InlineAsm: mixin(visitStmtCase("InlineAsm")); |
| 1930 |
case STMT.GccAsm: mixin(visitStmtCase("GccAsm")); |
| 1931 |
case STMT.Import: mixin(visitStmtCase("Import")); |
| 1932 |
} |
| 1933 |
} |
| 1934 |
} |
| 1935 |
|
| 1936 |
/**************************************** |
| 1937 |
* CTFE-only helper function for VisitInitializer. |
| 1938 |
* Params: |
| 1939 |
* handler = string for the name of the visit handler |
| 1940 |
* Returns: boilerplate code for a case |
| 1941 |
*/ |
| 1942 |
pure string visitStmtCase(string handler) @safe |
| 1943 |
{ |
| 1944 |
if (__ctfe) |
| 1945 |
{ |
| 1946 |
return |
| 1947 |
" |
| 1948 |
enum isVoid = is(Result == void); |
| 1949 |
auto sx = s.is"~handler~"Statement(); |
| 1950 |
static if (__traits(compiles, visit"~handler~"(sx))) |
| 1951 |
{ |
| 1952 |
static if (isVoid) |
| 1953 |
{ |
| 1954 |
visit"~handler~"(sx); |
| 1955 |
return; |
| 1956 |
} |
| 1957 |
else |
| 1958 |
{ |
| 1959 |
if (Result r = visit"~handler~"(sx)) |
| 1960 |
return r; |
| 1961 |
return Result.init; |
| 1962 |
} |
| 1963 |
} |
| 1964 |
else static if (__traits(compiles, visitDefaultCase(s))) |
| 1965 |
{ |
| 1966 |
static if (isVoid) |
| 1967 |
{ |
| 1968 |
visitDefaultCase(sx); |
| 1969 |
return; |
| 1970 |
} |
| 1971 |
else |
| 1972 |
{ |
| 1973 |
if (Result r = visitDefaultCase(s)) |
| 1974 |
return r; |
| 1975 |
return Result.init; |
| 1976 |
} |
| 1977 |
} |
| 1978 |
else |
| 1979 |
static assert(0, "~handler~"); |
| 1980 |
"; |
| 1981 |
} |
| 1982 |
assert(0); |
| 1983 |
} |