fixes a bug that kept sugar.collect from working with for loop macros [backport]
This commit is contained in:
parent
fd5aa89304
commit
a7b4b2ed54
1 changed files with 11 additions and 10 deletions
|
|
@ -784,7 +784,8 @@ proc isTrivalStmtExpr(n: PNode): bool =
|
||||||
return false
|
return false
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc handleStmtMacro(c: PContext; n, selector: PNode; magicType: string): PNode =
|
proc handleStmtMacro(c: PContext; n, selector: PNode; magicType: string;
|
||||||
|
flags: TExprFlags): PNode =
|
||||||
if selector.kind in nkCallKinds:
|
if selector.kind in nkCallKinds:
|
||||||
# we transform
|
# we transform
|
||||||
# n := for a, b, c in m(x, y, z): Y
|
# n := for a, b, c in m(x, y, z): Y
|
||||||
|
|
@ -813,14 +814,14 @@ proc handleStmtMacro(c: PContext; n, selector: PNode; magicType: string): PNode
|
||||||
callExpr.add newSymNode(match)
|
callExpr.add newSymNode(match)
|
||||||
callExpr.add n
|
callExpr.add n
|
||||||
case match.kind
|
case match.kind
|
||||||
of skMacro: result = semMacroExpr(c, callExpr, callExpr, match, {})
|
of skMacro: result = semMacroExpr(c, callExpr, callExpr, match, flags)
|
||||||
of skTemplate: result = semTemplateExpr(c, callExpr, match, {})
|
of skTemplate: result = semTemplateExpr(c, callExpr, match, flags)
|
||||||
else: result = nil
|
else: result = nil
|
||||||
|
|
||||||
proc handleForLoopMacro(c: PContext; n: PNode): PNode =
|
proc handleForLoopMacro(c: PContext; n: PNode; flags: TExprFlags): PNode =
|
||||||
result = handleStmtMacro(c, n, n[^2], "ForLoopStmt")
|
result = handleStmtMacro(c, n, n[^2], "ForLoopStmt", flags)
|
||||||
|
|
||||||
proc handleCaseStmtMacro(c: PContext; n: PNode): PNode =
|
proc handleCaseStmtMacro(c: PContext; n: PNode; flags: TExprFlags): PNode =
|
||||||
# n[0] has been sem'checked and has a type. We use this to resolve
|
# n[0] has been sem'checked and has a type. We use this to resolve
|
||||||
# 'match(n[0])' but then we pass 'n' to the 'match' macro. This seems to
|
# 'match(n[0])' but then we pass 'n' to the 'match' macro. This seems to
|
||||||
# be the best solution.
|
# be the best solution.
|
||||||
|
|
@ -840,8 +841,8 @@ proc handleCaseStmtMacro(c: PContext; n: PNode): PNode =
|
||||||
r.call[1] = n
|
r.call[1] = n
|
||||||
let toExpand = semResolvedCall(c, r, r.call, {})
|
let toExpand = semResolvedCall(c, r, r.call, {})
|
||||||
case match.kind
|
case match.kind
|
||||||
of skMacro: result = semMacroExpr(c, toExpand, toExpand, match, {})
|
of skMacro: result = semMacroExpr(c, toExpand, toExpand, match, flags)
|
||||||
of skTemplate: result = semTemplateExpr(c, toExpand, match, {})
|
of skTemplate: result = semTemplateExpr(c, toExpand, match, flags)
|
||||||
else: result = nil
|
else: result = nil
|
||||||
# this would be the perfectly consistent solution with 'for loop macros',
|
# this would be the perfectly consistent solution with 'for loop macros',
|
||||||
# but it kinda sucks for pattern matching as the matcher is not attached to
|
# but it kinda sucks for pattern matching as the matcher is not attached to
|
||||||
|
|
@ -852,7 +853,7 @@ proc handleCaseStmtMacro(c: PContext; n: PNode): PNode =
|
||||||
proc semFor(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
proc semFor(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||||
checkMinSonsLen(n, 3, c.config)
|
checkMinSonsLen(n, 3, c.config)
|
||||||
if forLoopMacros in c.features:
|
if forLoopMacros in c.features:
|
||||||
result = handleForLoopMacro(c, n)
|
result = handleForLoopMacro(c, n, flags)
|
||||||
if result != nil: return result
|
if result != nil: return result
|
||||||
openScope(c)
|
openScope(c)
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -914,7 +915,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||||
popCaseContext(c)
|
popCaseContext(c)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
if caseStmtMacros in c.features:
|
if caseStmtMacros in c.features:
|
||||||
result = handleCaseStmtMacro(c, n)
|
result = handleCaseStmtMacro(c, n, flags)
|
||||||
if result != nil:
|
if result != nil:
|
||||||
return result
|
return result
|
||||||
localError(c.config, n[0].info, errSelectorMustBeOfCertainTypes)
|
localError(c.config, n[0].info, errSelectorMustBeOfCertainTypes)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue