code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
#line 1 "example_c_file.c" #line 1 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 19 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 25 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 11 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 1 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 3 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 16 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 52 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 58 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 83 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 86 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 89 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 95 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 5 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 11 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 143 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 157 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 195 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 207 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 17 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 30 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 19 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 26 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 30 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 39 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 42 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 53 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 56 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 67 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 76 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 98 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 108 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 126 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 131 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 170 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef long unsigned int size_t; #line 243 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 246 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 290 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 302 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 310 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 361 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 365 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 418 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 422 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 427 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 19 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 26 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 30 "D:\eli\cpp_stuff\libc_include/stdarg.h" typedef char* __builtin_va_list; typedef __builtin_va_list __gnuc_va_list; #line 50 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 66 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 80 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 98 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 38 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 44 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 6 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 1 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 11 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 14 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 8 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 4 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 4 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 15 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 17 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/limits.h" #line 1 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 3 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 5 "D:\eli\cpp_stuff\libc_include/limits.h" #line 19 "D:\eli\cpp_stuff\libc_include/limits.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 11 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 143 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 157 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 195 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 207 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 25 "D:\eli\cpp_stuff\libc_include/limits.h" #line 79 "D:\eli\cpp_stuff\libc_include/limits.h" #line 23 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" typedef signed char __int8_t ; typedef unsigned char __uint8_t ; typedef signed short __int16_t; typedef unsigned short __uint16_t; typedef __int16_t __int_least16_t; typedef __uint16_t __uint_least16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; typedef __int32_t __int_least32_t; typedef __uint32_t __uint_least32_t; #line 8 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 13 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/lock.h" typedef int _LOCK_T; typedef int _LOCK_RECURSIVE_T; #line 14 "D:\eli\cpp_stuff\libc_include/sys/_types.h" typedef long _off_t; typedef short __dev_t; typedef unsigned short __uid_t; typedef unsigned short __gid_t; typedef long long _off64_t; #line 43 "D:\eli\cpp_stuff\libc_include/sys/_types.h" typedef long _fpos_t; typedef int _ssize_t; #line 1 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 19 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 26 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 30 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 39 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 42 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 53 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 56 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 67 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 76 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 98 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 108 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 126 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 131 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 170 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 243 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 246 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 290 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 302 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 310 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef unsigned int wint_t; #line 361 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 365 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 418 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 422 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 427 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 64 "D:\eli\cpp_stuff\libc_include/sys/_types.h" typedef struct { int __count; union { wint_t __wch; unsigned char __wchb[4]; } __value; } _mbstate_t; typedef _LOCK_RECURSIVE_T _flock_t; typedef void *_iconv_t; #line 15 "D:\eli\cpp_stuff\libc_include/sys/reent.h" typedef unsigned long __ULong; struct _reent; #line 43 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _Bigint { struct _Bigint *_next; int _k, _maxwds, _sign, _wds; __ULong _x[1]; }; struct __tm { int __tm_sec; int __tm_min; int __tm_hour; int __tm_mday; int __tm_mon; int __tm_year; int __tm_wday; int __tm_yday; int __tm_isdst; }; #line 68 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _on_exit_args { void * _fnargs[32]; void * _dso_handle[32]; __ULong _fntypes; #line 77 "D:\eli\cpp_stuff\libc_include/sys/reent.h" __ULong _is_cxa; }; struct _atexit { struct _atexit *_next; int _ind; void (*_fns[32])(void); struct _on_exit_args _on_exit_args; }; #line 104 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct __sbuf { unsigned char *_base; int _size; }; #line 134 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 141 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct __sFILE { unsigned char *_p; int _r; int _w; short _flags; short _file; struct __sbuf _bf; int _lbfsize; char * _cookie; int(*_read)(); #line 176 "D:\eli\cpp_stuff\libc_include/sys/reent.h" int(*_write)(); #line 178 "D:\eli\cpp_stuff\libc_include/sys/reent.h" _fpos_t(*_seek)(); int(*_close)(); struct __sbuf _ub; unsigned char *_up; int _ur; unsigned char _ubuf[3]; unsigned char _nbuf[1]; struct __sbuf _lb; int _blksize; int _offset; struct _reent *_data; _flock_t _lock; }; typedef struct __sFILE __FILE; struct _glue { struct _glue *_next; int _niobs; __FILE *_iobs; }; #line 284 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _rand48 { unsigned short _seed[3]; unsigned short _mult[3]; unsigned short _add; }; #line 313 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 344 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 350 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 420 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 452 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 474 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 478 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 482 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 494 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 496 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 503 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 505 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 508 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 531 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 533 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 536 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _reent { int _errno; #line 571 "D:\eli\cpp_stuff\libc_include/sys/reent.h" __FILE *_stdin, *_stdout, *_stderr; int _inc; char _emergency[25]; int _current_category; char *_current_locale; int __sdidinit; void(*__cleanup)(); struct _Bigint *_result; int _result_k; struct _Bigint *_p5s; struct _Bigint **_freelist; int _cvtlen; char *_cvtbuf; union { struct { unsigned int _unused_rand; char * _strtok_last; char _asctime_buf[26]; struct __tm _localtime_buf; int _gamma_signgam; unsigned long long _rand_next; struct _rand48 _r48; _mbstate_t _mblen_state; _mbstate_t _mbtowc_state; _mbstate_t _wctomb_state; char _l64a_buf[8]; char _signal_buf[24]; int _getdate_err; _mbstate_t _mbrlen_state; _mbstate_t _mbrtowc_state; _mbstate_t _mbsrtowcs_state; _mbstate_t _wcrtomb_state; _mbstate_t _wcsrtombs_state; } _reent; #line 619 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct { unsigned char * _nextf[30]; unsigned int _nmalloc[30]; } _unused; } _new; struct _atexit *_atexit; struct _atexit _atexit0; void (**(_sig_func))(int); #line 637 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _glue __sglue; __FILE __sf[3]; }; #line 689 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 751 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 791 "D:\eli\cpp_stuff\libc_include/sys/reent.h" extern struct _reent *_impure_ptr; extern struct _reent * _global_impure_ptr; void _reclaim_reent(); #line 46 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 17 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 11 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 4 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 26 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 33 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 8 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 43 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 62 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 19 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 26 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 30 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 39 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 42 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 53 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 56 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 67 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 76 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 98 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 108 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 126 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 131 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef long int ptrdiff_t; #line 170 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 243 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 246 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 290 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 302 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 310 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef int wchar_t; #line 361 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 365 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 418 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 422 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 427 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 70 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/types.h" #line 9 "D:\eli\cpp_stuff\libc_include/machine/types.h" typedef long int __off_t; typedef int __pid_t; typedef long int __loff_t; #line 71 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 79 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long clock_t; typedef long time_t; struct timespec { time_t tv_sec; long tv_nsec; }; struct itimerspec { struct timespec it_interval; struct timespec it_value; }; typedef long daddr_t; typedef char * caddr_t; #line 131 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef unsigned short ino_t; #line 160 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef _off_t off_t; typedef __dev_t dev_t; typedef __uid_t uid_t; typedef __gid_t gid_t; typedef int pid_t; typedef long key_t; typedef _ssize_t ssize_t; typedef unsigned int mode_t; typedef unsigned short nlink_t; #line 200 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 209 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef long fd_mask; #line 221 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef struct _types_fd_set { fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))]; } _types_fd_set; #line 236 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef unsigned long clockid_t; typedef unsigned long timer_t; typedef unsigned long useconds_t; typedef long suseconds_t; #line 1 "D:\eli\cpp_stuff\libc_include/sys/features.h" #line 20 "D:\eli\cpp_stuff\libc_include/sys/features.h" #line 257 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 266 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 273 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 47 "D:\eli\cpp_stuff\libc_include/stdio.h" typedef __FILE FILE; typedef _fpos_t fpos_t; #line 1 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/lock.h" #line 5 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 6 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 43 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 68 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 77 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 104 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 134 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 141 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 284 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 313 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 344 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 350 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 420 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 452 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 474 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 478 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 482 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 494 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 496 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 503 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 505 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 508 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 531 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 533 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 536 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 571 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 619 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 637 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 689 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 751 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 791 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 6 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 11 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 66 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 96 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 163 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * tmpfile(); char * tmpnam(); int fclose(); int fflush(); FILE * freopen(); void setbuf(); int setvbuf(); int fprintf(); #line 179 "D:\eli\cpp_stuff\libc_include/stdio.h" int fscanf(); #line 181 "D:\eli\cpp_stuff\libc_include/stdio.h" int printf(); #line 183 "D:\eli\cpp_stuff\libc_include/stdio.h" int scanf(); #line 185 "D:\eli\cpp_stuff\libc_include/stdio.h" int sscanf(); #line 187 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfprintf(); #line 189 "D:\eli\cpp_stuff\libc_include/stdio.h" int vprintf(); #line 191 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsprintf(); #line 193 "D:\eli\cpp_stuff\libc_include/stdio.h" int fgetc(); char * fgets(); int fputc(); int fputs(); int getc(); int getchar(); char * gets(); int putc(); int putchar(); int puts(); int ungetc(); size_t fread(); size_t fwrite(); int fgetpos(); int fseek(); int fsetpos(); long ftell(); void rewind(); void clearerr(); int feof(); int ferror(); void perror(); FILE * fopen(); int sprintf(); #line 227 "D:\eli\cpp_stuff\libc_include/stdio.h" int remove(); int rename(); int fseeko(); off_t ftello(); int asiprintf(); #line 241 "D:\eli\cpp_stuff\libc_include/stdio.h" char * asniprintf(); #line 243 "D:\eli\cpp_stuff\libc_include/stdio.h" char * asnprintf(); #line 245 "D:\eli\cpp_stuff\libc_include/stdio.h" int asprintf(); #line 247 "D:\eli\cpp_stuff\libc_include/stdio.h" int diprintf(); #line 250 "D:\eli\cpp_stuff\libc_include/stdio.h" int fcloseall(); int fiprintf(); #line 254 "D:\eli\cpp_stuff\libc_include/stdio.h" int fiscanf(); #line 256 "D:\eli\cpp_stuff\libc_include/stdio.h" int iprintf(); #line 258 "D:\eli\cpp_stuff\libc_include/stdio.h" int iscanf(); #line 260 "D:\eli\cpp_stuff\libc_include/stdio.h" int siprintf(); #line 262 "D:\eli\cpp_stuff\libc_include/stdio.h" int siscanf(); #line 264 "D:\eli\cpp_stuff\libc_include/stdio.h" int snprintf(); #line 266 "D:\eli\cpp_stuff\libc_include/stdio.h" int sniprintf(); #line 268 "D:\eli\cpp_stuff\libc_include/stdio.h" char * tempnam(); int vasiprintf(); #line 271 "D:\eli\cpp_stuff\libc_include/stdio.h" char * vasniprintf(); #line 273 "D:\eli\cpp_stuff\libc_include/stdio.h" char * vasnprintf(); #line 275 "D:\eli\cpp_stuff\libc_include/stdio.h" int vasprintf(); #line 277 "D:\eli\cpp_stuff\libc_include/stdio.h" int vdiprintf(); #line 279 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfiprintf(); #line 281 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfiscanf(); #line 283 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfscanf(); #line 285 "D:\eli\cpp_stuff\libc_include/stdio.h" int viprintf(); #line 287 "D:\eli\cpp_stuff\libc_include/stdio.h" int viscanf(); #line 289 "D:\eli\cpp_stuff\libc_include/stdio.h" int vscanf(); #line 291 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsiprintf(); #line 293 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsiscanf(); #line 295 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsniprintf(); #line 297 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsnprintf(); #line 299 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsscanf(); #line 301 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 307 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * fdopen(); int fileno(); int getw(); int pclose(); FILE * popen(); int putw(); void setbuffer(); int setlinebuf(); int getc_unlocked(); int getchar_unlocked(); void flockfile(); int ftrylockfile(); void funlockfile(); int putc_unlocked(); int putchar_unlocked(); #line 331 "D:\eli\cpp_stuff\libc_include/stdio.h" int dprintf(); #line 337 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * fmemopen(); FILE * open_memstream(); int vdprintf(); #line 345 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 351 "D:\eli\cpp_stuff\libc_include/stdio.h" int _asiprintf_r(); #line 354 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _asniprintf_r(); #line 356 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _asnprintf_r(); #line 358 "D:\eli\cpp_stuff\libc_include/stdio.h" int _asprintf_r(); #line 360 "D:\eli\cpp_stuff\libc_include/stdio.h" int _diprintf_r(); #line 362 "D:\eli\cpp_stuff\libc_include/stdio.h" int _dprintf_r(); #line 364 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fclose_r(); int _fcloseall_r(); FILE * _fdopen_r(); int _fflush_r(); char * _fgets_r(); int _fiprintf_r(); #line 371 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fiscanf_r(); #line 373 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * _fmemopen_r(); FILE * _fopen_r(); int _fprintf_r(); #line 377 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fputc_r(); int _fputs_r(); size_t _fread_r(); int _fscanf_r(); #line 382 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fseek_r(); long _ftell_r(); size_t _fwrite_r(); int _getc_r(); int _getc_unlocked_r(); int _getchar_r(); int _getchar_unlocked_r(); char * _gets_r(); int _iprintf_r(); #line 392 "D:\eli\cpp_stuff\libc_include/stdio.h" int _iscanf_r(); #line 394 "D:\eli\cpp_stuff\libc_include/stdio.h" int _mkstemp_r(); char * _mktemp_r(); FILE * _open_memstream_r(); void _perror_r(); int _printf_r(); #line 400 "D:\eli\cpp_stuff\libc_include/stdio.h" int _putc_r(); int _putc_unlocked_r(); int _putchar_unlocked_r(); int _putchar_r(); int _puts_r(); int _remove_r(); int _rename_r(); #line 408 "D:\eli\cpp_stuff\libc_include/stdio.h" int _scanf_r(); #line 410 "D:\eli\cpp_stuff\libc_include/stdio.h" int _siprintf_r(); #line 412 "D:\eli\cpp_stuff\libc_include/stdio.h" int _siscanf_r(); #line 414 "D:\eli\cpp_stuff\libc_include/stdio.h" int _sniprintf_r(); #line 416 "D:\eli\cpp_stuff\libc_include/stdio.h" int _snprintf_r(); #line 418 "D:\eli\cpp_stuff\libc_include/stdio.h" int _sprintf_r(); #line 420 "D:\eli\cpp_stuff\libc_include/stdio.h" int _sscanf_r(); #line 422 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _tempnam_r(); FILE * _tmpfile_r(); char * _tmpnam_r(); int _ungetc_r(); int _vasiprintf_r(); #line 428 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _vasniprintf_r(); #line 430 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _vasnprintf_r(); #line 432 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vasprintf_r(); #line 434 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vdiprintf_r(); #line 436 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vdprintf_r(); #line 438 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfiprintf_r(); #line 440 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfiscanf_r(); #line 442 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfprintf_r(); #line 444 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfscanf_r(); #line 446 "D:\eli\cpp_stuff\libc_include/stdio.h" int _viprintf_r(); #line 448 "D:\eli\cpp_stuff\libc_include/stdio.h" int _viscanf_r(); #line 450 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vprintf_r(); #line 452 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vscanf_r(); #line 454 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsiprintf_r(); #line 456 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsiscanf_r(); #line 458 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsniprintf_r(); #line 460 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsnprintf_r(); #line 462 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsprintf_r(); #line 464 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsscanf_r(); #line 466 "D:\eli\cpp_stuff\libc_include/stdio.h" ssize_t __getdelim(); ssize_t __getline(); #line 493 "D:\eli\cpp_stuff\libc_include/stdio.h" int __srget_r(); int __swbuf_r(); #line 500 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * funopen(); #line 514 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 518 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 520 "D:\eli\cpp_stuff\libc_include/stdio.h" typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n); typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf, size_t __n); typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence); typedef int cookie_close_function_t(void *__cookie); typedef struct { #line 535 "D:\eli\cpp_stuff\libc_include/stdio.h" cookie_read_function_t *read; cookie_write_function_t *write; cookie_seek_function_t *seek; cookie_close_function_t *close; } cookie_io_functions_t; FILE * fopencookie(); #line 542 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 549 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 574 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 580 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 603 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 613 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 621 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 626 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 657 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 4 "example_c_file.c" #line 8 "example_c_file.c" char tav = 'b'; char maav = L"'guruguru\n"; char* moral = "ain't I \\\"\\\t\" a nice string?\"\""; char* comment_inside = "but you will /* see it */!!!!"; char* i_have_newlines = "line one\nline two\nline three"; int main() { auto char* multi = "a multi"; }
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/cppd_with_stdio_h.c
C
apache-2.0
35,859
#define PERFECTLY #define NORMAL #define TO #define HAVE #define HEADER #define WITH #define ONLY #define DEFINES
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/empty.h
C
apache-2.0
114
char tav = 'b'; char* moral = "ain't I \\\"\\\t\" a nice string?\"\""; char* comment_inside = "but you will /* see it */!!!!"; char* i_have_newlines = "line one\nline two\nline three"; int main() { auto char* multi = "a multi"; }
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/example_c_file.c
C
apache-2.0
250
extern int ie;
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/hdir/9/inc.h
C
apache-2.0
15
//---------------------------------------------------------------- // Statically-allocated memory manager // // by Eli Bendersky (eliben@gmail.com) // // This code is in the public domain. //---------------------------------------------------------------- #include "memmgr.h" typedef ulong Align; union mem_header_union { struct { // Pointer to the next block in the free list // union mem_header_union* next; // Size of the block (in quantas of sizeof(mem_header_t)) // ulong size; } s; // Used to align headers in memory to a boundary // Align align_dummy; }; typedef union mem_header_union mem_header_t; // Initial empty list // static mem_header_t base; // Start of free list // static mem_header_t* freep = 0; // Static pool for new allocations // static byte pool[POOL_SIZE] = {0}; static ulong pool_free_pos = 0; void memmgr_init() { base.s.next = 0; base.s.size = 0; freep = 0; pool_free_pos = 0; } static mem_header_t* get_mem_from_pool(ulong nquantas) { ulong total_req_size; mem_header_t* h; if (nquantas < MIN_POOL_ALLOC_QUANTAS) nquantas = MIN_POOL_ALLOC_QUANTAS; total_req_size = nquantas * sizeof(mem_header_t); if (pool_free_pos + total_req_size <= POOL_SIZE) { h = (mem_header_t*) (pool + pool_free_pos); h->s.size = nquantas; memmgr_free((void*) (h + 1)); pool_free_pos += total_req_size; } else { return 0; } return freep; } // Allocations are done in 'quantas' of header size. // The search for a free block of adequate size begins at the point 'freep' // where the last block was found. // If a too-big block is found, it is split and the tail is returned (this // way the header of the original needs only to have its size adjusted). // The pointer returned to the user points to the free space within the block, // which begins one quanta after the header. // void* memmgr_alloc(ulong nbytes) { mem_header_t* p; mem_header_t* prevp; // Calculate how many quantas are required: we need enough to house all // the requested bytes, plus the header. The -1 and +1 are there to make sure // that if nbytes is a multiple of nquantas, we don't allocate too much // ulong nquantas = (nbytes + sizeof(mem_header_t) - 1) / sizeof(mem_header_t) + 1; // First alloc call, and no free list yet ? Use 'base' for an initial // denegerate block of size 0, which points to itself // if ((prevp = freep) == 0) { base.s.next = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.next; ; prevp = p, p = p->s.next) { // big enough ? if (p->s.size >= nquantas) { // exactly ? if (p->s.size == nquantas) { // just eliminate this block from the free list by pointing // its prev's next to its next // prevp->s.next = p->s.next; } else // too big { p->s.size -= nquantas; p += p->s.size; p->s.size = nquantas; } freep = prevp; return (void*) (p + 1); } // Reached end of free list ? // Try to allocate the block from the pool. If that succeeds, // get_mem_from_pool adds the new block to the free list and // it will be found in the following iterations. If the call // to get_mem_from_pool doesn't succeed, we've run out of // memory // else if (p == freep) { if ((p = get_mem_from_pool(nquantas)) == 0) { #ifdef DEBUG_MEMMGR_FATAL printf("!! Memory allocation failed !!\n"); #endif return 0; } } } } // Scans the free list, starting at freep, looking the the place to insert the // free block. This is either between two existing blocks or at the end of the // list. In any case, if the block being freed is adjacent to either neighbor, // the adjacent blocks are combined. // void memmgr_free(void* ap) { mem_header_t* block; mem_header_t* p; // acquire pointer to block header block = ((mem_header_t*) ap) - 1; // Find the correct place to place the block in (the free list is sorted by // address, increasing order) // for (p = freep; !(block > p && block < p->s.next); p = p->s.next) { // Since the free list is circular, there is one link where a // higher-addressed block points to a lower-addressed block. // This condition checks if the block should be actually // inserted between them // if (p >= p->s.next && (block > p || block < p->s.next)) break; } // Try to combine with the higher neighbor // if (block + block->s.size == p->s.next) { block->s.size += p->s.next->s.size; block->s.next = p->s.next->s.next; } else { block->s.next = p->s.next; } // Try to combine with the lower neighbor // if (p + p->s.size == block) { p->s.size += block->s.size; p->s.next = block->s.next; } else { p->s.next = block; } freep = p; }
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/memmgr.c
C
apache-2.0
5,597
//---------------------------------------------------------------- // Statically-allocated memory manager // // by Eli Bendersky (eliben@gmail.com) // // This code is in the public domain. //---------------------------------------------------------------- #ifndef MEMMGR_H #define MEMMGR_H // // Memory manager: dynamically allocates memory from // a fixed pool that is allocated statically at link-time. // // Usage: after calling memmgr_init() in your // initialization routine, just use memmgr_alloc() instead // of malloc() and memmgr_free() instead of free(). // Naturally, you can use the preprocessor to define // malloc() and free() as aliases to memmgr_alloc() and // memmgr_free(). This way the manager will be a drop-in // replacement for the standard C library allocators, and can // be useful for debugging memory allocation problems and // leaks. // // Preprocessor flags you can define to customize the // memory manager: // // DEBUG_MEMMGR_FATAL // Allow printing out a message when allocations fail // // DEBUG_MEMMGR_SUPPORT_STATS // Allow printing out of stats in function // memmgr_print_stats When this is disabled, // memmgr_print_stats does nothing. // // Note that in production code on an embedded system // you'll probably want to keep those undefined, because // they cause printf to be called. // // POOL_SIZE // Size of the pool for new allocations. This is // effectively the heap size of the application, and can // be changed in accordance with the available memory // resources. // // MIN_POOL_ALLOC_QUANTAS // Internally, the memory manager allocates memory in // quantas roughly the size of two ulong objects. To // minimize pool fragmentation in case of multiple allocations // and deallocations, it is advisable to not allocate // blocks that are too small. // This flag sets the minimal ammount of quantas for // an allocation. If the size of a ulong is 4 and you // set this flag to 16, the minimal size of an allocation // will be 4 * 2 * 16 = 128 bytes // If you have a lot of small allocations, keep this value // low to conserve memory. If you have mostly large // allocations, it is best to make it higher, to avoid // fragmentation. // // Notes: // 1. This memory manager is *not thread safe*. Use it only // for single thread/task applications. // #define DEBUG_MEMMGR_SUPPORT_STATS 1 #define POOL_SIZE 8 * 1024 #define MIN_POOL_ALLOC_QUANTAS 16 typedef unsigned char byte; typedef unsigned long ulong; // Initialize the memory manager. This function should be called // only once in the beginning of the program. // void memmgr_init(); // 'malloc' clone // void* memmgr_alloc(ulong nbytes); // 'free' clone // void memmgr_free(void* ap); // Prints statistics about the current state of the memory // manager // void memmgr_print_stats(); #endif // MEMMGR_H
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/memmgr.h
C
apache-2.0
2,999
#line 1 "memmgr.c" #line 1 "./memmgr.h" typedef unsigned char byte; typedef unsigned long ulong; void memmgr_init(); void* memmgr_alloc(ulong nbytes); void memmgr_free(void* ap); void memmgr_print_stats(); #line 9 "memmgr.c" typedef ulong Align; union mem_header_union { struct { union mem_header_union* next; ulong size; } s; Align align_dummy; }; typedef union mem_header_union mem_header_t; static mem_header_t base; static mem_header_t* freep = 0; static byte pool[8 * 1024] = {0}; static ulong pool_free_pos = 0; void memmgr_init() { base.s.next = 0; base.s.size = 0; freep = 0; pool_free_pos = 0; } void memmgr_print_stats() { mem_header_t* p; printf("------ Memory manager stats ------\n\n"); printf( "Pool: free_pos = %lu (%lu bytes left)\n\n", pool_free_pos,8 * 1024 - pool_free_pos); p = (mem_header_t*) pool; while (p < (mem_header_t*) (pool + pool_free_pos)) { printf( " * Addr: 0x%8lu; Size: %8lu\n", p, p->s.size); p += p->s.size; } printf("\nFree list:\n\n"); if (freep) { p = freep; while (1) { printf( " * Addr: 0x%8lu; Size: %8lu; Next: 0x%8lu\n", p, p->s.size, p->s.next); p = p->s.next; if (p == freep) break; } } else { printf("Empty\n"); } printf("\n"); } static mem_header_t* get_mem_from_pool(ulong nquantas) { ulong total_req_size; mem_header_t* h; if (nquantas < 16) nquantas = 16; total_req_size = nquantas * sizeof(mem_header_t); if (pool_free_pos + total_req_size <= 8 * 1024) { h = (mem_header_t*) (pool + pool_free_pos); h->s.size = nquantas; memmgr_free((void*) (h + 1)); pool_free_pos += total_req_size; } else { return 0; } return freep; } void* memmgr_alloc(ulong nbytes) { mem_header_t* p; mem_header_t* prevp; ulong nquantas = (nbytes + sizeof(mem_header_t) - 1) / sizeof(mem_header_t) + 1; if ((prevp = freep) == 0) { base.s.next = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.next; ; prevp = p, p = p->s.next) { if (p->s.size >= nquantas) { if (p->s.size == nquantas) { prevp->s.next = p->s.next; } else { p->s.size -= nquantas; p += p->s.size; p->s.size = nquantas; } freep = prevp; return (void*) (p + 1); } else if (p == freep) { if ((p = get_mem_from_pool(nquantas)) == 0) { return 0; } } } } void memmgr_free(void* ap) { mem_header_t* block; mem_header_t* p; block = ((mem_header_t*) ap) - 1; for (p = freep; !(block > p && block < p->s.next); p = p->s.next) { if (p >= p->s.next && (block > p || block < p->s.next)) break; } if (block + block->s.size == p->s.next) { block->s.size += p->s.next->s.size; block->s.next = p->s.next->s.next; } else { block->s.next = p->s.next; } if (p + p->s.size == block) { p->s.size += block->s.size; p->s.next = block->s.next; } else { p->s.next = block; } freep = p; }
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/memmgr_with_h.c
C
apache-2.0
4,038
#include "hdir\emptydir\..\9\inc.h" int main() { return 0; }
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/simplemain.c
C
apache-2.0
64
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdbool.h> /* C99 bools */ _Bool just_a_flag = false; bool another_flag = true; void convert(int thousands, int hundreds, int tens, int ones) { char *num[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; char *for_ten[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty"}; char *af_ten[] = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen"}; printf("\nThe year in words is:\n"); printf("%s thousand", num[thousands]); if (hundreds != 0) printf(" %s hundred", num[hundreds]); if (tens != 1) printf(" %s %s", for_ten[tens], num[ones]); else printf(" %s", af_ten[ones]); va_list jajaja; } int main() { int year; int n1000, n100, n10, n1; printf("\nEnter the year (4 digits): "); scanf("%d", &year); if (year > 9999 || year < 1000) { printf("\nError !! The year must contain 4 digits."); exit(EXIT_FAILURE); } n1000 = year/1000; n100 = ((year)%1000)/100; n10 = (year%100)/10; n1 = ((year%10)%10); convert(n1000, n100, n10, n1); return 0; }
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/c_files/year.c
C
apache-2.0
1,281
import pprint import re import sys import unittest import weakref sys.path.insert(0, '..') import pycparser.c_ast as c_ast import pycparser.plyparser as plyparser class Test_c_ast(unittest.TestCase): def test_BinaryOp(self): b1 = c_ast.BinaryOp( op='+', left=c_ast.Constant(type='int', value='6'), right=c_ast.ID(name='joe')) self.assertIsInstance(b1.left, c_ast.Constant) self.assertEqual(b1.left.type, 'int') self.assertEqual(b1.left.value, '6') self.assertIsInstance(b1.right, c_ast.ID) self.assertEqual(b1.right.name, 'joe') def test_weakref_works_on_nodes(self): c1 = c_ast.Constant(type='float', value='3.14') wr = weakref.ref(c1) cref = wr() self.assertEqual(cref.type, 'float') self.assertEqual(weakref.getweakrefcount(c1), 1) def test_weakref_works_on_coord(self): coord = plyparser.Coord(file='a', line=2) wr = weakref.ref(coord) cref = wr() self.assertEqual(cref.line, 2) self.assertEqual(weakref.getweakrefcount(coord), 1) class TestNodeVisitor(unittest.TestCase): class ConstantVisitor(c_ast.NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) def test_scalar_children(self): b1 = c_ast.BinaryOp( op='+', left=c_ast.Constant(type='int', value='6'), right=c_ast.ID(name='joe')) cv = self.ConstantVisitor() cv.visit(b1) self.assertEqual(cv.values, ['6']) b2 = c_ast.BinaryOp( op='*', left=c_ast.Constant(type='int', value='111'), right=b1) b3 = c_ast.BinaryOp( op='^', left=b2, right=b1) cv = self.ConstantVisitor() cv.visit(b3) self.assertEqual(cv.values, ['111', '6', '6']) def tests_list_children(self): c1 = c_ast.Constant(type='float', value='5.6') c2 = c_ast.Constant(type='char', value='t') b1 = c_ast.BinaryOp( op='+', left=c1, right=c2) b2 = c_ast.BinaryOp( op='-', left=b1, right=c2) comp = c_ast.Compound( block_items=[b1, b2, c1, c2]) cv = self.ConstantVisitor() cv.visit(comp) self.assertEqual(cv.values, ['5.6', 't', '5.6', 't', 't', '5.6', 't']) def test_repr(self): c1 = c_ast.Constant(type='float', value='5.6') c2 = c_ast.Constant(type='char', value='t') b1 = c_ast.BinaryOp( op='+', left=c1, right=c2) b2 = c_ast.BinaryOp( op='-', left=b1, right=c2) comp = c_ast.Compound( block_items=[b1, b2, c1, c2]) expected = ("Compound(block_items=[BinaryOp(op='+',\n" " left=Constant(type='float',\n" " value='5.6'\n" " ),\n" " right=Constant(type='char',\n" " value='t'\n" " )\n" " ),\n" " BinaryOp(op='-',\n" " left=BinaryOp(op='+',\n" " left=Constant(type='float',\n" " value='5.6'\n" " ),\n" " right=Constant(type='char',\n" " value='t'\n" " )\n" " ),\n" " right=Constant(type='char',\n" " value='t'\n" " )\n" " ),\n" " Constant(type='float',\n" " value='5.6'\n" " ),\n" " Constant(type='char',\n" " value='t'\n" " )\n" " ]\n" " )") self.assertEqual(repr(comp), expected) if __name__ == '__main__': unittest.main()
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/test_c_ast.py
Python
apache-2.0
5,171
import os import platform import sys import unittest # Run from the root dir sys.path.insert(0, '.') from pycparser import c_parser, c_generator, c_ast, parse_file _c_parser = c_parser.CParser( lex_optimize=False, yacc_debug=True, yacc_optimize=False, yacctab='yacctab') def compare_asts(ast1, ast2): if type(ast1) != type(ast2): return False if isinstance(ast1, tuple) and isinstance(ast2, tuple): if ast1[0] != ast2[0]: return False ast1 = ast1[1] ast2 = ast2[1] return compare_asts(ast1, ast2) for attr in ast1.attr_names: if getattr(ast1, attr) != getattr(ast2, attr): return False for i, c1 in enumerate(ast1.children()): if compare_asts(c1, ast2.children()[i]) == False: return False return True def parse_to_ast(src): return _c_parser.parse(src) class TestFunctionDeclGeneration(unittest.TestCase): class _FuncDeclVisitor(c_ast.NodeVisitor): def __init__(self): self.stubs = [] def visit_FuncDecl(self, node): gen = c_generator.CGenerator() self.stubs.append(gen.visit(node)) def test_partial_funcdecl_generation(self): src = r''' void noop(void); void *something(void *thing); int add(int x, int y);''' ast = parse_to_ast(src) v = TestFunctionDeclGeneration._FuncDeclVisitor() v.visit(ast) self.assertEqual(len(v.stubs), 3) self.assertTrue(r'void noop(void)' in v.stubs) self.assertTrue(r'void *something(void *thing)' in v.stubs) self.assertTrue(r'int add(int x, int y)' in v.stubs) class TestCtoC(unittest.TestCase): def _run_c_to_c(self, src, *args, **kwargs): ast = parse_to_ast(src) generator = c_generator.CGenerator(*args, **kwargs) return generator.visit(ast) def _assert_ctoc_correct(self, src, *args, **kwargs): """ Checks that the c2c translation was correct by parsing the code generated by c2c for src and comparing the AST with the original AST. Additional arguments are passed to CGenerator.__init__. """ src2 = self._run_c_to_c(src, *args, **kwargs) self.assertTrue(compare_asts(parse_to_ast(src), parse_to_ast(src2)), "{!r} != {!r}".format(src, src2)) return src2 def test_trivial_decls(self): self._assert_ctoc_correct('int a;') self._assert_ctoc_correct('int b, a;') self._assert_ctoc_correct('int c, b, a;') def test_complex_decls(self): self._assert_ctoc_correct('int** (*a)(void);') self._assert_ctoc_correct('int** (*a)(void*, int);') self._assert_ctoc_correct('int (*b)(char * restrict k, float);') self._assert_ctoc_correct('int test(const char* const* arg);') self._assert_ctoc_correct('int test(const char** const arg);') def test_ternary(self): self._assert_ctoc_correct(''' int main(void) { int a, b; (a == 0) ? (b = 1) : (b = 2); }''') def test_casts(self): self._assert_ctoc_correct(r''' int main() { int b = (int) f; int c = (int*) f; }''') self._assert_ctoc_correct(r''' int main() { int a = (int) b + 8; int t = (int) c; } ''') def test_initlist(self): self._assert_ctoc_correct('int arr[] = {1, 2, 3};') def test_exprs(self): self._assert_ctoc_correct(''' int main(void) { int a; int b = a++; int c = ++a; int d = a--; int e = --a; }''') def test_statements(self): # note two minuses here self._assert_ctoc_correct(r''' int main() { int a; a = 5; ; b = - - a; return a; }''') def test_struct_decl(self): self._assert_ctoc_correct(r''' typedef struct node_t { struct node_t* next; int data; } node; ''') def test_krstyle(self): self._assert_ctoc_correct(r''' int main(argc, argv) int argc; char** argv; { return 0; } ''') def test_switchcase(self): self._assert_ctoc_correct(r''' int main() { switch (myvar) { case 10: { k = 10; p = k + 1; break; } case 20: case 30: return 20; default: break; } } ''') def test_nest_initializer_list(self): self._assert_ctoc_correct(r''' int main() { int i[1][1] = { { 1 } }; }''') def test_nest_named_initializer(self): self._assert_ctoc_correct(r'''struct test { int i; struct test_i_t { int k; } test_i; int j; }; struct test test_var = {.i = 0, .test_i = {.k = 1}, .j = 2}; ''') def test_expr_list_in_initializer_list(self): self._assert_ctoc_correct(r''' int main() { int i[1] = { (1, 2) }; }''') def test_issue36(self): self._assert_ctoc_correct(r''' int main() { }''') def test_issue37(self): self._assert_ctoc_correct(r''' int main(void) { unsigned size; size = sizeof(size); return 0; }''') def test_issue66(self): # A non-existing body must not be generated # (previous valid behavior, still working) self._assert_ctoc_correct(r''' struct foo; ''') # An empty body must be generated # (added behavior) self._assert_ctoc_correct(r''' struct foo {}; ''') def test_issue83(self): self._assert_ctoc_correct(r''' void x(void) { int i = (9, k); } ''') def test_issue84(self): self._assert_ctoc_correct(r''' void x(void) { for (int i = 0;;) i; } ''') def test_issue246(self): self._assert_ctoc_correct(r''' int array[3] = {[0] = 0, [1] = 1, [1+1] = 2}; ''') def test_exprlist_with_semi(self): self._assert_ctoc_correct(r''' void x() { if (i < j) tmp = C[i], C[i] = C[j], C[j] = tmp; if (i <= j) i++, j--; } ''') def test_exprlist_with_subexprlist(self): self._assert_ctoc_correct(r''' void x() { (a = b, (b = c, c = a)); } ''') def test_comma_operator_funcarg(self): self._assert_ctoc_correct(r''' void f(int x) { return x; } int main(void) { f((1, 2)); return 0; } ''') def test_comma_op_in_ternary(self): self._assert_ctoc_correct(r''' void f() { (0, 0) ? (0, 0) : (0, 0); } ''') def test_comma_op_assignment(self): self._assert_ctoc_correct(r''' void f() { i = (a, b, c); } ''') def test_pragma(self): self._assert_ctoc_correct(r''' #pragma foo void f() { #pragma bar i = (a, b, c); } typedef struct s { #pragma baz } s; ''') def test_compound_literal(self): self._assert_ctoc_correct('char **foo = (char *[]){ "x", "y", "z" };') self._assert_ctoc_correct('int i = ++(int){ 1 };') self._assert_ctoc_correct('struct foo_s foo = (struct foo_s){ 1, 2 };') def test_enum(self): self._assert_ctoc_correct(r''' enum e { a, b = 2, c = 3 }; ''') self._assert_ctoc_correct(r''' enum f { g = 4, h, i }; ''') def test_enum_typedef(self): self._assert_ctoc_correct('typedef enum EnumName EnumTypedefName;') def test_generate_struct_union_enum_exception(self): generator = c_generator.CGenerator() self.assertRaises( AssertionError, generator._generate_struct_union_enum, n=c_ast.Struct( name='TestStruct', decls=[], ), name='', ) def test_array_decl(self): self._assert_ctoc_correct('int g(const int a[const 20]){}') ast = parse_to_ast('const int a[const 20];') generator = c_generator.CGenerator() self.assertEqual(generator.visit(ast.ext[0].type), 'const int [const 20]') self.assertEqual(generator.visit(ast.ext[0].type.type), 'const int') def test_ptr_decl(self): src = 'const int ** const x;' self._assert_ctoc_correct(src) ast = parse_to_ast(src) generator = c_generator.CGenerator() self.assertEqual(generator.visit(ast.ext[0].type), 'const int ** const') self.assertEqual(generator.visit(ast.ext[0].type.type), 'const int *') self.assertEqual(generator.visit(ast.ext[0].type.type.type), 'const int') def test_nested_sizeof(self): src = '1' for _ in range(30): src = 'sizeof(' + src + ')' src = 'int x = ' + src + ';' self._assert_ctoc_correct(src) def test_reduce_parentheses_binaryops(self): c1 = 'int x = a + b + c + d;'; self.assertEqual(self._run_c_to_c(c1), 'int x = ((a + b) + c) + d;\n') self.assertEqual( self._run_c_to_c(c1, reduce_parentheses=True), 'int x = a + b + c + d;\n') # codes with minimum number of (necessary) parenthesis: test_snippets = [ 'int x = a*b*c*d;', 'int x = a+b*c*d;', 'int x = a*b+c*d;', 'int x = a*b*c+d;', 'int x = (a+b)*c*d;', 'int x = (a+b)*(c+d);', 'int x = (a+b)/(c-d);', 'int x = a+b-c-d;', 'int x = a+(b-c)-d;' ] for src in test_snippets: src2 = self._assert_ctoc_correct(src, reduce_parentheses=True) self.assertTrue( src2.count('(') == src.count('('), msg="{!r} did not have minimum number of parenthesis, should be like {!r}.".format( src2, src)) class TestCasttoC(unittest.TestCase): def _find_file(self, name): test_dir = os.path.dirname(__file__) name = os.path.join(test_dir, 'c_files', name) assert os.path.exists(name) return name def test_to_type(self): src = 'int *x;' generator = c_generator.CGenerator() test_fun = c_ast.FuncCall(c_ast.ID('test_fun'), c_ast.ExprList([])) ast1 = parse_to_ast(src) int_ptr_type = ast1.ext[0].type int_type = int_ptr_type.type self.assertEqual(generator.visit(c_ast.Cast(int_ptr_type, test_fun)), '(int *) test_fun()') self.assertEqual(generator.visit(c_ast.Cast(int_type, test_fun)), '(int) test_fun()') @unittest.skipUnless(platform.system() == 'Linux', 'cpp only works on Linux') def test_to_type_with_cpp(self): generator = c_generator.CGenerator() test_fun = c_ast.FuncCall(c_ast.ID('test_fun'), c_ast.ExprList([])) memmgr_path = self._find_file('memmgr.h') ast2 = parse_file(memmgr_path, use_cpp=True) void_ptr_type = ast2.ext[-3].type.type void_type = void_ptr_type.type self.assertEqual(generator.visit(c_ast.Cast(void_ptr_type, test_fun)), '(void *) test_fun()') self.assertEqual(generator.visit(c_ast.Cast(void_type, test_fun)), '(void) test_fun()') def test_nested_else_if_line_breaks(self): generator = c_generator.CGenerator() test_ast1 = c_ast.If(None, None, None) test_ast2 = c_ast.If(None, None, c_ast.If(None, None, None)) test_ast3 = c_ast.If(None, None, c_ast.If(None, None, c_ast.If(None, None, None))) test_ast4 = c_ast.If(None, c_ast.Compound([]), c_ast.If(None, c_ast.Compound([]), c_ast.If(None, c_ast.Compound([]), None))) self.assertEqual(generator.visit(test_ast1), 'if ()\n \n') self.assertEqual(generator.visit(test_ast2), 'if ()\n \nelse\n if ()\n \n') self.assertEqual(generator.visit(test_ast3), 'if ()\n \nelse\n if ()\n \nelse\n if ()\n \n') self.assertEqual(generator.visit(test_ast4), 'if ()\n{\n}\nelse\n if ()\n{\n}\nelse\n if ()\n{\n}\n') if __name__ == "__main__": unittest.main()
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/test_c_generator.py
Python
apache-2.0
13,686
import re import sys import unittest sys.path.insert(0, '..') from pycparser.c_lexer import CLexer def token_list(clex): return list(iter(clex.token, None)) def token_types(clex): return [i.type for i in token_list(clex)] class TestCLexerNoErrors(unittest.TestCase): """ Test lexing of strings that are not supposed to cause errors. Therefore, the error_func passed to the lexer raises an exception. """ def error_func(self, msg, line, column): self.fail(msg) def on_lbrace_func(self): pass def on_rbrace_func(self): pass def type_lookup_func(self, typ): if typ.startswith('mytype'): return True else: return False def setUp(self): self.clex = CLexer(self.error_func, lambda: None, lambda: None, self.type_lookup_func) self.clex.build(optimize=False) def assertTokensTypes(self, str, types): self.clex.input(str) self.assertEqual(token_types(self.clex), types) def test_trivial_tokens(self): self.assertTokensTypes('1', ['INT_CONST_DEC']) self.assertTokensTypes('-', ['MINUS']) self.assertTokensTypes('volatile', ['VOLATILE']) self.assertTokensTypes('...', ['ELLIPSIS']) self.assertTokensTypes('++', ['PLUSPLUS']) self.assertTokensTypes('case int', ['CASE', 'INT']) self.assertTokensTypes('caseint', ['ID']) self.assertTokensTypes('$dollar cent$', ['ID', 'ID']) self.assertTokensTypes('i ^= 1;', ['ID', 'XOREQUAL', 'INT_CONST_DEC', 'SEMI']) def test_id_typeid(self): self.assertTokensTypes('myt', ['ID']) self.assertTokensTypes('mytype', ['TYPEID']) self.assertTokensTypes('mytype6 var', ['TYPEID', 'ID']) def test_integer_constants(self): self.assertTokensTypes('12', ['INT_CONST_DEC']) self.assertTokensTypes('12u', ['INT_CONST_DEC']) self.assertTokensTypes('12l', ['INT_CONST_DEC']) self.assertTokensTypes('199872Ul', ['INT_CONST_DEC']) self.assertTokensTypes('199872lU', ['INT_CONST_DEC']) self.assertTokensTypes('199872LL', ['INT_CONST_DEC']) self.assertTokensTypes('199872ull', ['INT_CONST_DEC']) self.assertTokensTypes('199872llu', ['INT_CONST_DEC']) self.assertTokensTypes('1009843200000uLL', ['INT_CONST_DEC']) self.assertTokensTypes('1009843200000LLu', ['INT_CONST_DEC']) self.assertTokensTypes('077', ['INT_CONST_OCT']) self.assertTokensTypes('0123456L', ['INT_CONST_OCT']) self.assertTokensTypes('0xf7', ['INT_CONST_HEX']) self.assertTokensTypes('0b110', ['INT_CONST_BIN']) self.assertTokensTypes('0x01202AAbbf7Ul', ['INT_CONST_HEX']) self.assertTokensTypes("'12'", ['INT_CONST_CHAR']) self.assertTokensTypes("'123'", ['INT_CONST_CHAR']) self.assertTokensTypes("'1AB4'", ['INT_CONST_CHAR']) self.assertTokensTypes(r"'1A\n4'", ['INT_CONST_CHAR']) # no 0 before x, so ID catches it self.assertTokensTypes('xf7', ['ID']) # - is MINUS, the rest a constnant self.assertTokensTypes('-1', ['MINUS', 'INT_CONST_DEC']) def test_special_names(self): self.assertTokensTypes('sizeof offsetof', ['SIZEOF', 'OFFSETOF']) def test_floating_constants(self): self.assertTokensTypes('1.5f', ['FLOAT_CONST']) self.assertTokensTypes('01.5', ['FLOAT_CONST']) self.assertTokensTypes('.15L', ['FLOAT_CONST']) self.assertTokensTypes('0.', ['FLOAT_CONST']) # but just a period is a period self.assertTokensTypes('.', ['PERIOD']) self.assertTokensTypes('3.3e-3', ['FLOAT_CONST']) self.assertTokensTypes('.7e25L', ['FLOAT_CONST']) self.assertTokensTypes('6.e+125f', ['FLOAT_CONST']) self.assertTokensTypes('666e666', ['FLOAT_CONST']) self.assertTokensTypes('00666e+3', ['FLOAT_CONST']) # but this is a hex integer + 3 self.assertTokensTypes('0x0666e+3', ['INT_CONST_HEX', 'PLUS', 'INT_CONST_DEC']) def test_hexadecimal_floating_constants(self): self.assertTokensTypes('0xDE.488641p0', ['HEX_FLOAT_CONST']) self.assertTokensTypes('0x.488641p0', ['HEX_FLOAT_CONST']) self.assertTokensTypes('0X12.P0', ['HEX_FLOAT_CONST']) def test_char_constants(self): self.assertTokensTypes(r"""'x'""", ['CHAR_CONST']) self.assertTokensTypes(r"""L'x'""", ['WCHAR_CONST']) self.assertTokensTypes(r"""'\t'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\''""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\?'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\0'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\012'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\x2f'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\x2f12'""", ['CHAR_CONST']) self.assertTokensTypes(r"""L'\xaf'""", ['WCHAR_CONST']) def test_on_rbrace_lbrace(self): braces = [] def on_lbrace(): braces.append('{') def on_rbrace(): braces.append('}') clex = CLexer(self.error_func, on_lbrace, on_rbrace, self.type_lookup_func) clex.build(optimize=False) clex.input('hello { there } } and again }}{') token_list(clex) self.assertEqual(braces, ['{', '}', '}', '}', '}', '{']) def test_string_literal(self): self.assertTokensTypes('"a string"', ['STRING_LITERAL']) self.assertTokensTypes('L"ing"', ['WSTRING_LITERAL']) self.assertTokensTypes( '"i am a string too \t"', ['STRING_LITERAL']) self.assertTokensTypes( r'''"esc\ape \"\'\? \0234 chars \rule"''', ['STRING_LITERAL']) self.assertTokensTypes( r'''"hello 'joe' wanna give it a \"go\"?"''', ['STRING_LITERAL']) self.assertTokensTypes( '"\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123"', ['STRING_LITERAL']) # Note: a-zA-Z and '.-~^_!=&;,' are allowed as escape chars to support #line # directives with Windows paths as filenames (..\..\dir\file) self.assertTokensTypes( r'"\x"', ['STRING_LITERAL']) self.assertTokensTypes( r'"\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z"', ['STRING_LITERAL']) self.assertTokensTypes( r'"C:\x\fa\x1e\xited"', ['STRING_LITERAL']) # The lexer is permissive and allows decimal escapes (not just octal) self.assertTokensTypes( r'"jx\9"', ['STRING_LITERAL']) self.assertTokensTypes( r'"fo\9999999"', ['STRING_LITERAL']) def test_mess(self): self.assertTokensTypes( r'[{}]()', ['LBRACKET', 'LBRACE', 'RBRACE', 'RBRACKET', 'LPAREN', 'RPAREN']) self.assertTokensTypes( r'()||!C&~Z?J', ['LPAREN', 'RPAREN', 'LOR', 'LNOT', 'ID', 'AND', 'NOT', 'ID', 'CONDOP', 'ID']) self.assertTokensTypes( r'+-*/%|||&&&^><>=<===!=', ['PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 'LOR', 'OR', 'LAND', 'AND', 'XOR', 'GT', 'LT', 'GE', 'LE', 'EQ', 'NE']) self.assertTokensTypes( r'++--->?.,;:', ['PLUSPLUS', 'MINUSMINUS', 'ARROW', 'CONDOP', 'PERIOD', 'COMMA', 'SEMI', 'COLON']) def test_exprs(self): self.assertTokensTypes( 'bb-cc', ['ID', 'MINUS', 'ID']) self.assertTokensTypes( 'foo & 0xFF', ['ID', 'AND', 'INT_CONST_HEX']) self.assertTokensTypes( '(2+k) * 62', ['LPAREN', 'INT_CONST_DEC', 'PLUS', 'ID', 'RPAREN', 'TIMES', 'INT_CONST_DEC'],) self.assertTokensTypes( 'x | y >> z', ['ID', 'OR', 'ID', 'RSHIFT', 'ID']) self.assertTokensTypes( 'x <<= z << 5', ['ID', 'LSHIFTEQUAL', 'ID', 'LSHIFT', 'INT_CONST_DEC']) self.assertTokensTypes( 'x = y > 0 ? y : -6', ['ID', 'EQUALS', 'ID', 'GT', 'INT_CONST_OCT', 'CONDOP', 'ID', 'COLON', 'MINUS', 'INT_CONST_DEC']) self.assertTokensTypes( 'a+++b', ['ID', 'PLUSPLUS', 'PLUS', 'ID']) def test_statements(self): self.assertTokensTypes( 'for (int i = 0; i < n; ++i)', ['FOR', 'LPAREN', 'INT', 'ID', 'EQUALS', 'INT_CONST_OCT', 'SEMI', 'ID', 'LT', 'ID', 'SEMI', 'PLUSPLUS', 'ID', 'RPAREN']) self.assertTokensTypes( 'self: goto self;', ['ID', 'COLON', 'GOTO', 'ID', 'SEMI']) self.assertTokensTypes( """ switch (typ) { case TYPE_ID: m = 5; break; default: m = 8; }""", ['SWITCH', 'LPAREN', 'ID', 'RPAREN', 'LBRACE', 'CASE', 'ID', 'COLON', 'ID', 'EQUALS', 'INT_CONST_DEC', 'SEMI', 'BREAK', 'SEMI', 'DEFAULT', 'COLON', 'ID', 'EQUALS', 'INT_CONST_DEC', 'SEMI', 'RBRACE']) def test_preprocessor_line(self): self.assertTokensTypes('#abracadabra', ['PPHASH', 'ID']) str = r""" 546 #line 66 "kwas\df.h" id 4 dsf # 9 armo #line 10 "..\~..\test.h" tok1 #line 99999 "include/me.h" tok2 """ #~ self.clex.filename self.clex.input(str) self.clex.reset_lineno() t1 = self.clex.token() self.assertEqual(t1.type, 'INT_CONST_DEC') self.assertEqual(t1.lineno, 2) t2 = self.clex.token() self.assertEqual(t2.type, 'ID') self.assertEqual(t2.value, 'id') self.assertEqual(t2.lineno, 66) self.assertEqual(self.clex.filename, r'kwas\df.h') for i in range(3): t = self.clex.token() self.assertEqual(t.type, 'ID') self.assertEqual(t.value, 'armo') self.assertEqual(t.lineno, 9) self.assertEqual(self.clex.filename, r'kwas\df.h') t4 = self.clex.token() self.assertEqual(t4.type, 'ID') self.assertEqual(t4.value, 'tok1') self.assertEqual(t4.lineno, 10) self.assertEqual(self.clex.filename, r'..\~..\test.h') t5 = self.clex.token() self.assertEqual(t5.type, 'ID') self.assertEqual(t5.value, 'tok2') self.assertEqual(t5.lineno, 99999) self.assertEqual(self.clex.filename, r'include/me.h') def test_preprocessor_line_funny(self): str = r''' #line 10 "..\6\joe.h" 10 ''' self.clex.input(str) self.clex.reset_lineno() t1 = self.clex.token() self.assertEqual(t1.type, 'INT_CONST_DEC') self.assertEqual(t1.lineno, 10) self.assertEqual(self.clex.filename, r'..\6\joe.h') def test_preprocessor_pragma(self): str = ''' 42 #pragma #pragma helo me #pragma once # pragma omp parallel private(th_id) #\tpragma {pack: 2, smack: 3} #pragma <includeme.h> "nowit.h" #pragma "string" #pragma somestring="some_other_string" #pragma id 124124 and numbers 0235495 59 ''' # Check that pragmas are tokenized, including trailing string self.clex.input(str) self.clex.reset_lineno() t1 = self.clex.token() self.assertEqual(t1.type, 'INT_CONST_DEC') t2 = self.clex.token() self.assertEqual(t2.type, 'PPPRAGMA') t3 = self.clex.token() self.assertEqual(t3.type, 'PPPRAGMA') t4 = self.clex.token() self.assertEqual(t4.type, 'PPPRAGMASTR') self.assertEqual(t4.value, 'helo me') for i in range(3): t = self.clex.token() t5 = self.clex.token() self.assertEqual(t5.type, 'PPPRAGMASTR') self.assertEqual(t5.value, 'omp parallel private(th_id)') for i in range(5): ta = self.clex.token() self.assertEqual(ta.type, 'PPPRAGMA') tb = self.clex.token() self.assertEqual(tb.type, 'PPPRAGMASTR') t6 = self.clex.token() self.assertEqual(t6.type, 'INT_CONST_DEC') self.assertEqual(t6.lineno, 12) # Keeps all the errors the lexer spits in one place, to allow # easier modification if the error syntax changes. # ERR_ILLEGAL_CHAR = 'Illegal character' ERR_OCTAL = 'Invalid octal constant' ERR_UNMATCHED_QUOTE = 'Unmatched \'' ERR_INVALID_CCONST = 'Invalid char constant' ERR_STRING_ESCAPE = 'String contains invalid escape' ERR_FILENAME_BEFORE_LINE = 'filename before line' ERR_LINENUM_MISSING = 'line number missing' ERR_INVALID_LINE_DIRECTIVE = 'invalid #line directive' class TestCLexerErrors(unittest.TestCase): """ Test lexing of erroneous strings. Works by passing an error functions that saves the error in an attribute for later perusal. """ def error_func(self, msg, line, column): self.error = msg def on_lbrace_func(self): pass def on_rbrace_func(self): pass def type_lookup_func(self, typ): return False def setUp(self): self.clex = CLexer(self.error_func, self.on_lbrace_func, self.on_rbrace_func, self.type_lookup_func) self.clex.build(optimize=False) self.error = "" def assertLexerError(self, str, error_like): # feed the string to the lexer self.clex.input(str) # Pulls all tokens from the string. Errors will # be written into self.error by the error_func # callback # token_types(self.clex) # compare the error to the expected self.assertTrue(re.search(error_like, self.error), "\nExpected error matching: %s\nGot: %s" % (error_like, self.error)) # clear last error, for the sake of subsequent invocations self.error = "" def test_trivial_tokens(self): self.assertLexerError('@', ERR_ILLEGAL_CHAR) self.assertLexerError('`', ERR_ILLEGAL_CHAR) self.assertLexerError('\\', ERR_ILLEGAL_CHAR) def test_integer_constants(self): self.assertLexerError('029', ERR_OCTAL) self.assertLexerError('012345678', ERR_OCTAL) def test_char_constants(self): self.assertLexerError("'", ERR_UNMATCHED_QUOTE) self.assertLexerError("'b\n", ERR_UNMATCHED_QUOTE) self.assertLexerError("'\\xaa\n'", ERR_UNMATCHED_QUOTE) self.assertLexerError(r"'123\12a'", ERR_INVALID_CCONST) self.assertLexerError(r"'123\xabg'", ERR_INVALID_CCONST) self.assertLexerError("''", ERR_INVALID_CCONST) self.assertLexerError("'abcjx'", ERR_INVALID_CCONST) self.assertLexerError(r"'\*'", ERR_INVALID_CCONST) def test_string_literals(self): self.assertLexerError(r'"jx\`"', ERR_STRING_ESCAPE) self.assertLexerError(r'"hekllo\* on ix"', ERR_STRING_ESCAPE) self.assertLexerError(r'L"hekllo\* on ix"', ERR_STRING_ESCAPE) # Should not suffer from slow backtracking self.assertLexerError(r'"\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\`\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123"', ERR_STRING_ESCAPE) self.assertLexerError(r'"\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\x23\`\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23\xf1\x23"', ERR_STRING_ESCAPE) # Should not suffer from slow backtracking when there's no end quote self.assertLexerError(r'"\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\`\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\123\12\123456', ERR_ILLEGAL_CHAR) self.assertLexerError(r'"\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\`\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x2\x23456', ERR_ILLEGAL_CHAR) def test_preprocessor(self): self.assertLexerError('#line "ka"', ERR_FILENAME_BEFORE_LINE) self.assertLexerError('#line df', ERR_INVALID_LINE_DIRECTIVE) self.assertLexerError('#line \n', ERR_LINENUM_MISSING) if __name__ == '__main__': unittest.main()
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/test_c_lexer.py
Python
apache-2.0
17,042
#!/usr/bin/env python import pprint import re import os, sys import io import unittest sys.path[0:0] = ['.', '..'] from pycparser import c_parser from pycparser.c_ast import * from pycparser.c_parser import CParser, Coord, ParseError _c_parser = c_parser.CParser( lex_optimize=False, yacc_debug=True, yacc_optimize=False, yacctab='yacctab') def expand_decl(decl): """ Converts the declaration into a nested list. """ typ = type(decl) if typ == TypeDecl: return ['TypeDecl', expand_decl(decl.type)] elif typ == IdentifierType: return ['IdentifierType', decl.names] elif typ == ID: return ['ID', decl.name] elif typ in [Struct, Union]: decls = [expand_decl(d) for d in decl.decls or []] return [typ.__name__, decl.name, decls] elif typ == Enum: if decl.values is None: values = None else: assert isinstance(decl.values, EnumeratorList) values = [enum.name for enum in decl.values.enumerators] return ['Enum', decl.name, values] else: nested = expand_decl(decl.type) if typ == Decl: if decl.quals: return ['Decl', decl.quals, decl.name, nested] else: return ['Decl', decl.name, nested] elif typ == Typename: # for function parameters if decl.quals: return ['Typename', decl.quals, nested] else: return ['Typename', nested] elif typ == ArrayDecl: dimval = decl.dim.value if decl.dim else '' return ['ArrayDecl', dimval, decl.dim_quals, nested] elif typ == PtrDecl: if decl.quals: return ['PtrDecl', decl.quals, nested] else: return ['PtrDecl', nested] elif typ == Typedef: return ['Typedef', decl.name, nested] elif typ == FuncDecl: if decl.args: params = [expand_decl(param) for param in decl.args.params] else: params = [] return ['FuncDecl', params, nested] def expand_init(init): """ Converts an initialization into a nested list """ typ = type(init) if typ == NamedInitializer: des = [expand_init(dp) for dp in init.name] return (des, expand_init(init.expr)) elif typ in (InitList, ExprList): return [expand_init(expr) for expr in init.exprs] elif typ == Constant: return ['Constant', init.type, init.value] elif typ == ID: return ['ID', init.name] elif typ == UnaryOp: return ['UnaryOp', init.op, expand_decl(init.expr)] class TestCParser_base(unittest.TestCase): def parse(self, txt, filename=''): return self.cparser.parse(txt, filename) def setUp(self): self.cparser = _c_parser def assert_coord(self, node, line, column=None, file=None): self.assertEqual(node.coord.line, line) if column is not None: self.assertEqual(node.coord.column, column) if file: self.assertEqual(node.coord.file, file) class TestCParser_fundamentals(TestCParser_base): def get_decl(self, txt, index=0): """ Given a source and an index returns the expanded declaration at that index. FileAST holds a list of 'external declarations'. index is the offset of the desired declaration in that list. """ t = self.parse(txt).ext[index] return expand_decl(t) def get_decl_init(self, txt, index=0): """ Returns the expanded initializer of the declaration at index. """ t = self.parse(txt).ext[index] return expand_init(t.init) def test_FileAST(self): t = self.parse('int a; char c;') self.assertIsInstance(t, FileAST) self.assertEqual(len(t.ext), 2) # empty file t2 = self.parse('') self.assertIsInstance(t2, FileAST) self.assertEqual(len(t2.ext), 0) def test_empty_toplevel_decl(self): code = 'int foo;;' t = self.parse(code) self.assertIsInstance(t, FileAST) self.assertEqual(len(t.ext), 1) self.assertEqual(self.get_decl(code), ['Decl', 'foo', ['TypeDecl', ['IdentifierType', ['int']]]]) def test_initial_semi(self): t = self.parse(';') self.assertEqual(len(t.ext), 0) t = self.parse(';int foo;') self.assertEqual(len(t.ext), 1) self.assertEqual(expand_decl(t.ext[0]), ['Decl', 'foo', ['TypeDecl', ['IdentifierType', ['int']]]]) def test_coords(self): """ Tests the "coordinates" of parsed elements - file name, line and column numbers, with modification insterted by #line directives. """ self.assert_coord(self.parse('int a;').ext[0], 1, 5) t1 = """ int a; int b;\n\n int c; """ f1 = self.parse(t1, filename='test.c') self.assert_coord(f1.ext[0], 2, 13, 'test.c') self.assert_coord(f1.ext[1], 3, 13, 'test.c') self.assert_coord(f1.ext[2], 6, 13, 'test.c') t1_1 = ''' int main() { k = p; printf("%d", b); return 0; }''' f1_1 = self.parse(t1_1, filename='test.c') self.assert_coord(f1_1.ext[0].body.block_items[0], 3, 13, 'test.c') self.assert_coord(f1_1.ext[0].body.block_items[1], 4, 13, 'test.c') t1_2 = ''' int main () { int p = (int) k; }''' f1_2 = self.parse(t1_2, filename='test.c') # make sure that the Cast has a coord (issue 23) self.assert_coord(f1_2.ext[0].body.block_items[0].init, 3, 21, file='test.c') t2 = """ #line 99 int c; """ self.assert_coord(self.parse(t2).ext[0], 99, 13) t3 = """ int dsf; char p; #line 3000 "in.h" char d; """ f3 = self.parse(t3, filename='test.c') self.assert_coord(f3.ext[0], 2, 13, 'test.c') self.assert_coord(f3.ext[1], 3, 14, 'test.c') self.assert_coord(f3.ext[2], 3000, 14, 'in.h') t4 = """ #line 20 "restore.h" int maydler(char); #line 30 "includes/daween.ph" long j, k; #line 50000 char* ro; """ f4 = self.parse(t4, filename='myb.c') self.assert_coord(f4.ext[0], 20, 13, 'restore.h') self.assert_coord(f4.ext[1], 30, 14, 'includes/daween.ph') self.assert_coord(f4.ext[2], 30, 17, 'includes/daween.ph') self.assert_coord(f4.ext[3], 50000, 13, 'includes/daween.ph') t5 = """ int #line 99 c; """ self.assert_coord(self.parse(t5).ext[0], 99, 9) # coord for ellipsis t6 = """ int foo(int j, ...) { }""" f6 = self.parse(t6, filename='z.c') self.assert_coord(self.parse(t6).ext[0].decl.type.args.params[1], 3, 17) def test_forloop_coord(self): t = '''\ void foo() { for(int z=0; z<4; z++){} } ''' s = self.parse(t, filename='f.c') forloop = s.ext[0].body.block_items[0] self.assert_coord(forloop.init, 2, 13, 'f.c') self.assert_coord(forloop.cond, 2, 26, 'f.c') self.assert_coord(forloop.next, 3, 17, 'f.c') def test_simple_decls(self): self.assertEqual(self.get_decl('int a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl('unsigned int a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['unsigned', 'int']]]]) self.assertEqual(self.get_decl('_Bool a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['_Bool']]]]) self.assertEqual(self.get_decl('float _Complex fcc;'), ['Decl', 'fcc', ['TypeDecl', ['IdentifierType', ['float', '_Complex']]]]) self.assertEqual(self.get_decl('char* string;'), ['Decl', 'string', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]) self.assertEqual(self.get_decl('long ar[15];'), ['Decl', 'ar', ['ArrayDecl', '15', [], ['TypeDecl', ['IdentifierType', ['long']]]]]) self.assertEqual(self.get_decl('long long ar[15];'), ['Decl', 'ar', ['ArrayDecl', '15', [], ['TypeDecl', ['IdentifierType', ['long', 'long']]]]]) self.assertEqual(self.get_decl('unsigned ar[];'), ['Decl', 'ar', ['ArrayDecl', '', [], ['TypeDecl', ['IdentifierType', ['unsigned']]]]]) self.assertEqual(self.get_decl('int strlen(char* s);'), ['Decl', 'strlen', ['FuncDecl', [['Decl', 's', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int strcmp(char* s1, char* s2);'), ['Decl', 'strcmp', ['FuncDecl', [ ['Decl', 's1', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]], ['Decl', 's2', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]] ], ['TypeDecl', ['IdentifierType', ['int']]]]]) # function return values and parameters may not have type information self.assertEqual(self.get_decl('extern foobar(foo, bar);'), ['Decl', 'foobar', ['FuncDecl', [ ['ID', 'foo'], ['ID', 'bar'] ], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_int128(self): self.assertEqual(self.get_decl('__int128 a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['__int128']]]]) def test_nested_decls(self): # the fun begins self.assertEqual(self.get_decl('char** ar2D;'), ['Decl', 'ar2D', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(self.get_decl('int (*a)[1][2];'), ['Decl', 'a', ['PtrDecl', ['ArrayDecl', '1', [], ['ArrayDecl', '2', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]]) self.assertEqual(self.get_decl('int *a[1][2];'), ['Decl', 'a', ['ArrayDecl', '1', [], ['ArrayDecl', '2', [], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]]]) self.assertEqual(self.get_decl('char* const* p;'), ['Decl', 'p', ['PtrDecl', ['PtrDecl', ['const'], ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(self.get_decl('char* * const p;'), ['Decl', 'p', ['PtrDecl', ['const'], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(self.get_decl('char ***ar3D[40];'), ['Decl', 'ar3D', ['ArrayDecl', '40', [], ['PtrDecl', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]) self.assertEqual(self.get_decl('char (***ar3D)[40];'), ['Decl', 'ar3D', ['PtrDecl', ['PtrDecl', ['PtrDecl', ['ArrayDecl', '40', [], ['TypeDecl', ['IdentifierType', ['char']]]]]]]]) self.assertEqual(self.get_decl('int (*x[4])(char, int);'), ['Decl', 'x', ['ArrayDecl', '4', [], ['PtrDecl', ['FuncDecl', [ ['Typename', ['TypeDecl', ['IdentifierType', ['char']]]], ['Typename', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]]) self.assertEqual(self.get_decl('char *(*(**foo [][8])())[];'), ['Decl', 'foo', ['ArrayDecl', '', [], ['ArrayDecl', '8', [], ['PtrDecl', ['PtrDecl', ['FuncDecl', [], ['PtrDecl', ['ArrayDecl', '', [], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]]]]) # explore named and unnamed function pointer parameters, # with and without qualifiers # unnamed w/o quals self.assertEqual(self.get_decl('int (*k)(int);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Typename', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # unnamed w/ quals self.assertEqual(self.get_decl('int (*k)(const int);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Typename', ['const'], ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # named w/o quals self.assertEqual(self.get_decl('int (*k)(int q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', 'q', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # named w/ quals self.assertEqual(self.get_decl('int (*k)(const volatile int q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', ['const', 'volatile'], 'q', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) self.assertEqual(self.get_decl('int (*k)(const volatile int* q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', ['const', 'volatile'], 'q', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # restrict qualifier self.assertEqual(self.get_decl('int (*k)(restrict int* q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', ['restrict'], 'q', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) def test_func_decls_with_array_dim_qualifiers(self): # named function parameter self.assertEqual(self.get_decl('int zz(int p[static 10]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '10', ['static'], ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int p[const 10]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '10', ['const'], ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int p[restrict][5]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '', ['restrict'], ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int p[const restrict static 10][5]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '10', ['const', 'restrict', 'static'], ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) # unnamed function parameter self.assertEqual(self.get_decl('int zz(int [const 10]);'), ['Decl', 'zz', ['FuncDecl', [['Typename', ['ArrayDecl', '10', ['const'], ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int [restrict][5]);'), ['Decl', 'zz', ['FuncDecl', [['Typename', ['ArrayDecl', '', ['restrict'], ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int [const restrict volatile 10][5]);'), ['Decl', 'zz', ['FuncDecl', [['Typename', ['ArrayDecl', '10', ['const', 'restrict', 'volatile'], ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_qualifiers_storage_specifiers(self): def assert_qs(txt, index, quals, storage): d = self.parse(txt).ext[index] self.assertEqual(d.quals, quals) self.assertEqual(d.storage, storage) assert_qs("extern int p;", 0, [], ['extern']) assert_qs("const long p = 6;", 0, ['const'], []) d1 = "static const int p, q, r;" for i in range(3): assert_qs(d1, i, ['const'], ['static']) d2 = "static char * const p;" assert_qs(d2, 0, [], ['static']) pdecl = self.parse(d2).ext[0].type self.assertIsInstance(pdecl, PtrDecl) self.assertEqual(pdecl.quals, ['const']) def test_sizeof(self): e = """ void foo() { int a = sizeof k; int b = sizeof(int); int c = sizeof(int**);; char* p = "just to make sure this parses w/o error..."; int d = sizeof(int()); } """ compound = self.parse(e).ext[0].body s1 = compound.block_items[0].init self.assertIsInstance(s1, UnaryOp) self.assertEqual(s1.op, 'sizeof') self.assertIsInstance(s1.expr, ID) self.assertEqual(s1.expr.name, 'k') s2 = compound.block_items[1].init self.assertEqual(expand_decl(s2.expr), ['Typename', ['TypeDecl', ['IdentifierType', ['int']]]]) s3 = compound.block_items[2].init self.assertEqual(expand_decl(s3.expr), ['Typename', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]]) def test_offsetof(self): def expand_ref(n): if isinstance(n, StructRef): return ['StructRef', expand_ref(n.name), expand_ref(n.field)] elif isinstance(n, ArrayRef): return ['ArrayRef', expand_ref(n.name), expand_ref(n.subscript)] elif isinstance(n, ID): return ['ID', n.name] elif isinstance(n, Constant): return ['Constant', n.type, n.value] else: raise TypeError("Unexpected type " + n.__class__.__name__) e = """ void foo() { int a = offsetof(struct S, p); a.b = offsetof(struct sockaddr, sp) + strlen(bar); int a = offsetof(struct S, p.q.r); int a = offsetof(struct S, p[5].q[4][5]); } """ compound = self.parse(e).ext[0].body s1 = compound.block_items[0].init self.assertIsInstance(s1, FuncCall) self.assertIsInstance(s1.name, ID) self.assertEqual(s1.name.name, 'offsetof') self.assertIsInstance(s1.args.exprs[0], Typename) self.assertIsInstance(s1.args.exprs[1], ID) s3 = compound.block_items[2].init self.assertIsInstance(s3.args.exprs[1], StructRef) self.assertEqual(expand_ref(s3.args.exprs[1]), ['StructRef', ['StructRef', ['ID', 'p'], ['ID', 'q']], ['ID', 'r']]) s4 = compound.block_items[3].init self.assertIsInstance(s4.args.exprs[1], ArrayRef) self.assertEqual(expand_ref(s4.args.exprs[1]), ['ArrayRef', ['ArrayRef', ['StructRef', ['ArrayRef', ['ID', 'p'], ['Constant', 'int', '5']], ['ID', 'q']], ['Constant', 'int', '4']], ['Constant', 'int', '5']]) def test_compound_statement(self): e = """ void foo() { } """ compound = self.parse(e).ext[0].body self.assertIsInstance(compound, Compound) self.assert_coord(compound, 2) # The C99 compound literal feature # def test_compound_literals(self): ps1 = self.parse(r''' void foo() { p = (long long){k}; tc = (struct jk){.a = {1, 2}, .b[0] = t}; }''') compound = ps1.ext[0].body.block_items[0].rvalue self.assertEqual(expand_decl(compound.type), ['Typename', ['TypeDecl', ['IdentifierType', ['long', 'long']]]]) self.assertEqual(expand_init(compound.init), [['ID', 'k']]) compound = ps1.ext[0].body.block_items[1].rvalue self.assertEqual(expand_decl(compound.type), ['Typename', ['TypeDecl', ['Struct', 'jk', []]]]) self.assertEqual(expand_init(compound.init), [ ([['ID', 'a']], [['Constant', 'int', '1'], ['Constant', 'int', '2']]), ([['ID', 'b'], ['Constant', 'int', '0']], ['ID', 't'])]) def test_enums(self): e1 = "enum mycolor op;" e1_type = self.parse(e1).ext[0].type.type self.assertIsInstance(e1_type, Enum) self.assertEqual(e1_type.name, 'mycolor') self.assertEqual(e1_type.values, None) e2 = "enum mysize {large=20, small, medium} shoes;" e2_type = self.parse(e2).ext[0].type.type self.assertIsInstance(e2_type, Enum) self.assertEqual(e2_type.name, 'mysize') e2_elist = e2_type.values self.assertIsInstance(e2_elist, EnumeratorList) for e2_eval in e2_elist.enumerators: self.assertIsInstance(e2_eval, Enumerator) self.assertEqual(e2_elist.enumerators[0].name, 'large') self.assertEqual(e2_elist.enumerators[0].value.value, '20') self.assertEqual(e2_elist.enumerators[2].name, 'medium') self.assertEqual(e2_elist.enumerators[2].value, None) # enum with trailing comma (C99 feature) e3 = """ enum { red, blue, green, } color; """ e3_type = self.parse(e3).ext[0].type.type self.assertIsInstance(e3_type, Enum) e3_elist = e3_type.values self.assertIsInstance(e3_elist, EnumeratorList) for e3_eval in e3_elist.enumerators: self.assertIsInstance(e3_eval, Enumerator) self.assertEqual(e3_elist.enumerators[0].name, 'red') self.assertEqual(e3_elist.enumerators[0].value, None) self.assertEqual(e3_elist.enumerators[1].name, 'blue') self.assertEqual(e3_elist.enumerators[2].name, 'green') def test_typedef(self): # without typedef, error s1 = """ node k; """ self.assertRaises(ParseError, self.parse, s1) # now with typedef, works s2 = """ typedef void* node; node k; """ ps2 = self.parse(s2) self.assertEqual(expand_decl(ps2.ext[0]), ['Typedef', 'node', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['void']]]]]) self.assertEqual(expand_decl(ps2.ext[1]), ['Decl', 'k', ['TypeDecl', ['IdentifierType', ['node']]]]) s3 = """ typedef int T; typedef T *pT; pT aa, bb; """ ps3 = self.parse(s3) self.assertEqual(expand_decl(ps3.ext[3]), ['Decl', 'bb', ['TypeDecl', ['IdentifierType', ['pT']]]]) s4 = ''' typedef char* __builtin_va_list; typedef __builtin_va_list __gnuc_va_list; ''' ps4 = self.parse(s4) self.assertEqual(expand_decl(ps4.ext[1]), ['Typedef', '__gnuc_va_list', ['TypeDecl', ['IdentifierType', ['__builtin_va_list']]]]) s5 = '''typedef struct tagHash Hash;''' ps5 = self.parse(s5) self.assertEqual(expand_decl(ps5.ext[0]), ['Typedef', 'Hash', ['TypeDecl', ['Struct', 'tagHash', []]]]) def test_struct_union(self): s1 = """ struct { int id; char* name; } joe; """ self.assertEqual(expand_decl(self.parse(s1).ext[0]), ['Decl', 'joe', ['TypeDecl', ['Struct', None, [ ['Decl', 'id', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'name', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]) s2 = """ struct node p; """ self.assertEqual(expand_decl(self.parse(s2).ext[0]), ['Decl', 'p', ['TypeDecl', ['Struct', 'node', []]]]) s21 = """ union pri ra; """ self.assertEqual(expand_decl(self.parse(s21).ext[0]), ['Decl', 'ra', ['TypeDecl', ['Union', 'pri', []]]]) s3 = """ struct node* p; """ self.assertEqual(expand_decl(self.parse(s3).ext[0]), ['Decl', 'p', ['PtrDecl', ['TypeDecl', ['Struct', 'node', []]]]]) s4 = """ struct node; """ self.assertEqual(expand_decl(self.parse(s4).ext[0]), ['Decl', None, ['Struct', 'node', []]]) s5 = """ union { struct { int type; } n; struct { int type; int intnode; } ni; } u; """ self.assertEqual(expand_decl(self.parse(s5).ext[0]), ['Decl', 'u', ['TypeDecl', ['Union', None, [['Decl', 'n', ['TypeDecl', ['Struct', None, [['Decl', 'type', ['TypeDecl', ['IdentifierType', ['int']]]]]]]], ['Decl', 'ni', ['TypeDecl', ['Struct', None, [['Decl', 'type', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'intnode', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]]]]]) s6 = """ typedef struct foo_tag { void* data; } foo, *pfoo; """ s6_ast = self.parse(s6) self.assertEqual(expand_decl(s6_ast.ext[0]), ['Typedef', 'foo', ['TypeDecl', ['Struct', 'foo_tag', [['Decl', 'data', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['void']]]]]]]]]) self.assertEqual(expand_decl(s6_ast.ext[1]), ['Typedef', 'pfoo', ['PtrDecl', ['TypeDecl', ['Struct', 'foo_tag', [['Decl', 'data', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['void']]]]]]]]]]) s7 = r""" struct _on_exit_args { void * _fnargs[32]; void * _dso_handle[32]; long _fntypes; #line 77 "D:\eli\cpp_stuff\libc_include/sys/reent.h" long _is_cxa; }; """ s7_ast = self.parse(s7, filename='test.c') self.assert_coord(s7_ast.ext[0].type.decls[2], 6, 22, 'test.c') self.assert_coord(s7_ast.ext[0].type.decls[3], 78, 22, r'D:\eli\cpp_stuff\libc_include/sys/reent.h') s8 = """ typedef enum tagReturnCode {SUCCESS, FAIL} ReturnCode; typedef struct tagEntry { char* key; char* value; } Entry; typedef struct tagNode { Entry* entry; struct tagNode* next; } Node; typedef struct tagHash { unsigned int table_size; Node** heads; } Hash; """ s8_ast = self.parse(s8) self.assertEqual(expand_decl(s8_ast.ext[3]), ['Typedef', 'Hash', ['TypeDecl', ['Struct', 'tagHash', [['Decl', 'table_size', ['TypeDecl', ['IdentifierType', ['unsigned', 'int']]]], ['Decl', 'heads', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['Node']]]]]]]]]]) def test_struct_enum(self): s1 = """ struct Foo { enum Bar { A = 1 }; }; """ self.assertEqual(expand_decl(self.parse(s1).ext[0]), ['Decl', None, ['Struct', 'Foo', [['Decl', None, ['Enum', 'Bar', ['A']]]]]]) s2 = """ struct Foo { enum Bar { A = 1, B, C } bar; enum Baz { D = A } baz; } foo; """ self.assertEqual(expand_decl(self.parse(s2).ext[0]), ['Decl', 'foo', ['TypeDecl', ['Struct', 'Foo', [['Decl', 'bar', ['TypeDecl', ['Enum', 'Bar', ['A', 'B', 'C']]]], ['Decl', 'baz', ['TypeDecl', ['Enum', 'Baz', ['D']]]]]]]]) def test_struct_with_extra_semis_inside(self): s1 = """ struct { int a;; } foo; """ s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[0]), ['Decl', 'foo', ['TypeDecl', ['Struct', None, [['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) s2 = """ struct { int a;;;; float b, c; ;; char d; } foo; """ s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[0]), ['Decl', 'foo', ['TypeDecl', ['Struct', None, [['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'b', ['TypeDecl', ['IdentifierType', ['float']]]], ['Decl', 'c', ['TypeDecl', ['IdentifierType', ['float']]]], ['Decl', 'd', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]) def test_struct_with_initial_semi(self): s1 = """ struct { ;int a; } foo; """ s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[0]), ['Decl', 'foo', ['TypeDecl', ['Struct', None, [['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) def test_anonymous_struct_union(self): s1 = """ union { union { int i; long l; }; struct { int type; int intnode; }; } u; """ self.assertEqual(expand_decl(self.parse(s1).ext[0]), ['Decl', 'u', ['TypeDecl', ['Union', None, [['Decl', None, ['Union', None, [['Decl', 'i', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'l', ['TypeDecl', ['IdentifierType', ['long']]]]]]], ['Decl', None, ['Struct', None, [['Decl', 'type', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'intnode', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]]]]) s2 = """ struct { int i; union { int id; char* name; }; float f; } joe; """ self.assertEqual(expand_decl(self.parse(s2).ext[0]), ['Decl', 'joe', ['TypeDecl', ['Struct', None, [['Decl', 'i', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', None, ['Union', None, [['Decl', 'id', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'name', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]], ['Decl', 'f', ['TypeDecl', ['IdentifierType', ['float']]]]]]]]) # ISO/IEC 9899:201x Commitee Draft 2010-11-16, N1539 # section 6.7.2.1, par. 19, example 1 s3 = """ struct v { union { struct { int i, j; }; struct { long k, l; } w; }; int m; } v1; """ self.assertEqual(expand_decl(self.parse(s3).ext[0]), ['Decl', 'v1', ['TypeDecl', ['Struct', 'v', [['Decl', None, ['Union', None, [['Decl', None, ['Struct', None, [['Decl', 'i', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'j', ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['Decl', 'w', ['TypeDecl', ['Struct', None, [['Decl', 'k', ['TypeDecl', ['IdentifierType', ['long']]]], ['Decl', 'l', ['TypeDecl', ['IdentifierType', ['long']]]]]]]]]]], ['Decl', 'm', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) s4 = """ struct v { int i; float; } v2;""" # just make sure this doesn't raise ParseError self.parse(s4) def test_struct_members_namespace(self): """ Tests that structure/union member names reside in a separate namespace and can be named after existing types. """ s1 = """ typedef int Name; typedef Name NameArray[10]; struct { Name Name; Name NameArray[3]; } sye; void main(void) { sye.Name = 1; } """ s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[2]), ['Decl', 'sye', ['TypeDecl', ['Struct', None, [ ['Decl', 'Name', ['TypeDecl', ['IdentifierType', ['Name']]]], ['Decl', 'NameArray', ['ArrayDecl', '3', [], ['TypeDecl', ['IdentifierType', ['Name']]]]]]]]]) self.assertEqual(s1_ast.ext[3].body.block_items[0].lvalue.field.name, 'Name') def test_struct_bitfields(self): # a struct with two bitfields, one unnamed s1 = """ struct { int k:6; int :2; } joe; """ parsed_struct = self.parse(s1).ext[0] # We can see here the name of the decl for the unnamed bitfield is # None, but expand_decl doesn't show bitfield widths # ... self.assertEqual(expand_decl(parsed_struct), ['Decl', 'joe', ['TypeDecl', ['Struct', None, [ ['Decl', 'k', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', None, ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) # ... # so we test them manually self.assertEqual(parsed_struct.type.type.decls[0].bitsize.value, '6') self.assertEqual(parsed_struct.type.type.decls[1].bitsize.value, '2') def test_struct_empty(self): """ Tests that parsing an empty struct works. Empty structs do NOT follow C99 (See 6.2.5-20 of the C99 standard). This is nevertheless supported by some compilers (clang, gcc), especially when using FORTIFY code. Some compilers (visual) will fail to compile with an error. """ # an empty struct. This is NOT C99 compliant s1 = """ struct foo { }; """ parsed_struct = self.parse(s1).ext[0] self.assertEqual(expand_decl(parsed_struct), ['Decl', None, ['Struct', 'foo', []]]) s2 = """struct { } foo;""" parsed_struct = self.parse(s2).ext[0] self.assertEqual(expand_decl(parsed_struct), ['Decl', 'foo', ['TypeDecl', ['Struct', None, []]]]) s3 = """union { } foo;""" parsed_struct = self.parse(s3).ext[0] self.assertEqual(expand_decl(parsed_struct), ['Decl', 'foo', ['TypeDecl', ['Union', None, []]]]) def test_tags_namespace(self): """ Tests that the tags of structs/unions/enums reside in a separate namespace and can be named after existing types. """ s1 = """ typedef int tagEntry; struct tagEntry { char* key; char* value; } Entry; """ s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1]), ['Decl', 'Entry', ['TypeDecl', ['Struct', 'tagEntry', [['Decl', 'key', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]], ['Decl', 'value', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]) s2 = """ struct tagEntry; typedef struct tagEntry tagEntry; struct tagEntry { char* key; char* value; } Entry; """ s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[2]), ['Decl', 'Entry', ['TypeDecl', ['Struct', 'tagEntry', [['Decl', 'key', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]], ['Decl', 'value', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]) s3 = """ typedef int mytag; enum mytag {ABC, CDE}; enum mytag joe; """ s3_type = self.parse(s3).ext[1].type self.assertIsInstance(s3_type, Enum) self.assertEqual(s3_type.name, 'mytag') def test_multi_decls(self): d1 = 'int a, b;' self.assertEqual(self.get_decl(d1, 0), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl(d1, 1), ['Decl', 'b', ['TypeDecl', ['IdentifierType', ['int']]]]) d2 = 'char* p, notp, ar[4];' self.assertEqual(self.get_decl(d2, 0), ['Decl', 'p', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]) self.assertEqual(self.get_decl(d2, 1), ['Decl', 'notp', ['TypeDecl', ['IdentifierType', ['char']]]]) self.assertEqual(self.get_decl(d2, 2), ['Decl', 'ar', ['ArrayDecl', '4', [], ['TypeDecl', ['IdentifierType', ['char']]]]]) def test_invalid_multiple_types_error(self): bad = [ 'int enum {ab, cd} fubr;', 'enum kid char brbr;'] for b in bad: self.assertRaises(ParseError, self.parse, b) def test_invalid_typedef_storage_qual_error(self): """ Tests that using typedef as a storage qualifier is correctly flagged as an error. """ bad = 'typedef const int foo(int a) { return 0; }' self.assertRaises(ParseError, self.parse, bad) def test_duplicate_typedef(self): """ Tests that redeclarations of existing types are parsed correctly. This is non-standard, but allowed by many compilers. """ d1 = ''' typedef int numbertype; typedef int numbertype; ''' self.assertEqual(self.get_decl(d1, 0), ['Typedef', 'numbertype', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl(d1, 1), ['Typedef', 'numbertype', ['TypeDecl', ['IdentifierType', ['int']]]]) d2 = ''' typedef int (*funcptr)(int x); typedef int (*funcptr)(int x); ''' self.assertEqual(self.get_decl(d2, 0), ['Typedef', 'funcptr', ['PtrDecl', ['FuncDecl', [['Decl', 'x', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) self.assertEqual(self.get_decl(d2, 1), ['Typedef', 'funcptr', ['PtrDecl', ['FuncDecl', [['Decl', 'x', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) d3 = ''' typedef int numberarray[5]; typedef int numberarray[5]; ''' self.assertEqual(self.get_decl(d3, 0), ['Typedef', 'numberarray', ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl(d3, 1), ['Typedef', 'numberarray', ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_decl_inits(self): d1 = 'int a = 16;' #~ self.parse(d1).show() self.assertEqual(self.get_decl(d1), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl_init(d1), ['Constant', 'int', '16']) d1_1 = 'float f = 0xEF.56p1;' self.assertEqual(self.get_decl_init(d1_1), ['Constant', 'float', '0xEF.56p1']) d1_2 = 'int bitmask = 0b1001010;' self.assertEqual(self.get_decl_init(d1_2), ['Constant', 'int', '0b1001010']) d2 = 'long ar[] = {7, 8, 9};' self.assertEqual(self.get_decl(d2), ['Decl', 'ar', ['ArrayDecl', '', [], ['TypeDecl', ['IdentifierType', ['long']]]]]) self.assertEqual(self.get_decl_init(d2), [ ['Constant', 'int', '7'], ['Constant', 'int', '8'], ['Constant', 'int', '9']]) d21 = 'long ar[4] = {};' self.assertEqual(self.get_decl_init(d21), []) d3 = 'char p = j;' self.assertEqual(self.get_decl(d3), ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['char']]]]) self.assertEqual(self.get_decl_init(d3), ['ID', 'j']) d4 = "char x = 'c', *p = {0, 1, 2, {4, 5}, 6};" self.assertEqual(self.get_decl(d4, 0), ['Decl', 'x', ['TypeDecl', ['IdentifierType', ['char']]]]) self.assertEqual(self.get_decl_init(d4, 0), ['Constant', 'char', "'c'"]) self.assertEqual(self.get_decl(d4, 1), ['Decl', 'p', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]) self.assertEqual(self.get_decl_init(d4, 1), [ ['Constant', 'int', '0'], ['Constant', 'int', '1'], ['Constant', 'int', '2'], [['Constant', 'int', '4'], ['Constant', 'int', '5']], ['Constant', 'int', '6']]) d5 = 'float d = 1.0;' self.assertEqual(self.get_decl_init(d5), ['Constant', 'double', '1.0']) d51 = 'float ld = 1.0l;' self.assertEqual(self.get_decl_init(d51), ['Constant', 'long double', '1.0l']) d52 = 'float ld = 1.0L;' self.assertEqual(self.get_decl_init(d52), ['Constant', 'long double', '1.0L']) d53 = 'float ld = 1.0f;' self.assertEqual(self.get_decl_init(d53), ['Constant', 'float', '1.0f']) d54 = 'float ld = 1.0F;' self.assertEqual(self.get_decl_init(d54), ['Constant', 'float', '1.0F']) d55 = 'float ld = 0xDE.38p0;' self.assertEqual(self.get_decl_init(d55), ['Constant', 'float', '0xDE.38p0']) d6 = 'int i = 1;' self.assertEqual(self.get_decl_init(d6), ['Constant', 'int', '1']) d61 = 'long int li = 1l;' self.assertEqual(self.get_decl_init(d61), ['Constant', 'long int', '1l']) d62 = 'unsigned int ui = 1u;' self.assertEqual(self.get_decl_init(d62), ['Constant', 'unsigned int', '1u']) d63 = 'unsigned long long int ulli = 1LLU;' self.assertEqual(self.get_decl_init(d63), ['Constant', 'unsigned long long int', '1LLU']) def test_decl_named_inits(self): d1 = 'int a = {.k = 16};' self.assertEqual(self.get_decl_init(d1), [( [['ID', 'k']], ['Constant', 'int', '16'])]) d2 = 'int a = { [0].a = {1}, [1].a[0] = 2 };' self.assertEqual(self.get_decl_init(d2), [ ([['Constant', 'int', '0'], ['ID', 'a']], [['Constant', 'int', '1']]), ([['Constant', 'int', '1'], ['ID', 'a'], ['Constant', 'int', '0']], ['Constant', 'int', '2'])]) d3 = 'int a = { .a = 1, .c = 3, 4, .b = 5};' self.assertEqual(self.get_decl_init(d3), [ ([['ID', 'a']], ['Constant', 'int', '1']), ([['ID', 'c']], ['Constant', 'int', '3']), ['Constant', 'int', '4'], ([['ID', 'b']], ['Constant', 'int', '5'])]) def test_function_definitions(self): def parse_fdef(str): return self.parse(str).ext[0] def fdef_decl(fdef): return expand_decl(fdef.decl) f1 = parse_fdef(''' int factorial(int p) { return 3; } ''') self.assertEqual(fdef_decl(f1), ['Decl', 'factorial', ['FuncDecl', [['Decl', 'p', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(type(f1.body.block_items[0]), Return) f2 = parse_fdef(''' char* zzz(int p, char* c) { int a; char b; a = b + 2; return 3; } ''') self.assertEqual(fdef_decl(f2), ['Decl', 'zzz', ['FuncDecl', [ ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'c', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(list(map(type, f2.body.block_items)), [Decl, Decl, Assignment, Return]) f3 = parse_fdef(''' char* zzz(p, c) long p, *c; { int a; char b; a = b + 2; return 3; } ''') self.assertEqual(fdef_decl(f3), ['Decl', 'zzz', ['FuncDecl', [ ['ID', 'p'], ['ID', 'c']], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(list(map(type, f3.body.block_items)), [Decl, Decl, Assignment, Return]) self.assertEqual(expand_decl(f3.param_decls[0]), ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['long']]]]) self.assertEqual(expand_decl(f3.param_decls[1]), ['Decl', 'c', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['long']]]]]) # function return values and parameters may not have type information f4 = parse_fdef(''' que(p) { return 3; } ''') self.assertEqual(fdef_decl(f4), ['Decl', 'que', ['FuncDecl', [['ID', 'p']], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_unified_string_literals(self): # simple string, for reference d1 = self.get_decl_init('char* s = "hello";') self.assertEqual(d1, ['Constant', 'string', '"hello"']) d2 = self.get_decl_init('char* s = "hello" " world";') self.assertEqual(d2, ['Constant', 'string', '"hello world"']) # the test case from issue 6 d3 = self.parse(r''' int main() { fprintf(stderr, "Wrong Params?\n" "Usage:\n" "%s <binary_file_path>\n", argv[0] ); } ''') self.assertEqual( d3.ext[0].body.block_items[0].args.exprs[1].value, r'"Wrong Params?\nUsage:\n%s <binary_file_path>\n"') d4 = self.get_decl_init('char* s = "" "foobar";') self.assertEqual(d4, ['Constant', 'string', '"foobar"']) d5 = self.get_decl_init(r'char* s = "foo\"" "bar";') self.assertEqual(d5, ['Constant', 'string', r'"foo\"bar"']) # This is not correct based on the the C spec, but testing it here to # see the behavior in action. Will have to fix this # for https://github.com/eliben/pycparser/issues/392 # # The spec says in section 6.4.5 that "escape sequences are converted # into single members of the execution character set just prior to # adjacent string literal concatenation". d6 = self.get_decl_init(r'char* s = "\1" "23";') self.assertEqual(d6, ['Constant', 'string', r'"\123"']) def test_unified_wstring_literals(self): d1 = self.get_decl_init('char* s = L"hello" L"world";') self.assertEqual(d1, ['Constant', 'string', 'L"helloworld"']) d2 = self.get_decl_init('char* s = L"hello " L"world" L" and I";') self.assertEqual(d2, ['Constant', 'string', 'L"hello world and I"']) def test_inline_specifier(self): ps2 = self.parse('static inline void inlinefoo(void);') self.assertEqual(ps2.ext[0].funcspec, ['inline']) # variable length array def test_vla(self): ps2 = self.parse(r''' int main() { int size; int var[size = 5]; int var2[*]; } ''') self.assertIsInstance(ps2.ext[0].body.block_items[1].type.dim, Assignment) self.assertIsInstance(ps2.ext[0].body.block_items[2].type.dim, ID) def test_pragma(self): s1 = r''' #pragma bar void main() { #pragma foo for(;;) {} #pragma baz { int i = 0; } #pragma } struct s { #pragma baz } s; ''' s1_ast = self.parse(s1) self.assertIsInstance(s1_ast.ext[0], Pragma) self.assertEqual(s1_ast.ext[0].string, 'bar') self.assertEqual(s1_ast.ext[0].coord.line, 2) self.assertIsInstance(s1_ast.ext[1].body.block_items[0], Pragma) self.assertEqual(s1_ast.ext[1].body.block_items[0].string, 'foo') self.assertEqual(s1_ast.ext[1].body.block_items[0].coord.line, 4) self.assertIsInstance(s1_ast.ext[1].body.block_items[2], Pragma) self.assertEqual(s1_ast.ext[1].body.block_items[2].string, 'baz') self.assertEqual(s1_ast.ext[1].body.block_items[2].coord.line, 6) self.assertIsInstance(s1_ast.ext[1].body.block_items[4], Pragma) self.assertEqual(s1_ast.ext[1].body.block_items[4].string, '') self.assertEqual(s1_ast.ext[1].body.block_items[4].coord.line, 10) self.assertIsInstance(s1_ast.ext[2].type.type.decls[0], Pragma) self.assertEqual(s1_ast.ext[2].type.type.decls[0].string, 'baz') self.assertEqual(s1_ast.ext[2].type.type.decls[0].coord.line, 13) def test_pragmacomp_or_statement(self): s1 = r''' void main() { int sum = 0; for (int i; i < 3; i++) #pragma omp critical sum += 1; while(sum < 10) #pragma omp critical sum += 1; mylabel: #pragma foo sum += 10; if (sum > 10) #pragma bar sum = 10; switch (sum) case 10: #pragma foo sum = 20; } ''' s1_ast = self.parse(s1) self.assertIsInstance(s1_ast.ext[0].body.block_items[1], For) self.assertIsInstance(s1_ast.ext[0].body.block_items[1].stmt, Compound) self.assertIsInstance(s1_ast.ext[0].body.block_items[1].stmt.block_items[0], Pragma) self.assertIsInstance(s1_ast.ext[0].body.block_items[1].stmt.block_items[1], Assignment) self.assertIsInstance(s1_ast.ext[0].body.block_items[2], While) self.assertIsInstance(s1_ast.ext[0].body.block_items[2].stmt, Compound) self.assertIsInstance(s1_ast.ext[0].body.block_items[2].stmt.block_items[0], Pragma) self.assertIsInstance(s1_ast.ext[0].body.block_items[2].stmt.block_items[1], Assignment) self.assertIsInstance(s1_ast.ext[0].body.block_items[3], Label) self.assertIsInstance(s1_ast.ext[0].body.block_items[3].stmt, Compound) self.assertIsInstance(s1_ast.ext[0].body.block_items[3].stmt.block_items[0], Pragma) self.assertIsInstance(s1_ast.ext[0].body.block_items[3].stmt.block_items[1], Assignment) self.assertIsInstance(s1_ast.ext[0].body.block_items[4], If) self.assertIsInstance(s1_ast.ext[0].body.block_items[4].iftrue, Compound) self.assertIsInstance(s1_ast.ext[0].body.block_items[4].iftrue.block_items[0], Pragma) self.assertIsInstance(s1_ast.ext[0].body.block_items[4].iftrue.block_items[1], Assignment) self.assertIsInstance(s1_ast.ext[0].body.block_items[5], Switch) self.assertIsInstance(s1_ast.ext[0].body.block_items[5].stmt.stmts[0], Compound) self.assertIsInstance(s1_ast.ext[0].body.block_items[5].stmt.stmts[0].block_items[0], Pragma) self.assertIsInstance(s1_ast.ext[0].body.block_items[5].stmt.stmts[0].block_items[1], Assignment) class TestCParser_whole_code(TestCParser_base): """ Testing of parsing whole chunks of code. Since I don't want to rely on the structure of ASTs too much, most of these tests are implemented with visitors. """ # A simple helper visitor that lists the values of all the # Constant nodes it sees. # class ConstantVisitor(NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) # This visitor counts the amount of references to the ID # with the name provided to it in the constructor. # class IDNameCounter(NodeVisitor): def __init__(self, name): self.name = name self.nrefs = 0 def visit_ID(self, node): if node.name == self.name: self.nrefs += 1 # Counts the amount of nodes of a given class # class NodeKlassCounter(NodeVisitor): def __init__(self, node_klass): self.klass = node_klass self.n = 0 def generic_visit(self, node): if node.__class__ == self.klass: self.n += 1 NodeVisitor.generic_visit(self, node) def assert_all_Constants(self, code, constants): """ Asserts that the list of all Constant values (by 'preorder' appearance) in the chunk of code is as given. """ if isinstance(code, str): parsed = self.parse(code) else: parsed = code cv = self.ConstantVisitor() cv.visit(parsed) self.assertEqual(cv.values, constants) def assert_num_ID_refs(self, code, name, num): """ Asserts the number of references to the ID with the given name. """ if isinstance(code, str): parsed = self.parse(code) else: parsed = code iv = self.IDNameCounter(name) iv.visit(parsed) self.assertEqual(iv.nrefs, num) def assert_num_klass_nodes(self, code, klass, num): """ Asserts the amount of klass nodes in the code. """ if isinstance(code, str): parsed = self.parse(code) else: parsed = code cv = self.NodeKlassCounter(klass) cv.visit(parsed) self.assertEqual(cv.n, num) def test_expressions(self): e1 = '''int k = (r + 10.0) >> 6 + 8 << (3 & 0x14);''' self.assert_all_Constants(e1, ['10.0', '6', '8', '3', '0x14']) e2 = r'''char n = '\n', *prefix = "st_";''' self.assert_all_Constants(e2, [r"'\n'", '"st_"']) s1 = r'''int main() { int i = 5, j = 6, k = 1; if ((i=j && k == 1) || k > j) printf("Hello, world\n"); return 0; }''' ps1 = self.parse(s1) self.assert_all_Constants(ps1, ['5', '6', '1', '1', '"Hello, world\\n"', '0']) self.assert_num_ID_refs(ps1, 'i', 1) self.assert_num_ID_refs(ps1, 'j', 2) def test_statements(self): s1 = r''' void foo(){ if (sp == 1) if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return -1; else if (strcmp(argv[optind], "--") == 0) { optind++; return -1; } } ''' self.assert_all_Constants(s1, ['1', '0', r"'-'", '1', r"'\0'", '1', r'"--"', '0', '1']) ps1 = self.parse(s1) self.assert_num_ID_refs(ps1, 'argv', 3) self.assert_num_ID_refs(ps1, 'optind', 5) self.assert_num_klass_nodes(ps1, If, 3) self.assert_num_klass_nodes(ps1, Return, 2) self.assert_num_klass_nodes(ps1, FuncCall, 1) # strcmp self.assert_num_klass_nodes(ps1, BinaryOp, 7) # In the following code, Hash and Node were defined as # int to pacify the parser that sees they're used as # types # s2 = r''' typedef int Hash, Node; void HashDestroy(Hash* hash) { unsigned int i; if (hash == NULL) return; for (i = 0; i < hash->table_size; ++i) { Node* temp = hash->heads[i]; while (temp != NULL) { Node* temp2 = temp; free(temp->entry->key); free(temp->entry->value); free(temp->entry); temp = temp->next; free(temp2); } } free(hash->heads); hash->heads = NULL; free(hash); } ''' ps2 = self.parse(s2) self.assert_num_klass_nodes(ps2, FuncCall, 6) self.assert_num_klass_nodes(ps2, FuncDef, 1) self.assert_num_klass_nodes(ps2, For, 1) self.assert_num_klass_nodes(ps2, While, 1) self.assert_num_klass_nodes(ps2, StructRef, 10) # declarations don't count self.assert_num_ID_refs(ps2, 'hash', 6) self.assert_num_ID_refs(ps2, 'i', 4) s3 = r''' void x(void) { int a, b; if (a < b) do { a = 0; } while (0); else if (a == b) { a = 1; } } ''' ps3 = self.parse(s3) self.assert_num_klass_nodes(ps3, DoWhile, 1) self.assert_num_ID_refs(ps3, 'a', 4) self.assert_all_Constants(ps3, ['0', '0', '1']) def test_empty_statements(self): s1 = r''' void foo(void){ ; return;; ; } ''' ps1 = self.parse(s1) self.assert_num_klass_nodes(ps1, EmptyStatement, 3) self.assert_num_klass_nodes(ps1, Return, 1) self.assert_coord(ps1.ext[0].body.block_items[0], 3) self.assert_coord(ps1.ext[0].body.block_items[1], 4) self.assert_coord(ps1.ext[0].body.block_items[2], 4) self.assert_coord(ps1.ext[0].body.block_items[3], 6) def test_switch_statement(self): def assert_case_node(node, const_value): self.assertIsInstance(node, Case) self.assertIsInstance(node.expr, Constant) self.assertEqual(node.expr.value, const_value) def assert_default_node(node): self.assertIsInstance(node, Default) s1 = r''' int foo(void) { switch (myvar) { case 10: k = 10; p = k + 1; return 10; case 20: case 30: return 20; default: break; } return 0; } ''' ps1 = self.parse(s1) switch = ps1.ext[0].body.block_items[0] block = switch.stmt.block_items self.assertEqual(len(block), 4) assert_case_node(block[0], '10') self.assertEqual(len(block[0].stmts), 3) assert_case_node(block[1], '20') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[2], '30') self.assertEqual(len(block[2].stmts), 1) assert_default_node(block[3]) s2 = r''' int foo(void) { switch (myvar) { default: joe = moe; return 10; case 10: case 20: case 30: case 40: break; } return 0; } ''' ps2 = self.parse(s2) switch = ps2.ext[0].body.block_items[0] block = switch.stmt.block_items self.assertEqual(len(block), 5) assert_default_node(block[0]) self.assertEqual(len(block[0].stmts), 2) assert_case_node(block[1], '10') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[2], '20') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[3], '30') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[4], '40') self.assertEqual(len(block[4].stmts), 1) s3 = r''' int foo(void) { switch (myvar) { } return 0; } ''' ps3 = self.parse(s3) switch = ps3.ext[0].body.block_items[0] self.assertEqual(switch.stmt.block_items, []) def test_for_statement(self): s2 = r''' void x(void) { int i; for (i = 0; i < 5; ++i) { x = 50; } } ''' ps2 = self.parse(s2) self.assert_num_klass_nodes(ps2, For, 1) # here there are 3 refs to 'i' since the declaration doesn't count as # a ref in the visitor # self.assert_num_ID_refs(ps2, 'i', 3) s3 = r''' void x(void) { for (int i = 0; i < 5; ++i) { x = 50; } } ''' ps3 = self.parse(s3) self.assert_num_klass_nodes(ps3, For, 1) # here there are 2 refs to 'i' since the declaration doesn't count as # a ref in the visitor # self.assert_num_ID_refs(ps3, 'i', 2) s4 = r''' void x(void) { for (int i = 0;;) i; } ''' ps4 = self.parse(s4) self.assert_num_ID_refs(ps4, 'i', 1) def _open_c_file(self, name): """ Find a c file by name, taking into account the current dir can be in a couple of typical places """ testdir = os.path.dirname(__file__) name = os.path.join(testdir, 'c_files', name) assert os.path.exists(name) return io.open(name) def test_whole_file(self): # See how pycparser handles a whole, real C file. # with self._open_c_file('memmgr_with_h.c') as f: code = f.read() p = self.parse(code) self.assert_num_klass_nodes(p, FuncDef, 5) # each FuncDef also has a FuncDecl. 4 declarations # + 5 definitions, overall 9 self.assert_num_klass_nodes(p, FuncDecl, 9) self.assert_num_klass_nodes(p, Typedef, 4) self.assertEqual(p.ext[4].coord.line, 88) self.assertEqual(p.ext[4].coord.file, "./memmgr.h") self.assertEqual(p.ext[6].coord.line, 10) self.assertEqual(p.ext[6].coord.file, "memmgr.c") def test_whole_file_with_stdio(self): # Parse a whole file with stdio.h included by cpp # with self._open_c_file('cppd_with_stdio_h.c') as f: code = f.read() p = self.parse(code) self.assertIsInstance(p.ext[0], Typedef) self.assertEqual(p.ext[0].coord.line, 213) self.assertEqual(p.ext[0].coord.file, r"D:\eli\cpp_stuff\libc_include/stddef.h") self.assertIsInstance(p.ext[-1], FuncDef) self.assertEqual(p.ext[-1].coord.line, 15) self.assertEqual(p.ext[-1].coord.file, "example_c_file.c") self.assertIsInstance(p.ext[-8], Typedef) self.assertIsInstance(p.ext[-8].type, TypeDecl) self.assertEqual(p.ext[-8].name, 'cookie_io_functions_t') class TestCParser_typenames(TestCParser_base): """ Test issues related to the typedef-name problem. """ def test_innerscope_typedef(self): # should fail since TT is not a type in bar s1 = r''' void foo() { typedef char TT; TT x; } void bar() { TT y; } ''' self.assertRaises(ParseError, self.parse, s1) # should succeed since TT is not a type in bar s2 = r''' void foo() { typedef char TT; TT x; } void bar() { unsigned TT; } ''' self.assertIsInstance(self.parse(s2), FileAST) def test_ambiguous_parameters(self): # From ISO/IEC 9899:TC2, 6.7.5.3.11: # "If, in a parameter declaration, an identifier can be treated either # as a typedef name or as a parameter name, it shall be taken as a # typedef name." # foo takes an int named aa # bar takes a function taking a TT s1 = r''' typedef char TT; int foo(int (aa)); int bar(int (TT)); ''' s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1].type.args.params[0]), ['Decl', 'aa', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(expand_decl(s1_ast.ext[2].type.args.params[0]), ['Typename', ['FuncDecl', [['Typename', ['TypeDecl', ['IdentifierType', ['TT']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) # foo takes a function taking a char # bar takes a function taking a function taking a char s2 = r''' typedef char TT; int foo(int (aa (char))); int bar(int (TT (char))); ''' s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[1].type.args.params[0]), ['Decl', 'aa', ['FuncDecl', [['Typename', ['TypeDecl', ['IdentifierType', ['char']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(expand_decl(s2_ast.ext[2].type.args.params[0]), ['Typename', ['FuncDecl', [['Typename', ['FuncDecl', [['Typename', ['TypeDecl', ['IdentifierType', ['char']]]]], ['TypeDecl', ['IdentifierType', ['TT']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) # foo takes an int array named aa # bar takes a function taking a TT array s3 = r''' typedef char TT; int foo(int (aa[])); int bar(int (TT[])); ''' s3_ast = self.parse(s3) self.assertEqual(expand_decl(s3_ast.ext[1].type.args.params[0]), ['Decl', 'aa', ['ArrayDecl', '', [], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(expand_decl(s3_ast.ext[2].type.args.params[0]), ['Typename', ['FuncDecl', [['Typename', ['ArrayDecl', '', [], ['TypeDecl', ['IdentifierType', ['TT']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_innerscope_reuse_typedef_name(self): # identifiers can be reused in inner scopes; the original should be # restored at the end of the block s1 = r''' typedef char TT; void foo(void) { unsigned TT; TT = 10; } TT x = 5; ''' s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1].body.block_items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) self.assertEqual(expand_decl(s1_ast.ext[2]), ['Decl', 'x', ['TypeDecl', ['IdentifierType', ['TT']]]]) # this should be recognized even with an initializer s2 = r''' typedef char TT; void foo(void) { unsigned TT = 10; } ''' s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[1].body.block_items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # before the second local variable, TT is a type; after, it's a # variable s3 = r''' typedef char TT; void foo(void) { TT tt = sizeof(TT); unsigned TT = 10; } ''' s3_ast = self.parse(s3) self.assertEqual(expand_decl(s3_ast.ext[1].body.block_items[0]), ['Decl', 'tt', ['TypeDecl', ['IdentifierType', ['TT']]]]) self.assertEqual(expand_decl(s3_ast.ext[1].body.block_items[1]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # a variable and its type can even share the same name s4 = r''' typedef char TT; void foo(void) { TT TT = sizeof(TT); unsigned uu = TT * 2; } ''' s4_ast = self.parse(s4) self.assertEqual(expand_decl(s4_ast.ext[1].body.block_items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['TT']]]]) self.assertEqual(expand_decl(s4_ast.ext[1].body.block_items[1]), ['Decl', 'uu', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # ensure an error is raised if a type, redeclared as a variable, is # used as a type s5 = r''' typedef char TT; void foo(void) { unsigned TT = 10; TT erroneous = 20; } ''' self.assertRaises(ParseError, self.parse, s5) # reusing a type name should work with multiple declarators s6 = r''' typedef char TT; void foo(void) { unsigned TT, uu; } ''' s6_ast = self.parse(s6) items = s6_ast.ext[1].body.block_items self.assertEqual(expand_decl(items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) self.assertEqual(expand_decl(items[1]), ['Decl', 'uu', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # reusing a type name should work after a pointer s7 = r''' typedef char TT; void foo(void) { unsigned * TT; } ''' s7_ast = self.parse(s7) items = s7_ast.ext[1].body.block_items self.assertEqual(expand_decl(items[0]), ['Decl', 'TT', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['unsigned']]]]]) # redefine a name in the middle of a multi-declarator declaration s8 = r''' typedef char TT; void foo(void) { int tt = sizeof(TT), TT, uu = sizeof(TT); int uu = sizeof(tt); } ''' s8_ast = self.parse(s8) items = s8_ast.ext[1].body.block_items self.assertEqual(expand_decl(items[0]), ['Decl', 'tt', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(expand_decl(items[1]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(expand_decl(items[2]), ['Decl', 'uu', ['TypeDecl', ['IdentifierType', ['int']]]]) # Don't test this until we have support for it # self.assertEqual(expand_init(items[0].init), # ['UnaryOp', 'sizeof', ['Typename', ['TypeDecl', ['IdentifierType', ['TT']]]]]) # self.assertEqual(expand_init(items[2].init), # ['UnaryOp', 'sizeof', ['ID', 'TT']]) def test_parameter_reuse_typedef_name(self): # identifiers can be reused as parameter names; parameter name scope # begins and ends with the function body; it's important that TT is # used immediately before the LBRACE or after the RBRACE, to test # a corner case s1 = r''' typedef char TT; void foo(unsigned TT, TT bar) { TT = 10; } TT x = 5; ''' s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1].decl), ['Decl', 'foo', ['FuncDecl', [ ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]], ['Decl', 'bar', ['TypeDecl', ['IdentifierType', ['TT']]]]], ['TypeDecl', ['IdentifierType', ['void']]]]]) # the scope of a parameter name in a function declaration ends at the # end of the declaration...so it is effectively never used; it's # important that TT is used immediately after the declaration, to # test a corner case s2 = r''' typedef char TT; void foo(unsigned TT, TT bar); TT x = 5; ''' s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[1]), ['Decl', 'foo', ['FuncDecl', [ ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]], ['Decl', 'bar', ['TypeDecl', ['IdentifierType', ['TT']]]]], ['TypeDecl', ['IdentifierType', ['void']]]]]) # ensure an error is raised if a type, redeclared as a parameter, is # used as a type s3 = r''' typedef char TT; void foo(unsigned TT, TT bar) { TT erroneous = 20; } ''' self.assertRaises(ParseError, self.parse, s3) def test_nested_function_decls(self): # parameter names of nested function declarations must not escape into # the top-level function _definition's_ scope; the following must # succeed because TT is still a typedef inside foo's body s1 = r''' typedef char TT; void foo(unsigned bar(int TT)) { TT x = 10; } ''' self.assertIsInstance(self.parse(s1), FileAST) def test_samescope_reuse_name(self): # a typedef name cannot be reused as an object name in the same scope s1 = r''' typedef char TT; char TT = 5; ''' self.assertRaises(ParseError, self.parse, s1) # ...and vice-versa s2 = r''' char TT = 5; typedef char TT; ''' self.assertRaises(ParseError, self.parse, s2) if __name__ == '__main__': #~ suite = unittest.TestLoader().loadTestsFromNames( #~ ['test_c_parser.TestCParser_fundamentals.test_typedef']) #~ unittest.TextTestRunner(verbosity=2).run(suite) unittest.main()
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/test_c_parser.py
Python
apache-2.0
80,777
import os import platform import sys import unittest sys.path.insert(0, '..') from pycparser import parse_file, c_ast CPPPATH = 'cpp' # Test successful parsing # class TestParsing(unittest.TestCase): def _find_file(self, name): """ Find a c file by name, taking into account the current dir can be in a couple of typical places """ testdir = os.path.dirname(__file__) name = os.path.join(testdir, 'c_files', name) assert os.path.exists(name) return name def test_without_cpp(self): ast = parse_file(self._find_file('example_c_file.c')) self.assertIsInstance(ast, c_ast.FileAST) @unittest.skipUnless(platform.system() == 'Linux', 'cpp only works on Linux') def test_with_cpp(self): memmgr_path = self._find_file('memmgr.c') c_files_path = os.path.dirname(memmgr_path) ast = parse_file(memmgr_path, use_cpp=True, cpp_path=CPPPATH, cpp_args='-I%s' % c_files_path) self.assertIsInstance(ast, c_ast.FileAST) fake_libc = os.path.join(c_files_path, '..', '..', 'utils', 'fake_libc_include') ast2 = parse_file(self._find_file('year.c'), use_cpp=True, cpp_path=CPPPATH, cpp_args=[r'-I%s' % fake_libc]) self.assertIsInstance(ast2, c_ast.FileAST) @unittest.skipUnless(platform.system() == 'Linux', 'cpp only works on Linux') def test_cpp_funkydir(self): # This test contains Windows specific path escapes if sys.platform != 'win32': return c_files_path = os.path.join('tests', 'c_files') ast = parse_file(self._find_file('simplemain.c'), use_cpp=True, cpp_path=CPPPATH, cpp_args='-I%s' % c_files_path) self.assertIsInstance(ast, c_ast.FileAST) @unittest.skipUnless(platform.system() == 'Linux', 'cpp only works on Linux') def test_no_real_content_after_cpp(self): ast = parse_file(self._find_file('empty.h'), use_cpp=True, cpp_path=CPPPATH) self.assertIsInstance(ast, c_ast.FileAST) if __name__ == '__main__': unittest.main()
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/tests/test_general.py
Python
apache-2.0
2,244
#----------------------------------------------------------------- # Benchmarking utility for internal use. # # Use with Python 3.6+ # # Eli Bendersky [https://eli.thegreenplace.net/] # License: BSD #----------------------------------------------------------------- import os import statistics import sys import time sys.path.extend(['.', '..']) from pycparser import c_parser, c_ast def measure_parse(text, n, progress_cb): """Measure the parsing of text with pycparser. text should represent a full file. n is the number of iterations to measure. progress_cb will be called with the iteration number each time one is done. Returns a list of elapsed times, one per iteration. """ times = [] for i in range(n): parser = c_parser.CParser() t1 = time.time() ast = parser.parse(text, '') elapsed = time.time() - t1 assert isinstance(ast, c_ast.FileAST) times.append(elapsed) progress_cb(i) return times def measure_file(filename, n): progress_cb = lambda i: print('.', sep='', end='', flush=True) with open(filename) as f: print('%-25s' % os.path.basename(filename), end='', flush=True) text = f.read() times = measure_parse(text, n, progress_cb) print(' Mean: %.3f Stddev: %.3f' % (statistics.mean(times), statistics.stdev(times))) NUM_RUNS = 5 if __name__ == '__main__': if len(sys.argv) < 2: print("Usage: %s <dir with input files>") sys.exit(1) for filename in os.listdir(sys.argv[1]): filename = os.path.join(sys.argv[1], filename) measure_file(filename, NUM_RUNS)
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/benchmark/benchmark-parse.py
Python
apache-2.0
1,691
#include "_fake_defines.h" #include "_fake_typedefs.h" #include "_X11_fake_defines.h" #include "_X11_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/X11/Intrinsic.h
C
apache-2.0
118
#include "_fake_defines.h" #include "_fake_typedefs.h" #include "_X11_fake_defines.h" #include "_X11_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/X11/Xlib.h
C
apache-2.0
118
#ifndef _X11_FAKE_DEFINES_H #define _X11_FAKE_DEFINES_H #define Atom CARD32 #define Bool int #define KeySym CARD32 #define Pixmap CARD32 #define Time CARD32 #define _XFUNCPROTOBEGIN #define _XFUNCPROTOEND #define _Xconst const #define _X_RESTRICT_KYWD #define Cardinal unsigned int #define Boolean int #endif
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/X11/_X11_fake_defines.h
C
apache-2.0
311
#ifndef _X11_FAKE_TYPEDEFS_H #define _X11_FAKE_TYPEDEFS_H typedef char* XPointer; typedef unsigned char KeyCode; typedef unsigned int CARD32; typedef unsigned long VisualID; typedef unsigned long XIMResetState; typedef unsigned long XID; typedef XID Window; typedef XID Colormap; typedef XID Cursor; typedef XID Drawable; typedef void* XtPointer; typedef XtPointer XtRequestId; typedef struct Display Display; typedef struct Screen Screen; typedef struct Status Status; typedef struct Visual Visual; typedef struct Widget *Widget; typedef struct XColor XColor; typedef struct XClassHint XClassHint; typedef struct XEvent XEvent; typedef struct XFontStruct XFontStruct; typedef struct XGCValues XGCValues; typedef struct XKeyEvent XKeyEvent; typedef struct XKeyPressedEvent XKeyPressedEvent; typedef struct XPoint XPoint; typedef struct XRectangle XRectangle; typedef struct XSelectionRequestEvent XSelectionRequestEvent; typedef struct XWindowChanges XWindowChanges; typedef struct _XGC _XCG; typedef struct _XGC *GC; typedef struct _XIC *XIC; typedef struct _XIM *XIM; typedef struct _XImage XImage; #endif
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/X11/_X11_fake_typedefs.h
C
apache-2.0
1,111
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/_ansi.h
C
apache-2.0
55
#ifndef _FAKE_DEFINES_H #define _FAKE_DEFINES_H #define NULL 0 #define BUFSIZ 1024 #define FOPEN_MAX 20 #define FILENAME_MAX 1024 #ifndef SEEK_SET #define SEEK_SET 0 /* set file offset to offset */ #endif #ifndef SEEK_CUR #define SEEK_CUR 1 /* set file offset to current plus offset */ #endif #ifndef SEEK_END #define SEEK_END 2 /* set file offset to EOF plus offset */ #endif #define __LITTLE_ENDIAN 1234 #define LITTLE_ENDIAN __LITTLE_ENDIAN #define __BIG_ENDIAN 4321 #define BIG_ENDIAN __BIG_ENDIAN #define __BYTE_ORDER __LITTLE_ENDIAN #define BYTE_ORDER __BYTE_ORDER #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define CHAR_MIN -128 #define CHAR_MAX 127 #define UCHAR_MAX 255 #define SHRT_MIN -32768 #define SHRT_MAX 32767 #define USHRT_MAX 65535 #define INT_MIN -2147483648 #define INT_MAX 2147483647 #define UINT_MAX 4294967295U #define LONG_MIN -9223372036854775808L #define LONG_MAX 9223372036854775807L #define ULONG_MAX 18446744073709551615UL #define RAND_MAX 32767 /* C99 inttypes.h defines */ #define PRId8 "d" #define PRIi8 "i" #define PRIo8 "o" #define PRIu8 "u" #define PRIx8 "x" #define PRIX8 "X" #define PRId16 "d" #define PRIi16 "i" #define PRIo16 "o" #define PRIu16 "u" #define PRIx16 "x" #define PRIX16 "X" #define PRId32 "d" #define PRIi32 "i" #define PRIo32 "o" #define PRIu32 "u" #define PRIx32 "x" #define PRIX32 "X" #define PRId64 "d" #define PRIi64 "i" #define PRIo64 "o" #define PRIu64 "u" #define PRIx64 "x" #define PRIX64 "X" #define PRIdLEAST8 "d" #define PRIiLEAST8 "i" #define PRIoLEAST8 "o" #define PRIuLEAST8 "u" #define PRIxLEAST8 "x" #define PRIXLEAST8 "X" #define PRIdLEAST16 "d" #define PRIiLEAST16 "i" #define PRIoLEAST16 "o" #define PRIuLEAST16 "u" #define PRIxLEAST16 "x" #define PRIXLEAST16 "X" #define PRIdLEAST32 "d" #define PRIiLEAST32 "i" #define PRIoLEAST32 "o" #define PRIuLEAST32 "u" #define PRIxLEAST32 "x" #define PRIXLEAST32 "X" #define PRIdLEAST64 "d" #define PRIiLEAST64 "i" #define PRIoLEAST64 "o" #define PRIuLEAST64 "u" #define PRIxLEAST64 "x" #define PRIXLEAST64 "X" #define PRIdFAST8 "d" #define PRIiFAST8 "i" #define PRIoFAST8 "o" #define PRIuFAST8 "u" #define PRIxFAST8 "x" #define PRIXFAST8 "X" #define PRIdFAST16 "d" #define PRIiFAST16 "i" #define PRIoFAST16 "o" #define PRIuFAST16 "u" #define PRIxFAST16 "x" #define PRIXFAST16 "X" #define PRIdFAST32 "d" #define PRIiFAST32 "i" #define PRIoFAST32 "o" #define PRIuFAST32 "u" #define PRIxFAST32 "x" #define PRIXFAST32 "X" #define PRIdFAST64 "d" #define PRIiFAST64 "i" #define PRIoFAST64 "o" #define PRIuFAST64 "u" #define PRIxFAST64 "x" #define PRIXFAST64 "X" #define PRIdPTR "d" #define PRIiPTR "i" #define PRIoPTR "o" #define PRIuPTR "u" #define PRIxPTR "x" #define PRIXPTR "X" #define PRIdMAX "d" #define PRIiMAX "i" #define PRIoMAX "o" #define PRIuMAX "u" #define PRIxMAX "x" #define PRIXMAX "X" #define SCNd8 "d" #define SCNi8 "i" #define SCNo8 "o" #define SCNu8 "u" #define SCNx8 "x" #define SCNd16 "d" #define SCNi16 "i" #define SCNo16 "o" #define SCNu16 "u" #define SCNx16 "x" #define SCNd32 "d" #define SCNi32 "i" #define SCNo32 "o" #define SCNu32 "u" #define SCNx32 "x" #define SCNd64 "d" #define SCNi64 "i" #define SCNo64 "o" #define SCNu64 "u" #define SCNx64 "x" #define SCNdLEAST8 "d" #define SCNiLEAST8 "i" #define SCNoLEAST8 "o" #define SCNuLEAST8 "u" #define SCNxLEAST8 "x" #define SCNdLEAST16 "d" #define SCNiLEAST16 "i" #define SCNoLEAST16 "o" #define SCNuLEAST16 "u" #define SCNxLEAST16 "x" #define SCNdLEAST32 "d" #define SCNiLEAST32 "i" #define SCNoLEAST32 "o" #define SCNuLEAST32 "u" #define SCNxLEAST32 "x" #define SCNdLEAST64 "d" #define SCNiLEAST64 "i" #define SCNoLEAST64 "o" #define SCNuLEAST64 "u" #define SCNxLEAST64 "x" #define SCNdFAST8 "d" #define SCNiFAST8 "i" #define SCNoFAST8 "o" #define SCNuFAST8 "u" #define SCNxFAST8 "x" #define SCNdFAST16 "d" #define SCNiFAST16 "i" #define SCNoFAST16 "o" #define SCNuFAST16 "u" #define SCNxFAST16 "x" #define SCNdFAST32 "d" #define SCNiFAST32 "i" #define SCNoFAST32 "o" #define SCNuFAST32 "u" #define SCNxFAST32 "x" #define SCNdFAST64 "d" #define SCNiFAST64 "i" #define SCNoFAST64 "o" #define SCNuFAST64 "u" #define SCNxFAST64 "x" #define SCNdPTR "d" #define SCNiPTR "i" #define SCNoPTR "o" #define SCNuPTR "u" #define SCNxPTR "x" #define SCNdMAX "d" #define SCNiMAX "i" #define SCNoMAX "o" #define SCNuMAX "u" #define SCNxMAX "x" /* C99 stdbool.h defines */ #define __bool_true_false_are_defined 1 #define false 0 #define true 1 /* va_arg macros and type*/ #define va_start(_ap, _type) __builtin_va_start((_ap)) #define va_arg(_ap, _type) __builtin_va_arg((_ap)) #define va_end(_list) #endif /* Vectors */ #define __m128 int #define __m128_u int #define __m128d int #define __m128d_u int #define __m128i int #define __m128i_u int #define __m256 int #define __m256_u int #define __m256d int #define __m256d_u int #define __m256i int #define __m256i_u int #define __m512 int #define __m512_u int #define __m512d int #define __m512d_u int #define __m512i int #define __m512i_u int
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/_fake_defines.h
C
apache-2.0
5,001
#ifndef _FAKE_TYPEDEFS_H #define _FAKE_TYPEDEFS_H typedef int size_t; typedef int __builtin_va_list; typedef int __gnuc_va_list; typedef int va_list; typedef int __int8_t; typedef int __uint8_t; typedef int __int16_t; typedef int __uint16_t; typedef int __int_least16_t; typedef int __uint_least16_t; typedef int __int32_t; typedef int __uint32_t; typedef int __int64_t; typedef int __uint64_t; typedef int __int_least32_t; typedef int __uint_least32_t; typedef int __s8; typedef int __u8; typedef int __s16; typedef int __u16; typedef int __s32; typedef int __u32; typedef int __s64; typedef int __u64; typedef int _LOCK_T; typedef int _LOCK_RECURSIVE_T; typedef int _off_t; typedef int __dev_t; typedef int __uid_t; typedef int __gid_t; typedef int _off64_t; typedef int _fpos_t; typedef int _ssize_t; typedef int wint_t; typedef int _mbstate_t; typedef int _flock_t; typedef int _iconv_t; typedef int __ULong; typedef int __FILE; typedef int ptrdiff_t; typedef int wchar_t; typedef int __off_t; typedef int __pid_t; typedef int __loff_t; typedef int u_char; typedef int u_short; typedef int u_int; typedef int u_long; typedef int ushort; typedef int uint; typedef int clock_t; typedef int time_t; typedef int daddr_t; typedef int caddr_t; typedef int ino_t; typedef int off_t; typedef int dev_t; typedef int uid_t; typedef int gid_t; typedef int pid_t; typedef int key_t; typedef int ssize_t; typedef int mode_t; typedef int nlink_t; typedef int fd_mask; typedef int _types_fd_set; typedef int clockid_t; typedef int timer_t; typedef int useconds_t; typedef int suseconds_t; typedef int FILE; typedef int fpos_t; typedef int cookie_read_function_t; typedef int cookie_write_function_t; typedef int cookie_seek_function_t; typedef int cookie_close_function_t; typedef int cookie_io_functions_t; typedef int div_t; typedef int ldiv_t; typedef int lldiv_t; typedef int sigset_t; typedef int __sigset_t; typedef int _sig_func_ptr; typedef int sig_atomic_t; typedef int __tzrule_type; typedef int __tzinfo_type; typedef int mbstate_t; typedef int sem_t; typedef int pthread_t; typedef int pthread_attr_t; typedef int pthread_mutex_t; typedef int pthread_mutexattr_t; typedef int pthread_cond_t; typedef int pthread_condattr_t; typedef int pthread_key_t; typedef int pthread_once_t; typedef int pthread_rwlock_t; typedef int pthread_rwlockattr_t; typedef int pthread_spinlock_t; typedef int pthread_barrier_t; typedef int pthread_barrierattr_t; typedef int jmp_buf; typedef int rlim_t; typedef int sa_family_t; typedef int sigjmp_buf; typedef int stack_t; typedef int siginfo_t; typedef int z_stream; /* C99 exact-width integer types */ typedef int int8_t; typedef int uint8_t; typedef int int16_t; typedef int uint16_t; typedef int int32_t; typedef int uint32_t; typedef int int64_t; typedef int uint64_t; /* C99 minimum-width integer types */ typedef int int_least8_t; typedef int uint_least8_t; typedef int int_least16_t; typedef int uint_least16_t; typedef int int_least32_t; typedef int uint_least32_t; typedef int int_least64_t; typedef int uint_least64_t; /* C99 fastest minimum-width integer types */ typedef int int_fast8_t; typedef int uint_fast8_t; typedef int int_fast16_t; typedef int uint_fast16_t; typedef int int_fast32_t; typedef int uint_fast32_t; typedef int int_fast64_t; typedef int uint_fast64_t; /* C99 integer types capable of holding object pointers */ typedef int intptr_t; typedef int uintptr_t; /* C99 greatest-width integer types */ typedef int intmax_t; typedef int uintmax_t; /* C99 stdbool.h bool type. _Bool is built-in in C99 */ typedef _Bool bool; /* Mir typedefs */ typedef void* MirEGLNativeWindowType; typedef void* MirEGLNativeDisplayType; typedef struct MirConnection MirConnection; typedef struct MirSurface MirSurface; typedef struct MirSurfaceSpec MirSurfaceSpec; typedef struct MirScreencast MirScreencast; typedef struct MirPromptSession MirPromptSession; typedef struct MirBufferStream MirBufferStream; typedef struct MirPersistentId MirPersistentId; typedef struct MirBlob MirBlob; typedef struct MirDisplayConfig MirDisplayConfig; /* xcb typedefs */ typedef struct xcb_connection_t xcb_connection_t; typedef uint32_t xcb_window_t; typedef uint32_t xcb_visualid_t; #endif
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/_fake_typedefs.h
C
apache-2.0
4,226
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/_syslist.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/aio.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/alloca.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/ar.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/argz.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/arpa/inet.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/asm-generic/int-ll64.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/assert.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/complex.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/cpio.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/ctype.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/dirent.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/dlfcn.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/emmintrin.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/endian.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/envz.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/errno.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/fastmath.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/fcntl.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/features.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/fenv.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/float.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/fmtmsg.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/fnmatch.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/ftw.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/getopt.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/glob.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/grp.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/iconv.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/ieeefp.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/immintrin.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/inttypes.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/iso646.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/langinfo.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/libgen.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/libintl.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/limits.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/linux/socket.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/linux/version.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/locale.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/malloc.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/math.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/mir_toolkit/client_types.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/monetary.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/mqueue.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/ndbm.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/net/if.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/netdb.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/netinet/in.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/netinet/tcp.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/newlib.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/nl_types.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/openssl/err.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/openssl/evp.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/openssl/hmac.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/openssl/ssl.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/openssl/x509v3.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/paths.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/poll.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/process.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/pthread.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/pwd.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/reent.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/regdef.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/regex.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/sched.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/search.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/semaphore.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/setjmp.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/signal.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/smmintrin.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/spawn.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/stdarg.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/stdbool.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/stddef.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/stdint.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/stdio.h
C
apache-2.0
55
#include "_fake_defines.h" #include "_fake_typedefs.h"
YifuLiu/AliOS-Things
components/py_engine/engine/lib/lv_bindings/pycparser/utils/fake_libc_include/stdlib.h
C
apache-2.0
55