some improvements for nimfix

This commit is contained in:
Araq
2014-09-09 21:31:34 +02:00
parent 12796b6c86
commit 490371977e
8 changed files with 38 additions and 13 deletions

View File

@@ -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)

View File

@@ -306,9 +306,6 @@ proc mainCommand* =
CommandCompileToLLVM()
else:
rawMessage(errInvalidCommandX, command)
of "pretty":
gCmd = cmdPretty
commandPretty()
of "doc":
gCmd = cmdDoc
loadConfigs(DocConfig)

View File

@@ -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)

View File

@@ -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', '_'}

View File

@@ -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:

View File

@@ -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:

View File

@@ -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

View File

@@ -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".}