xref: /PHP-8.3/ext/ffi/tests/002.phpt (revision bd9f4fa6)
1--TEST--
2FFI 002: Check C declaration parser
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9echo "Empty declaration\n";
10$ffi = FFI::cdef(<<<EOF
11EOF
12);
13echo "  ok\n";
14
15echo "Various declarations\n";
16$ffi = FFI::cdef(<<<EOF
17    /* allowed storage classes */
18    typedef  int type1;
19//	extern   int var2;
20    static   int var3;
21    auto     int var4;
22    register int var5;
23
24    /* allowed types */
25    typedef void type6;
26    typedef char type7;                     /* sint8_t or uint8_t */
27    typedef signed char type8;              /* sint8_t  */
28    typedef unsigned char type9;            /* uint8_t  */
29    typedef short type10;                   /* sint16_t */
30    typedef signed short type11;            /* sint16_t */
31    typedef short int type12;               /* sint16_t */
32    typedef signed short int type13;        /* sint16_t */
33    typedef unsigned short type14;          /* uint16_t */
34    typedef unsigned short int type15;      /* uint16_t */
35    typedef int type16;                     /* sint32_t */
36    typedef signed type17;                  /* sint32_t */
37    typedef signed int type18;              /* sint32_t */
38    typedef unsigned type19;                /* uint32_t */
39    typedef unsigned int type20;            /* uint32_t */
40    typedef long type21;                    /* sint32_t or sint64_t */
41    typedef signed long type22;             /* sint32_t or sint64_t */
42    typedef long int type23;                /* sint32_t or sint64_t */
43    typedef signed long int type24;         /* sint32_t or sint64_t */
44    typedef unsigned long type25;           /* uint32_t or uint64_t */
45    typedef unsigned long int type25_2;     /* uint32_t or uint64_t */
46    typedef long long type26;               /* sint64_t */
47    typedef signed long long type27;        /* sint64_t */
48    typedef long long int type28;           /* sint64_t */
49    typedef signed long long int type29;    /* sint64_t */
50    typedef unsigned long long type30;      /* uint64_t */
51    typedef unsigned long long int type31;  /* uint64_t */
52    typedef float type32;
53    typedef double type33;
54    typedef long double type34;
55    typedef _Bool type35;
56//	typedef float _Complex type36;
57//	typedef double _Complex type36_2;
58//	typedef long double _Complex type36_3;
59
60    /* struct and union */
61    struct tag1;
62    union tag2;
63    typedef struct tag1 {int x; int y;} type37;
64    typedef union tag2 {int x; int y;} type38;
65    typedef struct {int x, y; int z;} type39;
66    typedef struct {unsigned int x:8, y:8;} type40;
67    typedef struct {unsigned int x:8, :8, y:8;} type41;
68
69    /* enum */
70    enum tag3;
71    typedef enum tag3 {A,B,C} type42;
72    typedef enum {D,E=10,F,} type43;
73
74    /* type qualifiers */
75    typedef void* type46;
76    typedef const void* type47;
77    typedef restrict void* type48;
78    typedef volatile void* type49;
79    typedef _Atomic void* type50;
80    typedef const volatile void* type51;
81
82    /* function specifiers */
83    static void f1();
84    static inline void f2();
85    static _Noreturn void f3();
86
87    /* align specifier */
88    typedef double _Alignas(char) type52;
89    typedef double _Alignas(1) type53;
90
91    /* pointers */
92    typedef void * type54;
93    typedef void ** type55;
94    typedef const void * const volatile * const type56;
95
96    /* arrays */
97    typedef char type57[];
98    typedef char type58[const];
99    typedef char type59[const volatile];
100    typedef char type60[10];
101    typedef char type61[const 10];
102    typedef char type62[static 10];
103    typedef char type63[static const volatile 10];
104    typedef char type64[const volatile static 10];
105    typedef char type65[];
106    typedef char type66[const volatile];
107    typedef char type67[10][10];
108
109    /* functions */
110    static void f4();
111    static void f5(void);
112    static void f6(int x);
113    static void f7(int x, int y);
114    static void f8(int x, int y, ...);
115    static void f9(int, int);
116    static void f9(int, int, ...);
117    static void f10(...);
118    static void f11(const char *name);
119    static void f12(const char *);
120    static void f13(const int a[5]);
121    static void f14(const int[5]);
122
123    /* nested */
124    typedef int *type69[4];
125    typedef int (*type70)[4];
126    typedef int (*type71[3])(int *x, int *y);
127    typedef int (*type72(int (*)(long), int))(int, ...);
128EOF
129);
130echo "  ok\n";
131?>
132--EXPECT--
133Empty declaration
134  ok
135Various declarations
136  ok
137