Fix #231 - const func type, comment in struct
This commit is contained in:
parent
6c3142a27c
commit
7738063038
4 changed files with 92 additions and 10 deletions
|
|
@ -1238,8 +1238,9 @@ proc addType(gState: State, node: TSNode, union = false) =
|
||||||
gState.addTypeObject(node[0], union = union)
|
gState.addTypeObject(node[0], union = union)
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
fdecl = node[1].anyChildInTree("function_declarator")
|
start = node.getStartAtom()
|
||||||
adecl = node[1].anyChildInTree("array_declarator")
|
fdecl = node[start+1].anyChildInTree("function_declarator")
|
||||||
|
adecl = node[start+1].anyChildInTree("array_declarator")
|
||||||
if fdlist.isNil:
|
if fdlist.isNil:
|
||||||
if adecl.isNil and fdecl.isNil:
|
if adecl.isNil and fdecl.isNil:
|
||||||
# typedef X Y;
|
# typedef X Y;
|
||||||
|
|
@ -1341,9 +1342,9 @@ proc addType(gState: State, node: TSNode, union = false) =
|
||||||
|
|
||||||
# First add struct as object
|
# First add struct as object
|
||||||
decho("addType(): case 6")
|
decho("addType(): case 6")
|
||||||
gState.addTypeObject(node[0], union = union)
|
gState.addTypeObject(node[start], union = union)
|
||||||
|
|
||||||
if node.len > 1 and gState.getNodeVal(node[1]) != "":
|
if node.len > start+1 and gState.getNodeVal(node[start+1]) != "":
|
||||||
# Add any additional names
|
# Add any additional names
|
||||||
gState.addTypeTyped(node)
|
gState.addTypeTyped(node)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1357,14 +1358,14 @@ proc addType(gState: State, node: TSNode, union = false) =
|
||||||
name = block:
|
name = block:
|
||||||
var
|
var
|
||||||
name = ""
|
name = ""
|
||||||
for i in 1 ..< node.len:
|
for i in start+1 ..< node.len:
|
||||||
if node[i].getName() == "type_identifier":
|
if node[i].getName() == "type_identifier":
|
||||||
name = gState.getNodeVal(node[i].getAtom())
|
name = gState.getNodeVal(node[i].getAtom())
|
||||||
|
|
||||||
name
|
name
|
||||||
|
|
||||||
# Now add struct as object with specified name
|
# Now add struct as object with specified name
|
||||||
gState.addTypeObject(node[0], fname = name, istype = true, union = union)
|
gState.addTypeObject(node[start], fname = name, istype = true, union = union)
|
||||||
|
|
||||||
if name.nBl:
|
if name.nBl:
|
||||||
# Add any additional names
|
# Add any additional names
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ proc getAtom*(node: TSNode): TSNode =
|
||||||
if node.getName() in gAtoms:
|
if node.getName() in gAtoms:
|
||||||
return node
|
return node
|
||||||
elif node.len != 0:
|
elif node.len != 0:
|
||||||
if node[0].getName() == "type_qualifier":
|
if node[0].getName() in ["type_qualifier", "comment"]:
|
||||||
# Skip const, volatile
|
# Skip const, volatile
|
||||||
if node.len > 1:
|
if node.len > 1:
|
||||||
return node[1].getAtom()
|
return node[1].getAtom()
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ struct some_struct_s
|
||||||
|
|
||||||
struct parent_struct_s
|
struct parent_struct_s
|
||||||
{
|
{
|
||||||
|
/* Random comment */
|
||||||
struct some_struct_s s[SOME_CONST];
|
struct some_struct_s s[SOME_CONST];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -108,6 +109,9 @@ typedef struct A20 { char a1; } A20, A21, *A21p;
|
||||||
//Expression
|
//Expression
|
||||||
typedef struct A22 { const int **f1; int *f2[123+132]; } A22;
|
typedef struct A22 { const int **f1; int *f2[123+132]; } A22;
|
||||||
|
|
||||||
|
// #231
|
||||||
|
typedef const char *(*A23)();
|
||||||
|
|
||||||
//Unions
|
//Unions
|
||||||
union U1 {int f1; float f2; };
|
union U1 {int f1; float f2; };
|
||||||
typedef union U2 { const int **f1; int abc[123+132]; } U2;
|
typedef union U2 { const int **f1; int abc[123+132]; } U2;
|
||||||
|
|
@ -239,6 +243,7 @@ typedef struct {
|
||||||
struct { int f1; } f2;
|
struct { int f1; } f2;
|
||||||
|
|
||||||
struct NT3 {
|
struct NT3 {
|
||||||
|
/* Random comment */
|
||||||
struct {
|
struct {
|
||||||
int f1;
|
int f1;
|
||||||
union NU1 {
|
union NU1 {
|
||||||
|
|
@ -277,6 +282,65 @@ struct TestMyInt {
|
||||||
#define C 0x10
|
#define C 0x10
|
||||||
#define D "hello"
|
#define D "hello"
|
||||||
#define E 'c'
|
#define E 'c'
|
||||||
|
#define F 01234
|
||||||
|
|
||||||
|
#define UEXPR (1234u << 1)
|
||||||
|
#define ULEXPR (1234ul << 2)
|
||||||
|
#define ULLEXPR (1234ull << 3)
|
||||||
|
#define LEXPR (1234l << 4)
|
||||||
|
#define LLEXPR (1234ll << 5)
|
||||||
|
|
||||||
|
#define SHL1 (1u << 1)
|
||||||
|
#define SHL2 (1u << 2)
|
||||||
|
#define SHL3 (1u << 3)
|
||||||
|
#define COERCE 645635634896ull + 35436
|
||||||
|
#define COERCE2 645635634896 + 35436ul
|
||||||
|
#define BINEXPR ~(-(1u << !-1)) ^ (10 >> 1)
|
||||||
|
#define POINTEREXPR (int*)0
|
||||||
|
#define POINTERPOINTERPOINTEREXPR (int***)0
|
||||||
|
#define BOOL true
|
||||||
|
#define MATHEXPR (1 + 2/3*20 - 100)
|
||||||
|
#define ANDEXPR (100 & 11000)
|
||||||
|
#define CASTEXPR (char) 34
|
||||||
|
#define AVAL 100
|
||||||
|
#define BVAL 200
|
||||||
|
#define EQ1 AVAL <= BVAL
|
||||||
|
#define EQ2 AVAL >= BVAL
|
||||||
|
#define EQ3 AVAL > BVAL
|
||||||
|
#define EQ4 AVAL < BVAL
|
||||||
|
#define EQ5 AVAL != BVAL
|
||||||
|
#define EQ6 AVAL == BVAL
|
||||||
|
|
||||||
|
// testing integer out of long int range
|
||||||
|
#define INT_FAST16_MIN (-9223372036854775807L-1)
|
||||||
|
|
||||||
|
#define SIZEOF sizeof(char)
|
||||||
|
#define REG_STR "regular string"
|
||||||
|
#define NOTSUPPORTEDSTR "not a " REG_STR
|
||||||
|
|
||||||
|
#define NULLCHAR '\0'
|
||||||
|
#define OCTCHAR '\012'
|
||||||
|
#define HEXCHAR '\xFE'
|
||||||
|
#define TRICKYSTR "\x4E\034\nfoo\0\'\"\r\v\a\b\e\f\t\\\?bar"
|
||||||
|
|
||||||
|
#define ALLSHL (SHL1 | SHL2 | SHL3)
|
||||||
|
|
||||||
|
#ifdef NIMTEROP
|
||||||
|
#define SOME_CONST 8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct some_struct_s
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct parent_struct_s
|
||||||
|
{
|
||||||
|
/* Random comment */
|
||||||
|
struct some_struct_s s[SOME_CONST];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct some_struct_s SOME_ARRAY[SOME_CONST];
|
||||||
|
|
||||||
struct A0;
|
struct A0;
|
||||||
struct A1 {};
|
struct A1 {};
|
||||||
|
|
@ -303,10 +367,10 @@ typedef char *(*A11)[3];
|
||||||
typedef struct A0 *A111[12];
|
typedef struct A0 *A111[12];
|
||||||
|
|
||||||
typedef int
|
typedef int
|
||||||
**(*A12)(int, int b, int *c, int *, int *count[4], int (*func)(int, int)),
|
**(*A12)(int, int b, int *c, int *, int /*out*/ *count[4], int (*func)(int, int)),
|
||||||
**(*A121)(float, float b, float *c, float *, float *count[4], float (*func)(float, float)),
|
**(*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));
|
**(*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; };
|
||||||
struct A15 { char *a1; const int *a2[1]; };
|
struct A15 { char *a1; const int *a2[1]; };
|
||||||
|
|
@ -320,6 +384,9 @@ typedef struct A20 { char a1; } A20, A21, *A21p;
|
||||||
//Expression
|
//Expression
|
||||||
typedef struct A22 { const int **f1; int *f2[123+132]; } A22;
|
typedef struct A22 { const int **f1; int *f2[123+132]; } A22;
|
||||||
|
|
||||||
|
// #231
|
||||||
|
typedef const char *(*A23)();
|
||||||
|
|
||||||
//Unions
|
//Unions
|
||||||
union U1 {int f1; float f2; };
|
union U1 {int f1; float f2; };
|
||||||
typedef union U2 { const int **f1; int abc[123+132]; } U2;
|
typedef union U2 { const int **f1; int abc[123+132]; } U2;
|
||||||
|
|
@ -403,6 +470,16 @@ void
|
||||||
|
|
||||||
int sqlite3_bind_blob(struct A1*, int, const void*, int n, void(*)(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];
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct fieldfuncfunc {
|
typedef struct fieldfuncfunc {
|
||||||
int *(*func1)(int f1, int *(*sfunc1)(int f1, int *(*ssfunc1)(int f1, ...)));
|
int *(*func1)(int f1, int *(*sfunc1)(int f1, int *(*ssfunc1)(int f1, ...)));
|
||||||
};
|
};
|
||||||
|
|
@ -441,6 +518,7 @@ typedef struct {
|
||||||
struct { int f1; } f2;
|
struct { int f1; } f2;
|
||||||
|
|
||||||
struct NT3 {
|
struct NT3 {
|
||||||
|
/* Random comment */
|
||||||
struct {
|
struct {
|
||||||
int f1;
|
int f1;
|
||||||
union NU1 {
|
union NU1 {
|
||||||
|
|
@ -469,7 +547,6 @@ struct TestMyInt {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,10 @@ checkPragmas(A22, pHeaderBy, istype = false)
|
||||||
var a22: A22
|
var a22: A22
|
||||||
a22.f1 = addr a15.a2[0]
|
a22.f1 = addr a15.a2[0]
|
||||||
|
|
||||||
|
assert A23 is proc(): cstring {.cdecl.}
|
||||||
|
checkPragmas(A23, pHeaderImp & "cdecl")
|
||||||
|
var a23: A23
|
||||||
|
|
||||||
assert U1 is object
|
assert U1 is object
|
||||||
assert sizeof(U1) == sizeof(cfloat)
|
assert sizeof(U1) == sizeof(cfloat)
|
||||||
checkPragmas(U1, pHeaderBy & @["union"], istype = false)
|
checkPragmas(U1, pHeaderBy & @["union"], istype = false)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue