Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
0002 
0003 /*
0004  * BTF-to-C dumper test for majority of C syntax quirks.
0005  *
0006  * Copyright (c) 2019 Facebook
0007  */
0008 /* ----- START-EXPECTED-OUTPUT ----- */
0009 enum e1 {
0010     A = 0,
0011     B = 1,
0012 };
0013 
0014 enum e2 {
0015     C = 100,
0016     D = 4294967295,
0017     E = 0,
0018 };
0019 
0020 typedef enum e2 e2_t;
0021 
0022 typedef enum {
0023     F = 0,
0024     G = 1,
0025     H = 2,
0026 } e3_t;
0027 
0028 typedef int int_t;
0029 
0030 typedef volatile const int * volatile const crazy_ptr_t;
0031 
0032 typedef int *****we_need_to_go_deeper_ptr_t;
0033 
0034 typedef volatile const we_need_to_go_deeper_ptr_t * restrict * volatile * const * restrict volatile * restrict const * volatile const * restrict volatile const how_about_this_ptr_t;
0035 
0036 typedef int *ptr_arr_t[10];
0037 
0038 typedef void (*fn_ptr1_t)(int);
0039 
0040 typedef void (*printf_fn_t)(const char *, ...);
0041 
0042 /* ------ END-EXPECTED-OUTPUT ------ */
0043 /*
0044  * While previous function pointers are pretty trivial (C-syntax-level
0045  * trivial), the following are deciphered here for future generations:
0046  *
0047  * - `fn_ptr2_t`: function, taking anonymous struct as a first arg and pointer
0048  *   to a function, that takes int and returns int, as a second arg; returning
0049  *   a pointer to a const pointer to a char. Equivalent to:
0050  *  typedef struct { int a; } s_t;
0051  *  typedef int (*fn_t)(int);
0052  *  typedef char * const * (*fn_ptr2_t)(s_t, fn_t);
0053  *
0054  * - `fn_complext_t`: pointer to a function returning struct and accepting
0055  *   union and struct. All structs and enum are anonymous and defined inline.
0056  *
0057  * - `signal_t: pointer to a function accepting a pointer to a function as an
0058  *   argument and returning pointer to a function as a result. Sane equivalent:
0059  *  typedef void (*signal_handler_t)(int);
0060  *  typedef signal_handler_t (*signal_ptr_t)(int, signal_handler_t);
0061  *
0062  * - fn_ptr_arr1_t: array of pointers to a function accepting pointer to
0063  *   a pointer to an int and returning pointer to a char. Easy.
0064  *
0065  * - fn_ptr_arr2_t: array of const pointers to a function taking no arguments
0066  *   and returning a const pointer to a function, that takes pointer to a
0067  *   `int -> char *` function and returns pointer to a char. Equivalent:
0068  *   typedef char * (*fn_input_t)(int);
0069  *   typedef char * (*fn_output_outer_t)(fn_input_t);
0070  *   typedef const fn_output_outer_t (* fn_output_inner_t)();
0071  *   typedef const fn_output_inner_t fn_ptr_arr2_t[5];
0072  */
0073 /* ----- START-EXPECTED-OUTPUT ----- */
0074 typedef char * const * (*fn_ptr2_t)(struct {
0075     int a;
0076 }, int (*)(int));
0077 
0078 typedef struct {
0079     int a;
0080     void (*b)(int, struct {
0081         int c;
0082     }, union {
0083         char d;
0084         int e[5];
0085     });
0086 } (*fn_complex_t)(union {
0087     void *f;
0088     char g[16];
0089 }, struct {
0090     int h;
0091 });
0092 
0093 typedef void (* (*signal_t)(int, void (*)(int)))(int);
0094 
0095 typedef char * (*fn_ptr_arr1_t[10])(int **);
0096 
0097 typedef char * (* (* const fn_ptr_arr2_t[5])())(char * (*)(int));
0098 
0099 struct struct_w_typedefs {
0100     int_t a;
0101     crazy_ptr_t b;
0102     we_need_to_go_deeper_ptr_t c;
0103     how_about_this_ptr_t d;
0104     ptr_arr_t e;
0105     fn_ptr1_t f;
0106     printf_fn_t g;
0107     fn_ptr2_t h;
0108     fn_complex_t i;
0109     signal_t j;
0110     fn_ptr_arr1_t k;
0111     fn_ptr_arr2_t l;
0112 };
0113 
0114 typedef struct {
0115     int x;
0116     int y;
0117     int z;
0118 } anon_struct_t;
0119 
0120 struct struct_fwd;
0121 
0122 typedef struct struct_fwd struct_fwd_t;
0123 
0124 typedef struct struct_fwd *struct_fwd_ptr_t;
0125 
0126 union union_fwd;
0127 
0128 typedef union union_fwd union_fwd_t;
0129 
0130 typedef union union_fwd *union_fwd_ptr_t;
0131 
0132 struct struct_empty {};
0133 
0134 struct struct_simple {
0135     int a;
0136     char b;
0137     const int_t *p;
0138     struct struct_empty s;
0139     enum e2 e;
0140     enum {
0141         ANON_VAL1 = 1,
0142         ANON_VAL2 = 2,
0143     } f;
0144     int arr1[13];
0145     enum e2 arr2[5];
0146 };
0147 
0148 union union_empty {};
0149 
0150 union union_simple {
0151     void *ptr;
0152     int num;
0153     int_t num2;
0154     union union_empty u;
0155 };
0156 
0157 struct struct_in_struct {
0158     struct struct_simple simple;
0159     union union_simple also_simple;
0160     struct {
0161         int a;
0162     } not_so_hard_as_well;
0163     union {
0164         int b;
0165         int c;
0166     } anon_union_is_good;
0167     struct {
0168         int d;
0169         int e;
0170     };
0171     union {
0172         int f;
0173         int g;
0174     };
0175 };
0176 
0177 struct struct_in_array {};
0178 
0179 struct struct_in_array_typed {};
0180 
0181 typedef struct struct_in_array_typed struct_in_array_t[2];
0182 
0183 struct struct_with_embedded_stuff {
0184     int a;
0185     struct {
0186         int b;
0187         struct {
0188             struct struct_with_embedded_stuff *c;
0189             const char *d;
0190         } e;
0191         union {
0192             volatile long f;
0193             void * restrict g;
0194         };
0195     };
0196     union {
0197         const int_t *h;
0198         void (*i)(char, int, void *);
0199     } j;
0200     enum {
0201         K = 100,
0202         L = 200,
0203     } m;
0204     char n[16];
0205     struct {
0206         char o;
0207         int p;
0208         void (*q)(int);
0209     } r[5];
0210     struct struct_in_struct s[10];
0211     int t[11];
0212     struct struct_in_array (*u)[2];
0213     struct_in_array_t *v;
0214 };
0215 
0216 struct float_struct {
0217     float f;
0218     const double *d;
0219     volatile long double *ld;
0220 };
0221 
0222 struct root_struct {
0223     enum e1 _1;
0224     enum e2 _2;
0225     e2_t _2_1;
0226     e3_t _2_2;
0227     struct struct_w_typedefs _3;
0228     anon_struct_t _7;
0229     struct struct_fwd *_8;
0230     struct_fwd_t *_9;
0231     struct_fwd_ptr_t _10;
0232     union union_fwd *_11;
0233     union_fwd_t *_12;
0234     union_fwd_ptr_t _13;
0235     struct struct_with_embedded_stuff _14;
0236     struct float_struct _15;
0237 };
0238 
0239 /* ------ END-EXPECTED-OUTPUT ------ */
0240 
0241 int f(struct root_struct *s)
0242 {
0243     return 0;
0244 }