Fix #53 - array size expressions
This commit is contained in:
parent
a8028a62ec
commit
f9d0514ad4
3 changed files with 14 additions and 13 deletions
|
|
@ -294,3 +294,11 @@ proc getPxName*(node: TSNode, offset: int): string =
|
|||
|
||||
if count == offset and not np.tsNodeIsNull():
|
||||
return $np.tsNodeType()
|
||||
|
||||
proc getNimExpression*(expr: string): string =
|
||||
return expr.multiReplace([
|
||||
(" ", ""),
|
||||
("<<", " shl "), (">>", " shr "),
|
||||
("^", " xor "), ("&", " and "), ("|", " or "),
|
||||
("~", " not ")
|
||||
])
|
||||
|
|
|
|||
|
|
@ -213,9 +213,9 @@ proc initGrammar() =
|
|||
i += 1
|
||||
|
||||
fname = gStateRT.data[i].val.getIdentifier()
|
||||
if i+1 < gStateRT.data.len-fend and gStateRT.data[i+1].name in ["identifier", "number_literal"]:
|
||||
if i+1 < gStateRT.data.len-fend and gStateRT.data[i+1].name in gEnumVals:
|
||||
let
|
||||
flen = gStateRT.data[i+1].val.getIdentifier()
|
||||
flen = gStateRT.data[i+1].val.getNimExpression()
|
||||
gStateRT.typeStr &= &" {fname}*: {aptr}array[{flen}, {getPtrType(fptr&ftyp)}]\n"
|
||||
i += 2
|
||||
elif i+1 < gStateRT.data.len-fend and gStateRT.data[i+1].name == "function_declarator":
|
||||
|
|
@ -265,7 +265,7 @@ proc initGrammar() =
|
|||
(pointer_declarator
|
||||
(field_identifier)
|
||||
)
|
||||
(identifier|number_literal)
|
||||
(^$1+)
|
||||
)
|
||||
(function_declarator+
|
||||
(pointer_declarator
|
||||
|
|
@ -273,7 +273,7 @@ proc initGrammar() =
|
|||
)
|
||||
{paramListGrammar}
|
||||
)
|
||||
"""
|
||||
""" % gEnumVals.join("|")
|
||||
|
||||
fieldListGrammar = &"""
|
||||
(field_declaration_list?
|
||||
|
|
@ -347,14 +347,7 @@ proc initGrammar() =
|
|||
if gStateRT.consts.addNewIdentifer(fname):
|
||||
if i+1 < gStateRT.data.len-fend and
|
||||
gStateRT.data[i+1].name in gEnumVals:
|
||||
gStateRT.data[i+1].val = gStateRT.data[i+1].val.multiReplace([
|
||||
(" ", ""),
|
||||
("<<", " shl "), (">>", " shr "),
|
||||
("^", " xor "), ("&", " and "), ("|", " or "),
|
||||
("~", " not ")
|
||||
])
|
||||
|
||||
gStateRT.constStr &= &" {fname}* = ({gStateRT.data[i+1].val}).{nname}\n"
|
||||
gStateRT.constStr &= &" {fname}* = ({gStateRT.data[i+1].val.getNimExpression()}).{nname}\n"
|
||||
try:
|
||||
count = gStateRT.data[i+1].val.parseInt() + 1
|
||||
except:
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ typedef struct {
|
|||
int field2[TEST_INT];
|
||||
enum ENUM field3[TEST_INT];
|
||||
int *field4[TEST_INT];
|
||||
ENUM4 *field5[TEST_INT];
|
||||
ENUM4 *field5[TEST_INT+TEST_INT];
|
||||
} STRUCT4;
|
||||
|
||||
typedef struct struct5 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue