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 size
|
||||||
result.add typ
|
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 getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode
|
||||||
|
|
||||||
proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, exported = false): 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)
|
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
||||||
pident = nimState.getIdent(pname, pinfo, exported)
|
pident = nimState.getIdent(pname, pinfo, exported)
|
||||||
result.add pident
|
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)
|
result.add newNode(nkEmpty)
|
||||||
elif not adecl.isNil:
|
elif not adecl.isNil:
|
||||||
# Named param, array type
|
# 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)
|
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
||||||
pident = nimState.getIdent(pname, pinfo, exported)
|
pident = nimState.getIdent(pname, pinfo, exported)
|
||||||
result.add pident
|
result.add pident
|
||||||
result.add nimState.getTypeArray(node, name)
|
result.add nimState.getTypeArray(node[start+1], node[start], name)
|
||||||
result.add newNode(nkEmpty)
|
result.add newNode(nkEmpty)
|
||||||
else:
|
else:
|
||||||
result = nil
|
result = nil
|
||||||
|
|
@ -838,24 +838,22 @@ proc addTypeTyped(nimState: NimState, node: TSNode, ftname = "", offset = 0) =
|
||||||
else:
|
else:
|
||||||
nimState.addTypeObject(node, typeDef = typeDef, istype = true)
|
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
|
# Create array type tree
|
||||||
let
|
let
|
||||||
start = getStartAtom(node)
|
# tnode = identifier = type name
|
||||||
|
(tname, _, info) = nimState.getNameInfo(tnode.getAtom(), nskType, parent = name)
|
||||||
# node[start] = identifier = type name
|
|
||||||
(tname, _, info) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name)
|
|
||||||
ident = nimState.getIdent(tname, info, exported = false)
|
ident = nimState.getIdent(tname, info, exported = false)
|
||||||
|
|
||||||
# Top-most array declarator
|
# 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()
|
acount = adecl.getArrayCount()
|
||||||
innermost = adecl.mostNestedChildInTree()
|
innermost = adecl.mostNestedChildInTree()
|
||||||
|
|
||||||
# node[start+1] could have nested pointers - type
|
# node could have nested pointers - type
|
||||||
tcount = node[start+1].getPtrCount()
|
tcount = node.getPtrCount()
|
||||||
|
|
||||||
# Name could be nested pointer to array
|
# Name could be nested pointer to array
|
||||||
#
|
#
|
||||||
|
|
@ -894,39 +892,47 @@ proc addTypeArray(nimState: NimState, node: TSNode) =
|
||||||
# Add a type of array type
|
# Add a type of array type
|
||||||
decho("addTypeArray()")
|
decho("addTypeArray()")
|
||||||
let
|
let
|
||||||
# node[1] = identifer = name
|
start = getStartAtom(node)
|
||||||
typeDef = nimState.newXIdent(node[1], istype = true)
|
|
||||||
|
|
||||||
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
|
let
|
||||||
name = typeDef.getIdentName()
|
# node[i] = identifer = name
|
||||||
typ = nimState.getTypeArray(node, 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]
|
typeDef.add typ
|
||||||
#
|
|
||||||
# nkTypeDef(
|
|
||||||
# nkPostfix(
|
|
||||||
# nkIdent("*"),
|
|
||||||
# nkIdent("X")
|
|
||||||
# ),
|
|
||||||
# nkEmpty(),
|
|
||||||
# nkPtrTy( # optional, nested
|
|
||||||
# nkBracketExpr(
|
|
||||||
# nkIdent("array")
|
|
||||||
# nkXLit(x),
|
|
||||||
# nkPtrTy( # optional, nested
|
|
||||||
# nkIdent("Y")
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
|
|
||||||
# nkTypeSection.add
|
# type X* = [ptr] array[x, [ptr] Y]
|
||||||
nimState.typeSection.add typeDef
|
#
|
||||||
|
# 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 =
|
proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode =
|
||||||
# Create proc type tree
|
# Create proc type tree
|
||||||
|
|
@ -939,7 +945,7 @@ proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode =
|
||||||
# Parameter list
|
# Parameter list
|
||||||
plist = node.anyChildInTree("parameter_list")
|
plist = node.anyChildInTree("parameter_list")
|
||||||
|
|
||||||
# node[1] could have nested pointers
|
# node could have nested pointers
|
||||||
tcount = node.getPtrCount()
|
tcount = node.getPtrCount()
|
||||||
|
|
||||||
# Name could be nested pointer to function
|
# Name could be nested pointer to function
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ struct A4 {
|
||||||
float f1;
|
float f1;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef char *A9p[3]; //, A9[4];
|
typedef char *A9p[3], A9[4];
|
||||||
typedef char *A10[3][6];
|
typedef char *A10[3][6];
|
||||||
typedef char *(*A11)[3];
|
typedef char *(*A11)[3];
|
||||||
typedef struct A0 *A111[12];
|
typedef struct A0 *A111[12];
|
||||||
|
|
@ -113,6 +113,16 @@ void
|
||||||
(*pcre_free)(void *),
|
(*pcre_free)(void *),
|
||||||
*(*pcre_stack_malloc)(size_t);
|
*(*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;
|
float f1;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef char *A9p[3]; //, A9[4];
|
typedef char *A9p[3], A9[4];
|
||||||
typedef char *A10[3][6];
|
typedef char *A10[3][6];
|
||||||
typedef char *(*A11)[3];
|
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));
|
typedef int A13(int, int, void (*func)(void));
|
||||||
|
|
||||||
struct A14 { volatile char a1; };
|
struct A14 { volatile char a1; };
|
||||||
|
|
@ -222,6 +235,22 @@ typedef enum VSPresetFormat {
|
||||||
|
|
||||||
//struct A2 test_proc1(struct A0 a);
|
//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
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -165,10 +165,10 @@ var a9p: A9p
|
||||||
a9p[1] = nil
|
a9p[1] = nil
|
||||||
a9p[2] = "hello".cstring
|
a9p[2] = "hello".cstring
|
||||||
|
|
||||||
#Not implemented yet
|
assert A9 is array[4, cchar]
|
||||||
#assert A9 is array[4, cchar]
|
checkPragmas(A9, pHeaderImp)
|
||||||
#checkPragmas(A9, pHeaderImp)
|
var a9: A9
|
||||||
#var a9: A9
|
a9[2] = 'c'
|
||||||
|
|
||||||
assert A10 is array[3, array[6, cstring]]
|
assert A10 is array[3, array[6, cstring]]
|
||||||
checkPragmas(A10, pHeaderImp)
|
checkPragmas(A10, pHeaderImp)
|
||||||
|
|
@ -309,3 +309,19 @@ checkPragmas(pcre_free, @["importc", "cdecl"] & pHeader)
|
||||||
|
|
||||||
assert pcre_stack_malloc is proc(a1: uint): pointer {.cdecl.}
|
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