improvements for nimfix
This commit is contained in:
parent
569fbe8c37
commit
c5dbcb548f
9 changed files with 37 additions and 12 deletions
|
|
@ -94,18 +94,21 @@ proc checkStyle(info: TLineInfo, s: string, k: TSymKind) =
|
||||||
if s != beau:
|
if s != beau:
|
||||||
message(info, hintName, beau)
|
message(info, hintName, beau)
|
||||||
|
|
||||||
proc styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) =
|
proc styleCheckDefImpl(info: TLineInfo; s: PSym; k: TSymKind) =
|
||||||
if gStyleCheck == StyleCheck.None: return
|
|
||||||
# operators stay as they are:
|
# operators stay as they are:
|
||||||
if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters:
|
if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters: return
|
||||||
return
|
|
||||||
if k in {skType, skGenericParam} and sfAnon in s.flags: return
|
if k in {skType, skGenericParam} and sfAnon in s.flags: return
|
||||||
|
|
||||||
if {sfImportc, sfExportc} * s.flags == {} or gCheckExtern:
|
if {sfImportc, sfExportc} * s.flags == {} or gCheckExtern:
|
||||||
checkStyle(info, s.name.s, k)
|
checkStyle(info, s.name.s, k)
|
||||||
|
|
||||||
proc styleCheckDef*(info: TLineInfo; s: PSym) = styleCheckDef(info, s, s.kind)
|
template styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) =
|
||||||
proc styleCheckDef*(s: PSym) = styleCheckDef(s.info, s, s.kind)
|
when defined(nimfix):
|
||||||
|
if gStyleCheck != StyleCheck.None: styleCheckDefImpl(info, s, k)
|
||||||
|
|
||||||
|
template styleCheckDef*(info: TLineInfo; s: PSym) =
|
||||||
|
styleCheckDef(info, s, s.kind)
|
||||||
|
template styleCheckDef*(s: PSym) =
|
||||||
|
styleCheckDef(s.info, s, s.kind)
|
||||||
|
|
||||||
proc styleCheckUse*(info: TLineInfo; s: PSym) =
|
proc styleCheckUse*(info: TLineInfo; s: PSym) =
|
||||||
if info.fileIndex < 0: return
|
if info.fileIndex < 0: return
|
||||||
|
|
@ -134,3 +137,4 @@ proc styleCheckUse*(info: TLineInfo; s: PSym) =
|
||||||
var x = line.substr(0, first-1) & newName & line.substr(last+1)
|
var x = line.substr(0, first-1) & newName & line.substr(last+1)
|
||||||
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
||||||
gSourceFiles[info.fileIndex].dirty = true
|
gSourceFiles[info.fileIndex].dirty = true
|
||||||
|
if newName == "File": writeStackTrace()
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PIdent) =
|
||||||
var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
|
var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
|
||||||
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
||||||
gSourceFiles[info.fileIndex].dirty = true
|
gSourceFiles[info.fileIndex].dirty = true
|
||||||
|
if newSym.s == "File": writeStackTrace()
|
||||||
|
|
||||||
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) =
|
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) =
|
||||||
replaceDeprecated(info, oldSym.name, newSym.name)
|
replaceDeprecated(info, oldSym.name, newSym.name)
|
||||||
|
|
|
||||||
|
|
@ -311,6 +311,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
||||||
pushInfoContext(nOrig.info)
|
pushInfoContext(nOrig.info)
|
||||||
|
|
||||||
markUsed(n.info, sym)
|
markUsed(n.info, sym)
|
||||||
|
styleCheckUse(n.info, sym)
|
||||||
if sym == c.p.owner:
|
if sym == c.p.owner:
|
||||||
globalError(n.info, errRecursiveDependencyX, sym.name.s)
|
globalError(n.info, errRecursiveDependencyX, sym.name.s)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ proc considerOverloadedOp(c: TLiftCtx; t: PType; x, y: PNode): bool =
|
||||||
let op = t.attachedOps[c.kind]
|
let op = t.attachedOps[c.kind]
|
||||||
if op != nil:
|
if op != nil:
|
||||||
markUsed(c.info, op)
|
markUsed(c.info, op)
|
||||||
|
styleCheckUse(c.info, op)
|
||||||
case c.kind
|
case c.kind
|
||||||
of attachedDestructor:
|
of attachedDestructor:
|
||||||
c.result.add newDestructorCall(op, x)
|
c.result.add newDestructorCall(op, x)
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,7 @@ proc semResolvedCall(c: PContext, n: PNode, x: TCandidate): PNode =
|
||||||
assert x.state == csMatch
|
assert x.state == csMatch
|
||||||
var finalCallee = x.calleeSym
|
var finalCallee = x.calleeSym
|
||||||
markUsed(n.sons[0].info, finalCallee)
|
markUsed(n.sons[0].info, finalCallee)
|
||||||
|
styleCheckUse(n.sons[0].info, finalCallee)
|
||||||
if finalCallee.ast == nil:
|
if finalCallee.ast == nil:
|
||||||
internalError(n.info, "calleeSym.ast is nil") # XXX: remove this check!
|
internalError(n.info, "calleeSym.ast is nil") # XXX: remove this check!
|
||||||
if finalCallee.ast.sons[genericParamsPos].kind != nkEmpty:
|
if finalCallee.ast.sons[genericParamsPos].kind != nkEmpty:
|
||||||
|
|
@ -286,6 +287,7 @@ proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
initCandidate(c, m, s, n)
|
initCandidate(c, m, s, n)
|
||||||
var newInst = generateInstance(c, s, m.bindings, n.info)
|
var newInst = generateInstance(c, s, m.bindings, n.info)
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
result = newSymNode(newInst, n.info)
|
result = newSymNode(newInst, n.info)
|
||||||
|
|
||||||
proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
|
proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
proc semTemplateExpr(c: PContext, n: PNode, s: PSym,
|
proc semTemplateExpr(c: PContext, n: PNode, s: PSym,
|
||||||
flags: TExprFlags = {}): PNode =
|
flags: TExprFlags = {}): PNode =
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
pushInfoContext(n.info)
|
pushInfoContext(n.info)
|
||||||
result = evalTemplate(n, s, getCurrOwner())
|
result = evalTemplate(n, s, getCurrOwner())
|
||||||
if efNoSemCheck notin flags: result = semAfterMacroCall(c, result, s, flags)
|
if efNoSemCheck notin flags: result = semAfterMacroCall(c, result, s, flags)
|
||||||
|
|
@ -79,6 +80,7 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
case s.kind
|
case s.kind
|
||||||
of skConst:
|
of skConst:
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
case skipTypes(s.typ, abstractInst-{tyTypeDesc}).kind
|
case skipTypes(s.typ, abstractInst-{tyTypeDesc}).kind
|
||||||
of tyNil, tyChar, tyInt..tyInt64, tyFloat..tyFloat128,
|
of tyNil, tyChar, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||||
tyTuple, tySet, tyUInt..tyUInt64:
|
tyTuple, tySet, tyUInt..tyUInt64:
|
||||||
|
|
@ -103,6 +105,7 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
of skTemplate: result = semTemplateExpr(c, n, s, flags)
|
of skTemplate: result = semTemplateExpr(c, n, s, flags)
|
||||||
of skVar, skLet, skResult, skParam, skForVar:
|
of skVar, skLet, skResult, skParam, skForVar:
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
# if a proc accesses a global variable, it is not side effect free:
|
# if a proc accesses a global variable, it is not side effect free:
|
||||||
if sfGlobal in s.flags:
|
if sfGlobal in s.flags:
|
||||||
incl(c.p.owner.flags, sfSideEffect)
|
incl(c.p.owner.flags, sfSideEffect)
|
||||||
|
|
@ -115,6 +118,7 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
# var len = 0 # but won't be called
|
# var len = 0 # but won't be called
|
||||||
# genericThatUsesLen(x) # marked as taking a closure?
|
# genericThatUsesLen(x) # marked as taking a closure?
|
||||||
of skGenericParam:
|
of skGenericParam:
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
if s.typ.kind == tyStatic:
|
if s.typ.kind == tyStatic:
|
||||||
result = newSymNode(s, n.info)
|
result = newSymNode(s, n.info)
|
||||||
result.typ = s.typ
|
result.typ = s.typ
|
||||||
|
|
@ -125,12 +129,14 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
return n
|
return n
|
||||||
of skType:
|
of skType:
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
if s.typ.kind == tyStatic and s.typ.n != nil:
|
if s.typ.kind == tyStatic and s.typ.n != nil:
|
||||||
return s.typ.n
|
return s.typ.n
|
||||||
result = newSymNode(s, n.info)
|
result = newSymNode(s, n.info)
|
||||||
result.typ = makeTypeDesc(c, s.typ)
|
result.typ = makeTypeDesc(c, s.typ)
|
||||||
else:
|
else:
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
|
styleCheckUse(n.info, s)
|
||||||
result = newSymNode(s, n.info)
|
result = newSymNode(s, n.info)
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -259,6 +265,7 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
let status = checkConvertible(c, result.typ, it.typ)
|
let status = checkConvertible(c, result.typ, it.typ)
|
||||||
if status in {convOK, convNotNeedeed}:
|
if status in {convOK, convNotNeedeed}:
|
||||||
markUsed(n.info, it.sym)
|
markUsed(n.info, it.sym)
|
||||||
|
styleCheckUse(n.info, it.sym)
|
||||||
markIndirect(c, it.sym)
|
markIndirect(c, it.sym)
|
||||||
return it
|
return it
|
||||||
localError(n.info, errUseQualifier, op.sons[0].sym.name.s)
|
localError(n.info, errUseQualifier, op.sons[0].sym.name.s)
|
||||||
|
|
@ -981,6 +988,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
var s = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared})
|
var s = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared})
|
||||||
if s != nil:
|
if s != nil:
|
||||||
markUsed(n.sons[1].info, s)
|
markUsed(n.sons[1].info, s)
|
||||||
|
styleCheckUse(n.sons[1].info, s)
|
||||||
return semSym(c, n, s, flags)
|
return semSym(c, n, s, flags)
|
||||||
|
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
|
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
|
||||||
|
|
@ -1004,6 +1012,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
result.info = n.info
|
result.info = n.info
|
||||||
result.typ = ty
|
result.typ = ty
|
||||||
markUsed(n.info, f)
|
markUsed(n.info, f)
|
||||||
|
styleCheckUse(n.info, f)
|
||||||
return
|
return
|
||||||
of tyTypeParamsHolders:
|
of tyTypeParamsHolders:
|
||||||
return readTypeParameter(c, ty, i, n.info)
|
return readTypeParameter(c, ty, i, n.info)
|
||||||
|
|
@ -1036,12 +1045,13 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if fieldVisible(c, f):
|
if fieldVisible(c, f):
|
||||||
# is the access to a public field or in the same module or in a friend?
|
# is the access to a public field or in the same module or in a friend?
|
||||||
markUsed(n.sons[1].info, f)
|
markUsed(n.sons[1].info, f)
|
||||||
|
styleCheckUse(n.sons[1].info, f)
|
||||||
n.sons[0] = makeDeref(n.sons[0])
|
n.sons[0] = makeDeref(n.sons[0])
|
||||||
n.sons[1] = newSymNode(f) # we now have the correct field
|
n.sons[1] = newSymNode(f) # we now have the correct field
|
||||||
n.typ = f.typ
|
n.typ = f.typ
|
||||||
if check == nil:
|
if check == nil:
|
||||||
result = n
|
result = n
|
||||||
else:
|
else:
|
||||||
check.sons[0] = n
|
check.sons[0] = n
|
||||||
check.typ = n.typ
|
check.typ = n.typ
|
||||||
result = check
|
result = check
|
||||||
|
|
@ -1049,6 +1059,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
f = getSymFromList(ty.n, i)
|
f = getSymFromList(ty.n, i)
|
||||||
if f != nil:
|
if f != nil:
|
||||||
markUsed(n.sons[1].info, f)
|
markUsed(n.sons[1].info, f)
|
||||||
|
styleCheckUse(n.sons[1].info, s)
|
||||||
n.sons[0] = makeDeref(n.sons[0])
|
n.sons[0] = makeDeref(n.sons[0])
|
||||||
n.sons[1] = newSymNode(f)
|
n.sons[1] = newSymNode(f)
|
||||||
n.typ = f.typ
|
n.typ = f.typ
|
||||||
|
|
@ -1465,6 +1476,7 @@ proc semExpandToAst(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
macroCall.sons[0] = newSymNode(expandedSym, macroCall.info)
|
macroCall.sons[0] = newSymNode(expandedSym, macroCall.info)
|
||||||
markUsed(n.info, expandedSym)
|
markUsed(n.info, expandedSym)
|
||||||
|
styleCheckUse(n.info, expandedSym)
|
||||||
|
|
||||||
for i in countup(1, macroCall.len-1):
|
for i in countup(1, macroCall.len-1):
|
||||||
macroCall.sons[i] = semExprWithType(c, macroCall[i], {})
|
macroCall.sons[i] = semExprWithType(c, macroCall[i], {})
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
|
||||||
result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared})
|
result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared})
|
||||||
if result != nil:
|
if result != nil:
|
||||||
markUsed(n.info, result)
|
markUsed(n.info, result)
|
||||||
|
styleCheckUse(n.info, result)
|
||||||
if result.kind == skParam and result.typ.kind == tyTypeDesc:
|
if result.kind == skParam and result.typ.kind == tyTypeDesc:
|
||||||
# This is a typedesc param. is it already bound?
|
# This is a typedesc param. is it already bound?
|
||||||
# it's not bound when it's used multiple times in the
|
# it's not bound when it's used multiple times in the
|
||||||
|
|
@ -835,6 +836,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
|
|
||||||
of tyGenericParam:
|
of tyGenericParam:
|
||||||
markUsed(info, paramType.sym)
|
markUsed(info, paramType.sym)
|
||||||
|
styleCheckUse(info, paramType.sym)
|
||||||
if tfWildcard in paramType.flags:
|
if tfWildcard in paramType.flags:
|
||||||
paramType.flags.excl tfWildcard
|
paramType.flags.excl tfWildcard
|
||||||
paramType.sym.kind = skType
|
paramType.sym.kind = skType
|
||||||
|
|
@ -1195,6 +1197,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
assignType(prev, t)
|
assignType(prev, t)
|
||||||
result = prev
|
result = prev
|
||||||
markUsed(n.info, n.sym)
|
markUsed(n.info, n.sym)
|
||||||
|
styleCheckUse(n.info, n.sym)
|
||||||
else:
|
else:
|
||||||
if n.sym.kind != skError: localError(n.info, errTypeExpected)
|
if n.sym.kind != skError: localError(n.info, errTypeExpected)
|
||||||
result = newOrPrevType(tyError, prev, c)
|
result = newOrPrevType(tyError, prev, c)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst,
|
intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst,
|
||||||
magicsys, condsyms, idents, lexer, options, parampatterns, strutils, trees
|
magicsys, condsyms, idents, lexer, options, parampatterns, strutils, trees,
|
||||||
|
pretty
|
||||||
|
|
||||||
when not defined(noDocgen):
|
when not defined(noDocgen):
|
||||||
import docgen
|
import docgen
|
||||||
|
|
@ -1272,6 +1273,7 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
|
||||||
else:
|
else:
|
||||||
# only one valid interpretation found:
|
# only one valid interpretation found:
|
||||||
markUsed(arg.info, arg.sons[best].sym)
|
markUsed(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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
# included from sigmatch.nim
|
# included from sigmatch.nim
|
||||||
|
|
||||||
import algorithm, sequtils, pretty
|
import algorithm, sequtils
|
||||||
|
|
||||||
const
|
const
|
||||||
sep = '\t'
|
sep = '\t'
|
||||||
|
|
@ -331,7 +331,6 @@ proc markUsed(info: TLineInfo; s: PSym) =
|
||||||
if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s)
|
if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s)
|
||||||
if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s)
|
if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s)
|
||||||
suggestSym(info, s)
|
suggestSym(info, s)
|
||||||
if gCmd == cmdPretty: styleCheckUse(info, s)
|
|
||||||
|
|
||||||
proc useSym*(sym: PSym): PNode =
|
proc useSym*(sym: PSym): PNode =
|
||||||
result = newSymNode(sym)
|
result = newSymNode(sym)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue