diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/lists.nim | 4 | ||||
-rw-r--r-- | compiler/pretty.nim | 30 | ||||
-rw-r--r-- | compiler/suggest.nim | 3 |
3 files changed, 23 insertions, 14 deletions
diff --git a/compiler/lists.nim b/compiler/lists.nim index 93448c0b2..dd4f5d6be 100644 --- a/compiler/lists.nim +++ b/compiler/lists.nim @@ -20,12 +20,12 @@ type PStrEntry* = ref TStrEntry TLinkedList* = object # for the "find" operation: head*, tail*: PListEntry - Counter*: int + counter*: int TCompareProc* = proc (entry: PListEntry, closure: pointer): bool {.nimcall.} proc initLinkedList*(list: var TLinkedList) = - list.Counter = 0 + list.counter = 0 list.head = nil list.tail = nil diff --git a/compiler/pretty.nim b/compiler/pretty.nim index a59694d8f..704857f37 100644 --- a/compiler/pretty.nim +++ b/compiler/pretty.nim @@ -17,9 +17,10 @@ import const removeTP = false # when true, "nimrod pretty" converts TTyp to Typ. -type +type TGen = object of TPassContext module*: PSym + checkExtern: bool PGen = ref TGen TSourceFile = object @@ -44,13 +45,19 @@ proc loadFile(info: TLineInfo) = gSourceFiles[i].lines.add(line) proc overwriteFiles*() = + let overWrite = options.getConfigVar("pretty.overwrite").normalize == "on" + let doStrip = options.getConfigVar("pretty.strip").normalize == "on" for i in 0 .. high(gSourceFiles): if not gSourceFiles[i].dirty: continue - let newFile = gSourceFiles[i].fullpath #.changeFileExt(".pretty.nim") + let newFile = if overWrite: gSourceFiles[i].fullpath + else: gSourceFiles[i].fullpath.changeFileExt(".pretty.nim") try: var f = open(newFile, fmWrite) for line in gSourceFiles[i].lines: - f.write line #.strip(leading = false, trailing = true) + if doStrip: + f.write line.strip(leading = false, trailing = true) + else: + f.write line f.write("\L") f.close except EIO: @@ -131,8 +138,6 @@ proc differ(line: string, a, b: int, x: string): bool = inc j return false -var cannotRename = initIntSet() - proc checkDef(c: PGen; n: PNode) = if n.kind != nkSym: return let s = n.sym @@ -141,10 +146,11 @@ proc checkDef(c: PGen; n: PNode) = if s.kind in {skResult, skTemp} or s.name.s[0] notin Letters: return if s.kind in {skType, skGenericParam} and sfAnon in s.flags: return - checkStyle(n.info, s.name.s, s.kind) + if {sfImportc, sfExportc} * s.flags == {} or c.checkExtern: + checkStyle(n.info, s.name.s, s.kind) -proc checkUse(c: PGen; n: PNode) = - if n.info.fileIndex < 0: return +proc checkUse*(n: PNode) = + if n.info.fileIndex < 0 or n.kind != nkSym: return let s = n.sym # we simply convert it to what it looks like in the definition # for consistency @@ -177,8 +183,9 @@ proc checkUse(c: PGen; n: PNode) = system.shallowCopy(gSourceFiles[n.info.fileIndex].lines[n.info.line-1], x) gSourceFiles[n.info.fileIndex].dirty = true - when false: + var cannotRename = initIntSet() + proc beautifyName(s: string, k: TSymKind): string = let allUpper = allCharsInSet(s, {'A'..'Z', '0'..'9', '_'}) result = newStringOfCap(s.len) @@ -260,9 +267,9 @@ when false: proc check(c: PGen, n: PNode) = case n.kind - of nkSym: checkUse(c, n) + of nkSym: checkUse(n) of nkBlockStmt, nkBlockExpr, nkBlockType: - if n.sons[0].kind != nkEmpty: checkDef(c, n[0]) + checkDef(c, n[0]) check(c, n.sons[1]) of nkForStmt, nkParForStmt: let L = n.len @@ -300,6 +307,7 @@ proc myOpen(module: PSym): PPassContext = var g: PGen new(g) g.module = module + g.checkExtern = options.getConfigVar("pretty.checkextern").normalize == "on" result = g if rules.isNil: rules = newStringTable(modeStyleInsensitive) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 888f958d0..7e0a28afb 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -11,7 +11,7 @@ # included from sigmatch.nim -import algorithm, sequtils +import algorithm, sequtils, pretty const sep = '\t' @@ -327,6 +327,7 @@ proc markUsed(n: PNode, s: PSym) = if sfDeprecated in s.flags: message(n.info, warnDeprecated, s.name.s) if sfError in s.flags: localError(n.info, errWrongSymbolX, s.name.s) suggestSym(n, s) + if gCmd == cmdPretty: checkUse(n) proc useSym*(sym: PSym): PNode = result = newSymNode(sym) |