refactorings
This commit is contained in:
parent
e52044660d
commit
be2efa69ea
1 changed files with 55 additions and 42 deletions
|
|
@ -717,6 +717,34 @@ proc resolveIndirectCall(c: PContext; n, nOrig: PNode;
|
||||||
initCandidate(c, result, t)
|
initCandidate(c, result, t)
|
||||||
matches(c, n, nOrig, result)
|
matches(c, n, nOrig, result)
|
||||||
|
|
||||||
|
proc bracketedMacro(n: PNode): PSym =
|
||||||
|
if n.len >= 1 and n[0].kind == nkSym:
|
||||||
|
result = n[0].sym
|
||||||
|
if result.kind notin {skMacro, skTemplate}:
|
||||||
|
result = nil
|
||||||
|
|
||||||
|
proc semBracketedMacro(c: PContext; outer, inner: PNode; s: PSym;
|
||||||
|
flags: TExprFlags): PNode =
|
||||||
|
# We received untransformed bracket expression coming from macroOrTmpl[].
|
||||||
|
# Transform it to macro or template call, where first come normal
|
||||||
|
# arguments, next come generic template arguments.
|
||||||
|
var sons = newSeq[PNode]()
|
||||||
|
sons.add inner.sons[0]
|
||||||
|
# Normal arguments:
|
||||||
|
for i in 1..<outer.len:
|
||||||
|
sons.add outer.sons[i]
|
||||||
|
# Generic template arguments from bracket expression:
|
||||||
|
for i in 1..<inner.len:
|
||||||
|
sons.add inner.sons[i]
|
||||||
|
shallowCopy(outer.sons, sons)
|
||||||
|
# FIXME: Shouldn't we check sfImmediate and call semDirectOp?
|
||||||
|
# However passing to semDirectOp doesn't work here.
|
||||||
|
case s.kind
|
||||||
|
of skMacro: result = semMacroExpr(c, outer, outer, s, flags)
|
||||||
|
of skTemplate: result = semTemplateExpr(c, outer, s, flags)
|
||||||
|
else: assert(false)
|
||||||
|
return
|
||||||
|
|
||||||
proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
result = nil
|
result = nil
|
||||||
checkMinSonsLen(n, 1)
|
checkMinSonsLen(n, 1)
|
||||||
|
|
@ -737,29 +765,10 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if t != nil and t.kind == tyVar:
|
if t != nil and t.kind == tyVar:
|
||||||
n.sons[0] = newDeref(n.sons[0])
|
n.sons[0] = newDeref(n.sons[0])
|
||||||
elif n.sons[0].kind == nkBracketExpr:
|
elif n.sons[0].kind == nkBracketExpr:
|
||||||
checkMinSonsLen(n.sons[0], 2)
|
let s = bracketedMacro(n.sons[0])
|
||||||
# We received untransformed bracket expression coming from macroOrTmpl[].
|
if s != nil:
|
||||||
# Transform it to macro or template call, where first come normal
|
return semBracketedMacro(c, n, n.sons[0], s, flags)
|
||||||
# arguments, next come generic template arguments.
|
|
||||||
if n.sons[0].sons[0].kind == nkSym:
|
|
||||||
let s = n.sons[0].sons[0].sym
|
|
||||||
if s.kind in {skMacro, skTemplate}:
|
|
||||||
var sons = newSeq[PNode]()
|
|
||||||
sons.add n.sons[0].sons[0]
|
|
||||||
# Normal arguments:
|
|
||||||
for i in 1..<n.len:
|
|
||||||
sons.add n.sons[i]
|
|
||||||
# Generic template arguments from bracket expression:
|
|
||||||
for i in 1..<n.sons[0].len:
|
|
||||||
sons.add n.sons[0].sons[i]
|
|
||||||
n.sons = sons
|
|
||||||
# FIXME: Shouldn't we check sfImmediate and call semDirectOp?
|
|
||||||
# However passing to semDirectOp doesn't work here.
|
|
||||||
case s.kind
|
|
||||||
of skMacro: result = semMacroExpr(c, n, n, s, flags)
|
|
||||||
of skTemplate: result = semTemplateExpr(c, n, s, flags)
|
|
||||||
else: discard
|
|
||||||
return
|
|
||||||
let nOrig = n.copyTree
|
let nOrig = n.copyTree
|
||||||
semOpAux(c, n)
|
semOpAux(c, n)
|
||||||
var t: PType = nil
|
var t: PType = nil
|
||||||
|
|
@ -1274,26 +1283,30 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
let s = if n.sons[0].kind == nkSym: n.sons[0].sym
|
let s = if n.sons[0].kind == nkSym: n.sons[0].sym
|
||||||
elif n[0].kind in nkSymChoices: n.sons[0][0].sym
|
elif n[0].kind in nkSymChoices: n.sons[0][0].sym
|
||||||
else: nil
|
else: nil
|
||||||
if s != nil and s.kind in {skProc, skMethod, skConverter, skIterator}:
|
if s != nil:
|
||||||
# type parameters: partial generic specialization
|
case s.kind
|
||||||
n.sons[0] = semSymGenericInstantiation(c, n.sons[0], s)
|
of skProc, skMethod, skConverter, skIterator:
|
||||||
result = explicitGenericInstantiation(c, n, s)
|
# type parameters: partial generic specialization
|
||||||
elif s != nil and s.kind in {skMacro, skTemplate}:
|
n.sons[0] = semSymGenericInstantiation(c, n.sons[0], s)
|
||||||
if efInCall in flags:
|
result = explicitGenericInstantiation(c, n, s)
|
||||||
# We are processing macroOrTmpl[] in macroOrTmpl[](...) call.
|
of skMacro, skTemplate:
|
||||||
# Return as is, so it can be transformed into complete macro or
|
if efInCall in flags:
|
||||||
# template call in semIndirectOp caller.
|
# We are processing macroOrTmpl[] in macroOrTmpl[](...) call.
|
||||||
result = n
|
# Return as is, so it can be transformed into complete macro or
|
||||||
|
# template call in semIndirectOp caller.
|
||||||
|
result = n
|
||||||
|
else:
|
||||||
|
# We are processing macroOrTmpl[] not in call. Transform it to the
|
||||||
|
# macro or template call with generic arguments here.
|
||||||
|
n.kind = nkCall
|
||||||
|
case s.kind
|
||||||
|
of skMacro: result = semMacroExpr(c, n, n, s, flags)
|
||||||
|
of skTemplate: result = semTemplateExpr(c, n, s, flags)
|
||||||
|
else: discard
|
||||||
|
of skType:
|
||||||
|
result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
|
||||||
else:
|
else:
|
||||||
# We are processing macroOrTmpl[] not in call. Transform it to the
|
c.p.bracketExpr = n.sons[0]
|
||||||
# macro or template call with generic arguments here.
|
|
||||||
n.kind = nkCall
|
|
||||||
case s.kind
|
|
||||||
of skMacro: result = semMacroExpr(c, n, n, s, flags)
|
|
||||||
of skTemplate: result = semTemplateExpr(c, n, s, flags)
|
|
||||||
else: discard
|
|
||||||
elif s != nil and s.kind == skType:
|
|
||||||
result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
|
|
||||||
else:
|
else:
|
||||||
c.p.bracketExpr = n.sons[0]
|
c.p.bracketExpr = n.sons[0]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue