diff --git a/compiler/lookups.nim b/compiler/lookups.nim index dbd03c87d7..07ac43f386 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -383,6 +383,5 @@ proc pickSym*(c: PContext, n: PNode; kind: TSymKind; var a = initOverloadIter(o, c, n) while a != nil: if a.kind == kind and flags <= a.flags: - incl(a.flags, sfUsed) return a a = nextOverloadIter(o, c, n) diff --git a/compiler/main.nim b/compiler/main.nim index 5e4a0da762..e73654a4b8 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -15,8 +15,7 @@ import wordrecg, sem, semdata, idents, passes, docgen, extccomp, cgen, jsgen, json, nversion, platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen, - tables, docgen2, service, parser, modules, ccgutils, sigmatch, ropes, lists, - pretty + tables, docgen2, service, parser, modules, ccgutils, sigmatch, ropes, lists from magicsys import systemModule, resetSysTypes @@ -164,13 +163,6 @@ proc commandEval(exp: string) = var echoExp = "echo \"eval\\t\", " & "repr(" & exp & ")" evalNim(echoExp.parseString, makeStdinModule()) -proc commandPretty = - msgs.gErrorMax = high(int) # do not stop after first error - semanticPasses() - registerPass(prettyPass) - compileProject() - pretty.overwriteFiles() - proc commandScan = var f = addFileExt(mainCommandArg(), NimExt) var stream = llStreamOpen(f, fmRead) diff --git a/compiler/nimfix.nim b/compiler/nimfix.nim index 5cdcc65db3..7e546fe0fd 100644 --- a/compiler/nimfix.nim +++ b/compiler/nimfix.nim @@ -32,7 +32,6 @@ proc mainCommand = #msgs.gErrorMax = high(int) # do not stop after first error registerPass verbosePass registerPass semPass - registerPass prettyPass gCmd = cmdPretty appendStr(searchPaths, options.libpath) if gProjectFull.len != 0: diff --git a/compiler/pretty.nim b/compiler/pretty.nim index e6d2d7b70b..2d8d79ce13 100644 --- a/compiler/pretty.nim +++ b/compiler/pretty.nim @@ -11,10 +11,9 @@ ## to convert Nim code into a consistent style. import - strutils, os, options, ast, astalgo, msgs, ropes, idents, passes, + strutils, os, options, ast, astalgo, msgs, ropes, idents, intsets, strtabs, semdata, prettybase - type StyleCheck* {.pure.} = enum None, Confirm, Auto @@ -23,11 +22,6 @@ var gStyleCheck*: StyleCheck gCheckExtern*: bool -type - TGen = object of TPassContext - module*: PSym - PGen = ref TGen - proc overwriteFiles*() = let doStrip = options.getConfigVar("pretty.strip").normalize == "on" for i in 0 .. high(gSourceFiles): @@ -100,21 +94,20 @@ proc checkStyle(info: TLineInfo, s: string, k: TSymKind) = if s != beau: message(info, hintName, beau) -proc checkDef*(n: PNode; s: PSym) = +proc styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) = if gStyleCheck == StyleCheck.None: return # operators stay as they are: - if s.kind 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 - if s.kind 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: - checkStyle(n.info, s.name.s, s.kind) + checkStyle(info, s.name.s, k) -proc checkDef(c: PGen; n: PNode) = - if n.kind != nkSym: return - checkDef(n, n.sym) +proc styleCheckDef*(info: TLineInfo; s: PSym) = styleCheckDef(info, s, s.kind) +proc styleCheckDef*(s: PSym) = styleCheckDef(s.info, s, s.kind) -proc checkUse*(info: TLineInfo; s: PSym) = +proc styleCheckUse*(info: TLineInfo; s: PSym) = if info.fileIndex < 0: return # we simply convert it to what it looks like in the definition # for consistency @@ -141,50 +134,3 @@ proc checkUse*(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 - -proc check(c: PGen, n: PNode) = - case n.kind - of nkSym: checkUse(n.info, n.sym) - of nkBlockStmt, nkBlockExpr, nkBlockType: - checkDef(c, n[0]) - check(c, n.sons[1]) - of nkForStmt, nkParForStmt: - let L = n.len - for i in countup(0, L-3): - checkDef(c, n[i]) - check(c, n[L-2]) - check(c, n[L-1]) - of nkProcDef, nkLambdaKinds, nkMethodDef, nkIteratorDef, nkTemplateDef, - nkMacroDef, nkConverterDef: - checkDef(c, n[namePos]) - for i in namePos+1 .. MaxSetElements: @@ -363,7 +364,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType = else: addSon(result.n, newSymNode(field)) addSonSkipIntLit(result, typ) - if gCmd == cmdPretty: checkDef(a.sons[j], field) + if gCmd == cmdPretty: styleCheckDef(a.sons[j].info, field) proc semIdentVis(c: PContext, kind: TSymKind, n: PNode, allowed: TSymFlags): PSym = @@ -399,7 +400,7 @@ proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode, else: discard else: result = semIdentVis(c, kind, n, allowed) - if gCmd == cmdPretty: checkDef(n, result) + if gCmd == cmdPretty: styleCheckDef(n.info, result) proc checkForOverlap(c: PContext, t: PNode, currentEx, branchIndex: int) = let ex = t[branchIndex][currentEx].skipConv @@ -579,6 +580,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int, localError(n.sons[i].info, errAttemptToRedefine, f.name.s) if a.kind == nkEmpty: addSon(father, newSymNode(f)) else: addSon(a, newSymNode(f)) + styleCheckDef(f) if a.kind != nkEmpty: addSon(father, a) of nkEmpty: discard else: illFormedAst(n) @@ -918,7 +920,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, addSon(result.n, newSymNode(arg)) rawAddSon(result, finalType) addParamOrResult(c, arg, kind) - if gCmd == cmdPretty: checkDef(a.sons[j], arg) + if gCmd == cmdPretty: styleCheckDef(a.sons[j].info, arg) var r: PType if n.sons[0].kind != nkEmpty: diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 650e5b3fb8..99e0e93c1a 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -331,7 +331,7 @@ 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: checkUse(info, s) + if gCmd == cmdPretty: styleCheckUse(info, s) proc useSym*(sym: PSym): PNode = result = newSymNode(sym) diff --git a/todo.txt b/todo.txt index 66f47a1d8a..2785e4d2ea 100644 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,7 @@ version 0.10 - Test nimfix on various babel packages - Pegs do not work at compile-time +- rename cgi.URLencode to encodeUrl version 0.9.6