next steps in binding [] properly
This commit is contained in:
parent
03d8467942
commit
e01e0a4b40
4 changed files with 33 additions and 16 deletions
|
|
@ -308,7 +308,7 @@ proc semResolvedCall(c: PContext, n: PNode, x: TCandidate): PNode =
|
||||||
let gp = finalCallee.ast.sons[genericParamsPos]
|
let gp = finalCallee.ast.sons[genericParamsPos]
|
||||||
if gp.kind != nkEmpty:
|
if gp.kind != nkEmpty:
|
||||||
if x.calleeSym.kind notin {skMacro, skTemplate}:
|
if x.calleeSym.kind notin {skMacro, skTemplate}:
|
||||||
if x.calleeSym.magic == mArrPut:
|
if x.calleeSym.magic in {mArrGet, mArrPut}:
|
||||||
finalCallee = x.calleeSym
|
finalCallee = x.calleeSym
|
||||||
else:
|
else:
|
||||||
finalCallee = generateInstance(c, x.calleeSym, x.bindings, n.info)
|
finalCallee = generateInstance(c, x.calleeSym, x.bindings, n.info)
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ type
|
||||||
TExprFlag* = enum
|
TExprFlag* = enum
|
||||||
efLValue, efWantIterator, efInTypeof,
|
efLValue, efWantIterator, efInTypeof,
|
||||||
efWantStmt, efAllowStmt, efDetermineType,
|
efWantStmt, efAllowStmt, efDetermineType,
|
||||||
efAllowDestructor, efWantValue, efOperand, efNoSemCheck
|
efAllowDestructor, efWantValue, efOperand, efNoSemCheck,
|
||||||
|
efNoProcvarCheck
|
||||||
TExprFlags* = set[TExprFlag]
|
TExprFlags* = set[TExprFlag]
|
||||||
|
|
||||||
TTypeAttachedOp* = enum
|
TTypeAttachedOp* = enum
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result.typ = errorType(c)
|
result.typ = errorType(c)
|
||||||
else:
|
else:
|
||||||
# XXX tyGenericInst here?
|
# XXX tyGenericInst here?
|
||||||
semProcvarCheck(c, result)
|
if efNoProcvarCheck notin flags: semProcvarCheck(c, result)
|
||||||
if result.typ.kind == tyVar: result = newDeref(result)
|
if result.typ.kind == tyVar: result = newDeref(result)
|
||||||
semDestructorCheck(c, result, flags)
|
semDestructorCheck(c, result, flags)
|
||||||
|
|
||||||
|
|
@ -1156,7 +1156,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
result.add(x[0])
|
result.add(x[0])
|
||||||
return
|
return
|
||||||
checkMinSonsLen(n, 2)
|
checkMinSonsLen(n, 2)
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0])
|
n.sons[0] = semExprWithType(c, n.sons[0], {efNoProcvarCheck})
|
||||||
let arr = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyPtr, tyRef})
|
let arr = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyPtr, tyRef})
|
||||||
case arr.kind
|
case arr.kind
|
||||||
of tyArray, tyOpenArray, tyVarargs, tyArrayConstr, tySequence, tyString,
|
of tyArray, tyOpenArray, tyVarargs, tyArrayConstr, tySequence, tyString,
|
||||||
|
|
@ -1196,7 +1196,17 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
localError(n.info, errIndexTypesDoNotMatch)
|
localError(n.info, errIndexTypesDoNotMatch)
|
||||||
result = n
|
result = n
|
||||||
else:
|
else:
|
||||||
c.p.bracketExpr = n.sons[0]
|
let s = if n.sons[0].kind == nkSym: n.sons[0].sym
|
||||||
|
elif n[0].kind in nkSymChoices: n.sons[0][0].sym
|
||||||
|
else: nil
|
||||||
|
if s != nil and s.kind in {skProc, skMethod, skConverter}+skIterators:
|
||||||
|
# type parameters: partial generic specialization
|
||||||
|
n.sons[0] = semSymGenericInstantiation(c, n.sons[0], s)
|
||||||
|
result = explicitGenericInstantiation(c, n, s)
|
||||||
|
elif s != nil and s.kind == skType:
|
||||||
|
result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
|
||||||
|
else:
|
||||||
|
c.p.bracketExpr = n.sons[0]
|
||||||
|
|
||||||
proc semArrayAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
proc semArrayAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
let oldBracketExpr = c.p.bracketExpr
|
let oldBracketExpr = c.p.bracketExpr
|
||||||
|
|
@ -2073,6 +2083,19 @@ proc semExport(c: PContext, n: PNode): PNode =
|
||||||
c.module.ast.add x
|
c.module.ast.add x
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
|
proc shouldBeBracketExpr(n: PNode): bool =
|
||||||
|
assert n.kind in nkCallKinds
|
||||||
|
let a = n.sons[0]
|
||||||
|
if a.kind in nkCallKinds:
|
||||||
|
let b = a[0]
|
||||||
|
if b.kind in nkSymChoices:
|
||||||
|
for i in 0..<b.len:
|
||||||
|
if b[i].sym.magic == mArrGet:
|
||||||
|
let be = newNodeI(nkBracketExpr, n.info)
|
||||||
|
for i in 1..<a.len: be.add(a[i])
|
||||||
|
n.sons[0] = be
|
||||||
|
return true
|
||||||
|
|
||||||
proc setGenericParams(c: PContext, n: PNode) =
|
proc setGenericParams(c: PContext, n: PNode) =
|
||||||
for i in 1 .. <n.len:
|
for i in 1 .. <n.len:
|
||||||
n[i].typ = semTypeNode(c, n[i], nil)
|
n[i].typ = semTypeNode(c, n[i], nil)
|
||||||
|
|
@ -2180,7 +2203,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
else:
|
else:
|
||||||
#liMessage(n.info, warnUser, renderTree(n));
|
#liMessage(n.info, warnUser, renderTree(n));
|
||||||
result = semIndirectOp(c, n, flags)
|
result = semIndirectOp(c, n, flags)
|
||||||
elif n[0].kind == nkBracketExpr and isSymChoice(n[0][0]):
|
elif (n[0].kind == nkBracketExpr or shouldBeBracketExpr(n)) and
|
||||||
|
isSymChoice(n[0][0]):
|
||||||
# indirectOp can deal with explicit instantiations; the fixes
|
# indirectOp can deal with explicit instantiations; the fixes
|
||||||
# the 'newSeq[T](x)' bug
|
# the 'newSeq[T](x)' bug
|
||||||
setGenericParams(c, n.sons[0])
|
setGenericParams(c, n.sons[0])
|
||||||
|
|
@ -2201,16 +2225,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result = semExpr(c, result, flags)
|
result = semExpr(c, result, flags)
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
checkMinSonsLen(n, 1)
|
checkMinSonsLen(n, 1)
|
||||||
var s = qualifiedLookUp(c, n.sons[0], {checkUndeclared})
|
result = semArrayAccess(c, n, flags)
|
||||||
if (s != nil and s.kind in {skProc, skMethod, skConverter}+skIterators) or
|
|
||||||
n[0].kind in nkSymChoices:
|
|
||||||
# type parameters: partial generic specialization
|
|
||||||
n.sons[0] = semSymGenericInstantiation(c, n.sons[0], s)
|
|
||||||
result = explicitGenericInstantiation(c, n, s)
|
|
||||||
elif s != nil and s.kind in {skType}:
|
|
||||||
result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
|
|
||||||
else:
|
|
||||||
result = semArrayAccess(c, n, flags)
|
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
result = semExpr(c, buildOverloadedSubscripts(n, getIdent"{}"), flags)
|
result = semExpr(c, buildOverloadedSubscripts(n, getIdent"{}"), flags)
|
||||||
of nkPragmaExpr:
|
of nkPragmaExpr:
|
||||||
|
|
|
||||||
|
|
@ -1696,6 +1696,7 @@ proc partialMatch*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||||
proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
||||||
if m.calleeSym != nil and m.calleeSym.magic == mArrGet:
|
if m.calleeSym != nil and m.calleeSym.magic == mArrGet:
|
||||||
m.state = csMatch
|
m.state = csMatch
|
||||||
|
m.call = n
|
||||||
return
|
return
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
matchesAux(c, n, nOrig, m, marker)
|
matchesAux(c, n, nOrig, m, marker)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue