From 5de900b45694cf52c1b00fd2ac7fd743308e814c Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 29 Nov 2015 14:58:06 +0100 Subject: [PATCH] added iterToProc plugin --- compiler/plugins.nim | 13 ++++++++----- compiler/plugins/active.nim | 2 +- compiler/semexprs.nim | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler/plugins.nim b/compiler/plugins.nim index 1c9b7b77b8..ff31ab4205 100644 --- a/compiler/plugins.nim +++ b/compiler/plugins.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -## Plugin support for the Nim compiler. Right now there are no plugins and they +## Plugin support for the Nim compiler. Right now they ## need to be build with the compiler, no DLL support. import ast, semdata, idents @@ -20,13 +20,16 @@ type next: Plugin proc pluginMatches(p: Plugin; s: PSym): bool = - if s.name.id != p.fn.id: return false - let module = s.owner + if s.name.id != p.fn.id: + return false + let module = s.owner.skipGenericOwner if module == nil or module.kind != skModule or - module.name.id != p.module.id: return false + module.name.id != p.module.id: + return false let package = module.owner if package == nil or package.kind != skPackage or - package.name.id != p.package.id: return false + package.name.id != p.package.id: + return false return true var head: Plugin diff --git a/compiler/plugins/active.nim b/compiler/plugins/active.nim index e9c11c2ea7..7b6411178c 100644 --- a/compiler/plugins/active.nim +++ b/compiler/plugins/active.nim @@ -10,4 +10,4 @@ ## Include file that imports all plugins that are active. import - locals.locals + locals.locals, itersgen diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 58c42d410e..2d8d0e6219 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1780,7 +1780,24 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode = result = setMs(n, s) result.sons[1] = semExpr(c, n.sons[1]) result.typ = n[1].typ - else: result = semDirectOp(c, n, flags) + of mPlugin: + # semDirectOp with conditional 'afterCallActions': + let nOrig = n.copyTree + #semLazyOpAux(c, n) + result = semOverloadedCallAnalyseEffects(c, n, nOrig, flags) + if result == nil: + result = errorNode(c, n) + else: + let callee = result.sons[0].sym + if callee.magic == mNone: + semFinishOperands(c, result) + activate(c, result) + fixAbstractType(c, result) + analyseIfAddressTakenInCall(c, result) + if callee.magic != mNone: + result = magicsAfterOverloadResolution(c, result, flags) + else: + result = semDirectOp(c, n, flags) proc semWhen(c: PContext, n: PNode, semCheck = true): PNode = # If semCheck is set to false, ``when`` will return the verbatim AST of