updated the compiler to use the new symbol names

This commit is contained in:
Araq 2014-08-28 23:48:42 +02:00
commit 5946747970
30 changed files with 307 additions and 114 deletions

View file

@ -16,9 +16,9 @@ type
TAnalysisResult* = enum TAnalysisResult* = enum
arNo, arMaybe, arYes arNo, arMaybe, arYes
proc isPartOfAux(a, b: PType, marker: var TIntSet): TAnalysisResult proc isPartOfAux(a, b: PType, marker: var IntSet): TAnalysisResult
proc isPartOfAux(n: PNode, b: PType, marker: var TIntSet): TAnalysisResult = proc isPartOfAux(n: PNode, b: PType, marker: var IntSet): TAnalysisResult =
result = arNo result = arNo
case n.kind case n.kind
of nkRecList: of nkRecList:
@ -39,7 +39,7 @@ proc isPartOfAux(n: PNode, b: PType, marker: var TIntSet): TAnalysisResult =
result = isPartOfAux(n.sym.typ, b, marker) result = isPartOfAux(n.sym.typ, b, marker)
else: internalError(n.info, "isPartOfAux()") else: internalError(n.info, "isPartOfAux()")
proc isPartOfAux(a, b: PType, marker: var TIntSet): TAnalysisResult = proc isPartOfAux(a, b: PType, marker: var IntSet): TAnalysisResult =
result = arNo result = arNo
if a == nil or b == nil: return if a == nil or b == nil: return
if containsOrIncl(marker, a.id): return if containsOrIncl(marker, a.id): return

View file

@ -245,13 +245,13 @@ proc lineInfoToStr(info: TLineInfo): PRope =
toRope(toLinenumber(info)), toRope(toLinenumber(info)),
toRope(toColumn(info))]) toRope(toColumn(info))])
proc treeToYamlAux(n: PNode, marker: var TIntSet, proc treeToYamlAux(n: PNode, marker: var IntSet,
indent, maxRecDepth: int): PRope indent, maxRecDepth: int): PRope
proc symToYamlAux(n: PSym, marker: var TIntSet, proc symToYamlAux(n: PSym, marker: var IntSet,
indent, maxRecDepth: int): PRope indent, maxRecDepth: int): PRope
proc typeToYamlAux(n: PType, marker: var TIntSet, proc typeToYamlAux(n: PType, marker: var IntSet,
indent, maxRecDepth: int): PRope indent, maxRecDepth: int): PRope
proc strTableToYaml(n: TStrTable, marker: var TIntSet, indent: int, proc strTableToYaml(n: TStrTable, marker: var IntSet, indent: int,
maxRecDepth: int): PRope = maxRecDepth: int): PRope =
var istr = spaces(indent + 2) var istr = spaces(indent + 2)
result = toRope("[") result = toRope("[")
@ -277,7 +277,7 @@ proc ropeConstr(indent: int, c: openArray[PRope]): PRope =
inc(i, 2) inc(i, 2)
appf(result, "$N$1}", [spaces(indent)]) appf(result, "$N$1}", [spaces(indent)])
proc symToYamlAux(n: PSym, marker: var TIntSet, indent: int, proc symToYamlAux(n: PSym, marker: var IntSet, indent: int,
maxRecDepth: int): PRope = maxRecDepth: int): PRope =
if n == nil: if n == nil:
result = toRope("null") result = toRope("null")
@ -298,7 +298,7 @@ proc symToYamlAux(n: PSym, marker: var TIntSet, indent: int,
flagsToStr(n.options), toRope("position"), flagsToStr(n.options), toRope("position"),
toRope(n.position)]) toRope(n.position)])
proc typeToYamlAux(n: PType, marker: var TIntSet, indent: int, proc typeToYamlAux(n: PType, marker: var IntSet, indent: int,
maxRecDepth: int): PRope = maxRecDepth: int): PRope =
if n == nil: if n == nil:
result = toRope("null") result = toRope("null")
@ -326,7 +326,7 @@ proc typeToYamlAux(n: PType, marker: var TIntSet, indent: int,
toRope("align"), toRope(n.align), toRope("align"), toRope(n.align),
toRope("sons"), result]) toRope("sons"), result])
proc treeToYamlAux(n: PNode, marker: var TIntSet, indent: int, proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
maxRecDepth: int): PRope = maxRecDepth: int): PRope =
if n == nil: if n == nil:
result = toRope("null") result = toRope("null")
@ -677,7 +677,7 @@ proc nextIdentIter(ti: var TIdentIter, tab: TStrTable): PSym =
ti.h = nextTry(h, high(tab.data)) ti.h = nextTry(h, high(tab.data))
proc nextIdentExcluding*(ti: var TIdentIter, tab: TStrTable, proc nextIdentExcluding*(ti: var TIdentIter, tab: TStrTable,
excluding: TIntSet): PSym = excluding: IntSet): PSym =
var h: THash = ti.h and high(tab.data) var h: THash = ti.h and high(tab.data)
var start = h var start = h
result = tab.data[h] result = tab.data[h]
@ -693,7 +693,7 @@ proc nextIdentExcluding*(ti: var TIdentIter, tab: TStrTable,
if result != nil and contains(excluding, result.id): result = nil if result != nil and contains(excluding, result.id): result = nil
proc firstIdentExcluding*(ti: var TIdentIter, tab: TStrTable, s: PIdent, proc firstIdentExcluding*(ti: var TIdentIter, tab: TStrTable, s: PIdent,
excluding: TIntSet): PSym = excluding: IntSet): PSym =
ti.h = s.h ti.h = s.h
ti.name = s ti.name = s
if tab.counter == 0: result = nil if tab.counter == 0: result = nil

View file

@ -43,7 +43,7 @@ proc `<.`(a, b: string): bool =
if a[i] == '.': inc i if a[i] == '.': inc i
if b[j] == '.': inc j if b[j] == '.': inc j
proc addPackage(packages: PStringTable, p: string) = proc addPackage(packages: StringTableRef, p: string) =
let x = versionSplitPos(p) let x = versionSplitPos(p)
let name = p.substr(0, x-1) let name = p.substr(0, x-1)
if x < p.len: if x < p.len:
@ -53,7 +53,7 @@ proc addPackage(packages: PStringTable, p: string) =
else: else:
packages[name] = latest packages[name] = latest
iterator chosen(packages: PStringTable): string = iterator chosen(packages: StringTableRef): string =
for key, val in pairs(packages): for key, val in pairs(packages):
let res = if val == latest: key else: key & '-' & val let res = if val == latest: key else: key & '-' & val
yield res yield res

View file

@ -83,7 +83,7 @@ proc writeTypeCache(a: TIdTable, s: var string) =
inc i inc i
s.add('}') s.add('}')
proc writeIntSet(a: TIntSet, s: var string) = proc writeIntSet(a: IntSet, s: var string) =
var i = 0 var i = 0
for x in items(a): for x in items(a):
if i == 10: if i == 10:
@ -200,7 +200,7 @@ proc readTypeCache(L: var TBaseLexer, result: var TIdTable) =
idTablePut(result, newFakeType(key), value.toRope) idTablePut(result, newFakeType(key), value.toRope)
inc L.bufpos inc L.bufpos
proc readIntSet(L: var TBaseLexer, result: var TIntSet) = proc readIntSet(L: var TBaseLexer, result: var IntSet) =
if ^L.bufpos != '{': internalError("ccgmerge: '{' expected") if ^L.bufpos != '{': internalError("ccgmerge: '{' expected")
inc L.bufpos inc L.bufpos
while ^L.bufpos != '}': while ^L.bufpos != '}':

View file

@ -162,7 +162,7 @@ proc mapReturnType(typ: PType): TCTypeKind =
if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr
else: result = mapType(typ) else: result = mapType(typ)
proc getTypeDescAux(m: BModule, typ: PType, check: var TIntSet): PRope proc getTypeDescAux(m: BModule, typ: PType, check: var IntSet): PRope
proc needsComplexAssignment(typ: PType): bool = proc needsComplexAssignment(typ: PType): bool =
result = containsGarbageCollectedRef(typ) result = containsGarbageCollectedRef(typ)
@ -228,7 +228,7 @@ proc fillResult(param: PSym) =
incl(param.loc.flags, lfIndirect) incl(param.loc.flags, lfIndirect)
param.loc.s = OnUnknown param.loc.s = OnUnknown
proc getParamTypeDesc(m: BModule, t: PType, check: var TIntSet): PRope = proc getParamTypeDesc(m: BModule, t: PType, check: var IntSet): PRope =
when false: when false:
if t.Kind in {tyRef, tyPtr, tyVar}: if t.Kind in {tyRef, tyPtr, tyVar}:
var b = skipTypes(t.lastson, typedescInst) var b = skipTypes(t.lastson, typedescInst)
@ -243,7 +243,7 @@ proc paramStorageLoc(param: PSym): TStorageLoc =
result = OnUnknown result = OnUnknown
proc genProcParams(m: BModule, t: PType, rettype, params: var PRope, proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
check: var TIntSet, declareEnvironment=true) = check: var IntSet, declareEnvironment=true) =
params = nil params = nil
if (t.sons[0] == nil) or isInvalidReturnType(t.sons[0]): if (t.sons[0] == nil) or isInvalidReturnType(t.sons[0]):
rettype = ~"void" rettype = ~"void"
@ -370,7 +370,7 @@ proc mangleRecFieldName(field: PSym, rectype: PType): PRope =
proc genRecordFieldsAux(m: BModule, n: PNode, proc genRecordFieldsAux(m: BModule, n: PNode,
accessExpr: PRope, rectype: PType, accessExpr: PRope, rectype: PType,
check: var TIntSet): PRope = check: var IntSet): PRope =
var var
ae, uname, sname, a: PRope ae, uname, sname, a: PRope
k: PNode k: PNode
@ -419,11 +419,11 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
appf(result, "$1 $2;$n", [getTypeDescAux(m, fieldType, check), sname]) appf(result, "$1 $2;$n", [getTypeDescAux(m, fieldType, check), sname])
else: internalError(n.info, "genRecordFieldsAux()") else: internalError(n.info, "genRecordFieldsAux()")
proc getRecordFields(m: BModule, typ: PType, check: var TIntSet): PRope = proc getRecordFields(m: BModule, typ: PType, check: var IntSet): PRope =
result = genRecordFieldsAux(m, typ.n, nil, typ, check) result = genRecordFieldsAux(m, typ.n, nil, typ, check)
proc getRecordDesc(m: BModule, typ: PType, name: PRope, proc getRecordDesc(m: BModule, typ: PType, name: PRope,
check: var TIntSet): PRope = check: var IntSet): PRope =
# declare the record: # declare the record:
var hasField = false var hasField = false
@ -461,7 +461,7 @@ proc getRecordDesc(m: BModule, typ: PType, name: PRope,
app(result, "};" & tnl) app(result, "};" & tnl)
proc getTupleDesc(m: BModule, typ: PType, name: PRope, proc getTupleDesc(m: BModule, typ: PType, name: PRope,
check: var TIntSet): PRope = check: var IntSet): PRope =
result = ropef("$1 $2 {$n", [structOrUnion(typ), name]) result = ropef("$1 $2 {$n", [structOrUnion(typ), name])
var desc: PRope = nil var desc: PRope = nil
for i in countup(0, sonsLen(typ) - 1): for i in countup(0, sonsLen(typ) - 1):
@ -474,7 +474,7 @@ proc getTupleDesc(m: BModule, typ: PType, name: PRope,
proc pushType(m: BModule, typ: PType) = proc pushType(m: BModule, typ: PType) =
add(m.typeStack, typ) add(m.typeStack, typ)
proc getTypeDescAux(m: BModule, typ: PType, check: var TIntSet): PRope = proc getTypeDescAux(m: BModule, typ: PType, check: var IntSet): PRope =
# returns only the type's name # returns only the type's name
var var
name, rettype, desc, recdesc: PRope name, rettype, desc, recdesc: PRope

View file

@ -101,10 +101,10 @@ type
# without extension) # without extension)
typeCache*: TIdTable # cache the generated types typeCache*: TIdTable # cache the generated types
forwTypeCache*: TIdTable # cache for forward declarations of types forwTypeCache*: TIdTable # cache for forward declarations of types
declaredThings*: TIntSet # things we have declared in this .c file declaredThings*: IntSet # things we have declared in this .c file
declaredProtos*: TIntSet # prototypes we have declared in this .c file declaredProtos*: IntSet # prototypes we have declared in this .c file
headerFiles*: TLinkedList # needed headers to include headerFiles*: TLinkedList # needed headers to include
typeInfoMarker*: TIntSet # needed for generating type information typeInfoMarker*: IntSet # needed for generating type information
initProc*: BProc # code for init procedure initProc*: BProc # code for init procedure
postInitProc*: BProc # code to be executed after the init proc postInitProc*: BProc # code to be executed after the init proc
preInitProc*: BProc # code executed before the init proc preInitProc*: BProc # code executed before the init proc

View file

@ -115,7 +115,7 @@ proc relevantCol(methods: TSymSeq, col: int): bool =
if not sameType(t2, t): if not sameType(t2, t):
return true return true
proc cmpSignatures(a, b: PSym, relevantCols: TIntSet): int = proc cmpSignatures(a, b: PSym, relevantCols: IntSet): int =
for col in countup(1, sonsLen(a.typ) - 1): for col in countup(1, sonsLen(a.typ) - 1):
if contains(relevantCols, col): if contains(relevantCols, col):
var aa = skipTypes(a.typ.sons[col], skipPtrs) var aa = skipTypes(a.typ.sons[col], skipPtrs)
@ -124,7 +124,7 @@ proc cmpSignatures(a, b: PSym, relevantCols: TIntSet): int =
if (d != high(int)): if (d != high(int)):
return d return d
proc sortBucket(a: var TSymSeq, relevantCols: TIntSet) = proc sortBucket(a: var TSymSeq, relevantCols: IntSet) =
# we use shellsort here; fast and simple # we use shellsort here; fast and simple
var n = len(a) var n = len(a)
var h = 1 var h = 1
@ -143,7 +143,7 @@ proc sortBucket(a: var TSymSeq, relevantCols: TIntSet) =
a[j] = v a[j] = v
if h == 1: break if h == 1: break
proc genDispatcher(methods: TSymSeq, relevantCols: TIntSet): PSym = proc genDispatcher(methods: TSymSeq, relevantCols: IntSet): PSym =
var base = lastSon(methods[0].ast).sym var base = lastSon(methods[0].ast).sym
result = base result = base
var paramLen = sonsLen(base.typ) var paramLen = sonsLen(base.typ)

View file

@ -14,7 +14,7 @@ import
# We need to use a PStringTable here as defined symbols are always guaranteed # We need to use a PStringTable here as defined symbols are always guaranteed
# to be style insensitive. Otherwise hell would break lose. # to be style insensitive. Otherwise hell would break lose.
var gSymbols: PStringTable var gSymbols: StringTableRef
proc defineSymbol*(symbol: string) = proc defineSymbol*(symbol: string) =
gSymbols[symbol] = "true" gSymbols[symbol] = "true"

View file

@ -23,7 +23,7 @@ type
id: int # for generating IDs id: int # for generating IDs
toc, section: TSections toc, section: TSections
indexValFilename: string indexValFilename: string
seenSymbols: PStringTable # avoids duplicate symbol generation for HTML. seenSymbols: StringTableRef # avoids duplicate symbol generation for HTML.
PDoc* = ref TDocumentor ## Alias to type less. PDoc* = ref TDocumentor ## Alias to type less.
@ -55,7 +55,7 @@ proc parseRst(text, filename: string,
result = rstParse(text, filename, line, column, hasToc, rstOptions, result = rstParse(text, filename, line, column, hasToc, rstOptions,
docgenFindFile, compilerMsgHandler) docgenFindFile, compilerMsgHandler)
proc newDocumentor*(filename: string, config: PStringTable): PDoc = proc newDocumentor*(filename: string, config: StringTableRef): PDoc =
new(result) new(result)
initRstGenerator(result[], (if gCmd != cmdRst2tex: outHtml else: outLatex), initRstGenerator(result[], (if gCmd != cmdRst2tex: outHtml else: outLatex),
options.gConfigVars, filename, {roSupportRawDirective}, options.gConfigVars, filename, {roSupportRawDirective},
@ -411,7 +411,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) =
setIndexTerm(d[], symbolOrId, name, linkTitle, setIndexTerm(d[], symbolOrId, name, linkTitle,
xmltree.escape(plainDocstring.docstringSummary)) xmltree.escape(plainDocstring.docstringSummary))
proc genJSONItem(d: PDoc, n, nameNode: PNode, k: TSymKind): PJsonNode = proc genJSONItem(d: PDoc, n, nameNode: PNode, k: TSymKind): JsonNode =
if not isVisible(nameNode): return if not isVisible(nameNode): return
var var
name = getName(d, nameNode) name = getName(d, nameNode)
@ -471,7 +471,7 @@ proc generateDoc*(d: PDoc, n: PNode) =
of nkFromStmt, nkImportExceptStmt: traceDeps(d, n.sons[0]) of nkFromStmt, nkImportExceptStmt: traceDeps(d, n.sons[0])
else: discard else: discard
proc generateJson(d: PDoc, n: PNode, jArray: PJsonNode = nil): PJsonNode = proc generateJson(d: PDoc, n: PNode, jArray: JsonNode = nil): JsonNode =
case n.kind case n.kind
of nkCommentStmt: of nkCommentStmt:
if n.comment != nil and startsWith(n.comment, "##"): if n.comment != nil and startsWith(n.comment, "##"):

View file

@ -113,7 +113,7 @@ proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
e = nextIdentIter(it, fromMod.tab) e = nextIdentIter(it, fromMod.tab)
else: rawImportSymbol(c, s) else: rawImportSymbol(c, s)
proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: TIntSet) = proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) =
var i: TTabIter var i: TTabIter
var s = initTabIter(i, fromMod.tab) var s = initTabIter(i, fromMod.tab)
while s != nil: while s != nil:
@ -126,10 +126,10 @@ proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: TIntSet) =
s = nextIter(i, fromMod.tab) s = nextIter(i, fromMod.tab)
proc importAllSymbols*(c: PContext, fromMod: PSym) = proc importAllSymbols*(c: PContext, fromMod: PSym) =
var exceptSet: TIntSet var exceptSet: IntSet
importAllSymbolsExcept(c, fromMod, exceptSet) importAllSymbolsExcept(c, fromMod, exceptSet)
proc importForwarded(c: PContext, n: PNode, exceptSet: TIntSet) = proc importForwarded(c: PContext, n: PNode, exceptSet: IntSet) =
if n.isNil: return if n.isNil: return
case n.kind case n.kind
of nkExportStmt: of nkExportStmt:
@ -164,7 +164,7 @@ proc myImportModule(c: PContext, n: PNode): PSym =
proc evalImport(c: PContext, n: PNode): PNode = proc evalImport(c: PContext, n: PNode): PNode =
result = n result = n
var emptySet: TIntSet var emptySet: IntSet
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
var m = myImportModule(c, n.sons[i]) var m = myImportModule(c, n.sons[i])
if m != nil: if m != nil:

View file

@ -71,8 +71,8 @@ type
TGlobals = object TGlobals = object
typeInfo, code: PRope typeInfo, code: PRope
forwarded: seq[PSym] forwarded: seq[PSym]
generatedSyms: TIntSet generatedSyms: IntSet
typeInfoGenerated: TIntSet typeInfoGenerated: IntSet
PGlobals = ref TGlobals PGlobals = ref TGlobals
PProc = ref TProc PProc = ref TProc

View file

@ -140,12 +140,12 @@ type
fn: PSym # function that belongs to this scope; fn: PSym # function that belongs to this scope;
# if up.fn != fn then we cross function boundaries. # if up.fn != fn then we cross function boundaries.
# This is an important case to consider. # This is an important case to consider.
vars: TIntSet # variables belonging to this environment vars: IntSet # variables belonging to this environment
TOuterContext = object TOuterContext = object
fn: PSym # may also be a module! fn: PSym # may also be a module!
head: PEnv head: PEnv
capturedVars, processed: TIntSet capturedVars, processed: IntSet
localsToAccess: TIdNodeTable localsToAccess: TIdNodeTable
lambdasToEnv: TIdTable # PSym->PEnv mapping lambdasToEnv: TIdTable # PSym->PEnv mapping

View file

@ -21,10 +21,10 @@ import
const const
MaxLineLength* = 80 # lines longer than this lead to a warning MaxLineLength* = 80 # lines longer than this lead to a warning
numChars*: TCharSet = {'0'..'9', 'a'..'z', 'A'..'Z'} numChars*: set[char] = {'0'..'9', 'a'..'z', 'A'..'Z'}
SymChars*: TCharSet = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF'} SymChars*: set[char] = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF'}
SymStartChars*: TCharSet = {'a'..'z', 'A'..'Z', '\x80'..'\xFF'} SymStartChars*: set[char] = {'a'..'z', 'A'..'Z', '\x80'..'\xFF'}
OpChars*: TCharSet = {'+', '-', '*', '/', '\\', '<', '>', '!', '?', '^', '.', OpChars*: set[char] = {'+', '-', '*', '/', '\\', '<', '>', '!', '?', '^', '.',
'|', '=', '%', '&', '$', '@', '~', ':', '\x80'..'\xFF'} '|', '=', '%', '&', '$', '@', '~', ':', '\x80'..'\xFF'}
# don't forget to update the 'highlite' module if these charsets should change # don't forget to update the 'highlite' module if these charsets should change
@ -229,7 +229,7 @@ proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
var info = newLineInfo(L.fileIdx, L.lineNumber, pos - L.lineStart) var info = newLineInfo(L.fileIdx, L.lineNumber, pos - L.lineStart)
msgs.message(info, msg, arg) msgs.message(info, msg, arg)
proc matchUnderscoreChars(L: var TLexer, tok: var TToken, chars: TCharSet) = proc matchUnderscoreChars(L: var TLexer, tok: var TToken, chars: set[char]) =
var pos = L.bufpos # use registers for pos, buf var pos = L.bufpos # use registers for pos, buf
var buf = L.buf var buf = L.buf
while true: while true:
@ -246,7 +246,7 @@ proc matchUnderscoreChars(L: var TLexer, tok: var TToken, chars: TCharSet) =
inc(pos) inc(pos)
L.bufpos = pos L.bufpos = pos
proc matchTwoChars(L: TLexer, first: char, second: TCharSet): bool = proc matchTwoChars(L: TLexer, first: char, second: set[char]): bool =
result = (L.buf[L.bufpos] == first) and (L.buf[L.bufpos + 1] in second) result = (L.buf[L.bufpos] == first) and (L.buf[L.bufpos + 1] in second)
proc isFloatLiteral(s: string): bool = proc isFloatLiteral(s: string): bool =

View file

@ -40,11 +40,8 @@ proc considerQuotedIdent*(n: PNode): PIdent =
template addSym*(scope: PScope, s: PSym) = template addSym*(scope: PScope, s: PSym) =
strTableAdd(scope.symbols, s) strTableAdd(scope.symbols, s)
proc addUniqueSym*(scope: PScope, s: PSym): TResult = proc addUniqueSym*(scope: PScope, s: PSym): bool =
if strTableIncl(scope.symbols, s): result = not strTableIncl(scope.symbols, s)
result = Failure
else:
result = Success
proc openScope*(c: PContext): PScope {.discardable.} = proc openScope*(c: PContext): PScope {.discardable.} =
result = PScope(parent: c.currentScope, result = PScope(parent: c.currentScope,
@ -117,7 +114,7 @@ type
mode*: TOverloadIterMode mode*: TOverloadIterMode
symChoiceIndex*: int symChoiceIndex*: int
scope*: PScope scope*: PScope
inSymChoice: TIntSet inSymChoice: IntSet
proc getSymRepr*(s: PSym): string = proc getSymRepr*(s: PSym): string =
case s.kind case s.kind
@ -150,14 +147,14 @@ proc wrongRedefinition*(info: TLineInfo, s: string) =
localError(info, errAttemptToRedefine, s) localError(info, errAttemptToRedefine, s)
proc addDecl*(c: PContext, sym: PSym) = proc addDecl*(c: PContext, sym: PSym) =
if c.currentScope.addUniqueSym(sym) == Failure: if not c.currentScope.addUniqueSym(sym):
wrongRedefinition(sym.info, sym.name.s) wrongRedefinition(sym.info, sym.name.s)
proc addPrelimDecl*(c: PContext, sym: PSym) = proc addPrelimDecl*(c: PContext, sym: PSym) =
discard c.currentScope.addUniqueSym(sym) discard c.currentScope.addUniqueSym(sym)
proc addDeclAt*(scope: PScope, sym: PSym) = proc addDeclAt*(scope: PScope, sym: PSym) =
if scope.addUniqueSym(sym) == Failure: if not scope.addUniqueSym(sym):
wrongRedefinition(sym.info, sym.name.s) wrongRedefinition(sym.info, sym.name.s)
proc addInterfaceDeclAux(c: PContext, sym: PSym) = proc addInterfaceDeclAux(c: PContext, sym: PSym) =

View file

@ -567,7 +567,7 @@ var
gErrorMax*: int = 1 # stop after gErrorMax errors gErrorMax*: int = 1 # stop after gErrorMax errors
when useCaas: when useCaas:
var stdoutSocket*: TSocket var stdoutSocket*: Socket
proc unknownLineInfo*(): TLineInfo = proc unknownLineInfo*(): TLineInfo =
result.line = int16(-1) result.line = int16(-1)

View file

@ -137,7 +137,7 @@ type
line: int # only used for debugging, but is always in the code line: int # only used for debugging, but is always in the code
moduleID: int moduleID: int
syms: TIdTable # already processed symbols syms: TIdTable # already processed symbols
memfile: TMemFile # unfortunately there is no point in time where we memfile: MemFile # unfortunately there is no point in time where we
# can close this! XXX # can close this! XXX
methods*: TSymSeq methods*: TSymSeq
origFile: string origFile: string

View file

@ -340,7 +340,7 @@ type
TSemGenericFlags = set[TSemGenericFlag] TSemGenericFlags = set[TSemGenericFlag]
proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags, proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags,
ctx: var TIntSet): PNode ctx: var IntSet): PNode
include semtypes, semtempl, semgnrc, semstmts, semexprs include semtypes, semtempl, semgnrc, semstmts, semexprs

196
compiler/semasgn.nim Normal file
View file

@ -0,0 +1,196 @@
#
#
# The Nim Compiler
# (c) Copyright 2014 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module implements lifting for assignments and ``deepCopy``.
# included from sem.nim
type
TLiftCtx = object
c: PContext
info: TLineInfo # for construction
result: PNode
kind: TTypeAttachedOp
type
TFieldInstCtx = object # either 'tup[i]' or 'field' is valid
tupleType: PType # if != nil we're traversing a tuple
tupleIndex: int
field: PSym
replaceByFieldName: bool
proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
case n.kind
of nkEmpty..pred(nkIdent), succ(nkIdent)..nkNilLit: result = n
of nkIdent:
result = n
var L = sonsLen(forLoop)
if c.replaceByFieldName:
if n.ident.id == forLoop[0].ident.id:
let fieldName = if c.tupleType.isNil: c.field.name.s
elif c.tupleType.n.isNil: "Field" & $c.tupleIndex
else: c.tupleType.n.sons[c.tupleIndex].sym.name.s
result = newStrNode(nkStrLit, fieldName)
return
# other fields:
for i in ord(c.replaceByFieldName)..L-3:
if n.ident.id == forLoop[i].ident.id:
var call = forLoop.sons[L-2]
var tupl = call.sons[i+1-ord(c.replaceByFieldName)]
if c.field.isNil:
result = newNodeI(nkBracketExpr, n.info)
result.add(tupl)
result.add(newIntNode(nkIntLit, c.tupleIndex))
else:
result = newNodeI(nkDotExpr, n.info)
result.add(tupl)
result.add(newSymNode(c.field, n.info))
break
else:
if n.kind == nkContinueStmt:
localError(n.info, errGenerated,
"'continue' not supported in a 'fields' loop")
result = copyNode(n)
newSons(result, sonsLen(n))
for i in countup(0, sonsLen(n)-1):
result.sons[i] = instFieldLoopBody(c, n.sons[i], forLoop)
proc liftBodyObj(c: TLiftCtx; typ, x, y: PNode) =
case typ.kind
of nkSym:
var fc: TFieldInstCtx # either 'tup[i]' or 'field' is valid
fc.field = typ.sym
fc.replaceByFieldName = c.m == mFieldPairs
openScope(c.c)
inc c.c.inUnrolledContext
let body = instFieldLoopBody(fc, lastSon(forLoop), forLoop)
father.add(semStmt(c.c, body))
dec c.c.inUnrolledContext
closeScope(c.c)
of nkNilLit: discard
of nkRecCase:
let L = forLoop.len
let call = forLoop.sons[L-2]
if call.len > 2:
localError(forLoop.info, errGenerated,
"parallel 'fields' iterator does not work for 'case' objects")
return
# iterate over the selector:
asgnForObjectFields(c, typ[0], forLoop, father)
# we need to generate a case statement:
var caseStmt = newNodeI(nkCaseStmt, c.info)
# generate selector:
var access = newNodeI(nkDotExpr, forLoop.info, 2)
access.sons[0] = call.sons[1]
access.sons[1] = newSymNode(typ.sons[0].sym, forLoop.info)
caseStmt.add(semExprWithType(c.c, access))
# copy the branches over, but replace the fields with the for loop body:
for i in 1 .. <typ.len:
var branch = copyTree(typ[i])
let L = branch.len
branch.sons[L-1] = newNodeI(nkStmtList, forLoop.info)
semForObjectFields(c, typ[i].lastSon, forLoop, branch[L-1])
caseStmt.add(branch)
father.add(caseStmt)
of nkRecList:
for t in items(typ): liftBodyObj(c, t, x, y)
else:
illFormedAst(typ)
proc newAsgnCall(op: PSym; x, y: PNode): PNode =
result = newNodeI(nkCall, x.info)
result.add(newSymNode(op))
result.add x
result.add y
proc newAsgnStmt(le, ri: PNode): PNode =
result = newNodeI(nkAsgn, le.info, 2)
result.sons[0] = le
result.sons[1] = ri
proc newDestructorCall(op: PSym; x: PNode): PNode =
result = newNodeIT(nkCall, x.info, op.typ.sons[0])
result.add(newSymNode(op))
result.add x
proc newDeepCopyCall(op: PSym; x, y: PNode): PNode =
result = newAsgnStmt(x, newDestructorCall(op, y))
proc considerOverloadedOp(c: TLiftCtx; t: PType; x, y: PNode): bool =
let op = t.attachedOps[c.kind]
if op != nil:
markUsed(c.info, op)
case c.kind
of attachedDestructor:
c.result.add newDestructorCall(op, x)
of attachedAsgn:
c.result.add newAsgnCall(op, x, y)
of attachedDeepCopy:
c.result.add newDeepCopyCall(op, x, y)
result = true
proc defaultOp(c: TLiftCtx; t: PType; x, y: PNode) =
if c.kind != attachedDestructor:
c.result.add newAsgnStmt(x, y)
proc liftBodyAux(c: TLiftCtx; t: PType; x, y: PNode) =
const hasAttachedOp: array[TTypeAttachedOp, TTypeIter] = [
(proc (t: PType, closure: PObject): bool =
t.attachedOp[attachedDestructor] != nil),
(proc (t: PType, closure: PObject): bool =
t.attachedOp[attachedAsgn] != nil),
(proc (t: PType, closure: PObject): bool =
t.attachedOp[attachedDeepCopy] != nil)]
case t.kind
of tyNone, tyEmpty: discard
of tyPointer, tySet, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString:
defaultOp(c, t, x, y)
of tyPtr, tyString:
if not considerOverloadedOp(c, t, x, y):
defaultOp(c, t, x, y)
of tyArrayConstr, tyArray, tySequence:
if iterOverType(lastSon(t), hasAttachedOp[c.kind], nil):
# generate loop and call the attached Op:
else:
defaultOp(c, t, x, y)
of tyObject:
liftBodyObj(c, t.n, x, y)
of tyTuple:
liftBodyTup(c, t, x, y)
of tyRef:
# we MUST not check for acyclic here as a DAG might still share nodes:
of tyProc:
if t.callConv != ccClosure or c.kind != attachedDeepCopy:
defaultOp(c, t, x, y)
else:
# a big problem is that we don't know the enviroment's type here, so we
# have to go through some indirection; we delegate this to the codegen:
call = newNodeI(nkCall, n.info, 2)
call.typ = t
call.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy))
call.sons[1] = y
c.result.add newAsgnStmt(x, call)
of tyVarargs, tyOpenArray:
localError(c.info, errGenerated, "cannot copy openArray")
of tyFromExpr, tyIter, tyProxy, tyBuiltInTypeClass, tyUserTypeClass,
tyUserTypeClassInst, tyCompositeTypeClass, tyAnd, tyOr, tyNot, tyAnything,
tyMutable, tyGenericParam, tyGenericBody, tyNil, tyExpr, tyStmt,
tyTypeDesc, tyGenericInvokation, tyBigNum, tyConst, tyForward:
internalError(c.info, "assignment requested for type: " & typeToString(t))
of tyDistinct, tyOrdinal, tyRange,
tyGenericInst, tyFieldAccessor, tyStatic, tyVar:
liftBodyAux(c, lastSon(t))
proc liftBody(c: PContext; typ: PType; info: TLineInfo): PNode =
var a: TLiftCtx
a.info = info
a.result = newNodeI(nkStmtList, info)
liftBodyAux(a, typ)

View file

@ -57,7 +57,7 @@ type
# can access private object fields # can access private object fields
instCounter*: int # to prevent endless instantiations instCounter*: int # to prevent endless instantiations
ambiguousSymbols*: TIntSet # ids of all ambiguous symbols (cannot ambiguousSymbols*: IntSet # ids of all ambiguous symbols (cannot
# store this info in the syms themselves!) # store this info in the syms themselves!)
inTypeClass*: int # > 0 if we are in a user-defined type class inTypeClass*: int # > 0 if we are in a user-defined type class
inGenericContext*: int # > 0 if we are in a generic type inGenericContext*: int # > 0 if we are in a generic type
@ -83,10 +83,10 @@ type
semInferredLambda*: proc(c: PContext, pt: TIdTable, n: PNode): PNode semInferredLambda*: proc(c: PContext, pt: TIdTable, n: PNode): PNode
semGenerateInstance*: proc (c: PContext, fn: PSym, pt: TIdTable, semGenerateInstance*: proc (c: PContext, fn: PSym, pt: TIdTable,
info: TLineInfo): PSym info: TLineInfo): PSym
includedFiles*: TIntSet # used to detect recursive include files includedFiles*: IntSet # used to detect recursive include files
userPragmas*: TStrTable userPragmas*: TStrTable
evalContext*: PEvalContext evalContext*: PEvalContext
unknownIdents*: TIntSet # ids of all unknown identifiers to prevent unknownIdents*: IntSet # ids of all unknown identifiers to prevent
# naming it multiple times # naming it multiple times
generics*: seq[TInstantiationPair] # pending list of instantiated generics to compile generics*: seq[TInstantiationPair] # pending list of instantiated generics to compile
lastGenericIdx*: int # used for the generics stack lastGenericIdx*: int # used for the generics stack

View file

@ -1816,7 +1816,7 @@ proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
addSonSkipIntLit(typ, n.sons[i].typ) addSonSkipIntLit(typ, n.sons[i].typ)
result.typ = typ result.typ = typ
proc checkInitialized(n: PNode, ids: TIntSet, info: TLineInfo) = proc checkInitialized(n: PNode, ids: IntSet, info: TLineInfo) =
case n.kind case n.kind
of nkRecList: of nkRecList:
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):

View file

@ -28,7 +28,7 @@ proc getIdentNode(n: PNode): PNode =
proc semGenericStmtScope(c: PContext, n: PNode, proc semGenericStmtScope(c: PContext, n: PNode,
flags: TSemGenericFlags, flags: TSemGenericFlags,
ctx: var TIntSet): PNode = ctx: var IntSet): PNode =
openScope(c) openScope(c)
result = semGenericStmt(c, n, flags, ctx) result = semGenericStmt(c, n, flags, ctx)
closeScope(c) closeScope(c)
@ -67,7 +67,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
else: result = newSymNode(s, n.info) else: result = newSymNode(s, n.info)
proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags, proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
ctx: var TIntSet): PNode = ctx: var IntSet): PNode =
result = n result = n
let ident = considerQuotedIdent(n) let ident = considerQuotedIdent(n)
var s = searchInScopes(c, ident).skipAlias(n) var s = searchInScopes(c, ident).skipAlias(n)
@ -89,7 +89,7 @@ proc newDot(n, b: PNode): PNode =
result.add(b) result.add(b)
proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags, proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
ctx: var TIntSet): PNode = ctx: var IntSet): PNode =
assert n.kind == nkDotExpr assert n.kind == nkDotExpr
let luf = if withinMixin notin flags: {checkUndeclared} else: {} let luf = if withinMixin notin flags: {checkUndeclared} else: {}
@ -114,7 +114,7 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
result = newDot(result, sym) result = newDot(result, sym)
proc semGenericStmt(c: PContext, n: PNode, proc semGenericStmt(c: PContext, n: PNode,
flags: TSemGenericFlags, ctx: var TIntSet): PNode = flags: TSemGenericFlags, ctx: var IntSet): PNode =
result = n result = n
if gCmd == cmdIdeTools: suggestStmt(c, n) if gCmd == cmdIdeTools: suggestStmt(c, n)
case n.kind case n.kind

View file

@ -71,7 +71,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode =
addSon(result, newSymNode(a, n.info)) addSon(result, newSymNode(a, n.info))
a = nextOverloadIter(o, c, n) a = nextOverloadIter(o, c, n)
proc semBindStmt(c: PContext, n: PNode, toBind: var TIntSet): PNode = proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
for i in 0 .. < n.len: for i in 0 .. < n.len:
var a = n.sons[i] var a = n.sons[i]
# If 'a' is an overloaded symbol, we used to use the first symbol # If 'a' is an overloaded symbol, we used to use the first symbol
@ -91,7 +91,7 @@ proc semBindStmt(c: PContext, n: PNode, toBind: var TIntSet): PNode =
illFormedAst(a) illFormedAst(a)
result = newNodeI(nkEmpty, n.info) result = newNodeI(nkEmpty, n.info)
proc semMixinStmt(c: PContext, n: PNode, toMixin: var TIntSet): PNode = proc semMixinStmt(c: PContext, n: PNode, toMixin: var IntSet): PNode =
for i in 0 .. < n.len: for i in 0 .. < n.len:
toMixin.incl(considerQuotedIdent(n.sons[i]).id) toMixin.incl(considerQuotedIdent(n.sons[i]).id)
result = newNodeI(nkEmpty, n.info) result = newNodeI(nkEmpty, n.info)
@ -106,7 +106,7 @@ proc replaceIdentBySym(n: var PNode, s: PNode) =
type type
TemplCtx {.pure, final.} = object TemplCtx {.pure, final.} = object
c: PContext c: PContext
toBind, toMixin, toInject: TIntSet toBind, toMixin, toInject: IntSet
owner: PSym owner: PSym
proc getIdentNode(c: var TemplCtx, n: PNode): PNode = proc getIdentNode(c: var TemplCtx, n: PNode): PNode =

View file

@ -461,9 +461,9 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
swap(branch.sons[L-2], branch.sons[L-1]) swap(branch.sons[L-2], branch.sons[L-1])
checkForOverlap(c, t, i, branchIndex) checkForOverlap(c, t, i, branchIndex)
proc semRecordNodeAux(c: PContext, n: PNode, check: var TIntSet, pos: var int, proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
father: PNode, rectype: PType) father: PNode, rectype: PType)
proc semRecordCase(c: PContext, n: PNode, check: var TIntSet, pos: var int, proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
father: PNode, rectype: PType) = father: PNode, rectype: PType) =
var a = copyNode(n) var a = copyNode(n)
checkMinSonsLen(n, 2) checkMinSonsLen(n, 2)
@ -498,7 +498,7 @@ proc semRecordCase(c: PContext, n: PNode, check: var TIntSet, pos: var int,
localError(a.info, errNotAllCasesCovered) localError(a.info, errNotAllCasesCovered)
addSon(father, a) addSon(father, a)
proc semRecordNodeAux(c: PContext, n: PNode, check: var TIntSet, pos: var int, proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
father: PNode, rectype: PType) = father: PNode, rectype: PType) =
if n == nil: return if n == nil: return
case n.kind case n.kind
@ -524,7 +524,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var TIntSet, pos: var int,
else: illFormedAst(n) else: illFormedAst(n)
if c.inGenericContext > 0: if c.inGenericContext > 0:
# use a new check intset here for each branch: # use a new check intset here for each branch:
var newCheck: TIntSet var newCheck: IntSet
assign(newCheck, check) assign(newCheck, check)
var newPos = pos var newPos = pos
var newf = newNodeI(nkRecList, n.info) var newf = newNodeI(nkRecList, n.info)
@ -578,7 +578,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var TIntSet, pos: var int,
of nkEmpty: discard of nkEmpty: discard
else: illFormedAst(n) else: illFormedAst(n)
proc addInheritedFieldsAux(c: PContext, check: var TIntSet, pos: var int, proc addInheritedFieldsAux(c: PContext, check: var IntSet, pos: var int,
n: PNode) = n: PNode) =
case n.kind case n.kind
of nkRecCase: of nkRecCase:
@ -597,7 +597,7 @@ proc addInheritedFieldsAux(c: PContext, check: var TIntSet, pos: var int,
inc(pos) inc(pos)
else: internalError(n.info, "addInheritedFieldsAux()") else: internalError(n.info, "addInheritedFieldsAux()")
proc addInheritedFields(c: PContext, check: var TIntSet, pos: var int, proc addInheritedFields(c: PContext, check: var IntSet, pos: var int,
obj: PType) = obj: PType) =
if (sonsLen(obj) > 0) and (obj.sons[0] != nil): if (sonsLen(obj) > 0) and (obj.sons[0] != nil):
addInheritedFields(c, check, pos, obj.sons[0]) addInheritedFields(c, check, pos, obj.sons[0])
@ -847,7 +847,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
prev: PType, kind: TSymKind): PType = prev: PType, kind: TSymKind): PType =
var var
res: PNode res: PNode
cl: TIntSet cl: IntSet
checkMinSonsLen(n, 1) checkMinSonsLen(n, 1)
result = newOrPrevType(tyProc, prev, c) result = newOrPrevType(tyProc, prev, c)
result.callConv = lastOptionEntry(c).defaultCC result.callConv = lastOptionEntry(c).defaultCC

View file

@ -84,9 +84,9 @@ proc serve*(action: proc (){.nimcall.}) =
of "tcp", "": of "tcp", "":
when useCaas: when useCaas:
var server = socket() var server = socket()
if server == invalidSocket: osError(osLastError()) if server == invalidSocket: raiseOSError(osLastError())
let p = getConfigVar("server.port") let p = getConfigVar("server.port")
let port = if p.len > 0: parseInt(p).TPort else: 6000.TPort let port = if p.len > 0: parseInt(p).Port else: 6000.Port
server.bindAddr(port, getConfigVar("server.address")) server.bindAddr(port, getConfigVar("server.address"))
var inp = "".TaintedString var inp = "".TaintedString
server.listen() server.listen()

View file

@ -1319,7 +1319,7 @@ proc incrIndexType(t: PType) =
inc t.sons[0].n.sons[1].intVal inc t.sons[0].n.sons[1].intVal
proc matchesAux(c: PContext, n, nOrig: PNode, proc matchesAux(c: PContext, n, nOrig: PNode,
m: var TCandidate, marker: var TIntSet) = m: var TCandidate, marker: var IntSet) =
template checkConstraint(n: expr) {.immediate, dirty.} = template checkConstraint(n: expr) {.immediate, dirty.} =
if not formal.constraint.isNil: if not formal.constraint.isNil:
if matchNodeKinds(formal.constraint, n): if matchNodeKinds(formal.constraint, n):

View file

@ -160,9 +160,9 @@ proc enumHasHoles(t: PType): bool =
while b.kind in {tyConst, tyMutable, tyRange, tyGenericInst}: b = b.sons[0] while b.kind in {tyConst, tyMutable, tyRange, tyGenericInst}: b = b.sons[0]
result = b.kind == tyEnum and tfEnumHasHoles in b.flags result = b.kind == tyEnum and tfEnumHasHoles in b.flags
proc iterOverTypeAux(marker: var TIntSet, t: PType, iter: TTypeIter, proc iterOverTypeAux(marker: var IntSet, t: PType, iter: TTypeIter,
closure: RootRef): bool closure: RootRef): bool
proc iterOverNode(marker: var TIntSet, n: PNode, iter: TTypeIter, proc iterOverNode(marker: var IntSet, n: PNode, iter: TTypeIter,
closure: RootRef): bool = closure: RootRef): bool =
if n != nil: if n != nil:
case n.kind case n.kind
@ -174,7 +174,7 @@ proc iterOverNode(marker: var TIntSet, n: PNode, iter: TTypeIter,
result = iterOverNode(marker, n.sons[i], iter, closure) result = iterOverNode(marker, n.sons[i], iter, closure)
if result: return if result: return
proc iterOverTypeAux(marker: var TIntSet, t: PType, iter: TTypeIter, proc iterOverTypeAux(marker: var IntSet, t: PType, iter: TTypeIter,
closure: RootRef): bool = closure: RootRef): bool =
result = false result = false
if t == nil: return if t == nil: return
@ -195,10 +195,10 @@ proc iterOverType(t: PType, iter: TTypeIter, closure: RootRef): bool =
result = iterOverTypeAux(marker, t, iter, closure) result = iterOverTypeAux(marker, t, iter, closure)
proc searchTypeForAux(t: PType, predicate: TTypePredicate, proc searchTypeForAux(t: PType, predicate: TTypePredicate,
marker: var TIntSet): bool marker: var IntSet): bool
proc searchTypeNodeForAux(n: PNode, p: TTypePredicate, proc searchTypeNodeForAux(n: PNode, p: TTypePredicate,
marker: var TIntSet): bool = marker: var IntSet): bool =
result = false result = false
case n.kind case n.kind
of nkRecList: of nkRecList:
@ -220,7 +220,7 @@ proc searchTypeNodeForAux(n: PNode, p: TTypePredicate,
else: internalError(n.info, "searchTypeNodeForAux()") else: internalError(n.info, "searchTypeNodeForAux()")
proc searchTypeForAux(t: PType, predicate: TTypePredicate, proc searchTypeForAux(t: PType, predicate: TTypePredicate,
marker: var TIntSet): bool = marker: var IntSet): bool =
# iterates over VALUE types! # iterates over VALUE types!
result = false result = false
if t == nil: return if t == nil: return
@ -256,7 +256,7 @@ proc isObjectWithTypeFieldPredicate(t: PType): bool =
tfFinal notin t.flags tfFinal notin t.flags
proc analyseObjectWithTypeFieldAux(t: PType, proc analyseObjectWithTypeFieldAux(t: PType,
marker: var TIntSet): TTypeFieldResult = marker: var IntSet): TTypeFieldResult =
var res: TTypeFieldResult var res: TTypeFieldResult
result = frNone result = frNone
if t == nil: return if t == nil: return
@ -310,8 +310,8 @@ proc containsHiddenPointer(typ: PType): bool =
# that need to be copied deeply) # that need to be copied deeply)
result = searchTypeFor(typ, isHiddenPointer) result = searchTypeFor(typ, isHiddenPointer)
proc canFormAcycleAux(marker: var TIntSet, typ: PType, startId: int): bool proc canFormAcycleAux(marker: var IntSet, typ: PType, startId: int): bool
proc canFormAcycleNode(marker: var TIntSet, n: PNode, startId: int): bool = proc canFormAcycleNode(marker: var IntSet, n: PNode, startId: int): bool =
result = false result = false
if n != nil: if n != nil:
result = canFormAcycleAux(marker, n.typ, startId) result = canFormAcycleAux(marker, n.typ, startId)
@ -324,7 +324,7 @@ proc canFormAcycleNode(marker: var TIntSet, n: PNode, startId: int): bool =
result = canFormAcycleNode(marker, n.sons[i], startId) result = canFormAcycleNode(marker, n.sons[i], startId)
if result: return if result: return
proc canFormAcycleAux(marker: var TIntSet, typ: PType, startId: int): bool = proc canFormAcycleAux(marker: var IntSet, typ: PType, startId: int): bool =
result = false result = false
if typ == nil: return if typ == nil: return
if tfAcyclic in typ.flags: return if tfAcyclic in typ.flags: return
@ -353,9 +353,9 @@ proc canFormAcycle(typ: PType): bool =
var marker = initIntSet() var marker = initIntSet()
result = canFormAcycleAux(marker, typ, typ.id) result = canFormAcycleAux(marker, typ, typ.id)
proc mutateTypeAux(marker: var TIntSet, t: PType, iter: TTypeMutator, proc mutateTypeAux(marker: var IntSet, t: PType, iter: TTypeMutator,
closure: RootRef): PType closure: RootRef): PType
proc mutateNode(marker: var TIntSet, n: PNode, iter: TTypeMutator, proc mutateNode(marker: var IntSet, n: PNode, iter: TTypeMutator,
closure: RootRef): PNode = closure: RootRef): PNode =
result = nil result = nil
if n != nil: if n != nil:
@ -369,7 +369,7 @@ proc mutateNode(marker: var TIntSet, n: PNode, iter: TTypeMutator,
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
addSon(result, mutateNode(marker, n.sons[i], iter, closure)) addSon(result, mutateNode(marker, n.sons[i], iter, closure))
proc mutateTypeAux(marker: var TIntSet, t: PType, iter: TTypeMutator, proc mutateTypeAux(marker: var IntSet, t: PType, iter: TTypeMutator,
closure: RootRef): PType = closure: RootRef): PType =
result = nil result = nil
if t == nil: return if t == nil: return
@ -1012,10 +1012,10 @@ type
TTypeAllowedFlags = set[TTypeAllowedFlag] TTypeAllowedFlags = set[TTypeAllowedFlag]
proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind, proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
flags: TTypeAllowedFlags = {}): bool flags: TTypeAllowedFlags = {}): bool
proc typeAllowedNode(marker: var TIntSet, n: PNode, kind: TSymKind, proc typeAllowedNode(marker: var IntSet, n: PNode, kind: TSymKind,
flags: TTypeAllowedFlags = {}): bool = flags: TTypeAllowedFlags = {}): bool =
result = true result = true
if n != nil: if n != nil:
@ -1039,7 +1039,7 @@ proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]],
a = a.sons[i] a = a.sons[i]
result = a.kind == last result = a.kind == last
proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind, proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
flags: TTypeAllowedFlags = {}): bool = flags: TTypeAllowedFlags = {}): bool =
assert(kind in {skVar, skLet, skConst, skParam, skResult}) assert(kind in {skVar, skLet, skConst, skParam, skResult})
# if we have already checked the type, return true, because we stop the # if we have already checked the type, return true, because we stop the

View file

@ -9,7 +9,7 @@
import ast, types, msgs, osproc, streams, options import ast, types, msgs, osproc, streams, options
proc readOutput(p: PProcess): string = proc readOutput(p: Process): string =
result = "" result = ""
var output = p.outputStream var output = p.outputStream
discard p.waitForExit discard p.waitForExit

View file

@ -66,8 +66,8 @@ proc getArgument*(n: PRstNode): string
# ----------------------------- scanner part -------------------------------- # ----------------------------- scanner part --------------------------------
const const
SymChars: TCharSet = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF'} SymChars: set[char] = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF'}
SmileyStartChars: TCharSet = {':', ';', '8'} SmileyStartChars: set[char] = {':', ';', '8'}
Smilies = { Smilies = {
":D": "icon_e_biggrin", ":D": "icon_e_biggrin",
":-D": "icon_e_biggrin", ":-D": "icon_e_biggrin",
@ -111,7 +111,7 @@ const
type type
TTokType = enum TTokType = enum
tkEof, tkIndent, tkWhite, tkWord, tkAdornment, tkPunct, tkOther tkEof, tkIndent, tkWhite, tkWord, tkAdornment, tkPunct, tkOther
TToken{.final.} = object # a RST token TToken = object # a RST token
kind*: TTokType # the type of the token kind*: TTokType # the type of the token
ival*: int # the indentation or parsed integer value ival*: int # the indentation or parsed integer value
symbol*: string # the parsed symbol as string symbol*: string # the parsed symbol as string
@ -125,7 +125,7 @@ type
skipPounds*: bool skipPounds*: bool
proc getThing(L: var TLexer, tok: var TToken, s: TCharSet) = proc getThing(L: var TLexer, tok: var TToken, s: set[char]) =
tok.kind = tkWord tok.kind = tkWord
tok.line = L.line tok.line = L.line
tok.col = L.col tok.col = L.col

View file

@ -286,7 +286,7 @@ proc renderRstToRst*(n: PRstNode, result: var string) =
var d: TRenderContext var d: TRenderContext
renderRstToRst(d, n, result) renderRstToRst(d, n, result)
proc renderRstToJsonNode(node: PRstNode): PJsonNode = proc renderRstToJsonNode(node: PRstNode): JsonNode =
result = result =
%[ %[
(key: "kind", val: %($node.kind)), (key: "kind", val: %($node.kind)),
@ -295,7 +295,7 @@ proc renderRstToJsonNode(node: PRstNode): PJsonNode =
if node.text != nil: if node.text != nil:
result.add("text", %node.text) result.add("text", %node.text)
if node.sons != nil and len(node.sons) > 0: if node.sons != nil and len(node.sons) > 0:
var accm = newSeq[PJsonNode](len(node.sons)) var accm = newSeq[JsonNode](len(node.sons))
for i, son in node.sons: for i, son in node.sons:
accm[i] = renderRstToJsonNode(son) accm[i] = renderRstToJsonNode(son)
result.add("sons", %accm) result.add("sons", %accm)

View file

@ -35,7 +35,7 @@ type
outHtml, # output is HTML outHtml, # output is HTML
outLatex # output is Latex outLatex # output is Latex
TTocEntry{.final.} = object TTocEntry = object
n*: PRstNode n*: PRstNode
refname*, header*: string refname*, header*: string
@ -44,7 +44,7 @@ type
TRstGenerator* = object of RootObj TRstGenerator* = object of RootObj
target*: TOutputTarget target*: TOutputTarget
config*: PStringTable config*: StringTableRef
splitAfter*: int # split too long entries in the TOC splitAfter*: int # split too long entries in the TOC
tocPart*: seq[TTocEntry] tocPart*: seq[TTocEntry]
hasToc*: bool hasToc*: bool
@ -57,21 +57,21 @@ type
currentSection: string ## \ currentSection: string ## \
## Stores the empty string or the last headline/overline found in the rst ## Stores the empty string or the last headline/overline found in the rst
## document, so it can be used as a prettier name for term index generation. ## document, so it can be used as a prettier name for term index generation.
seenIndexTerms: TTable[string, int] ## \ seenIndexTerms: Table[string, int] ## \
## Keeps count of same text index terms to generate different identifiers ## Keeps count of same text index terms to generate different identifiers
## for hyperlinks. See renderIndexTerm proc for details. ## for hyperlinks. See renderIndexTerm proc for details.
PDoc = var TRstGenerator ## Alias to type less. PDoc = var TRstGenerator ## Alias to type less.
proc initRstGenerator*(g: var TRstGenerator, target: TOutputTarget, proc initRstGenerator*(g: var TRstGenerator, target: TOutputTarget,
config: PStringTable, filename: string, config: StringTableRef, filename: string,
options: TRstParseOptions, options: TRstParseOptions,
findFile: TFindFileHandler, findFile: TFindFileHandler,
msgHandler: TMsgHandler) = msgHandler: TMsgHandler) =
## Initializes a ``TRstGenerator``. ## Initializes a ``TRstGenerator``.
## ##
## You need to call this before using a ``TRstGenerator`` with any other ## You need to call this before using a ``TRstGenerator`` with any other
## procs in this module. Pass a non ``nil`` ``PStringTable`` value as ## procs in this module. Pass a non ``nil`` ``StringTableRef`` value as
## `config` with parameters used by the HTML output generator. If you don't ## `config` with parameters used by the HTML output generator. If you don't
## know what to use, pass the results of the `defaultConfig() ## know what to use, pass the results of the `defaultConfig()
## <#defaultConfig>_` proc. ## <#defaultConfig>_` proc.
@ -341,13 +341,13 @@ proc renderIndexTerm*(d: PDoc, n: PRstNode, result: var string) =
[id, term]) [id, term])
type type
TIndexEntry {.pure, final.} = object TIndexEntry = object
keyword: string keyword: string
link: string link: string
linkTitle: string ## If not nil, contains a prettier text for the href linkTitle: string ## If not nil, contains a prettier text for the href
linkDesc: string ## If not nil, the title attribute of the final href linkDesc: string ## If not nil, the title attribute of the final href
TIndexedDocs {.pure, final.} = TTable[TIndexEntry, seq[TIndexEntry]] ## \ TIndexedDocs = Table[TIndexEntry, seq[TIndexEntry]] ## \
## Contains the index sequences for doc types. ## Contains the index sequences for doc types.
## ##
## The key is a *fake* TIndexEntry which will contain the title of the ## The key is a *fake* TIndexEntry which will contain the title of the
@ -1048,10 +1048,10 @@ proc formatNamedVars*(frmt: string, varnames: openArray[string],
if i-1 >= start: add(result, substr(frmt, start, i - 1)) if i-1 >= start: add(result, substr(frmt, start, i - 1))
proc defaultConfig*(): PStringTable = proc defaultConfig*(): StringTableRef =
## Returns a default configuration for embedded HTML generation. ## Returns a default configuration for embedded HTML generation.
## ##
## The returned ``PStringTable`` contains the paramters used by the HTML ## The returned ``StringTableRef`` contains the paramters used by the HTML
## engine to build the final output. For information on what these parameters ## engine to build the final output. For information on what these parameters
## are and their purpose, please look up the file ``config/nimdoc.cfg`` ## are and their purpose, please look up the file ``config/nimdoc.cfg``
## bundled with the compiler. ## bundled with the compiler.
@ -1113,7 +1113,7 @@ $content
# ---------- forum --------------------------------------------------------- # ---------- forum ---------------------------------------------------------
proc rstToHtml*(s: string, options: TRstParseOptions, proc rstToHtml*(s: string, options: TRstParseOptions,
config: PStringTable): string = config: StringTableRef): string =
## Converts an input rst string into embeddable HTML. ## Converts an input rst string into embeddable HTML.
## ##
## This convenience proc parses any input string using rst markup (it doesn't ## This convenience proc parses any input string using rst markup (it doesn't