diff options
Diffstat (limited to 'compiler/semdestruct.nim')
-rw-r--r-- | compiler/semdestruct.nim | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/compiler/semdestruct.nim b/compiler/semdestruct.nim index b09404b39..4b61c6316 100644 --- a/compiler/semdestruct.nim +++ b/compiler/semdestruct.nim @@ -30,7 +30,7 @@ proc instantiateDestructor(c: PContext, typ: PType): PType proc doDestructorStuff(c: PContext, s: PSym, n: PNode) = var t = s.typ.sons[1].skipTypes({tyVar}) if t.kind == tyGenericInvocation: - for i in 1 .. <t.sonsLen: + for i in 1 ..< t.sonsLen: if t.sons[i].kind != tyGenericParam: localError(n.info, errDestructorNotGenericEnough) return @@ -184,62 +184,3 @@ proc createDestructorCall(c: PContext, s: PSym): PNode = useSym(destructableT.destructor, c.graph.usageSym), useSym(s, c.graph.usageSym)])) result = newNode(nkDefer, s.info, @[call]) - -proc insertDestructors(c: PContext, - varSection: PNode): tuple[outer, inner: PNode] = - # Accepts a var or let section. - # - # When a var section has variables with destructors - # the var section is split up and finally blocks are inserted - # immediately after all "destructable" vars - # - # In case there were no destrucable variables, the proc returns - # (nil, nil) and the enclosing stmt-list requires no modifications. - # - # Otherwise, after the try blocks are created, the rest of the enclosing - # stmt-list should be inserted in the most `inner` such block (corresponding - # to the last variable). - # - # `outer` is a statement list that should replace the original var section. - # It will include the new truncated var section followed by the outermost - # try block. - let totalVars = varSection.sonsLen - for j in countup(0, totalVars - 1): - let - varId = varSection[j][0] - varTyp = varId.sym.typ - info = varId.info - - if varTyp == nil or sfGlobal in varId.sym.flags: continue - let destructableT = instantiateDestructor(c, varTyp) - - if destructableT != nil: - var tryStmt = newNodeI(nkTryStmt, info) - - if j < totalVars - 1: - var remainingVars = newNodeI(varSection.kind, info) - remainingVars.sons = varSection.sons[(j+1)..varSection.len-1] - let (outer, inner) = insertDestructors(c, remainingVars) - if outer != nil: - tryStmt.addSon(outer) - result.inner = inner - else: - result.inner = newNodeI(nkStmtList, info) - result.inner.addSon(remainingVars) - tryStmt.addSon(result.inner) - else: - result.inner = newNodeI(nkStmtList, info) - tryStmt.addSon(result.inner) - - tryStmt.addSon( - newNode(nkFinally, info, @[ - semStmt(c, newNode(nkCall, info, @[ - useSym(destructableT.destructor, c.graph.usageSym), - useSym(varId.sym, c.graph.usageSym)]))])) - - result.outer = newNodeI(nkStmtList, info) - varSection.sons.setLen(j+1) - result.outer.addSon(varSection) - result.outer.addSon(tryStmt) - - return |