refactoring: remove idents.legacy global variable and pass the IdentCache around explicitly
This commit is contained in:
parent
a325692fb2
commit
40ec7be45c
41 changed files with 338 additions and 353 deletions
|
|
@ -1699,7 +1699,7 @@ proc isImportedException*(t: PType; conf: ConfigRef): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc isInfixAs*(n: PNode): bool =
|
proc isInfixAs*(n: PNode): bool =
|
||||||
return n.kind == nkInfix and n[0].kind == nkIdent and n[0].ident.id == getIdent("as").id
|
return n.kind == nkInfix and n[0].kind == nkIdent and n[0].ident.s == "as"
|
||||||
|
|
||||||
proc findUnresolvedStatic*(n: PNode): PNode =
|
proc findUnresolvedStatic*(n: PNode): PNode =
|
||||||
if n.kind == nkSym and n.typ.kind == tyStatic and n.typ.n == nil:
|
if n.kind == nkSym and n.typ.kind == tyStatic and n.typ.n == nil:
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ type
|
||||||
|
|
||||||
proc getTemp(c: var Con; typ: PType; info: TLineInfo): PNode =
|
proc getTemp(c: var Con; typ: PType; info: TLineInfo): PNode =
|
||||||
# XXX why are temps fields in an object here?
|
# XXX why are temps fields in an object here?
|
||||||
let f = newSym(skField, getIdent(":d" & $c.tmpObj.n.len), c.owner, info)
|
let f = newSym(skField, getIdent(c.graph.cache, ":d" & $c.tmpObj.n.len), c.owner, info)
|
||||||
f.typ = typ
|
f.typ = typ
|
||||||
rawAddField c.tmpObj, f
|
rawAddField c.tmpObj, f
|
||||||
result = rawDirectAccess(c.tmp, f)
|
result = rawDirectAccess(c.tmp, f)
|
||||||
|
|
@ -251,7 +251,7 @@ proc dropBit(c: var Con; s: PSym): PSym =
|
||||||
assert result != nil
|
assert result != nil
|
||||||
|
|
||||||
proc registerDropBit(c: var Con; s: PSym) =
|
proc registerDropBit(c: var Con; s: PSym) =
|
||||||
let result = newSym(skTemp, getIdent(s.name.s & "_AliveBit"), c.owner, s.info)
|
let result = newSym(skTemp, getIdent(c.graph.cache, s.name.s & "_AliveBit"), c.owner, s.info)
|
||||||
result.typ = getSysType(c.graph, s.info, tyBool)
|
result.typ = getSysType(c.graph, s.info, tyBool)
|
||||||
let trueVal = newIntTypeNode(nkIntLit, 1, result.typ)
|
let trueVal = newIntTypeNode(nkIntLit, 1, result.typ)
|
||||||
c.topLevelVars.add newTree(nkIdentDefs, newSymNode result, c.emptyNode, trueVal)
|
c.topLevelVars.add newTree(nkIdentDefs, newSymNode result, c.emptyNode, trueVal)
|
||||||
|
|
@ -323,7 +323,7 @@ proc destructiveMoveVar(n: PNode; c: var Con): PNode =
|
||||||
# generate: (let tmp = v; reset(v); tmp)
|
# generate: (let tmp = v; reset(v); tmp)
|
||||||
result = newNodeIT(nkStmtListExpr, n.info, n.typ)
|
result = newNodeIT(nkStmtListExpr, n.info, n.typ)
|
||||||
|
|
||||||
var temp = newSym(skLet, getIdent("blitTmp"), c.owner, n.info)
|
var temp = newSym(skLet, getIdent(c.graph.cache, "blitTmp"), c.owner, n.info)
|
||||||
var v = newNodeI(nkLetSection, n.info)
|
var v = newNodeI(nkLetSection, n.info)
|
||||||
let tempAsNode = newSymNode(temp)
|
let tempAsNode = newSymNode(temp)
|
||||||
|
|
||||||
|
|
@ -428,7 +428,7 @@ proc injectDestructorCalls*(g: ModuleGraph; owner: PSym; n: PNode): PNode =
|
||||||
echo "injecting into ", n
|
echo "injecting into ", n
|
||||||
var c: Con
|
var c: Con
|
||||||
c.owner = owner
|
c.owner = owner
|
||||||
c.tmp = newSym(skTemp, getIdent":d", owner, n.info)
|
c.tmp = newSym(skTemp, getIdent(g.cache, ":d"), owner, n.info)
|
||||||
c.tmpObj = createObj(g, owner, n.info)
|
c.tmpObj = createObj(g, owner, n.info)
|
||||||
c.tmp.typ = c.tmpObj
|
c.tmp.typ = c.tmpObj
|
||||||
c.destroys = newNodeI(nkStmtList, n.info)
|
c.destroys = newNodeI(nkStmtList, n.info)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ type
|
||||||
types: TStrTable
|
types: TStrTable
|
||||||
isPureRst: bool
|
isPureRst: bool
|
||||||
conf*: ConfigRef
|
conf*: ConfigRef
|
||||||
|
cache*: IdentCache
|
||||||
|
|
||||||
PDoc* = ref TDocumentor ## Alias to type less.
|
PDoc* = ref TDocumentor ## Alias to type less.
|
||||||
|
|
||||||
|
|
@ -86,10 +87,11 @@ 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, conf: ConfigRef): PDoc =
|
proc newDocumentor*(filename: string; cache: IdentCache; conf: ConfigRef): PDoc =
|
||||||
declareClosures()
|
declareClosures()
|
||||||
new(result)
|
new(result)
|
||||||
result.conf = conf
|
result.conf = conf
|
||||||
|
result.cache = cache
|
||||||
initRstGenerator(result[], (if conf.cmd != cmdRst2tex: outHtml else: outLatex),
|
initRstGenerator(result[], (if conf.cmd != cmdRst2tex: outHtml else: outLatex),
|
||||||
conf.configVars, filename, {roSupportRawDirective},
|
conf.configVars, filename, {roSupportRawDirective},
|
||||||
docgenFindFile, compilerMsgHandler)
|
docgenFindFile, compilerMsgHandler)
|
||||||
|
|
@ -349,18 +351,18 @@ proc getName(d: PDoc, n: PNode, splitAfter = -1): string =
|
||||||
else:
|
else:
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
proc getNameIdent(n: PNode): PIdent =
|
proc getNameIdent(cache: IdentCache; n: PNode): PIdent =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkPostfix: result = getNameIdent(n.sons[1])
|
of nkPostfix: result = getNameIdent(cache, n.sons[1])
|
||||||
of nkPragmaExpr: result = getNameIdent(n.sons[0])
|
of nkPragmaExpr: result = getNameIdent(cache, n.sons[0])
|
||||||
of nkSym: result = n.sym.name
|
of nkSym: result = n.sym.name
|
||||||
of nkIdent: result = n.ident
|
of nkIdent: result = n.ident
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
var r = ""
|
var r = ""
|
||||||
for i in 0..<n.len: r.add(getNameIdent(n[i]).s)
|
for i in 0..<n.len: r.add(getNameIdent(cache, n[i]).s)
|
||||||
result = getIdent(r)
|
result = getIdent(cache, r)
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
result = getNameIdent(n[0])
|
result = getNameIdent(cache, n[0])
|
||||||
else:
|
else:
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
|
|
@ -586,21 +588,21 @@ proc generateDoc*(d: PDoc, n: PNode) =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkCommentStmt: add(d.modDesc, genComment(d, n))
|
of nkCommentStmt: add(d.modDesc, genComment(d, n))
|
||||||
of nkProcDef:
|
of nkProcDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
genItem(d, n, n.sons[namePos], skProc)
|
genItem(d, n, n.sons[namePos], skProc)
|
||||||
of nkFuncDef:
|
of nkFuncDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
genItem(d, n, n.sons[namePos], skFunc)
|
genItem(d, n, n.sons[namePos], skFunc)
|
||||||
of nkMethodDef:
|
of nkMethodDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
genItem(d, n, n.sons[namePos], skMethod)
|
genItem(d, n, n.sons[namePos], skMethod)
|
||||||
of nkIteratorDef:
|
of nkIteratorDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
genItem(d, n, n.sons[namePos], skIterator)
|
genItem(d, n, n.sons[namePos], skIterator)
|
||||||
of nkMacroDef: genItem(d, n, n.sons[namePos], skMacro)
|
of nkMacroDef: genItem(d, n, n.sons[namePos], skMacro)
|
||||||
of nkTemplateDef: genItem(d, n, n.sons[namePos], skTemplate)
|
of nkTemplateDef: genItem(d, n, n.sons[namePos], skTemplate)
|
||||||
of nkConverterDef:
|
of nkConverterDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
genItem(d, n, n.sons[namePos], skConverter)
|
genItem(d, n, n.sons[namePos], skConverter)
|
||||||
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
@ -630,23 +632,23 @@ proc generateJson*(d: PDoc, n: PNode) =
|
||||||
d.add %{ "comment": %stripped, "line": %n.info.line.int,
|
d.add %{ "comment": %stripped, "line": %n.info.line.int,
|
||||||
"col": %n.info.col }
|
"col": %n.info.col }
|
||||||
of nkProcDef:
|
of nkProcDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skProc)
|
d.add genJsonItem(d, n, n.sons[namePos], skProc)
|
||||||
of nkFuncDef:
|
of nkFuncDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skFunc)
|
d.add genJsonItem(d, n, n.sons[namePos], skFunc)
|
||||||
of nkMethodDef:
|
of nkMethodDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skMethod)
|
d.add genJsonItem(d, n, n.sons[namePos], skMethod)
|
||||||
of nkIteratorDef:
|
of nkIteratorDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skIterator)
|
d.add genJsonItem(d, n, n.sons[namePos], skIterator)
|
||||||
of nkMacroDef:
|
of nkMacroDef:
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skMacro)
|
d.add genJsonItem(d, n, n.sons[namePos], skMacro)
|
||||||
of nkTemplateDef:
|
of nkTemplateDef:
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skTemplate)
|
d.add genJsonItem(d, n, n.sons[namePos], skTemplate)
|
||||||
of nkConverterDef:
|
of nkConverterDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
d.add genJsonItem(d, n, n.sons[namePos], skConverter)
|
d.add genJsonItem(d, n, n.sons[namePos], skConverter)
|
||||||
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
@ -673,23 +675,23 @@ proc generateTags*(d: PDoc, n: PNode, r: var Rope) =
|
||||||
let stripped = n.comment.substr(2).strip
|
let stripped = n.comment.substr(2).strip
|
||||||
r.add stripped
|
r.add stripped
|
||||||
of nkProcDef:
|
of nkProcDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skProc)
|
r.add genTagsItem(d, n, n.sons[namePos], skProc)
|
||||||
of nkFuncDef:
|
of nkFuncDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skFunc)
|
r.add genTagsItem(d, n, n.sons[namePos], skFunc)
|
||||||
of nkMethodDef:
|
of nkMethodDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skMethod)
|
r.add genTagsItem(d, n, n.sons[namePos], skMethod)
|
||||||
of nkIteratorDef:
|
of nkIteratorDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skIterator)
|
r.add genTagsItem(d, n, n.sons[namePos], skIterator)
|
||||||
of nkMacroDef:
|
of nkMacroDef:
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skMacro)
|
r.add genTagsItem(d, n, n.sons[namePos], skMacro)
|
||||||
of nkTemplateDef:
|
of nkTemplateDef:
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skTemplate)
|
r.add genTagsItem(d, n, n.sons[namePos], skTemplate)
|
||||||
of nkConverterDef:
|
of nkConverterDef:
|
||||||
when useEffectSystem: documentRaises(n)
|
when useEffectSystem: documentRaises(d.cache, n)
|
||||||
r.add genTagsItem(d, n, n.sons[namePos], skConverter)
|
r.add genTagsItem(d, n, n.sons[namePos], skConverter)
|
||||||
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
@ -804,18 +806,18 @@ proc writeOutputJson*(d: PDoc, filename, outExt: string,
|
||||||
else:
|
else:
|
||||||
discard "fixme: error report"
|
discard "fixme: error report"
|
||||||
|
|
||||||
proc commandDoc*(conf: ConfigRef) =
|
proc commandDoc*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, conf)
|
var d = newDocumentor(conf.projectFull, cache, conf)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
generateDoc(d, ast)
|
generateDoc(d, ast)
|
||||||
writeOutput(d, conf.projectFull, HtmlExt)
|
writeOutput(d, conf.projectFull, HtmlExt)
|
||||||
generateIndex(d)
|
generateIndex(d)
|
||||||
|
|
||||||
proc commandRstAux(conf: ConfigRef; filename, outExt: string) =
|
proc commandRstAux(cache: IdentCache, conf: ConfigRef; filename, outExt: string) =
|
||||||
var filen = addFileExt(filename, "txt")
|
var filen = addFileExt(filename, "txt")
|
||||||
var d = newDocumentor(filen, conf)
|
var d = newDocumentor(filen, cache, conf)
|
||||||
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
|
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
|
||||||
status: int; content: string) =
|
status: int; content: string) =
|
||||||
var outp: string
|
var outp: string
|
||||||
|
|
@ -847,17 +849,17 @@ proc commandRstAux(conf: ConfigRef; filename, outExt: string) =
|
||||||
writeOutput(d, filename, outExt)
|
writeOutput(d, filename, outExt)
|
||||||
generateIndex(d)
|
generateIndex(d)
|
||||||
|
|
||||||
proc commandRst2Html*(conf: ConfigRef) =
|
proc commandRst2Html*(cache: IdentCache, conf: ConfigRef) =
|
||||||
commandRstAux(conf, conf.projectFull, HtmlExt)
|
commandRstAux(cache, conf, conf.projectFull, HtmlExt)
|
||||||
|
|
||||||
proc commandRst2TeX*(conf: ConfigRef) =
|
proc commandRst2TeX*(cache: IdentCache, conf: ConfigRef) =
|
||||||
splitter = "\\-"
|
splitter = "\\-"
|
||||||
commandRstAux(conf, conf.projectFull, TexExt)
|
commandRstAux(cache, conf, conf.projectFull, TexExt)
|
||||||
|
|
||||||
proc commandJson*(conf: ConfigRef) =
|
proc commandJson*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, conf)
|
var d = newDocumentor(conf.projectFull, cache, conf)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
generateJson(d, ast)
|
generateJson(d, ast)
|
||||||
let json = d.jArray
|
let json = d.jArray
|
||||||
|
|
@ -871,10 +873,10 @@ proc commandJson*(conf: ConfigRef) =
|
||||||
if not writeRope(content, filename):
|
if not writeRope(content, filename):
|
||||||
rawMessage(conf, errCannotOpenFile, filename)
|
rawMessage(conf, errCannotOpenFile, filename)
|
||||||
|
|
||||||
proc commandTags*(conf: ConfigRef) =
|
proc commandTags*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, conf)
|
var d = newDocumentor(conf.projectFull, cache, conf)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
var
|
var
|
||||||
content: Rope
|
content: Rope
|
||||||
|
|
@ -888,7 +890,7 @@ proc commandTags*(conf: ConfigRef) =
|
||||||
if not writeRope(content, filename):
|
if not writeRope(content, filename):
|
||||||
rawMessage(conf, errCannotOpenFile, filename)
|
rawMessage(conf, errCannotOpenFile, filename)
|
||||||
|
|
||||||
proc commandBuildIndex*(conf: ConfigRef) =
|
proc commandBuildIndex*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var content = mergeIndexes(conf.projectFull).rope
|
var content = mergeIndexes(conf.projectFull).rope
|
||||||
|
|
||||||
let code = ropeFormatNamedVars(conf, getConfigVar(conf, "doc.file"), ["title",
|
let code = ropeFormatNamedVars(conf, getConfigVar(conf, "doc.file"), ["title",
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
var g: PGen
|
var g: PGen
|
||||||
new(g)
|
new(g)
|
||||||
g.module = module
|
g.module = module
|
||||||
var d = newDocumentor(toFilename(graph.config, FileIndex module.position), graph.config)
|
var d = newDocumentor(toFilename(graph.config, FileIndex module.position), graph.cache, graph.config)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
g.doc = d
|
g.doc = d
|
||||||
result = g
|
result = g
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,12 @@ type
|
||||||
wordCounter: int
|
wordCounter: int
|
||||||
idAnon*, idDelegator*, emptyIdent*: PIdent
|
idAnon*, idDelegator*, emptyIdent*: PIdent
|
||||||
|
|
||||||
|
when false:
|
||||||
var
|
var
|
||||||
legacy: IdentCache
|
legacy: IdentCache
|
||||||
|
|
||||||
proc resetIdentCache*() =
|
proc resetIdentCache*() =
|
||||||
|
when false:
|
||||||
for i in low(legacy.buckets)..high(legacy.buckets):
|
for i in low(legacy.buckets)..high(legacy.buckets):
|
||||||
legacy.buckets[i] = nil
|
legacy.buckets[i] = nil
|
||||||
|
|
||||||
|
|
@ -111,7 +113,6 @@ proc getIdent*(self: IdentCache; identifier: string, h: Hash): PIdent =
|
||||||
result = getIdent(cstring(identifier), len(identifier), h)
|
result = getIdent(cstring(identifier), len(identifier), h)
|
||||||
|
|
||||||
proc newIdentCache*(): IdentCache =
|
proc newIdentCache*(): IdentCache =
|
||||||
if legacy.isNil:
|
|
||||||
result = IdentCache()
|
result = IdentCache()
|
||||||
result.idAnon = result.getIdent":anonymous"
|
result.idAnon = result.getIdent":anonymous"
|
||||||
result.wordCounter = 1
|
result.wordCounter = 1
|
||||||
|
|
@ -120,16 +121,7 @@ proc newIdentCache*(): IdentCache =
|
||||||
# initialize the keywords:
|
# initialize the keywords:
|
||||||
for s in countup(succ(low(specialWords)), high(specialWords)):
|
for s in countup(succ(low(specialWords)), high(specialWords)):
|
||||||
result.getIdent(specialWords[s], hashIgnoreStyle(specialWords[s])).id = ord(s)
|
result.getIdent(specialWords[s], hashIgnoreStyle(specialWords[s])).id = ord(s)
|
||||||
legacy = result
|
|
||||||
else:
|
|
||||||
result = legacy
|
|
||||||
|
|
||||||
proc whichKeyword*(id: PIdent): TSpecialWord =
|
proc whichKeyword*(id: PIdent): TSpecialWord =
|
||||||
if id.id < 0: result = wInvalid
|
if id.id < 0: result = wInvalid
|
||||||
else: result = TSpecialWord(id.id)
|
else: result = TSpecialWord(id.id)
|
||||||
|
|
||||||
proc getIdent*(identifier: string): PIdent =
|
|
||||||
## for backwards compatibility.
|
|
||||||
if legacy.isNil:
|
|
||||||
discard newIdentCache()
|
|
||||||
legacy.getIdent identifier
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ proc readExceptSet*(c: PContext, n: PNode): IntSet =
|
||||||
assert n.kind in {nkImportExceptStmt, nkExportExceptStmt}
|
assert n.kind in {nkImportExceptStmt, nkExportExceptStmt}
|
||||||
result = initIntSet()
|
result = initIntSet()
|
||||||
for i in 1 ..< n.len:
|
for i in 1 ..< n.len:
|
||||||
let ident = lookups.considerQuotedIdent(c.config, n[i])
|
let ident = lookups.considerQuotedIdent(c, n[i])
|
||||||
result.incl(ident.id)
|
result.incl(ident.id)
|
||||||
|
|
||||||
proc importPureEnumField*(c: PContext; s: PSym) =
|
proc importPureEnumField*(c: PContext; s: PSym) =
|
||||||
|
|
@ -69,7 +69,7 @@ proc rawImportSymbol(c: PContext, s: PSym) =
|
||||||
if hasPattern(s): addPattern(c, s)
|
if hasPattern(s): addPattern(c, s)
|
||||||
|
|
||||||
proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
|
proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
|
||||||
let ident = lookups.considerQuotedIdent(c.config, n)
|
let ident = lookups.considerQuotedIdent(c, n)
|
||||||
let s = strTableGet(fromMod.tab, ident)
|
let s = strTableGet(fromMod.tab, ident)
|
||||||
if s == nil:
|
if s == nil:
|
||||||
errorUndeclaredIdentifier(c, n.info, ident.s)
|
errorUndeclaredIdentifier(c, n.info, ident.s)
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ proc createStateType(g: ModuleGraph; iter: PSym): PType =
|
||||||
rawAddSon(result, intType)
|
rawAddSon(result, intType)
|
||||||
|
|
||||||
proc createStateField(g: ModuleGraph; iter: PSym): PSym =
|
proc createStateField(g: ModuleGraph; iter: PSym): PSym =
|
||||||
result = newSym(skField, getIdent(":state"), iter, iter.info, {})
|
result = newSym(skField, getIdent(g.cache, ":state"), iter, iter.info, {})
|
||||||
result.typ = createStateType(g, iter)
|
result.typ = createStateType(g, iter)
|
||||||
|
|
||||||
proc createEnvObj(g: ModuleGraph; owner: PSym; info: TLineInfo): PType =
|
proc createEnvObj(g: ModuleGraph; owner: PSym; info: TLineInfo): PType =
|
||||||
|
|
@ -146,12 +146,12 @@ proc createEnvObj(g: ModuleGraph; owner: PSym; info: TLineInfo): PType =
|
||||||
result = createObj(g, owner, info, final=false)
|
result = createObj(g, owner, info, final=false)
|
||||||
rawAddField(result, createStateField(g, owner))
|
rawAddField(result, createStateField(g, owner))
|
||||||
|
|
||||||
proc getIterResult(iter: PSym): PSym =
|
proc getIterResult(iter: PSym; cache: IdentCache): PSym =
|
||||||
if resultPos < iter.ast.len:
|
if resultPos < iter.ast.len:
|
||||||
result = iter.ast.sons[resultPos].sym
|
result = iter.ast.sons[resultPos].sym
|
||||||
else:
|
else:
|
||||||
# XXX a bit hacky:
|
# XXX a bit hacky:
|
||||||
result = newSym(skResult, getIdent":result", iter, iter.info, {})
|
result = newSym(skResult, getIdent(cache, ":result"), iter, iter.info, {})
|
||||||
result.typ = iter.typ.sons[0]
|
result.typ = iter.typ.sons[0]
|
||||||
incl(result.flags, sfUsed)
|
incl(result.flags, sfUsed)
|
||||||
iter.ast.add newSymNode(result)
|
iter.ast.add newSymNode(result)
|
||||||
|
|
@ -245,7 +245,7 @@ proc liftIterSym*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
var env: PNode
|
var env: PNode
|
||||||
if owner.isIterator:
|
if owner.isIterator:
|
||||||
let it = getHiddenParam(g, owner)
|
let it = getHiddenParam(g, owner)
|
||||||
addUniqueField(it.typ.sons[0], hp)
|
addUniqueField(it.typ.sons[0], hp, g.cache)
|
||||||
env = indirectAccess(newSymNode(it), hp, hp.info)
|
env = indirectAccess(newSymNode(it), hp, hp.info)
|
||||||
else:
|
else:
|
||||||
let e = newSym(skLet, iter.name, owner, n.info)
|
let e = newSym(skLet, iter.name, owner, n.info)
|
||||||
|
|
@ -262,7 +262,7 @@ proc liftIterSym*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
proc freshVarForClosureIter*(g: ModuleGraph; s, owner: PSym): PNode =
|
proc freshVarForClosureIter*(g: ModuleGraph; s, owner: PSym): PNode =
|
||||||
let envParam = getHiddenParam(g, owner)
|
let envParam = getHiddenParam(g, owner)
|
||||||
let obj = envParam.typ.lastSon
|
let obj = envParam.typ.lastSon
|
||||||
addField(obj, s)
|
addField(obj, s, g.cache)
|
||||||
|
|
||||||
var access = newSymNode(envParam)
|
var access = newSymNode(envParam)
|
||||||
assert obj.kind == tyObject
|
assert obj.kind == tyObject
|
||||||
|
|
@ -326,7 +326,7 @@ proc createUpField(c: var DetectionPass; dest, dep: PSym; info: TLineInfo) =
|
||||||
if refObj == fieldType:
|
if refObj == fieldType:
|
||||||
localError(c.graph.config, dep.info, "internal error: invalid up reference computed")
|
localError(c.graph.config, dep.info, "internal error: invalid up reference computed")
|
||||||
|
|
||||||
let upIdent = getIdent(upName)
|
let upIdent = getIdent(c.graph.cache, upName)
|
||||||
let upField = lookupInRecord(obj.n, upIdent)
|
let upField = lookupInRecord(obj.n, upIdent)
|
||||||
if upField != nil:
|
if upField != nil:
|
||||||
if upField.typ != fieldType:
|
if upField.typ != fieldType:
|
||||||
|
|
@ -367,7 +367,7 @@ proc addClosureParam(c: var DetectionPass; fn: PSym; info: TLineInfo) =
|
||||||
let owner = if fn.kind == skIterator: fn else: fn.skipGenericOwner
|
let owner = if fn.kind == skIterator: fn else: fn.skipGenericOwner
|
||||||
let t = c.getEnvTypeForOwner(owner, info)
|
let t = c.getEnvTypeForOwner(owner, info)
|
||||||
if cp == nil:
|
if cp == nil:
|
||||||
cp = newSym(skParam, getIdent(paramName), fn, fn.info)
|
cp = newSym(skParam, getIdent(c.graph.cache, paramName), fn, fn.info)
|
||||||
incl(cp.flags, sfFromGeneric)
|
incl(cp.flags, sfFromGeneric)
|
||||||
cp.typ = t
|
cp.typ = t
|
||||||
addHiddenParam(fn, cp)
|
addHiddenParam(fn, cp)
|
||||||
|
|
@ -400,7 +400,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
|
||||||
if not c.capturedVars.containsOrIncl(s.id):
|
if not c.capturedVars.containsOrIncl(s.id):
|
||||||
let obj = getHiddenParam(c.graph, owner).typ.lastSon
|
let obj = getHiddenParam(c.graph, owner).typ.lastSon
|
||||||
#let obj = c.getEnvTypeForOwner(s.owner).lastSon
|
#let obj = c.getEnvTypeForOwner(s.owner).lastSon
|
||||||
addField(obj, s)
|
addField(obj, s, c.graph.cache)
|
||||||
# but always return because the rest of the proc is only relevant when
|
# but always return because the rest of the proc is only relevant when
|
||||||
# ow != owner:
|
# ow != owner:
|
||||||
return
|
return
|
||||||
|
|
@ -425,7 +425,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
|
||||||
if interestingVar(s) and not c.capturedVars.containsOrIncl(s.id):
|
if interestingVar(s) and not c.capturedVars.containsOrIncl(s.id):
|
||||||
let obj = c.getEnvTypeForOwner(ow, n.info).lastSon
|
let obj = c.getEnvTypeForOwner(ow, n.info).lastSon
|
||||||
#getHiddenParam(owner).typ.lastSon
|
#getHiddenParam(owner).typ.lastSon
|
||||||
addField(obj, s)
|
addField(obj, s, c.graph.cache)
|
||||||
# create required upFields:
|
# create required upFields:
|
||||||
var w = owner.skipGenericOwner
|
var w = owner.skipGenericOwner
|
||||||
if isInnerProc(w) or owner.isIterator:
|
if isInnerProc(w) or owner.isIterator:
|
||||||
|
|
@ -482,14 +482,14 @@ proc accessViaEnvParam(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
let field = getFieldFromObj(obj, s)
|
let field = getFieldFromObj(obj, s)
|
||||||
if field != nil:
|
if field != nil:
|
||||||
return rawIndirectAccess(access, field, n.info)
|
return rawIndirectAccess(access, field, n.info)
|
||||||
let upField = lookupInRecord(obj.n, getIdent(upName))
|
let upField = lookupInRecord(obj.n, getIdent(g.cache, upName))
|
||||||
if upField == nil: break
|
if upField == nil: break
|
||||||
access = rawIndirectAccess(access, upField, n.info)
|
access = rawIndirectAccess(access, upField, n.info)
|
||||||
localError(g.config, n.info, "internal error: environment misses: " & s.name.s)
|
localError(g.config, n.info, "internal error: environment misses: " & s.name.s)
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
proc newEnvVar(owner: PSym; typ: PType): PNode =
|
proc newEnvVar(cache: IdentCache; owner: PSym; typ: PType): PNode =
|
||||||
var v = newSym(skVar, getIdent(envName), owner, owner.info)
|
var v = newSym(skVar, getIdent(cache, envName), owner, owner.info)
|
||||||
incl(v.flags, sfShadowed)
|
incl(v.flags, sfShadowed)
|
||||||
v.typ = typ
|
v.typ = typ
|
||||||
result = newSymNode(v)
|
result = newSymNode(v)
|
||||||
|
|
@ -510,14 +510,14 @@ proc setupEnvVar(owner: PSym; d: DetectionPass;
|
||||||
let envVarType = d.ownerToType.getOrDefault(owner.id)
|
let envVarType = d.ownerToType.getOrDefault(owner.id)
|
||||||
if envVarType.isNil:
|
if envVarType.isNil:
|
||||||
localError d.graph.config, owner.info, "internal error: could not determine closure type"
|
localError d.graph.config, owner.info, "internal error: could not determine closure type"
|
||||||
result = newEnvVar(owner, envVarType)
|
result = newEnvVar(d.graph.cache, owner, envVarType)
|
||||||
c.envVars[owner.id] = result
|
c.envVars[owner.id] = result
|
||||||
|
|
||||||
proc getUpViaParam(g: ModuleGraph; owner: PSym): PNode =
|
proc getUpViaParam(g: ModuleGraph; owner: PSym): PNode =
|
||||||
let p = getHiddenParam(g, owner)
|
let p = getHiddenParam(g, owner)
|
||||||
result = p.newSymNode
|
result = p.newSymNode
|
||||||
if owner.isIterator:
|
if owner.isIterator:
|
||||||
let upField = lookupInRecord(p.typ.lastSon.n, getIdent(upName))
|
let upField = lookupInRecord(p.typ.lastSon.n, getIdent(g.cache, upName))
|
||||||
if upField == nil:
|
if upField == nil:
|
||||||
localError(g.config, owner.info, "could not find up reference for closure iter")
|
localError(g.config, owner.info, "could not find up reference for closure iter")
|
||||||
else:
|
else:
|
||||||
|
|
@ -546,7 +546,7 @@ proc rawClosureCreation(owner: PSym;
|
||||||
# add ``env.param = param``
|
# add ``env.param = param``
|
||||||
result.add(newAsgnStmt(fieldAccess, newSymNode(local), env.info))
|
result.add(newAsgnStmt(fieldAccess, newSymNode(local), env.info))
|
||||||
|
|
||||||
let upField = lookupInRecord(env.typ.lastSon.n, getIdent(upName))
|
let upField = lookupInRecord(env.typ.lastSon.n, getIdent(d.graph.cache, upName))
|
||||||
if upField != nil:
|
if upField != nil:
|
||||||
let up = getUpViaParam(d.graph, owner)
|
let up = getUpViaParam(d.graph, owner)
|
||||||
if up != nil and upField.typ == up.typ:
|
if up != nil and upField.typ == up.typ:
|
||||||
|
|
@ -562,13 +562,13 @@ proc closureCreationForIter(iter: PNode;
|
||||||
d: DetectionPass; c: var LiftingPass): PNode =
|
d: DetectionPass; c: var LiftingPass): PNode =
|
||||||
result = newNodeIT(nkStmtListExpr, iter.info, iter.sym.typ)
|
result = newNodeIT(nkStmtListExpr, iter.info, iter.sym.typ)
|
||||||
let owner = iter.sym.skipGenericOwner
|
let owner = iter.sym.skipGenericOwner
|
||||||
var v = newSym(skVar, getIdent(envName), owner, iter.info)
|
var v = newSym(skVar, getIdent(d.graph.cache, envName), owner, iter.info)
|
||||||
incl(v.flags, sfShadowed)
|
incl(v.flags, sfShadowed)
|
||||||
v.typ = getHiddenParam(d.graph, iter.sym).typ
|
v.typ = getHiddenParam(d.graph, iter.sym).typ
|
||||||
var vnode: PNode
|
var vnode: PNode
|
||||||
if owner.isIterator:
|
if owner.isIterator:
|
||||||
let it = getHiddenParam(d.graph, owner)
|
let it = getHiddenParam(d.graph, owner)
|
||||||
addUniqueField(it.typ.sons[0], v)
|
addUniqueField(it.typ.sons[0], v, d.graph.cache)
|
||||||
vnode = indirectAccess(newSymNode(it), v, v.info)
|
vnode = indirectAccess(newSymNode(it), v, v.info)
|
||||||
else:
|
else:
|
||||||
vnode = v.newSymNode
|
vnode = v.newSymNode
|
||||||
|
|
@ -577,7 +577,7 @@ proc closureCreationForIter(iter: PNode;
|
||||||
result.add(vs)
|
result.add(vs)
|
||||||
result.add(newCall(getSysSym(d.graph, iter.info, "internalNew"), vnode))
|
result.add(newCall(getSysSym(d.graph, iter.info, "internalNew"), vnode))
|
||||||
|
|
||||||
let upField = lookupInRecord(v.typ.lastSon.n, getIdent(upName))
|
let upField = lookupInRecord(v.typ.lastSon.n, getIdent(d.graph.cache, upName))
|
||||||
if upField != nil:
|
if upField != nil:
|
||||||
let u = setupEnvVar(owner, d, c)
|
let u = setupEnvVar(owner, d, c)
|
||||||
if u.typ == upField.typ:
|
if u.typ == upField.typ:
|
||||||
|
|
@ -625,7 +625,7 @@ proc transformYield(n: PNode; owner: PSym; d: DetectionPass;
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
var a = newNodeI(nkAsgn, n.sons[0].info)
|
var a = newNodeI(nkAsgn, n.sons[0].info)
|
||||||
var retVal = liftCapturedVars(n.sons[0], owner, d, c)
|
var retVal = liftCapturedVars(n.sons[0], owner, d, c)
|
||||||
addSon(a, newSymNode(getIterResult(owner)))
|
addSon(a, newSymNode(getIterResult(owner, d.graph.cache)))
|
||||||
addSon(a, retVal)
|
addSon(a, retVal)
|
||||||
retStmt.add(a)
|
retStmt.add(a)
|
||||||
else:
|
else:
|
||||||
|
|
@ -700,7 +700,7 @@ proc symToClosure(n: PNode; owner: PSym; d: DetectionPass;
|
||||||
if access.typ == wanted:
|
if access.typ == wanted:
|
||||||
return makeClosure(d.graph, s, access, n.info)
|
return makeClosure(d.graph, s, access, n.info)
|
||||||
let obj = access.typ.sons[0]
|
let obj = access.typ.sons[0]
|
||||||
let upField = lookupInRecord(obj.n, getIdent(upName))
|
let upField = lookupInRecord(obj.n, getIdent(d.graph.cache, upName))
|
||||||
if upField == nil:
|
if upField == nil:
|
||||||
localError(d.graph.config, n.info, "internal error: no environment found")
|
localError(d.graph.config, n.info, "internal error: no environment found")
|
||||||
return n
|
return n
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,14 @@ type
|
||||||
Ctx = object
|
Ctx = object
|
||||||
partialParam: PSym
|
partialParam: PSym
|
||||||
objType: PType
|
objType: PType
|
||||||
|
cache: IdentCache
|
||||||
|
|
||||||
proc interestingVar(s: PSym): bool {.inline.} =
|
proc interestingVar(s: PSym): bool {.inline.} =
|
||||||
result = s.kind in {skVar, skLet, skTemp, skForVar, skResult} and
|
result = s.kind in {skVar, skLet, skTemp, skForVar, skResult} and
|
||||||
sfGlobal notin s.flags
|
sfGlobal notin s.flags
|
||||||
|
|
||||||
proc lookupOrAdd(c: var Ctx; s: PSym; info: TLineInfo): PNode =
|
proc lookupOrAdd(c: var Ctx; s: PSym; info: TLineInfo): PNode =
|
||||||
let field = addUniqueField(c.objType, s)
|
let field = addUniqueField(c.objType, s, c.cache)
|
||||||
var deref = newNodeI(nkHiddenDeref, info)
|
var deref = newNodeI(nkHiddenDeref, info)
|
||||||
deref.typ = c.objType
|
deref.typ = c.objType
|
||||||
add(deref, newSymNode(c.partialParam, info))
|
add(deref, newSymNode(c.partialParam, info))
|
||||||
|
|
@ -52,7 +53,7 @@ proc lookupParam(params, dest: PNode): PSym =
|
||||||
if params[i].kind == nkSym and params[i].sym.name.id == dest.ident.id:
|
if params[i].kind == nkSym and params[i].sym.name.id == dest.ident.id:
|
||||||
return params[i].sym
|
return params[i].sym
|
||||||
|
|
||||||
proc liftLocalsIfRequested*(prc: PSym; n: PNode; conf: ConfigRef): PNode =
|
proc liftLocalsIfRequested*(prc: PSym; n: PNode; cache: IdentCache; conf: ConfigRef): PNode =
|
||||||
let liftDest = getPragmaVal(prc.ast, wLiftLocals)
|
let liftDest = getPragmaVal(prc.ast, wLiftLocals)
|
||||||
if liftDest == nil: return n
|
if liftDest == nil: return n
|
||||||
let partialParam = lookupParam(prc.typ.n, liftDest)
|
let partialParam = lookupParam(prc.typ.n, liftDest)
|
||||||
|
|
@ -64,7 +65,7 @@ proc liftLocalsIfRequested*(prc: PSym; n: PNode; conf: ConfigRef): PNode =
|
||||||
if objType.kind != tyObject or tfPartial notin objType.flags:
|
if objType.kind != tyObject or tfPartial notin objType.flags:
|
||||||
localError(conf, liftDest.info, "parameter '$1' is not a pointer to a partial object" % $liftDest)
|
localError(conf, liftDest.info, "parameter '$1' is not a pointer to a partial object" % $liftDest)
|
||||||
return n
|
return n
|
||||||
var c = Ctx(partialParam: partialParam, objType: objType)
|
var c = Ctx(partialParam: partialParam, objType: objType, cache: cache)
|
||||||
let w = newTree(nkStmtList, n)
|
let w = newTree(nkStmtList, n)
|
||||||
liftLocals(w, 0, c)
|
liftLocals(w, 0, c)
|
||||||
result = w[0]
|
result = w[0]
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ proc noidentError(conf: ConfigRef; n, origin: PNode) =
|
||||||
m.add "identifier expected, but found '" & n.renderTree & "'"
|
m.add "identifier expected, but found '" & n.renderTree & "'"
|
||||||
localError(conf, n.info, m)
|
localError(conf, n.info, m)
|
||||||
|
|
||||||
proc considerQuotedIdent*(conf: ConfigRef; n: PNode, origin: PNode = nil): PIdent =
|
proc considerQuotedIdent*(c: PContext; n: PNode, origin: PNode = nil): PIdent =
|
||||||
## Retrieve a PIdent from a PNode, taking into account accent nodes.
|
## Retrieve a PIdent from a PNode, taking into account accent nodes.
|
||||||
## ``origin`` can be nil. If it is not nil, it is used for a better
|
## ``origin`` can be nil. If it is not nil, it is used for a better
|
||||||
## error message.
|
## error message.
|
||||||
template handleError(n, origin: PNode) =
|
template handleError(n, origin: PNode) =
|
||||||
noidentError(conf, n, origin)
|
noidentError(c.config, n, origin)
|
||||||
result = getIdent"<Error>"
|
result = getIdent(c.cache, "<Error>")
|
||||||
|
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkIdent: result = n.ident
|
of nkIdent: result = n.ident
|
||||||
|
|
@ -36,7 +36,7 @@ proc considerQuotedIdent*(conf: ConfigRef; n: PNode, origin: PNode = nil): PIden
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
case n.len
|
case n.len
|
||||||
of 0: handleError(n, origin)
|
of 0: handleError(n, origin)
|
||||||
of 1: result = considerQuotedIdent(conf, n.sons[0], origin)
|
of 1: result = considerQuotedIdent(c, n.sons[0], origin)
|
||||||
else:
|
else:
|
||||||
var id = ""
|
var id = ""
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
|
|
@ -46,7 +46,7 @@ proc considerQuotedIdent*(conf: ConfigRef; n: PNode, origin: PNode = nil): PIden
|
||||||
of nkSym: id.add(x.sym.name.s)
|
of nkSym: id.add(x.sym.name.s)
|
||||||
of nkLiterals - nkFloatLiterals: id.add(x.renderTree)
|
of nkLiterals - nkFloatLiterals: id.add(x.renderTree)
|
||||||
else: handleError(n, origin)
|
else: handleError(n, origin)
|
||||||
result = getIdent(id)
|
result = getIdent(c.cache, id)
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
if n[0].kind == nkSym:
|
if n[0].kind == nkSym:
|
||||||
result = n.sons[0].sym.name
|
result = n.sons[0].sym.name
|
||||||
|
|
@ -126,9 +126,9 @@ proc errorSym*(c: PContext, n: PNode): PSym =
|
||||||
# ensure that 'considerQuotedIdent' can't fail:
|
# ensure that 'considerQuotedIdent' can't fail:
|
||||||
if m.kind == nkDotExpr: m = m.sons[1]
|
if m.kind == nkDotExpr: m = m.sons[1]
|
||||||
let ident = if m.kind in {nkIdent, nkSym, nkAccQuoted}:
|
let ident = if m.kind in {nkIdent, nkSym, nkAccQuoted}:
|
||||||
considerQuotedIdent(c.config, m)
|
considerQuotedIdent(c, m)
|
||||||
else:
|
else:
|
||||||
getIdent("err:" & renderTree(m))
|
getIdent(c.cache, "err:" & renderTree(m))
|
||||||
result = newSym(skError, ident, getCurrOwner(c), n.info, {})
|
result = newSym(skError, ident, getCurrOwner(c), n.info, {})
|
||||||
result.typ = errorType(c)
|
result.typ = errorType(c)
|
||||||
incl(result.flags, sfDiscardable)
|
incl(result.flags, sfDiscardable)
|
||||||
|
|
@ -140,7 +140,7 @@ type
|
||||||
TOverloadIterMode* = enum
|
TOverloadIterMode* = enum
|
||||||
oimDone, oimNoQualifier, oimSelfModule, oimOtherModule, oimSymChoice,
|
oimDone, oimNoQualifier, oimSelfModule, oimOtherModule, oimSymChoice,
|
||||||
oimSymChoiceLocalLookup
|
oimSymChoiceLocalLookup
|
||||||
TOverloadIter*{.final.} = object
|
TOverloadIter* = object
|
||||||
it*: TIdentIter
|
it*: TIdentIter
|
||||||
m*: PSym
|
m*: PSym
|
||||||
mode*: TOverloadIterMode
|
mode*: TOverloadIterMode
|
||||||
|
|
@ -277,7 +277,7 @@ proc lookUp*(c: PContext, n: PNode): PSym =
|
||||||
of nkSym:
|
of nkSym:
|
||||||
result = n.sym
|
result = n.sym
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
var ident = considerQuotedIdent(c.config, n)
|
var ident = considerQuotedIdent(c, n)
|
||||||
result = searchInScopes(c, ident).skipAlias(n, c.config)
|
result = searchInScopes(c, ident).skipAlias(n, c.config)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
fixSpelling(n, ident, searchInScopes)
|
fixSpelling(n, ident, searchInScopes)
|
||||||
|
|
@ -298,7 +298,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
|
||||||
const allExceptModule = {low(TSymKind)..high(TSymKind)}-{skModule,skPackage}
|
const allExceptModule = {low(TSymKind)..high(TSymKind)}-{skModule,skPackage}
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkIdent, nkAccQuoted:
|
of nkIdent, nkAccQuoted:
|
||||||
var ident = considerQuotedIdent(c.config, n)
|
var ident = considerQuotedIdent(c, n)
|
||||||
if checkModule in flags:
|
if checkModule in flags:
|
||||||
result = searchInScopes(c, ident).skipAlias(n, c.config)
|
result = searchInScopes(c, ident).skipAlias(n, c.config)
|
||||||
else:
|
else:
|
||||||
|
|
@ -324,7 +324,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
|
||||||
if n.sons[1].kind == nkIdent:
|
if n.sons[1].kind == nkIdent:
|
||||||
ident = n.sons[1].ident
|
ident = n.sons[1].ident
|
||||||
elif n.sons[1].kind == nkAccQuoted:
|
elif n.sons[1].kind == nkAccQuoted:
|
||||||
ident = considerQuotedIdent(c.config, n.sons[1])
|
ident = considerQuotedIdent(c, n.sons[1])
|
||||||
if ident != nil:
|
if ident != nil:
|
||||||
if m == c.module:
|
if m == c.module:
|
||||||
result = strTableGet(c.topLevelScope.symbols, ident).skipAlias(n, c.config)
|
result = strTableGet(c.topLevelScope.symbols, ident).skipAlias(n, c.config)
|
||||||
|
|
@ -348,7 +348,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
|
||||||
proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
|
proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkIdent, nkAccQuoted:
|
of nkIdent, nkAccQuoted:
|
||||||
var ident = considerQuotedIdent(c.config, n)
|
var ident = considerQuotedIdent(c, n)
|
||||||
o.scope = c.currentScope
|
o.scope = c.currentScope
|
||||||
o.mode = oimNoQualifier
|
o.mode = oimNoQualifier
|
||||||
while true:
|
while true:
|
||||||
|
|
@ -369,7 +369,7 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
|
||||||
if n.sons[1].kind == nkIdent:
|
if n.sons[1].kind == nkIdent:
|
||||||
ident = n.sons[1].ident
|
ident = n.sons[1].ident
|
||||||
elif n.sons[1].kind == nkAccQuoted:
|
elif n.sons[1].kind == nkAccQuoted:
|
||||||
ident = considerQuotedIdent(c.config, n.sons[1], n)
|
ident = considerQuotedIdent(c, n.sons[1], n)
|
||||||
if ident != nil:
|
if ident != nil:
|
||||||
if o.m == c.module:
|
if o.m == c.module:
|
||||||
# a module may access its private members:
|
# a module may access its private members:
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ proc lowerTupleUnpacking*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
let value = n.lastSon
|
let value = n.lastSon
|
||||||
result = newNodeI(nkStmtList, n.info)
|
result = newNodeI(nkStmtList, n.info)
|
||||||
|
|
||||||
var temp = newSym(skTemp, getIdent(genPrefix), owner, value.info, g.config.options)
|
var temp = newSym(skTemp, getIdent(g.cache, genPrefix), owner, value.info, g.config.options)
|
||||||
temp.typ = skipTypes(value.typ, abstractInst)
|
temp.typ = skipTypes(value.typ, abstractInst)
|
||||||
incl(temp.flags, sfFromGeneric)
|
incl(temp.flags, sfFromGeneric)
|
||||||
|
|
||||||
|
|
@ -74,11 +74,11 @@ proc newTupleAccessRaw*(tup: PNode, i: int): PNode =
|
||||||
proc newTryFinally*(body, final: PNode): PNode =
|
proc newTryFinally*(body, final: PNode): PNode =
|
||||||
result = newTree(nkTryStmt, body, newTree(nkFinally, final))
|
result = newTree(nkTryStmt, body, newTree(nkFinally, final))
|
||||||
|
|
||||||
proc lowerTupleUnpackingForAsgn*(n: PNode; owner: PSym): PNode =
|
proc lowerTupleUnpackingForAsgn*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
let value = n.lastSon
|
let value = n.lastSon
|
||||||
result = newNodeI(nkStmtList, n.info)
|
result = newNodeI(nkStmtList, n.info)
|
||||||
|
|
||||||
var temp = newSym(skLet, getIdent("_"), owner, value.info, owner.options)
|
var temp = newSym(skLet, getIdent(g.cache, "_"), owner, value.info, owner.options)
|
||||||
var v = newNodeI(nkLetSection, value.info)
|
var v = newNodeI(nkLetSection, value.info)
|
||||||
let tempAsNode = newSymNode(temp) #newIdentNode(getIdent(genPrefix & $temp.id), value.info)
|
let tempAsNode = newSymNode(temp) #newIdentNode(getIdent(genPrefix & $temp.id), value.info)
|
||||||
|
|
||||||
|
|
@ -93,10 +93,10 @@ proc lowerTupleUnpackingForAsgn*(n: PNode; owner: PSym): PNode =
|
||||||
for i in 0 .. lhs.len-1:
|
for i in 0 .. lhs.len-1:
|
||||||
result.add newAsgnStmt(lhs.sons[i], newTupleAccessRaw(tempAsNode, i))
|
result.add newAsgnStmt(lhs.sons[i], newTupleAccessRaw(tempAsNode, i))
|
||||||
|
|
||||||
proc lowerSwap*(n: PNode; owner: PSym): PNode =
|
proc lowerSwap*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
|
||||||
result = newNodeI(nkStmtList, n.info)
|
result = newNodeI(nkStmtList, n.info)
|
||||||
# note: cannot use 'skTemp' here cause we really need the copy for the VM :-(
|
# note: cannot use 'skTemp' here cause we really need the copy for the VM :-(
|
||||||
var temp = newSym(skVar, getIdent(genPrefix), owner, n.info, owner.options)
|
var temp = newSym(skVar, getIdent(g.cache, genPrefix), owner, n.info, owner.options)
|
||||||
temp.typ = n.sons[1].typ
|
temp.typ = n.sons[1].typ
|
||||||
incl(temp.flags, sfFromGeneric)
|
incl(temp.flags, sfFromGeneric)
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ proc createObj*(g: ModuleGraph; owner: PSym, info: TLineInfo; final=true): PType
|
||||||
else:
|
else:
|
||||||
rawAddSon(result, getCompilerProc(g, "RootObj").typ)
|
rawAddSon(result, getCompilerProc(g, "RootObj").typ)
|
||||||
result.n = newNodeI(nkRecList, info)
|
result.n = newNodeI(nkRecList, info)
|
||||||
let s = newSym(skType, getIdent("Env_" & toFilename(g.config, info)),
|
let s = newSym(skType, getIdent(g.cache, "Env_" & toFilename(g.config, info)),
|
||||||
owner, info, owner.options)
|
owner, info, owner.options)
|
||||||
incl s.flags, sfAnon
|
incl s.flags, sfAnon
|
||||||
s.typ = result
|
s.typ = result
|
||||||
|
|
@ -172,10 +172,10 @@ proc lookupInRecord(n: PNode, id: int): PSym =
|
||||||
if n.sym.id == -abs(id): result = n.sym
|
if n.sym.id == -abs(id): result = n.sym
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc addField*(obj: PType; s: PSym) =
|
proc addField*(obj: PType; s: PSym; cache: IdentCache) =
|
||||||
# because of 'gensym' support, we have to mangle the name with its ID.
|
# because of 'gensym' support, we have to mangle the name with its ID.
|
||||||
# This is hacky but the clean solution is much more complex than it looks.
|
# This is hacky but the clean solution is much more complex than it looks.
|
||||||
var field = newSym(skField, getIdent(s.name.s & $obj.n.len), s.owner, s.info,
|
var field = newSym(skField, getIdent(cache, s.name.s & $obj.n.len), s.owner, s.info,
|
||||||
s.options)
|
s.options)
|
||||||
field.id = -s.id
|
field.id = -s.id
|
||||||
let t = skipIntLit(s.typ)
|
let t = skipIntLit(s.typ)
|
||||||
|
|
@ -184,10 +184,10 @@ proc addField*(obj: PType; s: PSym) =
|
||||||
field.position = sonsLen(obj.n)
|
field.position = sonsLen(obj.n)
|
||||||
addSon(obj.n, newSymNode(field))
|
addSon(obj.n, newSymNode(field))
|
||||||
|
|
||||||
proc addUniqueField*(obj: PType; s: PSym): PSym {.discardable.} =
|
proc addUniqueField*(obj: PType; s: PSym; cache: IdentCache): PSym {.discardable.} =
|
||||||
result = lookupInRecord(obj.n, s.id)
|
result = lookupInRecord(obj.n, s.id)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
var field = newSym(skField, getIdent(s.name.s & $obj.n.len), s.owner, s.info,
|
var field = newSym(skField, getIdent(cache, s.name.s & $obj.n.len), s.owner, s.info,
|
||||||
s.options)
|
s.options)
|
||||||
field.id = -s.id
|
field.id = -s.id
|
||||||
let t = skipIntLit(s.typ)
|
let t = skipIntLit(s.typ)
|
||||||
|
|
@ -228,13 +228,13 @@ proc indirectAccess*(a: PNode, b: int, info: TLineInfo): PNode =
|
||||||
addSon(result, newSymNode(field))
|
addSon(result, newSymNode(field))
|
||||||
result.typ = field.typ
|
result.typ = field.typ
|
||||||
|
|
||||||
proc indirectAccess(a: PNode, b: string, info: TLineInfo): PNode =
|
proc indirectAccess(a: PNode, b: string, info: TLineInfo; cache: IdentCache): PNode =
|
||||||
# returns a[].b as a node
|
# returns a[].b as a node
|
||||||
var deref = newNodeI(nkHiddenDeref, info)
|
var deref = newNodeI(nkHiddenDeref, info)
|
||||||
deref.typ = a.typ.skipTypes(abstractInst).sons[0]
|
deref.typ = a.typ.skipTypes(abstractInst).sons[0]
|
||||||
var t = deref.typ.skipTypes(abstractInst)
|
var t = deref.typ.skipTypes(abstractInst)
|
||||||
var field: PSym
|
var field: PSym
|
||||||
let bb = getIdent(b)
|
let bb = getIdent(cache, b)
|
||||||
while true:
|
while true:
|
||||||
assert t.kind == tyObject
|
assert t.kind == tyObject
|
||||||
field = getSymFromList(t.n, bb)
|
field = getSymFromList(t.n, bb)
|
||||||
|
|
@ -338,7 +338,7 @@ proc typeNeedsNoDeepCopy(t: PType): bool =
|
||||||
|
|
||||||
proc addLocalVar(g: ModuleGraph; varSection, varInit: PNode; owner: PSym; typ: PType;
|
proc addLocalVar(g: ModuleGraph; varSection, varInit: PNode; owner: PSym; typ: PType;
|
||||||
v: PNode; useShallowCopy=false): PSym =
|
v: PNode; useShallowCopy=false): PSym =
|
||||||
result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info,
|
result = newSym(skTemp, getIdent(g.cache, genPrefix), owner, varSection.info,
|
||||||
owner.options)
|
owner.options)
|
||||||
result.typ = typ
|
result.typ = typ
|
||||||
incl(result.flags, sfFromGeneric)
|
incl(result.flags, sfFromGeneric)
|
||||||
|
|
@ -411,7 +411,7 @@ proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym;
|
||||||
# generate:
|
# generate:
|
||||||
# fv.owner = threadParam
|
# fv.owner = threadParam
|
||||||
body.add newAsgnStmt(indirectAccess(threadLocalProm.newSymNode,
|
body.add newAsgnStmt(indirectAccess(threadLocalProm.newSymNode,
|
||||||
"owner", fv.info), threadParam.newSymNode)
|
"owner", fv.info, g.cache), threadParam.newSymNode)
|
||||||
|
|
||||||
body.add callCodegenProc(g, "nimArgsPassingDone", threadParam.newSymNode)
|
body.add callCodegenProc(g, "nimArgsPassingDone", threadParam.newSymNode)
|
||||||
if spawnKind == srByVar:
|
if spawnKind == srByVar:
|
||||||
|
|
@ -422,12 +422,12 @@ proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym;
|
||||||
localError(g.config, f.info, "cannot create a flowVar of type: " &
|
localError(g.config, f.info, "cannot create a flowVar of type: " &
|
||||||
typeToString(fv.typ.sons[1]))
|
typeToString(fv.typ.sons[1]))
|
||||||
body.add newAsgnStmt(indirectAccess(threadLocalProm.newSymNode,
|
body.add newAsgnStmt(indirectAccess(threadLocalProm.newSymNode,
|
||||||
if fk == fvGC: "data" else: "blob", fv.info), call)
|
if fk == fvGC: "data" else: "blob", fv.info, g.cache), call)
|
||||||
if fk == fvGC:
|
if fk == fvGC:
|
||||||
let incRefCall = newNodeI(nkCall, fv.info, 2)
|
let incRefCall = newNodeI(nkCall, fv.info, 2)
|
||||||
incRefCall.sons[0] = newSymNode(getSysMagic(g, fv.info, "GCref", mGCref))
|
incRefCall.sons[0] = newSymNode(getSysMagic(g, fv.info, "GCref", mGCref))
|
||||||
incRefCall.sons[1] = indirectAccess(threadLocalProm.newSymNode,
|
incRefCall.sons[1] = indirectAccess(threadLocalProm.newSymNode,
|
||||||
"data", fv.info)
|
"data", fv.info, g.cache)
|
||||||
body.add incRefCall
|
body.add incRefCall
|
||||||
if barrier == nil:
|
if barrier == nil:
|
||||||
# by now 'fv' is shared and thus might have beeen overwritten! we need
|
# by now 'fv' is shared and thus might have beeen overwritten! we need
|
||||||
|
|
@ -453,7 +453,7 @@ proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym;
|
||||||
t.n.add argsParam.newSymNode
|
t.n.add argsParam.newSymNode
|
||||||
|
|
||||||
let name = (if f.kind == nkSym: f.sym.name.s else: genPrefix) & "Wrapper"
|
let name = (if f.kind == nkSym: f.sym.name.s else: genPrefix) & "Wrapper"
|
||||||
result = newSym(skProc, getIdent(name), argsParam.owner, f.info,
|
result = newSym(skProc, getIdent(g.cache, name), argsParam.owner, f.info,
|
||||||
argsParam.options)
|
argsParam.options)
|
||||||
let emptyNode = newNodeI(nkEmpty, f.info)
|
let emptyNode = newNodeI(nkEmpty, f.info)
|
||||||
result.ast = newProcNode(nkProcDef, f.info, body = body,
|
result.ast = newProcNode(nkProcDef, f.info, body = body,
|
||||||
|
|
@ -473,7 +473,7 @@ proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
castExpr, call,
|
castExpr, call,
|
||||||
varSection, varInit, result: PNode) =
|
varSection, varInit, result: PNode) =
|
||||||
let formals = n[0].typ.n
|
let formals = n[0].typ.n
|
||||||
let tmpName = getIdent(genPrefix)
|
let tmpName = getIdent(g.cache, genPrefix)
|
||||||
for i in 1 ..< n.len:
|
for i in 1 ..< n.len:
|
||||||
# we pick n's type here, which hopefully is 'tyArray' and not
|
# we pick n's type here, which hopefully is 'tyArray' and not
|
||||||
# 'tyOpenArray':
|
# 'tyOpenArray':
|
||||||
|
|
@ -486,7 +486,7 @@ proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
let fieldname = if i < formals.len: formals[i].sym.name else: tmpName
|
let fieldname = if i < formals.len: formals[i].sym.name else: tmpName
|
||||||
var field = newSym(skField, fieldname, objType.owner, n.info, g.config.options)
|
var field = newSym(skField, fieldname, objType.owner, n.info, g.config.options)
|
||||||
field.typ = argType
|
field.typ = argType
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[i])
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[i])
|
||||||
|
|
||||||
let temp = addLocalVar(g, varSection, varInit, objType.owner, argType,
|
let temp = addLocalVar(g, varSection, varInit, objType.owner, argType,
|
||||||
|
|
@ -527,7 +527,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
castExpr, call,
|
castExpr, call,
|
||||||
varSection, varInit, result: PNode) =
|
varSection, varInit, result: PNode) =
|
||||||
let formals = n[0].typ.n
|
let formals = n[0].typ.n
|
||||||
let tmpName = getIdent(genPrefix)
|
let tmpName = getIdent(g.cache, genPrefix)
|
||||||
# we need to copy the foreign scratch object fields into local variables
|
# we need to copy the foreign scratch object fields into local variables
|
||||||
# for correctness: These are called 'threadLocal' here.
|
# for correctness: These are called 'threadLocal' here.
|
||||||
for i in 1 ..< n.len:
|
for i in 1 ..< n.len:
|
||||||
|
|
@ -548,17 +548,17 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
slice.sons[0].typ = getSysType(g, n.info, tyInt) # fake type
|
slice.sons[0].typ = getSysType(g, n.info, tyInt) # fake type
|
||||||
var fieldB = newSym(skField, tmpName, objType.owner, n.info, g.config.options)
|
var fieldB = newSym(skField, tmpName, objType.owner, n.info, g.config.options)
|
||||||
fieldB.typ = getSysType(g, n.info, tyInt)
|
fieldB.typ = getSysType(g, n.info, tyInt)
|
||||||
objType.addField(fieldB)
|
objType.addField(fieldB, g.cache)
|
||||||
|
|
||||||
if getMagic(n) == mSlice:
|
if getMagic(n) == mSlice:
|
||||||
let a = genAddrOf(n[1])
|
let a = genAddrOf(n[1])
|
||||||
field.typ = a.typ
|
field.typ = a.typ
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
|
||||||
|
|
||||||
var fieldA = newSym(skField, tmpName, objType.owner, n.info, g.config.options)
|
var fieldA = newSym(skField, tmpName, objType.owner, n.info, g.config.options)
|
||||||
fieldA.typ = getSysType(g, n.info, tyInt)
|
fieldA.typ = getSysType(g, n.info, tyInt)
|
||||||
objType.addField(fieldA)
|
objType.addField(fieldA, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldA), n[2])
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldA), n[2])
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3])
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3])
|
||||||
|
|
||||||
|
|
@ -569,7 +569,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
else:
|
else:
|
||||||
let a = genAddrOf(n)
|
let a = genAddrOf(n)
|
||||||
field.typ = a.typ
|
field.typ = a.typ
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), genHigh(g, n))
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), genHigh(g, n))
|
||||||
|
|
||||||
|
|
@ -587,7 +587,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
# it is more efficient to pass a pointer instead:
|
# it is more efficient to pass a pointer instead:
|
||||||
let a = genAddrOf(n)
|
let a = genAddrOf(n)
|
||||||
field.typ = a.typ
|
field.typ = a.typ
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
|
||||||
let threadLocal = addLocalVar(g, varSection,nil, objType.owner, field.typ,
|
let threadLocal = addLocalVar(g, varSection,nil, objType.owner, field.typ,
|
||||||
indirectAccess(castExpr, field, n.info),
|
indirectAccess(castExpr, field, n.info),
|
||||||
|
|
@ -596,7 +596,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb
|
||||||
else:
|
else:
|
||||||
# boring case
|
# boring case
|
||||||
field.typ = argType
|
field.typ = argType
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n)
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n)
|
||||||
let threadLocal = addLocalVar(g, varSection, varInit,
|
let threadLocal = addLocalVar(g, varSection, varInit,
|
||||||
objType.owner, field.typ,
|
objType.owner, field.typ,
|
||||||
|
|
@ -628,8 +628,8 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P
|
||||||
if {tfThread, tfNoSideEffect} * n[0].typ.flags == {}:
|
if {tfThread, tfNoSideEffect} * n[0].typ.flags == {}:
|
||||||
localError(g.config, n.info, "'spawn' takes a GC safe call expression")
|
localError(g.config, n.info, "'spawn' takes a GC safe call expression")
|
||||||
var
|
var
|
||||||
threadParam = newSym(skParam, getIdent"thread", owner, n.info, g.config.options)
|
threadParam = newSym(skParam, getIdent(g.cache, "thread"), owner, n.info, g.config.options)
|
||||||
argsParam = newSym(skParam, getIdent"args", owner, n.info, g.config.options)
|
argsParam = newSym(skParam, getIdent(g.cache, "args"), owner, n.info, g.config.options)
|
||||||
block:
|
block:
|
||||||
let ptrType = getSysType(g, n.info, tyPointer)
|
let ptrType = getSysType(g, n.info, tyPointer)
|
||||||
threadParam.typ = ptrType
|
threadParam.typ = ptrType
|
||||||
|
|
@ -640,7 +640,7 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P
|
||||||
incl(objType.flags, tfFinal)
|
incl(objType.flags, tfFinal)
|
||||||
let castExpr = createCastExpr(argsParam, objType)
|
let castExpr = createCastExpr(argsParam, objType)
|
||||||
|
|
||||||
var scratchObj = newSym(skVar, getIdent"scratch", owner, n.info, g.config.options)
|
var scratchObj = newSym(skVar, getIdent(g.cache, "scratch"), owner, n.info, g.config.options)
|
||||||
block:
|
block:
|
||||||
scratchObj.typ = objType
|
scratchObj.typ = objType
|
||||||
incl(scratchObj.flags, sfFromGeneric)
|
incl(scratchObj.flags, sfFromGeneric)
|
||||||
|
|
@ -658,9 +658,9 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P
|
||||||
skFunc, skMethod, skConverter}):
|
skFunc, skMethod, skConverter}):
|
||||||
# for indirect calls we pass the function pointer in the scratchObj
|
# for indirect calls we pass the function pointer in the scratchObj
|
||||||
var argType = n[0].typ.skipTypes(abstractInst)
|
var argType = n[0].typ.skipTypes(abstractInst)
|
||||||
var field = newSym(skField, getIdent"fn", owner, n.info, g.config.options)
|
var field = newSym(skField, getIdent(g.cache, "fn"), owner, n.info, g.config.options)
|
||||||
field.typ = argType
|
field.typ = argType
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[0])
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[0])
|
||||||
fn = indirectAccess(castExpr, field, n.info)
|
fn = indirectAccess(castExpr, field, n.info)
|
||||||
elif fn.kind == nkSym and fn.sym.kind == skIterator:
|
elif fn.kind == nkSym and fn.sym.kind == skIterator:
|
||||||
|
|
@ -682,17 +682,17 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P
|
||||||
if barrier != nil:
|
if barrier != nil:
|
||||||
let typ = newType(tyPtr, owner)
|
let typ = newType(tyPtr, owner)
|
||||||
typ.rawAddSon(magicsys.getCompilerProc(g, "Barrier").typ)
|
typ.rawAddSon(magicsys.getCompilerProc(g, "Barrier").typ)
|
||||||
var field = newSym(skField, getIdent"barrier", owner, n.info, g.config.options)
|
var field = newSym(skField, getIdent(g.cache, "barrier"), owner, n.info, g.config.options)
|
||||||
field.typ = typ
|
field.typ = typ
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), barrier)
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), barrier)
|
||||||
barrierAsExpr = indirectAccess(castExpr, field, n.info)
|
barrierAsExpr = indirectAccess(castExpr, field, n.info)
|
||||||
|
|
||||||
var fvField, fvAsExpr: PNode = nil
|
var fvField, fvAsExpr: PNode = nil
|
||||||
if spawnKind == srFlowVar:
|
if spawnKind == srFlowVar:
|
||||||
var field = newSym(skField, getIdent"fv", owner, n.info, g.config.options)
|
var field = newSym(skField, getIdent(g.cache, "fv"), owner, n.info, g.config.options)
|
||||||
field.typ = retType
|
field.typ = retType
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
fvField = newDotExpr(scratchObj, field)
|
fvField = newDotExpr(scratchObj, field)
|
||||||
fvAsExpr = indirectAccess(castExpr, field, n.info)
|
fvAsExpr = indirectAccess(castExpr, field, n.info)
|
||||||
# create flowVar:
|
# create flowVar:
|
||||||
|
|
@ -701,10 +701,10 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P
|
||||||
result.add callCodegenProc(g, "nimFlowVarCreateSemaphore", fvField)
|
result.add callCodegenProc(g, "nimFlowVarCreateSemaphore", fvField)
|
||||||
|
|
||||||
elif spawnKind == srByVar:
|
elif spawnKind == srByVar:
|
||||||
var field = newSym(skField, getIdent"fv", owner, n.info, g.config.options)
|
var field = newSym(skField, getIdent(g.cache, "fv"), owner, n.info, g.config.options)
|
||||||
field.typ = newType(tyPtr, objType.owner)
|
field.typ = newType(tyPtr, objType.owner)
|
||||||
field.typ.rawAddSon(retType)
|
field.typ.rawAddSon(retType)
|
||||||
objType.addField(field)
|
objType.addField(field, g.cache)
|
||||||
fvAsExpr = indirectAccess(castExpr, field, n.info)
|
fvAsExpr = indirectAccess(castExpr, field, n.info)
|
||||||
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), genAddrOf(dest))
|
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), genAddrOf(dest))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,27 +26,17 @@ proc newSysType(g: ModuleGraph; kind: TTypeKind, size: int): PType =
|
||||||
result.align = size.int16
|
result.align = size.int16
|
||||||
|
|
||||||
proc getSysSym*(g: ModuleGraph; info: TLineInfo; name: string): PSym =
|
proc getSysSym*(g: ModuleGraph; info: TLineInfo; name: string): PSym =
|
||||||
result = strTableGet(g.systemModule.tab, getIdent(name))
|
result = strTableGet(g.systemModule.tab, getIdent(g.cache, name))
|
||||||
if result == nil:
|
if result == nil:
|
||||||
localError(g.config, info, "system module needs: " & name)
|
localError(g.config, info, "system module needs: " & name)
|
||||||
result = newSym(skError, getIdent(name), g.systemModule, g.systemModule.info, {})
|
result = newSym(skError, getIdent(g.cache, name), g.systemModule, g.systemModule.info, {})
|
||||||
result.typ = newType(tyError, g.systemModule)
|
result.typ = newType(tyError, g.systemModule)
|
||||||
if result.kind == skStub: loadStub(result)
|
if result.kind == skStub: loadStub(result)
|
||||||
if result.kind == skAlias: result = result.owner
|
if result.kind == skAlias: result = result.owner
|
||||||
|
|
||||||
when false:
|
|
||||||
proc createMagic*(g: ModuleGraph; name: string, m: TMagic): PSym =
|
|
||||||
result = newSym(skProc, getIdent(name), nil, unknownLineInfo())
|
|
||||||
result.magic = m
|
|
||||||
|
|
||||||
when false:
|
|
||||||
let
|
|
||||||
opNot* = createMagic("not", mNot)
|
|
||||||
opContains* = createMagic("contains", mInSet)
|
|
||||||
|
|
||||||
proc getSysMagic*(g: ModuleGraph; info: TLineInfo; name: string, m: TMagic): PSym =
|
proc getSysMagic*(g: ModuleGraph; info: TLineInfo; name: string, m: TMagic): PSym =
|
||||||
var ti: TIdentIter
|
var ti: TIdentIter
|
||||||
let id = getIdent(name)
|
let id = getIdent(g.cache, name)
|
||||||
var r = initIdentIter(ti, g.systemModule.tab, id)
|
var r = initIdentIter(ti, g.systemModule.tab, id)
|
||||||
while r != nil:
|
while r != nil:
|
||||||
if r.kind == skStub: loadStub(r)
|
if r.kind == skStub: loadStub(r)
|
||||||
|
|
@ -167,7 +157,7 @@ proc setIntLitType*(g: ModuleGraph; result: PNode) =
|
||||||
internalError(g.config, result.info, "invalid int size")
|
internalError(g.config, result.info, "invalid int size")
|
||||||
|
|
||||||
proc getCompilerProc*(g: ModuleGraph; name: string): PSym =
|
proc getCompilerProc*(g: ModuleGraph; name: string): PSym =
|
||||||
let ident = getIdent(name)
|
let ident = getIdent(g.cache, name)
|
||||||
result = strTableGet(g.compilerprocs, ident)
|
result = strTableGet(g.compilerprocs, ident)
|
||||||
when false:
|
when false:
|
||||||
if result == nil:
|
if result == nil:
|
||||||
|
|
@ -190,6 +180,6 @@ proc registerNimScriptSymbol*(g: ModuleGraph; s: PSym) =
|
||||||
"symbol conflicts with other .exportNims symbol at: " & g.config$conflict.info)
|
"symbol conflicts with other .exportNims symbol at: " & g.config$conflict.info)
|
||||||
|
|
||||||
proc getNimScriptSymbol*(g: ModuleGraph; name: string): PSym =
|
proc getNimScriptSymbol*(g: ModuleGraph; name: string): PSym =
|
||||||
strTableGet(g.exposed, getIdent(name))
|
strTableGet(g.exposed, getIdent(g.cache, name))
|
||||||
|
|
||||||
proc resetNimScriptSymbols*(g: ModuleGraph) = initStrTable(g.exposed)
|
proc resetNimScriptSymbols*(g: ModuleGraph) = initStrTable(g.exposed)
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
wantMainModule(conf)
|
wantMainModule(conf)
|
||||||
conf.cmd = cmdDoc
|
conf.cmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
commandDoc(conf)
|
commandDoc(cache, conf)
|
||||||
of "doc2", "doc":
|
of "doc2", "doc":
|
||||||
conf.cmd = cmdDoc
|
conf.cmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
|
|
@ -198,18 +198,18 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
of "rst2html":
|
of "rst2html":
|
||||||
conf.cmd = cmdRst2html
|
conf.cmd = cmdRst2html
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
commandRst2Html(conf)
|
commandRst2Html(cache, conf)
|
||||||
of "rst2tex":
|
of "rst2tex":
|
||||||
conf.cmd = cmdRst2tex
|
conf.cmd = cmdRst2tex
|
||||||
loadConfigs(DocTexConfig, cache, conf)
|
loadConfigs(DocTexConfig, cache, conf)
|
||||||
commandRst2TeX(conf)
|
commandRst2TeX(cache, conf)
|
||||||
of "jsondoc0":
|
of "jsondoc0":
|
||||||
wantMainModule(conf)
|
wantMainModule(conf)
|
||||||
conf.cmd = cmdDoc
|
conf.cmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
wantMainModule(conf)
|
wantMainModule(conf)
|
||||||
defineSymbol(conf.symbols, "nimdoc")
|
defineSymbol(conf.symbols, "nimdoc")
|
||||||
commandJson(conf)
|
commandJson(cache, conf)
|
||||||
of "jsondoc2", "jsondoc":
|
of "jsondoc2", "jsondoc":
|
||||||
conf.cmd = cmdDoc
|
conf.cmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
|
|
@ -221,11 +221,11 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
conf.cmd = cmdDoc
|
conf.cmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
defineSymbol(conf.symbols, "nimdoc")
|
defineSymbol(conf.symbols, "nimdoc")
|
||||||
commandTags(conf)
|
commandTags(cache, conf)
|
||||||
of "buildindex":
|
of "buildindex":
|
||||||
conf.cmd = cmdDoc
|
conf.cmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache, conf)
|
loadConfigs(DocConfig, cache, conf)
|
||||||
commandBuildIndex(conf)
|
commandBuildIndex(cache, conf)
|
||||||
of "gendepend":
|
of "gendepend":
|
||||||
conf.cmd = cmdGenDepend
|
conf.cmd = cmdGenDepend
|
||||||
commandGenDepend(graph, cache)
|
commandGenDepend(graph, cache)
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ type
|
||||||
# module dependencies.
|
# module dependencies.
|
||||||
backend*: RootRef # minor hack so that a backend can extend this easily
|
backend*: RootRef # minor hack so that a backend can extend this easily
|
||||||
config*: ConfigRef
|
config*: ConfigRef
|
||||||
|
cache*: IdentCache
|
||||||
doStopCompile*: proc(): bool {.closure.}
|
doStopCompile*: proc(): bool {.closure.}
|
||||||
usageSym*: PSym # for nimsuggest
|
usageSym*: PSym # for nimsuggest
|
||||||
owners*: seq[PSym]
|
owners*: seq[PSym]
|
||||||
|
|
@ -60,20 +61,18 @@ proc stopCompile*(g: ModuleGraph): bool {.inline.} =
|
||||||
result = doStopCompile != nil and doStopCompile()
|
result = doStopCompile != nil and doStopCompile()
|
||||||
|
|
||||||
proc createMagic*(g: ModuleGraph; name: string, m: TMagic): PSym =
|
proc createMagic*(g: ModuleGraph; name: string, m: TMagic): PSym =
|
||||||
result = newSym(skProc, getIdent(name), nil, unknownLineInfo(), {})
|
result = newSym(skProc, getIdent(g.cache, name), nil, unknownLineInfo(), {})
|
||||||
result.magic = m
|
result.magic = m
|
||||||
|
|
||||||
proc newModuleGraph*(config: ConfigRef = nil): ModuleGraph =
|
proc newModuleGraph*(cache: IdentCache; config: ConfigRef): ModuleGraph =
|
||||||
result = ModuleGraph()
|
result = ModuleGraph()
|
||||||
initStrTable(result.packageSyms)
|
initStrTable(result.packageSyms)
|
||||||
result.deps = initIntSet()
|
result.deps = initIntSet()
|
||||||
result.modules = @[]
|
result.modules = @[]
|
||||||
result.importStack = @[]
|
result.importStack = @[]
|
||||||
result.inclToMod = initTable[FileIndex, FileIndex]()
|
result.inclToMod = initTable[FileIndex, FileIndex]()
|
||||||
if config.isNil:
|
|
||||||
result.config = newConfigRef()
|
|
||||||
else:
|
|
||||||
result.config = config
|
result.config = config
|
||||||
|
result.cache = cache
|
||||||
result.owners = @[]
|
result.owners = @[]
|
||||||
result.methods = @[]
|
result.methods = @[]
|
||||||
initStrTable(result.compilerprocs)
|
initStrTable(result.compilerprocs)
|
||||||
|
|
@ -106,7 +105,7 @@ proc addDep*(g: ModuleGraph; m: PSym, dep: FileIndex) =
|
||||||
if suggestMode:
|
if suggestMode:
|
||||||
deps.incl m.position.dependsOn(dep.int)
|
deps.incl m.position.dependsOn(dep.int)
|
||||||
# we compute the transitive closure later when quering the graph lazily.
|
# we compute the transitive closure later when quering the graph lazily.
|
||||||
# this improve efficiency quite a lot:
|
# this improves efficiency quite a lot:
|
||||||
#invalidTransitiveClosure = true
|
#invalidTransitiveClosure = true
|
||||||
|
|
||||||
proc addIncludeDep*(g: ModuleGraph; module, includeFile: FileIndex) =
|
proc addIncludeDep*(g: ModuleGraph; module, includeFile: FileIndex) =
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string =
|
||||||
of nkInfix:
|
of nkInfix:
|
||||||
let n0 = n[0]
|
let n0 = n[0]
|
||||||
let n1 = n[1]
|
let n1 = n[1]
|
||||||
if n0.kind == nkIdent and n0.ident.id == getIdent("as").id:
|
if n0.kind == nkIdent and n0.ident.s == "as":
|
||||||
# XXX hack ahead:
|
# XXX hack ahead:
|
||||||
n.kind = nkImportAs
|
n.kind = nkImportAs
|
||||||
n.sons[0] = n.sons[1]
|
n.sons[0] = n.sons[1]
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
|
||||||
result.id = -1 # for better error checking
|
result.id = -1 # for better error checking
|
||||||
result.kind = skModule
|
result.kind = skModule
|
||||||
let filename = toFullPath(graph.config, fileIdx)
|
let filename = toFullPath(graph.config, fileIdx)
|
||||||
result.name = getIdent(splitFile(filename).name)
|
result.name = getIdent(graph.cache, splitFile(filename).name)
|
||||||
if not isNimIdentifier(result.name.s):
|
if not isNimIdentifier(result.name.s):
|
||||||
rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s)
|
rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s)
|
||||||
|
|
||||||
|
|
@ -32,10 +32,10 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
|
||||||
let
|
let
|
||||||
pck = getPackageName(graph.config, filename)
|
pck = getPackageName(graph.config, filename)
|
||||||
pck2 = if pck.len > 0: pck else: "unknown"
|
pck2 = if pck.len > 0: pck else: "unknown"
|
||||||
pack = getIdent(pck2)
|
pack = getIdent(graph.cache, pck2)
|
||||||
var packSym = graph.packageSyms.strTableGet(pack)
|
var packSym = graph.packageSyms.strTableGet(pack)
|
||||||
if packSym == nil:
|
if packSym == nil:
|
||||||
packSym = newSym(skPackage, getIdent(pck2), nil, result.info)
|
packSym = newSym(skPackage, getIdent(graph.cache, pck2), nil, result.info)
|
||||||
initStrTable(packSym.tab)
|
initStrTable(packSym.tab)
|
||||||
graph.packageSyms.strTableAdd(packSym)
|
graph.packageSyms.strTableAdd(packSym)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
processCmdLine(passCmd2, "", conf)
|
processCmdLine(passCmd2, "", conf)
|
||||||
if conf.command == "":
|
if conf.command == "":
|
||||||
rawMessage(conf, errGenerated, "command missing")
|
rawMessage(conf, errGenerated, "command missing")
|
||||||
mainCommand(newModuleGraph(conf), cache)
|
mainCommand(newModuleGraph(cache, conf), cache)
|
||||||
if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics())
|
if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics())
|
||||||
#echo(GC_getStatistics())
|
#echo(GC_getStatistics())
|
||||||
if conf.errorCounter == 0:
|
if conf.errorCounter == 0:
|
||||||
|
|
|
||||||
|
|
@ -111,32 +111,32 @@ proc replaceInFile(conf: ConfigRef; info: TLineInfo; newName: string) =
|
||||||
system.shallowCopy(gSourceFiles[info.fileIndex.int].lines[info.line.int-1], x)
|
system.shallowCopy(gSourceFiles[info.fileIndex.int].lines[info.line.int-1], x)
|
||||||
gSourceFiles[info.fileIndex.int].dirty = true
|
gSourceFiles[info.fileIndex.int].dirty = true
|
||||||
|
|
||||||
proc checkStyle(conf: ConfigRef; info: TLineInfo, s: string, k: TSymKind; sym: PSym) =
|
proc checkStyle(conf: ConfigRef; cache: IdentCache; info: TLineInfo, s: string, k: TSymKind; sym: PSym) =
|
||||||
let beau = beautifyName(s, k)
|
let beau = beautifyName(s, k)
|
||||||
if s != beau:
|
if s != beau:
|
||||||
if gStyleCheck == StyleCheck.Auto:
|
if gStyleCheck == StyleCheck.Auto:
|
||||||
sym.name = getIdent(beau)
|
sym.name = getIdent(cache, beau)
|
||||||
replaceInFile(conf, info, beau)
|
replaceInFile(conf, info, beau)
|
||||||
else:
|
else:
|
||||||
message(conf, info, hintName, beau)
|
message(conf, info, hintName, beau)
|
||||||
|
|
||||||
proc styleCheckDefImpl(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) =
|
proc styleCheckDefImpl(conf: ConfigRef; cache: IdentCache; info: TLineInfo; s: PSym; k: TSymKind) =
|
||||||
# operators stay as they are:
|
# operators stay as they are:
|
||||||
if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters: return
|
if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters: return
|
||||||
if k in {skType, skGenericParam} and sfAnon in s.flags: return
|
if k in {skType, skGenericParam} and sfAnon in s.flags: return
|
||||||
if {sfImportc, sfExportc} * s.flags == {} or gCheckExtern:
|
if {sfImportc, sfExportc} * s.flags == {} or gCheckExtern:
|
||||||
checkStyle(conf, info, s.name.s, k, s)
|
checkStyle(conf, cache, info, s.name.s, k, s)
|
||||||
|
|
||||||
template styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) =
|
template styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) =
|
||||||
when defined(nimfix):
|
when defined(nimfix):
|
||||||
if gStyleCheck != StyleCheck.None: styleCheckDefImpl(conf, info, s, k)
|
if gStyleCheck != StyleCheck.None: styleCheckDefImpl(conf, cache, info, s, k)
|
||||||
|
|
||||||
template styleCheckDef*(info: TLineInfo; s: PSym) =
|
template styleCheckDef*(info: TLineInfo; s: PSym) =
|
||||||
styleCheckDef(info, s, s.kind)
|
styleCheckDef(info, s, s.kind)
|
||||||
template styleCheckDef*(s: PSym) =
|
template styleCheckDef*(s: PSym) =
|
||||||
styleCheckDef(s.info, s, s.kind)
|
styleCheckDef(s.info, s, s.kind)
|
||||||
|
|
||||||
proc styleCheckUseImpl(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
proc styleCheckUseImpl(conf: ConfigRef; cache: IdentCache; info: TLineInfo; s: PSym) =
|
||||||
if info.fileIndex.int < 0: return
|
if info.fileIndex.int < 0: return
|
||||||
# we simply convert it to what it looks like in the definition
|
# we simply convert it to what it looks like in the definition
|
||||||
# for consistency
|
# for consistency
|
||||||
|
|
@ -152,4 +152,4 @@ proc styleCheckUseImpl(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
||||||
|
|
||||||
template styleCheckUse*(info: TLineInfo; s: PSym) =
|
template styleCheckUse*(info: TLineInfo; s: PSym) =
|
||||||
when defined(nimfix):
|
when defined(nimfix):
|
||||||
if gStyleCheck != StyleCheck.None: styleCheckUseImpl(conf, info, s)
|
if gStyleCheck != StyleCheck.None: styleCheckUseImpl(conf, cache, info, s)
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ proc semAsmOrEmit*(con: PContext, n: PNode, marker: char): PNode =
|
||||||
if c < 0: sub = substr(str, b + 1)
|
if c < 0: sub = substr(str, b + 1)
|
||||||
else: sub = substr(str, b + 1, c - 1)
|
else: sub = substr(str, b + 1, c - 1)
|
||||||
if sub != "":
|
if sub != "":
|
||||||
var e = searchInScopes(con, getIdent(sub))
|
var e = searchInScopes(con, getIdent(con.cache, sub))
|
||||||
if e != nil:
|
if e != nil:
|
||||||
if e.kind == skStub: loadStub(e)
|
if e.kind == skStub: loadStub(e)
|
||||||
incl(e.flags, sfUsed)
|
incl(e.flags, sfUsed)
|
||||||
|
|
@ -634,7 +634,7 @@ proc deprecatedStmt(c: PContext; outerPragma: PNode) =
|
||||||
let dest = qualifiedLookUp(c, n[1], {checkUndeclared})
|
let dest = qualifiedLookUp(c, n[1], {checkUndeclared})
|
||||||
if dest == nil or dest.kind in routineKinds:
|
if dest == nil or dest.kind in routineKinds:
|
||||||
localError(c.config, n.info, warnUser, "the .deprecated pragma is unreliable for routines")
|
localError(c.config, n.info, warnUser, "the .deprecated pragma is unreliable for routines")
|
||||||
let src = considerQuotedIdent(c.config, n[0])
|
let src = considerQuotedIdent(c, n[0])
|
||||||
let alias = newSym(skAlias, src, dest, n[0].info, c.config.options)
|
let alias = newSym(skAlias, src, dest, n[0].info, c.config.options)
|
||||||
incl(alias.flags, sfExported)
|
incl(alias.flags, sfExported)
|
||||||
if sfCompilerProc in dest.flags: markCompilerProc(c, alias)
|
if sfCompilerProc in dest.flags: markCompilerProc(c, alias)
|
||||||
|
|
@ -657,7 +657,7 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym =
|
||||||
# We return a dummy symbol; later passes over the type will repair it.
|
# We return a dummy symbol; later passes over the type will repair it.
|
||||||
# Generic instantiation needs to know about this too. But we're lazy
|
# Generic instantiation needs to know about this too. But we're lazy
|
||||||
# and perform the lookup on demand instead.
|
# and perform the lookup on demand instead.
|
||||||
result = newSym(skUnknown, considerQuotedIdent(c.config, n), nil, n.info,
|
result = newSym(skUnknown, considerQuotedIdent(c, n), nil, n.info,
|
||||||
c.config.options)
|
c.config.options)
|
||||||
else:
|
else:
|
||||||
result = qualifiedLookUp(c, n, {checkUndeclared})
|
result = qualifiedLookUp(c, n, {checkUndeclared})
|
||||||
|
|
@ -710,7 +710,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
||||||
elif key.kind notin nkIdentKinds:
|
elif key.kind notin nkIdentKinds:
|
||||||
n.sons[i] = semCustomPragma(c, it)
|
n.sons[i] = semCustomPragma(c, it)
|
||||||
return
|
return
|
||||||
let ident = considerQuotedIdent(c.config, key)
|
let ident = considerQuotedIdent(c, key)
|
||||||
var userPragma = strTableGet(c.userPragmas, ident)
|
var userPragma = strTableGet(c.userPragmas, ident)
|
||||||
if userPragma != nil:
|
if userPragma != nil:
|
||||||
# number of pragmas increase/decrease with user pragma expansion
|
# number of pragmas increase/decrease with user pragma expansion
|
||||||
|
|
@ -1017,9 +1017,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
||||||
processExperimental(c, it, sym)
|
processExperimental(c, it, sym)
|
||||||
of wThis:
|
of wThis:
|
||||||
if it.kind in nkPragmaCallKinds and it.len == 2:
|
if it.kind in nkPragmaCallKinds and it.len == 2:
|
||||||
c.selfName = considerQuotedIdent(c.config, it[1])
|
c.selfName = considerQuotedIdent(c, it[1])
|
||||||
elif it.kind == nkIdent or it.len == 1:
|
elif it.kind == nkIdent or it.len == 1:
|
||||||
c.selfName = getIdent("self")
|
c.selfName = getIdent(c.cache, "self")
|
||||||
else:
|
else:
|
||||||
localError(c.config, it.info, "'this' pragma is allowed to have zero or one arguments")
|
localError(c.config, it.info, "'this' pragma is allowed to have zero or one arguments")
|
||||||
of wNoRewrite:
|
of wNoRewrite:
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ proc newDepN(id: int, pnode: PNode): DepN =
|
||||||
when defined(debugReorder):
|
when defined(debugReorder):
|
||||||
result.expls = @[]
|
result.expls = @[]
|
||||||
|
|
||||||
proc accQuoted(n: PNode): PIdent =
|
proc accQuoted(cache: IdentCache; n: PNode): PIdent =
|
||||||
var id = ""
|
var id = ""
|
||||||
for i in 0 ..< n.len:
|
for i in 0 ..< n.len:
|
||||||
let x = n[i]
|
let x = n[i]
|
||||||
|
|
@ -41,12 +41,12 @@ proc accQuoted(n: PNode): PIdent =
|
||||||
of nkIdent: id.add(x.ident.s)
|
of nkIdent: id.add(x.ident.s)
|
||||||
of nkSym: id.add(x.sym.name.s)
|
of nkSym: id.add(x.sym.name.s)
|
||||||
else: discard
|
else: discard
|
||||||
result = getIdent(id)
|
result = getIdent(cache, id)
|
||||||
|
|
||||||
proc addDecl(n: PNode; declares: var IntSet) =
|
proc addDecl(cache: IdentCache; n: PNode; declares: var IntSet) =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkPostfix: addDecl(n[1], declares)
|
of nkPostfix: addDecl(cache, n[1], declares)
|
||||||
of nkPragmaExpr: addDecl(n[0], declares)
|
of nkPragmaExpr: addDecl(cache, n[0], declares)
|
||||||
of nkIdent:
|
of nkIdent:
|
||||||
declares.incl n.ident.id
|
declares.incl n.ident.id
|
||||||
when defined(debugReorder):
|
when defined(debugReorder):
|
||||||
|
|
@ -56,18 +56,18 @@ proc addDecl(n: PNode; declares: var IntSet) =
|
||||||
when defined(debugReorder):
|
when defined(debugReorder):
|
||||||
idNames[n.sym.name.id] = n.sym.name.s
|
idNames[n.sym.name.id] = n.sym.name.s
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
let a = accQuoted(n)
|
let a = accQuoted(cache, n)
|
||||||
declares.incl a.id
|
declares.incl a.id
|
||||||
when defined(debugReorder):
|
when defined(debugReorder):
|
||||||
idNames[a.id] = a.s
|
idNames[a.id] = a.s
|
||||||
of nkEnumFieldDef:
|
of nkEnumFieldDef:
|
||||||
addDecl(n[0], declares)
|
addDecl(cache, n[0], declares)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc computeDeps(n: PNode, declares, uses: var IntSet; topLevel: bool) =
|
proc computeDeps(cache: IdentCache; n: PNode, declares, uses: var IntSet; topLevel: bool) =
|
||||||
template deps(n) = computeDeps(n, declares, uses, false)
|
template deps(n) = computeDeps(cache, n, declares, uses, false)
|
||||||
template decl(n) =
|
template decl(n) =
|
||||||
if topLevel: addDecl(n, declares)
|
if topLevel: addDecl(cache, n, declares)
|
||||||
case n.kind
|
case n.kind
|
||||||
of procDefs, nkMacroDef, nkTemplateDef:
|
of procDefs, nkMacroDef, nkTemplateDef:
|
||||||
decl(n[0])
|
decl(n[0])
|
||||||
|
|
@ -93,11 +93,11 @@ proc computeDeps(n: PNode, declares, uses: var IntSet; topLevel: bool) =
|
||||||
deps(n[i])
|
deps(n[i])
|
||||||
of nkIdent: uses.incl n.ident.id
|
of nkIdent: uses.incl n.ident.id
|
||||||
of nkSym: uses.incl n.sym.name.id
|
of nkSym: uses.incl n.sym.name.id
|
||||||
of nkAccQuoted: uses.incl accQuoted(n).id
|
of nkAccQuoted: uses.incl accQuoted(cache, n).id
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
uses.incl n.sons[0].sym.name.id
|
uses.incl n.sons[0].sym.name.id
|
||||||
of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt:
|
of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt:
|
||||||
for i in 0..<len(n): computeDeps(n[i], declares, uses, topLevel)
|
for i in 0..<len(n): computeDeps(cache, n[i], declares, uses, topLevel)
|
||||||
of nkPragma:
|
of nkPragma:
|
||||||
let a = n.sons[0]
|
let a = n.sons[0]
|
||||||
if a.kind == nkExprColonExpr and a.sons[0].kind == nkIdent and
|
if a.kind == nkExprColonExpr and a.sons[0].kind == nkIdent and
|
||||||
|
|
@ -439,7 +439,7 @@ proc reorder*(graph: ModuleGraph, n: PNode, module: PSym, cache: IdentCache): PN
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
deps[i][0] = initIntSet()
|
deps[i][0] = initIntSet()
|
||||||
deps[i][1] = initIntSet()
|
deps[i][1] = initIntSet()
|
||||||
computeDeps(n[i], deps[i][0], deps[i][1], true)
|
computeDeps(cache, n[i], deps[i][0], deps[i][1], true)
|
||||||
|
|
||||||
var g = buildGraph(n, deps)
|
var g = buildGraph(n, deps)
|
||||||
let comps = getStrongComponents(g)
|
let comps = getStrongComponents(g)
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ proc runNimScript*(cache: IdentCache; scriptName: string;
|
||||||
rawMessage(conf, hintConf, scriptName)
|
rawMessage(conf, hintConf, scriptName)
|
||||||
passes.gIncludeFile = includeModule
|
passes.gIncludeFile = includeModule
|
||||||
passes.gImportModule = importModule
|
passes.gImportModule = importModule
|
||||||
let graph = newModuleGraph(conf)
|
let graph = newModuleGraph(cache, conf)
|
||||||
if freshDefines: initDefines(conf.symbols)
|
if freshDefines: initDefines(conf.symbols)
|
||||||
|
|
||||||
defineSymbol(conf.symbols, "nimscript")
|
defineSymbol(conf.symbols, "nimscript")
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ proc fitNode(c: PContext, formal: PType, arg: PNode; info: TLineInfo): PNode =
|
||||||
proc inferWithMetatype(c: PContext, formal: PType,
|
proc inferWithMetatype(c: PContext, formal: PType,
|
||||||
arg: PNode, coerceDistincts = false): PNode
|
arg: PNode, coerceDistincts = false): PNode
|
||||||
|
|
||||||
var commonTypeBegin = PType(kind: tyExpr)
|
template commonTypeBegin*(): PType = PType(kind: tyExpr)
|
||||||
|
|
||||||
proc commonType*(x, y: PType): PType =
|
proc commonType*(x, y: PType): PType =
|
||||||
# new type relation that is used for array constructors,
|
# new type relation that is used for array constructors,
|
||||||
|
|
@ -181,7 +181,7 @@ proc commonType*(x: PType, y: PNode): PType =
|
||||||
commonType(x, y.typ)
|
commonType(x, y.typ)
|
||||||
|
|
||||||
proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
result = newSym(kind, considerQuotedIdent(c.config, n), getCurrOwner(c), n.info)
|
result = newSym(kind, considerQuotedIdent(c, n), getCurrOwner(c), n.info)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
suggestDecl(c, n, result)
|
suggestDecl(c, n, result)
|
||||||
|
|
||||||
|
|
@ -205,7 +205,7 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
# template; we must fix it here: see #909
|
# template; we must fix it here: see #909
|
||||||
result.owner = getCurrOwner(c)
|
result.owner = getCurrOwner(c)
|
||||||
else:
|
else:
|
||||||
result = newSym(kind, considerQuotedIdent(c.config, n), getCurrOwner(c), n.info)
|
result = newSym(kind, considerQuotedIdent(c, n), getCurrOwner(c), n.info)
|
||||||
#if kind in {skForVar, skLet, skVar} and result.owner.kind == skModule:
|
#if kind in {skForVar, skLet, skVar} and result.owner.kind == skModule:
|
||||||
# incl(result.flags, sfGlobal)
|
# incl(result.flags, sfGlobal)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
|
|
@ -240,14 +240,14 @@ proc semTemplateExpr(c: PContext, n: PNode, s: PSym,
|
||||||
proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
||||||
flags: TExprFlags = {}): PNode
|
flags: TExprFlags = {}): PNode
|
||||||
|
|
||||||
proc symFromType(t: PType, info: TLineInfo): PSym =
|
proc symFromType(c: PContext; t: PType, info: TLineInfo): PSym =
|
||||||
if t.sym != nil: return t.sym
|
if t.sym != nil: return t.sym
|
||||||
result = newSym(skType, getIdent"AnonType", t.owner, info)
|
result = newSym(skType, getIdent(c.cache, "AnonType"), t.owner, info)
|
||||||
result.flags.incl sfAnon
|
result.flags.incl sfAnon
|
||||||
result.typ = t
|
result.typ = t
|
||||||
|
|
||||||
proc symNodeFromType(c: PContext, t: PType, info: TLineInfo): PNode =
|
proc symNodeFromType(c: PContext, t: PType, info: TLineInfo): PNode =
|
||||||
result = newSymNode(symFromType(t, info), info)
|
result = newSymNode(symFromType(c, t, info), info)
|
||||||
result.typ = makeTypeDesc(c, t)
|
result.typ = makeTypeDesc(c, t)
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
|
|
@ -483,7 +483,7 @@ proc addCodeForGenerics(c: PContext, n: PNode) =
|
||||||
c.lastGenericIdx = c.generics.len
|
c.lastGenericIdx = c.generics.len
|
||||||
|
|
||||||
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
proc myOpen(graph: ModuleGraph; module: PSym; cache: IdentCache): PPassContext =
|
||||||
var c = newContext(graph, module, cache)
|
var c = newContext(graph, module)
|
||||||
if c.p != nil: internalError(graph.config, module.info, "sem.myOpen")
|
if c.p != nil: internalError(graph.config, module.info, "sem.myOpen")
|
||||||
c.semConstExpr = semConstExpr
|
c.semConstExpr = semConstExpr
|
||||||
c.semExpr = semExpr
|
c.semExpr = semExpr
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ proc addVar(father, v, value: PNode) =
|
||||||
addSon(father, vpart)
|
addSon(father, vpart)
|
||||||
|
|
||||||
proc declareCounter(c: var TLiftCtx; body: PNode; first: BiggestInt): PNode =
|
proc declareCounter(c: var TLiftCtx; body: PNode; first: BiggestInt): PNode =
|
||||||
var temp = newSym(skTemp, getIdent(lowerings.genPrefix), c.fn, c.info)
|
var temp = newSym(skTemp, getIdent(c.c.cache, lowerings.genPrefix), c.fn, c.info)
|
||||||
temp.typ = getSysType(c.c.graph, body.info, tyInt)
|
temp.typ = getSysType(c.c.graph, body.info, tyInt)
|
||||||
incl(temp.flags, sfFromGeneric)
|
incl(temp.flags, sfFromGeneric)
|
||||||
|
|
||||||
|
|
@ -268,17 +268,17 @@ proc liftBody(c: PContext; typ: PType; kind: TTypeAttachedOp;
|
||||||
a.kind = kind
|
a.kind = kind
|
||||||
let body = newNodeI(nkStmtList, info)
|
let body = newNodeI(nkStmtList, info)
|
||||||
let procname = case kind
|
let procname = case kind
|
||||||
of attachedAsgn: getIdent"="
|
of attachedAsgn: getIdent(c.cache, "=")
|
||||||
of attachedSink: getIdent"=sink"
|
of attachedSink: getIdent(c.cache, "=sink")
|
||||||
of attachedDeepCopy: getIdent"=deepcopy"
|
of attachedDeepCopy: getIdent(c.cache, "=deepcopy")
|
||||||
of attachedDestructor: getIdent"=destroy"
|
of attachedDestructor: getIdent(c.cache, "=destroy")
|
||||||
|
|
||||||
result = newSym(skProc, procname, typ.owner, info)
|
result = newSym(skProc, procname, typ.owner, info)
|
||||||
a.fn = result
|
a.fn = result
|
||||||
a.asgnForType = typ
|
a.asgnForType = typ
|
||||||
|
|
||||||
let dest = newSym(skParam, getIdent"dest", result, info)
|
let dest = newSym(skParam, getIdent(c.cache, "dest"), result, info)
|
||||||
let src = newSym(skParam, getIdent"src", result, info)
|
let src = newSym(skParam, getIdent(c.cache, "src"), result, info)
|
||||||
dest.typ = makeVarType(c, typ)
|
dest.typ = makeVarType(c, typ)
|
||||||
src.typ = typ
|
src.typ = typ
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
|
||||||
orig.sons[0..1] = [nil, orig[1], f]
|
orig.sons[0..1] = [nil, orig[1], f]
|
||||||
|
|
||||||
template tryOp(x) =
|
template tryOp(x) =
|
||||||
let op = newIdentNode(getIdent(x), n.info)
|
let op = newIdentNode(getIdent(c.cache, x), n.info)
|
||||||
n.sons[0] = op
|
n.sons[0] = op
|
||||||
orig.sons[0] = op
|
orig.sons[0] = op
|
||||||
pickBest(op)
|
pickBest(op)
|
||||||
|
|
@ -306,17 +306,17 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
|
||||||
|
|
||||||
elif nfDotSetter in n.flags and f.kind == nkIdent and n.len == 3:
|
elif nfDotSetter in n.flags and f.kind == nkIdent and n.len == 3:
|
||||||
# we need to strip away the trailing '=' here:
|
# we need to strip away the trailing '=' here:
|
||||||
let calleeName = newIdentNode(getIdent(f.ident.s[0..f.ident.s.len-2]), n.info)
|
let calleeName = newIdentNode(getIdent(c.cache, f.ident.s[0..f.ident.s.len-2]), n.info)
|
||||||
let callOp = newIdentNode(getIdent".=", n.info)
|
let callOp = newIdentNode(getIdent(c.cache, ".="), n.info)
|
||||||
n.sons[0..1] = [callOp, n[1], calleeName]
|
n.sons[0..1] = [callOp, n[1], calleeName]
|
||||||
orig.sons[0..1] = [callOp, orig[1], calleeName]
|
orig.sons[0..1] = [callOp, orig[1], calleeName]
|
||||||
pickBest(callOp)
|
pickBest(callOp)
|
||||||
|
|
||||||
if overloadsState == csEmpty and result.state == csEmpty:
|
if overloadsState == csEmpty and result.state == csEmpty:
|
||||||
if nfDotField in n.flags and nfExplicitCall notin n.flags:
|
if nfDotField in n.flags and nfExplicitCall notin n.flags:
|
||||||
localError(c.config, n.info, errUndeclaredField % considerQuotedIdent(c.config, f, n).s)
|
localError(c.config, n.info, errUndeclaredField % considerQuotedIdent(c, f, n).s)
|
||||||
else:
|
else:
|
||||||
localError(c.config, n.info, errUndeclaredRoutine % considerQuotedIdent(c.config, f, n).s)
|
localError(c.config, n.info, errUndeclaredRoutine % considerQuotedIdent(c, f, n).s)
|
||||||
return
|
return
|
||||||
elif result.state != csMatch:
|
elif result.state != csMatch:
|
||||||
if nfExprCall in n.flags:
|
if nfExprCall in n.flags:
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ proc newOptionEntry*(conf: ConfigRef): POptionEntry =
|
||||||
result.dynlib = nil
|
result.dynlib = nil
|
||||||
result.notes = conf.notes
|
result.notes = conf.notes
|
||||||
|
|
||||||
proc newContext*(graph: ModuleGraph; module: PSym; cache: IdentCache): PContext =
|
proc newContext*(graph: ModuleGraph; module: PSym): PContext =
|
||||||
new(result)
|
new(result)
|
||||||
result.enforceVoidContext = PType(kind: tyStmt)
|
result.enforceVoidContext = PType(kind: tyStmt)
|
||||||
result.ambiguousSymbols = initIntSet()
|
result.ambiguousSymbols = initIntSet()
|
||||||
|
|
@ -227,7 +227,7 @@ proc newContext*(graph: ModuleGraph; module: PSym; cache: IdentCache): PContext
|
||||||
initStrTable(result.userPragmas)
|
initStrTable(result.userPragmas)
|
||||||
result.generics = @[]
|
result.generics = @[]
|
||||||
result.unknownIdents = initIntSet()
|
result.unknownIdents = initIntSet()
|
||||||
result.cache = cache
|
result.cache = graph.cache
|
||||||
result.graph = graph
|
result.graph = graph
|
||||||
initStrTable(result.signatures)
|
initStrTable(result.signatures)
|
||||||
result.typesWithOps = @[]
|
result.typesWithOps = @[]
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ proc semOpAux(c: PContext, n: PNode) =
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkExprEqExpr and sonsLen(a) == 2:
|
if a.kind == nkExprEqExpr and sonsLen(a) == 2:
|
||||||
let info = a.sons[0].info
|
let info = a.sons[0].info
|
||||||
a.sons[0] = newIdentNode(considerQuotedIdent(c.config, a.sons[0], a), info)
|
a.sons[0] = newIdentNode(considerQuotedIdent(c, a.sons[0], a), info)
|
||||||
a.sons[1] = semExprWithType(c, a.sons[1], flags)
|
a.sons[1] = semExprWithType(c, a.sons[1], flags)
|
||||||
a.typ = a.sons[1].typ
|
a.typ = a.sons[1].typ
|
||||||
else:
|
else:
|
||||||
|
|
@ -361,7 +361,7 @@ proc semOpAux(c: PContext, n: PNode) =
|
||||||
|
|
||||||
proc overloadedCallOpr(c: PContext, n: PNode): PNode =
|
proc overloadedCallOpr(c: PContext, n: PNode): PNode =
|
||||||
# quick check if there is *any* () operator overloaded:
|
# quick check if there is *any* () operator overloaded:
|
||||||
var par = getIdent("()")
|
var par = getIdent(c.cache, "()")
|
||||||
if searchInScopes(c, par) == nil:
|
if searchInScopes(c, par) == nil:
|
||||||
result = nil
|
result = nil
|
||||||
else:
|
else:
|
||||||
|
|
@ -802,7 +802,7 @@ proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
||||||
# we MUST not check 'n' for semantics again here! But for now we give up:
|
# we MUST not check 'n' for semantics again here! But for now we give up:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
var e = strTableGet(c.graph.systemModule.tab, getIdent"echo")
|
var e = strTableGet(c.graph.systemModule.tab, getIdent(c.cache, "echo"))
|
||||||
if e != nil:
|
if e != nil:
|
||||||
add(result, newSymNode(e))
|
add(result, newSymNode(e))
|
||||||
else:
|
else:
|
||||||
|
|
@ -1097,7 +1097,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
|
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
|
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
|
||||||
#restoreOldStyleType(n.sons[0])
|
#restoreOldStyleType(n.sons[0])
|
||||||
var i = considerQuotedIdent(c.config, n.sons[1], n)
|
var i = considerQuotedIdent(c, n.sons[1], n)
|
||||||
var ty = n.sons[0].typ
|
var ty = n.sons[0].typ
|
||||||
var f: PSym = nil
|
var f: PSym = nil
|
||||||
result = nil
|
result = nil
|
||||||
|
|
@ -1217,7 +1217,7 @@ proc dotTransformation(c: PContext, n: PNode): PNode =
|
||||||
addSon(result, n.sons[1])
|
addSon(result, n.sons[1])
|
||||||
addSon(result, copyTree(n[0]))
|
addSon(result, copyTree(n[0]))
|
||||||
else:
|
else:
|
||||||
var i = considerQuotedIdent(c.config, n.sons[1], n)
|
var i = considerQuotedIdent(c, n.sons[1], n)
|
||||||
result = newNodeI(nkDotCall, n.info)
|
result = newNodeI(nkDotCall, n.info)
|
||||||
result.flags.incl nfDotField
|
result.flags.incl nfDotField
|
||||||
addSon(result, newIdentNode(i, n[1].info))
|
addSon(result, newIdentNode(i, n[1].info))
|
||||||
|
|
@ -1328,11 +1328,11 @@ proc semArrayAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
result = semSubscript(c, n, flags)
|
result = semSubscript(c, n, flags)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
# overloaded [] operator:
|
# overloaded [] operator:
|
||||||
result = semExpr(c, buildOverloadedSubscripts(n, getIdent"[]"))
|
result = semExpr(c, buildOverloadedSubscripts(n, getIdent(c.cache, "[]")))
|
||||||
|
|
||||||
proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
|
proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
|
||||||
var id = considerQuotedIdent(c.config, a[1], a)
|
var id = considerQuotedIdent(c, a[1], a)
|
||||||
var setterId = newIdentNode(getIdent(id.s & '='), n.info)
|
var setterId = newIdentNode(getIdent(c.cache, id.s & '='), n.info)
|
||||||
# a[0] is already checked for semantics, that does ``builtinFieldAccess``
|
# a[0] is already checked for semantics, that does ``builtinFieldAccess``
|
||||||
# this is ugly. XXX Semantic checking should use the ``nfSem`` flag for
|
# this is ugly. XXX Semantic checking should use the ``nfSem`` flag for
|
||||||
# nodes?
|
# nodes?
|
||||||
|
|
@ -1409,7 +1409,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
|
||||||
# --> `[]=`(a, i, x)
|
# --> `[]=`(a, i, x)
|
||||||
a = semSubscript(c, a, {efLValue})
|
a = semSubscript(c, a, {efLValue})
|
||||||
if a == nil:
|
if a == nil:
|
||||||
result = buildOverloadedSubscripts(n.sons[0], getIdent"[]=")
|
result = buildOverloadedSubscripts(n.sons[0], getIdent(c.cache, "[]="))
|
||||||
add(result, n[1])
|
add(result, n[1])
|
||||||
if mode == noOverloadedSubscript:
|
if mode == noOverloadedSubscript:
|
||||||
bracketNotFoundError(c, result)
|
bracketNotFoundError(c, result)
|
||||||
|
|
@ -1419,7 +1419,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
|
||||||
return result
|
return result
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
# a{i} = x --> `{}=`(a, i, x)
|
# a{i} = x --> `{}=`(a, i, x)
|
||||||
result = buildOverloadedSubscripts(n.sons[0], getIdent"{}=")
|
result = buildOverloadedSubscripts(n.sons[0], getIdent(c.cache, "{}="))
|
||||||
add(result, n[1])
|
add(result, n[1])
|
||||||
return semExprNoType(c, result)
|
return semExprNoType(c, result)
|
||||||
of nkPar, nkTupleConstr:
|
of nkPar, nkTupleConstr:
|
||||||
|
|
@ -1427,7 +1427,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
|
||||||
# unfortunately we need to rewrite ``(x, y) = foo()`` already here so
|
# unfortunately we need to rewrite ``(x, y) = foo()`` already here so
|
||||||
# that overloading of the assignment operator still works. Usually we
|
# that overloading of the assignment operator still works. Usually we
|
||||||
# prefer to do these rewritings in transf.nim:
|
# prefer to do these rewritings in transf.nim:
|
||||||
return semStmt(c, lowerTupleUnpackingForAsgn(n, c.p.owner))
|
return semStmt(c, lowerTupleUnpackingForAsgn(c.graph, n, c.p.owner))
|
||||||
else:
|
else:
|
||||||
a = semExprWithType(c, a, {efLValue})
|
a = semExprWithType(c, a, {efLValue})
|
||||||
else:
|
else:
|
||||||
|
|
@ -1593,13 +1593,13 @@ proc lookUpForDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PSym =
|
||||||
checkSonsLen(n, 2, c.config)
|
checkSonsLen(n, 2, c.config)
|
||||||
var m = lookUpForDefined(c, n.sons[0], onlyCurrentScope)
|
var m = lookUpForDefined(c, n.sons[0], onlyCurrentScope)
|
||||||
if m != nil and m.kind == skModule:
|
if m != nil and m.kind == skModule:
|
||||||
let ident = considerQuotedIdent(c.config, n[1], n)
|
let ident = considerQuotedIdent(c, n[1], n)
|
||||||
if m == c.module:
|
if m == c.module:
|
||||||
result = strTableGet(c.topLevelScope.symbols, ident)
|
result = strTableGet(c.topLevelScope.symbols, ident)
|
||||||
else:
|
else:
|
||||||
result = strTableGet(m.tab, ident)
|
result = strTableGet(m.tab, ident)
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
result = lookUpForDefined(c, considerQuotedIdent(c.config, n), onlyCurrentScope)
|
result = lookUpForDefined(c, considerQuotedIdent(c, n), onlyCurrentScope)
|
||||||
of nkSym:
|
of nkSym:
|
||||||
result = n.sym
|
result = n.sym
|
||||||
of nkOpenSymChoice, nkClosedSymChoice:
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
|
|
@ -1612,7 +1612,7 @@ proc semDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PNode =
|
||||||
checkSonsLen(n, 2, c.config)
|
checkSonsLen(n, 2, c.config)
|
||||||
# we replace this node by a 'true' or 'false' node:
|
# we replace this node by a 'true' or 'false' node:
|
||||||
result = newIntNode(nkIntLit, 0)
|
result = newIntNode(nkIntLit, 0)
|
||||||
if not onlyCurrentScope and considerQuotedIdent(c.config, n[0], n).s == "defined":
|
if not onlyCurrentScope and considerQuotedIdent(c, n[0], n).s == "defined":
|
||||||
if n.sons[1].kind != nkIdent:
|
if n.sons[1].kind != nkIdent:
|
||||||
localError(c.config, n.info, "obsolete usage of 'defined', use 'declared' instead")
|
localError(c.config, n.info, "obsolete usage of 'defined', use 'declared' instead")
|
||||||
elif isDefined(c.config, n.sons[1].ident.s):
|
elif isDefined(c.config, n.sons[1].ident.s):
|
||||||
|
|
@ -1711,7 +1711,7 @@ proc processQuotations(c: PContext; n: var PNode, op: string,
|
||||||
ids: var seq[PNode]) =
|
ids: var seq[PNode]) =
|
||||||
template returnQuote(q) =
|
template returnQuote(q) =
|
||||||
quotes.add q
|
quotes.add q
|
||||||
n = newIdentNode(getIdent($quotes.len), n.info)
|
n = newIdentNode(getIdent(c.cache, $quotes.len), n.info)
|
||||||
ids.add n
|
ids.add n
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -1722,7 +1722,7 @@ proc processQuotations(c: PContext; n: var PNode, op: string,
|
||||||
if examinedOp == op:
|
if examinedOp == op:
|
||||||
returnQuote n[1]
|
returnQuote n[1]
|
||||||
elif examinedOp.startsWith(op):
|
elif examinedOp.startsWith(op):
|
||||||
n.sons[0] = newIdentNode(getIdent(examinedOp.substr(op.len)), n.info)
|
n.sons[0] = newIdentNode(getIdent(c.cache, examinedOp.substr(op.len)), n.info)
|
||||||
elif n.kind == nkAccQuoted and op == "``":
|
elif n.kind == nkAccQuoted and op == "``":
|
||||||
returnQuote n[0]
|
returnQuote n[0]
|
||||||
|
|
||||||
|
|
@ -2366,12 +2366,12 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
checkMinSonsLen(n, 1, c.config)
|
checkMinSonsLen(n, 1, c.config)
|
||||||
result = semArrayAccess(c, n, flags)
|
result = semArrayAccess(c, n, flags)
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
result = semExpr(c, buildOverloadedSubscripts(n, getIdent"{}"), flags)
|
result = semExpr(c, buildOverloadedSubscripts(n, getIdent(c.cache, "{}")), flags)
|
||||||
of nkPragmaExpr:
|
of nkPragmaExpr:
|
||||||
var
|
var
|
||||||
expr = n[0]
|
expr = n[0]
|
||||||
pragma = n[1]
|
pragma = n[1]
|
||||||
pragmaName = considerQuotedIdent(c.config, pragma[0])
|
pragmaName = considerQuotedIdent(c, pragma[0])
|
||||||
flags = flags
|
flags = flags
|
||||||
|
|
||||||
case whichKeyword(pragmaName)
|
case whichKeyword(pragmaName)
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
|
||||||
of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
|
of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
|
||||||
of nkIdent, nkSym:
|
of nkIdent, nkSym:
|
||||||
result = n
|
result = n
|
||||||
let ident = considerQuotedIdent(c.c.config, n)
|
let ident = considerQuotedIdent(c.c, n)
|
||||||
var L = sonsLen(forLoop)
|
var L = sonsLen(forLoop)
|
||||||
if c.replaceByFieldName:
|
if c.replaceByFieldName:
|
||||||
if ident.id == considerQuotedIdent(c.c.config, forLoop[0]).id:
|
if ident.id == considerQuotedIdent(c.c, forLoop[0]).id:
|
||||||
let fieldName = if c.tupleType.isNil: c.field.name.s
|
let fieldName = if c.tupleType.isNil: c.field.name.s
|
||||||
elif c.tupleType.n.isNil: "Field" & $c.tupleIndex
|
elif c.tupleType.n.isNil: "Field" & $c.tupleIndex
|
||||||
else: c.tupleType.n.sons[c.tupleIndex].sym.name.s
|
else: c.tupleType.n.sons[c.tupleIndex].sym.name.s
|
||||||
|
|
@ -34,7 +34,7 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
|
||||||
return
|
return
|
||||||
# other fields:
|
# other fields:
|
||||||
for i in ord(c.replaceByFieldName)..L-3:
|
for i in ord(c.replaceByFieldName)..L-3:
|
||||||
if ident.id == considerQuotedIdent(c.c.config, forLoop[i]).id:
|
if ident.id == considerQuotedIdent(c.c, forLoop[i]).id:
|
||||||
var call = forLoop.sons[L-2]
|
var call = forLoop.sons[L-2]
|
||||||
var tupl = call.sons[i+1-ord(c.replaceByFieldName)]
|
var tupl = call.sons[i+1-ord(c.replaceByFieldName)]
|
||||||
if c.field.isNil:
|
if c.field.isNil:
|
||||||
|
|
@ -107,10 +107,10 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
|
||||||
# so that 'break' etc. work as expected, we produce
|
# so that 'break' etc. work as expected, we produce
|
||||||
# a 'while true: stmt; break' loop ...
|
# a 'while true: stmt; break' loop ...
|
||||||
result = newNodeI(nkWhileStmt, n.info, 2)
|
result = newNodeI(nkWhileStmt, n.info, 2)
|
||||||
var trueSymbol = strTableGet(c.graph.systemModule.tab, getIdent"true")
|
var trueSymbol = strTableGet(c.graph.systemModule.tab, getIdent(c.cache, "true"))
|
||||||
if trueSymbol == nil:
|
if trueSymbol == nil:
|
||||||
localError(c.config, n.info, "system needs: 'true'")
|
localError(c.config, n.info, "system needs: 'true'")
|
||||||
trueSymbol = newSym(skUnknown, getIdent"true", getCurrOwner(c), n.info)
|
trueSymbol = newSym(skUnknown, getIdent(c.cache, "true"), getCurrOwner(c), n.info)
|
||||||
trueSymbol.typ = getSysType(c.graph, n.info, tyBool)
|
trueSymbol.typ = getSysType(c.graph, n.info, tyBool)
|
||||||
|
|
||||||
result.sons[0] = newSymNode(trueSymbol, n.info)
|
result.sons[0] = newSymNode(trueSymbol, n.info)
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
|
||||||
proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||||
ctx: var GenericCtx): PNode =
|
ctx: var GenericCtx): PNode =
|
||||||
result = n
|
result = n
|
||||||
let ident = considerQuotedIdent(c.config, n)
|
let ident = considerQuotedIdent(c, n)
|
||||||
var s = searchInScopes(c, ident).skipAlias(n, c.config)
|
var s = searchInScopes(c, ident).skipAlias(n, c.config)
|
||||||
if s == nil:
|
if s == nil:
|
||||||
s = strTableGet(c.pureEnumFields, ident)
|
s = strTableGet(c.pureEnumFields, ident)
|
||||||
|
|
@ -140,7 +140,7 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags,
|
||||||
n.sons[0] = semGenericStmt(c, n.sons[0], flags, ctx)
|
n.sons[0] = semGenericStmt(c, n.sons[0], flags, ctx)
|
||||||
result = n
|
result = n
|
||||||
let n = n[1]
|
let n = n[1]
|
||||||
let ident = considerQuotedIdent(c.config, n)
|
let ident = considerQuotedIdent(c, n)
|
||||||
var s = searchInScopes(c, ident).skipAlias(n, c.config)
|
var s = searchInScopes(c, ident).skipAlias(n, c.config)
|
||||||
if s != nil and s.kind in routineKinds:
|
if s != nil and s.kind in routineKinds:
|
||||||
isMacro = s.kind in {skTemplate, skMacro}
|
isMacro = s.kind in {skTemplate, skMacro}
|
||||||
|
|
@ -207,7 +207,7 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
if s == nil and
|
if s == nil and
|
||||||
{withinMixin, withinConcept}*flags == {} and
|
{withinMixin, withinConcept}*flags == {} and
|
||||||
fn.kind in {nkIdent, nkAccQuoted} and
|
fn.kind in {nkIdent, nkAccQuoted} and
|
||||||
considerQuotedIdent(c.config, fn).id notin ctx.toMixin:
|
considerQuotedIdent(c, fn).id notin ctx.toMixin:
|
||||||
errorUndeclaredIdentifier(c, n.info, fn.renderTree)
|
errorUndeclaredIdentifier(c, n.info, fn.renderTree)
|
||||||
|
|
||||||
var first = int ord(withinConcept in flags)
|
var first = int ord(withinConcept in flags)
|
||||||
|
|
@ -275,12 +275,12 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
result.sons[i] = semGenericStmt(c, result.sons[i], flags, ctx)
|
result.sons[i] = semGenericStmt(c, result.sons[i], flags, ctx)
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("{}"), n.info)
|
result.add newIdentNode(getIdent(c.cache, "{}"), n.info)
|
||||||
for i in 0 ..< n.len: result.add(n[i])
|
for i in 0 ..< n.len: result.add(n[i])
|
||||||
result = semGenericStmt(c, result, flags, ctx)
|
result = semGenericStmt(c, result, flags, ctx)
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("[]"), n.info)
|
result.add newIdentNode(getIdent(c.cache, "[]"), n.info)
|
||||||
for i in 0 ..< n.len: result.add(n[i])
|
for i in 0 ..< n.len: result.add(n[i])
|
||||||
withBracketExpr ctx, n.sons[0]:
|
withBracketExpr ctx, n.sons[0]:
|
||||||
result = semGenericStmt(c, result, flags, ctx)
|
result = semGenericStmt(c, result, flags, ctx)
|
||||||
|
|
@ -293,13 +293,13 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
case k
|
case k
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("{}="), n.info)
|
result.add newIdentNode(getIdent(c.cache, "{}="), n.info)
|
||||||
for i in 0 ..< a.len: result.add(a[i])
|
for i in 0 ..< a.len: result.add(a[i])
|
||||||
result.add(b)
|
result.add(b)
|
||||||
result = semGenericStmt(c, result, flags, ctx)
|
result = semGenericStmt(c, result, flags, ctx)
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("[]="), n.info)
|
result.add newIdentNode(getIdent(c.cache, "[]="), n.info)
|
||||||
for i in 0 ..< a.len: result.add(a[i])
|
for i in 0 ..< a.len: result.add(a[i])
|
||||||
result.add(b)
|
result.add(b)
|
||||||
withBracketExpr ctx, a.sons[0]:
|
withBracketExpr ctx, a.sons[0]:
|
||||||
|
|
@ -448,7 +448,7 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
flags, ctx)
|
flags, ctx)
|
||||||
if n.sons[paramsPos].kind != nkEmpty:
|
if n.sons[paramsPos].kind != nkEmpty:
|
||||||
if n.sons[paramsPos].sons[0].kind != nkEmpty:
|
if n.sons[paramsPos].sons[0].kind != nkEmpty:
|
||||||
addPrelimDecl(c, newSym(skUnknown, getIdent("result"), nil, n.info))
|
addPrelimDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nil, n.info))
|
||||||
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, ctx)
|
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, ctx)
|
||||||
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, ctx)
|
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, ctx)
|
||||||
var body: PNode
|
var body: PNode
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ proc semArrGet(c: PContext; n: PNode; flags: TExprFlags): PNode =
|
||||||
result = semSubscript(c, result, flags)
|
result = semSubscript(c, result, flags)
|
||||||
if result.isNil:
|
if result.isNil:
|
||||||
let x = copyTree(n)
|
let x = copyTree(n)
|
||||||
x.sons[0] = newIdentNode(getIdent"[]", n.info)
|
x.sons[0] = newIdentNode(getIdent(c.cache, "[]"), n.info)
|
||||||
bracketNotFoundError(c, x)
|
bracketNotFoundError(c, x)
|
||||||
#localError(c.config, n.info, "could not resolve: " & $n)
|
#localError(c.config, n.info, "could not resolve: " & $n)
|
||||||
result = n
|
result = n
|
||||||
|
|
@ -194,7 +194,7 @@ proc semBindSym(c: PContext, n: PNode): PNode =
|
||||||
localError(c.config, n.sons[2].info, errConstExprExpected)
|
localError(c.config, n.sons[2].info, errConstExprExpected)
|
||||||
return errorNode(c, n)
|
return errorNode(c, n)
|
||||||
|
|
||||||
let id = newIdentNode(getIdent(sl.strVal), n.info)
|
let id = newIdentNode(getIdent(c.cache, sl.strVal), n.info)
|
||||||
let s = qualifiedLookUp(c, id, {checkUndeclared})
|
let s = qualifiedLookUp(c, id, {checkUndeclared})
|
||||||
if s != nil:
|
if s != nil:
|
||||||
# we need to mark all symbols:
|
# we need to mark all symbols:
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ proc locateFieldInInitExpr(c: PContext, field: PSym, initExpr: PNode): PNode =
|
||||||
invalidObjConstr(c, assignment)
|
invalidObjConstr(c, assignment)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if fieldId == considerQuotedIdent(c.config, assignment[0]).id:
|
if fieldId == considerQuotedIdent(c, assignment[0]).id:
|
||||||
return assignment
|
return assignment
|
||||||
|
|
||||||
proc semConstrField(c: PContext, flags: TExprFlags,
|
proc semConstrField(c: PContext, flags: TExprFlags,
|
||||||
|
|
@ -295,11 +295,11 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if field.kind != nkExprColonExpr:
|
if field.kind != nkExprColonExpr:
|
||||||
invalidObjConstr(c, field)
|
invalidObjConstr(c, field)
|
||||||
continue
|
continue
|
||||||
let id = considerQuotedIdent(c.config, field[0])
|
let id = considerQuotedIdent(c, field[0])
|
||||||
# This node was not processed. There are two possible reasons:
|
# This node was not processed. There are two possible reasons:
|
||||||
# 1) It was shadowed by a field with the same name on the left
|
# 1) It was shadowed by a field with the same name on the left
|
||||||
for j in 1 ..< i:
|
for j in 1 ..< i:
|
||||||
let prevId = considerQuotedIdent(c.config, result[j][0])
|
let prevId = considerQuotedIdent(c, result[j][0])
|
||||||
if prevId.id == id.id:
|
if prevId.id == id.id:
|
||||||
localError(c.config, field.info, errFieldInitTwice % id.s)
|
localError(c.config, field.info, errFieldInitTwice % id.s)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -483,7 +483,7 @@ proc liftParallel*(g: ModuleGraph; owner: PSym; n: PNode): PNode =
|
||||||
checkArgs(a, body)
|
checkArgs(a, body)
|
||||||
|
|
||||||
var varSection = newNodeI(nkVarSection, n.info)
|
var varSection = newNodeI(nkVarSection, n.info)
|
||||||
var temp = newSym(skTemp, getIdent"barrier", owner, n.info)
|
var temp = newSym(skTemp, getIdent(g.cache, "barrier"), owner, n.info)
|
||||||
temp.typ = magicsys.getCompilerProc(g, "Barrier").typ
|
temp.typ = magicsys.getCompilerProc(g, "Barrier").typ
|
||||||
incl(temp.flags, sfFromGeneric)
|
incl(temp.flags, sfFromGeneric)
|
||||||
let tempNode = newSymNode(temp)
|
let tempNode = newSymNode(temp)
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ proc markGcUnsafe(a: PEffects; reason: PNode) =
|
||||||
if reason.kind == nkSym:
|
if reason.kind == nkSym:
|
||||||
a.owner.gcUnsafetyReason = reason.sym
|
a.owner.gcUnsafetyReason = reason.sym
|
||||||
else:
|
else:
|
||||||
a.owner.gcUnsafetyReason = newSym(skUnknown, getIdent("<unknown>"),
|
a.owner.gcUnsafetyReason = newSym(skUnknown, a.owner.name,
|
||||||
a.owner, reason.info, {})
|
a.owner, reason.info, {})
|
||||||
|
|
||||||
when true:
|
when true:
|
||||||
|
|
@ -410,7 +410,7 @@ proc effectSpec(n: PNode, effectType: TSpecialWord): PNode =
|
||||||
result.add(it.sons[1])
|
result.add(it.sons[1])
|
||||||
return
|
return
|
||||||
|
|
||||||
proc documentEffect(n, x: PNode, effectType: TSpecialWord, idx: int): PNode =
|
proc documentEffect(cache: IdentCache; n, x: PNode, effectType: TSpecialWord, idx: int): PNode =
|
||||||
let spec = effectSpec(x, effectType)
|
let spec = effectSpec(x, effectType)
|
||||||
if isNil(spec):
|
if isNil(spec):
|
||||||
let s = n.sons[namePos].sym
|
let s = n.sons[namePos].sym
|
||||||
|
|
@ -424,14 +424,14 @@ proc documentEffect(n, x: PNode, effectType: TSpecialWord, idx: int): PNode =
|
||||||
for i in 0 ..< real.len:
|
for i in 0 ..< real.len:
|
||||||
var t = typeToString(real[i].typ)
|
var t = typeToString(real[i].typ)
|
||||||
if t.startsWith("ref "): t = substr(t, 4)
|
if t.startsWith("ref "): t = substr(t, 4)
|
||||||
effects.sons[i] = newIdentNode(getIdent(t), n.info)
|
effects.sons[i] = newIdentNode(getIdent(cache, t), n.info)
|
||||||
# set the type so that the following analysis doesn't screw up:
|
# set the type so that the following analysis doesn't screw up:
|
||||||
effects.sons[i].typ = real[i].typ
|
effects.sons[i].typ = real[i].typ
|
||||||
|
|
||||||
result = newNode(nkExprColonExpr, n.info, @[
|
result = newNode(nkExprColonExpr, n.info, @[
|
||||||
newIdentNode(getIdent(specialWords[effectType]), n.info), effects])
|
newIdentNode(getIdent(cache, specialWords[effectType]), n.info), effects])
|
||||||
|
|
||||||
proc documentWriteEffect(n: PNode; flag: TSymFlag; pragmaName: string): PNode =
|
proc documentWriteEffect(cache: IdentCache; n: PNode; flag: TSymFlag; pragmaName: string): PNode =
|
||||||
let s = n.sons[namePos].sym
|
let s = n.sons[namePos].sym
|
||||||
let params = s.typ.n
|
let params = s.typ.n
|
||||||
|
|
||||||
|
|
@ -442,21 +442,21 @@ proc documentWriteEffect(n: PNode; flag: TSymFlag; pragmaName: string): PNode =
|
||||||
|
|
||||||
if effects.len > 0:
|
if effects.len > 0:
|
||||||
result = newNode(nkExprColonExpr, n.info, @[
|
result = newNode(nkExprColonExpr, n.info, @[
|
||||||
newIdentNode(getIdent(pragmaName), n.info), effects])
|
newIdentNode(getIdent(cache, pragmaName), n.info), effects])
|
||||||
|
|
||||||
proc documentNewEffect(n: PNode): PNode =
|
proc documentNewEffect(cache: IdentCache; n: PNode): PNode =
|
||||||
let s = n.sons[namePos].sym
|
let s = n.sons[namePos].sym
|
||||||
if tfReturnsNew in s.typ.flags:
|
if tfReturnsNew in s.typ.flags:
|
||||||
result = newIdentNode(getIdent("new"), n.info)
|
result = newIdentNode(getIdent(cache, "new"), n.info)
|
||||||
|
|
||||||
proc documentRaises*(n: PNode) =
|
proc documentRaises*(cache: IdentCache; n: PNode) =
|
||||||
if n.sons[namePos].kind != nkSym: return
|
if n.sons[namePos].kind != nkSym: return
|
||||||
let pragmas = n.sons[pragmasPos]
|
let pragmas = n.sons[pragmasPos]
|
||||||
let p1 = documentEffect(n, pragmas, wRaises, exceptionEffects)
|
let p1 = documentEffect(cache, n, pragmas, wRaises, exceptionEffects)
|
||||||
let p2 = documentEffect(n, pragmas, wTags, tagEffects)
|
let p2 = documentEffect(cache, n, pragmas, wTags, tagEffects)
|
||||||
let p3 = documentWriteEffect(n, sfWrittenTo, "writes")
|
let p3 = documentWriteEffect(cache, n, sfWrittenTo, "writes")
|
||||||
let p4 = documentNewEffect(n)
|
let p4 = documentNewEffect(cache, n)
|
||||||
let p5 = documentWriteEffect(n, sfEscapes, "escapes")
|
let p5 = documentWriteEffect(cache, n, sfEscapes, "escapes")
|
||||||
|
|
||||||
if p1 != nil or p2 != nil or p3 != nil or p4 != nil or p5 != nil:
|
if p1 != nil or p2 != nil or p3 != nil or p4 != nil or p5 != nil:
|
||||||
if pragmas.kind == nkEmpty:
|
if pragmas.kind == nkEmpty:
|
||||||
|
|
|
||||||
|
|
@ -440,10 +440,10 @@ proc makeDeref(n: PNode): PNode =
|
||||||
proc fillPartialObject(c: PContext; n: PNode; typ: PType) =
|
proc fillPartialObject(c: PContext; n: PNode; typ: PType) =
|
||||||
if n.len == 2:
|
if n.len == 2:
|
||||||
let x = semExprWithType(c, n[0])
|
let x = semExprWithType(c, n[0])
|
||||||
let y = considerQuotedIdent(c.config, n[1])
|
let y = considerQuotedIdent(c, n[1])
|
||||||
let obj = x.typ.skipTypes(abstractPtrs)
|
let obj = x.typ.skipTypes(abstractPtrs)
|
||||||
if obj.kind == tyObject and tfPartial in obj.flags:
|
if obj.kind == tyObject and tfPartial in obj.flags:
|
||||||
let field = newSym(skField, getIdent(y.s), obj.sym, n[1].info)
|
let field = newSym(skField, getIdent(c.cache, y.s), obj.sym, n[1].info)
|
||||||
field.typ = skipIntLit(typ)
|
field.typ = skipIntLit(typ)
|
||||||
field.position = sonsLen(obj.n)
|
field.position = sonsLen(obj.n)
|
||||||
addSon(obj.n, newSymNode(field))
|
addSon(obj.n, newSymNode(field))
|
||||||
|
|
@ -664,7 +664,7 @@ proc semForVars(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
proc implicitIterator(c: PContext, it: string, arg: PNode): PNode =
|
proc implicitIterator(c: PContext, it: string, arg: PNode): PNode =
|
||||||
result = newNodeI(nkCall, arg.info)
|
result = newNodeI(nkCall, arg.info)
|
||||||
result.add(newIdentNode(it.getIdent, arg.info))
|
result.add(newIdentNode(getIdent(c.cache, it), arg.info))
|
||||||
if arg.typ != nil and arg.typ.kind in {tyVar, tyLent}:
|
if arg.typ != nil and arg.typ.kind in {tyVar, tyLent}:
|
||||||
result.add newDeref(arg)
|
result.add newDeref(arg)
|
||||||
else:
|
else:
|
||||||
|
|
@ -796,8 +796,8 @@ proc typeSectionLeftSidePass(c: PContext, n: PNode) =
|
||||||
let name = a.sons[0]
|
let name = a.sons[0]
|
||||||
var s: PSym
|
var s: PSym
|
||||||
if name.kind == nkDotExpr and a[2].kind == nkObjectTy:
|
if name.kind == nkDotExpr and a[2].kind == nkObjectTy:
|
||||||
let pkgName = considerQuotedIdent(c.config, name[0])
|
let pkgName = considerQuotedIdent(c, name[0])
|
||||||
let typName = considerQuotedIdent(c.config, name[1])
|
let typName = considerQuotedIdent(c, name[1])
|
||||||
let pkg = c.graph.packageSyms.strTableGet(pkgName)
|
let pkg = c.graph.packageSyms.strTableGet(pkgName)
|
||||||
if pkg.isNil or pkg.kind != skPackage:
|
if pkg.isNil or pkg.kind != skPackage:
|
||||||
localError(c.config, name.info, "unknown package name: " & pkgName.s)
|
localError(c.config, name.info, "unknown package name: " & pkgName.s)
|
||||||
|
|
@ -989,7 +989,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
internalAssert c.config, st.kind in {tyPtr, tyRef}
|
internalAssert c.config, st.kind in {tyPtr, tyRef}
|
||||||
internalAssert c.config, st.lastSon.sym == nil
|
internalAssert c.config, st.lastSon.sym == nil
|
||||||
incl st.flags, tfRefsAnonObj
|
incl st.flags, tfRefsAnonObj
|
||||||
let obj = newSym(skType, getIdent(s.name.s & ":ObjectType"),
|
let obj = newSym(skType, getIdent(c.cache, s.name.s & ":ObjectType"),
|
||||||
getCurrOwner(c), s.info)
|
getCurrOwner(c), s.info)
|
||||||
obj.typ = st.lastSon
|
obj.typ = st.lastSon
|
||||||
st.lastSon.sym = obj
|
st.lastSon.sym = obj
|
||||||
|
|
@ -1131,7 +1131,7 @@ proc semBorrow(c: PContext, n: PNode, s: PSym) =
|
||||||
|
|
||||||
proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) =
|
proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) =
|
||||||
if t != nil:
|
if t != nil:
|
||||||
var s = newSym(skResult, getIdent"result", getCurrOwner(c), info)
|
var s = newSym(skResult, getIdent(c.cache, "result"), getCurrOwner(c), info)
|
||||||
s.typ = t
|
s.typ = t
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
addParamOrResult(c, s, owner)
|
addParamOrResult(c, s, owner)
|
||||||
|
|
@ -1150,7 +1150,7 @@ proc lookupMacro(c: PContext, n: PNode): PSym =
|
||||||
result = n.sym
|
result = n.sym
|
||||||
if result.kind notin {skMacro, skTemplate}: result = nil
|
if result.kind notin {skMacro, skTemplate}: result = nil
|
||||||
else:
|
else:
|
||||||
result = searchInScopes(c, considerQuotedIdent(c.config, n), {skMacro, skTemplate})
|
result = searchInScopes(c, considerQuotedIdent(c, n), {skMacro, skTemplate})
|
||||||
|
|
||||||
proc semProcAnnotation(c: PContext, prc: PNode;
|
proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
validPragmas: TSpecialWords): PNode =
|
validPragmas: TSpecialWords): PNode =
|
||||||
|
|
@ -1162,7 +1162,7 @@ proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
let m = lookupMacro(c, key)
|
let m = lookupMacro(c, key)
|
||||||
if m == nil:
|
if m == nil:
|
||||||
if key.kind == nkIdent and key.ident.id == ord(wDelegator):
|
if key.kind == nkIdent and key.ident.id == ord(wDelegator):
|
||||||
if considerQuotedIdent(c.config, prc.sons[namePos]).s == "()":
|
if considerQuotedIdent(c, prc.sons[namePos]).s == "()":
|
||||||
prc.sons[namePos] = newIdentNode(c.cache.idDelegator, prc.info)
|
prc.sons[namePos] = newIdentNode(c.cache.idDelegator, prc.info)
|
||||||
prc.sons[pragmasPos] = copyExcept(n, i)
|
prc.sons[pragmasPos] = copyExcept(n, i)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1605,7 +1605,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
n.sons[bodyPos] = transformBody(c.graph, c.module, semBody, s)
|
n.sons[bodyPos] = transformBody(c.graph, c.module, semBody, s)
|
||||||
else:
|
else:
|
||||||
if s.typ.sons[0] != nil and kind != skIterator:
|
if s.typ.sons[0] != nil and kind != skIterator:
|
||||||
addDecl(c, newSym(skUnknown, getIdent"result", nil, n.info))
|
addDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nil, n.info))
|
||||||
|
|
||||||
openScope(c)
|
openScope(c)
|
||||||
n.sons[bodyPos] = semGenericStmt(c, n.sons[bodyPos])
|
n.sons[bodyPos] = semGenericStmt(c, n.sons[bodyPos])
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
||||||
|
|
||||||
proc semMixinStmt(c: PContext, n: PNode, toMixin: var IntSet): 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(c.config, n.sons[i]).id)
|
toMixin.incl(considerQuotedIdent(c, n.sons[i]).id)
|
||||||
result = newNodeI(nkEmpty, n.info)
|
result = newNodeI(nkEmpty, n.info)
|
||||||
|
|
||||||
proc replaceIdentBySym(c: PContext; n: var PNode, s: PNode) =
|
proc replaceIdentBySym(c: PContext; n: var PNode, s: PNode) =
|
||||||
|
|
@ -166,7 +166,7 @@ proc onlyReplaceParams(c: var TemplCtx, n: PNode): PNode =
|
||||||
result.sons[i] = onlyReplaceParams(c, n.sons[i])
|
result.sons[i] = onlyReplaceParams(c, n.sons[i])
|
||||||
|
|
||||||
proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
|
proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
|
||||||
result = newSym(kind, considerQuotedIdent(c.c.config, n), c.owner, n.info)
|
result = newSym(kind, considerQuotedIdent(c.c, n), c.owner, n.info)
|
||||||
incl(result.flags, sfGenSym)
|
incl(result.flags, sfGenSym)
|
||||||
incl(result.flags, sfShadowed)
|
incl(result.flags, sfShadowed)
|
||||||
|
|
||||||
|
|
@ -206,7 +206,7 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
|
||||||
#
|
#
|
||||||
# We need to ensure that both 'a' produce the same gensym'ed symbol.
|
# We need to ensure that both 'a' produce the same gensym'ed symbol.
|
||||||
# So we need only check the *current* scope.
|
# So we need only check the *current* scope.
|
||||||
let s = localSearchInScope(c.c, considerQuotedIdent(c.c.config, ident))
|
let s = localSearchInScope(c.c, considerQuotedIdent(c.c, ident))
|
||||||
if s != nil and s.owner == c.owner and sfGenSym in s.flags:
|
if s != nil and s.owner == c.owner and sfGenSym in s.flags:
|
||||||
styleCheckUse(n.info, s)
|
styleCheckUse(n.info, s)
|
||||||
replaceIdentBySym(c.c, n, newSymNode(s, n.info))
|
replaceIdentBySym(c.c, n, newSymNode(s, n.info))
|
||||||
|
|
@ -460,14 +460,14 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
x.sons[1] = semTemplBody(c, x.sons[1])
|
x.sons[1] = semTemplBody(c, x.sons[1])
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("[]"), n.info)
|
result.add newIdentNode(getIdent(c.c.cache, "[]"), n.info)
|
||||||
for i in 0 ..< n.len: result.add(n[i])
|
for i in 0 ..< n.len: result.add(n[i])
|
||||||
let n0 = semTemplBody(c, n.sons[0])
|
let n0 = semTemplBody(c, n.sons[0])
|
||||||
withBracketExpr c, n0:
|
withBracketExpr c, n0:
|
||||||
result = semTemplBodySons(c, result)
|
result = semTemplBodySons(c, result)
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("{}"), n.info)
|
result.add newIdentNode(getIdent(c.c.cache, "{}"), n.info)
|
||||||
for i in 0 ..< n.len: result.add(n[i])
|
for i in 0 ..< n.len: result.add(n[i])
|
||||||
result = semTemplBodySons(c, result)
|
result = semTemplBodySons(c, result)
|
||||||
of nkAsgn, nkFastAsgn:
|
of nkAsgn, nkFastAsgn:
|
||||||
|
|
@ -479,7 +479,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
case k
|
case k
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("[]="), n.info)
|
result.add newIdentNode(getIdent(c.c.cache, "[]="), n.info)
|
||||||
for i in 0 ..< a.len: result.add(a[i])
|
for i in 0 ..< a.len: result.add(a[i])
|
||||||
result.add(b)
|
result.add(b)
|
||||||
let a0 = semTemplBody(c, a.sons[0])
|
let a0 = semTemplBody(c, a.sons[0])
|
||||||
|
|
@ -487,7 +487,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
result = semTemplBodySons(c, result)
|
result = semTemplBodySons(c, result)
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
result.add newIdentNode(getIdent("{}="), n.info)
|
result.add newIdentNode(getIdent(c.c.cache, "{}="), n.info)
|
||||||
for i in 0 ..< a.len: result.add(a[i])
|
for i in 0 ..< a.len: result.add(a[i])
|
||||||
result.add(b)
|
result.add(b)
|
||||||
result = semTemplBodySons(c, result)
|
result = semTemplBodySons(c, result)
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ proc semVarargs(c: PContext, n: PNode, prev: PType): PType =
|
||||||
var base = semTypeNode(c, n.sons[1], nil)
|
var base = semTypeNode(c, n.sons[1], nil)
|
||||||
addSonSkipIntLit(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
if sonsLen(n) == 3:
|
if sonsLen(n) == 3:
|
||||||
result.n = newIdentNode(considerQuotedIdent(c.config, n.sons[2]), n.sons[2].info)
|
result.n = newIdentNode(considerQuotedIdent(c, n.sons[2]), n.sons[2].info)
|
||||||
else:
|
else:
|
||||||
localError(c.config, n.info, errXExpectsOneTypeParam % "varargs")
|
localError(c.config, n.info, errXExpectsOneTypeParam % "varargs")
|
||||||
addSonSkipIntLit(result, errorType(c))
|
addSonSkipIntLit(result, errorType(c))
|
||||||
|
|
@ -267,7 +267,7 @@ proc semRange(c: PContext, n: PNode, prev: PType): PType =
|
||||||
n.sons[1].floatVal < 0.0:
|
n.sons[1].floatVal < 0.0:
|
||||||
incl(result.flags, tfNeedsInit)
|
incl(result.flags, tfNeedsInit)
|
||||||
else:
|
else:
|
||||||
if n[1].kind == nkInfix and considerQuotedIdent(c.config, n[1][0]).s == "..<":
|
if n[1].kind == nkInfix and considerQuotedIdent(c, n[1][0]).s == "..<":
|
||||||
localError(c.config, n[0].info, "range types need to be constructed with '..', '..<' is not supported")
|
localError(c.config, n[0].info, "range types need to be constructed with '..', '..<' is not supported")
|
||||||
else:
|
else:
|
||||||
localError(c.config, n.sons[0].info, "expected range")
|
localError(c.config, n.sons[0].info, "expected range")
|
||||||
|
|
@ -462,7 +462,7 @@ proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
|
||||||
# for gensym'ed identifiers the identifier may already have been
|
# for gensym'ed identifiers the identifier may already have been
|
||||||
# transformed to a symbol and we need to use that here:
|
# transformed to a symbol and we need to use that here:
|
||||||
result = newSymG(kind, n.sons[1], c)
|
result = newSymG(kind, n.sons[1], c)
|
||||||
var v = considerQuotedIdent(c.config, n.sons[0])
|
var v = considerQuotedIdent(c, n.sons[0])
|
||||||
if sfExported in allowed and v.id == ord(wStar):
|
if sfExported in allowed and v.id == ord(wStar):
|
||||||
incl(result.flags, sfExported)
|
incl(result.flags, sfExported)
|
||||||
else:
|
else:
|
||||||
|
|
@ -770,7 +770,7 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result)
|
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result)
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
# dummy symbol for `pragma`:
|
# dummy symbol for `pragma`:
|
||||||
var s = newSymS(skType, newIdentNode(getIdent("dummy"), n.info), c)
|
var s = newSymS(skType, newIdentNode(getIdent(c.cache, "dummy"), n.info), c)
|
||||||
s.typ = result
|
s.typ = result
|
||||||
pragma(c, s, n.sons[0], typePragmas)
|
pragma(c, s, n.sons[0], typePragmas)
|
||||||
if base == nil and tfInheritable notin result.flags:
|
if base == nil and tfInheritable notin result.flags:
|
||||||
|
|
@ -804,8 +804,6 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
||||||
else:
|
else:
|
||||||
if sfGenSym notin param.flags: addDecl(c, param)
|
if sfGenSym notin param.flags: addDecl(c, param)
|
||||||
|
|
||||||
let typedescId = getIdent"typedesc"
|
|
||||||
|
|
||||||
template shouldHaveMeta(t) =
|
template shouldHaveMeta(t) =
|
||||||
internalAssert c.config, tfHasMeta in t.flags
|
internalAssert c.config, tfHasMeta in t.flags
|
||||||
# result.lastSon.flags.incl tfHasMeta
|
# result.lastSon.flags.incl tfHasMeta
|
||||||
|
|
@ -815,13 +813,13 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
info: TLineInfo, anon = false): PType =
|
info: TLineInfo, anon = false): PType =
|
||||||
if paramType == nil: return # (e.g. proc return type)
|
if paramType == nil: return # (e.g. proc return type)
|
||||||
|
|
||||||
proc addImplicitGenericImpl(typeClass: PType, typId: PIdent): PType =
|
proc addImplicitGenericImpl(c: PContext; typeClass: PType, typId: PIdent): PType =
|
||||||
if genericParams == nil:
|
if genericParams == nil:
|
||||||
# This happens with anonymous proc types appearing in signatures
|
# This happens with anonymous proc types appearing in signatures
|
||||||
# XXX: we need to lift these earlier
|
# XXX: we need to lift these earlier
|
||||||
return
|
return
|
||||||
let finalTypId = if typId != nil: typId
|
let finalTypId = if typId != nil: typId
|
||||||
else: getIdent(paramName & ":type")
|
else: getIdent(c.cache, paramName & ":type")
|
||||||
# is this a bindOnce type class already present in the param list?
|
# is this a bindOnce type class already present in the param list?
|
||||||
for i in countup(0, genericParams.len - 1):
|
for i in countup(0, genericParams.len - 1):
|
||||||
if genericParams.sons[i].sym.name.id == finalTypId.id:
|
if genericParams.sons[i].sym.name.id == finalTypId.id:
|
||||||
|
|
@ -852,11 +850,11 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
(if lifted != nil: lifted else: typ)
|
(if lifted != nil: lifted else: typ)
|
||||||
|
|
||||||
template addImplicitGeneric(e): untyped =
|
template addImplicitGeneric(e): untyped =
|
||||||
addImplicitGenericImpl(e, paramTypId)
|
addImplicitGenericImpl(c, e, paramTypId)
|
||||||
|
|
||||||
case paramType.kind:
|
case paramType.kind:
|
||||||
of tyAnything:
|
of tyAnything:
|
||||||
result = addImplicitGenericImpl(newTypeS(tyGenericParam, c), nil)
|
result = addImplicitGenericImpl(c, newTypeS(tyGenericParam, c), nil)
|
||||||
|
|
||||||
of tyStatic:
|
of tyStatic:
|
||||||
# proc(a: expr{string}, b: expr{nkLambda})
|
# proc(a: expr{string}, b: expr{nkLambda})
|
||||||
|
|
@ -873,7 +871,9 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
if tfUnresolved notin paramType.flags:
|
if tfUnresolved notin paramType.flags:
|
||||||
# naked typedescs are not bindOnce types
|
# naked typedescs are not bindOnce types
|
||||||
if paramType.base.kind == tyNone and paramTypId != nil and
|
if paramType.base.kind == tyNone and paramTypId != nil and
|
||||||
paramTypId.id == typedescId.id: paramTypId = nil
|
paramTypId.id == getIdent(c.cache, "typedesc").id:
|
||||||
|
# XXX Why doesn't this check for tyTypeDesc instead?
|
||||||
|
paramTypId = nil
|
||||||
result = addImplicitGeneric(
|
result = addImplicitGeneric(
|
||||||
c.newTypeWithSons(tyTypeDesc, @[paramType.base]))
|
c.newTypeWithSons(tyTypeDesc, @[paramType.base]))
|
||||||
|
|
||||||
|
|
@ -1322,7 +1322,7 @@ proc semProcTypeWithScope(c: PContext, n: PNode,
|
||||||
# start with 'ccClosure', but of course pragmas can overwrite this:
|
# start with 'ccClosure', but of course pragmas can overwrite this:
|
||||||
result.callConv = ccClosure
|
result.callConv = ccClosure
|
||||||
# dummy symbol for `pragma`:
|
# dummy symbol for `pragma`:
|
||||||
var s = newSymS(kind, newIdentNode(getIdent("dummy"), n.info), c)
|
var s = newSymS(kind, newIdentNode(getIdent(c.cache, "dummy"), n.info), c)
|
||||||
s.typ = result
|
s.typ = result
|
||||||
if n.sons[1].kind != nkEmpty and n.sons[1].len > 0:
|
if n.sons[1].kind != nkEmpty and n.sons[1].len > 0:
|
||||||
pragma(c, s, n.sons[1], procTypePragmas)
|
pragma(c, s, n.sons[1], procTypePragmas)
|
||||||
|
|
@ -1345,7 +1345,7 @@ proc fixupTypeOf(c: PContext, prev: PType, typExpr: PNode) =
|
||||||
|
|
||||||
proc symFromExpectedTypeNode(c: PContext, n: PNode): PSym =
|
proc symFromExpectedTypeNode(c: PContext, n: PNode): PSym =
|
||||||
if n.kind == nkType:
|
if n.kind == nkType:
|
||||||
result = symFromType(n.typ, n.info)
|
result = symFromType(c, n.typ, n.info)
|
||||||
else:
|
else:
|
||||||
localError(c.config, n.info, errTypeExpected)
|
localError(c.config, n.info, errTypeExpected)
|
||||||
result = errorSym(c, n)
|
result = errorSym(c, n)
|
||||||
|
|
@ -1393,7 +1393,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
elif n[0].kind notin nkIdentKinds:
|
elif n[0].kind notin nkIdentKinds:
|
||||||
result = semTypeExpr(c, n, prev)
|
result = semTypeExpr(c, n, prev)
|
||||||
else:
|
else:
|
||||||
let op = considerQuotedIdent(c.config, n.sons[0])
|
let op = considerQuotedIdent(c, n.sons[0])
|
||||||
if op.id in {ord(wAnd), ord(wOr)} or op.s == "|":
|
if op.id in {ord(wAnd), ord(wOr)} or op.s == "|":
|
||||||
checkSonsLen(n, 3, c.config)
|
checkSonsLen(n, 3, c.config)
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -768,11 +768,11 @@ proc shouldSkipDistinct(m: TCandidate; rules: PNode, callIdent: PIdent): bool =
|
||||||
# XXX This is bad as 'considerQuotedIdent' can produce an error!
|
# XXX This is bad as 'considerQuotedIdent' can produce an error!
|
||||||
if rules.kind == nkWith:
|
if rules.kind == nkWith:
|
||||||
for r in rules:
|
for r in rules:
|
||||||
if considerQuotedIdent(m.c.graph.config, r) == callIdent: return true
|
if considerQuotedIdent(m.c, r) == callIdent: return true
|
||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
for r in rules:
|
for r in rules:
|
||||||
if considerQuotedIdent(m.c.graph.config, r) == callIdent: return false
|
if considerQuotedIdent(m.c, r) == callIdent: return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc maybeSkipDistinct(m: TCandidate; t: PType, callee: PSym): PType =
|
proc maybeSkipDistinct(m: TCandidate; t: PType, callee: PSym): PType =
|
||||||
|
|
@ -2126,10 +2126,10 @@ proc prepareOperand(c: PContext; a: PNode): PNode =
|
||||||
result = a
|
result = a
|
||||||
considerGenSyms(c, result)
|
considerGenSyms(c, result)
|
||||||
|
|
||||||
proc prepareNamedParam(a: PNode; conf: ConfigRef) =
|
proc prepareNamedParam(a: PNode; c: PContext) =
|
||||||
if a.sons[0].kind != nkIdent:
|
if a.sons[0].kind != nkIdent:
|
||||||
var info = a.sons[0].info
|
var info = a.sons[0].info
|
||||||
a.sons[0] = newIdentNode(considerQuotedIdent(conf, a.sons[0]), info)
|
a.sons[0] = newIdentNode(considerQuotedIdent(c, a.sons[0]), info)
|
||||||
|
|
||||||
proc arrayConstr(c: PContext, n: PNode): PType =
|
proc arrayConstr(c: PContext, n: PNode): PType =
|
||||||
result = newTypeS(tyArray, c)
|
result = newTypeS(tyArray, c)
|
||||||
|
|
@ -2194,7 +2194,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
elif n.sons[a].kind == nkExprEqExpr:
|
elif n.sons[a].kind == nkExprEqExpr:
|
||||||
# named param
|
# named param
|
||||||
# check if m.callee has such a param:
|
# check if m.callee has such a param:
|
||||||
prepareNamedParam(n.sons[a], c.config)
|
prepareNamedParam(n.sons[a], c)
|
||||||
if n.sons[a].sons[0].kind != nkIdent:
|
if n.sons[a].sons[0].kind != nkIdent:
|
||||||
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ proc getCurrOwner(c: PTransf): PSym =
|
||||||
else: result = c.module
|
else: result = c.module
|
||||||
|
|
||||||
proc newTemp(c: PTransf, typ: PType, info: TLineInfo): PNode =
|
proc newTemp(c: PTransf, typ: PType, info: TLineInfo): PNode =
|
||||||
let r = newSym(skTemp, getIdent(genPrefix), getCurrOwner(c), info)
|
let r = newSym(skTemp, getIdent(c.graph.cache, genPrefix), getCurrOwner(c), info)
|
||||||
r.typ = typ #skipTypes(typ, {tyGenericInst, tyAlias, tySink})
|
r.typ = typ #skipTypes(typ, {tyGenericInst, tyAlias, tySink})
|
||||||
incl(r.flags, sfFromGeneric)
|
incl(r.flags, sfFromGeneric)
|
||||||
let owner = getCurrOwner(c)
|
let owner = getCurrOwner(c)
|
||||||
|
|
@ -221,7 +221,7 @@ proc hasContinue(n: PNode): bool =
|
||||||
|
|
||||||
proc newLabel(c: PTransf, n: PNode): PSym =
|
proc newLabel(c: PTransf, n: PNode): PSym =
|
||||||
result = newSym(skLabel, nil, getCurrOwner(c), n.info)
|
result = newSym(skLabel, nil, getCurrOwner(c), n.info)
|
||||||
result.name = getIdent(genPrefix & $result.id)
|
result.name = getIdent(c.graph.cache, genPrefix & $result.id)
|
||||||
|
|
||||||
proc freshLabels(c: PTransf, n: PNode; symMap: var TIdTable) =
|
proc freshLabels(c: PTransf, n: PNode; symMap: var TIdTable) =
|
||||||
if n.kind in {nkBlockStmt, nkBlockExpr}:
|
if n.kind in {nkBlockStmt, nkBlockExpr}:
|
||||||
|
|
@ -981,7 +981,7 @@ proc transformBody*(g: ModuleGraph; module: PSym, n: PNode, prc: PSym): PNode =
|
||||||
liftDefer(c, result)
|
liftDefer(c, result)
|
||||||
#result = liftLambdas(prc, result)
|
#result = liftLambdas(prc, result)
|
||||||
when useEffectSystem: trackProc(g, prc, result)
|
when useEffectSystem: trackProc(g, prc, result)
|
||||||
result = liftLocalsIfRequested(prc, result, g.config)
|
result = liftLocalsIfRequested(prc, result, g.cache, g.config)
|
||||||
if c.needsDestroyPass: #and newDestructors:
|
if c.needsDestroyPass: #and newDestructors:
|
||||||
result = injectDestructorCalls(g, prc, result)
|
result = injectDestructorCalls(g, prc, result)
|
||||||
incl(result.flags, nfTransf)
|
incl(result.flags, nfTransf)
|
||||||
|
|
|
||||||
|
|
@ -1291,7 +1291,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
# getType opcode:
|
# getType opcode:
|
||||||
ensureKind(rkNode)
|
ensureKind(rkNode)
|
||||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||||
regs[ra].node = opMapTypeToAst(regs[rb].node.typ, c.debug[pc])
|
regs[ra].node = opMapTypeToAst(c.cache, regs[rb].node.typ, c.debug[pc])
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, "node has no type")
|
stackTrace(c, tos, pc, "node has no type")
|
||||||
of 1:
|
of 1:
|
||||||
|
|
@ -1305,14 +1305,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
# getTypeInst opcode:
|
# getTypeInst opcode:
|
||||||
ensureKind(rkNode)
|
ensureKind(rkNode)
|
||||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||||
regs[ra].node = opMapTypeInstToAst(regs[rb].node.typ, c.debug[pc])
|
regs[ra].node = opMapTypeInstToAst(c.cache, regs[rb].node.typ, c.debug[pc])
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, "node has no type")
|
stackTrace(c, tos, pc, "node has no type")
|
||||||
else:
|
else:
|
||||||
# getTypeImpl opcode:
|
# getTypeImpl opcode:
|
||||||
ensureKind(rkNode)
|
ensureKind(rkNode)
|
||||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||||
regs[ra].node = opMapTypeImplToAst(regs[rb].node.typ, c.debug[pc])
|
regs[ra].node = opMapTypeImplToAst(c.cache, regs[rb].node.typ, c.debug[pc])
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, "node has no type")
|
stackTrace(c, tos, pc, "node has no type")
|
||||||
of opcNStrVal:
|
of opcNStrVal:
|
||||||
|
|
@ -1453,7 +1453,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
stackTrace(c, tos, pc, errFieldXNotFound & "strVal")
|
stackTrace(c, tos, pc, errFieldXNotFound & "strVal")
|
||||||
else:
|
else:
|
||||||
regs[ra].node = newNodeI(nkIdent, c.debug[pc])
|
regs[ra].node = newNodeI(nkIdent, c.debug[pc])
|
||||||
regs[ra].node.ident = getIdent(regs[rb].node.strVal)
|
regs[ra].node.ident = getIdent(c.cache, regs[rb].node.strVal)
|
||||||
of opcSetType:
|
of opcSetType:
|
||||||
if regs[ra].kind != rkNode:
|
if regs[ra].kind != rkNode:
|
||||||
internalError(c.config, c.debug[pc], "cannot set type")
|
internalError(c.config, c.debug[pc], "cannot set type")
|
||||||
|
|
@ -1566,7 +1566,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
else: regs[rc].node.strVal
|
else: regs[rc].node.strVal
|
||||||
if k < 0 or k > ord(high(TSymKind)):
|
if k < 0 or k > ord(high(TSymKind)):
|
||||||
internalError(c.config, c.debug[pc], "request to create symbol of invalid kind")
|
internalError(c.config, c.debug[pc], "request to create symbol of invalid kind")
|
||||||
var sym = newSym(k.TSymKind, name.getIdent, c.module.owner, c.debug[pc])
|
var sym = newSym(k.TSymKind, getIdent(c.cache, name), c.module.owner, c.debug[pc])
|
||||||
incl(sym.flags, sfGenSym)
|
incl(sym.flags, sfGenSym)
|
||||||
regs[ra].node = newSymNode(sym)
|
regs[ra].node = newSymNode(sym)
|
||||||
of opcTypeTrait:
|
of opcTypeTrait:
|
||||||
|
|
@ -1583,7 +1583,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
let rb = instr.regB
|
let rb = instr.regB
|
||||||
inc pc
|
inc pc
|
||||||
let typ = c.types[c.code[pc].regBx - wordExcess]
|
let typ = c.types[c.code[pc].regBx - wordExcess]
|
||||||
putIntoReg(regs[ra], loadAny(regs[rb].node.strVal, typ, c.config))
|
putIntoReg(regs[ra], loadAny(regs[rb].node.strVal, typ, c.cache, c.config))
|
||||||
of opcMarshalStore:
|
of opcMarshalStore:
|
||||||
decodeB(rkNode)
|
decodeB(rkNode)
|
||||||
inc pc
|
inc pc
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): str
|
||||||
localError(conf, info, "cannot open file: " & file)
|
localError(conf, info, "cannot open file: " & file)
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
proc atomicTypeX(name: string; m: TMagic; t: PType; info: TLineInfo): PNode =
|
proc atomicTypeX(cache: IdentCache; name: string; m: TMagic; t: PType; info: TLineInfo): PNode =
|
||||||
let sym = newSym(skType, getIdent(name), t.owner, info)
|
let sym = newSym(skType, getIdent(cache, name), t.owner, info)
|
||||||
sym.magic = m
|
sym.magic = m
|
||||||
sym.typ = t
|
sym.typ = t
|
||||||
result = newSymNode(sym)
|
result = newSymNode(sym)
|
||||||
|
|
@ -34,44 +34,44 @@ proc atomicTypeX(s: PSym; info: TLineInfo): PNode =
|
||||||
result = newSymNode(s)
|
result = newSymNode(s)
|
||||||
result.info = info
|
result.info = info
|
||||||
|
|
||||||
proc mapTypeToAstX(t: PType; info: TLineInfo;
|
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||||
inst=false; allowRecursionX=false): PNode
|
inst=false; allowRecursionX=false): PNode
|
||||||
|
|
||||||
proc mapTypeToBracketX(name: string; m: TMagic; t: PType; info: TLineInfo;
|
proc mapTypeToBracketX(cache: IdentCache; name: string; m: TMagic; t: PType; info: TLineInfo;
|
||||||
inst=false): PNode =
|
inst=false): PNode =
|
||||||
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
||||||
result.add atomicTypeX(name, m, t, info)
|
result.add atomicTypeX(cache, name, m, t, info)
|
||||||
for i in 0 ..< t.len:
|
for i in 0 ..< t.len:
|
||||||
if t.sons[i] == nil:
|
if t.sons[i] == nil:
|
||||||
let void = atomicTypeX("void", mVoid, t, info)
|
let void = atomicTypeX(cache, "void", mVoid, t, info)
|
||||||
void.typ = newType(tyVoid, t.owner)
|
void.typ = newType(tyVoid, t.owner)
|
||||||
result.add void
|
result.add void
|
||||||
else:
|
else:
|
||||||
result.add mapTypeToAstX(t.sons[i], info, inst)
|
result.add mapTypeToAstX(cache, t.sons[i], info, inst)
|
||||||
|
|
||||||
proc objectNode(n: PNode): PNode =
|
proc objectNode(cache: IdentCache; n: PNode): PNode =
|
||||||
if n.kind == nkSym:
|
if n.kind == nkSym:
|
||||||
result = newNodeI(nkIdentDefs, n.info)
|
result = newNodeI(nkIdentDefs, n.info)
|
||||||
result.add n # name
|
result.add n # name
|
||||||
result.add mapTypeToAstX(n.sym.typ, n.info, true, false) # type
|
result.add mapTypeToAstX(cache, n.sym.typ, n.info, true, false) # type
|
||||||
result.add newNodeI(nkEmpty, n.info) # no assigned value
|
result.add newNodeI(nkEmpty, n.info) # no assigned value
|
||||||
else:
|
else:
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
for i in 0 ..< n.safeLen:
|
for i in 0 ..< n.safeLen:
|
||||||
result.add objectNode(n[i])
|
result.add objectNode(cache, n[i])
|
||||||
|
|
||||||
proc mapTypeToAstX(t: PType; info: TLineInfo;
|
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||||
inst=false; allowRecursionX=false): PNode =
|
inst=false; allowRecursionX=false): PNode =
|
||||||
var allowRecursion = allowRecursionX
|
var allowRecursion = allowRecursionX
|
||||||
template atomicType(name, m): untyped = atomicTypeX(name, m, t, info)
|
template atomicType(name, m): untyped = atomicTypeX(cache, name, m, t, info)
|
||||||
template atomicType(s): untyped = atomicTypeX(s, info)
|
template atomicType(s): untyped = atomicTypeX(s, info)
|
||||||
template mapTypeToAst(t,info): untyped = mapTypeToAstX(t, info, inst)
|
template mapTypeToAst(t,info): untyped = mapTypeToAstX(cache, t, info, inst)
|
||||||
template mapTypeToAstR(t,info): untyped = mapTypeToAstX(t, info, inst, true)
|
template mapTypeToAstR(t,info): untyped = mapTypeToAstX(cache, t, info, inst, true)
|
||||||
template mapTypeToAst(t,i,info): untyped =
|
template mapTypeToAst(t,i,info): untyped =
|
||||||
if i<t.len and t.sons[i]!=nil: mapTypeToAstX(t.sons[i], info, inst)
|
if i<t.len and t.sons[i]!=nil: mapTypeToAstX(cache, t.sons[i], info, inst)
|
||||||
else: newNodeI(nkEmpty, info)
|
else: newNodeI(nkEmpty, info)
|
||||||
template mapTypeToBracket(name, m, t, info): untyped =
|
template mapTypeToBracket(name, m, t, info): untyped =
|
||||||
mapTypeToBracketX(name, m, t, info, inst)
|
mapTypeToBracketX(cache, name, m, t, info, inst)
|
||||||
template newNodeX(kind): untyped =
|
template newNodeX(kind): untyped =
|
||||||
newNodeIT(kind, if t.n.isNil: info else: t.n.info, t)
|
newNodeIT(kind, if t.n.isNil: info else: t.n.info, t)
|
||||||
template newIdentDefs(n,t): untyped =
|
template newIdentDefs(n,t): untyped =
|
||||||
|
|
@ -103,7 +103,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
result.add atomicType("array", mArray)
|
result.add atomicType("array", mArray)
|
||||||
if inst and t.sons[0].kind == tyRange:
|
if inst and t.sons[0].kind == tyRange:
|
||||||
var rng = newNodeX(nkInfix)
|
var rng = newNodeX(nkInfix)
|
||||||
rng.add newIdentNode(getIdent(".."), info)
|
rng.add newIdentNode(getIdent(cache, ".."), info)
|
||||||
rng.add t.sons[0].n.sons[0].copyTree
|
rng.add t.sons[0].n.sons[0].copyTree
|
||||||
rng.add t.sons[0].n.sons[1].copyTree
|
rng.add t.sons[0].n.sons[1].copyTree
|
||||||
result.add rng
|
result.add rng
|
||||||
|
|
@ -132,14 +132,14 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
for i in 1 ..< t.len-1:
|
for i in 1 ..< t.len-1:
|
||||||
result.add mapTypeToAst(t.sons[i], info)
|
result.add mapTypeToAst(t.sons[i], info)
|
||||||
else:
|
else:
|
||||||
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
result = mapTypeToAstX(cache, t.lastSon, info, inst, allowRecursion)
|
||||||
of tyGenericBody:
|
of tyGenericBody:
|
||||||
if inst:
|
if inst:
|
||||||
result = mapTypeToAstR(t.lastSon, info)
|
result = mapTypeToAstR(t.lastSon, info)
|
||||||
else:
|
else:
|
||||||
result = mapTypeToAst(t.lastSon, info)
|
result = mapTypeToAst(t.lastSon, info)
|
||||||
of tyAlias:
|
of tyAlias:
|
||||||
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
|
result = mapTypeToAstX(cache, t.lastSon, info, inst, allowRecursion)
|
||||||
of tyOrdinal:
|
of tyOrdinal:
|
||||||
result = mapTypeToAst(t.lastSon, info)
|
result = mapTypeToAst(t.lastSon, info)
|
||||||
of tyDistinct:
|
of tyDistinct:
|
||||||
|
|
@ -163,7 +163,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
nn.add mapTypeToAst(t.sons[0], info)
|
nn.add mapTypeToAst(t.sons[0], info)
|
||||||
result.add nn
|
result.add nn
|
||||||
if t.n.len > 0:
|
if t.n.len > 0:
|
||||||
result.add objectNode(t.n)
|
result.add objectNode(cache, t.n)
|
||||||
else:
|
else:
|
||||||
result.add newNodeI(nkEmpty, info)
|
result.add newNodeI(nkEmpty, info)
|
||||||
else:
|
else:
|
||||||
|
|
@ -283,15 +283,15 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||||
result.add t.n.copyTree
|
result.add t.n.copyTree
|
||||||
of tyUnused, tyOptAsRef: assert(false, "mapTypeToAstX")
|
of tyUnused, tyOptAsRef: assert(false, "mapTypeToAstX")
|
||||||
|
|
||||||
proc opMapTypeToAst*(t: PType; info: TLineInfo): PNode =
|
proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||||
result = mapTypeToAstX(t, info, false, true)
|
result = mapTypeToAstX(cache, t, info, false, true)
|
||||||
|
|
||||||
# the "Inst" version includes generic parameters in the resulting type tree
|
# the "Inst" version includes generic parameters in the resulting type tree
|
||||||
# and also tries to look like the corresponding Nim type declaration
|
# and also tries to look like the corresponding Nim type declaration
|
||||||
proc opMapTypeInstToAst*(t: PType; info: TLineInfo): PNode =
|
proc opMapTypeInstToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||||
result = mapTypeToAstX(t, info, true, false)
|
result = mapTypeToAstX(cache, t, info, true, false)
|
||||||
|
|
||||||
# the "Impl" version includes generic parameters in the resulting type tree
|
# the "Impl" version includes generic parameters in the resulting type tree
|
||||||
# and also tries to look like the corresponding Nim type implementation
|
# and also tries to look like the corresponding Nim type implementation
|
||||||
proc opMapTypeImplToAst*(t: PType; info: TLineInfo): PNode =
|
proc opMapTypeImplToAst*(cache: IdentCache; t: PType; info: TLineInfo): PNode =
|
||||||
result = mapTypeToAstX(t, info, true, true)
|
result = mapTypeToAstX(cache, t, info, true, true)
|
||||||
|
|
|
||||||
|
|
@ -965,7 +965,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
c.freeTemp(tmp)
|
c.freeTemp(tmp)
|
||||||
of mSwap:
|
of mSwap:
|
||||||
unused(c, n, dest)
|
unused(c, n, dest)
|
||||||
c.gen(lowerSwap(n, if c.prc == nil: c.module else: c.prc.sym))
|
c.gen(lowerSwap(c.graph, n, if c.prc == nil: c.module else: c.prc.sym))
|
||||||
of mIsNil: genUnaryABC(c, n, dest, opcIsNil)
|
of mIsNil: genUnaryABC(c, n, dest, opcIsNil)
|
||||||
of mCopyStr:
|
of mCopyStr:
|
||||||
if dest < 0: dest = c.getTemp(n.typ)
|
if dest < 0: dest = c.getTemp(n.typ)
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ proc storeAny*(s: var string; t: PType; a: PNode; conf: ConfigRef) =
|
||||||
|
|
||||||
proc loadAny(p: var JsonParser, t: PType,
|
proc loadAny(p: var JsonParser, t: PType,
|
||||||
tab: var Table[BiggestInt, PNode];
|
tab: var Table[BiggestInt, PNode];
|
||||||
|
cache: IdentCache;
|
||||||
conf: ConfigRef): PNode =
|
conf: ConfigRef): PNode =
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyNone: assert false
|
of tyNone: assert false
|
||||||
|
|
@ -174,7 +175,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
next(p)
|
next(p)
|
||||||
result = newNode(nkBracket)
|
result = newNode(nkBracket)
|
||||||
while p.kind != jsonArrayEnd and p.kind != jsonEof:
|
while p.kind != jsonArrayEnd and p.kind != jsonEof:
|
||||||
result.add loadAny(p, t.elemType, tab, conf)
|
result.add loadAny(p, t.elemType, tab, cache, conf)
|
||||||
if p.kind == jsonArrayEnd: next(p)
|
if p.kind == jsonArrayEnd: next(p)
|
||||||
else: raiseParseErr(p, "']' end of array expected")
|
else: raiseParseErr(p, "']' end of array expected")
|
||||||
of tySequence:
|
of tySequence:
|
||||||
|
|
@ -186,7 +187,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
next(p)
|
next(p)
|
||||||
result = newNode(nkBracket)
|
result = newNode(nkBracket)
|
||||||
while p.kind != jsonArrayEnd and p.kind != jsonEof:
|
while p.kind != jsonArrayEnd and p.kind != jsonEof:
|
||||||
result.add loadAny(p, t.elemType, tab, conf)
|
result.add loadAny(p, t.elemType, tab, cache, conf)
|
||||||
if p.kind == jsonArrayEnd: next(p)
|
if p.kind == jsonArrayEnd: next(p)
|
||||||
else: raiseParseErr(p, "")
|
else: raiseParseErr(p, "")
|
||||||
else:
|
else:
|
||||||
|
|
@ -202,7 +203,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
next(p)
|
next(p)
|
||||||
if i >= t.len:
|
if i >= t.len:
|
||||||
raiseParseErr(p, "too many fields to tuple type " & typeToString(t))
|
raiseParseErr(p, "too many fields to tuple type " & typeToString(t))
|
||||||
result.add loadAny(p, t.sons[i], tab, conf)
|
result.add loadAny(p, t.sons[i], tab, cache, conf)
|
||||||
inc i
|
inc i
|
||||||
if p.kind == jsonObjectEnd: next(p)
|
if p.kind == jsonObjectEnd: next(p)
|
||||||
else: raiseParseErr(p, "'}' end of object expected")
|
else: raiseParseErr(p, "'}' end of object expected")
|
||||||
|
|
@ -214,7 +215,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
while p.kind != jsonObjectEnd and p.kind != jsonEof:
|
while p.kind != jsonObjectEnd and p.kind != jsonEof:
|
||||||
if p.kind != jsonString:
|
if p.kind != jsonString:
|
||||||
raiseParseErr(p, "string expected for a field name")
|
raiseParseErr(p, "string expected for a field name")
|
||||||
let ident = getIdent(p.str)
|
let ident = getIdent(cache, p.str)
|
||||||
let field = lookupInRecord(t.n, ident)
|
let field = lookupInRecord(t.n, ident)
|
||||||
if field.isNil:
|
if field.isNil:
|
||||||
raiseParseErr(p, "unknown field for object of type " & typeToString(t))
|
raiseParseErr(p, "unknown field for object of type " & typeToString(t))
|
||||||
|
|
@ -224,7 +225,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
setLen(result.sons, pos + 1)
|
setLen(result.sons, pos + 1)
|
||||||
let fieldNode = newNode(nkExprColonExpr)
|
let fieldNode = newNode(nkExprColonExpr)
|
||||||
fieldNode.addSon(newSymNode(newSym(skField, ident, nil, unknownLineInfo())))
|
fieldNode.addSon(newSymNode(newSym(skField, ident, nil, unknownLineInfo())))
|
||||||
fieldNode.addSon(loadAny(p, field.typ, tab, conf))
|
fieldNode.addSon(loadAny(p, field.typ, tab, cache, conf))
|
||||||
result.sons[pos] = fieldNode
|
result.sons[pos] = fieldNode
|
||||||
if p.kind == jsonObjectEnd: next(p)
|
if p.kind == jsonObjectEnd: next(p)
|
||||||
else: raiseParseErr(p, "'}' end of object expected")
|
else: raiseParseErr(p, "'}' end of object expected")
|
||||||
|
|
@ -233,7 +234,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
next(p)
|
next(p)
|
||||||
result = newNode(nkCurly)
|
result = newNode(nkCurly)
|
||||||
while p.kind != jsonArrayEnd and p.kind != jsonEof:
|
while p.kind != jsonArrayEnd and p.kind != jsonEof:
|
||||||
result.add loadAny(p, t.lastSon, tab, conf)
|
result.add loadAny(p, t.lastSon, tab, cache, conf)
|
||||||
next(p)
|
next(p)
|
||||||
if p.kind == jsonArrayEnd: next(p)
|
if p.kind == jsonArrayEnd: next(p)
|
||||||
else: raiseParseErr(p, "']' end of array expected")
|
else: raiseParseErr(p, "']' end of array expected")
|
||||||
|
|
@ -252,7 +253,7 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
if p.kind == jsonInt:
|
if p.kind == jsonInt:
|
||||||
let idx = p.getInt
|
let idx = p.getInt
|
||||||
next(p)
|
next(p)
|
||||||
result = loadAny(p, t.lastSon, tab, conf)
|
result = loadAny(p, t.lastSon, tab, cache, conf)
|
||||||
tab[idx] = result
|
tab[idx] = result
|
||||||
else: raiseParseErr(p, "index for ref type expected")
|
else: raiseParseErr(p, "index for ref type expected")
|
||||||
if p.kind == jsonArrayEnd: next(p)
|
if p.kind == jsonArrayEnd: next(p)
|
||||||
|
|
@ -280,14 +281,14 @@ proc loadAny(p: var JsonParser, t: PType,
|
||||||
return
|
return
|
||||||
raiseParseErr(p, "float expected")
|
raiseParseErr(p, "float expected")
|
||||||
of tyRange, tyGenericInst, tyAlias, tySink:
|
of tyRange, tyGenericInst, tyAlias, tySink:
|
||||||
result = loadAny(p, t.lastSon, tab, conf)
|
result = loadAny(p, t.lastSon, tab, cache, conf)
|
||||||
else:
|
else:
|
||||||
internalError conf, "cannot marshal at compile-time " & t.typeToString
|
internalError conf, "cannot marshal at compile-time " & t.typeToString
|
||||||
|
|
||||||
proc loadAny*(s: string; t: PType; conf: ConfigRef): PNode =
|
proc loadAny*(s: string; t: PType; cache: IdentCache; conf: ConfigRef): PNode =
|
||||||
var tab = initTable[BiggestInt, PNode]()
|
var tab = initTable[BiggestInt, PNode]()
|
||||||
var p: JsonParser
|
var p: JsonParser
|
||||||
open(p, newStringStream(s), "unknown file")
|
open(p, newStringStream(s), "unknown file")
|
||||||
next(p)
|
next(p)
|
||||||
result = loadAny(p, t, tab, conf)
|
result = loadAny(p, t, tab, cache, conf)
|
||||||
close(p)
|
close(p)
|
||||||
|
|
|
||||||
|
|
@ -627,7 +627,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
extccomp.initVars(conf)
|
extccomp.initVars(conf)
|
||||||
processCmdLine(passCmd2, "", conf)
|
processCmdLine(passCmd2, "", conf)
|
||||||
|
|
||||||
let graph = newModuleGraph(conf)
|
let graph = newModuleGraph(cache, conf)
|
||||||
graph.suggestMode = true
|
graph.suggestMode = true
|
||||||
mainCommand(graph, cache)
|
mainCommand(graph, cache)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue