a4aae52002-11-06Martin Nilsson // $Id: Subject.pike,v 1.6 2002/11/06 04:59:06 nilsson Exp $
344cae2002-10-20Martin Nilsson  //! This is a probe subject which you can send in somewhere to //! get probed (not to be confused with a probe object, which
8024d82002-10-31Johan Sundström //! does some active probing). All calls to LFUNs will be printed //! to stderr. It is possible to name the subject by passing a //! string as the first and only argument when creating the subject
344cae2002-10-20Martin Nilsson //! object. //! //! @example //! > object s = Debug.Subject();
8024d82002-10-31Johan Sundström //! create()
344cae2002-10-20Martin Nilsson //! > random(s);
8024d82002-10-31Johan Sundström //! _random()
344cae2002-10-20Martin Nilsson //! (1) Result: 0 //! > abs(s);
8024d82002-10-31Johan Sundström //! `<(0) //! _sprintf(79, ([ "indent":2 ]))
344cae2002-10-20Martin Nilsson //! (2) Result: Debug.Subject //! > abs(class { inherit Debug.Subject; int `<(mixed ... args) { return 1; } }());
8024d82002-10-31Johan Sundström //! create() //! `-() //! destroy()
344cae2002-10-20Martin Nilsson //! (3) Result: 0 //! > pow(s,2);
8024d82002-10-31Johan Sundström //! `[]("pow")
344cae2002-10-20Martin Nilsson //! Attempt to call the NULL-value //! Unknown program: 0(2)
8024d82002-10-31Johan Sundström #define ENTER(X) \ string t = sprintf("%{%O, %}", args); \ werror("%s%s(%s)\n", id, #X, \ has_suffix(t, ", ") ? t[..sizeof(t)-3] : t) #define PROXY(X,Y) X(mixed ... args) { ENTER(X); return Y; }
344cae2002-10-20Martin Nilsson  static string id = "";
8024d82002-10-31Johan Sundström void create(mixed ... args) { ENTER(create);
344cae2002-10-20Martin Nilsson  if(sizeof(args)==1 && stringp(args[0])) id = "(" + args[0] + ") "; }
4d18f62002-10-21Marek Habersack void PROXY(destroy, 0); mixed PROXY(`->, 0); mixed PROXY(`->=, 0); mixed PROXY(`[], 0); mixed PROXY(`[]=, 0); mixed PROXY(`+, 0); mixed PROXY(`-, 0); mixed PROXY(`&, 0); mixed PROXY(`|, 0); mixed PROXY(`^, 0); mixed PROXY(`<<, 0); mixed PROXY(`>>, 0); mixed PROXY(`*, 0); mixed PROXY(`/, 0); mixed PROXY(`%, 0); mixed PROXY(`~, 0); int(0..1) PROXY(`==, 0); int(0..1) PROXY(`<, 0); int(0..1) PROXY(`>, 0); int PROXY(`!, 0); int PROXY(__hash, 0); int PROXY(_sizeof, 0); mixed PROXY(cast, 0); mixed PROXY(`(), 0); mixed PROXY(``+, 0); mixed PROXY(``-, 0); mixed PROXY(``&, 0); mixed PROXY(``|, 0); mixed PROXY(``^, 0); mixed PROXY(``<<, 0); mixed PROXY(``>>, 0); mixed PROXY(``*, 0); mixed PROXY(``/, 0); mixed PROXY(``%, 0); mixed PROXY(`+=, 0); int(0..1) PROXY(_is_type, 0); int PROXY(_equal, 0); mixed PROXY(_m_delete, 0);
a4aae52002-11-06Martin Nilsson //! @ignore array PROXY(_indices, ::_indices()); array PROXY(_values, ::_values()); //! @endignore
344cae2002-10-20Martin Nilsson 
8024d82002-10-31Johan Sundström object _get_iterator(mixed ... args) { ENTER(_get_iterator);
344cae2002-10-20Martin Nilsson  string iid = id==""?"":id[1..sizeof(id)-3]; return this_program("("+iid+" iterator) "); }
8024d82002-10-31Johan Sundström string _sprintf(int|void t, mapping|void opt, mixed ... x) { string args = ""; if(t) args += sprintf("'%c'", t); if(opt == ([])) args += ", ([])"; else if(opt) { string tmp = sprintf("%O", opt); sscanf(tmp, "([ /*%*s*/\n %s\n])", tmp); args += sprintf(", ([ %s ])", replace(tmp, "\n ", "")); } string tmp = sprintf("%{%O, %}", x); if(has_suffix(tmp, ", ")) tmp = tmp[..sizeof(tmp)-3]; if(sizeof(tmp)) args += ", " + tmp; werror("%s_sprintf(%s)\n", id, args); return "Debug.Subject" + id[..sizeof(id)-2];
344cae2002-10-20Martin Nilsson }
4d18f62002-10-21Marek Habersack mixed PROXY(_random, 0);