diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-26 20:18:38 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-26 20:18:38 -0600 |
| commit | e59e34a7be12c7f84099d8b56b038d3c3ab9c15c (patch) | |
| tree | 5272c84122c6ed4f37cf0947ad4ebd815726c6a6 | |
| parent | 373e9decf333ec65c14d7c36a0d1d33e9eb2a803 (diff) | |
| download | nimterop-e59e34a7be12c7f84099d8b56b038d3c3ab9c15c.tar.gz nimterop-e59e34a7be12c7f84099d8b56b038d3c3ab9c15c.zip | |
Array ptr, numeric length, tests
| -rw-r--r-- | nimterop/ast.nim | 4 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 16 | ||||
| -rw-r--r-- | tests/include/test.h | 4 | ||||
| -rw-r--r-- | tests/tnimterop_c.nim | 2 |
4 files changed, 16 insertions, 10 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index ff7dbcb..105d543 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -34,12 +34,12 @@ proc saveNodeData(node: TSNode): bool = let nparent = node.tsNodeParent() - if not nparent.tsNodeIsNull(): + if not nparent.tsNodeIsNull() and node.tsNodePrevNamedSibling().tsNodeIsNull(): let npname = nparent.tsNodeType() npparent = nparent.tsNodeParent() if npname == "pointer_declarator" or - (npname == "function_declarator" and + ($npname in ["function_declarator", "array_declarator"] and not npparent.tsNodeIsNull() and npparent.tsNodeType() == "pointer_declarator"): if gStateRT.data[^1].val != "object": diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index c72e29b..90aff2f 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -34,7 +34,7 @@ proc initGrammar() = (sized_type_specifier? (primitive_type?) ) - (struct_specifier? + (struct_specifier|union_specifier|enum_specifier? (type_identifier) ) (type_identifier?) @@ -87,7 +87,7 @@ proc initGrammar() = let ftyp = gStateRT.data[i].val.getIdentifier() fname = gStateRT.data[i+1].val.getIdentifier() - if i+2 < gStateRT.data.len-fend and gStateRT.data[i+2].name == "identifier": + if i+2 < gStateRT.data.len-fend and gStateRT.data[i+2].name in ["identifier", "number_literal"]: let flen = gStateRT.data[i+2].val.getIdentifier() gStateRT.typeStr &= &" {fname}*: array[{flen}, {ftyp}]\n" @@ -106,7 +106,7 @@ proc initGrammar() = (sized_type_specifier? (primitive_type?) ) - (struct_specifier? + (struct_specifier|union_specifier|enum_specifier? (type_identifier) ) (field_identifier?) @@ -114,12 +114,12 @@ proc initGrammar() = (field_identifier?) (array_declarator? (field_identifier) - (identifier) + (identifier|number_literal) ) ) (array_declarator? (field_identifier) - (identifier) + (identifier|number_literal) ) ) ) @@ -140,7 +140,7 @@ proc initGrammar() = (sized_type_specifier? (primitive_type?) ) - (struct_specifier? + (struct_specifier|union_specifier|enum_specifier? (type_identifier) ) (field_identifier?) @@ -148,12 +148,12 @@ proc initGrammar() = (field_identifier?) (array_declarator? (field_identifier) - (identifier) + (identifier|number_literal) ) ) (array_declarator? (field_identifier) - (identifier) + (identifier|number_literal) ) ) ) diff --git a/tests/include/test.h b/tests/include/test.h index bf4f70d..e040d7f 100644 --- a/tests/include/test.h +++ b/tests/include/test.h @@ -46,6 +46,10 @@ typedef int * INTPTR; typedef struct { int *field; + int field2[TEST_INT]; + enum ENUM field3[TEST_INT]; + int *field4[TEST_INT]; + ENUM4 *field5[TEST_INT]; } STRUCT4; union UNION1 { diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim index 45e94d6..deef7d2 100644 --- a/tests/tnimterop_c.nim +++ b/tests/tnimterop_c.nim @@ -39,6 +39,8 @@ ct = 4 s.field1 = 5 s2.field1 = 6 s3.field1 = 7 +s4.field2[2] = 5 +s4.field3[3] = enum1 e = enum1 e2 = enum4 |
