diff options
-rw-r--r-- | compiler/pretty.nim | 18 | ||||
-rw-r--r-- | compiler/prettybase.nim | 1 | ||||
-rw-r--r-- | compiler/sem.nim | 1 | ||||
-rw-r--r-- | compiler/semasgn.nim | 1 | ||||
-rw-r--r-- | compiler/semcall.nim | 2 | ||||
-rw-r--r-- | compiler/semexprs.nim | 16 | ||||
-rw-r--r-- | compiler/semtypes.nim | 3 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 4 | ||||
-rw-r--r-- | compiler/suggest.nim | 3 |
9 files changed, 37 insertions, 12 deletions
diff --git a/compiler/pretty.nim b/compiler/pretty.nim index 2d8d79ce1..d6b593318 100644 --- a/compiler/pretty.nim +++ b/compiler/pretty.nim @@ -94,18 +94,21 @@ proc checkStyle(info: TLineInfo, s: string, k: TSymKind) = if s != beau: message(info, hintName, beau) -proc styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) = - if gStyleCheck == StyleCheck.None: return +proc styleCheckDefImpl(info: TLineInfo; s: PSym; k: TSymKind) = # operators stay as they are: - if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters: - return + if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters: return if k in {skType, skGenericParam} and sfAnon in s.flags: return - if {sfImportc, sfExportc} * s.flags == {} or gCheckExtern: checkStyle(info, s.name.s, k) -proc styleCheckDef*(info: TLineInfo; s: PSym) = styleCheckDef(info, s, s.kind) -proc styleCheckDef*(s: PSym) = styleCheckDef(s.info, s, s.kind) +template styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) = + 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) = 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) system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x) gSourceFiles[info.fileIndex].dirty = true + if newName == "File": writeStackTrace() diff --git a/compiler/prettybase.nim b/compiler/prettybase.nim index 24bc601e3..e2679f456 100644 --- a/compiler/prettybase.nim +++ b/compiler/prettybase.nim @@ -74,6 +74,7 @@ proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PIdent) = var x = line.substr(0, first-1) & newSym.s & line.substr(last+1) system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x) gSourceFiles[info.fileIndex].dirty = true + if newSym.s == "File": writeStackTrace() proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) = replaceDeprecated(info, oldSym.name, newSym.name) diff --git a/compiler/sem.nim b/compiler/sem.nim index 71e60f0b6..1b6e6fe2e 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -311,6 +311,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym, pushInfoContext(nOrig.info) markUsed(n.info, sym) + styleCheckUse(n.info, sym) if sym == c.p.owner: globalError(n.info, errRecursiveDependencyX, sym.name.s) diff --git a/compiler/semasgn.nim b/compiler/semasgn.nim index 2c77bff7b..483d36bf3 100644 --- a/compiler/semasgn.nim +++ b/compiler/semasgn.nim @@ -126,6 +126,7 @@ proc considerOverloadedOp(c: TLiftCtx; t: PType; x, y: PNode): bool = let op = t.attachedOps[c.kind] if op != nil: markUsed(c.info, op) + styleCheckUse(c.info, op) case c.kind of attachedDestructor: c.result.add newDestructorCall(op, x) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 3ce88651f..6f92a75a6 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -254,6 +254,7 @@ proc semResolvedCall(c: PContext, n: PNode, x: TCandidate): PNode = assert x.state == csMatch var finalCallee = x.calleeSym markUsed(n.sons[0].info, finalCallee) + styleCheckUse(n.sons[0].info, finalCallee) if finalCallee.ast == nil: internalError(n.info, "calleeSym.ast is nil") # XXX: remove this check! 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) var newInst = generateInstance(c, s, m.bindings, n.info) markUsed(n.info, s) + styleCheckUse(n.info, s) result = newSymNode(newInst, n.info) proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode = diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 95a60ef23..0034c3718 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -13,6 +13,7 @@ proc semTemplateExpr(c: PContext, n: PNode, s: PSym, flags: TExprFlags = {}): PNode = markUsed(n.info, s) + styleCheckUse(n.info, s) pushInfoContext(n.info) result = evalTemplate(n, s, getCurrOwner()) 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 of skConst: markUsed(n.info, s) + styleCheckUse(n.info, s) case skipTypes(s.typ, abstractInst-{tyTypeDesc}).kind of tyNil, tyChar, tyInt..tyInt64, tyFloat..tyFloat128, 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 skVar, skLet, skResult, skParam, skForVar: markUsed(n.info, s) + styleCheckUse(n.info, s) # if a proc accesses a global variable, it is not side effect free: if sfGlobal in s.flags: 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 # genericThatUsesLen(x) # marked as taking a closure? of skGenericParam: + styleCheckUse(n.info, s) if s.typ.kind == tyStatic: result = newSymNode(s, n.info) result.typ = s.typ @@ -125,12 +129,14 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode = return n of skType: markUsed(n.info, s) + styleCheckUse(n.info, s) if s.typ.kind == tyStatic and s.typ.n != nil: return s.typ.n result = newSymNode(s, n.info) result.typ = makeTypeDesc(c, s.typ) else: markUsed(n.info, s) + styleCheckUse(n.info, s) result = newSymNode(s, n.info) type @@ -259,6 +265,7 @@ proc semConv(c: PContext, n: PNode): PNode = let status = checkConvertible(c, result.typ, it.typ) if status in {convOK, convNotNeedeed}: markUsed(n.info, it.sym) + styleCheckUse(n.info, it.sym) markIndirect(c, it.sym) return it 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}) if s != nil: markUsed(n.sons[1].info, s) + styleCheckUse(n.sons[1].info, s) return semSym(c, n, s, flags) 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.typ = ty markUsed(n.info, f) + styleCheckUse(n.info, f) return of tyTypeParamsHolders: return readTypeParameter(c, ty, i, n.info) @@ -1036,12 +1045,13 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = if fieldVisible(c, f): # is the access to a public field or in the same module or in a friend? markUsed(n.sons[1].info, f) + styleCheckUse(n.sons[1].info, f) n.sons[0] = makeDeref(n.sons[0]) n.sons[1] = newSymNode(f) # we now have the correct field n.typ = f.typ - if check == nil: + if check == nil: result = n - else: + else: check.sons[0] = n check.typ = n.typ result = check @@ -1049,6 +1059,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = f = getSymFromList(ty.n, i) if f != nil: markUsed(n.sons[1].info, f) + styleCheckUse(n.sons[1].info, s) n.sons[0] = makeDeref(n.sons[0]) n.sons[1] = newSymNode(f) n.typ = f.typ @@ -1465,6 +1476,7 @@ proc semExpandToAst(c: PContext, n: PNode): PNode = macroCall.sons[0] = newSymNode(expandedSym, macroCall.info) markUsed(n.info, expandedSym) + styleCheckUse(n.info, expandedSym) for i in countup(1, macroCall.len-1): macroCall.sons[i] = semExprWithType(c, macroCall[i], {}) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 6f80cbffe..4badf8f4e 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -288,6 +288,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym = result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared}) if result != nil: markUsed(n.info, result) + styleCheckUse(n.info, result) if result.kind == skParam and result.typ.kind == tyTypeDesc: # This is a typedesc param. is it already bound? # 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: markUsed(info, paramType.sym) + styleCheckUse(info, paramType.sym) if tfWildcard in paramType.flags: paramType.flags.excl tfWildcard paramType.sym.kind = skType @@ -1195,6 +1197,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = assignType(prev, t) result = prev markUsed(n.info, n.sym) + styleCheckUse(n.info, n.sym) else: if n.sym.kind != skError: localError(n.info, errTypeExpected) result = newOrPrevType(tyError, prev, c) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index d7b397af6..51ae4e8f5 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -12,7 +12,8 @@ import 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): import docgen @@ -1272,6 +1273,7 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType, else: # only one valid interpretation found: 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], argOrig) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 99e0e93c1..c700db323 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -11,7 +11,7 @@ # included from sigmatch.nim -import algorithm, sequtils, pretty +import algorithm, sequtils const sep = '\t' @@ -331,7 +331,6 @@ proc markUsed(info: TLineInfo; s: PSym) = if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s) if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s) suggestSym(info, s) - if gCmd == cmdPretty: styleCheckUse(info, s) proc useSym*(sym: PSym): PNode = result = newSymNode(sym) |