Save skipped symbols with -d

This commit is contained in:
Ganesh Viswanathan 2019-10-28 17:13:50 -05:00
commit 1f09de2531
3 changed files with 21 additions and 4 deletions

View file

@ -1,4 +1,4 @@
import macros, os, sets, strformat, strutils, tables, times import hashes, macros, os, sets, strformat, strutils, tables, times
import regex import regex
@ -204,5 +204,13 @@ proc printNim*(gState: State, fullpath: string, root: TSNode, astTable: AstTable
if nimState.procStr.nBl: if nimState.procStr.nBl:
echo &"{nimState.procStr}\n" echo &"{nimState.procStr}\n"
if nimState.debugStr.nBl: if nimState.gState.debug:
echo nimState.debugStr if nimState.debugStr.nBl:
echo nimState.debugStr
if nimState.skipStr.nBl:
let
hash = nimState.skipStr.hash().abs()
sname = getTempDir() / &"nimterop_{$hash}.h"
echo &"# Writing skipped definitions to {sname}\n"
writeFile(sname, nimState.skipStr)

View file

@ -65,7 +65,7 @@ type
NimState {.used.} = ref object NimState {.used.} = ref object
identifiers*: TableRef[string, string] identifiers*: TableRef[string, string]
commentStr*, constStr*, debugStr*, enumStr*, procStr*, typeStr*: string commentStr*, constStr*, debugStr*, enumStr*, procStr*, skipStr*, typeStr*: string
gState*: State gState*: State

View file

@ -31,6 +31,8 @@ proc initGrammar(): Grammar =
nimState.constStr &= &"{nimState.getComments()}\n{override}" nimState.constStr &= &"{nimState.getComments()}\n{override}"
else: else:
nimState.constStr &= &"{nimState.getComments()}\n # Const '{name}' skipped" nimState.constStr &= &"{nimState.getComments()}\n # Const '{name}' skipped"
if nimState.gState.debug:
nimState.skipStr &= &"\n{nimState.getNodeVal(node)}"
elif val.nBl and nimState.addNewIdentifer(nname): elif val.nBl and nimState.addNewIdentifer(nname):
nimState.constStr &= &"{nimState.getComments()}\n {nname}* = {val}" nimState.constStr &= &"{nimState.getComments()}\n {nname}* = {val}"
)) ))
@ -667,6 +669,8 @@ proc initGrammar(): Grammar =
) )
""", """,
proc (ast: ref Ast, node: TSNode, nimState: NimState) = proc (ast: ref Ast, node: TSNode, nimState: NimState) =
var
done = false
for i in nimState.data: for i in nimState.data:
case $node.tsNodeType() case $node.tsNodeType()
of "declaration": of "declaration":
@ -676,6 +680,7 @@ proc initGrammar(): Grammar =
if override.len != 0: if override.len != 0:
nimState.procStr &= &"{nimState.getComments(true)}\n{override}" nimState.procStr &= &"{nimState.getComments(true)}\n{override}"
done = true
break break
else: else:
nimState.procStr &= &"{nimState.getComments(true)}\n# Declaration '{i.val}' skipped" nimState.procStr &= &"{nimState.getComments(true)}\n# Declaration '{i.val}' skipped"
@ -687,9 +692,13 @@ proc initGrammar(): Grammar =
if override.len != 0: if override.len != 0:
nimState.typeStr &= &"{nimState.getComments()}\n{override}" nimState.typeStr &= &"{nimState.getComments()}\n{override}"
done = true
break
else: else:
nimState.typeStr &= &"{nimState.getComments()}\n # Type '{i.val}' skipped" nimState.typeStr &= &"{nimState.getComments()}\n # Type '{i.val}' skipped"
if nimState.gState.debug and not done:
nimState.skipStr &= &"\n{nimState.getNodeVal(node)}"
)) ))
proc initRegex(ast: ref Ast) = proc initRegex(ast: ref Ast) =