some improvements for nimfix

This commit is contained in:
Araq 2014-09-09 21:31:34 +02:00
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) n.sons[0].sym.name, o.inSymChoice).skipAlias(n)
if result != nil and result.kind == skStub: loadStub(result) 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() CommandCompileToLLVM()
else: else:
rawMessage(errInvalidCommandX, command) rawMessage(errInvalidCommandX, command)
of "pretty":
gCmd = cmdPretty
commandPretty()
of "doc": of "doc":
gCmd = cmdDoc gCmd = cmdDoc
loadConfigs(DocConfig) loadConfigs(DocConfig)

View file

@ -41,7 +41,7 @@ proc overwriteFiles*() =
f.write line.strip(leading = false, trailing = true) f.write line.strip(leading = false, trailing = true)
else: else:
f.write line f.write line
f.write("\L") f.write(gSourceFiles[i].newline)
f.close f.close
except IOError: except IOError:
rawMessage(errCannotOpenFile, newFile) rawMessage(errCannotOpenFile, newFile)

View file

@ -7,14 +7,14 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
import ast, msgs, strutils, idents import ast, msgs, strutils, idents, lexbase, streams
from os import splitFile from os import splitFile
type type
TSourceFile* = object TSourceFile* = object
lines*: seq[string] lines*: seq[string]
dirty*, isNimfixFile*: bool dirty*, isNimfixFile*: bool
fullpath*: string fullpath*, newline*: string
var var
gSourceFiles*: seq[TSourceFile] = @[] gSourceFiles*: seq[TSourceFile] = @[]
@ -27,10 +27,24 @@ proc loadFile*(info: TLineInfo) =
gSourceFiles[i].lines = @[] gSourceFiles[i].lines = @[]
let path = info.toFullPath let path = info.toFullPath
gSourceFiles[i].fullpath = path 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: # we want to die here for IOError:
for line in lines(path): for line in lines(path):
gSourceFiles[i].lines.add(line) 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 const
Letters* = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '_'} Letters* = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '_'}

View file

@ -2015,8 +2015,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
let mode = if nfDotField in n.flags: {} else: {checkUndeclared} let mode = if nfDotField in n.flags: {} else: {checkUndeclared}
var s = qualifiedLookUp(c, n.sons[0], mode) var s = qualifiedLookUp(c, n.sons[0], mode)
if s != nil: if s != nil:
if gCmd == cmdPretty and n.sons[0].kind == nkDotExpr: #if gCmd == cmdPretty and n.sons[0].kind == nkDotExpr:
pretty.checkUse(n.sons[0].sons[1].info, s) # pretty.checkUse(n.sons[0].sons[1].info, s)
case s.kind case s.kind
of skMacro: of skMacro:
if sfImmediate notin s.flags: if sfImmediate notin s.flags:

View file

@ -279,7 +279,12 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
if n.kind == nkSym: if n.kind == nkSym:
result = n.sym result = n.sym
else: 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: if result != nil:
markUsed(n.info, result) markUsed(n.info, result)
if result.kind == skParam and result.typ.kind == tyTypeDesc: if result.kind == skParam and result.typ.kind == tyTypeDesc:

View file

@ -12,7 +12,6 @@ Advanced commands:
module dependency graph module dependency graph
//dump dump all defined conditionals and search paths //dump dump all defined conditionals and search paths
//check checks the project for syntax and semantic //check checks the project for syntax and semantic
//pretty homogenizes source code style
//idetools compiler support for IDEs: possible options: //idetools compiler support for IDEs: possible options:
--track:FILE,LINE,COL track a file/cursor position --track:FILE,LINE,COL track a file/cursor position
--trackDirty:DIRTY_FILE,ORIG_FILE,LINE,COL --trackDirty:DIRTY_FILE,ORIG_FILE,LINE,COL

View file

@ -690,7 +690,7 @@ proc getQueuedCompletionStatus*(CompletionPort: THandle,
dwMilliseconds: DWORD): WINBOOL{.stdcall, dwMilliseconds: DWORD): WINBOOL{.stdcall,
dynlib: "kernel32", importc: "GetQueuedCompletionStatus".} dynlib: "kernel32", importc: "GetQueuedCompletionStatus".}
proc getOverlappedResult*(hFile: THandle, lpOverlapped: TOverlapped, proc getOverlappedResult*(hFile: THandle, lpOverlapped: TOVERLAPPED,
lpNumberOfBytesTransferred: var DWORD, bWait: WINBOOL): WINBOOL{. lpNumberOfBytesTransferred: var DWORD, bWait: WINBOOL): WINBOOL{.
stdcall, dynlib: "kernel32", importc: "GetOverlappedResult".} stdcall, dynlib: "kernel32", importc: "GetOverlappedResult".}