common revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
1633838b8255282d10af15c5c84cee5a51466712Bob Halleyiff AST_COMMON
8f34db7d4e391cde13f398a2a72ad009980d12feBob Halleyhdr pthread,stdarg,stddef,stdint,inttypes,types,unistd
1633838b8255282d10af15c5c84cee5a51466712Bob Halleytyp long.double,size_t,ssize_t
1633838b8255282d10af15c5c84cee5a51466712Bob Halleydll import note{ Microsoft import/export nonsense }end execute{
1633838b8255282d10af15c5c84cee5a51466712Bob Halley __declspec(dllimport) int foo;
1633838b8255282d10af15c5c84cee5a51466712Bob Halley int main() { return foo == 5 ? 0 : 1; }
1633838b8255282d10af15c5c84cee5a51466712Bob Halley int bar = 5;
1633838b8255282d10af15c5c84cee5a51466712Bob Halley int* _imp__foo = &bar;
1633838b8255282d10af15c5c84cee5a51466712Bob Halleystd proto note{ standard C prototypes ok }end compile{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley extern int foo(int, int);
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley bar() { foo(1, 1); }
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halleytst ptr_void note{ standard C void* ok }end compile{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley extern void* foo();
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley void* bar() { return foo(); }
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* disable non-standard linux/gnu inlines */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #ifdef __GNUC__
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # undef __OPTIMIZE_SIZE__
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __OPTIMIZE_SIZE__ 1
3740b569ae76295b941d57a724a43beb75b533baBob Halley /* __STD_C indicates that the language is ANSI-C or C++ */
3740b569ae76295b941d57a724a43beb75b533baBob Halley #if !defined(__STD_C) && __STDC__
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __STD_C 1
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley #if !defined(__STD_C) && (__cplusplus || c_plusplus)
3740b569ae76295b941d57a724a43beb75b533baBob Halley # define __STD_C 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(__STD_C) && _std_proto
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # define __STD_C 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(__STD_C)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __STD_C 0
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* extern symbols must be protected against C++ name mangling */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #ifndef _BEGIN_EXTERNS_
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # if __cplusplus || c_plusplus
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # define _BEGIN_EXTERNS_ extern "C" {
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _END_EXTERNS_ }
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _BEGIN_EXTERNS_
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _END_EXTERNS_
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley /* _ARG_ simplifies function prototyping among flavors of C */
3740b569ae76295b941d57a724a43beb75b533baBob Halley #ifndef _ARG_
3740b569ae76295b941d57a724a43beb75b533baBob Halley # if __STD_C
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _ARG_(x) x
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley # define _ARG_(x) ()
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley /* _NIL_ simplifies defining nil pointers to a given type */
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley #ifndef _NIL_
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define _NIL_(x) ((x)0)
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley /* __INLINE__, if defined, is the inline keyword */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(__INLINE__) && defined(__cplusplus)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __INLINE__ inline
3740b569ae76295b941d57a724a43beb75b533baBob Halley #if !defined(__INLINE__) && defined(_WIN32) && !defined(__GNUC__)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __INLINE__ __inline
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* Void_t is defined so that Void_t* can address any type */
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley #ifndef Void_t
5f74ac33a07148f2f28b26870c5beccb778b4bd3Bob Halley # if __STD_C
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define Void_t void
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define Void_t char
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* windows variants and veneers */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if !defined(_WINIX) && (_UWIN || __CYGWIN__ || __EMX__)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _WINIX 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley /* dynamic linked library external scope handling */
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley #ifdef __DYNAMIC__
b32248301c1f0c9b8ed71e1355657a5640e153f7Bob Halley # undef __DYNAMIC__
0ab04d76c8b47210c91cb960854a17b28e2daa35Bob Halley # ifndef _DLL
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define _DLL 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #if _dll_import
3740b569ae76295b941d57a724a43beb75b533baBob Halley # if _BLD_STATIC && !_BLD_DLL
3740b569ae76295b941d57a724a43beb75b533baBob Halley # undef _DLL
3740b569ae76295b941d57a724a43beb75b533baBob Halley # if !_UWIN && !defined(_DLL)
3740b569ae76295b941d57a724a43beb75b533baBob Halley # define _DLL 1
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # if !defined(__EXPORT__) && _BLD_DLL
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __EXPORT__ __declspec(dllexport)
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # if !defined(__IMPORT__) && ( _BLD_DLL || defined(_DLL) )
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __IMPORT__ __declspec(dllimport)
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # if _BLD_DLL && _UWIN
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # define __DYNAMIC__(v) (_ast_getdll()->_ast_ ## v)
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if !defined(_astimport)
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # if defined(__IMPORT__) && defined(_DLL)
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # define _astimport __IMPORT__
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley # define _astimport extern
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #if _dll_import && ( !_BLD_DLL || _WINIX && !_UWIN )
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # ifdef __STDC__
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __EXTERN__(T,obj) extern T obj; T* _imp__ ## obj = &obj
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __DEFINE__(T,obj,val) T obj = val; T* _imp__ ## obj = &obj
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __EXTERN__(T,obj) extern T obj; T* _imp__/**/obj = &obj
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halley # define __DEFINE__(T,obj,val) T obj = val; T* _imp__/**/obj = &obj
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __EXTERN__(T,obj) extern T obj
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley # define __DEFINE__(T,obj,val) T obj = val
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halleyif tst - note{ <stdarg.h>+<wchar.h> works }end compile{
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley /*<NOSTDIO>*/
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halleyelif tst - note{ explicit <sys/va_list.h> before <stdarg.h>+<wchar.h> }end compile{
db1e643c60d9b521c421f3f528e7946dd37cacbfBob Halley /*<NOSTDIO>*/
1d9b3491ab3216c8f278dd821455a7a3b08ddfeeBob Halleytst ast_LL note{ LL numeric suffix supported }end compile{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley int i = 1LL;
c92ba071011bbc09e7146729606fd9e89a9be02cBob Halley unsigned int u = 1ULL; /* NOTE: some compilers choke on 1LLU */
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halleytst - -DN=1 - -DN=2 - -DN=3 - -DN=4 - -DN=5 - -DN=6 - -DN=7 - -DN=8 - -DN=0 output{
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #define _BYTESEX_H
c92ba071011bbc09e7146729606fd9e89a9be02cBob Halley #define _ast_int8_t long
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #define _ast_int8_str "long"
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_t long long
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_str "long long"
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_t __int64
2c711cbaceee2acdd6ccb157ed0e97ac5c5ef90cBob Halley #define _ast_int8_str "__int64"
a75f433c831be334df8f1eafa9f77e940b5ae58cBob Halley #define _ast_int8_t __int64_t
#include <string.h>
#include <sys/types.h>
printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].cond * 2, types[t].name);
printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].cond, types[t].name);
printf("#define _ast_sizeof_%s%s %d /* sizeof(%s) */\n", types[t].name, strlen(types[t].name) < 4 ? "\t" : "", types[t].size, types[t].name);
#include <string.h>
#include <sys/types.h>
#include <stdarg.h>
#include <varargs.h>
printf("#include <stdarg.h>\n");
printf("#include <varargs.h>\n");
# include <stddef.h>
# include <sys/types.h>
# include <stdint.h>
# include <inttypes.h>
# include <ast_map.h>