Handle struct pointer first field, additional debugging
This commit is contained in:
parent
cc1cbb459c
commit
9a90495a1e
4 changed files with 38 additions and 4 deletions
|
|
@ -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
|
||||
|
|
@ -63,6 +63,8 @@ type
|
|||
|
||||
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
|
||||
|
||||
debug*: bool
|
||||
|
||||
currentHeader*: string
|
||||
|
||||
data*: seq[tuple[name, val: string]]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue