diff options
author | Araq <rumpf_a@web.de> | 2014-09-09 21:31:34 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-09-09 21:31:34 +0200 |
commit | 490371977e8ff61ccebe505b33edada0d674ac25 (patch) | |
tree | 0ed60989917f6c53f859a80214910dba2031c35a /compiler | |
parent | 12796b6c86444e253c5ba8ae9ec05e26bc0b4285 (diff) | |
download | Nim-490371977e8ff61ccebe505b33edada0d674ac25.tar.gz |
some improvements for nimfix
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/lookups.nim | 10 | ||||
-rw-r--r-- | compiler/main.nim | 3 | ||||
-rw-r--r-- | compiler/pretty.nim | 2 | ||||
-rw-r--r-- | compiler/prettybase.nim | 20 | ||||
-rw-r--r-- | compiler/semexprs.nim | 6 | ||||
-rw-r--r-- | compiler/semtypes.nim | 7 |
6 files changed, 37 insertions, 11 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 466ac824a..dbd03c87d 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -376,3 +376,13 @@ proc nextOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym = n.sons[0].sym.name, o.inSymChoice).skipAlias(n) if result != nil and result.kind == skStub: loadStub(result) + +proc pickSym*(c: PContext, n: PNode; kind: TSymKind; + flags: TSymFlags = {}): PSym = + var o: TOverloadIter + 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 47da96a03..5e4a0da76 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -306,9 +306,6 @@ proc mainCommand* = CommandCompileToLLVM() else: rawMessage(errInvalidCommandX, command) - of "pretty": - gCmd = cmdPretty - commandPretty() of "doc": gCmd = cmdDoc loadConfigs(DocConfig) diff --git a/compiler/pretty.nim b/compiler/pretty.nim index 436181bbc..e6d2d7b70 100644 --- a/compiler/pretty.nim +++ b/compiler/pretty.nim @@ -41,7 +41,7 @@ proc overwriteFiles*() = f.write line.strip(leading = false, trailing = true) else: f.write line - f.write("\L") + f.write(gSourceFiles[i].newline) f.close except IOError: rawMessage(errCannotOpenFile, newFile) diff --git a/compiler/prettybase.nim b/compiler/prettybase.nim index e3c1e6ae9..467f3d402 100644 --- a/compiler/prettybase.nim +++ b/compiler/prettybase.nim @@ -7,14 +7,14 @@ # distribution, for details about the copyright. # -import ast, msgs, strutils, idents +import ast, msgs, strutils, idents, lexbase, streams from os import splitFile type TSourceFile* = object lines*: seq[string] dirty*, isNimfixFile*: bool - fullpath*: string + fullpath*, newline*: string var gSourceFiles*: seq[TSourceFile] = @[] @@ -27,10 +27,24 @@ proc loadFile*(info: TLineInfo) = gSourceFiles[i].lines = @[] let path = info.toFullPath gSourceFiles[i].fullpath = path - gSourceFiles[i].isNimfixFile = path.splitFile.ext == "nimfix" + gSourceFiles[i].isNimfixFile = path.splitFile.ext == ".nimfix" # we want to die here for IOError: for line in lines(path): gSourceFiles[i].lines.add(line) + # extract line ending of the file: + var lex: BaseLexer + open(lex, newFileStream(path)) + var pos = lex.bufpos + while true: + case lex.buf[pos] + of '\c': + gSourceFiles[i].newline = "\c\L" + break + of '\L', '\0': + gSourceFiles[i].newline = "\L" + break + inc pos + close(lex) const Letters* = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '_'} diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index a397993d8..9b850bd86 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2014,9 +2014,9 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = checkMinSonsLen(n, 1) let mode = if nfDotField in n.flags: {} else: {checkUndeclared} var s = qualifiedLookUp(c, n.sons[0], mode) - if s != nil: - if gCmd == cmdPretty and n.sons[0].kind == nkDotExpr: - pretty.checkUse(n.sons[0].sons[1].info, s) + if s != nil: + #if gCmd == cmdPretty and n.sons[0].kind == nkDotExpr: + # pretty.checkUse(n.sons[0].sons[1].info, s) case s.kind of skMacro: if sfImmediate notin s.flags: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index a0fe81db3..9a2a64a9e 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -279,7 +279,12 @@ proc semTypeIdent(c: PContext, n: PNode): PSym = if n.kind == nkSym: result = n.sym else: - result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared}) + when defined(nimfix): + result = pickSym(c, n, skType) + if result.isNil: + result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared}) + else: + result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared}) if result != nil: markUsed(n.info, result) if result.kind == skParam and result.typ.kind == tyTypeDesc: |