summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-09-09 21:31:34 +0200
committerAraq <rumpf_a@web.de>2014-09-09 21:31:34 +0200
commit490371977e8ff61ccebe505b33edada0d674ac25 (patch)
tree0ed60989917f6c53f859a80214910dba2031c35a
parent12796b6c86444e253c5ba8ae9ec05e26bc0b4285 (diff)
downloadNim-490371977e8ff61ccebe505b33edada0d674ac25.tar.gz
some improvements for nimfix
-rw-r--r--compiler/lookups.nim10
-rw-r--r--compiler/main.nim3
-rw-r--r--compiler/pretty.nim2
-rw-r--r--compiler/prettybase.nim20
-rw-r--r--compiler/semexprs.nim6
-rw-r--r--compiler/semtypes.nim7
-rw-r--r--doc/advopt.txt1
-rw-r--r--lib/windows/winlean.nim2
8 files changed, 38 insertions, 13 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:
diff --git a/doc/advopt.txt b/doc/advopt.txt
index 0febf778f..2ddba12e8 100644
--- a/doc/advopt.txt
+++ b/doc/advopt.txt
@@ -12,7 +12,6 @@ Advanced commands:
                             module dependency graph
   //dump                    dump all defined conditionals and search paths
   //check                   checks the project for syntax and semantic
-  //pretty                  homogenizes source code style
   //idetools                compiler support for IDEs: possible options:
     --track:FILE,LINE,COL   track a file/cursor position
     --trackDirty:DIRTY_FILE,ORIG_FILE,LINE,COL
diff --git a/lib/windows/winlean.nim b/lib/windows/winlean.nim
index 1ac82d84a..cc633d90b 100644
--- a/lib/windows/winlean.nim
+++ b/lib/windows/winlean.nim
@@ -690,7 +690,7 @@ proc getQueuedCompletionStatus*(CompletionPort: THandle,
                                 dwMilliseconds: DWORD): WINBOOL{.stdcall,
     dynlib: "kernel32", importc: "GetQueuedCompletionStatus".}
 
-proc getOverlappedResult*(hFile: THandle, lpOverlapped: TOverlapped,
+proc getOverlappedResult*(hFile: THandle, lpOverlapped: TOVERLAPPED,
               lpNumberOfBytesTransferred: var DWORD, bWait: WINBOOL): WINBOOL{.
     stdcall, dynlib: "kernel32", importc: "GetOverlappedResult".}