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. */
1b10db2002-10-08Martin Nilsson 
81299f1999-03-19Fredrik Hübinette (Hubbe) #ifdef ERR_DECLARE
d98ad32008-05-23Henrik Grubbström (Grubba) #define DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT) \ PMOD_EXPORT struct program *PIKE_CONCAT(NAME,_error_program);
df019f2004-04-18Martin Stjernholm #define DECLARE_ERROR(NAME, SCNAME, INHERIT, DECL) \
d98ad32008-05-23Henrik Grubbström (Grubba)  DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT) \ ptrdiff_t PIKE_CONCAT(NAME,_error_offset); \ DECL
0269592006-09-20Martin Stjernholm  #define ERR_FUNC_SAVE_ID(VAR, NAME, FUNC, TYPE, FLAGS) static int VAR;
928b782000-06-05Henrik Grubbström (Grubba)  #endif #ifdef ERR_EXT_DECLARE
d98ad32008-05-23Henrik Grubbström (Grubba) #define DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT) \ PMOD_EXPORT extern struct program *PIKE_CONCAT(NAME,_error_program); #define DECLARE_ERROR(NAME, SCNAME, INHERIT, DECL) \ DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT) \ extern ptrdiff_t PIKE_CONCAT(NAME,_error_offset); \ struct PIKE_CONCAT(NAME,_error_struct) { \ DECL \ };
81299f1999-03-19Fredrik Hübinette (Hubbe)  #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... */
d98ad32008-05-23Henrik Grubbström (Grubba) /* #define EMPTY ERR_VAR(INT_TYPE, int, PIKE_T_INT, ignored__) */
65a7eb2001-08-16Henrik Grubbström (Grubba) 
928b782000-06-05Henrik Grubbström (Grubba) #endif /* ERR_EXT_DECLARE */
81299f1999-03-19Fredrik Hübinette (Hubbe)  #ifdef ERR_SETUP
d98ad32008-05-23Henrik Grubbström (Grubba) #define DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT) do { \ start_new_program(); \ INHERIT \ add_string_constant("error_type", #SCNAME, 0); \
a18d9a2008-05-27Martin Stjernholm  add_string_constant ("error_name", "Error." #SCNAME, ID_PRIVATE|ID_USED); \
d98ad32008-05-23Henrik Grubbström (Grubba)  add_integer_constant("is_" #NAME "_error",1,0); \ PIKE_CONCAT(NAME,_error_program)=end_program(); \ add_program_constant( #SCNAME "Error",PIKE_CONCAT(NAME,_error_program),0); \ } while(0); #define DECLARE_ERROR(NAME, SCNAME, INHERIT, DECL) do { \ ptrdiff_t current_offset=0; \ struct PIKE_CONCAT(NAME,_error_struct) foo; \ DECLARE_PURE_ERROR(NAME, SCNAME, \ INHERIT \ current_offset = \ PIKE_CONCAT(NAME,_error_offset) = \ ADD_STORAGE(struct PIKE_CONCAT(NAME,_error_struct)); \ DECL) \ } while(0);
81299f1999-03-19Fredrik Hübinette (Hubbe)  #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. */
d98ad32008-05-23Henrik Grubbström (Grubba) /* #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
d98ad32008-05-23Henrik Grubbström (Grubba) #define DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT) \ if(PIKE_CONCAT(NAME,_error_program)) { \ free_program(PIKE_CONCAT(NAME,_error_program)); \ PIKE_CONCAT(NAME,_error_program)=0; \
81299f1999-03-19Fredrik Hübinette (Hubbe)  }
d98ad32008-05-23Henrik Grubbström (Grubba) #define DECLARE_ERROR(NAME, SCNAME, INHERIT, DECL) \ DECLARE_PURE_ERROR(NAME, SCNAME, INHERIT)
81299f1999-03-19Fredrik Hübinette (Hubbe) #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)
68ec3f2014-08-18Martin Nilsson  ERR_FUNC("cast",f_error_cast,tFunc(tString,tArray),ID_PRIVATE)
95489a2008-06-29Martin Nilsson  ERR_FUNC("`[]",f_error_index,tFunc(tInt01,tMixed),ID_PROTECTED)
87f2e92013-06-10Henrik Grubbström (Grubba)  ERR_FUNC("_sizeof",f_error__sizeof,tFunc(tNone,tInt2),ID_PROTECTED) ERR_FUNC("_indices",f_error__indices,tFunc(tNone,tArr(tInt01)),ID_PROTECTED) ERR_FUNC("_values",f_error__values,tFunc(tNone,tArr(tOr(tStr,tArr(tMixed)))),ID_PROTECTED)
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,
95489a2008-06-29Martin Nilsson  tFunc(tOr(tInt,tVoid) tOr(tMapping,tVoid),tString), ID_PROTECTED) ERR_FUNC("_is_type", f_error__is_type, tFunc(tString, tInt01), ID_PROTECTED) ERR_FUNC("create",f_error_create,tFunc(tStr tOr(tVoid,tArr(tMixed)),tVoid),ID_PROTECTED)
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 
2ac4992011-03-09Martin Stjernholm DECLARE_ERROR (decode, Decode, ERR_INHERIT (generic), ERR_VAR (struct pike_string *, tStr, PIKE_T_STRING, decode_string) )
d98ad32008-05-23Henrik Grubbström (Grubba) DECLARE_PURE_ERROR( cpp, Cpp, ERR_INHERIT(generic)
c853da2008-05-22Martin Stjernholm  ERR_CONST (integer, "is_cpp_or_compilation_error", 1) )
010dc62001-08-16Martin Stjernholm 
d98ad32008-05-23Henrik Grubbström (Grubba) DECLARE_PURE_ERROR( compilation, Compilation, ERR_INHERIT(generic)
c853da2008-05-22Martin Stjernholm  ERR_CONST (integer, "is_cpp_or_compilation_error", 1) )
32ffa12001-08-16Martin Stjernholm 
d98ad32008-05-23Henrik Grubbström (Grubba) DECLARE_PURE_ERROR(master_load, MasterLoad, ERR_INHERIT (generic))
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 )
d98ad32008-05-23Henrik Grubbström (Grubba) #undef DECLARE_PURE_ERROR
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