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):
|
if searchAstForNode(ast, node, nimState):
|
||||||
ast.tonim(ast, node, nimState)
|
ast.tonim(ast, node, nimState)
|
||||||
if gStateRT.debug:
|
if gStateRT.debug:
|
||||||
nimState.debugStr &= "\n# " & nimState.data.join("\n# ")
|
nimState.debugStr &= "\n# " & nimState.data.join("\n# ") & "\n"
|
||||||
break
|
break
|
||||||
nimState.data = @[]
|
nimState.data = @[]
|
||||||
else:
|
else:
|
||||||
|
|
@ -157,6 +157,8 @@ proc printNim*(fullpath: string, root: TSNode, astTable: AstTable) =
|
||||||
nimState.currentHeader = getCurrentHeader(fullpath)
|
nimState.currentHeader = getCurrentHeader(fullpath)
|
||||||
nimState.constStr &= &"\n {nimState.currentHeader} {{.used.}} = \"{fp}\""
|
nimState.constStr &= &"\n {nimState.currentHeader} {{.used.}} = \"{fp}\""
|
||||||
|
|
||||||
|
nimState.debug = gStateRT.debug
|
||||||
|
|
||||||
root.searchAst(astTable, nimState)
|
root.searchAst(astTable, nimState)
|
||||||
|
|
||||||
if nimState.enumStr.nBl:
|
if nimState.enumStr.nBl:
|
||||||
|
|
@ -171,5 +173,5 @@ proc printNim*(fullpath: string, root: TSNode, astTable: AstTable) =
|
||||||
if nimState.procStr.nBl:
|
if nimState.procStr.nBl:
|
||||||
echo &"{nimState.procStr}\n"
|
echo &"{nimState.procStr}\n"
|
||||||
|
|
||||||
if gStateRT.debug and nimState.debugStr.nBl:
|
if nimState.debugStr.nBl:
|
||||||
echo nimState.debugStr
|
echo nimState.debugStr
|
||||||
|
|
@ -63,6 +63,8 @@ type
|
||||||
|
|
||||||
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
|
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
|
||||||
|
|
||||||
|
debug*: bool
|
||||||
|
|
||||||
currentHeader*: string
|
currentHeader*: string
|
||||||
|
|
||||||
data*: seq[tuple[name, val: string]]
|
data*: seq[tuple[name, val: string]]
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# define X Y"
|
||||||
|
|
||||||
let
|
let
|
||||||
val = nimState.data[1].val.getLit()
|
val = nimState.data[1].val.getLit()
|
||||||
|
|
||||||
|
|
@ -128,6 +131,9 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# typedef X Y"
|
||||||
|
|
||||||
var
|
var
|
||||||
i = 0
|
i = 0
|
||||||
typ = nimState.data[i].val.getIdentifier(nskType)
|
typ = nimState.data[i].val.getIdentifier(nskType)
|
||||||
|
|
@ -184,8 +190,10 @@ proc initGrammar(): Grammar =
|
||||||
nimState.typeStr &= &"\n {name}* = {getPtrType(tptr&typ)}"
|
nimState.typeStr &= &"\n {name}* = {getPtrType(tptr&typ)}"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
proc pDupTypeCommon(nname: string, fend: int, nimState: NimState, isEnum=false) =
|
proc pDupTypeCommon(nname: string, fend: int, nimState: NimState, isEnum=false) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# pDupTypeCommon()"
|
||||||
|
|
||||||
var
|
var
|
||||||
dname = nimState.data[^1].val
|
dname = nimState.data[^1].val
|
||||||
ndname = nimState.data[^1].val.getIdentifier(nskType)
|
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}"
|
&"\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) =
|
proc pStructCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# pStructCommon"
|
||||||
|
|
||||||
var
|
var
|
||||||
nname = name.getIdentifier(nskType)
|
nname = name.getIdentifier(nskType)
|
||||||
prefix = ""
|
prefix = ""
|
||||||
|
|
@ -352,6 +363,9 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
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)
|
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) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# typedef struct X {}"
|
||||||
|
|
||||||
var
|
var
|
||||||
fstart = 0
|
fstart = 0
|
||||||
fend = 1
|
fend = 1
|
||||||
|
|
@ -381,7 +398,7 @@ proc initGrammar(): Grammar =
|
||||||
|
|
||||||
if nimState.data.len > 1 and
|
if nimState.data.len > 1 and
|
||||||
nimState.data[0].name == "type_identifier" 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
|
fstart = 1
|
||||||
pStructCommon(ast, node, nimState.data[0].val, fstart, fend, nimState)
|
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) =
|
proc pEnumCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# pEnumCommon()"
|
||||||
|
|
||||||
let nname =
|
let nname =
|
||||||
if name.len == 0:
|
if name.len == 0:
|
||||||
getUniqueIdentifier(nimState.identifiers, "Enum")
|
getUniqueIdentifier(nimState.identifiers, "Enum")
|
||||||
|
|
@ -442,6 +462,9 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
""" % gEnumVals.join("|"),
|
""" % gEnumVals.join("|"),
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# enum X {}"
|
||||||
|
|
||||||
var
|
var
|
||||||
name = ""
|
name = ""
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
@ -467,6 +490,9 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# typedef enum {}"
|
||||||
|
|
||||||
var
|
var
|
||||||
fstart = 0
|
fstart = 0
|
||||||
fend = 1
|
fend = 1
|
||||||
|
|
@ -497,6 +523,9 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
|
if nimState.debug:
|
||||||
|
nimState.debugStr &= "\n# typ function"
|
||||||
|
|
||||||
var
|
var
|
||||||
fptr = ""
|
fptr = ""
|
||||||
i = 1
|
i = 1
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ typedef void * VOIDPTR;
|
||||||
typedef int * INTPTR;
|
typedef int * INTPTR;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
struct STRUCT1 *field0;
|
||||||
int *field;
|
int *field;
|
||||||
int field2[TEST_INT];
|
int field2[TEST_INT];
|
||||||
enum ENUM field3[TEST_INT];
|
enum ENUM field3[TEST_INT];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue