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.
c853da2008-05-22Martin Stjernholm || $Id: errors.h,v 1.37 2008/05/22 20:17:13 mast Exp $
e576bb2002-10-11Martin Nilsson */
1b10db2002-10-08Martin Nilsson 
81299f1999-03-19Fredrik Hübinette (Hubbe) #ifdef ERR_DECLARE
df019f2004-04-18Martin Stjernholm #define DECLARE_ERROR(NAME, SCNAME, INHERIT, DECL) \
fa8c692000-11-30Fredrik Hübinette (Hubbe) PMOD_EXPORT struct program *PIKE_CONCAT(NAME,_error_program); \
0269592006-09-20Martin Stjernholm ptrdiff_t PIKE_CONCAT(NAME,_error_offset); \ DECL #define ERR_FUNC_SAVE_ID(VAR, NAME, FUNC, TYPE, FLAGS) static int VAR;
928b782000-06-05Henrik Grubbström (Grubba)  #endif #ifdef ERR_EXT_DECLARE
df019f2004-04-18Martin Stjernholm #define DECLARE_ERROR(NAME, SCNAME, 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 ;
c853da2008-05-22Martin Stjernholm #define ERR_CONST(TYPE, NAME, VALUE)
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
df019f2004-04-18Martin Stjernholm #define DECLARE_ERROR(NAME, SCNAME, 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));\
df019f2004-04-18Martin Stjernholm  add_string_constant("error_type", #SCNAME, 0); \
81299f1999-03-19Fredrik Hübinette (Hubbe)  add_integer_constant("is_" #NAME "_error",1,0); \ DECL \ PIKE_CONCAT(NAME,_error_program)=end_program(); \
df019f2004-04-18Martin Stjernholm  add_program_constant( #SCNAME "Error",PIKE_CONCAT(NAME,_error_program),0); \
81299f1999-03-19Fredrik Hübinette (Hubbe) }while(0); #define ERR_VAR(TYPE,CTYPE,RUNTYPE,NAME2) \
892b8a2005-01-20Martin Nilsson  MAP_VARIABLE(#NAME2, CTYPE, 0, \
81299f1999-03-19Fredrik Hübinette (Hubbe)  current_offset + (((char *)&(foo.NAME2))-((char *)&foo)), RUNTYPE);
c853da2008-05-22Martin Stjernholm #define ERR_CONST(TYPE, NAME, VALUE) \ PIKE_CONCAT3 (add_, TYPE, _constant) (NAME, VALUE, 0);
81299f1999-03-19Fredrik Hübinette (Hubbe) 
1abbfb2006-07-05Martin Stjernholm /* Reference foo just to avoid warning. */
54240e2006-07-05Martin Stjernholm #define EMPTY (void) &foo;
f93ed42001-08-20Martin Stjernholm 
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);
0269592006-09-20Martin Stjernholm #define ERR_FUNC_SAVE_ID(VAR, NAME, FUNC, TYPE, FLAGS) \ VAR = ADD_FUNCTION(NAME,FUNC,TYPE,FLAGS);
81299f1999-03-19Fredrik Hübinette (Hubbe) #endif #ifdef ERR_CLEANUP
df019f2004-04-18Martin Stjernholm #define DECLARE_ERROR(NAME, SCNAME, INHERIT, DECL) \
81299f1999-03-19Fredrik Hübinette (Hubbe)  if(PIKE_CONCAT(NAME,_error_program)) {\ free_program(PIKE_CONCAT(NAME,_error_program)); \ PIKE_CONCAT(NAME,_error_program)=0;\ } #endif
0269592006-09-20Martin Stjernholm #ifndef EMPTY #define EMPTY #endif
81299f1999-03-19Fredrik Hübinette (Hubbe)  #ifndef ERR_INHERIT #define ERR_INHERIT(NAME) #endif #ifndef ERR_VAR #define ERR_VAR(TYPE,CTYPE,RUNTYPE,NAME) #endif
c853da2008-05-22Martin Stjernholm #ifndef ERR_CONST #define ERR_CONST(TYPE, NAME, VALUE) #endif
81299f1999-03-19Fredrik Hübinette (Hubbe) #ifndef ERR_FUNC #define ERR_FUNC(NAME,FUNC,TYPE,FLAGS) #endif
0269592006-09-20Martin Stjernholm #ifndef ERR_FUNC_SAVE_ID #define ERR_FUNC_SAVE_ID(VAR, NAME, FUNC, TYPE, FLAGS) #endif
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(generic, Generic, EMPTY ,
892b8a2005-01-20Martin Nilsson  ERR_VAR(struct pike_string *,tStr,PIKE_T_STRING,error_message) ERR_VAR(struct array *,tArray,PIKE_T_ARRAY,error_backtrace)
5e05fb2005-01-21Martin Stjernholm  ERR_FUNC("cast",f_error_cast,tFunc(tString,tArray),ID_STATIC) ERR_FUNC("`[]",f_error_index,tFunc(tInt01,tMixed),ID_STATIC)
81299f1999-03-19Fredrik Hübinette (Hubbe)  ERR_FUNC("describe",f_error_describe,tFunc(tVoid,tString),0)
0269592006-09-20Martin Stjernholm  ERR_FUNC_SAVE_ID (generic_err_message_fun, "message", f_error_message, tFunc(tVoid,tString), 0) ERR_FUNC_SAVE_ID (generic_err_backtrace_fun, "backtrace", f_error_backtrace, tFunc(tVoid,tArr(tMixed)),0)
5e05fb2005-01-21Martin Stjernholm  ERR_FUNC("_sprintf", f_error__sprintf, tFunc(tOr(tInt,tVoid) tOr(tMapping,tVoid),tString), ID_STATIC)
1182472006-08-21Henrik Grubbström (Grubba)  ERR_FUNC("_is_type", f_error__is_type, tFunc(tString, tInt01), ID_STATIC)
1dc55b2004-12-17Martin Stjernholm  ERR_FUNC("create",f_error_create,tFunc(tStr tOr(tVoid,tArr(tMixed)),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) 
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(index, Index,
81299f1999-03-19Fredrik Hübinette (Hubbe)  ERR_INHERIT(generic),
892b8a2005-01-20Martin Nilsson  ERR_VAR(struct svalue, tMix, PIKE_T_MIXED, value) ERR_VAR(struct svalue, tMix, PIKE_T_MIXED, index)
81299f1999-03-19Fredrik Hübinette (Hubbe) )
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(bad_argument, BadArgument,
81299f1999-03-19Fredrik Hübinette (Hubbe)  ERR_INHERIT(generic),
892b8a2005-01-20Martin Nilsson  ERR_VAR(INT_TYPE, tInt, PIKE_T_INT, which_argument) ERR_VAR(struct pike_string *, tStr,PIKE_T_STRING,expected_type) ERR_VAR(struct svalue, tMix, PIKE_T_MIXED, got_value)
81299f1999-03-19Fredrik Hübinette (Hubbe) )
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(math, Math,
d0ed261999-03-20Fredrik Hübinette (Hubbe)  ERR_INHERIT(generic),
892b8a2005-01-20Martin Nilsson  ERR_VAR(struct svalue, tMix, PIKE_T_MIXED, number)
d0ed261999-03-20Fredrik Hübinette (Hubbe) )
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(resource, Resource,
d0ed261999-03-20Fredrik Hübinette (Hubbe)  ERR_INHERIT(generic),
892b8a2005-01-20Martin Nilsson  ERR_VAR(struct pike_string *, tStr, PIKE_T_STRING,resource_type) ERR_VAR(INT_TYPE, tInt, PIKE_T_INT, howmuch)
d0ed261999-03-20Fredrik Hübinette (Hubbe) )
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(permission, Permission,
64dc4c1999-04-17Henrik Grubbström (Grubba)  ERR_INHERIT(generic),
892b8a2005-01-20Martin Nilsson  ERR_VAR(struct pike_string *, tStr, PIKE_T_STRING,permission_type)
64dc4c1999-04-17Henrik Grubbström (Grubba) )
010dc62001-08-16Martin Stjernholm 
c853da2008-05-22Martin Stjernholm DECLARE_ERROR( cpp, Cpp, ERR_INHERIT(generic), ERR_CONST (integer, "is_cpp_or_compilation_error", 1) )
010dc62001-08-16Martin Stjernholm 
c853da2008-05-22Martin Stjernholm DECLARE_ERROR( compilation, Compilation, ERR_INHERIT(generic), ERR_CONST (integer, "is_cpp_or_compilation_error", 1) )
32ffa12001-08-16Martin Stjernholm 
df019f2004-04-18Martin Stjernholm DECLARE_ERROR(master_load, MasterLoad, ERR_INHERIT (generic), EMPTY)
667ec22003-07-22Martin Stjernholm 
df019f2004-04-18Martin Stjernholm DECLARE_ERROR (module_load, ModuleLoad,
20b5222004-03-22Martin Stjernholm  ERR_INHERIT (generic),
892b8a2005-01-20Martin Nilsson  ERR_VAR (struct pike_string *, tStr, PIKE_T_STRING, path) ERR_VAR (struct pike_string *, tStr, PIKE_T_STRING, reason)
20b5222004-03-22Martin Stjernholm )
81299f1999-03-19Fredrik Hübinette (Hubbe) #undef DECLARE_ERROR #undef ERR_INHERIT #undef ERR_VAR
c853da2008-05-22Martin Stjernholm #undef ERR_CONST
f93ed42001-08-20Martin Stjernholm #undef EMPTY
81299f1999-03-19Fredrik Hübinette (Hubbe) #undef ERR_FUNC
0269592006-09-20Martin Stjernholm #undef ERR_FUNC_SAVE_ID
81299f1999-03-19Fredrik Hübinette (Hubbe)  #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