From b8a436af93a0f05c47634b7dfa1aff120ce6efb8 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 23 Jan 2020 02:06:28 -0800 Subject: [PATCH] kochdocs: use a glob instead of hardcoded list; generate docs for compiler/; bugfixes (#13221) * kochdocs: use a glob instead of hardcoded list; generate docs for compiler/; bugfixes * fixup after #13212 isRelativeTo got merged --- compiler/astalgo.nim | 4 +- compiler/btrees.nim | 2 +- tools/kochdocs.nim | 283 +++++++++++++++++++++---------------------- 3 files changed, 141 insertions(+), 148 deletions(-) diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index f228de1cad..fd95b3780a 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -218,12 +218,12 @@ proc sameIgnoreBacktickGensymInfo(a, b: string): bool = proc getNamedParamFromList*(list: PNode, ident: PIdent): PSym = ## Named parameters are special because a named parameter can be - ## gensym'ed and then they have '`' suffix that we need to + ## gensym'ed and then they have '\`' suffix that we need to ## ignore, see compiler / evaltempl.nim, snippet: ## ##..code-block:: nim ## - ## result.add newIdentNode(getIdent(c.ic, x.name.s & "`gensym" & $x.id), + ## result.add newIdentNode(getIdent(c.ic, x.name.s & "\`gensym" & $x.id), ## if c.instLines: actual.info else: templ.info) for i in 1.. 0 and not ret.startsWith ".." + +proc getDocList(): seq[string] = + var t: HashSet[string] + for a in doc0: + doAssert a notin t + t.incl a + for a in withoutIndex: + doAssert a notin t, a + t.incl a + + for a in ignoredModules: + doAssert a notin t, a + t.incl a + + var t2: HashSet[string] + template myadd(a)= + result.add a + doAssert a notin t2, a + t2.incl a + + # don't ignore these even though in lib/system + const goodSystem = """ +lib/system/io.nim +lib/system/nimscript.nim +lib/system/assertions.nim +lib/system/iterators.nim +lib/system/dollars.nim +lib/system/widestrs.nim +""".splitWhitespace() + + for a in walkDirRec("lib"): + if a.splitFile.ext != ".nim": continue + if a.isRelativeTo("lib/pure/includes"): continue + if a.isRelativeTo("lib/genode"): continue + if a.isRelativeTo("lib/deprecated"): + if a notin @["lib/deprecated/pure/ospaths.nim"]: # REMOVE + continue + if a.isRelativeTo("lib/system"): + if a notin goodSystem: + continue + if a notin t: + result.add a + doAssert a notin t2, a + t2.incl a + + myadd "nimsuggest/sexp.nim" + # these are include files, even though some of them don't specify `included from ...` + const ignore = """ +compiler/ccgcalls.nim +compiler/ccgexprs.nim +compiler/ccgliterals.nim +compiler/ccgstmts.nim +compiler/ccgthreadvars.nim +compiler/ccgtrav.nim +compiler/ccgtypes.nim +compiler/jstypes.nim +compiler/semcall.nim +compiler/semexprs.nim +compiler/semfields.nim +compiler/semgnrc.nim +compiler/seminst.nim +compiler/semmagic.nim +compiler/semobjconstr.nim +compiler/semstmts.nim +compiler/semtempl.nim +compiler/semtypes.nim +compiler/sizealignoffsetimpl.nim +compiler/suggest.nim +compiler/packagehandling.nim +compiler/hlo.nim +compiler/rodimpl.nim +compiler/vmops.nim +compiler/vmhooks.nim +""".splitWhitespace() + + # not include files but doesn't work; not included/imported anywhere; dead code? + const bad = """ +compiler/debuginfo.nim +compiler/canonicalizer.nim +compiler/forloops.nim +""".splitWhitespace() + + # these cause errors even though they're imported (some of which are mysterious) + const bad2 = """ +compiler/closureiters.nim +compiler/tccgen.nim +compiler/lambdalifting.nim +compiler/layouter.nim +compiler/evalffi.nim +compiler/nimfix/nimfix.nim +compiler/plugins/active.nim +compiler/plugins/itersgen.nim +""".splitWhitespace() + + for a in walkDirRec("compiler"): + if a.splitFile.ext != ".nim": continue + if a in ignore: continue + if a in bad: continue + if a in bad2: continue + result.add a + +let doc = getDocList() + proc sexec(cmds: openArray[string]) = ## Serial queue wrapper around exec. for cmd in cmds: