ast2 multiple array type block
This commit is contained in:
parent
534acf9259
commit
e911a9ee92
3 changed files with 100 additions and 49 deletions
|
|
@ -465,7 +465,7 @@ proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode): PNode =
|
|||
result.add size
|
||||
result.add typ
|
||||
|
||||
proc getTypeArray(nimState: NimState, node: TSNode, name: string): PNode
|
||||
proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
|
||||
proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode
|
||||
|
||||
proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, exported = false): PNode =
|
||||
|
|
@ -562,7 +562,7 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
|||
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
||||
pident = nimState.getIdent(pname, pinfo, exported)
|
||||
result.add pident
|
||||
result.add nimState.getTypeProc(name, node[1], rnode = node[0])
|
||||
result.add nimState.getTypeProc(name, node[start+1], node[start])
|
||||
result.add newNode(nkEmpty)
|
||||
elif not adecl.isNil:
|
||||
# Named param, array type
|
||||
|
|
@ -570,7 +570,7 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
|||
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
||||
pident = nimState.getIdent(pname, pinfo, exported)
|
||||
result.add pident
|
||||
result.add nimState.getTypeArray(node, name)
|
||||
result.add nimState.getTypeArray(node[start+1], node[start], name)
|
||||
result.add newNode(nkEmpty)
|
||||
else:
|
||||
result = nil
|
||||
|
|
@ -838,24 +838,22 @@ proc addTypeTyped(nimState: NimState, node: TSNode, ftname = "", offset = 0) =
|
|||
else:
|
||||
nimState.addTypeObject(node, typeDef = typeDef, istype = true)
|
||||
|
||||
proc getTypeArray(nimState: NimState, node: TSNode, name: string): PNode =
|
||||
proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode =
|
||||
# Create array type tree
|
||||
let
|
||||
start = getStartAtom(node)
|
||||
|
||||
# node[start] = identifier = type name
|
||||
(tname, _, info) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name)
|
||||
# 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[start+1].firstChildInTree("array_declarator")
|
||||
adecl = node.firstChildInTree("array_declarator")
|
||||
|
||||
# node[start+1] could have nested arrays
|
||||
# node could have nested arrays
|
||||
acount = adecl.getArrayCount()
|
||||
innermost = adecl.mostNestedChildInTree()
|
||||
|
||||
# node[start+1] could have nested pointers - type
|
||||
tcount = node[start+1].getPtrCount()
|
||||
# node could have nested pointers - type
|
||||
tcount = node.getPtrCount()
|
||||
|
||||
# Name could be nested pointer to array
|
||||
#
|
||||
|
|
@ -894,39 +892,47 @@ proc addTypeArray(nimState: NimState, node: TSNode) =
|
|||
# Add a type of array type
|
||||
decho("addTypeArray()")
|
||||
let
|
||||
# node[1] = identifer = name
|
||||
typeDef = nimState.newXIdent(node[1], istype = true)
|
||||
start = getStartAtom(node)
|
||||
|
||||
if not typeDef.isNil:
|
||||
# node[start] = type name
|
||||
tnode = node[start]
|
||||
|
||||
# Could have multiple types, comma separated
|
||||
for i in start+1 ..< node.len:
|
||||
let
|
||||
name = typeDef.getIdentName()
|
||||
typ = nimState.getTypeArray(node, name)
|
||||
# node[i] = identifer = name
|
||||
typeDef = nimState.newXIdent(node[i], istype = true)
|
||||
|
||||
typeDef.add typ
|
||||
if not typeDef.isNil:
|
||||
let
|
||||
name = typeDef.getIdentName()
|
||||
typ = nimState.getTypeArray(node[i], tnode, name)
|
||||
|
||||
# type X* = [ptr] array[x, [ptr] Y]
|
||||
#
|
||||
# nkTypeDef(
|
||||
# nkPostfix(
|
||||
# nkIdent("*"),
|
||||
# nkIdent("X")
|
||||
# ),
|
||||
# nkEmpty(),
|
||||
# nkPtrTy( # optional, nested
|
||||
# nkBracketExpr(
|
||||
# nkIdent("array")
|
||||
# nkXLit(x),
|
||||
# nkPtrTy( # optional, nested
|
||||
# nkIdent("Y")
|
||||
# )
|
||||
# )
|
||||
# )
|
||||
# )
|
||||
typeDef.add typ
|
||||
|
||||
# nkTypeSection.add
|
||||
nimState.typeSection.add typeDef
|
||||
# type X* = [ptr] array[x, [ptr] Y]
|
||||
#
|
||||
# nkTypeDef(
|
||||
# nkPostfix(
|
||||
# nkIdent("*"),
|
||||
# nkIdent("X")
|
||||
# ),
|
||||
# nkEmpty(),
|
||||
# nkPtrTy( # optional, nested
|
||||
# nkBracketExpr(
|
||||
# nkIdent("array")
|
||||
# nkXLit(x),
|
||||
# nkPtrTy( # optional, nested
|
||||
# nkIdent("Y")
|
||||
# )
|
||||
# )
|
||||
# )
|
||||
# )
|
||||
|
||||
nimState.printDebug(typeDef)
|
||||
# nkTypeSection.add
|
||||
nimState.typeSection.add typeDef
|
||||
|
||||
nimState.printDebug(typeDef)
|
||||
|
||||
proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode =
|
||||
# Create proc type tree
|
||||
|
|
@ -939,7 +945,7 @@ proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode =
|
|||
# Parameter list
|
||||
plist = node.anyChildInTree("parameter_list")
|
||||
|
||||
# node[1] could have nested pointers
|
||||
# node could have nested pointers
|
||||
tcount = node.getPtrCount()
|
||||
|
||||
# Name could be nested pointer to function
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ struct A4 {
|
|||
float f1;
|
||||
};
|
||||
|
||||
typedef char *A9p[3]; //, A9[4];
|
||||
typedef char *A9p[3], A9[4];
|
||||
typedef char *A10[3][6];
|
||||
typedef char *(*A11)[3];
|
||||
typedef struct A0 *A111[12];
|
||||
|
|
@ -113,6 +113,16 @@ void
|
|||
(*pcre_free)(void *),
|
||||
*(*pcre_stack_malloc)(size_t);
|
||||
|
||||
typedef int ImageView, MagickBooleanType;
|
||||
typedef MagickBooleanType
|
||||
(*DuplexTransferImageViewMethod)(const ImageView *,const ImageView *,
|
||||
ImageView *,const size_t,const int,void *),
|
||||
(*GetImageViewMethod)(const ImageView *,const size_t,const int,void *),
|
||||
(*SetImageViewMethod)(ImageView *,const size_t,const int,void *),
|
||||
(*TransferImageViewMethod)(const ImageView *,ImageView *,const size_t,
|
||||
const int,void *),
|
||||
(*UpdateImageViewMethod)(ImageView *,const size_t,const int,void *);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -145,12 +155,15 @@ struct A4 {
|
|||
float f1;
|
||||
};
|
||||
|
||||
typedef char *A9p[3]; //, A9[4];
|
||||
typedef char *A9p[3], A9[4];
|
||||
typedef char *A10[3][6];
|
||||
typedef char *(*A11)[3];
|
||||
typedef struct A1 *A111[12];
|
||||
typedef struct A0 *A111[12];
|
||||
|
||||
typedef int **(*A12)(int, int b, int *c, int *, int *count[4], int (*func)(int, int));
|
||||
typedef int
|
||||
**(*A12)(int, int b, int *c, int *, int *count[4], int (*func)(int, int)),
|
||||
**(*A121)(float, float b, float *c, float *, float *count[4], float (*func)(float, float)),
|
||||
**(*A122)(char, char b, char *c, char *, char *count[4], char (*func)(char, char));
|
||||
typedef int A13(int, int, void (*func)(void));
|
||||
|
||||
struct A14 { volatile char a1; };
|
||||
|
|
@ -222,6 +235,22 @@ typedef enum VSPresetFormat {
|
|||
|
||||
//struct A2 test_proc1(struct A0 a);
|
||||
|
||||
// Proc vars
|
||||
void
|
||||
*(*pcre_malloc)(size_t),
|
||||
(*pcre_free)(void *),
|
||||
*(*pcre_stack_malloc)(size_t);
|
||||
|
||||
typedef MagickBooleanType
|
||||
(*DuplexTransferImageViewMethod)(const ImageView *,const ImageView *,
|
||||
ImageView *,const size_t,const int,void *),
|
||||
(*GetImageViewMethod)(const ImageView *,const size_t,const int,void *),
|
||||
(*SetImageViewMethod)(ImageView *,const size_t,const int,void *),
|
||||
(*TransferImageViewMethod)(const ImageView *,ImageView *,const size_t,
|
||||
const int,void *),
|
||||
(*UpdateImageViewMethod)(ImageView *,const size_t,const int,void *);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -165,10 +165,10 @@ var a9p: A9p
|
|||
a9p[1] = nil
|
||||
a9p[2] = "hello".cstring
|
||||
|
||||
#Not implemented yet
|
||||
#assert A9 is array[4, cchar]
|
||||
#checkPragmas(A9, pHeaderImp)
|
||||
#var a9: A9
|
||||
assert A9 is array[4, cchar]
|
||||
checkPragmas(A9, pHeaderImp)
|
||||
var a9: A9
|
||||
a9[2] = 'c'
|
||||
|
||||
assert A10 is array[3, array[6, cstring]]
|
||||
checkPragmas(A10, pHeaderImp)
|
||||
|
|
@ -308,4 +308,20 @@ assert pcre_free is proc(a1: pointer) {.cdecl.}
|
|||
checkPragmas(pcre_free, @["importc", "cdecl"] & pHeader)
|
||||
|
||||
assert pcre_stack_malloc is proc(a1: uint): pointer {.cdecl.}
|
||||
checkPragmas(pcre_stack_malloc, @["importc", "cdecl"] & pHeader)
|
||||
checkPragmas(pcre_stack_malloc, @["importc", "cdecl"] & pHeader)
|
||||
|
||||
assert DuplexTransferImageViewMethod is
|
||||
proc (a1: ptr ImageView; a2: ptr ImageView; a3: ptr ImageView; a4: uint;
|
||||
a5: cint; a6: pointer): MagickBooleanType {.cdecl.}
|
||||
|
||||
assert GetImageViewMethod is
|
||||
proc (a1: ptr ImageView; a2: uint; a3: cint; a4: pointer): MagickBooleanType {.cdecl.}
|
||||
|
||||
assert SetImageViewMethod is
|
||||
proc (a1: ptr ImageView; a2: uint; a3: cint; a4: pointer): MagickBooleanType {.cdecl.}
|
||||
|
||||
assert TransferImageViewMethod is
|
||||
proc (a1: ptr ImageView; a2: ptr ImageView; a3: uint; a4: cint; a5: pointer): MagickBooleanType {.cdecl.}
|
||||
|
||||
assert UpdateImageViewMethod is
|
||||
proc (a1: ptr ImageView; a2: uint; a3: cint; a4: pointer): MagickBooleanType {.cdecl.}
|
||||
Loading…
Add table
Add a link
Reference in a new issue