ast2 fix issue 174 - UncheckedArray
This commit is contained in:
parent
4ccde62d4f
commit
d877b20407
3 changed files with 44 additions and 8 deletions
|
|
@ -460,11 +460,18 @@ proc newPtrTree(nimState: NimState, count: int, typ: PNode): PNode =
|
|||
parent.add result
|
||||
result = nresult
|
||||
|
||||
proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode): PNode =
|
||||
proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode = nil): PNode =
|
||||
# Create nkBracketExpr tree depending on input
|
||||
#
|
||||
# If `size` is nil, create UncheckedArray[typ]
|
||||
let
|
||||
info = nimState.getLineInfo(node.getAtom())
|
||||
ident = nimState.getIdent("array", info, exported = false)
|
||||
tname =
|
||||
if size.isNil:
|
||||
"UncheckedArray"
|
||||
else:
|
||||
"array"
|
||||
ident = nimState.getIdent(tname, info, exported = false)
|
||||
|
||||
# array[size, typ]
|
||||
#
|
||||
|
|
@ -475,7 +482,8 @@ proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode): PNode =
|
|||
# )
|
||||
result = newNode(nkBracketExpr)
|
||||
result.add ident
|
||||
result.add size
|
||||
if not size.isNil:
|
||||
result.add size
|
||||
result.add typ
|
||||
|
||||
proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
|
||||
|
|
@ -906,11 +914,17 @@ proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
|
|||
result = nimState.newPtrTree(tcount, result)
|
||||
|
||||
for i in 0 ..< acount:
|
||||
let
|
||||
# Size of array could be a Nim expression
|
||||
size = nimState.getLit(nimState.getNodeVal(cnode[1]), expression = true)
|
||||
if size.kind != nkNilLit:
|
||||
result = nimState.newArrayTree(cnode, result, size)
|
||||
if cnode.len == 2:
|
||||
# type name[X] => array[X, type]
|
||||
let
|
||||
# Size of array could be a Nim expression
|
||||
size = nimState.getLit(nimState.getNodeVal(cnode[1]), expression = true)
|
||||
if size.kind != nkNilLit:
|
||||
result = nimState.newArrayTree(cnode, result, size)
|
||||
cnode = cnode[0]
|
||||
elif cnode.len == 1:
|
||||
# type name[] = UncheckedArray[type]
|
||||
result = nimState.newArrayTree(cnode, result)
|
||||
cnode = cnode[0]
|
||||
|
||||
if ncount > 0:
|
||||
|
|
|
|||
|
|
@ -133,6 +133,16 @@ void
|
|||
|
||||
int sqlite3_bind_blob(struct A1*, int, const void*, int n, void(*)(void*));
|
||||
|
||||
// Issue #174 - type name[] => UncheckedArray[type]
|
||||
int ucArrFunc1(int text[]);
|
||||
int ucArrFunc2(int text[][5], int (*func)(int text[]));
|
||||
|
||||
typedef int ucArrType1[][5];
|
||||
struct ucArrType2 {
|
||||
float f1[5][5];
|
||||
int *f2[][5];
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -335,3 +335,15 @@ assert absfunptr5 is proc(a1: proc(a1: ptr A4): cint {.cdecl.}) {.cdecl.}
|
|||
|
||||
assert sqlite3_bind_blob is
|
||||
proc(a1: ptr A1, a2: cint, a3: pointer, n: cint, a5: proc(a1: pointer) {.cdecl.}): cint {.cdecl.}
|
||||
|
||||
# Issue #174 - type name[] => UncheckedArray[type]
|
||||
assert ucArrFunc1 is proc(text: UncheckedArray[cint]): cint {.cdecl.}
|
||||
assert ucArrFunc2 is
|
||||
proc(text: UncheckedArray[array[5, cint]], `func`: proc(text: UncheckedArray[cint]): cint {.cdecl.}): cint {.cdecl.}
|
||||
|
||||
assert ucArrType1 is UncheckedArray[array[5, cint]]
|
||||
checkPragmas(ucArrType1, pHeaderImp)
|
||||
|
||||
assert ucArrType2 is object
|
||||
testFields(ucArrType2, "f1|f2:array[5, array[5, cfloat]]|UncheckedArray[array[5, ptr cint]]")
|
||||
checkPragmas(ucArrType2, pHeaderBy, istype = false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue