diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2020-04-14 22:47:33 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2020-04-14 22:47:33 -0500 |
| commit | 25b07a07fff0c15ddae2610016289368fe41f3e2 (patch) | |
| tree | 0b4f73bd8efa034b2710cb88921d61c3bcf92ba9 | |
| parent | 92fe90f834b1afc1098d4ed63760ca811ab48484 (diff) | |
| download | nimterop-25b07a07fff0c15ddae2610016289368fe41f3e2.tar.gz nimterop-25b07a07fff0c15ddae2610016289368fe41f3e2.zip | |
ast2 nested array field
| -rw-r--r-- | nimterop/ast2.nim | 23 | ||||
| -rw-r--r-- | tests/include/tast2.h | 46 | ||||
| -rw-r--r-- | tests/tast2.nim | 49 |
3 files changed, 105 insertions, 13 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim index 8dba84a..5bb33ae 100644 --- a/nimterop/ast2.nim +++ b/nimterop/ast2.nim @@ -73,7 +73,7 @@ proc getOverrideOrSkip(nimState: NimState, node: TSNode, origname: string, kind: # If not, symbol needs to be skipped - only get here if `name` is blank let # Get cleaned name for symbol, set parent so that cOverride is ignored - name = nimState.getIdentifier(origname, kind, parent = "override") + name = nimState.getIdentifier(origname, kind, parent = "getOverrideOrSkip") override = nimState.getOverride(origname, kind) @@ -492,7 +492,7 @@ proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode = nil): PNo result.add size result.add typ -proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode +proc getTypeArray(nimState: NimState, node: TSNode, tident: PNode, name: string): PNode proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode iterator newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, ftname = "", exported = false): PNode = @@ -637,7 +637,7 @@ iterator newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: So (pname, _, pinfo) = nimState.getNameInfo(node[i].getAtom(), nskField, parent = name) pident = nimState.getIdent(pname, pinfo, exported) result.add pident - result.add nimState.getTypeArray(node[i], node[start], name) + result.add nimState.getTypeArray(node[i], tident, name) result.add newNode(nkEmpty) else: result = nil @@ -958,13 +958,11 @@ proc addTypeTyped(nimState: NimState, node: TSNode, ftname = "", offset = 0) = else: nimState.addTypeObject(node, typeDef = typeDef, istype = true) -proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode = +proc getTypeArray(nimState: NimState, node: TSNode, tident: PNode, name: string): PNode = # Create array type tree + # + # `tident` is type PNode let - # tnode = identifier = type name - (tname, _, info) = nimState.getNameInfo(tnode.getAtom(), nskType, parent = name) - ident = nimState.getIdent(tname, info, exported = false) - # Top-most array declarator adecl = node.firstChildInTree("array_declarator") @@ -990,7 +988,7 @@ proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode # ) ncount = innermost[0].getAtom().tsNodeParent().getPtrCount(reverse = true) - result = ident + result = tident var cnode = adecl @@ -1021,8 +1019,9 @@ proc addTypeArray(nimState: NimState, node: TSNode) = let start = getStartAtom(node) - # node[start] = type name - tnode = node[start] + # node[start] = identifier = type name + (tname, _, info) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = "addTypeArray") + tident = nimState.getIdent(tname, info, exported = false) # Could have multiple types, comma separated for i in start+1 ..< node.len: @@ -1033,7 +1032,7 @@ proc addTypeArray(nimState: NimState, node: TSNode) = if not typeDef.isNil: let name = typeDef.getIdentName() - typ = nimState.getTypeArray(node[i], tnode, name) + typ = nimState.getTypeArray(node[i], tident, name) typeDef.add typ diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 136784a..fe78146 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -175,6 +175,29 @@ typedef struct { const char* const* x; } SomeType; +// Nested #137 +typedef struct { + struct NT1 { int f1; } f1; + struct { int f1; } f2; + + struct NT3 { + struct { + int f1; + union NU1 { + float f1; + } f2; + enum { NEV1, NEV2, NEV3 } f3; + } f1; + } f3; + + struct { int f1; } f4; + + union NU2 { int f1; } f5; + union { int f1; } f6; + enum NE1 { NEV4 = 8, NEV5 } f7; + enum { NEV6 = 8 * 8, NEV7 } f8; +} nested; + // DUPLICATES @@ -344,6 +367,29 @@ typedef struct { const char* const* x; } SomeType; +// Nested #137 +typedef struct { + struct NT1 { int f1; } f1; + struct { int f1; } f2; + + struct NT3 { + struct { + int f1; + union NU1 { + float f1; + } f2; + enum { NEV1, NEV2, NEV3 } f3; + } f1; + } f3; + + struct { int f1; } f4; + + union NU2 { int f1; } f5; + union { int f1; } f6; + enum NE1 { NEV4 = 8, NEV5 } f7; + enum { NEV6 = 8 * 8, NEV7 } f8; +} nested; + #endif diff --git a/tests/tast2.nim b/tests/tast2.nim index 6d749c6..46101d5 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -372,4 +372,51 @@ checkPragmas(AudioCVT, pHeaderBy, istype = false, "SDL_") # Issue #172 assert SomeType is object testFields(SomeType, "x!ptr cstring") -checkPragmas(SomeType, pHeaderImpBy)
\ No newline at end of file +checkPragmas(SomeType, pHeaderImpBy) + +# Nested #137 +assert NT1 is object +testFields(NT1, "f1!cint") +checkPragmas(NT1, pHeaderBy, istype = false) + +assert Type_tast2h1 is object +testFields(Type_tast2h1, "f1!cint") +checkPragmas(Type_tast2h1, pHeaderBy, istype = false) + +assert NU1 is object +testFields(NU1, "f1!cfloat") +checkPragmas(NU1, pHeaderBy & @["union"], istype = false) + +assert NEV1 == 0 +assert NEV2 == 1 +assert NEV3 == 2 + +assert Type_tast2h2 is object +testFields(Type_tast2h2, "f1|f2|f3!cint|NU1|Enum_tast2h1") +checkPragmas(Type_tast2h2, pHeaderBy, istype = false) + +assert NT3 is object +testFields(NT3, "f1!Type_tast2h2") +checkPragmas(NT3, pHeaderBy, istype = false) + +assert Type_tast2h3 is object +testFields(Type_tast2h3, "f1!cint") +checkPragmas(Type_tast2h3, pHeaderBy, istype = false) + +assert NU2 is object +testFields(NU2, "f1!cint") +checkPragmas(NU2, pHeaderBy & @["union"], istype = false) + +assert Union_tast2h1 is object +testFields(Union_tast2h1, "f1!cint") +checkPragmas(Union_tast2h1, pHeaderBy & @["union"], istype = false) + +assert NEV4 == 8 +assert NEV5 == 9 + +assert NEV6 == 64 +assert NEV7 == 65 + +assert nested is object +testFields(nested, "f1|f2|f3|f4|f5|f6|f7|f8!NT1|Type_tast2h1|NT3|Type_tast2h3|NU2|Union_tast2h1|NE1|Enum_tast2h2") +checkPragmas(nested, pHeaderImpBy)
\ No newline at end of file |
