sigmatch compiles again
This commit is contained in:
parent
efc2ce1b7e
commit
84bc04ba32
3 changed files with 63 additions and 61 deletions
|
|
@ -385,7 +385,7 @@ errXhasSideEffects: "'$1' can have side effects",
|
||||||
errIteratorExpected: "iterator within for loop context expected",
|
errIteratorExpected: "iterator within for loop context expected",
|
||||||
errLetNeedsInit: "'let' symbol requires an initialization",
|
errLetNeedsInit: "'let' symbol requires an initialization",
|
||||||
errThreadvarCannotInit: "a thread var cannot be initialized explicitly; this would only run for the main thread",
|
errThreadvarCannotInit: "a thread var cannot be initialized explicitly; this would only run for the main thread",
|
||||||
errWrongSymbolX: "usage of '$1' is a user-defined error",
|
errWrongSymbolX:,
|
||||||
errIllegalCaptureX: "illegal capture '$1'",
|
errIllegalCaptureX: "illegal capture '$1'",
|
||||||
errXCannotBeClosure: "'$1' cannot have 'closure' calling convention",
|
errXCannotBeClosure: "'$1' cannot have 'closure' calling convention",
|
||||||
errXMustBeCompileTime: "'$1' can only be used in compile-time context",
|
errXMustBeCompileTime: "'$1' can only be used in compile-time context",
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ type
|
||||||
const
|
const
|
||||||
isNilConversion = isConvertible # maybe 'isIntConv' fits better?
|
isNilConversion = isConvertible # maybe 'isIntConv' fits better?
|
||||||
|
|
||||||
proc markUsed*(info: TLineInfo, s: PSym; usageSym: var PSym)
|
proc markUsed*(conf: ConfigRef; info: TLineInfo, s: PSym; usageSym: var PSym)
|
||||||
|
|
||||||
template hasFauxMatch*(c: TCandidate): bool = c.fauxMatch != tyNone
|
template hasFauxMatch*(c: TCandidate): bool = c.fauxMatch != tyNone
|
||||||
|
|
||||||
|
|
@ -152,7 +152,7 @@ proc initCandidate*(ctx: PContext, c: var TCandidate, callee: PSym,
|
||||||
for i in 1..min(sonsLen(typeParams), sonsLen(binding)-1):
|
for i in 1..min(sonsLen(typeParams), sonsLen(binding)-1):
|
||||||
var formalTypeParam = typeParams.sons[i-1].typ
|
var formalTypeParam = typeParams.sons[i-1].typ
|
||||||
var bound = binding[i].typ
|
var bound = binding[i].typ
|
||||||
internalAssert bound != nil
|
if bound != nil:
|
||||||
if formalTypeParam.kind == tyTypeDesc:
|
if formalTypeParam.kind == tyTypeDesc:
|
||||||
if bound.kind != tyTypeDesc:
|
if bound.kind != tyTypeDesc:
|
||||||
bound = makeTypeDesc(ctx, bound)
|
bound = makeTypeDesc(ctx, bound)
|
||||||
|
|
@ -362,8 +362,8 @@ proc concreteType(c: TCandidate, t: PType): PType =
|
||||||
# proc sort[T](cmp: proc(a, b: T): int = cmp)
|
# proc sort[T](cmp: proc(a, b: T): int = cmp)
|
||||||
if result.kind != tyGenericParam: break
|
if result.kind != tyGenericParam: break
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
internalError("cannot resolve type: " & typeToString(t))
|
|
||||||
result = t
|
result = t
|
||||||
|
doAssert(false, "cannot resolve type: " & typeToString(t))
|
||||||
else:
|
else:
|
||||||
result = t # Note: empty is valid here
|
result = t # Note: empty is valid here
|
||||||
|
|
||||||
|
|
@ -519,8 +519,8 @@ proc recordRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
if f.n != nil and a.n != nil:
|
if f.n != nil and a.n != nil:
|
||||||
for i in countup(0, sonsLen(f.n) - 1):
|
for i in countup(0, sonsLen(f.n) - 1):
|
||||||
# check field names:
|
# check field names:
|
||||||
if f.n.sons[i].kind != nkSym: internalError(f.n.info, "recordRel")
|
if f.n.sons[i].kind != nkSym: return isNone
|
||||||
elif a.n.sons[i].kind != nkSym: internalError(a.n.info, "recordRel")
|
elif a.n.sons[i].kind != nkSym: return isNone
|
||||||
else:
|
else:
|
||||||
var x = f.n.sons[i].sym
|
var x = f.n.sons[i].sym
|
||||||
var y = a.n.sons[i].sym
|
var y = a.n.sons[i].sym
|
||||||
|
|
@ -661,7 +661,7 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
||||||
matchedConceptContext.prev = prevMatchedConcept
|
matchedConceptContext.prev = prevMatchedConcept
|
||||||
matchedConceptContext.depth = prevMatchedConcept.depth + 1
|
matchedConceptContext.depth = prevMatchedConcept.depth + 1
|
||||||
if prevMatchedConcept.depth > 4:
|
if prevMatchedConcept.depth > 4:
|
||||||
localError(body.info, $body & " too nested for type matching")
|
localError(m.c.graph.config, body.info, $body & " too nested for type matching")
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
openScope(c)
|
openScope(c)
|
||||||
|
|
@ -760,19 +760,20 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
||||||
|
|
||||||
result.n = checkedBody
|
result.n = checkedBody
|
||||||
|
|
||||||
proc shouldSkipDistinct(rules: PNode, callIdent: PIdent): bool =
|
proc shouldSkipDistinct(m: TCandidate; rules: PNode, callIdent: PIdent): bool =
|
||||||
|
# XXX This is bad as 'considerQuotedIdent' can produce an error!
|
||||||
if rules.kind == nkWith:
|
if rules.kind == nkWith:
|
||||||
for r in rules:
|
for r in rules:
|
||||||
if r.considerQuotedIdent == callIdent: return true
|
if considerQuotedIdent(m.c.graph.config, r) == callIdent: return true
|
||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
for r in rules:
|
for r in rules:
|
||||||
if r.considerQuotedIdent == callIdent: return false
|
if considerQuotedIdent(m.c.graph.config, r) == callIdent: return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc maybeSkipDistinct(t: PType, callee: PSym): PType =
|
proc maybeSkipDistinct(m: TCandidate; t: PType, callee: PSym): PType =
|
||||||
if t != nil and t.kind == tyDistinct and t.n != nil and
|
if t != nil and t.kind == tyDistinct and t.n != nil and
|
||||||
shouldSkipDistinct(t.n, callee.name):
|
shouldSkipDistinct(m, t.n, callee.name):
|
||||||
result = t.base
|
result = t.base
|
||||||
else:
|
else:
|
||||||
result = t
|
result = t
|
||||||
|
|
@ -868,11 +869,11 @@ proc inferStaticParam*(c: var TCandidate, lhs: PNode, rhs: BiggestInt): bool =
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc failureToInferStaticParam(n: PNode) =
|
proc failureToInferStaticParam(conf: ConfigRef; n: PNode) =
|
||||||
let staticParam = n.findUnresolvedStatic
|
let staticParam = n.findUnresolvedStatic
|
||||||
let name = if staticParam != nil: staticParam.sym.name.s
|
let name = if staticParam != nil: staticParam.sym.name.s
|
||||||
else: "unknown"
|
else: "unknown"
|
||||||
localError(n.info, errCannotInferStaticParam, name)
|
localError(conf, n.info, "cannot infer the value of the static param '" & name & "'")
|
||||||
|
|
||||||
proc inferStaticsInRange(c: var TCandidate,
|
proc inferStaticsInRange(c: var TCandidate,
|
||||||
inferred, concrete: PType): TTypeRelation =
|
inferred, concrete: PType): TTypeRelation =
|
||||||
|
|
@ -886,7 +887,7 @@ proc inferStaticsInRange(c: var TCandidate,
|
||||||
if inferStaticParam(c, exp, rhs):
|
if inferStaticParam(c, exp, rhs):
|
||||||
return isGeneric
|
return isGeneric
|
||||||
else:
|
else:
|
||||||
failureToInferStaticParam exp
|
failureToInferStaticParam(c.c.graph.config, exp)
|
||||||
|
|
||||||
if lowerBound.kind == nkIntLit:
|
if lowerBound.kind == nkIntLit:
|
||||||
if upperBound.kind == nkIntLit:
|
if upperBound.kind == nkIntLit:
|
||||||
|
|
@ -999,7 +1000,8 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
of tyStatic:
|
of tyStatic:
|
||||||
candidate = computedType
|
candidate = computedType
|
||||||
else:
|
else:
|
||||||
localError(f.n.info, errTypeExpected)
|
# XXX What is this non-sense? Error reporting in signature matching?
|
||||||
|
discard "localError(f.n.info, errTypeExpected)"
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
@ -1013,7 +1015,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
template doBind: bool = trDontBind notin flags
|
template doBind: bool = trDontBind notin flags
|
||||||
|
|
||||||
# var and static arguments match regular modifier-free types
|
# var and static arguments match regular modifier-free types
|
||||||
var a = aOrig.skipTypes({tyStatic, tyVar, tyLent}).maybeSkipDistinct(c.calleeSym)
|
var a = maybeSkipDistinct(c, aOrig.skipTypes({tyStatic, tyVar, tyLent}), c.calleeSym)
|
||||||
# XXX: Theoretically, maybeSkipDistinct could be called before we even
|
# XXX: Theoretically, maybeSkipDistinct could be called before we even
|
||||||
# start the param matching process. This could be done in `prepareOperand`
|
# start the param matching process. This could be done in `prepareOperand`
|
||||||
# for example, but unfortunately `prepareOperand` is not called in certain
|
# for example, but unfortunately `prepareOperand` is not called in certain
|
||||||
|
|
@ -1442,7 +1444,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
(sonsLen(x) - 1 == sonsLen(f)):
|
(sonsLen(x) - 1 == sonsLen(f)):
|
||||||
for i in countup(1, sonsLen(f) - 1):
|
for i in countup(1, sonsLen(f) - 1):
|
||||||
if x.sons[i].kind == tyGenericParam:
|
if x.sons[i].kind == tyGenericParam:
|
||||||
internalError("wrong instantiated type!")
|
internalError(c.c.graph.config, "wrong instantiated type!")
|
||||||
elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype:
|
elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype:
|
||||||
# Workaround for regression #4589
|
# Workaround for regression #4589
|
||||||
if f.sons[i].kind != tyTypeDesc: return
|
if f.sons[i].kind != tyTypeDesc: return
|
||||||
|
|
@ -1474,7 +1476,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
if x == nil:
|
if x == nil:
|
||||||
discard "maybe fine (for eg. a==tyNil)"
|
discard "maybe fine (for eg. a==tyNil)"
|
||||||
elif x.kind in {tyGenericInvocation, tyGenericParam}:
|
elif x.kind in {tyGenericInvocation, tyGenericParam}:
|
||||||
internalError("wrong instantiated type!")
|
internalError(c.c.graph.config, "wrong instantiated type!")
|
||||||
else:
|
else:
|
||||||
put(c, f.sons[i], x)
|
put(c, f.sons[i], x)
|
||||||
|
|
||||||
|
|
@ -1597,7 +1599,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
if f.sonsLen == 0:
|
if f.sonsLen == 0:
|
||||||
result = isGeneric
|
result = isGeneric
|
||||||
else:
|
else:
|
||||||
internalAssert a.sons != nil and a.sons.len > 0
|
internalAssert c.c.graph.config, a.sons != nil and a.sons.len > 0
|
||||||
c.typedescMatched = true
|
c.typedescMatched = true
|
||||||
var aa = a
|
var aa = a
|
||||||
while aa.kind in {tyTypeDesc, tyGenericParam} and aa.len > 0:
|
while aa.kind in {tyTypeDesc, tyGenericParam} and aa.len > 0:
|
||||||
|
|
@ -1739,13 +1741,13 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
if not exprStructuralEquivalent(aOrig.n, reevaluated.typ.n):
|
if not exprStructuralEquivalent(aOrig.n, reevaluated.typ.n):
|
||||||
result = isNone
|
result = isNone
|
||||||
else:
|
else:
|
||||||
localError(f.n.info, errTypeExpected)
|
localError(c.c.graph.config, f.n.info, "type expected")
|
||||||
result = isNone
|
result = isNone
|
||||||
|
|
||||||
of tyNone:
|
of tyNone:
|
||||||
if a.kind == tyNone: result = isEqual
|
if a.kind == tyNone: result = isEqual
|
||||||
else:
|
else:
|
||||||
internalError " unknown type kind " & $f.kind
|
internalError c.c.graph.config, " unknown type kind " & $f.kind
|
||||||
|
|
||||||
proc cmpTypes*(c: PContext, f, a: PType): TTypeRelation =
|
proc cmpTypes*(c: PContext, f, a: PType): TTypeRelation =
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
|
|
@ -1758,7 +1760,7 @@ proc getInstantiatedType(c: PContext, arg: PNode, m: TCandidate,
|
||||||
if result == nil:
|
if result == nil:
|
||||||
result = generateTypeInstance(c, m.bindings, arg, f)
|
result = generateTypeInstance(c, m.bindings, arg, f)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
internalError(arg.info, "getInstantiatedType")
|
internalError(c.graph.config, arg.info, "getInstantiatedType")
|
||||||
result = errorType(c)
|
result = errorType(c)
|
||||||
|
|
||||||
proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate,
|
proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate,
|
||||||
|
|
@ -1771,7 +1773,7 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate,
|
||||||
result.typ = errorType(c)
|
result.typ = errorType(c)
|
||||||
else:
|
else:
|
||||||
result.typ = f
|
result.typ = f
|
||||||
if result.typ == nil: internalError(arg.info, "implicitConv")
|
if result.typ == nil: internalError(c.graph.config, arg.info, "implicitConv")
|
||||||
addSon(result, ast.emptyNode)
|
addSon(result, ast.emptyNode)
|
||||||
addSon(result, arg)
|
addSon(result, arg)
|
||||||
|
|
||||||
|
|
@ -1792,7 +1794,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
|
||||||
dest = generateTypeInstance(c, m.bindings, arg, dest)
|
dest = generateTypeInstance(c, m.bindings, arg, dest)
|
||||||
let fdest = typeRel(m, f, dest)
|
let fdest = typeRel(m, f, dest)
|
||||||
if fdest in {isEqual, isGeneric}:
|
if fdest in {isEqual, isGeneric}:
|
||||||
markUsed(arg.info, c.converters[i], c.graph.usageSym)
|
markUsed(c.config, arg.info, c.converters[i], c.graph.usageSym)
|
||||||
var s = newSymNode(c.converters[i])
|
var s = newSymNode(c.converters[i])
|
||||||
s.typ = c.converters[i].typ
|
s.typ = c.converters[i].typ
|
||||||
s.info = arg.info
|
s.info = arg.info
|
||||||
|
|
@ -2066,7 +2068,7 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
|
||||||
result = nil
|
result = nil
|
||||||
elif y.state == csMatch and cmpCandidates(x, y) == 0:
|
elif y.state == csMatch and cmpCandidates(x, y) == 0:
|
||||||
if x.state != csMatch:
|
if x.state != csMatch:
|
||||||
internalError(arg.info, "x.state is not csMatch")
|
internalError(m.c.graph.config, arg.info, "x.state is not csMatch")
|
||||||
# ambiguous: more than one symbol fits!
|
# ambiguous: more than one symbol fits!
|
||||||
# See tsymchoice_for_expr as an example. 'f.kind == tyExpr' should match
|
# See tsymchoice_for_expr as an example. 'f.kind == tyExpr' should match
|
||||||
# anyway:
|
# anyway:
|
||||||
|
|
@ -2074,12 +2076,11 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
|
||||||
else: result = nil
|
else: result = nil
|
||||||
else:
|
else:
|
||||||
# only one valid interpretation found:
|
# only one valid interpretation found:
|
||||||
markUsed(arg.info, arg.sons[best].sym, m.c.graph.usageSym)
|
markUsed(m.c.config, arg.info, arg.sons[best].sym, m.c.graph.usageSym)
|
||||||
styleCheckUse(arg.info, arg.sons[best].sym)
|
styleCheckUse(arg.info, arg.sons[best].sym)
|
||||||
result = paramTypesMatchAux(m, f, arg.sons[best].typ, arg.sons[best],
|
result = paramTypesMatchAux(m, f, arg.sons[best].typ, arg.sons[best],
|
||||||
argOrig)
|
argOrig)
|
||||||
|
|
||||||
|
|
||||||
proc setSon(father: PNode, at: int, son: PNode) =
|
proc setSon(father: PNode, at: int, son: PNode) =
|
||||||
let oldLen = father.len
|
let oldLen = father.len
|
||||||
if oldLen <= at:
|
if oldLen <= at:
|
||||||
|
|
@ -2115,10 +2116,10 @@ proc prepareOperand(c: PContext; a: PNode): PNode =
|
||||||
result = a
|
result = a
|
||||||
considerGenSyms(c, result)
|
considerGenSyms(c, result)
|
||||||
|
|
||||||
proc prepareNamedParam(a: PNode) =
|
proc prepareNamedParam(a: PNode; conf: ConfigRef) =
|
||||||
if a.sons[0].kind != nkIdent:
|
if a.sons[0].kind != nkIdent:
|
||||||
var info = a.sons[0].info
|
var info = a.sons[0].info
|
||||||
a.sons[0] = newIdentNode(considerQuotedIdent(a.sons[0]), info)
|
a.sons[0] = newIdentNode(considerQuotedIdent(conf, a.sons[0]), info)
|
||||||
|
|
||||||
proc arrayConstr(c: PContext, n: PNode): PType =
|
proc arrayConstr(c: PContext, n: PNode): PType =
|
||||||
result = newTypeS(tyArray, c)
|
result = newTypeS(tyArray, c)
|
||||||
|
|
@ -2182,9 +2183,9 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
elif n.sons[a].kind == nkExprEqExpr:
|
elif n.sons[a].kind == nkExprEqExpr:
|
||||||
# named param
|
# named param
|
||||||
# check if m.callee has such a param:
|
# check if m.callee has such a param:
|
||||||
prepareNamedParam(n.sons[a])
|
prepareNamedParam(n.sons[a], c.config)
|
||||||
if n.sons[a].sons[0].kind != nkIdent:
|
if n.sons[a].sons[0].kind != nkIdent:
|
||||||
localError(n.sons[a].info, errNamedParamHasToBeIdent)
|
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
return
|
return
|
||||||
formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1)
|
formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1)
|
||||||
|
|
@ -2227,7 +2228,8 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
# we have no formal here to snoop at:
|
# we have no formal here to snoop at:
|
||||||
n.sons[a] = prepareOperand(c, n.sons[a])
|
n.sons[a] = prepareOperand(c, n.sons[a])
|
||||||
if skipTypes(n.sons[a].typ, abstractVar-{tyTypeDesc}).kind==tyString:
|
if skipTypes(n.sons[a].typ, abstractVar-{tyTypeDesc}).kind==tyString:
|
||||||
addSon(m.call, implicitConv(nkHiddenStdConv, getSysType(tyCString),
|
addSon(m.call, implicitConv(nkHiddenStdConv,
|
||||||
|
getSysType(c.graph, n.sons[a].info, tyCString),
|
||||||
copyTree(n.sons[a]), m, c))
|
copyTree(n.sons[a]), m, c))
|
||||||
else:
|
else:
|
||||||
addSon(m.call, copyTree(n.sons[a]))
|
addSon(m.call, copyTree(n.sons[a]))
|
||||||
|
|
@ -2251,7 +2253,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if m.callee.n.sons[f].kind != nkSym:
|
if m.callee.n.sons[f].kind != nkSym:
|
||||||
internalError(n.sons[a].info, "matches")
|
internalError(c.config, n.sons[a].info, "matches")
|
||||||
return
|
return
|
||||||
formal = m.callee.n.sons[f].sym
|
formal = m.callee.n.sons[f].sym
|
||||||
if containsOrIncl(marker, formal.position) and container.isNil:
|
if containsOrIncl(marker, formal.position) and container.isNil:
|
||||||
|
|
@ -2359,7 +2361,7 @@ proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo;
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
initCandidate(c, m, dc.typ)
|
initCandidate(c, m, dc.typ)
|
||||||
if col >= dc.typ.len:
|
if col >= dc.typ.len:
|
||||||
localError(info, errGenerated, "cannot instantiate '" & dc.name.s & "'")
|
localError(c.config, info, "cannot instantiate '" & dc.name.s & "'")
|
||||||
return nil
|
return nil
|
||||||
var f = dc.typ.sons[col]
|
var f = dc.typ.sons[col]
|
||||||
|
|
||||||
|
|
@ -2368,7 +2370,7 @@ proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo;
|
||||||
else:
|
else:
|
||||||
if f.kind == tyVar: f = f.lastSon
|
if f.kind == tyVar: f = f.lastSon
|
||||||
if typeRel(m, f, t) == isNone:
|
if typeRel(m, f, t) == isNone:
|
||||||
localError(info, errGenerated, "cannot instantiate '" & dc.name.s & "'")
|
localError(c.config, info, "cannot instantiate '" & dc.name.s & "'")
|
||||||
else:
|
else:
|
||||||
result = c.semGenerateInstance(c, dc, m.bindings, info)
|
result = c.semGenerateInstance(c, dc, m.bindings, info)
|
||||||
if op == attachedDeepCopy:
|
if op == attachedDeepCopy:
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
# included from sigmatch.nim
|
# included from sigmatch.nim
|
||||||
|
|
||||||
import algorithm, prefixmatches
|
import algorithm, prefixmatches, configuration
|
||||||
from wordrecg import wDeprecated
|
from wordrecg import wDeprecated
|
||||||
|
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
|
|
@ -192,8 +192,8 @@ proc suggestResult(s: Suggest) =
|
||||||
else:
|
else:
|
||||||
suggestWriteln($s)
|
suggestWriteln($s)
|
||||||
|
|
||||||
proc produceOutput(a: var Suggestions) =
|
proc produceOutput(a: var Suggestions; conf: ConfigRef) =
|
||||||
if gIdeCmd in {ideSug, ideCon}:
|
if conf.ideCmd in {ideSug, ideCon}:
|
||||||
a.sort cmpSuggestions
|
a.sort cmpSuggestions
|
||||||
when defined(debug):
|
when defined(debug):
|
||||||
# debug code
|
# debug code
|
||||||
|
|
@ -480,30 +480,30 @@ proc suggestSym*(info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.in
|
||||||
isDecl:
|
isDecl:
|
||||||
suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
|
||||||
|
|
||||||
proc warnAboutDeprecated(info: TLineInfo; s: PSym) =
|
proc warnAboutDeprecated(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
||||||
if s.kind in routineKinds:
|
if s.kind in routineKinds:
|
||||||
let n = s.ast[pragmasPos]
|
let n = s.ast[pragmasPos]
|
||||||
if n.kind != nkEmpty:
|
if n.kind != nkEmpty:
|
||||||
for it in n:
|
for it in n:
|
||||||
if whichPragma(it) == wDeprecated and it.safeLen == 2 and
|
if whichPragma(it) == wDeprecated and it.safeLen == 2 and
|
||||||
it[1].kind in {nkStrLit..nkTripleStrLit}:
|
it[1].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
message(info, warnDeprecated, it[1].strVal & "; " & s.name.s)
|
message(conf, info, warnDeprecated, it[1].strVal & "; " & s.name.s)
|
||||||
return
|
return
|
||||||
message(info, warnDeprecated, s.name.s)
|
message(conf, info, warnDeprecated, s.name.s)
|
||||||
|
|
||||||
proc markUsed(info: TLineInfo; s: PSym; usageSym: var PSym) =
|
proc markUsed(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym) =
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
if s.kind == skEnumField and s.owner != nil:
|
if s.kind == skEnumField and s.owner != nil:
|
||||||
incl(s.owner.flags, sfUsed)
|
incl(s.owner.flags, sfUsed)
|
||||||
if {sfDeprecated, sfError} * s.flags != {}:
|
if {sfDeprecated, sfError} * s.flags != {}:
|
||||||
if sfDeprecated in s.flags: warnAboutDeprecated(info, s)
|
if sfDeprecated in s.flags: warnAboutDeprecated(conf, info, s)
|
||||||
if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s)
|
if sfError in s.flags: localError(conf, info, "usage of '$1' is a user-defined error" % s.name.s)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
suggestSym(info, s, usageSym, false)
|
suggestSym(info, s, usageSym, false)
|
||||||
|
|
||||||
proc useSym*(sym: PSym; usageSym: var PSym): PNode =
|
proc useSym*(conf: ConfigRef; sym: PSym; usageSym: var PSym): PNode =
|
||||||
result = newSymNode(sym)
|
result = newSymNode(sym)
|
||||||
markUsed(result.info, sym, usageSym)
|
markUsed(conf, result.info, sym, usageSym)
|
||||||
|
|
||||||
proc safeSemExpr*(c: PContext, n: PNode): PNode =
|
proc safeSemExpr*(c: PContext, n: PNode): PNode =
|
||||||
# use only for idetools support!
|
# use only for idetools support!
|
||||||
|
|
@ -534,9 +534,9 @@ proc suggestExprNoCheck*(c: PContext, n: PNode) =
|
||||||
if c.compilesContextId > 0: return
|
if c.compilesContextId > 0: return
|
||||||
inc(c.compilesContextId)
|
inc(c.compilesContextId)
|
||||||
var outputs: Suggestions = @[]
|
var outputs: Suggestions = @[]
|
||||||
if gIdeCmd == ideSug:
|
if c.config.ideCmd == ideSug:
|
||||||
sugExpr(c, n, outputs)
|
sugExpr(c, n, outputs)
|
||||||
elif gIdeCmd == ideCon:
|
elif c.config.ideCmd == ideCon:
|
||||||
if n.kind in nkCallKinds:
|
if n.kind in nkCallKinds:
|
||||||
var a = copyNode(n)
|
var a = copyNode(n)
|
||||||
var x = safeSemExpr(c, n.sons[0])
|
var x = safeSemExpr(c, n.sons[0])
|
||||||
|
|
@ -550,8 +550,8 @@ proc suggestExprNoCheck*(c: PContext, n: PNode) =
|
||||||
suggestCall(c, a, n, outputs)
|
suggestCall(c, a, n, outputs)
|
||||||
|
|
||||||
dec(c.compilesContextId)
|
dec(c.compilesContextId)
|
||||||
if outputs.len > 0 and gIdeCmd in {ideSug, ideCon, ideDef}:
|
if outputs.len > 0 and c.config.ideCmd in {ideSug, ideCon, ideDef}:
|
||||||
produceOutput(outputs)
|
produceOutput(outputs, c.config)
|
||||||
suggestQuit()
|
suggestQuit()
|
||||||
|
|
||||||
proc suggestExpr*(c: PContext, n: PNode) =
|
proc suggestExpr*(c: PContext, n: PNode) =
|
||||||
|
|
@ -570,11 +570,11 @@ proc suggestStmt*(c: PContext, n: PNode) =
|
||||||
proc suggestEnum*(c: PContext; n: PNode; t: PType) =
|
proc suggestEnum*(c: PContext; n: PNode; t: PType) =
|
||||||
var outputs: Suggestions = @[]
|
var outputs: Suggestions = @[]
|
||||||
suggestSymList(c, t.n, nil, n.info, outputs)
|
suggestSymList(c, t.n, nil, n.info, outputs)
|
||||||
produceOutput(outputs)
|
produceOutput(outputs, c.config)
|
||||||
if outputs.len > 0: suggestQuit()
|
if outputs.len > 0: suggestQuit()
|
||||||
|
|
||||||
proc suggestSentinel*(c: PContext) =
|
proc suggestSentinel*(c: PContext) =
|
||||||
if gIdeCmd != ideSug or c.module.position != gTrackPos.fileIndex.int32: return
|
if c.config.ideCmd != ideSug or c.module.position != gTrackPos.fileIndex.int32: return
|
||||||
if c.compilesContextId > 0: return
|
if c.compilesContextId > 0: return
|
||||||
inc(c.compilesContextId)
|
inc(c.compilesContextId)
|
||||||
var outputs: Suggestions = @[]
|
var outputs: Suggestions = @[]
|
||||||
|
|
@ -590,4 +590,4 @@ proc suggestSentinel*(c: PContext) =
|
||||||
outputs.add(symToSuggest(it, isLocal = isLocal, ideSug, newLineInfo(gTrackPos.fileIndex, -1, -1), 0, PrefixMatch.None, false, scopeN))
|
outputs.add(symToSuggest(it, isLocal = isLocal, ideSug, newLineInfo(gTrackPos.fileIndex, -1, -1), 0, PrefixMatch.None, false, scopeN))
|
||||||
|
|
||||||
dec(c.compilesContextId)
|
dec(c.compilesContextId)
|
||||||
produceOutput(outputs)
|
produceOutput(outputs, c.config)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue