e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
e86c8c2003-11-14Martin Stjernholm || $Id: errors.h,v 1.24 2003/11/14 04:10:32 mast Exp $
e576bb2002-10-11Martin Nilsson */
1b10db2002-10-08Martin Nilsson 
81299f1999-03-19Fredrik Hübinette (Hubbe) #ifdef ERR_DECLARE #define DECLARE_ERROR(NAME, INHERIT, DECL) \
fa8c692000-11-30Fredrik Hübinette (Hubbe) PMOD_EXPORT struct program *PIKE_CONCAT(NAME,_error_program); \
a9e5692000-08-15Henrik Grubbström (Grubba) ptrdiff_t PIKE_CONCAT(NAME,_error_offset);
928b782000-06-05Henrik Grubbström (Grubba)  #define ERR_VAR(TYPE,CTYPE,RUNTYPE,NAME) TYPE NAME ; #endif #ifdef ERR_EXT_DECLARE #define DECLARE_ERROR(NAME, INHERIT, DECL) \
f31ced2000-12-16Marcus Comstedt PMOD_EXPORT extern struct program *PIKE_CONCAT(NAME,_error_program); \
e0755c2000-08-15Henrik Grubbström (Grubba) extern ptrdiff_t PIKE_CONCAT(NAME,_error_offset); \
81299f1999-03-19Fredrik Hübinette (Hubbe) struct PIKE_CONCAT(NAME,_error_struct) { \ DECL \ }; #define ERR_VAR(TYPE,CTYPE,RUNTYPE,NAME) TYPE NAME ;
65a7eb2001-08-16Henrik Grubbström (Grubba)  /* Some compilers (eg cl) don't like empty structs... */ #define EMPTY ERR_VAR(INT_TYPE, int, PIKE_T_INT, ignored__)
928b782000-06-05Henrik Grubbström (Grubba) #endif /* ERR_EXT_DECLARE */
81299f1999-03-19Fredrik Hübinette (Hubbe)  #ifdef ERR_SETUP #define DECLARE_ERROR(NAME, INHERIT, DECL) do{ \
e0755c2000-08-15Henrik Grubbström (Grubba)  ptrdiff_t current_offset=0; \
81299f1999-03-19Fredrik Hübinette (Hubbe)  struct PIKE_CONCAT(NAME,_error_struct) foo; \ start_new_program(); \ INHERIT \
e0755c2000-08-15Henrik Grubbström (Grubba)  current_offset = PIKE_CONCAT(NAME,_error_offset) = \ ADD_STORAGE(struct PIKE_CONCAT(NAME,_error_struct));\
81299f1999-03-19Fredrik Hübinette (Hubbe)  add_string_constant("error_type",#NAME "_error",0); \ add_integer_constant("is_" #NAME "_error",1,0); \ DECL \ PIKE_CONCAT(NAME,_error_program)=end_program(); \
f01a521999-08-14Fredrik Hübinette (Hubbe)  add_program_constant( #NAME "_error",PIKE_CONCAT(NAME,_error_program),0); \
81299f1999-03-19Fredrik Hübinette (Hubbe) }while(0); #define ERR_VAR(TYPE,CTYPE,RUNTYPE,NAME2) \
e86c8c2003-11-14Martin Stjernholm  map_variable(#NAME2, #CTYPE, 0, \
81299f1999-03-19Fredrik Hübinette (Hubbe)  current_offset + (((char *)&(foo.NAME2))-((char *)&foo)), RUNTYPE);
f93ed42001-08-20Martin Stjernholm #define EMPTY
81299f1999-03-19Fredrik Hübinette (Hubbe) #define ERR_INHERIT(NAME) \ low_inherit(PIKE_CONCAT(NAME,_error_program),0,0,0,0,0); #define ERR_FUNC(NAME,FUNC,TYPE,FLAGS) \ ADD_FUNCTION(NAME,FUNC,TYPE,FLAGS); #endif #ifdef ERR_CLEANUP #define DECLARE_ERROR(NAME, INHERIT, DECL) \ if(PIKE_CONCAT(NAME,_error_program)) {\ free_program(PIKE_CONCAT(NAME,_error_program)); \ PIKE_CONCAT(NAME,_error_program)=0;\ } #endif #ifndef ERR_INHERIT #define ERR_INHERIT(NAME) #endif #ifndef ERR_VAR #define ERR_VAR(TYPE,CTYPE,RUNTYPE,NAME) #endif #ifndef ERR_FUNC #define ERR_FUNC(NAME,FUNC,TYPE,FLAGS) #endif
74988f1999-06-19Fredrik Hübinette (Hubbe) DECLARE_ERROR(generic, EMPTY ,
e86c8c2003-11-14Martin Stjernholm  ERR_VAR(struct pike_string *,string,PIKE_T_STRING,error_message) ERR_VAR(struct array *,array,PIKE_T_ARRAY,error_backtrace)
81299f1999-03-19Fredrik Hübinette (Hubbe)  ERR_FUNC("cast",f_error_cast,tFunc(tString,tMixed),0) ERR_FUNC("`[]",f_error_index,tFunc(tString,tMixed),0) ERR_FUNC("describe",f_error_describe,tFunc(tVoid,tString),0)
e86c8c2003-11-14Martin Stjernholm  ERR_FUNC("message", f_error_message, tFunc(tVoid,tString), 0)
81299f1999-03-19Fredrik Hübinette (Hubbe)  ERR_FUNC("backtrace",f_error_backtrace,tFunc(tVoid,tArr(tMixed)),0)
32ffa12001-08-16Martin Stjernholm  ERR_FUNC("_sprintf",f_error__sprintf,tFunc(tNone,tString),0)
4eb01f2002-08-15Marcus Comstedt  ERR_FUNC("create",f_error_create,tFunc(tStr,tVoid),ID_STATIC)
81299f1999-03-19Fredrik Hübinette (Hubbe) )
60d9872000-03-23Fredrik Hübinette (Hubbe) #define GENERIC_ERROR_THIS ((struct generic_error_struct *)CURRENT_STORAGE)
81299f1999-03-19Fredrik Hübinette (Hubbe)  DECLARE_ERROR(index, ERR_INHERIT(generic),
e86c8c2003-11-14Martin Stjernholm  ERR_VAR(struct svalue, mixed, PIKE_T_MIXED, value) ERR_VAR(struct svalue, mixed, PIKE_T_MIXED, index)
81299f1999-03-19Fredrik Hübinette (Hubbe) ) DECLARE_ERROR(bad_arg, ERR_INHERIT(generic),
e86c8c2003-11-14Martin Stjernholm  ERR_VAR(INT_TYPE, int, PIKE_T_INT, which_argument)
0542ef1999-11-17Fredrik Hübinette (Hubbe)  ERR_VAR(struct pike_string *,string,PIKE_T_STRING,expected_type)
e86c8c2003-11-14Martin Stjernholm  ERR_VAR(struct svalue, mixed, PIKE_T_MIXED, got_value)
81299f1999-03-19Fredrik Hübinette (Hubbe) )
d0ed261999-03-20Fredrik Hübinette (Hubbe) DECLARE_ERROR(math, ERR_INHERIT(generic),
2cd8ca2000-07-28Fredrik Hübinette (Hubbe)  ERR_VAR(struct svalue, mixed, PIKE_T_MIXED, number)
d0ed261999-03-20Fredrik Hübinette (Hubbe) ) DECLARE_ERROR(resource, ERR_INHERIT(generic),
0542ef1999-11-17Fredrik Hübinette (Hubbe)  ERR_VAR(struct pike_string *,string,PIKE_T_STRING,resource_type) ERR_VAR(INT_TYPE, int, PIKE_T_INT, howmuch)
d0ed261999-03-20Fredrik Hübinette (Hubbe) )
64dc4c1999-04-17Henrik Grubbström (Grubba) DECLARE_ERROR(permission, ERR_INHERIT(generic),
0542ef1999-11-17Fredrik Hübinette (Hubbe)  ERR_VAR(struct pike_string *,string,PIKE_T_STRING,permission_type)
64dc4c1999-04-17Henrik Grubbström (Grubba) )
010dc62001-08-16Martin Stjernholm  DECLARE_ERROR(cpp, ERR_INHERIT(generic), EMPTY)
32ffa12001-08-16Martin Stjernholm DECLARE_ERROR(compilation, ERR_INHERIT(generic), EMPTY)
667ec22003-07-22Martin Stjernholm DECLARE_ERROR(master_load, ERR_INHERIT (generic), EMPTY)
81299f1999-03-19Fredrik Hübinette (Hubbe) #undef DECLARE_ERROR #undef ERR_INHERIT #undef ERR_VAR
f93ed42001-08-20Martin Stjernholm #undef EMPTY
81299f1999-03-19Fredrik Hübinette (Hubbe) #undef ERR_FUNC #undef ERR_DECLARE
928b782000-06-05Henrik Grubbström (Grubba) #undef ERR_EXT_DECLARE
81299f1999-03-19Fredrik Hübinette (Hubbe) #undef ERR_SETUP #undef ERR_CLEANUP