Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
98ed7fbf16
24 changed files with 223 additions and 146 deletions
|
|
@ -97,7 +97,7 @@ type
|
|||
next*: ref TToken # for C we need arbitrary look-ahead :-(
|
||||
|
||||
TLexer* = object of TBaseLexer
|
||||
filename*: string
|
||||
fileIdx*: int32
|
||||
inDirective: bool
|
||||
|
||||
proc getTok*(L: var TLexer, tok: var TToken)
|
||||
|
|
@ -117,7 +117,7 @@ proc fillToken(L: var TToken) =
|
|||
|
||||
proc openLexer*(lex: var TLexer, filename: string, inputstream: PLLStream) =
|
||||
openBaseLexer(lex, inputstream)
|
||||
lex.filename = filename
|
||||
lex.fileIdx = filename.fileInfoIdx
|
||||
|
||||
proc closeLexer*(lex: var TLexer) =
|
||||
inc(gLinesCompiled, lex.LineNumber)
|
||||
|
|
@ -127,13 +127,13 @@ proc getColumn*(L: TLexer): int =
|
|||
result = getColNumber(L, L.bufPos)
|
||||
|
||||
proc getLineInfo*(L: TLexer): TLineInfo =
|
||||
result = newLineInfo(L.filename, L.linenumber, getColNumber(L, L.bufpos))
|
||||
result = newLineInfo(L.fileIdx, L.linenumber, getColNumber(L, L.bufpos))
|
||||
|
||||
proc lexMessage*(L: TLexer, msg: TMsgKind, arg = "") =
|
||||
msgs.GenericMessage(getLineInfo(L), msg, arg)
|
||||
|
||||
proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
|
||||
var info = newLineInfo(L.filename, L.linenumber, pos - L.lineStart)
|
||||
var info = newLineInfo(L.fileIdx, L.linenumber, pos - L.lineStart)
|
||||
msgs.GenericMessage(info, msg, arg)
|
||||
|
||||
proc TokKindToStr*(k: TTokKind): string =
|
||||
|
|
|
|||
|
|
@ -459,9 +459,7 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
|
|||
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
|
||||
else: InvalidCmdLineOption(pass, switch, info)
|
||||
|
||||
proc ProcessCommand(switch: string, pass: TCmdLinePass) =
|
||||
var
|
||||
cmd, arg: string
|
||||
var info = newLineInfo("command line", 1, 1)
|
||||
splitSwitch(switch, cmd, arg, pass, info)
|
||||
ProcessSwitch(cmd, arg, pass, info)
|
||||
proc ProcessCommand(switch: string, pass: TCmdLinePass) =
|
||||
var cmd, arg: string
|
||||
splitSwitch(switch, cmd, arg, pass, gCmdLineInfo)
|
||||
processSwitch(cmd, arg, pass, gCmdLineInfo)
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ proc addDotDependency(c: PPassContext, n: PNode): PNode =
|
|||
case n.kind
|
||||
of nkImportStmt:
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var imported = splitFile(getModuleFile(n.sons[i])).name
|
||||
var imported = getModuleName(n.sons[i])
|
||||
addDependencyAux(g.module.name.s, imported)
|
||||
of nkFromStmt:
|
||||
var imported = splitFile(getModuleFile(n.sons[0])).name
|
||||
var imported = getModuleName(n.sons[0])
|
||||
addDependencyAux(g.module.name.s, imported)
|
||||
of nkStmtList, nkBlockStmt, nkStmtListExpr, nkBlockExpr:
|
||||
for i in countup(0, sonsLen(n) - 1): discard addDotDependency(c, n.sons[i])
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
import
|
||||
ast, astalgo, strutils, hashes, options, nversion, msgs, os, ropes, idents,
|
||||
wordrecg, math, syntaxes, renderer, lexer, rst, times, highlite
|
||||
wordrecg, math, syntaxes, renderer, lexer, rst, times, highlite, importer
|
||||
|
||||
proc CommandDoc*()
|
||||
proc CommandRst2Html*()
|
||||
|
|
@ -760,21 +760,12 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
|
|||
proc checkForFalse(n: PNode): bool =
|
||||
result = n.kind == nkIdent and IdentEq(n.ident, "false")
|
||||
|
||||
proc getModuleFile(n: PNode): string =
|
||||
case n.kind
|
||||
of nkStrLit, nkRStrLit, nkTripleStrLit: result = n.strVal
|
||||
of nkIdent: result = n.ident.s
|
||||
of nkSym: result = n.sym.name.s
|
||||
else:
|
||||
internalError(n.info, "getModuleFile()")
|
||||
result = ""
|
||||
|
||||
proc traceDeps(d: PDoc, n: PNode) =
|
||||
const k = skModule
|
||||
if d.section[k] != nil: app(d.section[k], ", ")
|
||||
dispA(d.section[k],
|
||||
"<a class=\"reference external\" href=\"$1.html\">$1</a>",
|
||||
"$1", [toRope(getModuleFile(n))])
|
||||
"$1", [toRope(getModuleName(n))])
|
||||
|
||||
proc generateDoc(d: PDoc, n: PNode) =
|
||||
case n.kind
|
||||
|
|
|
|||
|
|
@ -16,26 +16,29 @@ import
|
|||
proc evalImport*(c: PContext, n: PNode): PNode
|
||||
proc evalFrom*(c: PContext, n: PNode): PNode
|
||||
proc importAllSymbols*(c: PContext, fromMod: PSym)
|
||||
proc getModuleFile*(n: PNode): string
|
||||
# implementation
|
||||
|
||||
proc findModule(info: TLineInfo, modulename: string): string =
|
||||
# returns path to module
|
||||
result = options.FindFile(AddFileExt(modulename, nimExt))
|
||||
if result == "": Fatal(info, errCannotOpenFile, modulename)
|
||||
|
||||
proc getModuleFile(n: PNode): string =
|
||||
proc getModuleName*(n: PNode): string =
|
||||
# This returns a short relative module name without the nim extension
|
||||
# e.g. like "system", "importer" or "somepath/module"
|
||||
# The proc won't perform any checks that the path is actually valid
|
||||
case n.kind
|
||||
of nkStrLit, nkRStrLit, nkTripleStrLit:
|
||||
result = findModule(n.info, UnixToNativePath(n.strVal))
|
||||
of nkIdent:
|
||||
result = findModule(n.info, n.ident.s)
|
||||
of nkSym:
|
||||
result = findModule(n.info, n.sym.name.s)
|
||||
else:
|
||||
internalError(n.info, "getModuleFile()")
|
||||
of nkStrLit, nkRStrLit, nkTripleStrLit:
|
||||
result = UnixToNativePath(n.strVal)
|
||||
of nkIdent:
|
||||
result = n.ident.s
|
||||
of nkSym:
|
||||
result = n.sym.name.s
|
||||
else:
|
||||
internalError(n.info, "getModuleName")
|
||||
result = ""
|
||||
|
||||
proc checkModuleName*(n: PNode): string =
|
||||
# This returns the full canonical path for a given module import
|
||||
var modulename = n.getModuleName
|
||||
result = findModule(modulename)
|
||||
if result.len == 0:
|
||||
Fatal(n.info, errCannotOpenFile, modulename)
|
||||
|
||||
proc rawImportSymbol(c: PContext, s: PSym) =
|
||||
# This does not handle stubs, because otherwise loading on demand would be
|
||||
# pointless in practice. So importing stubs is fine here!
|
||||
|
|
@ -103,7 +106,7 @@ proc importAllSymbols(c: PContext, fromMod: PSym) =
|
|||
proc evalImport(c: PContext, n: PNode): PNode =
|
||||
result = n
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var f = getModuleFile(n.sons[i])
|
||||
var f = checkModuleName(n.sons[i])
|
||||
var m = gImportModule(f)
|
||||
if sfDeprecated in m.flags:
|
||||
Message(n.sons[i].info, warnDeprecated, m.name.s)
|
||||
|
|
@ -114,7 +117,7 @@ proc evalImport(c: PContext, n: PNode): PNode =
|
|||
proc evalFrom(c: PContext, n: PNode): PNode =
|
||||
result = n
|
||||
checkMinSonsLen(n, 2)
|
||||
var f = getModuleFile(n.sons[0])
|
||||
var f = checkModuleName(n.sons[0])
|
||||
var m = gImportModule(f)
|
||||
n.sons[0] = newSymNode(m)
|
||||
addDecl(c, m) # add symbol to symbol table of module
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ type
|
|||
# documentation comments are here too
|
||||
|
||||
TLexer* = object of TBaseLexer
|
||||
filename*: string
|
||||
fileIdx*: int32
|
||||
indentStack*: seq[int] # the indentation stack
|
||||
dedent*: int # counter for DED token generation
|
||||
indentAhead*: int # if > 0 an indendation has already been read
|
||||
|
|
@ -198,7 +198,7 @@ proc fillToken(L: var TToken) =
|
|||
proc openLexer(lex: var TLexer, filename: string, inputstream: PLLStream) =
|
||||
openBaseLexer(lex, inputstream)
|
||||
lex.indentStack = @[0]
|
||||
lex.filename = filename
|
||||
lex.fileIdx = filename.fileInfoIdx
|
||||
lex.indentAhead = - 1
|
||||
inc(lex.Linenumber, inputstream.lineOffset)
|
||||
|
||||
|
|
@ -210,13 +210,13 @@ proc getColumn(L: TLexer): int =
|
|||
result = getColNumber(L, L.bufPos)
|
||||
|
||||
proc getLineInfo(L: TLexer): TLineInfo =
|
||||
result = newLineInfo(L.filename, L.linenumber, getColNumber(L, L.bufpos))
|
||||
result = newLineInfo(L.fileIdx, L.linenumber, getColNumber(L, L.bufpos))
|
||||
|
||||
proc lexMessage(L: TLexer, msg: TMsgKind, arg = "") =
|
||||
msgs.Message(getLineInfo(L), msg, arg)
|
||||
|
||||
proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
|
||||
var info = newLineInfo(L.filename, L.linenumber, pos - L.lineStart)
|
||||
var info = newLineInfo(L.fileIdx, L.linenumber, pos - L.lineStart)
|
||||
msgs.Message(info, msg, arg)
|
||||
|
||||
proc matchUnderscoreChars(L: var TLexer, tok: var TToken, chars: TCharSet) =
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ import
|
|||
os, lists, condsyms, rodread, rodwrite, ropes, trees,
|
||||
wordrecg, sem, semdata, idents, passes, docgen, extccomp,
|
||||
cgen, ecmasgen,
|
||||
platform, nimconf, importer, passaux, depends, transf, evals, types, idgen
|
||||
platform, nimconf, importer, passaux, depends, transf, evals, types, idgen,
|
||||
tables
|
||||
|
||||
const
|
||||
has_LLVM_Backend = false
|
||||
|
|
@ -27,19 +28,16 @@ proc MainCommand*()
|
|||
|
||||
# ------------------ module handling -----------------------------------------
|
||||
|
||||
type
|
||||
TFileModuleRec = tuple[filename: string, module: PSym]
|
||||
TFileModuleMap = seq[TFileModuleRec]
|
||||
var
|
||||
compMods = initTable[string, PSym]() # all compiled modules
|
||||
|
||||
var compMods: TFileModuleMap = @[] # all compiled modules
|
||||
# This expects a normalized module path
|
||||
proc registerModule(filename: string, module: PSym) =
|
||||
compMods[filename] = module
|
||||
|
||||
proc registerModule(filename: string, module: PSym) =
|
||||
compMods.add((filename, module))
|
||||
|
||||
proc getModule(filename: string): PSym =
|
||||
for i in countup(0, high(compMods)):
|
||||
if sameFile(compMods[i].filename, filename):
|
||||
return compMods[i].module
|
||||
# This expects a normalized module path
|
||||
proc getModule(filename: string): PSym =
|
||||
result = compMods[filename]
|
||||
|
||||
proc newModule(filename: string): PSym =
|
||||
# We cannot call ``newSym`` here, because we have to circumvent the ID
|
||||
|
|
@ -71,7 +69,7 @@ proc importModule(filename: string): PSym =
|
|||
proc CompileModule(filename: string, flags: TSymFlags): PSym =
|
||||
var rd: PRodReader = nil
|
||||
var f = addFileExt(filename, nimExt)
|
||||
result = newModule(filename)
|
||||
result = newModule(f)
|
||||
result.flags = result.flags + flags
|
||||
if gCmd in {cmdCompileToC, cmdCompileToCpp, cmdCheck, cmdIdeTools}:
|
||||
rd = handleSymbolFile(result, f)
|
||||
|
|
@ -178,7 +176,7 @@ proc CommandSuggest =
|
|||
|
||||
proc wantMainModule =
|
||||
if gProjectFull.len == 0:
|
||||
Fatal(newLineInfo("command line", 1, 1), errCommandExpectsFilename)
|
||||
Fatal(gCmdLineInfo, errCommandExpectsFilename)
|
||||
|
||||
proc MainCommand =
|
||||
appendStr(searchPaths, options.libpath)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#
|
||||
|
||||
import
|
||||
options, strutils, os
|
||||
options, strutils, os, tables
|
||||
|
||||
type
|
||||
TMsgKind* = enum
|
||||
|
|
@ -384,6 +384,11 @@ const
|
|||
type
|
||||
TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints
|
||||
TNoteKinds* = set[TNoteKind]
|
||||
|
||||
TFileInfo*{.final.} = object
|
||||
fullPath*: string # This is a canonical full filesystem path
|
||||
projPath*: string # This is relative to the project's root
|
||||
|
||||
TLineInfo*{.final.} = object # This is designed to be as small as possible,
|
||||
# because it is used
|
||||
# in syntax nodes. We safe space here by using
|
||||
|
|
@ -395,7 +400,45 @@ type
|
|||
|
||||
ERecoverableError* = object of EInvalidValue
|
||||
|
||||
proc newLineInfo*(filename: string, line, col: int): TLineInfo
|
||||
var
|
||||
filenameToIndexTbl = initTable[string, int32]()
|
||||
fileInfos: seq[TFileInfo] = @[]
|
||||
|
||||
proc newFileInfo(fullPath, projPath: string): TFileInfo =
|
||||
result.fullPath = fullPath
|
||||
result.projPath = projPath
|
||||
|
||||
proc fileInfoIdx*(filename: string): int32 =
|
||||
var
|
||||
canonical: string
|
||||
pseudoPath = false
|
||||
|
||||
try:
|
||||
canonical = canonicalizePath(filename)
|
||||
except:
|
||||
canonical = filename
|
||||
# The compiler uses "filenames" such as `command line` or `stdin`
|
||||
# This flag indicates that we are working with such a path here
|
||||
pseudoPath = true
|
||||
|
||||
if filenameToIndexTbl.hasKey(canonical):
|
||||
result = filenameToIndexTbl[canonical]
|
||||
else:
|
||||
result = fileInfos.len.int32
|
||||
fileInfos.add(newFileInfo(canonical, if pseudoPath: "" else: canonical.shortenDir))
|
||||
filenameToIndexTbl[canonical] = result
|
||||
|
||||
proc newLineInfo*(fileInfoIdx: int32, line, col: int): TLineInfo =
|
||||
result.fileIndex = fileInfoIdx
|
||||
result.line = int16(line)
|
||||
result.col = int16(col)
|
||||
|
||||
proc newLineInfo*(filename: string, line, col: int): TLineInfo {.inline.} =
|
||||
result = newLineInfo(filename.fileInfoIdx, line, col)
|
||||
|
||||
fileInfos.add(newFileInfo("", "command line"))
|
||||
var gCmdLineInfo* = newLineInfo(int32(0), 1, 1)
|
||||
|
||||
proc raiseRecoverableError*() {.noinline, noreturn.} =
|
||||
raise newException(ERecoverableError, "")
|
||||
|
||||
|
|
@ -423,9 +466,7 @@ proc UnknownLineInfo*(): TLineInfo =
|
|||
result.fileIndex = -1
|
||||
|
||||
var
|
||||
filenames: seq[tuple[filename: string, fullpath: string]] = @[]
|
||||
msgContext: seq[TLineInfo] = @[]
|
||||
gCmdLineInfo* = newLineInfo("command line", -1, -1)
|
||||
|
||||
proc pushInfoContext*(info: TLineInfo) =
|
||||
msgContext.add(info)
|
||||
|
|
@ -433,31 +474,13 @@ proc pushInfoContext*(info: TLineInfo) =
|
|||
proc popInfoContext*() =
|
||||
setlen(msgContext, len(msgContext) - 1)
|
||||
|
||||
proc includeFilename*(f: string): int =
|
||||
for i in countdown(high(filenames), low(filenames)):
|
||||
if filenames[i].filename == f:
|
||||
return i
|
||||
|
||||
result = len(filenames)
|
||||
|
||||
var fullpath: string
|
||||
try: fullpath = expandFilename(f)
|
||||
except: fullpath = ""
|
||||
|
||||
filenames.add((filename: f, fullpath: fullpath))
|
||||
|
||||
proc newLineInfo(filename: string, line, col: int): TLineInfo =
|
||||
result.fileIndex = includeFilename(filename)
|
||||
result.line = int16(line)
|
||||
result.col = int16(col)
|
||||
|
||||
proc ToFilename*(info: TLineInfo): string =
|
||||
proc ToFilename*(info: TLineInfo): string =
|
||||
if info.fileIndex < 0: result = "???"
|
||||
else: result = filenames[info.fileIndex].filename
|
||||
else: result = fileInfos[info.fileIndex].projPath
|
||||
|
||||
proc toFullPath*(info: TLineInfo): string =
|
||||
if info.fileIndex < 0: result = "???"
|
||||
else: result = filenames[info.fileIndex].fullpath
|
||||
else: result = fileInfos[info.fileIndex].fullPath
|
||||
|
||||
proc ToLinenumber*(info: TLineInfo): int {.inline.} =
|
||||
result = info.line
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
--hint[XDeclaredButNotUsed]=off
|
||||
path="llvm"
|
||||
path="$projectPath/.."
|
||||
|
||||
@if llvm_gcc or gcc:
|
||||
# GCC, LLVM and Visual C++ have a problem to optimize some modules.
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ proc HandleCmdLine() =
|
|||
ProcessCmdLine(passCmd1)
|
||||
if gProjectName != "":
|
||||
try:
|
||||
gProjectFull = expandFilename(gProjectName)
|
||||
gProjectFull = canonicalizePath(gProjectName)
|
||||
except EOS:
|
||||
gProjectFull = gProjectName
|
||||
var p = splitFile(gProjectFull)
|
||||
gProjectPath = p.dir
|
||||
gProjectName = p.name
|
||||
else:
|
||||
gProjectPath = getCurrentDir()
|
||||
gProjectPath = getCurrentDir()
|
||||
LoadConfigs(DefaultConfig) # load all config files
|
||||
# now process command line arguments again, because some options in the
|
||||
# command line can overwite the config file's settings
|
||||
|
|
|
|||
|
|
@ -138,12 +138,13 @@ proc getPrefixDir*(): string =
|
|||
## gets the application directory
|
||||
result = SplitPath(getAppDir()).head
|
||||
|
||||
proc canonicalizePath*(path: string): string =
|
||||
result = path.expandFilename
|
||||
when not FileSystemCaseSensitive: result = result.toLower
|
||||
|
||||
proc shortenDir*(dir: string): string =
|
||||
## returns the interesting part of a dir
|
||||
var prefix = getPrefixDir() & dirSep
|
||||
if startsWith(dir, prefix):
|
||||
return substr(dir, len(prefix))
|
||||
prefix = getCurrentDir() & dirSep
|
||||
if startsWith(dir, prefix):
|
||||
return substr(dir, len(prefix))
|
||||
prefix = gProjectPath & dirSep
|
||||
|
|
@ -185,21 +186,23 @@ iterator iterSearchPath*(): string =
|
|||
var it = PStrEntry(SearchPaths.head)
|
||||
while it != nil:
|
||||
yield it.data
|
||||
it = PStrEntry(it.Next)
|
||||
it = PStrEntry(it.Next)
|
||||
|
||||
proc rawFindFile(f: string): string =
|
||||
if ExistsFile(f):
|
||||
result = f
|
||||
else:
|
||||
for it in iterSearchPath():
|
||||
result = JoinPath(it, f)
|
||||
if ExistsFile(result): return
|
||||
result = ""
|
||||
proc rawFindFile(f: string): string =
|
||||
for it in iterSearchPath():
|
||||
result = JoinPath(it, f)
|
||||
if ExistsFile(result):
|
||||
return result.canonicalizePath
|
||||
result = ""
|
||||
|
||||
proc FindFile*(f: string): string =
|
||||
result = rawFindFile(f)
|
||||
if len(result) == 0: result = rawFindFile(toLower(f))
|
||||
|
||||
|
||||
proc findModule*(modulename: string): string {.inline.} =
|
||||
# returns path to module
|
||||
result = FindFile(AddFileExt(modulename, nimExt))
|
||||
|
||||
proc binaryStrSearch*(x: openarray[string], y: string): int =
|
||||
var a = 0
|
||||
var b = len(x) - 1
|
||||
|
|
|
|||
|
|
@ -576,7 +576,9 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
|
|||
L = 0
|
||||
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
|
||||
setlen(r.files, L + 1)
|
||||
r.files[L] = decodeStr(r.s, r.pos)
|
||||
var relativePath = decodeStr(r.s, r.pos)
|
||||
var resolvedPath = relativePath.findModule
|
||||
r.files[L] = if resolvedPath.len > 0: resolvedPath else: relativePath
|
||||
inc(r.pos) # skip #10
|
||||
inc(r.line)
|
||||
inc(L)
|
||||
|
|
@ -628,7 +630,8 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
|
|||
r.initIdx = r.pos + 2 # "(\10"
|
||||
skipSection(r)
|
||||
else:
|
||||
MsgWriteln("skipping section: " & $r.pos)
|
||||
MsgWriteln("skipping section: " & section &
|
||||
" at " & $r.pos & " in " & r.filename)
|
||||
skipSection(r)
|
||||
if r.s[r.pos] == '\x0A':
|
||||
inc(r.pos)
|
||||
|
|
@ -788,11 +791,11 @@ proc loadMethods(r: PRodReader) =
|
|||
|
||||
proc getModuleIdx(filename: string): int =
|
||||
for i in countup(0, high(gMods)):
|
||||
if sameFile(gMods[i].filename, filename): return i
|
||||
if gMods[i].filename == filename: return i
|
||||
result = len(gMods)
|
||||
setlen(gMods, result + 1)
|
||||
|
||||
proc checkDep(filename: string): TReasonForRecompile =
|
||||
proc checkDep(filename: string): TReasonForRecompile =
|
||||
assert(not isNil(filename))
|
||||
var idx = getModuleIdx(filename)
|
||||
if gMods[idx].reason != rrEmpty:
|
||||
|
|
@ -853,7 +856,7 @@ proc handleSymbolFile(module: PSym, filename: string): PRodReader =
|
|||
|
||||
proc GetCRC*(filename: string): TCrc32 =
|
||||
for i in countup(0, high(gMods)):
|
||||
if sameFile(gMods[i].filename, filename): return gMods[i].crc
|
||||
if gMods[i].filename == filename: return gMods[i].crc
|
||||
|
||||
result = crcFromFile(filename)
|
||||
#var idx = getModuleIdx(filename)
|
||||
|
|
|
|||
|
|
@ -87,17 +87,18 @@ proc newRodWriter(modfilename: string, crc: TCrc32, module: PSym): PRodWriter =
|
|||
result.init = ""
|
||||
result.data = newStringOfCap(12_000)
|
||||
|
||||
proc addModDep(w: PRodWriter, dep: string) =
|
||||
proc addModDep(w: PRodWriter, dep: string) =
|
||||
if w.modDeps.len != 0: add(w.modDeps, ' ')
|
||||
encodeVInt(fileIdx(w, dep), w.modDeps)
|
||||
|
||||
const
|
||||
rodNL = "\x0A"
|
||||
|
||||
proc addInclDep(w: PRodWriter, dep: string) =
|
||||
proc addInclDep(w: PRodWriter, dep: string) =
|
||||
var resolved = dep.findModule
|
||||
encodeVInt(fileIdx(w, dep), w.inclDeps)
|
||||
add(w.inclDeps, " ")
|
||||
encodeVInt(crcFromFile(dep), w.inclDeps)
|
||||
encodeVInt(crcFromFile(resolved), w.inclDeps)
|
||||
add(w.inclDeps, rodNL)
|
||||
|
||||
proc pushType(w: PRodWriter, t: PType) =
|
||||
|
|
@ -555,21 +556,21 @@ proc process(c: PPassContext, n: PNode): PNode =
|
|||
# addInterfaceSym(w, a.sons[j].sym);
|
||||
# end
|
||||
of nkImportStmt:
|
||||
for i in countup(0, sonsLen(n) - 1): addModDep(w, getModuleFile(n.sons[i]))
|
||||
for i in countup(0, sonsLen(n) - 1): addModDep(w, getModuleName(n.sons[i]))
|
||||
addStmt(w, n)
|
||||
of nkFromStmt:
|
||||
addModDep(w, getModuleFile(n.sons[0]))
|
||||
addModDep(w, getModuleName(n.sons[0]))
|
||||
addStmt(w, n)
|
||||
of nkIncludeStmt:
|
||||
for i in countup(0, sonsLen(n) - 1): addInclDep(w, getModuleFile(n.sons[i]))
|
||||
for i in countup(0, sonsLen(n) - 1): addInclDep(w, getModuleName(n.sons[i]))
|
||||
of nkPragma:
|
||||
addStmt(w, n)
|
||||
else:
|
||||
nil
|
||||
|
||||
proc myOpen(module: PSym, filename: string): PPassContext =
|
||||
proc myOpen(module: PSym, filename: string): PPassContext =
|
||||
if module.id < 0: InternalError("rodwrite: module ID not set")
|
||||
var w = newRodWriter(filename, rodread.GetCRC(filename), module)
|
||||
var w = newRodWriter(filename, rodread.GetCRC(module.info.toFullPath), module)
|
||||
rawAddInterfaceSym(w, module)
|
||||
result = w
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
|||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
removeDefaultParamValues(n.sons[ParamsPos])
|
||||
semParamList(c, n.sons[ParamsPos], nil, result)
|
||||
addParams(c, result.typ.n)
|
||||
# XXX: obsoleted - happens in semParamList #
|
||||
# addParams(c, result.typ.n)
|
||||
else:
|
||||
result.typ = newTypeS(tyProc, c)
|
||||
addSon(result.typ, nil)
|
||||
|
|
|
|||
|
|
@ -616,7 +616,8 @@ proc semLambda(c: PContext, n: PNode): PNode =
|
|||
illFormedAst(n) # process parameters:
|
||||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
||||
addParams(c, s.typ.n)
|
||||
# XXX: obsoleted - happens in semParamList
|
||||
# addParams(c, s.typ.n)
|
||||
ParamsTypeCheck(c, s.typ)
|
||||
else:
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
|
|
@ -665,7 +666,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
|||
n.sons[genericParamsPos] = gp
|
||||
# check for semantics again:
|
||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
||||
addParams(c, s.typ.n)
|
||||
# XXX: obsoleted - happens in semParamList
|
||||
# addParams(c, s.typ.n)
|
||||
else:
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
addSon(s.typ, nil)
|
||||
|
|
@ -795,8 +797,8 @@ proc evalInclude(c: PContext, n: PNode): PNode =
|
|||
result = newNodeI(nkStmtList, n.info)
|
||||
addSon(result, n)
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var f = getModuleFile(n.sons[i])
|
||||
var fileIndex = includeFilename(f)
|
||||
var f = checkModuleName(n.sons[i])
|
||||
var fileIndex = f.fileInfoIdx
|
||||
if ContainsOrIncl(c.includedFiles, fileIndex):
|
||||
GlobalError(n.info, errRecursiveDependencyX, f)
|
||||
addSon(result, semStmt(c, gIncludeFile(f)))
|
||||
|
|
|
|||
|
|
@ -185,7 +185,8 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
# use ``stmt`` as implicit result type
|
||||
s.typ.sons[0] = newTypeS(tyStmt, c)
|
||||
s.typ.n.sons[0] = newNodeIT(nkType, n.info, s.typ.sons[0])
|
||||
addParams(c, s.typ.n) # resolve parameters:
|
||||
# XXX: obsoleted - happens in semParamList #
|
||||
# addParams(c, s.typ.n) # resolve parameters:
|
||||
var toBind = initIntSet()
|
||||
n.sons[bodyPos] = resolveTemplateParams(c, n.sons[bodyPos], false, toBind)
|
||||
if s.typ.sons[0].kind notin {tyStmt, tyTypeDesc}:
|
||||
|
|
|
|||
|
|
@ -569,6 +569,8 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
|||
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
||||
addSon(result.n, newSymNode(arg))
|
||||
addSon(result, typ)
|
||||
addDecl(c, arg)
|
||||
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
var r = paramType(c, n.sons[0], genericParams, cl)
|
||||
# turn explicit 'void' return type into 'nil' because the rest of the
|
||||
|
|
@ -711,11 +713,13 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
|||
of nkDistinctTy: result = semDistinct(c, n, prev)
|
||||
of nkProcTy:
|
||||
checkSonsLen(n, 2)
|
||||
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
||||
openScope(c.tab)
|
||||
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
||||
# dummy symbol for `pragma`:
|
||||
var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c)
|
||||
s.typ = result
|
||||
pragma(c, s, n.sons[1], procTypePragmas)
|
||||
closeScope(c.tab)
|
||||
of nkEnumTy: result = semEnum(c, n, prev)
|
||||
of nkType: result = n.typ
|
||||
of nkStmtListType: result = semStmtListType(c, n, prev)
|
||||
|
|
|
|||
|
|
@ -713,7 +713,7 @@ proc matches*(c: PContext, n: PNode, m: var TCandidate) =
|
|||
|
||||
when false:
|
||||
if sfSystemModule notin c.module.flags:
|
||||
if includeFilename("temp.nim") == c.module.info.fileIndex:
|
||||
if fileInfoIdx("temp.nim") == c.module.info.fileIndex:
|
||||
echo "########################"
|
||||
echo m.call.renderTree
|
||||
for i in 1..m.call.len-1:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue