aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-10-28 17:13:50 -0500
committerGanesh Viswanathan <dev@genotrance.com>2019-10-28 17:13:50 -0500
commit1f09de2531f499160b2e766554aa1dfd8a376b95 (patch)
tree696148dcb0736261f65e77deb4bcd4b63beb5ae6
parent872873c07a0a85117da73c4a27a806d90029a4f7 (diff)
downloadnimterop-1f09de2531f499160b2e766554aa1dfd8a376b95.tar.gz
nimterop-1f09de2531f499160b2e766554aa1dfd8a376b95.zip
Save skipped symbols with -d
-rw-r--r--nimterop/ast.nim14
-rw-r--r--nimterop/globals.nim2
-rw-r--r--nimterop/grammar.nim9
3 files changed, 21 insertions, 4 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim
index 1617ea4..ad724b9 100644
--- a/nimterop/ast.nim
+++ b/nimterop/ast.nim
@@ -1,4 +1,4 @@
-import macros, os, sets, strformat, strutils, tables, times
+import hashes, macros, os, sets, strformat, strutils, tables, times
import regex
@@ -204,5 +204,13 @@ proc printNim*(gState: State, fullpath: string, root: TSNode, astTable: AstTable
if nimState.procStr.nBl:
echo &"{nimState.procStr}\n"
- if nimState.debugStr.nBl:
- echo nimState.debugStr
+ if nimState.gState.debug:
+ 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)
diff --git a/nimterop/globals.nim b/nimterop/globals.nim
index 428d927..b108a62 100644
--- a/nimterop/globals.nim
+++ b/nimterop/globals.nim
@@ -65,7 +65,7 @@ type
NimState {.used.} = ref object
identifiers*: TableRef[string, string]
- commentStr*, constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
+ commentStr*, constStr*, debugStr*, enumStr*, procStr*, skipStr*, typeStr*: string
gState*: State
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim
index 2d5cefb..f942422 100644
--- a/nimterop/grammar.nim
+++ b/nimterop/grammar.nim
@@ -31,6 +31,8 @@ proc initGrammar(): Grammar =
nimState.constStr &= &"{nimState.getComments()}\n{override}"
else:
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):
nimState.constStr &= &"{nimState.getComments()}\n {nname}* = {val}"
))
@@ -667,6 +669,8 @@ proc initGrammar(): Grammar =
)
""",
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
+ var
+ done = false
for i in nimState.data:
case $node.tsNodeType()
of "declaration":
@@ -676,6 +680,7 @@ proc initGrammar(): Grammar =
if override.len != 0:
nimState.procStr &= &"{nimState.getComments(true)}\n{override}"
+ done = true
break
else:
nimState.procStr &= &"{nimState.getComments(true)}\n# Declaration '{i.val}' skipped"
@@ -687,9 +692,13 @@ proc initGrammar(): Grammar =
if override.len != 0:
nimState.typeStr &= &"{nimState.getComments()}\n{override}"
+ done = true
+ break
else:
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) =