Skip to content

Commit

Permalink
fix #13100 nim doc now treats export localSymbol correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 12, 2020
1 parent a33b72a commit fdb0dfd
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,12 @@ proc genDeprecationMsg(d: PDoc, n: PNode): Rope =
else:
doAssert false

proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) =
if not isVisible(d, nameNode): return
type DocFlags = enum
kDefault
kForceExport

proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
if (docFlags != kForceExport) and not isVisible(d, nameNode): return
let
name = getName(d, nameNode)
nameRope = name.rope
Expand Down Expand Up @@ -847,35 +851,37 @@ proc documentRaises*(cache: IdentCache; n: PNode) =
if p4 != nil: n[pragmasPos].add p4
if p5 != nil: n[pragmasPos].add p5

proc generateDoc*(d: PDoc, n, orig: PNode) =
proc generateDoc*(d: PDoc, n, orig: PNode, docFlags: DocFlags = kDefault) =
template genItemAux(skind) =
genItem(d, n, n[namePos], skind, docFlags)
case n.kind
of nkPragma:
let pragmaNode = findPragma(n, wDeprecated)
d.modDeprecationMsg.add(genDeprecationMsg(d, pragmaNode))
of nkCommentStmt: d.modDesc.add(genComment(d, n))
of nkProcDef:
when useEffectSystem: documentRaises(d.cache, n)
genItem(d, n, n[namePos], skProc)
genItemAux(skProc)
of nkFuncDef:
when useEffectSystem: documentRaises(d.cache, n)
genItem(d, n, n[namePos], skFunc)
genItemAux(skFunc)
of nkMethodDef:
when useEffectSystem: documentRaises(d.cache, n)
genItem(d, n, n[namePos], skMethod)
genItemAux(skMethod)
of nkIteratorDef:
when useEffectSystem: documentRaises(d.cache, n)
genItem(d, n, n[namePos], skIterator)
of nkMacroDef: genItem(d, n, n[namePos], skMacro)
of nkTemplateDef: genItem(d, n, n[namePos], skTemplate)
genItemAux(skIterator)
of nkMacroDef: genItemAux(skMacro)
of nkTemplateDef: genItemAux(skTemplate)
of nkConverterDef:
when useEffectSystem: documentRaises(d.cache, n)
genItem(d, n, n[namePos], skConverter)
genItemAux(skConverter)
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
for i in 0..<n.len:
if n[i].kind != nkCommentStmt:
# order is always 'type var let const':
genItem(d, n[i], n[i][0],
succ(skType, ord(n.kind)-ord(nkTypeSection)))
succ(skType, ord(n.kind)-ord(nkTypeSection)), docFlags)
of nkStmtList:
for i in 0..<n.len: generateDoc(d, n[i], orig)
of nkWhenStmt:
Expand All @@ -886,7 +892,12 @@ proc generateDoc*(d: PDoc, n, orig: PNode) =
for it in n: traceDeps(d, it)
of nkExportStmt:
for it in n:
if it.kind == nkSym: exportSym(d, it.sym)
if it.kind == nkSym:
let ast = it.sym.ast
if it.info.fileIndex == ast.info.fileIndex:
generateDoc(d, ast, orig, kForceExport)
else:
exportSym(d, it.sym)
of nkExportExceptStmt: discard "transformed into nkExportStmt by semExportExcept"
of nkFromStmt, nkImportExceptStmt: traceDeps(d, n[0])
of nkCallKinds:
Expand Down

0 comments on commit fdb0dfd

Please sign in to comment.