summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/closureiters.nim31
1 files changed, 13 insertions, 18 deletions
diff --git a/compiler/closureiters.nim b/compiler/closureiters.nim
index 86b63e34b..75f0b92f6 100644
--- a/compiler/closureiters.nim
+++ b/compiler/closureiters.nim
@@ -155,6 +155,10 @@ type
     nearestFinally: int # Index of the nearest finally block. For try/except it
                     # is their finally. For finally it is parent finally. Otherwise -1
 
+const
+  nkSkip = { nkEmpty..nkNilLit, nkTemplateDef, nkTypeSection, nkStaticStmt,
+            nkCommentStmt } + procDefs
+
 proc newStateAccess(ctx: var Ctx): PNode =
   if ctx.stateVarSym.isNil:
     result = rawIndirectAccess(newSymNode(getEnvParam(ctx.fn)),
@@ -247,8 +251,7 @@ proc hasYields(n: PNode): bool =
   case n.kind
   of nkYieldStmt:
     result = true
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
   else:
     for c in n:
@@ -259,8 +262,7 @@ proc hasYields(n: PNode): bool =
 proc transformBreaksAndContinuesInWhile(ctx: var Ctx, n: PNode, before, after: PNode): PNode =
   result = n
   case n.kind
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
   of nkWhileStmt: discard # Do not recurse into nested whiles
   of nkContinueStmt:
@@ -279,8 +281,7 @@ proc transformBreaksAndContinuesInWhile(ctx: var Ctx, n: PNode, before, after: P
 proc transformBreaksInBlock(ctx: var Ctx, n: PNode, label, after: PNode): PNode =
   result = n
   case n.kind
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
   of nkBlockStmt, nkWhileStmt:
     inc ctx.blockLevel
@@ -380,8 +381,7 @@ proc getFinallyNode(n: PNode): PNode =
 
 proc hasYieldsInExpressions(n: PNode): bool =
   case n.kind
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
   of nkStmtListExpr:
     if isEmptyType(n.typ):
@@ -433,8 +433,7 @@ proc newNotCall(g: ModuleGraph; e: PNode): PNode =
 proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
   result = n
   case n.kind
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
 
   of nkYieldStmt:
@@ -797,8 +796,7 @@ proc transformReturnsInTry(ctx: var Ctx, n: PNode): PNode =
     let goto = newTree(nkGotoState, ctx.g.newIntLit(n.info, ctx.nearestFinally))
     result.add(goto)
 
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
   else:
     for i in 0 ..< n.len:
@@ -807,8 +805,7 @@ proc transformReturnsInTry(ctx: var Ctx, n: PNode): PNode =
 proc transformClosureIteratorBody(ctx: var Ctx, n: PNode, gotoOut: PNode): PNode =
   result = n
   case n.kind:
-    of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-        nkSym, nkIdent, procDefs, nkTemplateDef:
+    of nkSkip:
       discard
 
     of nkStmtList, nkStmtListExpr:
@@ -1013,8 +1010,7 @@ proc tranformStateAssignments(ctx: var Ctx, n: PNode): PNode =
       for i in 0 ..< n.len:
         n[i] = ctx.tranformStateAssignments(n[i])
 
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
 
   of nkReturnStmt:
@@ -1066,8 +1062,7 @@ proc skipEmptyStates(ctx: Ctx, stateIdx: int): int =
 proc skipThroughEmptyStates(ctx: var Ctx, n: PNode): PNode =
   result = n
   case n.kind
-  of nkCharLit..nkUInt64Lit, nkFloatLit..nkFloat128Lit, nkStrLit..nkTripleStrLit,
-      nkSym, nkIdent, procDefs, nkTemplateDef:
+  of nkSkip:
     discard
   of nkGotoState:
     result = copyTree(n)
57 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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421