Support for unsigned, function params with pointers
This commit is contained in:
parent
33956c36ee
commit
ba8c57984b
3 changed files with 44 additions and 6 deletions
|
|
@ -12,6 +12,7 @@ const gAtoms = @[
|
|||
"number_literal",
|
||||
"preproc_arg",
|
||||
"primitive_type",
|
||||
"sized_type_specifier",
|
||||
"type_identifier"
|
||||
]
|
||||
|
||||
|
|
@ -21,7 +22,10 @@ proc saveNodeData(node: TSNode): bool =
|
|||
var
|
||||
val = node.getNodeVal()
|
||||
|
||||
if name == "primitive_type":
|
||||
if name == "primitive_type" and node.tsNodeParent.tsNodeType() == "sized_type_specifier":
|
||||
return true
|
||||
|
||||
if name in ["primitive_type", "sized_type_specifier"]:
|
||||
val = val.getType()
|
||||
|
||||
if node.tsNodeParent().tsNodeType() == "pointer_declarator":
|
||||
|
|
@ -36,6 +40,8 @@ proc searchAstForNode(ast: ref Ast, node: TSNode): bool =
|
|||
let
|
||||
childNames = node.getTSNodeNamedChildNames().join()
|
||||
|
||||
if ast.isNil:
|
||||
return
|
||||
if ast.children.len != 0:
|
||||
let
|
||||
rstr = ast.getRegexForAstChildren()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,12 @@ proc getIdentifier*(str: string): string =
|
|||
result = str.strip(chars={'_'})
|
||||
|
||||
proc getType*(str: string): string =
|
||||
result = str.strip(chars={'_'}).replace(re"([u]?int[\d]+)_t", "$1").replace(re"^void$", "object")
|
||||
if str == "void":
|
||||
return "object"
|
||||
|
||||
result = str.strip(chars={'_'}).
|
||||
replace("unsigned ", "u").
|
||||
replace(re"([u]?int[\d]+)_t", "$1")
|
||||
|
||||
proc getLit*(str: string): string =
|
||||
if str.contains(re"^[\-]?[\d]+$") or
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ proc initGrammar() =
|
|||
name = gStateRT.data[0].val.getIdentifier()
|
||||
val = gStateRT.data[1].val
|
||||
|
||||
if name notin gStateRT.consts:
|
||||
if name notin gStateRT.consts and val.nBl:
|
||||
gStateRT.consts.add(name)
|
||||
gStateRT.constStr &= &" {name}* = {val}\n"
|
||||
))
|
||||
|
|
@ -27,6 +27,9 @@ proc initGrammar() =
|
|||
gStateRT.grammar.add(("""
|
||||
(type_definition
|
||||
(primitive_type|type_identifier?)
|
||||
(sized_type_specifier?
|
||||
(primitive_type)
|
||||
)
|
||||
(struct_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
|
|
@ -66,6 +69,9 @@ proc initGrammar() =
|
|||
(field_declaration_list
|
||||
(field_declaration+
|
||||
(primitive_type|type_identifier?)
|
||||
(sized_type_specifier?
|
||||
(primitive_type)
|
||||
)
|
||||
(struct_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
|
|
@ -88,6 +94,9 @@ proc initGrammar() =
|
|||
(field_declaration_list
|
||||
(field_declaration+
|
||||
(primitive_type|type_identifier?)
|
||||
(sized_type_specifier?
|
||||
(primitive_type)
|
||||
)
|
||||
(struct_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
|
|
@ -163,6 +172,9 @@ proc initGrammar() =
|
|||
gStateRT.grammar.add(("""
|
||||
(declaration
|
||||
(primitive_type|type_identifier?)
|
||||
(sized_type_specifier?
|
||||
(primitive_type)
|
||||
)
|
||||
(struct_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
|
|
@ -171,13 +183,19 @@ proc initGrammar() =
|
|||
(parameter_list
|
||||
(parameter_declaration*
|
||||
(primitive_type|type_identifier?)
|
||||
(sized_type_specifier?
|
||||
(primitive_type)
|
||||
)
|
||||
(struct_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
(enum_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
(identifier)
|
||||
(identifier?)
|
||||
(pointer_declarator?
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -187,13 +205,19 @@ proc initGrammar() =
|
|||
(parameter_list
|
||||
(parameter_declaration*
|
||||
(primitive_type|type_identifier?)
|
||||
(sized_type_specifier?
|
||||
(primitive_type)
|
||||
)
|
||||
(struct_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
(enum_specifier?
|
||||
(type_identifier)
|
||||
)
|
||||
(identifier)
|
||||
(identifier?)
|
||||
(pointer_declarator?
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -220,7 +244,10 @@ proc initGrammar() =
|
|||
if pout.len != 0 and pout[^1] == ',':
|
||||
pout = pout[0 .. ^2]
|
||||
|
||||
gStateRT.procStr &= &"proc {fnname}({pout}): {ftyp} {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
||||
if ftyp != "object":
|
||||
gStateRT.procStr &= &"proc {fnname}({pout}): {ftyp} {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
||||
else:
|
||||
gStateRT.procStr &= &"proc {fnname}({pout}) {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
||||
|
||||
))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue