diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-04-05 12:14:27 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-04-05 12:14:27 -0500 |
| commit | 9a90495a1e4350ba9f3153fee9d18ebfca597fa1 (patch) | |
| tree | 64e8c9b97b910183d2ddd0f1337ed85d1a680ae3 | |
| parent | cc1cbb459c0e725a038df449ff265c484b4086c0 (diff) | |
| download | nimterop-9a90495a1e4350ba9f3153fee9d18ebfca597fa1.tar.gz nimterop-9a90495a1e4350ba9f3153fee9d18ebfca597fa1.zip | |
Handle struct pointer first field, additional debugging
| -rw-r--r-- | nimterop/ast.nim | 6 | ||||
| -rw-r--r-- | nimterop/globals.nim | 2 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 33 | ||||
| -rw-r--r-- | tests/include/test.h | 1 |
4 files changed, 38 insertions, 4 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index dc0ac3c..0d96dfd 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -108,7 +108,7 @@ proc searchAst(root: TSNode, astTable: AstTable, nimState: NimState) = if searchAstForNode(ast, node, nimState): ast.tonim(ast, node, nimState) if gStateRT.debug: - nimState.debugStr &= "\n# " & nimState.data.join("\n# ") + nimState.debugStr &= "\n# " & nimState.data.join("\n# ") & "\n" break nimState.data = @[] else: @@ -157,6 +157,8 @@ proc printNim*(fullpath: string, root: TSNode, astTable: AstTable) = nimState.currentHeader = getCurrentHeader(fullpath) nimState.constStr &= &"\n {nimState.currentHeader} {{.used.}} = \"{fp}\"" + nimState.debug = gStateRT.debug + root.searchAst(astTable, nimState) if nimState.enumStr.nBl: @@ -171,5 +173,5 @@ proc printNim*(fullpath: string, root: TSNode, astTable: AstTable) = if nimState.procStr.nBl: echo &"{nimState.procStr}\n" - if gStateRT.debug and nimState.debugStr.nBl: + if nimState.debugStr.nBl: echo nimState.debugStr
\ No newline at end of file diff --git a/nimterop/globals.nim b/nimterop/globals.nim index bdb29dc..f866e71 100644 --- a/nimterop/globals.nim +++ b/nimterop/globals.nim @@ -63,6 +63,8 @@ type constStr*, debugStr*, enumStr*, procStr*, typeStr*: string + debug*: bool + currentHeader*: string data*: seq[tuple[name, val: string]] diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index 8cd3275..e83c2a1 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -21,6 +21,9 @@ proc initGrammar(): Grammar = ) """, proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# define X Y" + let val = nimState.data[1].val.getLit() @@ -128,6 +131,9 @@ proc initGrammar(): Grammar = ) """, proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# typedef X Y" + var i = 0 typ = nimState.data[i].val.getIdentifier(nskType) @@ -184,8 +190,10 @@ proc initGrammar(): Grammar = nimState.typeStr &= &"\n {name}* = {getPtrType(tptr&typ)}" )) - proc pDupTypeCommon(nname: string, fend: int, nimState: NimState, isEnum=false) = + if nimState.debug: + nimState.debugStr &= "\n# pDupTypeCommon()" + var dname = nimState.data[^1].val ndname = nimState.data[^1].val.getIdentifier(nskType) @@ -205,6 +213,9 @@ proc initGrammar(): Grammar = &"\n {ndname}* {{.{genImportC(dname, ndname)}, header: {nimState.currentHeader}, bycopy.}} = {dptr}{nname}" proc pStructCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# pStructCommon" + var nname = name.getIdentifier(nskType) prefix = "" @@ -352,6 +363,9 @@ proc initGrammar(): Grammar = ) """, proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# struct X {}" + pStructCommon(ast, node, nimState.data[0].val, 1, 1, nimState) )) @@ -372,6 +386,9 @@ proc initGrammar(): Grammar = ) """, proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# typedef struct X {}" + var fstart = 0 fend = 1 @@ -381,7 +398,7 @@ proc initGrammar(): Grammar = if nimState.data.len > 1 and nimState.data[0].name == "type_identifier" and - nimState.data[1].name != "field_identifier": + nimState.data[1].name notin ["field_identifier", "pointer_declarator"]: fstart = 1 pStructCommon(ast, node, nimState.data[0].val, fstart, fend, nimState) @@ -390,6 +407,9 @@ proc initGrammar(): Grammar = )) proc pEnumCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# pEnumCommon()" + let nname = if name.len == 0: getUniqueIdentifier(nimState.identifiers, "Enum") @@ -442,6 +462,9 @@ proc initGrammar(): Grammar = ) """ % gEnumVals.join("|"), proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# enum X {}" + var name = "" offset = 0 @@ -467,6 +490,9 @@ proc initGrammar(): Grammar = ) """, proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# typedef enum {}" + var fstart = 0 fend = 1 @@ -497,6 +523,9 @@ proc initGrammar(): Grammar = ) """, proc (ast: ref Ast, node: TSNode, nimState: NimState) = + if nimState.debug: + nimState.debugStr &= "\n# typ function" + var fptr = "" i = 1 diff --git a/tests/include/test.h b/tests/include/test.h index 9dba8ba..eb36650 100644 --- a/tests/include/test.h +++ b/tests/include/test.h @@ -74,6 +74,7 @@ typedef void * VOIDPTR; typedef int * INTPTR; typedef struct { + struct STRUCT1 *field0; int *field; int field2[TEST_INT]; enum ENUM field3[TEST_INT]; |
