typedef arrays, debug output
This commit is contained in:
parent
11c896f82e
commit
da06be80d1
4 changed files with 40 additions and 9 deletions
|
|
@ -99,6 +99,8 @@ proc searchAst(root: TSNode) =
|
|||
for ast in gStateRT.ast[name]:
|
||||
if searchAstForNode(ast, node):
|
||||
ast.tonim(ast, node)
|
||||
if gStateRT.debug:
|
||||
gStateRT.debugStr &= "\n\n# " & gStateRT.data.join("\n# ")
|
||||
break
|
||||
gStateRT.data = @[]
|
||||
else:
|
||||
|
|
@ -145,3 +147,6 @@ proc printNim*(fullpath: string, root: TSNode) =
|
|||
|
||||
if gStateRT.procStr.nBl:
|
||||
echo gStateRT.procStr
|
||||
|
||||
if gStateRT.debug and gStateRT.debugStr.nBl:
|
||||
echo gStateRT.debugStr
|
||||
|
|
@ -26,7 +26,7 @@ type
|
|||
|
||||
consts*, enums*, procs*, types*: seq[string]
|
||||
|
||||
code*, constStr*, currentHeader*, enumStr*, mode*, procStr*, typeStr*: string
|
||||
code*, constStr*, currentHeader*, debugStr*, enumStr*, mode*, procStr*, typeStr*: string
|
||||
sourceFile*: string # eg, C or C++ source or header file
|
||||
|
||||
ast*: Table[string, seq[ref Ast]]
|
||||
|
|
|
|||
|
|
@ -59,6 +59,16 @@ proc initGrammar() =
|
|||
)
|
||||
"""
|
||||
|
||||
arrGrammar = &"""
|
||||
(array_declarator!
|
||||
(pointer_declarator!
|
||||
(type_identifier)
|
||||
)
|
||||
(type_identifier)
|
||||
(identifier|number_literal)
|
||||
)
|
||||
"""
|
||||
|
||||
template funcParamCommon(pname, ptyp, pptr, pout, count, i: untyped): untyped =
|
||||
ptyp = gStateRT.data[i].val.getIdentifier()
|
||||
if i+1 < gStateRT.data.len and gStateRT.data[i+1].name == "pointer_declarator":
|
||||
|
|
@ -84,9 +94,11 @@ proc initGrammar() =
|
|||
gStateRT.grammar.add((&"""
|
||||
(type_definition
|
||||
{typeGrammar}
|
||||
(type_identifier?)
|
||||
(pointer_declarator?
|
||||
(type_identifier!)
|
||||
{arrGrammar}
|
||||
(pointer_declarator!
|
||||
(type_identifier!)
|
||||
{arrGrammar}
|
||||
{funcGrammar}
|
||||
)
|
||||
{funcGrammar}
|
||||
|
|
@ -98,12 +110,17 @@ proc initGrammar() =
|
|||
typ = gStateRT.data[i].val.getIdentifier()
|
||||
name = ""
|
||||
tptr = ""
|
||||
aptr = ""
|
||||
|
||||
i += 1
|
||||
if i < gStateRT.data.len:
|
||||
if gStateRT.data[i].name == "pointer_declarator":
|
||||
tptr = "ptr "
|
||||
i += 1
|
||||
case gStateRT.data[i].name:
|
||||
of "pointer_declarator":
|
||||
tptr = "ptr "
|
||||
i += 1
|
||||
of "array_pointer_declarator":
|
||||
aptr = "ptr "
|
||||
i += 1
|
||||
|
||||
if i < gStateRT.data.len:
|
||||
name = gStateRT.data[i].val.getIdentifier()
|
||||
|
|
@ -129,10 +146,15 @@ proc initGrammar() =
|
|||
gStateRT.typeStr &= &" {name}* = proc({pout}) {{.nimcall.}}\n"
|
||||
else:
|
||||
gStateRT.types.add(name)
|
||||
if name == typ or typ == "object":
|
||||
gStateRT.typeStr &= &" {name}* = object\n"
|
||||
if i < gStateRT.data.len and gStateRT.data[i].name in ["identifier", "number_literal"]:
|
||||
let
|
||||
flen = gStateRT.data[i].val.getIdentifier()
|
||||
gStateRT.typeStr &= &" {name}*: = {aptr}array[{flen}, {tptr}{typ}]\n"
|
||||
else:
|
||||
gStateRT.typeStr &= &" {name}* = {tptr}{typ}\n"
|
||||
if name == typ or typ == "object":
|
||||
gStateRT.typeStr &= &" {name}* = object\n"
|
||||
else:
|
||||
gStateRT.typeStr &= &" {name}* = {tptr}{typ}\n"
|
||||
))
|
||||
|
||||
proc pStructCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int) =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue