be7327 | 2001-06-18 | Martin Stjernholm | |
|
69e4a4 | 2001-08-14 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
6c902e | 2000-03-17 | Martin Stjernholm | | static object Roxen;
|
4becf2 | 2000-03-19 | Martin Nilsson | | class RequestID { };
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
12dd77 | 2001-07-20 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d8769c | 2000-02-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
cd7d5f | 2000-02-16 | Martin Stjernholm | | #include <config.h>
|
e8dffa | 2001-05-14 | Per Hedbor | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | #include <request_trace.h>
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #define MAGIC_HELP_ARG
|
fb605b | 2001-07-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
80e42c | 2001-06-26 | Martin Stjernholm | |
|
deecca | 2001-06-28 | Martin Stjernholm | |
|
13a5c3 | 2001-07-16 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
f853b8 | 2001-07-19 | Martin Stjernholm | |
|
423412 | 2001-08-14 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
e8dffa | 2001-05-14 | Per Hedbor | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define MARK_OBJECT \
|
fb605b | 2001-07-11 | Martin Stjernholm | | mapping|object __object_marker = Debug.ObjectMarker (this_object())
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define MARK_OBJECT_ONLY \
|
fb605b | 2001-07-11 | Martin Stjernholm | | mapping|object __object_marker = Debug.ObjectMarker (0)
|
ec027c | 2000-03-16 | Martin Stjernholm | | #else
|
a529ca | 2001-07-11 | Martin Stjernholm | | # define MARK_OBJECT ;
# define MARK_OBJECT_ONLY ;
|
ec027c | 2000-03-16 | Martin Stjernholm | | #endif
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #ifdef OBJ_COUNT_DEBUG
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # ifndef RXML_OBJ_DEBUG
# undef MARK_OBJECT
# undef MARK_OBJECT_ONLY
# define MARK_OBJECT \
|
fb605b | 2001-07-11 | Martin Stjernholm | | mapping|object __object_marker = (["count": ++all_constants()->_obj_count])
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define MARK_OBJECT_ONLY \
|
fb605b | 2001-07-11 | Martin Stjernholm | | mapping|object __object_marker = (["count": ++all_constants()->_obj_count])
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # endif
# define OBJ_COUNT (__object_marker ? "[" + __object_marker->count + "]" : "")
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #else
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define OBJ_COUNT ""
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #ifdef RXML_VERBOSE
|
09a16e | 2001-07-10 | Martin Stjernholm | | # define TAG_DEBUG_TEST(test) 1
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #else
|
423412 | 2001-08-14 | Martin Stjernholm | | # define TAG_DEBUG_TEST(test) (test)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #endif
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
09a16e | 2001-07-10 | Martin Stjernholm | | # define TAG_DEBUG(frame, msg, args...) \
|
a529ca | 2001-07-11 | Martin Stjernholm | | (TAG_DEBUG_TEST (frame && frame->flags & FLAG_DEBUG) && \
|
09a16e | 2001-07-10 | Martin Stjernholm | | report_debug ("%O: " + (msg), (frame), args), 0)
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | # define DO_IF_DEBUG(code...) code
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #else
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | # define TAG_DEBUG(frame, msg, args...) 0
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | # define DO_IF_DEBUG(code...)
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #ifdef MODULE_DEBUG
# define DO_IF_MODULE_DEBUG(code...) code
#else
# define DO_IF_MODULE_DEBUG(code...)
#endif
|
f853b8 | 2001-07-19 | Martin Stjernholm | | #ifdef FRAME_DEPTH_DEBUG
# define FRAME_DEPTH_MSG(msg...) report_debug (msg)
#else
# define FRAME_DEPTH_MSG(msg...)
#endif
|
a529ca | 2001-07-11 | Martin Stjernholm | | #define _LITERAL(X) #X
#define LITERAL(X) _LITERAL (X)
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #define HASH_INT2(m, n) (n < 65536 ? (m << 16) + n : sprintf ("%x,%x", m, n))
|
be7327 | 2001-06-18 | Martin Stjernholm | | #undef RXML_CONTEXT
#if constant (thread_create)
# define RXML_CONTEXT (_cur_rxml_context->get())
# define SET_RXML_CONTEXT(ctx) (_cur_rxml_context->set (ctx))
#else
# define RXML_CONTEXT (_cur_rxml_context)
# define SET_RXML_CONTEXT(ctx) (_cur_rxml_context = (ctx))
#endif
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
#define SCOPE_TYPE mapping(string:mixed)|object(Scope)
|
d4768a | 2001-05-18 | Martin Stjernholm | | #define UNWIND_STATE mapping(string|object:mixed|array)
|
02a656 | 2001-07-09 | Martin Stjernholm | | #define EVAL_ARGS_FUNC function(Context,Parser|PCode:mapping(string:mixed))|string
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
23a088 | 2000-08-12 | Martin Stjernholm | |
|
6570bf | 2001-06-29 | Martin Stjernholm | |
static int tag_set_count = 0;
|
02a656 | 2001-07-09 | Martin Stjernholm | | static mapping(int|string:TagSet) garb_composite_tag_set_cache()
|
6570bf | 2001-06-29 | Martin Stjernholm | | {
|
02a656 | 2001-07-09 | Martin Stjernholm | | call_out (garb_composite_tag_set_cache, 30*60);
return composite_tag_set_cache = ([]);
|
6570bf | 2001-06-29 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | static mapping(int|string:TagSet) composite_tag_set_cache =
garb_composite_tag_set_cache();
#define GET_COMPOSITE_TAG_SET(a, b, res) do { \
int|string hash = HASH_INT2 (b->id_number, a->id_number); \
if (!(res = composite_tag_set_cache[hash])) { \
|
59b056 | 2001-07-11 | Martin Stjernholm | | res = shared_tag_set ( \
a->name && b->name && \
sprintf ("[%d]%s+%s", sizeof (a->name), a->name, b->name)); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | res->imported = ({a, b}); \
/* Race, but it doesn't matter. */ \
composite_tag_set_cache[hash] = res; \
} \
} while (0)
|
6570bf | 2001-06-29 | Martin Stjernholm | |
|
7e0fda | 2001-07-12 | Martin Stjernholm | | static mapping(string:TagSet|int) all_tagsets = set_weak_flag(([]), 1);
|
6570bf | 2001-06-29 | Martin Stjernholm | |
static mapping(string:program) reg_parsers = ([]);
static mapping(string:Type) reg_types = ([]);
static mapping(mixed:string) reverse_constants = set_weak_flag (([]), 1);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Tag
{
|
cece9e | 2000-01-11 | Martin Stjernholm | | constant is_RXML_Tag = 1;
|
c1ee00 | 2001-06-29 | Martin Stjernholm | | constant is_RXML_encodable = 1;
|
02a656 | 2001-07-09 | Martin Stjernholm | | constant is_RXML_p_code_frame = 1;
|
cf042f | 2001-07-21 | Martin Stjernholm | | constant is_RXML_p_code_entry = 1;
|
cece9e | 2000-01-11 | Martin Stjernholm | |
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
fc7549 | 2001-06-22 | Marcus Comstedt | | TagSet tagset;
|
f58572 | 2000-01-18 | Martin Stjernholm | | int flags;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | | mapping(string:Type) req_arg_types = ([]);
mapping(string:Type) opt_arg_types = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | | Type def_arg_type = t_text (PEnt);
|
3187d8 | 2000-01-28 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
3187d8 | 2000-01-28 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | Type content_type = t_same (PXml);
|
590b3c | 2000-02-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
be7327 | 2001-06-18 | Martin Stjernholm | | array(Type) result_types = ({t_string, t_any_text});
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
be7327 | 2001-06-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | final object `() (mapping(string:mixed) args, void|mixed content)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
02a656 | 2001-07-09 | Martin Stjernholm | | object frame =
([function(:object)] this_object()->Frame)();
frame->tag = this_object();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | frame->flags = flags;
frame->args = args;
|
23a088 | 2000-08-12 | Martin Stjernholm | | frame->content = zero_type (content) ? nil : content;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return frame;
}
|
3704fa | 2001-06-09 | Martin Nilsson | | int eval_args (mapping(string:mixed) args, void|int dont_throw,
void|Context ctx, void|array(string) ignore_args)
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
3704fa | 2001-06-09 | Martin Nilsson | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | {
|
a529ca | 2001-07-11 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | | mapping(string:Type) atypes = args & req_arg_types;
if (sizeof (atypes) < sizeof (req_arg_types))
if (dont_throw) return 0;
else {
array(string) missing = sort (indices (req_arg_types - atypes));
|
5ed013 | 2000-02-13 | Martin Stjernholm | | parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (missing) + " are" :
"argument " + missing[0] + " is") + " missing.\n");
|
710b48 | 2000-02-07 | Martin Stjernholm | | }
atypes += args & opt_arg_types;
|
c159ec | 2000-02-04 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
710b48 | 2000-02-07 | Martin Stjernholm | | if (mixed err = catch {
|
c159ec | 2000-02-04 | Martin Stjernholm | | #endif
|
3704fa | 2001-06-09 | Martin Nilsson | | foreach (indices (args) - ( ignore_args||({}) ), string arg)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | args[arg] = (atypes[arg] || def_arg_type)->eval (
args[arg], ctx);
|
c159ec | 2000-02-04 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
710b48 | 2000-02-07 | Martin Stjernholm | | }) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
|
c159ec | 2000-02-04 | Martin Stjernholm | | }
|
710b48 | 2000-02-07 | Martin Stjernholm | | #endif
|
c159ec | 2000-02-04 | Martin Stjernholm | | return 1;
}
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | #define MAKE_FRAME(_frame, _ctx, _parser, _args, _content) \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | make_new_frame: do { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (UNWIND_STATE ustate = _ctx->unwind_state) \
if (ustate[_parser]) { \
_frame = [object/*(Frame)HMM*/] ustate[_parser][0]; \
m_delete (ustate, _parser); \
if (!sizeof (ustate)) _ctx->unwind_state = 0; \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | break make_new_frame; \
} \
|
02a656 | 2001-07-09 | Martin Stjernholm | | _frame = \
([function(:object/*(Frame)HMM*/)] this_object()->Frame)(); \
_frame->tag = this_object(); \
_frame->flags = flags|FLAG_UNPARSED; \
_frame->args = _args; \
_frame->content = _content || ""; \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | DO_IF_DEBUG( \
|
079f36 | 2001-06-29 | Martin Stjernholm | | if (_args && ([mapping] (mixed) _args)["_debug_"]) { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _frame->flags |= FLAG_DEBUG; \
|
079f36 | 2001-06-29 | Martin Stjernholm | | m_delete (_args, "_debug_"); \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | } \
); \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | } while (0)
|
02a656 | 2001-07-09 | Martin Stjernholm | | #define EVAL_FRAME(_frame, _ctx, _parser, _type, _res) \
do { \
|
446bfa | 2001-06-21 | Martin Stjernholm | | EVAL_ARGS_FUNC argfunc = 0; \
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (mixed err = catch { \
_res = _frame->_eval (_ctx, _parser, _type); \
|
fb605b | 2001-07-11 | Martin Stjernholm | | if (PCode p_code = _parser->p_code) \
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | p_code->add_frame (_ctx, _frame, _res); \
}) \
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) { \
UNWIND_STATE ustate = _ctx->unwind_state; \
if (!ustate) ustate = _ctx->unwind_state = ([]); \
DO_IF_DEBUG ( \
if (err != _frame) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Unexpected unwind object catched.\n"); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (ustate[_parser]) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Clobbering unwind state for parser.\n"); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | ); \
ustate[_parser] = ({_frame}); \
throw (_parser); \
} \
else { \
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | if (PCode p_code = _parser->p_code) \
p_code->add_frame (_ctx, _frame, PCode); \
throw (err); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | } \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | } while (0)
final mixed handle_tag (TagSetParser parser, mapping(string:string) args,
void|string content)
{
Context ctx = parser->context;
object frame;
|
02a656 | 2001-07-09 | Martin Stjernholm | | MAKE_FRAME (frame, ctx, parser, args, content);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!zero_type (frame->raw_tag_text))
frame->raw_tag_text = parser->raw_tag_text();
mixed result;
|
02a656 | 2001-07-09 | Martin Stjernholm | | EVAL_FRAME (frame, ctx, parser, parser->type, result);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return result;
}
final array _p_xml_handle_tag (object parser, mapping(string:string) args,
void|string content)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | Type type = parser->type;
|
446bfa | 2001-06-21 | Martin Stjernholm | | parser->drain_output();
|
56532d | 1999-12-19 | Martin Stjernholm | | Context ctx = parser->context;
|
f99720 | 2000-01-18 | Martin Stjernholm | | object frame;
|
02a656 | 2001-07-09 | Martin Stjernholm | | MAKE_FRAME (frame, ctx, parser, args, content);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!zero_type (frame->raw_tag_text))
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | frame->raw_tag_text = parser->current_input();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed result;
|
02a656 | 2001-07-09 | Martin Stjernholm | | EVAL_FRAME (frame, ctx, parser, type, result);
|
446bfa | 2001-06-21 | Martin Stjernholm | | if (result != nil) parser->add_value (result);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final array _p_xml_handle_pi_tag (object parser, string content)
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | Type type = parser->type;
|
446bfa | 2001-06-21 | Martin Stjernholm | | parser->drain_output();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | | sscanf (content, "%[ \t\n\r]%s", string ws, string rest);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (ws == "" && rest != "") {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!type->free_text)
return utils->unknown_pi_tag_error (parser, content);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return 0;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | Context ctx = parser->context;
object frame;
|
02a656 | 2001-07-09 | Martin Stjernholm | | MAKE_FRAME (frame, ctx, parser, 0, content);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!zero_type (frame->raw_tag_text))
frame->raw_tag_text = parser->current_input();
mixed result;
|
02a656 | 2001-07-09 | Martin Stjernholm | | EVAL_FRAME (frame, ctx, parser, type, result);
|
446bfa | 2001-06-21 | Martin Stjernholm | | if (result != nil) parser->add_value (result);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
|
87fb7e | 2000-03-25 | Martin Stjernholm | | }
|
a529ca | 2001-07-11 | Martin Stjernholm | | mapping(string:mixed) _eval_splice_args (Context ctx,
mapping(string:string) raw_args,
mapping(string:Type) my_req_args)
{
mapping(string:Type) atypes =
raw_args & (req_arg_types | opt_arg_types);
if (my_req_args) {
mapping(string:Type) missing = my_req_args - atypes;
if (sizeof (missing))
parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (
sort (indices (missing))) + " are" :
"argument " + indices (missing)[0] + " is") + " missing.\n");
}
#ifdef MODULE_DEBUG
if (mixed err = catch {
#endif
foreach (indices (raw_args), string arg) {
Type t = atypes[arg] || def_arg_type;
if (t->parser_prog != PNone) {
Parser parser = t->get_parser (ctx, ctx->tag_set, 0);
TAG_DEBUG (RXML_CONTEXT->frame,
"Evaluating argument value %s with %O\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (raw_args[arg]), parser);
|
a529ca | 2001-07-11 | Martin Stjernholm | | parser->finish (raw_args[arg]);
raw_args[arg] = parser->eval();
TAG_DEBUG (RXML_CONTEXT->frame,
"Setting dynamic argument %s to %s\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (arg),
format_short (raw_args[arg]));
|
a529ca | 2001-07-11 | Martin Stjernholm | | t->give_back (parser, ctx->tag_set);
}
}
#ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when evaluating dynamic arguments.\n");
throw_fatal (err);
}
#endif
return raw_args;
}
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT;
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string _sprintf()
{
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return "RXML.Tag(" + [string] this_object()->name +
(this_object()->plugin_name ? "#" + [string] this_object()->plugin_name : "") +
([int] this_object()->flags & FLAG_PROC_INSTR ? " [PI]" : "") + ")" +
OBJ_COUNT;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
class TagSet
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
c1ee00 | 2001-06-29 | Martin Stjernholm | | constant is_RXML_TagSet = 1;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | string name;
|
deecca | 2001-06-28 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string prefix;
|
f99720 | 2000-01-18 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f99720 | 2000-01-18 | Martin Stjernholm | | int prefix_req;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
array(TagSet) imported = ({});
|
936f63 | 2001-07-16 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
660cb5 | 2000-01-12 | Martin Stjernholm | | function(Context:void) prepare_context;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
be7327 | 2001-06-18 | Martin Stjernholm | |
function(Context:void) eval_finish;
|
660cb5 | 2000-01-12 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int generation = 1;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | int id_number;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | static void create (string _name, void|array(Tag) _tags)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
f02d00 | 2000-03-18 | Martin Stjernholm | | id_number = ++tag_set_count;
|
c1ac6c | 2001-07-02 | Martin Stjernholm | | set_name (_name);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (_tags) add_tags (_tags);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
__object_marker->create (this_object());
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void add_tag (Tag tag)
{
|
e82104 | 2000-08-17 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (!stringp (tag->name))
error ("Trying to register a tag %O without a name.\n", tag);
|
055e93 | 2001-04-09 | Per Hedbor | | if (!callablep (tag->Frame) && !tag->plugin_name)
|
e82104 | 2000-08-17 | Martin Stjernholm | | error ("Trying to register a tag %O without a Frame class or function.\n", tag);
|
1a65d9 | 2000-08-30 | Martin Stjernholm | | if (tag->name[..3] != "!--#" &&
replace (tag->name, "#<>& \t\n\r" / "", ({""}) * 8) != tag->name)
error ("Invalid character(s) in name for tag %O.\n", tag);
|
e82104 | 2000-08-17 | Martin Stjernholm | | #endif
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (tag->flags & FLAG_PROC_INSTR) {
if (!proc_instrs) proc_instrs = ([]);
if (tag->plugin_name) proc_instrs[tag->name + "#" + tag->plugin_name] = tag;
else proc_instrs[tag->name] = tag;
}
else
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag;
else tags[tag->name] = tag;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
void add_tags (array(Tag) _tags)
{
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | foreach (_tags, Tag tag) {
|
e82104 | 2000-08-17 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (!stringp (tag->name))
error ("Trying to register a tag %O without a name.\n", tag);
|
055e93 | 2001-04-09 | Per Hedbor | | if (!callablep (tag->Frame)&& !tag->plugin_name)
|
e82104 | 2000-08-17 | Martin Stjernholm | | error ("Trying to register a tag %O without a Frame class or function.\n", tag);
|
1a65d9 | 2000-08-30 | Martin Stjernholm | | if (tag->name[..3] != "!--#" &&
replace (tag->name, "#<>& \t\n\r" / "", ({""}) * 8) != tag->name)
error ("Invalid character(s) in name for tag %O.\n", tag);
|
e82104 | 2000-08-17 | Martin Stjernholm | | #endif
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (tag->flags & FLAG_PROC_INSTR) {
if (!proc_instrs) proc_instrs = ([]);
if (tag->plugin_name) proc_instrs[tag->name + "#" + tag->plugin_name] = tag;
else proc_instrs[tag->name] = tag;
}
else
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag;
else tags[tag->name] = tag;
|
fc7549 | 2001-06-22 | Marcus Comstedt | | tag->tagset = this_object();
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | void remove_tag (string|Tag tag, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
if (stringp (tag))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (proc_instr) {
if (proc_instrs) m_delete (proc_instrs, tag);
}
else
m_delete (tags, tag);
else {
string n;
if (tag->flags & FLAG_PROC_INSTR) {
if (proc_instrs && !zero_type (n = search (tags, [object(Tag)] tag)))
m_delete (proc_instrs, n);
}
else
if (!zero_type (n = search (tags, [object(Tag)] tag)))
m_delete (tags, n);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
|
2aa1dc | 2001-08-11 | Martin Stjernholm | | void clear()
{
tags = ([]), proc_instrs = 0;
clear_string_entities();
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | local Tag get_local_tag (string name, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return proc_instr ? proc_instrs && proc_instrs[name] : tags[name];
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local array(Tag) get_local_tags()
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | array(Tag) res = values (tags);
if (proc_instrs) res += values (proc_instrs);
return res;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local Tag get_tag (string name, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (object(Tag) def = get_local_tag (name, proc_instr))
|
56ffee | 2000-01-12 | Martin Stjernholm | | return def;
foreach (imported, TagSet tag_set)
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (object(Tag) tag = [object(Tag)] tag_set->get_tag (name, proc_instr))
return tag;
|
56ffee | 2000-01-12 | Martin Stjernholm | | return 0;
|
da54bd | 2000-01-08 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local int has_tag (Tag tag)
{
return !!get_tag (tag->name, tag->flags & FLAG_PROC_INSTR);
}
local multiset(string) get_tag_names()
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
{
return `| ((multiset) indices (tags), @imported->get_tag_names());
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local multiset(string) get_proc_instr_names()
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
{
return `| (proc_instrs ? (multiset) indices (proc_instrs) : (<>),
@imported->get_proc_instr_names());
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local Tag get_overridden_tag (Tag overrider)
|
56ffee | 2000-01-12 | Martin Stjernholm | |
|
2e0a6d | 2000-07-06 | Martin Stjernholm | |
|
da54bd | 2000-01-08 | Martin Stjernholm | | {
|
51f88b | 2000-06-23 | Martin Stjernholm | | if (!mappingp (overridden_tag_lookup))
overridden_tag_lookup = set_weak_flag (([]), 1);
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | Tag tag;
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (zero_type (tag = overridden_tag_lookup[overrider])) {
string overrider_name = overrider->plugin_name ?
overrider->plugin_name + "#" + overrider->name : overrider->name;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | tag = overridden_tag_lookup[overrider] =
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | overrider->flags & FLAG_PROC_INSTR ?
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | find_overridden_proc_instr (overrider, overrider_name) :
find_overridden_tag (overrider, overrider_name);
}
|
51f88b | 2000-06-23 | Martin Stjernholm | | return tag;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local array(Tag) get_overridden_tags (string name, void|int proc_instr)
|
56ffee | 2000-01-12 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
56ffee | 2000-01-12 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (object(Tag) def = get_local_tag (name, proc_instr))
return ({def}) + imported->get_overridden_tags (name, proc_instr) * ({});
else
return imported->get_overridden_tags (name, proc_instr) * ({});
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | }
void add_string_entities (mapping(string:string) entities)
|
fe628d | 2001-03-01 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | {
if (string_entities) string_entities |= entities;
else string_entities = entities + ([]);
changed();
}
void clear_string_entities()
{
string_entities = 0;
changed();
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mapping(string:string) get_string_entities()
|
2e0a6d | 2000-07-06 | Martin Stjernholm | |
{
if (string_entities)
return `+(@imported->get_string_entities(), string_entities);
else
return `+(@imported->get_string_entities(), ([]));
|
56ffee | 2000-01-12 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mapping(string:Tag) get_plugins (string name, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | {
mapping(string:Tag) res;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (proc_instr) {
if (!pi_plugins) pi_plugins = ([]);
if ((res = pi_plugins[name])) return res;
low_get_pi_plugins (name + "#", res = ([]));
return pi_plugins[name] = res;
}
else {
if (!plugins) plugins = ([]);
if ((res = plugins[name])) return res;
low_get_plugins (name + "#", res = ([]));
return plugins[name] = res;
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | }
|
936f63 | 2001-07-16 | Martin Stjernholm | | local string get_hash()
{
if (!hash)
hash = Crypto.md5()->update (encode_value_canonic (get_hash_data()))->digest();
return hash;
}
|
2aa1dc | 2001-08-11 | Martin Stjernholm | | local void add_tag_set_dependency (TagSet tset)
{
dep_tag_sets[tset] = 1;
tset->do_notify (changed);
changed();
}
local void remove_tag_set_dependency (TagSet tset)
{
dep_tag_sets[tset] = 0;
tset->dont_notify (changed);
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local int has_effective_tags (TagSet tset)
|
87fb7e | 2000-03-25 | Martin Stjernholm | |
{
return tset == top_tag_set && !got_local_tags;
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mixed `->= (string var, mixed val)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
switch (var) {
|
deecca | 2001-06-28 | Martin Stjernholm | | case "name":
|
7e0fda | 2001-07-12 | Martin Stjernholm | | if (name) all_tagsets[name] = generation;
|
c1ac6c | 2001-07-02 | Martin Stjernholm | | set_name (val);
|
deecca | 2001-06-28 | Martin Stjernholm | | break;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | case "imported":
|
49897a | 2000-02-13 | Martin Stjernholm | | if (!val) return val;
filter (imported, "dont_notify", changed);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | imported = [array(TagSet)] val;
imported->do_notify (changed);
|
87fb7e | 2000-03-25 | Martin Stjernholm | | top_tag_set = sizeof (imported) && imported[0];
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
default:
::`->= (var, val);
}
changed();
return val;
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mixed `[]= (string var, mixed val) {return `->= (var, val);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
be7327 | 2001-06-18 | Martin Stjernholm | | final Context new_context (void|RequestID id)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
660cb5 | 2000-01-12 | Martin Stjernholm | | Context ctx = Context (this_object(), id);
|
be7327 | 2001-06-18 | Martin Stjernholm | | call_prepare_funs (ctx);
return ctx;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
be7327 | 2001-06-18 | Martin Stjernholm | | final Parser get_parser (Type top_level_type, void|RequestID id, void|int make_p_code)
{
return new_context (id)->new_parser (top_level_type, make_p_code);
}
final Parser `() (Type top_level_type, void|RequestID id, void|int make_p_code)
|
bce4d2 | 2001-06-19 | Martin Stjernholm | | {
return get_parser (top_level_type, id, make_p_code);
}
|
be7327 | 2001-06-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | void changed()
{
generation++;
|
660cb5 | 2000-01-12 | Martin Stjernholm | | prepare_funs = 0;
|
51f88b | 2000-06-23 | Martin Stjernholm | | overridden_tag_lookup = 0;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | plugins = pi_plugins = 0;
|
936f63 | 2001-07-16 | Martin Stjernholm | | hash = 0;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | (notify_funcs -= ({0}))();
set_weak_flag (notify_funcs, 1);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | got_local_tags = sizeof (tags) || (proc_instrs && sizeof (proc_instrs));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
308357 | 2001-04-24 | Martin Nilsson | | function(Backtrace,Type:string) handle_run_error =
lambda (Backtrace err, Type type)
|
f5bd9e | 2001-04-25 | Martin Nilsson | |
|
308357 | 2001-04-24 | Martin Nilsson | | {
|
f5bd9e | 2001-04-25 | Martin Nilsson | | string result;
foreach(imported, TagSet tag_set) {
result = tag_set->handle_run_error(err, type);
if(result) return result;
}
return 0;
|
308357 | 2001-04-24 | Martin Nilsson | | };
function(Backtrace,Type:string) handle_parse_error =
lambda (Backtrace err, Type type)
|
f5bd9e | 2001-04-25 | Martin Nilsson | |
|
308357 | 2001-04-24 | Martin Nilsson | | {
|
f5bd9e | 2001-04-25 | Martin Nilsson | | string result;
foreach(imported, TagSet tag_set) {
result = tag_set->handle_parse_error(err, type);
if(result) return result;
}
return 0;
|
308357 | 2001-04-24 | Martin Nilsson | | };
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
void do_notify (function(:void) func)
{
notify_funcs |= ({func});
set_weak_flag (notify_funcs, 1);
}
void dont_notify (function(:void) func)
{
notify_funcs -= ({func});
set_weak_flag (notify_funcs, 1);
}
|
fae521 | 2001-06-28 | Martin Stjernholm | | static void destroy()
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
catch (changed());
|
7e0fda | 2001-07-12 | Martin Stjernholm | | if (name) all_tagsets[name] = generation;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
c1ac6c | 2001-07-02 | Martin Stjernholm | | static void set_name (string new_name)
{
if (new_name) {
|
10bd2c | 2001-07-12 | Martin Stjernholm | | object(TagSet)|int old_tag_set = all_tagsets[new_name];
if (objectp (old_tag_set)) {
old_tag_set->name = 0;
old_tag_set = old_tag_set->generation;
|
c1ac6c | 2001-07-02 | Martin Stjernholm | | }
|
10bd2c | 2001-07-12 | Martin Stjernholm | | if (generation <= old_tag_set) generation = old_tag_set;
all_tagsets[name = new_name] = this_object();
|
c1ac6c | 2001-07-02 | Martin Stjernholm | | }
|
10bd2c | 2001-07-12 | Martin Stjernholm | | else name = 0;
|
c1ac6c | 2001-07-02 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | static mapping(string:Tag) tags = ([]), proc_instrs;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | |
static mapping(string:string) string_entities;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
87fb7e | 2000-03-25 | Martin Stjernholm | | static TagSet top_tag_set;
static int got_local_tags;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
87fb7e | 2000-03-25 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | static array(function(:void)) notify_funcs = ({});
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | static array(function(Context:void)) prepare_funs;
|
660cb5 | 2000-01-12 | Martin Stjernholm | |
|
2aa1dc | 2001-08-11 | Martin Stjernholm | | static multiset(TagSet) dep_tag_sets = set_weak_flag ((<>), 1);
|
c159ec | 2000-02-04 | Martin Stjernholm | | array(function(Context:void)) get_prepare_funs()
|
660cb5 | 2000-01-12 | Martin Stjernholm | | {
if (prepare_funs) return prepare_funs;
array(function(Context:void)) funs = ({});
for (int i = sizeof (imported) - 1; i >= 0; i--)
funs += imported[i]->get_prepare_funs();
if (prepare_context) funs += ({prepare_context});
return funs;
}
|
be7327 | 2001-06-18 | Martin Stjernholm | | final void call_prepare_funs (Context ctx)
{
if (!prepare_funs) prepare_funs = get_prepare_funs();
(prepare_funs -= ({0})) (ctx);
}
static array(function(Context:void)) eval_finish_funs;
array(function(Context:void)) get_eval_finish_funs()
{
if (eval_finish_funs) return eval_finish_funs;
array(function(Context:void)) funs = ({});
for (int i = sizeof (imported) - 1; i >= 0; i--)
funs += imported[i]->get_eval_finish_funs();
if (eval_finish) funs += ({eval_finish});
return funs;
}
void call_eval_finish_funs (Context ctx)
{
if (!eval_finish_funs) eval_finish_funs = get_eval_finish_funs();
(eval_finish_funs -= ({0})) (ctx);
}
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | static mapping(Tag:Tag) overridden_tag_lookup;
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | Tag find_overridden_tag (Tag overrider, string overrider_name)
|
51f88b | 2000-06-23 | Martin Stjernholm | | {
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (tags[overrider_name] == overrider) {
|
51f88b | 2000-06-23 | Martin Stjernholm | | foreach (imported, TagSet tag_set)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (object(Tag) overrider = tag_set->get_tag (overrider_name))
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | return overrider;
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
else {
int found = 0;
foreach (imported, TagSet tag_set)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (object(Tag) subtag = tag_set->get_tag (overrider_name))
|
51f88b | 2000-06-23 | Martin Stjernholm | | if (found) return subtag;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | else if (subtag == overrider)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if ((subtag = tag_set->find_overridden_tag (
overrider, overrider_name)))
|
51f88b | 2000-06-23 | Martin Stjernholm | | return subtag;
else found = 1;
}
return 0;
}
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | Tag find_overridden_proc_instr (Tag overrider, string overrider_name)
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | {
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (proc_instrs && proc_instrs[overrider_name] == overrider) {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | foreach (imported, TagSet tag_set)
|
429307 | 2001-05-08 | Martin Stjernholm | | if (object(Tag) overrider = tag_set->get_tag (overrider_name, 1))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return overrider;
}
else {
int found = 0;
foreach (imported, TagSet tag_set)
|
429307 | 2001-05-08 | Martin Stjernholm | | if (object(Tag) subtag = tag_set->get_tag (overrider_name, 1))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (found) return subtag;
else if (subtag == overrider)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if ((subtag = tag_set->find_overridden_proc_instr (
overrider, overrider_name)))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return subtag;
else found = 1;
}
return 0;
}
static mapping(string:mapping(string:Tag)) plugins, pi_plugins;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
void low_get_plugins (string prefix, mapping(string:Tag) res)
{
for (int i = sizeof (imported) - 1; i >= 0; i--)
imported[i]->low_get_plugins (prefix, res);
foreach (indices (tags), string name)
if (name[..sizeof (prefix) - 1] == prefix) {
Tag tag = tags[name];
if (tag->plugin_name) res[[string] tag->plugin_name] = tag;
}
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | void low_get_pi_plugins (string prefix, mapping(string:Tag) res)
{
for (int i = sizeof (imported) - 1; i >= 0; i--)
imported[i]->low_get_pi_plugins (prefix, res);
if (proc_instrs)
foreach (indices (proc_instrs), string name)
if (name[..sizeof (prefix) - 1] == prefix) {
Tag tag = proc_instrs[name];
if (tag->plugin_name) res[[string] tag->plugin_name] = tag;
}
}
|
936f63 | 2001-07-16 | Martin Stjernholm | | static string hash;
array get_hash_data()
{
return ({
prefix,
prefix_req,
sort (indices (tags)),
proc_instrs && sort (indices (proc_instrs)),
string_entities,
|
2aa1dc | 2001-08-11 | Martin Stjernholm | | }) + imported->get_hash_data() +
({0}) + indices (dep_tag_sets)->get_hash_data();
|
936f63 | 2001-07-16 | Martin Stjernholm | | }
|
2bd21a | 2000-01-05 | Martin Stjernholm | | string _sprintf()
{
|
cf042f | 2001-07-21 | Martin Stjernholm | | return "RXML.TagSet(" + id_number + ")" + OBJ_COUNT;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
ec027c | 2000-03-16 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT_ONLY;
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | TagSet empty_tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | TagSet shared_tag_set (string name, void|array(Tag) tags)
{
|
7e0fda | 2001-07-12 | Martin Stjernholm | | if (TagSet tag_set = all_tagsets[name])
if (objectp (tag_set))
return tag_set;
|
02a656 | 2001-07-09 | Martin Stjernholm | | return TagSet (name, tags);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | class Value
{
|
a21fcb | 2000-02-08 | Martin Nilsson | | mixed rxml_var_eval (Context ctx, string var, string scope_name, void|Type type)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
ec860d | 2001-03-13 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | |
|
fe628d | 2001-03-01 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
a21fcb | 2000-02-08 | Martin Nilsson | | {
mixed val = rxml_const_eval (ctx, var, scope_name, type);
ctx->set_var(var, val, scope_name);
return val;
}
|
9d80e8 | 2000-02-11 | Martin Stjernholm | | mixed rxml_const_eval (Context ctx, string var, string scope_name, void|Type type);
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
string _sprintf() {return "RXML.Value";}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
class Scope
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | mixed `[] (string var, void|Context ctx,
void|string scope_name, void|Type type)
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot query variable" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
mixed `[]= (string var, mixed val, void|Context ctx, void|string scope_name)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot set variable" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
array(string) _indices (void|Context ctx, void|string scope_name)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot list variables" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | void _m_delete (string var, void|Context ctx, void|string scope_name)
{
if (m_delete != local::m_delete)
m_delete (var, ctx, scope_name);
else
parse_error ("Cannot delete variable" + _in_the_scope (scope_name) + ".\n");
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | void m_delete (string var, void|Context ctx, void|string scope_name)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
{_m_delete (var, ctx, scope_name);}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
private string _in_the_scope (string scope_name)
{
if (scope_name)
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name != "_") return " in the scope " + scope_name;
|
01e43b | 2000-01-14 | Martin Stjernholm | | else return " in the current scope";
else return "";
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
string _sprintf() {return "RXML.Scope";}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Context
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
Frame frame;
|
ffa693 | 2000-02-20 | Martin Stjernholm | | int frame_depth;
|
be7327 | 2001-06-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | constant max_frame_depth = 100;
|
be7327 | 2001-06-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | RequestID id;
|
be7327 | 2001-06-18 | Martin Stjernholm | | mapping(mixed:mixed) misc = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int type_check;
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
db0417 | 2000-01-14 | Martin Stjernholm | | int error_count;
|
deecca | 2001-06-28 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | TagSet tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c8021c | 2000-02-15 | Martin Nilsson | | #ifdef OLD_RXML_COMPAT
int compatible_scope = 0;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
#endif
|
968672 | 2001-07-25 | Martin Stjernholm | | void state_update()
{
state_updated++;
}
|
8abef5 | 2001-02-11 | Martin Stjernholm | | array(string|int) parse_user_var (string var, void|string|int scope_name)
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
c8021c | 2000-02-15 | Martin Nilsson | | #ifdef OLD_RXML_COMPAT
|
2cab1b | 2001-03-05 | Martin Nilsson | | if (compatible_scope && !intp(scope_name))
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | return ({scope_name || "form", var});
|
c8021c | 2000-02-15 | Martin Nilsson | | #endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
1766fe | 2001-02-11 | Martin Nilsson | | array(string|int) splitted;
|
0aa54b | 2001-02-11 | Martin Stjernholm | | if(has_value(var, "..")) {
|
6ec8cc | 2001-02-11 | Martin Stjernholm | |
|
0aa54b | 2001-02-11 | Martin Stjernholm | | string coded = replace (var, "\0", "\0\0");
if (coded != var)
splitted = map (replace (coded, "..", "\0p") / ".",
replace, ({"\0p", "\0\0"}), ({".", "\0"}));
else
splitted = map (replace (var, "..", "\0") / ".", replace, "\0", ".");
}
|
1766fe | 2001-02-11 | Martin Nilsson | | else
splitted = var / ".";
|
8abef5 | 2001-02-11 | Martin Stjernholm | | if (stringp (scope_name))
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | splitted = ({scope_name}) + splitted;
|
8abef5 | 2001-02-11 | Martin Stjernholm | | else if (sizeof (splitted) == 1)
splitted = ({scope_name || "_"}) + splitted;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
for (int i = 2; i < sizeof (splitted); i++)
if (sscanf (splitted[i], "%d%*c", int d) == 1) splitted[i] = d;
return splitted;
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | local mixed get_var (string|array(string|int) var, void|string scope_name,
void|Type want_type)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
if (arrayp (var) ? !sizeof (var) : !stringp (var))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid variable specifier.\n");
|
0ddf4e | 2000-09-15 | Martin Nilsson | | #endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | if (!scope_name) scope_name = "_";
if (SCOPE_TYPE vars = scopes[scope_name])
return rxml_index (vars, var, scope_name, this_object(), want_type);
else if (scope_name == "_") parse_error ("No current scope.\n");
else parse_error ("Unknown scope %O.\n", scope_name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
8778dd | 2000-02-05 | Martin Stjernholm | | mixed user_get_var (string var, void|string scope_name, void|Type want_type)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
if(!var || !sizeof(var)) return ([])[0];
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) splitted = parse_user_var (var, scope_name);
return get_var (splitted[1..], splitted[0], want_type);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | local mixed set_var (string|array(string|int) var, mixed val, void|string scope_name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (arrayp (var) ? !sizeof (var) : !stringp (var))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid variable specifier.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
if (!scope_name) scope_name = "_";
if (SCOPE_TYPE vars = scopes[scope_name]) {
string|int index;
if (arrayp (var))
if (sizeof (var) > 1) {
index = var[-1];
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | array(string|int) path = var[..sizeof (var) - 1];
vars = rxml_index (vars, path, scope_name, this_object());
scope_name += "." + (array(string)) path * ".";
if (mapping(string:mixed) var_chg = misc->variable_changes)
|
a835e8 | 2001-07-25 | Martin Stjernholm | | var_chg[encode_value_canonic (({scope_name}) + var)] = val;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | }
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | else {
index = var[0];
if (mapping(string:mixed) var_chg = misc->variable_changes)
var_chg[encode_value_canonic (({scope_name, index}))] = val;
}
else {
index = var;
if (mapping(string:mixed) var_chg = misc->variable_changes)
var_chg[encode_value_canonic (({scope_name, index}))] = val;
}
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
if (objectp (vars) && vars->`[]=)
return ([object(Scope)] vars)->`[]= (index, val, this_object(), scope_name);
else if (mappingp (vars) || multisetp (vars))
return vars[index] = val;
else if (arrayp (vars))
if (intp (index) && index)
if ((index < 0 ? -index : index) > sizeof (vars))
parse_error( "Index %d out of range for array of size %d in %s.\n",
index, sizeof (val), scope_name );
else if (index < 0)
return vars[index] = val;
else
return vars[index - 1] = val;
else
|
a835e8 | 2001-07-25 | Martin Stjernholm | | parse_error( "Cannot index the array in %s with %s.\n",
scope_name, format_short (index) );
|
01e43b | 2000-01-14 | Martin Stjernholm | | else
|
a835e8 | 2001-07-25 | Martin Stjernholm | | parse_error ("%s is %s which cannot be indexed with %s.\n",
scope_name, format_short (vars), format_short (index));
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | }
else if (scope_name == "_") parse_error ("No current scope.\n");
else parse_error ("Unknown scope %O.\n", scope_name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
9390fe | 2000-01-23 | Martin Nilsson | | mixed user_set_var (string var, mixed val, void|string scope_name)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
c8021c | 2000-02-15 | Martin Nilsson | | if(!var || !sizeof(var)) parse_error ("No variable specified.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) splitted = parse_user_var (var, scope_name);
return set_var(splitted[1..], val, splitted[0]);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | local void delete_var (string|array(string|int) var, void|string scope_name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (arrayp (var) ? !sizeof (var) : !stringp (var))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid variable specifier.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
if (!scope_name) scope_name = "_";
if (SCOPE_TYPE vars = scopes[scope_name]) {
if (arrayp (var))
if (sizeof (var) > 1) {
|
a835e8 | 2001-07-25 | Martin Stjernholm | | array(string|int) path = var[..sizeof (var) - 1];
vars = rxml_index (vars, path, scope_name, this_object());
scope_name += "." + (array(string)) path * ".";
if (mapping(string:mixed) var_chg = misc->variable_changes)
var_chg[encode_value_canonic (({scope_name}) + var)] = nil;
var = var[-1];
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | }
|
a835e8 | 2001-07-25 | Martin Stjernholm | | else {
var = var[0];
if (mapping(string:mixed) var_chg = misc->variable_changes)
var_chg[encode_value_canonic (({scope_name, var}))] = nil;
}
else {
if (mapping(string:mixed) var_chg = misc->variable_changes)
var_chg[encode_value_canonic (({scope_name, var}))] = nil;
}
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | if (objectp (vars) && vars->_m_delete)
([object(Scope)] vars)->_m_delete (var, this_object(), scope_name);
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | else if (mappingp (vars))
|
01e43b | 2000-01-14 | Martin Stjernholm | | m_delete ([mapping(string:mixed)] vars, var);
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | else if (multisetp (vars))
vars[var] = 0;
else
|
a835e8 | 2001-07-25 | Martin Stjernholm | | parse_error ("Cannot remove the index %s from the %t in %s.\n",
format_short (var), vars, scope_name);
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | }
else if (scope_name == "_") parse_error ("No current scope.\n");
|
9290ad | 2000-02-20 | Martin Stjernholm | | else parse_error ("Unknown scope %O.\n", scope_name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | void user_delete_var (string var, void|string scope_name)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
291ade | 2000-01-25 | Martin Stjernholm | | if(!var || !sizeof(var)) return;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) splitted = parse_user_var (var, scope_name);
delete_var(splitted[1..], splitted[0]);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | array(string) list_var (void|string scope_name)
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes[scope_name || "_"])
|
01e43b | 2000-01-14 | Martin Stjernholm | | if (objectp (vars))
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return ([object(Scope)] vars)->_indices (this_object(), scope_name || "_");
|
01e43b | 2000-01-14 | Martin Stjernholm | | else
return indices ([mapping(string:mixed)] vars);
|
9290ad | 2000-02-20 | Martin Stjernholm | | else if ((<0, "_">)[scope_name]) parse_error ("No current scope.\n");
else parse_error ("Unknown scope %O.\n", scope_name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
array(string) list_scopes()
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return indices (scopes) - ({"_"});
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
af06d5 | 2000-01-12 | Martin Stjernholm | | int exist_scope (void|string scope_name)
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return !!scopes[scope_name || "_"];
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
void add_scope (string scope_name, SCOPE_TYPE vars)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
if (scopes[scope_name])
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name == "_") {
|
291ade | 2000-01-25 | Martin Stjernholm | | array(SCOPE_TYPE) hid;
for (Frame f = frame; f; f = f->up)
if (array(SCOPE_TYPE) h = hidden[f]) hid = h;
if (hid) hid[0] = vars;
else scopes["_"] = vars;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
else {
Frame outermost;
for (Frame f = frame; f; f = f->up)
if (f->scope_name == scope_name) outermost = f;
|
291ade | 2000-01-25 | Martin Stjernholm | | if (outermost) hidden[outermost][1] = vars;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else scopes[scope_name] = vars;
}
else scopes[scope_name] = vars;
|
a835e8 | 2001-07-25 | Martin Stjernholm | |
if (mapping(string:mixed) var_chg = misc->variable_changes) {
foreach (indices (var_chg), string encoded_var) {
array var = decode_value (encoded_var);
if (var[0] == scope_name) m_delete (var_chg, encoded_var);
}
var_chg[encode_value_canonic (({scope_name}))] =
mappingp (vars) ? vars + ([]) : vars;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
a835e8 | 2001-07-25 | Martin Stjernholm | | void extend_scope (string scope_name, SCOPE_TYPE vars)
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
74fa38 | 2001-07-25 | Martin Stjernholm | |
|
0273b2 | 2000-01-21 | Martin Nilsson | | {
|
291ade | 2000-01-25 | Martin Stjernholm | | if (scopes[scope_name]) {
SCOPE_TYPE oldvars;
if (scope_name == "_") {
array(SCOPE_TYPE) hid;
for (Frame f = frame; f; f = f->up)
if (array(SCOPE_TYPE) h = hidden[f]) hid = h;
if (hid) oldvars = hid[0];
else oldvars = scopes["_"];
}
else {
Frame outermost;
for (Frame f = frame; f; f = f->up)
if (f->scope_name == scope_name) outermost = f;
if (outermost) oldvars = hidden[outermost][1];
else oldvars = scopes[scope_name];
}
#ifdef DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (!oldvars) fatal_error ("I before e except after c.\n");
|
291ade | 2000-01-25 | Martin Stjernholm | | #endif
foreach (indices(vars), string var)
set_var(var, vars[var], scope_name);
|
f6020c | 2000-01-23 | Martin Nilsson | | }
|
a835e8 | 2001-07-25 | Martin Stjernholm | |
else {
scopes[scope_name] = vars;
if (mapping(string:mixed) var_chg = misc->variable_changes) {
foreach (indices (var_chg), string encoded_var) {
array var = decode_value (encoded_var);
if (var[0] == scope_name) m_delete (var_chg, encoded_var);
}
var_chg[encode_value_canonic (({scope_name}))] =
mappingp (vars) ? vars + ([]) : vars;
}
}
|
0273b2 | 2000-01-21 | Martin Nilsson | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | void remove_scope (string scope_name)
{
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (scope_name == "_") fatal_error ("Cannot remove current scope.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
Frame outermost;
for (Frame f = frame; f; f = f->up)
if (f->scope_name == scope_name) outermost = f;
if (outermost) m_delete (hidden, outermost);
else m_delete (scopes, scope_name);
|
a835e8 | 2001-07-25 | Martin Stjernholm | |
if (mapping(string:mixed) var_chg = misc->variable_changes) {
foreach (indices (var_chg), string encoded_var) {
array var = decode_value (encoded_var);
if (var[0] == scope_name) m_delete (var_chg, encoded_var);
}
var_chg[encode_value_canonic (({scope_name}))] = 0;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
string current_scope()
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes["_"]) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | string scope_name = search (scopes, vars);
do
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name != "_") return scope_name;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | while ((scope_name = search (scopes, vars, scope_name)));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
return 0;
}
|
be7327 | 2001-06-18 | Martin Stjernholm | | SCOPE_TYPE get_scope (string scope_name)
{
return scopes[scope_name];
}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | void add_runtime_tag (Tag tag)
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (tag->plugin_name)
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | fatal_error ("Cannot handle plugin tags added at runtime.\n");
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | #endif
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!new_runtime_tags) new_runtime_tags = NewRuntimeTags();
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | new_runtime_tags->add_tag (tag);
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | void remove_runtime_tag (string|Tag tag, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!new_runtime_tags) new_runtime_tags = NewRuntimeTags();
|
87fb7e | 2000-03-25 | Martin Stjernholm | | if (objectp (tag)) tag = tag->name;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | new_runtime_tags->remove_tag (tag);
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
|
18abb3 | 2000-02-15 | Martin Stjernholm | | multiset(Tag) get_runtime_tags()
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | {
|
87fb7e | 2000-03-25 | Martin Stjernholm | | mapping(string:Tag) tags = runtime_tags;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (new_runtime_tags) tags = new_runtime_tags->filter_tags (tags);
|
87fb7e | 2000-03-25 | Martin Stjernholm | | return mkmultiset (values (tags));
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | }
|
bce4d2 | 2001-06-19 | Martin Stjernholm | | int incomplete_eval()
{
return unwind_state && unwind_state->reason == "streaming";
}
|
446bfa | 2001-06-21 | Martin Stjernholm | | void handle_exception (mixed err, PCode|Parser evaluator, void|int compile_error)
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
c757c4 | 2000-01-08 | Martin Stjernholm | | {
|
db0417 | 2000-01-14 | Martin Stjernholm | | error_count++;
|
c065af | 2001-07-11 | Martin Stjernholm | |
if (objectp (err)) {
if (err->is_RXML_break_eval) {
if (err->action == "continue") return;
Context ctx = RXML_CONTEXT;
if (ctx->frame) {
if (stringp (err->target) ? err->target == ctx->frame->scope_name :
err->target == ctx->frame)
err->action = "continue";
|
f5bd9e | 2001-04-25 | Martin Nilsson | | }
|
140f36 | 2000-10-19 | Martin Stjernholm | | else
|
c065af | 2001-07-11 | Martin Stjernholm | | if (err->target) {
ctx->frame = err->cur_frame;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | err = catch (parse_error ("There is no surrounding frame %s.\n",
|
c065af | 2001-07-11 | Martin Stjernholm | | stringp (err->target) ?
sprintf ("with scope %O", err->target) :
sprintf ("%O", err->target)));
ctx->frame = 0;
handle_exception (err, evaluator, compile_error);
}
throw (err);
}
else if (err->is_RXML_Backtrace) {
if (evaluator->report_error && evaluator->recover_errors &&
evaluator->type->free_text) {
string msg;
if (tag_set && id && id->conf) {
msg = err->type == "help" ? err->msg :
(err->type == "run" ?
([function(Backtrace,Type:string)]
tag_set->handle_run_error) :
([function(Backtrace,Type:string)]
tag_set->handle_parse_error)
) ([object(Backtrace)] err, evaluator->type);
if(!msg)
msg = describe_error(err);
}
else
msg = err->msg;
if (evaluator->report_error (msg)) {
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | if (compile_error && evaluator->p_code) {
CompiledError comp_err = CompiledError (err);
evaluator->p_code->add (RXML_CONTEXT, comp_err, comp_err);
}
|
c065af | 2001-07-11 | Martin Stjernholm | | return;
}
|
446bfa | 2001-06-21 | Martin Stjernholm | | }
|
c065af | 2001-07-11 | Martin Stjernholm | | throw (err);
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
c757c4 | 2000-01-08 | Martin Stjernholm | | }
|
c065af | 2001-07-11 | Martin Stjernholm | |
throw_fatal (err);
|
c757c4 | 2000-01-08 | Martin Stjernholm | | }
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | final array(mixed|PCode) eval_and_compile (Type type, string to_parse,
void|int stale_safe)
|
deecca | 2001-06-28 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
be7327 | 2001-06-18 | Martin Stjernholm | | {
mixed res;
PCode p_code;
|
968672 | 2001-07-25 | Martin Stjernholm | | int orig_make_p_code = make_p_code, orig_state_updated = state_updated;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | make_p_code = 1;
Parser parser = type->get_parser (
this_object(), tag_set, 0, stale_safe ? RenewablePCode (0) : PCode (0));
|
02a656 | 2001-07-09 | Martin Stjernholm | | mixed err = catch {
|
be7327 | 2001-06-18 | Martin Stjernholm | | parser->write_end (to_parse);
res = parser->eval();
p_code = parser->p_code;
|
02a656 | 2001-07-09 | Martin Stjernholm | | type->give_back (parser, tag_set);
|
968672 | 2001-07-25 | Martin Stjernholm | | make_p_code = orig_make_p_code, state_updated = orig_state_updated;
|
02a656 | 2001-07-09 | Martin Stjernholm | | return ({res, p_code});
};
type->give_back (parser, tag_set);
|
968672 | 2001-07-25 | Martin Stjernholm | | make_p_code = orig_make_p_code, state_updated = orig_state_updated;
|
02a656 | 2001-07-09 | Martin Stjernholm | | throw (err);
|
be7327 | 2001-06-18 | Martin Stjernholm | | }
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | final Parser new_parser (Type top_level_type, void|int _make_p_code)
|
c6245b | 1999-12-31 | Martin Stjernholm | |
{
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (in_use || frame) fatal_error ("Context already in use.\n");
|
c6245b | 1999-12-31 | Martin Stjernholm | | #endif
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | return top_level_type->get_parser (this_object(), tag_set, 0,
make_p_code = _make_p_code);
|
be7327 | 2001-06-18 | Martin Stjernholm | | }
#ifdef DEBUG
private int eval_finished = 0;
#endif
final void eval_finish()
{
|
f853b8 | 2001-07-19 | Martin Stjernholm | | FRAME_DEPTH_MSG ("%*s%O eval_finish\n", frame_depth, "", this_object());
if (!frame_depth) {
|
be7327 | 2001-06-18 | Martin Stjernholm | | #ifdef DEBUG
|
f853b8 | 2001-07-19 | Martin Stjernholm | | if (eval_finished) fatal_error ("Context already finished.\n");
|
be7327 | 2001-06-18 | Martin Stjernholm | | eval_finished = 1;
#endif
|
f853b8 | 2001-07-19 | Martin Stjernholm | | if (tag_set) tag_set->call_eval_finish_funs (this_object());
|
90918b | 2001-07-11 | Martin Stjernholm | | if (p_code_comp) p_code_comp->compile();
|
be7327 | 2001-06-18 | Martin Stjernholm | | }
|
c6245b | 1999-12-31 | Martin Stjernholm | | }
|
af06d5 | 2000-01-12 | Martin Stjernholm | | mapping(string:SCOPE_TYPE) scopes = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
3e5934 | 2000-01-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | | mapping(Frame:array(SCOPE_TYPE)) hidden = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
void enter_scope (Frame frame)
{
#ifdef DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (!frame->vars) fatal_error ("Frame has no variables.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
b2d01b | 2000-02-15 | Martin Stjernholm | | if (string scope_name = [string] frame->scope_name) {
if (!hidden[frame])
|
291ade | 2000-01-25 | Martin Stjernholm | | hidden[frame] = ({scopes["_"], scopes[scope_name]});
|
b2d01b | 2000-02-15 | Martin Stjernholm | | scopes["_"] = scopes[scope_name] = [SCOPE_TYPE] frame->vars;
}
else {
if (!hidden[frame])
|
291ade | 2000-01-25 | Martin Stjernholm | | hidden[frame] = ({scopes["_"], 0});
|
b2d01b | 2000-02-15 | Martin Stjernholm | | scopes["_"] = [SCOPE_TYPE] frame->vars;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void leave_scope (Frame frame)
{
|
291ade | 2000-01-25 | Martin Stjernholm | | if (array(SCOPE_TYPE) back = hidden[frame]) {
if (SCOPE_TYPE cur = back[0]) scopes["_"] = cur;
else m_delete (scopes, "_");
if (SCOPE_TYPE named = back[1]) {
#ifdef MODULE_DEBUG
if (!stringp (frame->scope_name))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Scope named changed to %O during parsing.\n", frame->scope_name);
|
291ade | 2000-01-25 | Martin Stjernholm | | #endif
scopes[[string] frame->scope_name] = named;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | else m_delete (scopes, [string] frame->scope_name);
m_delete (hidden, frame);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #define ENTER_SCOPE(ctx, frame) \
(frame->vars && frame->vars != ctx->scopes["_"] && ctx->enter_scope (frame))
#define LEAVE_SCOPE(ctx, frame) \
(frame->vars && ctx->leave_scope (frame))
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
87fb7e | 2000-03-25 | Martin Stjernholm | | mapping(string:Tag) runtime_tags = ([]);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | NewRuntimeTags new_runtime_tags;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
fb605b | 2001-07-11 | Martin Stjernholm | | int make_p_code;
|
968672 | 2001-07-25 | Martin Stjernholm | | int state_updated;
|
fb605b | 2001-07-11 | Martin Stjernholm | | PikeCompile p_code_comp;
|
6570bf | 2001-06-29 | Martin Stjernholm | | static void create (void|TagSet _tag_set, void|RequestID _id)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
02a656 | 2001-07-09 | Martin Stjernholm | | tag_set = _tag_set || empty_tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | id = _id;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
__object_marker->create (this_object());
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | UNWIND_STATE unwind_state;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
bce4d2 | 2001-06-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT_ONLY;
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | string _sprintf() {return "RXML.Context" + OBJ_COUNT;}
|
ec027c | 2000-03-16 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
2d2034 | 2000-02-12 | Martin Stjernholm | | #if constant (thread_create)
Thread.Thread in_use;
#else
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int in_use;
#endif
|
2d2034 | 2000-02-12 | Martin Stjernholm | | #endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
ec027c | 2000-03-16 | Martin Stjernholm | | static class NewRuntimeTags
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | static mapping(string:Tag) add_tags;
static mapping(string:int|string) remove_tags;
void add_tag (Tag tag)
{
if (!add_tags) add_tags = ([]);
if (tag->flags & FLAG_PROC_INSTR) {
add_tags["?" + tag->name] = tag;
if (remove_tags) m_delete (remove_tags, "?" + tag->name);
}
else {
add_tags[tag->name] = tag;
if (remove_tags) m_delete (remove_tags, tag->name);
}
}
void remove_tag (string name, int proc_instr)
{
if (!remove_tags) remove_tags = ([]);
if (proc_instr) remove_tags["?" + name] = name;
else remove_tags[name] = 1;
}
array(Tag) added_tags()
{
if (!add_tags) return ({});
if (remove_tags) return values (add_tags - remove_tags);
return values (add_tags);
}
array(string) removed_tags()
{
return remove_tags ? indices (filter (remove_tags, intp)) : ({});
}
array(string) removed_pi_tags()
{
return remove_tags ? values (remove_tags) - ({1}) : ({});
}
mapping(string:Tag) filter_tags (mapping(string:Tag) tags)
{
if (add_tags) tags |= add_tags;
if (remove_tags) tags -= remove_tags;
return tags;
}
|
ec027c | 2000-03-16 | Martin Stjernholm | | }
|
c065af | 2001-07-11 | Martin Stjernholm | | static class BreakEval (Frame|string target)
{
constant is_RXML_BreakEval = 1;
string action = "break";
Frame cur_frame = RXML_CONTEXT->frame;
}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | class Backtrace
{
constant is_generic_error = 1;
constant is_RXML_Backtrace = 1;
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | string type;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | string msg;
Context context;
|
80e42c | 2001-06-26 | Martin Stjernholm | | array(Frame) frames;
|
02a656 | 2001-07-09 | Martin Stjernholm | | array(mapping(string:mixed)) args;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | string current_var;
array backtrace;
|
6570bf | 2001-06-29 | Martin Stjernholm | | static void create (void|string _type, void|string _msg, void|Context _context,
void|array _backtrace)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | {
type = _type;
msg = _msg;
|
80e42c | 2001-06-26 | Martin Stjernholm | | if (context = _context || RXML_CONTEXT) {
frames = allocate (context->frame_depth);
|
02a656 | 2001-07-09 | Martin Stjernholm | | args = allocate (context->frame_depth);
|
80e42c | 2001-06-26 | Martin Stjernholm | | Frame frame = context->frame;
int i = 0;
|
02a656 | 2001-07-09 | Martin Stjernholm | | for (; frame; i++, frame = frame->up) {
|
f9e8b1 | 2001-08-09 | Martin Stjernholm | | if (i >= sizeof (frames)) {
frames += allocate (sizeof (frames) + 1);
args += allocate (sizeof (args) + 1);
}
|
02a656 | 2001-07-09 | Martin Stjernholm | | frames[i] = frame;
args[i] = frame->args;
}
|
80e42c | 2001-06-26 | Martin Stjernholm | | frames = frames[..i - 1];
|
02a656 | 2001-07-09 | Martin Stjernholm | | args = args[..i - 1];
|
80e42c | 2001-06-26 | Martin Stjernholm | | }
|
51f88b | 2000-06-23 | Martin Stjernholm | | if (_backtrace) backtrace = _backtrace;
else {
backtrace = predef::backtrace();
backtrace = backtrace[..sizeof (backtrace) - 2];
}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
string describe_rxml_backtrace (void|int no_msg)
{
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | String.Buffer txt = String.Buffer();
|
893ac1 | 2001-06-21 | Martin Stjernholm | | function(string...:void) add = txt->add;
|
09a16e | 2001-07-10 | Martin Stjernholm | | if (!no_msg) add ("RXML", type ? " " + type : "", " error");
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (context) {
|
893ac1 | 2001-06-21 | Martin Stjernholm | | if (!no_msg) add (": ", msg || "(no error message)\n");
if (current_var) add (" | &", current_var, ";\n");
|
02a656 | 2001-07-09 | Martin Stjernholm | | for (int i = 0; i < sizeof (frames); i++) {
Frame f = frames[i];
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | string name;
if (f->tag) name = f->tag->name;
|
80e42c | 2001-06-26 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | else name = "(unknown)";
if (f->flags & FLAG_PROC_INSTR)
|
893ac1 | 2001-06-21 | Martin Stjernholm | | add (" | <?", name, "?>\n");
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | else {
|
893ac1 | 2001-06-21 | Martin Stjernholm | | add (" | <", name);
|
02a656 | 2001-07-09 | Martin Stjernholm | | mapping(string:mixed) argmap = args[i];
if (mappingp (argmap))
foreach (sort (indices (argmap)), string arg) {
mixed val = argmap[arg];
|
893ac1 | 2001-06-21 | Martin Stjernholm | | add (" ", arg, "=");
|
446bfa | 2001-06-21 | Martin Stjernholm | | if (arrayp (val)) add (map (val, error_print_val) * ",");
else add (error_print_val (val));
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | }
|
446bfa | 2001-06-21 | Martin Stjernholm | | else add (" (no argmap)");
add (">\n");
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
}
else
|
893ac1 | 2001-06-21 | Martin Stjernholm | | if (!no_msg) add (" (no context): ", msg || "(no error message)\n");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | return txt->get();
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
private string error_print_val (mixed val)
{
if (arrayp (val)) return "array";
else if (mappingp (val)) return "mapping";
else if (multisetp (val)) return "multiset";
else return sprintf ("%O", val);
}
string|array `[] (int i)
{
switch (i) {
case 0: return describe_rxml_backtrace();
case 1: return backtrace;
}
}
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | mixed `[]= (int i, mixed val)
{
if (i == 0 && stringp (val)) {
string oldmsg = describe_rxml_backtrace();
if (has_prefix (val, oldmsg))
msg += val[sizeof (oldmsg)..];
else if (has_suffix (val, oldmsg))
msg = val[..sizeof (val) - sizeof (oldmsg) - 1] + msg;
else
msg = val;
return val;
}
error ("Cannot set index %O to %O.\n", i, val);
}
|
1c73f6 | 2000-03-04 | Martin Stjernholm | | string _sprintf() {return "RXML.Backtrace(" + (type || "") + ")";}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
be7327 | 2001-06-18 | Martin Stjernholm | | final void set_context (Context ctx) {SET_RXML_CONTEXT (ctx);}
final Context get_context() {return [object(Context)] RXML_CONTEXT;}
|
2d2034 | 2000-02-12 | Martin Stjernholm | | #if defined (MODULE_DEBUG) && constant (thread_create)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#define ENTER_CONTEXT(ctx) \
|
be7327 | 2001-06-18 | Martin Stjernholm | | Context __old_ctx = RXML_CONTEXT; \
SET_RXML_CONTEXT (ctx); \
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (ctx) { \
|
2d2034 | 2000-02-12 | Martin Stjernholm | | if (ctx->in_use && ctx->in_use != this_thread()) \
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Attempt to use context asynchronously.\n"); \
|
2d2034 | 2000-02-12 | Martin Stjernholm | | ctx->in_use = this_thread(); \
|
446bfa | 2001-06-21 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#define LEAVE_CONTEXT() \
|
be7327 | 2001-06-18 | Martin Stjernholm | | if (Context ctx = RXML_CONTEXT) \
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (__old_ctx != ctx) ctx->in_use = 0; \
|
be7327 | 2001-06-18 | Martin Stjernholm | | SET_RXML_CONTEXT (__old_ctx);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#else
#define ENTER_CONTEXT(ctx) \
|
be7327 | 2001-06-18 | Martin Stjernholm | | Context __old_ctx = RXML_CONTEXT; \
|
446bfa | 2001-06-21 | Martin Stjernholm | | SET_RXML_CONTEXT (ctx);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#define LEAVE_CONTEXT() \
|
be7327 | 2001-06-18 | Martin Stjernholm | | SET_RXML_CONTEXT (__old_ctx);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#endif
|
76cbfb | 2000-02-04 | Martin Stjernholm | |
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_NONE = 0x00000000;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | constant FLAG_DEBUG = 0x40000000;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | constant FLAG_EMPTY_ELEMENT = 0x00000001;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | constant FLAG_PROC_INSTR = 0x00000010;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | constant FLAG_COMPAT_PARSE = 0x00000002;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
constant FLAG_NO_PREFIX = 0x00000004;
|
cece9e | 2000-01-11 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | constant FLAG_SOCKET_TAG = 0x00000008;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_DONT_PREPARSE = 0x00000040;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_POSTPARSE = 0x00000080;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM_RESULT = 0x00000400;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM_CONTENT = 0x00000800;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM = FLAG_STREAM_RESULT | FLAG_STREAM_CONTENT;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_UNPARSED = 0x00001000;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | | constant FLAG_DONT_RECOVER = 0x00002000;
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
constant FLAG_DONT_REPORT_ERRORS = FLAG_DONT_RECOVER;
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
constant FLAG_RAW_ARGS = 0x00004000;
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
9a3806 | 2000-08-04 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | constant FLAG_COMPILE_INPUT = 0x00008000;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | constant FLAG_COMPILE_RESULT = 0x00010000;
|
692369 | 2001-07-16 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | constant FLAG_GET_RAW_CONTENT = 0x00020000;
constant FLAG_GET_EVALED_CONTENT = 0x00040000;
constant FLAG_DONT_CACHE_RESULT = 0x00080000;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Frame
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
69e4a4 | 2001-08-14 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
constant is_RXML_Frame = 1;
|
c1ee00 | 2001-06-29 | Martin Stjernholm | | constant is_RXML_encodable = 1;
|
02a656 | 2001-07-09 | Martin Stjernholm | | constant is_RXML_p_code_frame = 1;
|
cf042f | 2001-07-21 | Martin Stjernholm | | constant is_RXML_p_code_entry = 1;
|
56532d | 1999-12-19 | Martin Stjernholm | | constant thrown_at_unwind = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Frame up;
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Tag tag;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
int flags;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | mapping(string:mixed)|EVAL_ARGS_FUNC args;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Type content_type;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | | mixed content;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Type result_type;
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | mixed result;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f7469d | 2001-07-10 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
893ac1 | 2001-06-21 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
893ac1 | 2001-06-21 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
f7469d | 2001-07-10 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
893ac1 | 2001-06-21 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
f7469d | 2001-07-10 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
f7469d | 2001-07-10 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
f7469d | 2001-07-10 | Martin Stjernholm | |
|
893ac1 | 2001-06-21 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
893ac1 | 2001-06-21 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
947739 | 2000-03-20 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
947739 | 2000-03-20 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | optional mixed save();
|
968672 | 2001-07-25 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
968672 | 2001-07-25 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
optional void restore (mixed saved);
|
deb79a | 2001-06-26 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
fb605b | 2001-07-11 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
fb605b | 2001-07-11 | Martin Stjernholm | |
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
74fa38 | 2001-07-25 | Martin Stjernholm | | final mixed get_var (string|array(string|int) var, void|string scope_name,
void|Type want_type)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | | {
|
be7327 | 2001-06-18 | Martin Stjernholm | | return RXML_CONTEXT->get_var (var, scope_name, want_type);
|
ffa693 | 2000-02-20 | Martin Stjernholm | | }
|
74fa38 | 2001-07-25 | Martin Stjernholm | | final mixed set_var (string|array(string|int) var, mixed val, void|string scope_name)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | | {
|
be7327 | 2001-06-18 | Martin Stjernholm | | return RXML_CONTEXT->set_var (var, val, scope_name);
|
ffa693 | 2000-02-20 | Martin Stjernholm | | }
|
74fa38 | 2001-07-25 | Martin Stjernholm | | final void delete_var (string|array(string|int) var, void|string scope_name)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | | {
|
be7327 | 2001-06-18 | Martin Stjernholm | | RXML_CONTEXT->delete_var (var, scope_name);
|
ffa693 | 2000-02-20 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void run_error (string msg, mixed... args)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | _run_error (msg, @args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void parse_error (string msg, mixed... args)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | | {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | _parse_error (msg, @args);
|
291ade | 2000-01-25 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void tag_debug (string msg, mixed... args)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | {
|
2cab1b | 2001-03-05 | Martin Nilsson | | if (flags & FLAG_DEBUG) report_debug (msg, @args);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
c065af | 2001-07-11 | Martin Stjernholm | | void break_frame (void|Frame|string frame_or_scope)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
c065af | 2001-07-11 | Martin Stjernholm | | throw (BreakEval (frame_or_scope));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void suspend()
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void resume()
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | mapping(string:Tag) get_plugins()
|
cf3c90 | 2000-02-04 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
|
bca67e | 2000-10-18 | Martin Stjernholm | | if (!(tag->flags & FLAG_SOCKET_TAG))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("This tag is not a socket tag.\n");
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | #endif
|
be7327 | 2001-06-18 | Martin Stjernholm | | return RXML_CONTEXT->tag_set->get_plugins (tag->name, tag->flags & FLAG_PROC_INSTR);
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | }
|
938bfd | 2000-11-04 | Martin Stjernholm | | final Tag get_overridden_tag()
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
641d3c | 2000-10-12 | Martin Stjernholm | | {
|
be7327 | 2001-06-18 | Martin Stjernholm | | return RXML_CONTEXT->tag_set->get_overridden_tag (tag);
|
641d3c | 2000-10-12 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | Frame|string propagate_tag (void|mapping(string:string) args, void|string content)
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | {
|
429307 | 2001-05-08 | Martin Stjernholm | | #ifdef MODULE_DEBUG
#define CHECK_RAW_TEXT \
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (zero_type (this_object()->raw_tag_text)) \
|
429307 | 2001-05-08 | Martin Stjernholm | | fatal_error ("The variable raw_tag_text must be defined.\n"); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (!stringp (this_object()->raw_tag_text)) \
|
429307 | 2001-05-08 | Martin Stjernholm | | fatal_error ("raw_tag_text must have a string value.\n");
#else
#define CHECK_RAW_TEXT
#endif
|
641d3c | 2000-10-12 | Martin Stjernholm | | if (object(Tag) overridden = get_overridden_tag()) {
|
51f88b | 2000-06-23 | Martin Stjernholm | | Frame frame;
|
429307 | 2001-05-08 | Martin Stjernholm | | if (flags & FLAG_PROC_INSTR) {
if (!content) {
CHECK_RAW_TEXT;
|
02a656 | 2001-07-09 | Martin Stjernholm | | content = t_xml->parse_tag (this_object()->raw_tag_text)[2];
|
429307 | 2001-05-08 | Martin Stjernholm | | #ifdef DEBUG
if (!stringp (content))
fatal_error ("Failed to parse PI tag content for <?%s?> from %O.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | tag->name, this_object()->raw_tag_text);
|
51f88b | 2000-06-23 | Martin Stjernholm | | #endif
|
429307 | 2001-05-08 | Martin Stjernholm | | }
}
else if (!args || !content && !(flags & FLAG_EMPTY_ELEMENT)) {
CHECK_RAW_TEXT;
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | string ignored;
|
02a656 | 2001-07-09 | Martin Stjernholm | | [ignored, args, content] = t_xml->parse_tag (this_object()->raw_tag_text);
|
4c0ed6 | 2001-01-18 | Martin Stjernholm | | #ifdef DEBUG
|
429307 | 2001-05-08 | Martin Stjernholm | | if (!mappingp (args))
fatal_error ("Failed to parse tag args for <%s> from %O.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | tag->name, this_object()->raw_tag_text);
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | if (!stringp (content) && !(flags & FLAG_EMPTY_ELEMENT))
|
429307 | 2001-05-08 | Martin Stjernholm | | fatal_error ("Failed to parse tag content for <%s> from %O.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | tag->name, this_object()->raw_tag_text);
|
4c0ed6 | 2001-01-18 | Martin Stjernholm | | #endif
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
frame = overridden (args, content || "");
frame->flags |= FLAG_UNPARSED;
return frame;
}
|
429307 | 2001-05-08 | Martin Stjernholm | | else {
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | CHECK_RAW_TEXT;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
if (flags & FLAG_PROC_INSTR) {
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | if (content) {
string name;
|
02a656 | 2001-07-09 | Martin Stjernholm | | [name, args, content] = t_xml->parse_tag (this_object()->raw_tag_text);
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | return result_type->format_tag (name, 0, content, tag->flags);
|
429307 | 2001-05-08 | Martin Stjernholm | | }
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | else
|
02a656 | 2001-07-09 | Martin Stjernholm | | return this_object()->raw_tag_text;
|
429307 | 2001-05-08 | Martin Stjernholm | | }
else {
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | string s;
|
9d2646 | 2001-06-13 | Martin Stjernholm | | if (!args || !content && !(flags & FLAG_EMPTY_ELEMENT)) {
|
51f88b | 2000-06-23 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
9d2646 | 2001-06-13 | Martin Stjernholm | | if (mixed err = catch {
|
51f88b | 2000-06-23 | Martin Stjernholm | | #endif
|
02a656 | 2001-07-09 | Martin Stjernholm | | s = t_xml (PXml)->eval (this_object()->raw_tag_text,
|
be7327 | 2001-06-18 | Martin Stjernholm | | RXML_CONTEXT, empty_tag_set);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
9d2646 | 2001-06-13 | Martin Stjernholm | | }) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | #endif
|
9d2646 | 2001-06-13 | Martin Stjernholm | | if (!args && !content) return s;
}
|
02a656 | 2001-07-09 | Martin Stjernholm | | else s = this_object()->raw_tag_text;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | [string name, mapping(string:string) parsed_args,
|
02a656 | 2001-07-09 | Martin Stjernholm | | string parsed_content] = t_xml->parse_tag (this_object()->raw_tag_text);
|
429307 | 2001-05-08 | Martin Stjernholm | | #ifdef DEBUG
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | if (!mappingp (parsed_args))
fatal_error ("Failed to parse tag args for <%s> from %O.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | tag->name, this_object()->raw_tag_text);
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | if (!stringp (parsed_content))
fatal_error ("Failed to parse tag content for <%s> from %O.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | tag->name, this_object()->raw_tag_text);
|
429307 | 2001-05-08 | Martin Stjernholm | | #endif
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | if (!args) args = parsed_args;
|
9d2646 | 2001-06-13 | Martin Stjernholm | | if (!content && !(flags & FLAG_EMPTY_ELEMENT)) content = parsed_content;
|
9a6493 | 2001-06-12 | Martin Stjernholm | | return result_type->format_tag (name, args, content, tag->flags);
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
|
429307 | 2001-05-08 | Martin Stjernholm | | #undef CHECK_RAW_TEXT
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | }
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
09a16e | 2001-07-10 | Martin Stjernholm | | # define THIS_TAG_TOP_DEBUG(msg, args...) \
(TAG_DEBUG_TEST (flags & FLAG_DEBUG) && \
report_debug ("%O: " + (msg), this_object(), args), 0)
# define THIS_TAG_DEBUG(msg, args...) \
(TAG_DEBUG_TEST (flags & FLAG_DEBUG) && \
report_debug ("%O: " + (msg), this_object(), args), 0)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | # define THIS_TAG_DEBUG_ENTER_SCOPE(ctx, this) \
if (this->vars && ctx->scopes["_"] != this->vars) \
THIS_TAG_DEBUG ("(Re)entering scope %O\n", this->scope_name)
# define THIS_TAG_DEBUG_LEAVE_SCOPE(ctx, this) \
if (this->vars && ctx->scopes["_"] == this->vars) \
THIS_TAG_DEBUG ("Leaving scope %O\n", this->scope_name)
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #else
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | # define THIS_TAG_TOP_DEBUG(msg, args...) 0
# define THIS_TAG_DEBUG(msg, args...) 0
|
d52f8f | 2001-05-19 | Martin Stjernholm | | # define THIS_TAG_DEBUG_ENTER_SCOPE(ctx, this) 0
# define THIS_TAG_DEBUG_LEAVE_SCOPE(ctx, this) 0
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #define SET_SEQUENTIAL(from, to, desc) \
do { \
|
a835e8 | 2001-07-25 | Martin Stjernholm | | THIS_TAG_DEBUG ("Adding %s to " desc "\n", format_short (from)); \
|
893ac1 | 2001-06-21 | Martin Stjernholm | | /* Keep only one ref to to to allow destructive change. */ \
to = to + (to = 0, from); \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | } while (0)
#define SET_NONSEQUENTIAL(from, to, to_type, desc) \
do { \
if (from != nil) { \
if (to != nil) \
parse_error ( \
"Cannot append another value %s to non-sequential " desc \
|
a835e8 | 2001-07-25 | Martin Stjernholm | | " of type %s.\n", format_short (from), to_type->name); \
THIS_TAG_DEBUG ("Setting " desc " to %s\n", format_short (from)); \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | to = from; \
} \
} while (0)
|
893ac1 | 2001-06-21 | Martin Stjernholm | | #define CONVERT_VALUE(from, from_type, to, to_type, desc) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | do { \
if (from_type->name != to_type->name) { \
|
893ac1 | 2001-06-21 | Martin Stjernholm | | THIS_TAG_DEBUG (desc, from_type->name, to_type->name); \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | to = to_type->encode (from, from_type); \
} \
else to = from; \
} while (0)
|
893ac1 | 2001-06-21 | Martin Stjernholm | | #define CONV_RESULT(from, from_type, to, to_type) \
CONVERT_VALUE(from, from_type, to, to_type, \
"Converting result from %s to %s of surrounding content\n")
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | private void _exec_array_fatal (string where, int pos, mixed elem,
string msg, mixed... args)
{
if (sizeof (args)) msg = sprintf (msg, args);
fatal_error ("Position %d in exec array from %s is %s: %s", pos, where, elem, msg);
};
mixed _exec_array (Context ctx, TagSetParser|PCode evaler, array exec, string where)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
02a656 | 2001-07-09 | Martin Stjernholm | | int i = 0;
|
46c68f | 2000-08-12 | Martin Stjernholm | | mixed res = nil;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Parser subparser = 0;
|
02a656 | 2001-07-09 | Martin Stjernholm | | int orig_make_p_code = ctx->make_p_code;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
mixed err = catch {
for (; i < sizeof (exec); i++) {
|
46c68f | 2000-08-12 | Martin Stjernholm | | mixed elem = exec[i], piece = nil;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
switch (sprintf ("%t", elem)) {
case "string":
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (result_type->parser_prog == PNone) {
|
a835e8 | 2001-07-25 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: String %s\n", i, format_short (elem));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | piece = elem;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else {
|
692369 | 2001-07-16 | Martin Stjernholm | | {
PCode p_code = 0;
if ((ctx->make_p_code = flags & FLAG_COMPILE_RESULT)) {
p_code = RenewablePCode (0);
p_code->source = [string] elem;
}
subparser = result_type->get_parser (ctx, ctx->tag_set, evaler, p_code);
if (evaler->recover_errors && !(flags & FLAG_DONT_RECOVER)) {
subparser->recover_errors = 1;
if (p_code) p_code->recover_errors = 1;
}
THIS_TAG_DEBUG ("Exec[%d]: Parsing%s string %s with %O\n", i,
p_code ? " and compiling" : "",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (elem), subparser);
|
02a656 | 2001-07-09 | Martin Stjernholm | | }
|
56532d | 1999-12-19 | Martin Stjernholm | | subparser->finish ([string] elem);
piece = subparser->eval();
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (PCode p_code = subparser->p_code) {
|
fb605b | 2001-07-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | p_code->finish();
exec[i] = p_code;
}
result_type->give_back (subparser, ctx->tag_set);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | subparser = 0;
}
break;
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | case "mapping":
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Response mapping\n", i);
_exec_array_fatal (where, i, elem,
"Response mappings not yet implemented.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | case "multiset":
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (sizeof ([multiset] elem) == 1) {
piece = ((array) elem)[0];
|
a835e8 | 2001-07-25 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Verbatim value %s\n", i, format_short (piece));
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else
_exec_array_fatal (where, i, elem,
"Not exactly one value in multiset.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | default:
|
f7469d | 2001-07-10 | Martin Stjernholm | | if (objectp (elem)) {
|
5a455b | 2000-02-13 | Martin Stjernholm | |
if (([object] elem)->is_RXML_Frame) {
|
692369 | 2001-07-16 | Martin Stjernholm | | if (orig_make_p_code)
ctx->make_p_code = 0;
THIS_TAG_DEBUG ("Exec[%d]: Evaluating frame %O\n", i, elem);
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | piece = ([object(Frame)] elem)->_eval (
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | ctx, evaler, result_type);
|
02a656 | 2001-07-09 | Martin Stjernholm | | ([object(Frame)] elem)->up = 0;
break;
}
else if (([object] elem)->is_RXML_PCode) {
THIS_TAG_DEBUG ("Exec[%d]: Evaluating p-code %O\n", i, elem);
piece = ([object(PCode)] elem)->_eval (ctx);
CONVERT_VALUE (piece, ([object(PCode)] elem)->type,
piece, result_type,
"Converting p-code result from %s "
"to tag result type %s\n");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | break;
|
5a455b | 2000-02-13 | Martin Stjernholm | | }
else if (([object] elem)->is_RXML_Parser) {
|
02a656 | 2001-07-09 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Continuing eval of frame %O\n", i, elem);
|
5a455b | 2000-02-13 | Martin Stjernholm | | ([object(Parser)] elem)->finish();
piece = ([object(Parser)] elem)->eval();
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | break;
|
5a455b | 2000-02-13 | Martin Stjernholm | | }
|
f7469d | 2001-07-10 | Martin Stjernholm | | else if (elem == nil)
break;
}
else if (functionp (elem)) {
THIS_TAG_DEBUG ("Exec[%d]: Calling function %O\n", i, elem);
piece = ([function(RequestID:mixed)] elem) (ctx->id);
break;
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _exec_array_fatal (where, i, elem, "Not a valid type.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (result_type->sequential) SET_SEQUENTIAL (piece, res, "result");
else SET_NONSEQUENTIAL (piece, result, result_type, "result");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
893ac1 | 2001-06-21 | Martin Stjernholm | | if (result_type->sequential) result = result + (result = 0, res);
|
d52f8f | 2001-05-19 | Martin Stjernholm | | else res = result;
|
02a656 | 2001-07-09 | Martin Stjernholm | | ctx->make_p_code = orig_make_p_code;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return res;
};
|
893ac1 | 2001-06-21 | Martin Stjernholm | | if (result_type->sequential) result = result + (result = 0, res);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | ctx->make_p_code = orig_make_p_code;
|
56532d | 1999-12-19 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec: Interrupted at position %d\n", i);
|
d4768a | 2001-05-18 | Martin Stjernholm | | UNWIND_STATE ustate;
|
33712a | 2000-03-13 | Martin Stjernholm | | if ((ustate = ctx->unwind_state) && !zero_type (ustate->stream_piece)) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (result_type->name != evaler->type->name)
res = evaler->type->encode (res, result_type);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (result_type->sequential)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | SET_SEQUENTIAL (ustate->stream_piece, res, "stream piece");
else
SET_NONSEQUENTIAL (ustate->stream_piece, res, result_type, "stream piece");
ustate->stream_piece = res;
|
33712a | 2000-03-13 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | ustate->exec_left = exec[i..];
if (subparser)
|
56532d | 1999-12-19 | Martin Stjernholm | |
([array] ustate->exec_left)[0] = subparser;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | throw (err);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | throw_fatal (err);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
be7327 | 2001-06-18 | Martin Stjernholm | | private void _handle_runtime_tags (Context ctx, TagSetParser|PCode evaler)
|
2bd21a | 2000-01-05 | Martin Stjernholm | | {
|
be7327 | 2001-06-18 | Martin Stjernholm | | if (evaler->is_RXML_Parser) {
array(Tag) arr_add_tags = ctx->new_runtime_tags->added_tags();
array(string) arr_rem_tags = ctx->new_runtime_tags->removed_tags();
array(string) arr_rem_pi_tags = ctx->new_runtime_tags->removed_pi_tags();
for (Parser p = evaler; p; p = p->_parent)
if (p->tag_set_eval && !p->_local_tag_set && p->add_runtime_tag) {
foreach (arr_add_tags, Tag tag) {
THIS_TAG_DEBUG ("Adding runtime tag %O\n", tag);
([object(TagSetParser)] p)->add_runtime_tag (tag);
}
foreach (arr_rem_tags, string tag) {
THIS_TAG_DEBUG ("Removing runtime tag %s\n", tag);
([object(TagSetParser)] p)->remove_runtime_tag (tag);
}
foreach (arr_rem_pi_tags, string tag) {
THIS_TAG_DEBUG ("Removing runtime tag %s\n", tag);
([object(TagSetParser)] p)->remove_runtime_tag (tag, 1);
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
be7327 | 2001-06-18 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | ctx->runtime_tags = ctx->new_runtime_tags->filter_tags (ctx->runtime_tags);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | ctx->new_runtime_tags = 0;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #define LOW_CALL_CALLBACK(res, cb, args...) \
do { \
THIS_TAG_DEBUG ("Calling " #cb "\n"); \
COND_PROF_ENTER(tag,tag->name,"tag"); \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | res = (cb) (args); /* Might unwind. */ \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | COND_PROF_LEAVE(tag,tag->name,"tag"); \
} while (0)
#define EXEC_CALLBACK(ctx, evaler, exec, cb, args...) \
do { \
if (!exec) \
if (arrayp (cb)) { \
THIS_TAG_DEBUG ("Getting exec array from " #cb "\n"); \
exec = [array] cb; \
} \
else { \
LOW_CALL_CALLBACK (exec, cb, args); \
THIS_TAG_DEBUG ((exec ? "Exec array of length " + \
sizeof (exec) : "Zero") + \
" returned from " #cb "\n"); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this_object()); \
ENTER_SCOPE (ctx, this_object()); \
|
be7327 | 2001-06-18 | Martin Stjernholm | | if (ctx->new_runtime_tags) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | _handle_runtime_tags (ctx, evaler); \
} \
} while (0)
#define EXEC_ARRAY(ctx, evaler, exec, cb) \
do { \
if (exec) { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | mixed res = \
_exec_array (ctx, evaler, exec, #cb); /* Might unwind. */ \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (flags & FLAG_STREAM_RESULT) { \
DO_IF_DEBUG ( \
if (ctx->unwind_state) \
fatal_error ("Clobbering unwind_state to do streaming.\n"); \
if (piece != nil) \
fatal_error ("Thanks, we think about how nice it must be " \
"to play the harmonica...\n"); \
); \
CONV_RESULT (res, result_type, res, type); \
|
bce4d2 | 2001-06-19 | Martin Stjernholm | | ctx->unwind_state = (["stream_piece": res, \
"reason": "streaming"]); \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG ("Streaming %s from " #cb "\n", \
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (res)); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | throw (this_object()); \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | } \
exec = 0; \
} \
} while (0)
|
80e42c | 2001-06-26 | Martin Stjernholm | | EVAL_ARGS_FUNC|string _prepare (Context ctx, Type type,
mapping(string:string) raw_args,
PCode p_code)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
{
mixed err = catch {
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | if (ctx->frame_depth >= Context.max_frame_depth)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _run_error ("Too deep recursion -- exceeding %d nested tags.\n",
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | Context.max_frame_depth);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
80e42c | 2001-06-26 | Martin Stjernholm | | EVAL_ARGS_FUNC|string func;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
if (raw_args) {
#ifdef MODULE_DEBUG
if (flags & FLAG_PROC_INSTR)
fatal_error ("Can't pass arguments to a processing instruction tag.\n");
#endif
#ifdef MAGIC_HELP_ARG
if (raw_args->help) {
func = utils->return_help_arg;
args = raw_args;
}
else
#endif
if (sizeof (raw_args)) {
|
a529ca | 2001-07-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
string splice_arg = raw_args["::"];
|
d2aca0 | 2001-06-11 | Martin Stjernholm | | if (splice_arg) m_delete (raw_args, "::");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else splice_arg = 0;
mapping(string:Type) splice_req_types;
mapping(string:Type) atypes = raw_args & tag->req_arg_types;
if (sizeof (atypes) < sizeof (tag->req_arg_types))
if (splice_arg)
splice_req_types = tag->req_arg_types - atypes;
else {
array(string) missing = sort (indices (tag->req_arg_types - atypes));
parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (missing) + " are" :
"argument " + missing[0] + " is") + " missing.\n");
}
atypes += raw_args & tag->opt_arg_types;
|
02a656 | 2001-07-09 | Martin Stjernholm | | String.Buffer fn_text;
function(string...:void) fn_text_add;
|
fb605b | 2001-07-11 | Martin Stjernholm | | PCode sub_p_code = 0;
PikeCompile comp;
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (p_code) {
fn_text_add = (fn_text = String.Buffer())->add;
fn_text_add ("mixed tmp;\n");
|
fb605b | 2001-07-11 | Martin Stjernholm | | sub_p_code = PCode (0);
comp = ctx->p_code_comp;
|
02a656 | 2001-07-09 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
if (splice_arg) {
|
d2aca0 | 2001-06-11 | Martin Stjernholm | |
|
fb605b | 2001-07-11 | Martin Stjernholm | | Parser parser = splice_arg_type->get_parser (ctx, ctx->tag_set, 0,
sub_p_code);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_DEBUG ("Evaluating splice argument %s\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (splice_arg));
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (mixed err = catch {
#endif
|
02a656 | 2001-07-09 | Martin Stjernholm | | parser->finish (splice_arg);
splice_arg = parser->eval();
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when "
"evaluating splice argument.\n");
throw_fatal (err);
}
#endif
|
80e42c | 2001-06-26 | Martin Stjernholm | | if (p_code)
|
02a656 | 2001-07-09 | Martin Stjernholm | | fn_text_add (
|
fb605b | 2001-07-11 | Martin Stjernholm | | "return ", comp->bind (tag->_eval_splice_args), "(ctx,",
comp->bind (xml_tag_parser->parse_tag_args), "((",
sub_p_code->compile_text (comp), ")||\"\"),",
comp->bind (splice_req_types), ")+([\n");
|
02a656 | 2001-07-09 | Martin Stjernholm | | splice_arg_type->give_back (parser, ctx->tag_set);
|
a529ca | 2001-07-11 | Martin Stjernholm | | args = tag->_eval_splice_args (
ctx, xml_tag_parser->parse_tag_args (splice_arg || ""), splice_req_types);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
else {
args = raw_args;
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (p_code) fn_text_add ("return ([\n");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
#ifdef MODULE_DEBUG
if (mixed err = catch {
#endif
|
02a656 | 2001-07-09 | Martin Stjernholm | | TagSet ctx_tag_set = ctx->tag_set;
|
80e42c | 2001-06-26 | Martin Stjernholm | | if (p_code)
foreach (indices (raw_args), string arg) {
Type t = atypes[arg] || tag->def_arg_type;
if (t->parser_prog != PNone) {
|
fb605b | 2001-07-11 | Martin Stjernholm | | Parser parser = t->get_parser (ctx, ctx_tag_set, 0, sub_p_code);
|
80e42c | 2001-06-26 | Martin Stjernholm | | THIS_TAG_DEBUG ("Evaluating and compiling "
"argument value %s with %O\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (raw_args[arg]), parser);
|
80e42c | 2001-06-26 | Martin Stjernholm | | parser->finish (raw_args[arg]);
args[arg] = parser->eval();
THIS_TAG_DEBUG ("Setting argument %s to %s\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (arg), format_short (args[arg]));
|
02a656 | 2001-07-09 | Martin Stjernholm | | fn_text_add (sprintf ("%O: %s,\n", arg,
|
fb605b | 2001-07-11 | Martin Stjernholm | | sub_p_code->compile_text (comp)));
|
02a656 | 2001-07-09 | Martin Stjernholm | | t->give_back (parser, ctx_tag_set);
|
80e42c | 2001-06-26 | Martin Stjernholm | | }
else {
args[arg] = raw_args[arg];
|
fb605b | 2001-07-11 | Martin Stjernholm | | fn_text_add (sprintf ("%O: %s,\n", arg, comp->bind (raw_args[arg])));
|
80e42c | 2001-06-26 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
|
80e42c | 2001-06-26 | Martin Stjernholm | | else
foreach (indices (raw_args), string arg) {
Type t = atypes[arg] || tag->def_arg_type;
if (t->parser_prog != PNone) {
|
02a656 | 2001-07-09 | Martin Stjernholm | | Parser parser = t->get_parser (ctx, ctx_tag_set, 0, 0);
|
80e42c | 2001-06-26 | Martin Stjernholm | | THIS_TAG_DEBUG ("Evaluating argument value %s with %O\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (raw_args[arg]), parser);
|
80e42c | 2001-06-26 | Martin Stjernholm | | parser->finish (raw_args[arg]);
args[arg] = parser->eval();
THIS_TAG_DEBUG ("Setting argument %s to %s\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (arg), format_short (args[arg]));
|
02a656 | 2001-07-09 | Martin Stjernholm | | t->give_back (parser, ctx_tag_set);
|
80e42c | 2001-06-26 | Martin Stjernholm | | }
else
args[arg] = raw_args[arg];
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
#ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
}
#endif
|
80e42c | 2001-06-26 | Martin Stjernholm | | if (p_code) {
|
02a656 | 2001-07-09 | Martin Stjernholm | | fn_text_add ("]);\n");
|
fb605b | 2001-07-11 | Martin Stjernholm | | func = ctx->p_code_comp->add_func (
|
02a656 | 2001-07-09 | Martin Stjernholm | | "mapping(string:mixed)", "object ctx, object evaler", fn_text->get());
|
80e42c | 2001-06-26 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
else {
func = utils->return_empty_mapping;
args = raw_args;
}
}
else
func = utils->return_zero;
if (!result_type) {
#ifdef MODULE_DEBUG
if (!tag) fatal_error ("result_type not set in Frame object %O, "
"and it has no Tag object to use for inferring it.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | this_object());
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #endif
find_result_type: {
foreach (tag->result_types, Type rtype)
if (rtype->subtype_of (type)) {
result_type = rtype;
break find_result_type;
}
foreach (tag->result_types, Type rtype)
if (type->subtype_of (rtype)) {
result_type = type (rtype->parser_prog, @rtype->parser_args);
break find_result_type;
}
parse_error (
"Tag returns %s but %s is expected.\n",
String.implode_nicely ([array(string)] tag->result_types->name, "or"),
type->name);
}
THIS_TAG_DEBUG ("Resolved result_type to %s from surrounding %s\n",
result_type->name, type->name);
}
else THIS_TAG_DEBUG ("Keeping result_type %s\n", result_type->name);
if (!content_type) {
#ifdef MODULE_DEBUG
if (!tag) fatal_error ("content_type not set in Frame object %O, "
"and it has no Tag object to use for inferring it.\n",
|
02a656 | 2001-07-09 | Martin Stjernholm | | this_object());
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #endif
content_type = tag->content_type;
if (content_type == t_same) {
content_type =
result_type (content_type->parser_prog, @content_type->parser_args);
|
a835e8 | 2001-07-25 | Martin Stjernholm | | THIS_TAG_DEBUG ("Resolved t_same to content_type %s\n",
content_type->name);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
|
a835e8 | 2001-07-25 | Martin Stjernholm | | else THIS_TAG_DEBUG ("Setting content_type to %s from tag\n",
content_type->name);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
|
a835e8 | 2001-07-25 | Martin Stjernholm | | else THIS_TAG_DEBUG ("Keeping content_type %s\n", content_type->name);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
return func;
};
throw (err);
}
|
02a656 | 2001-07-09 | Martin Stjernholm | | mixed _eval (Context ctx, TagSetParser|PCode evaler, Type type)
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
80e42c | 2001-06-26 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
b48338 | 2000-06-30 | Martin Stjernholm | | RequestID id = ctx->id;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | #define EVSTAT_NONE 0
#define EVSTAT_BEGIN 1
#define EVSTAT_ENTERED 2
#define EVSTAT_LAST_ITER 3
#define EVSTAT_ITER_DONE 4
int eval_state = EVSTAT_NONE;
EVAL_ARGS_FUNC in_args = 0;
string|PCode in_content = 0;
|
291ade | 2000-01-25 | Martin Stjernholm | | int iter;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
int debug_iter = 1;
#endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | object(Parser)|object(PCode) subevaler;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | mixed piece;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | array exec = 0;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | TagSet orig_tag_set;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | int orig_make_p_code;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | #define PRE_INIT_ERROR(X...) (ctx->frame = this_object(), fatal_error (X))
|
2bd21a | 2000-01-05 | Martin Stjernholm | | #ifdef DEBUG
|
be7327 | 2001-06-18 | Martin Stjernholm | | if (ctx != RXML_CONTEXT)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | PRE_INIT_ERROR ("Context not current.\n");
if (!evaler->tag_set_eval)
PRE_INIT_ERROR ("Calling _eval() with non-tag set parser.\n");
|
deb79a | 2001-06-26 | Martin Stjernholm | | if (up)
|
02a656 | 2001-07-09 | Martin Stjernholm | | PRE_INIT_ERROR ("Up frame already set. Frame reused in different context?\n");
|
f9e8b1 | 2001-08-09 | Martin Stjernholm | | if (id && ctx->misc != ctx->id->misc->defines)
PRE_INIT_ERROR ("ctx->misc != ctx->id->misc->defines\n");
|
2bd21a | 2000-01-05 | Martin Stjernholm | | #endif
#ifdef MODULE_DEBUG
if (ctx->new_runtime_tags)
PRE_INIT_ERROR ("Looks like Context.add_runtime_tag() or "
"Context.remove_runtime_tag() was used outside any parser.\n");
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #undef PRE_INIT_ERROR
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
80e42c | 2001-06-26 | Martin Stjernholm | | up = ctx->frame;
|
02a656 | 2001-07-09 | Martin Stjernholm | | ctx->frame = this_object();
|
446bfa | 2001-06-21 | Martin Stjernholm | | ctx->frame_depth++;
|
f853b8 | 2001-07-19 | Martin Stjernholm | | FRAME_DEPTH_MSG ("%*s%O frame_depth increase line %d\n",
ctx->frame_depth, "", this_object(), __LINE__);
|
446bfa | 2001-06-21 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | process_tag:
|
02a656 | 2001-07-09 | Martin Stjernholm | | while (1) {
if (mixed err = catch {
if (array state = ctx->unwind_state && ctx->unwind_state[this_object()]) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | object ignored;
[ignored, eval_state, in_args, in_content, iter,
|
02a656 | 2001-07-09 | Martin Stjernholm | | subevaler, piece, exec, orig_tag_set,
ctx->new_runtime_tags, orig_make_p_code
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef DEBUG
, debug_iter
#endif
] = state;
|
02a656 | 2001-07-09 | Martin Stjernholm | | m_delete (ctx->unwind_state, this_object());
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!sizeof (ctx->unwind_state)) ctx->unwind_state = 0;
|
fb605b | 2001-07-11 | Martin Stjernholm | | ctx->make_p_code = orig_make_p_code;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Continuing evaluation" +
(piece ? " with stream piece\n" : "\n"));
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else {
if (tag) {
TRACE_ENTER("tag <" + tag->name + ">", tag);
#ifdef MODULE_LEVEL_SECURITY
if (id->conf->check_security (tag, id, id->misc->seclevel)) {
THIS_TAG_TOP_DEBUG ("Access denied - exiting\n");
TRACE_LEAVE("access denied");
|
8d9258 | 2001-07-26 | Martin Stjernholm | | return result = nil;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | orig_make_p_code = ctx->make_p_code;
if (functionp (args)) {
|
80e42c | 2001-06-26 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Evaluating with compiled arguments\n");
|
02a656 | 2001-07-09 | Martin Stjernholm | | args = (in_args = [EVAL_ARGS_FUNC] args) (ctx, evaler);
in_content = content;
|
80e42c | 2001-06-26 | Martin Stjernholm | | content = nil;
}
else if (flags & FLAG_UNPARSED) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef DEBUG
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (!(flags & FLAG_PROC_INSTR) && !mappingp (args))
fatal_error ("args is not a mapping in unparsed frame: %O\n", args);
if (content && !stringp (content))
fatal_error ("content is not a string in unparsed frame: %O.\n", content);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
02a656 | 2001-07-09 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Evaluating%s unparsed\n",
ctx->make_p_code ? " and compiling" : "");
if (PCode p_code = ctx->make_p_code &&
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | (evaler->is_RXML_PCode ? evaler : evaler->p_code)) {
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | if (!ctx->p_code_comp) ctx->p_code_comp = PikeCompile();
|
02a656 | 2001-07-09 | Martin Stjernholm | | in_args = _prepare (ctx, type, args && args + ([]), p_code);
|
968672 | 2001-07-25 | Martin Stjernholm | | ctx->state_updated++;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | else
_prepare (ctx, type, args && args + ([]), 0);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | in_content = content;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | else {
THIS_TAG_TOP_DEBUG ("Evaluating with constant arguments and content\n");
|
80e42c | 2001-06-26 | Martin Stjernholm | | _prepare (ctx, type, 0, 0);
|
d4768a | 2001-05-18 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | result = piece = nil;
|
02a656 | 2001-07-09 | Martin Stjernholm | | eval_state = EVSTAT_BEGIN;
|
87fb7e | 2000-03-25 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (TagSet add_tags = [object(TagSet)] this_object()->additional_tags) {
|
be7327 | 2001-06-18 | Martin Stjernholm | | TagSet tset = ctx->tag_set;
if (!tset->has_effective_tags (add_tags)) {
THIS_TAG_DEBUG ("Installing additional_tags %O\n", add_tags);
orig_tag_set = tset;
|
02a656 | 2001-07-09 | Martin Stjernholm | | TagSet comp_ts;
GET_COMPOSITE_TAG_SET (add_tags, tset, comp_ts);
ctx->tag_set = comp_ts;
|
be7327 | 2001-06-18 | Martin Stjernholm | | }
else
THIS_TAG_DEBUG ("Not installing additional_tags %O "
"since they're already in the tag set\n", add_tags);
}
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (!zero_type (this_object()->parent_frame))
if (up->local_tags && up->local_tags->has_tag (tag)) {
THIS_TAG_DEBUG ("Setting parent_frame to %O from local_tags\n", up);
this_object()->parent_frame = up;
}
else {
int nest = 1;
Frame frame = up;
for (; frame; frame = frame->up)
if (frame->additional_tags && frame->additional_tags->has_tag (tag)) {
if (!--nest) break;
}
else if (frame->tag == tag) nest++;
THIS_TAG_DEBUG ("Setting parent_frame to %O from additional_tags\n", frame);
this_object()->parent_frame = frame;
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef MAGIC_HELP_ARG
if (tag && (args || ([]))->help) {
TRACE_ENTER ("tag <" + tag->name + " help>", tag);
string help = id->conf->find_tag_doc (tag->name, id);
TRACE_LEAVE ("");
THIS_TAG_TOP_DEBUG ("Reporting help - frame done\n");
ctx->handle_exception (
Backtrace ("help", help, ctx), evaler);
|
8d9258 | 2001-07-26 | Martin Stjernholm | | return result = nil;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #endif
|
b48338 | 2000-06-30 | Martin Stjernholm | |
switch (eval_state) {
case EVSTAT_BEGIN:
if (array|function(RequestID:array) do_enter =
|
02a656 | 2001-07-09 | Martin Stjernholm | | [array|function(RequestID:array)] this_object()->do_enter) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | EXEC_CALLBACK (ctx, evaler, exec, do_enter, id);
EXEC_ARRAY (ctx, evaler, exec, do_enter);
}
else {
|
02a656 | 2001-07-09 | Martin Stjernholm | | THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this_object());
ENTER_SCOPE (ctx, this_object());
|
291ade | 2000-01-25 | Martin Stjernholm | | }
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | if (flags & FLAG_UNPARSED) content = nil;
|
b48338 | 2000-06-30 | Martin Stjernholm | | eval_state = EVSTAT_ENTERED;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | case EVSTAT_ENTERED:
case EVSTAT_LAST_ITER:
|
d52f8f | 2001-05-19 | Martin Stjernholm | | int|function(RequestID:int) do_iterate =
|
02a656 | 2001-07-09 | Martin Stjernholm | | [int|function(RequestID:int)] this_object()->do_iterate;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | array|function(RequestID:array) do_process =
|
02a656 | 2001-07-09 | Martin Stjernholm | | [array|function(RequestID:array)] this_object()->do_process;
int finished = 0;
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | do {
if (eval_state != EVSTAT_LAST_ITER) {
if (intp (do_iterate)) {
iter = [int] do_iterate || 1;
eval_state = EVSTAT_LAST_ITER;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
if (iter > 1)
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Getting %d iterations from do_iterate\n", iter);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | else if (iter < 0)
THIS_TAG_DEBUG ("Skipping to finish since do_iterate is negative\n");
#endif
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
else {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | LOW_CALL_CALLBACK (iter, do_iterate, id);
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("%O returned from do_iterate\n", iter);
|
02a656 | 2001-07-09 | Martin Stjernholm | | THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this_object());
ENTER_SCOPE (ctx, this_object());
|
be7327 | 2001-06-18 | Martin Stjernholm | | if (ctx->new_runtime_tags)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | _handle_runtime_tags (ctx, evaler);
|
deecca | 2001-06-28 | Martin Stjernholm | | if (iter <= 0) eval_state = EVSTAT_LAST_ITER;
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | for (; iter > 0; iter-- DO_IF_DEBUG (, debug_iter++)) {
|
80e42c | 2001-06-26 | Martin Stjernholm | | eval_content:
|
02a656 | 2001-07-09 | Martin Stjernholm | | {
finished++;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (subevaler)
finished = 0;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | else if (!in_content || in_content == "") {
if (flags & FLAG_GET_EVALED_CONTENT) {
this_object()->evaled_content = PCode (content_type);
this_object()->evaled_content->finish();
}
|
02a656 | 2001-07-09 | Martin Stjernholm | | break eval_content;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else if (stringp (in_content)) {
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (flags & FLAG_EMPTY_ELEMENT)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | parse_error ("This tag doesn't handle content.\n");
else {
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (finished > 1)
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | ctx->make_p_code = 1;
{
PCode p_code = ctx->make_p_code && PCode (0);
if (flags & FLAG_GET_EVALED_CONTENT) {
PCode evaled_content =
this_object()->evaled_content = PCode (0, 0, ctx);
if (p_code) p_code->p_code = evaled_content;
else p_code = evaled_content;
}
if (this_object()->local_tags) {
subevaler = content_type->get_parser (
ctx, [object(TagSet)] this_object()->local_tags,
evaler, p_code);
subevaler->_local_tag_set = 1;
|
cf042f | 2001-07-21 | Martin Stjernholm | | THIS_TAG_DEBUG ("Iter[%d]: Parsing%s%s content %s "
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | "with %O from local_tags\n", debug_iter,
|
fb605b | 2001-07-11 | Martin Stjernholm | | ctx->make_p_code ? " and compiling" : "",
|
cf042f | 2001-07-21 | Martin Stjernholm | | flags & FLAG_GET_EVALED_CONTENT ?
" and result compiling" : "",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (in_content), subevaler);
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | }
else {
subevaler = content_type->get_parser (
ctx, ctx->tag_set, evaler, p_code);
|
cf042f | 2001-07-21 | Martin Stjernholm | | THIS_TAG_DEBUG ("Iter[%d]: Parsing%s%s content %s "
"with %O%s\n", debug_iter,
ctx->make_p_code ? " and compiling" : "",
flags & FLAG_GET_EVALED_CONTENT ?
" and result compiling" : "",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (in_content), subevaler,
|
cf042f | 2001-07-21 | Martin Stjernholm | | this_object()->additional_tags ?
" from additional_tags" : "");
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | }
if (evaler->recover_errors && !(flags & FLAG_DONT_RECOVER)) {
subevaler->recover_errors = 1;
if (p_code) {
p_code->recover_errors = 1;
if ((p_code = p_code->p_code))
p_code->recover_errors = 1;
}
}
|
446bfa | 2001-06-21 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | subevaler->finish (in_content);
|
0f998b | 2000-08-15 | Martin Stjernholm | | finished = 1;
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
else {
|
fb605b | 2001-07-11 | Martin Stjernholm | | subevaler = in_content;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | if (flags & FLAG_GET_EVALED_CONTENT)
subevaler->p_code = this_object()->evaled_content =
PCode (content_type, subevaler->tag_set, ctx);
|
cf042f | 2001-07-21 | Martin Stjernholm | | THIS_TAG_DEBUG ("Iter[%d]: Evaluating%s with compiled content\n",
debug_iter,
flags & FLAG_GET_EVALED_CONTENT ?
" and result compiling" : "");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | eval_sub:
do {
if (piece != nil && flags & FLAG_STREAM_CONTENT) {
THIS_TAG_DEBUG ("Iter[%d]: Got %s stream piece %s\n",
debug_iter, finished ? "ending" : "a",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | format_short (piece));
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!arrayp (do_process)) {
EXEC_CALLBACK (ctx, evaler, exec, do_process, id, piece);
if (exec) {
mixed res = _exec_array (
ctx, evaler, exec, "do_process");
if (flags & FLAG_STREAM_RESULT) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef DEBUG
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!zero_type (ctx->unwind_state->stream_piece))
fatal_error ("Clobbering unwind_state->stream_piece.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | CONV_RESULT (res, result_type, res, type);
ctx->unwind_state->stream_piece = res;
|
bce4d2 | 2001-06-19 | Martin Stjernholm | | ctx->unwind_state->reason = "streaming";
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_DEBUG ("Iter[%d]: Streaming %s from do_process\n",
|
a835e8 | 2001-07-25 | Martin Stjernholm | | debug_iter, format_short (res));
|
02a656 | 2001-07-09 | Martin Stjernholm | | throw (this_object());
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | exec = 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else if (flags & FLAG_STREAM_RESULT) {
THIS_TAG_DEBUG ("Iter[%d]: do_process finished the stream; "
"ignoring remaining content\n", debug_iter);
ctx->unwind_state = 0;
piece = nil;
break eval_sub;
|
0f998b | 2000-08-15 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | piece = nil;
if (finished) break eval_sub;
}
else {
piece = nil;
if (finished) {
mixed res = subevaler->_eval (ctx);
if (content_type->sequential)
SET_SEQUENTIAL (res, content, "content");
else if (res != nil)
SET_NONSEQUENTIAL (res, content, content_type, "content");
break eval_sub;
}
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | subevaler->finish();
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | finished = 1;
} while (1);
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (PCode p_code = subevaler->p_code) {
|
cf042f | 2001-07-21 | Martin Stjernholm | | p_code->finish();
|
968672 | 2001-07-25 | Martin Stjernholm | | if (stringp (in_content) && ctx->make_p_code) {
in_content = p_code;
ctx->state_updated++;
}
|
cf042f | 2001-07-21 | Martin Stjernholm | | subevaler->p_code = 0;
|
02a656 | 2001-07-09 | Martin Stjernholm | | ctx->make_p_code = orig_make_p_code;
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | subevaler = 0;
}
|
b48338 | 2000-06-30 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (do_process) {
EXEC_CALLBACK (ctx, evaler, exec, do_process, id);
EXEC_ARRAY (ctx, evaler, exec, do_process);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
} while (eval_state != EVSTAT_LAST_ITER);
|
d52f8f | 2001-05-19 | Martin Stjernholm | | eval_state = EVSTAT_ITER_DONE;
|
6dfc81 | 2001-07-20 | Martin Stjernholm | |
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | case EVSTAT_ITER_DONE:
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (array|function(RequestID,void|PCode:array) do_return =
[array|function(RequestID,void|PCode:array)] this_object()->do_return) {
EXEC_CALLBACK (ctx, evaler, exec, do_return, id,
objectp (in_content) && in_content);
|
b48338 | 2000-06-30 | Martin Stjernholm | | if (exec) {
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _exec_array (ctx, evaler, exec, "do_return");
|
e86f2d | 2000-02-15 | Martin Stjernholm | | exec = 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
else if (result == nil && !(flags & FLAG_EMPTY_ELEMENT)) {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (result_type->parser_prog == PNone) {
|
fe628d | 2001-03-01 | Martin Stjernholm | | if (content_type->name != result_type->name) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Assigning content to result after "
|
d52f8f | 2001-05-19 | Martin Stjernholm | | "conversion from %s to %s\n",
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | content_type->name, result_type->name);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | result = result_type->encode (content, content_type);
}
else {
THIS_TAG_DEBUG ("Assigning content to result\n");
|
b48338 | 2000-06-30 | Martin Stjernholm | | result = content;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
else
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (stringp (content)) {
if (!exec) {
THIS_TAG_DEBUG ("Parsing content with exec array "
"for assignment to result\n");
exec = ({content});
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _exec_array (ctx, evaler, exec, "content parse");
|
b48338 | 2000-06-30 | Martin Stjernholm | | exec = 0;
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | mixed conv_result = nil;
if (result != nil)
CONV_RESULT (result, result_type, conv_result, type);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
02a656 | 2001-07-09 | Martin Stjernholm | | else THIS_TAG_DEBUG ("Skipping nil result\n");
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | THIS_TAG_DEBUG_LEAVE_SCOPE (ctx, this_object());
LEAVE_SCOPE (ctx, this_object());
|
f99720 | 2000-01-18 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (ctx->new_runtime_tags)
_handle_runtime_tags (ctx, evaler);
|
ffa693 | 2000-02-20 | Martin Stjernholm | |
|
f853b8 | 2001-07-19 | Martin Stjernholm | | #define CLEANUP do { \
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (in_args) args = in_args; \
if (in_content) content = in_content; \
ctx->make_p_code = orig_make_p_code; \
if (orig_tag_set) ctx->tag_set = orig_tag_set; \
|
cf042f | 2001-07-21 | Martin Stjernholm | | if (flags & FLAG_DONT_CACHE_RESULT && up) \
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | up->flags |= FLAG_DONT_CACHE_RESULT; \
|
02a656 | 2001-07-09 | Martin Stjernholm | | ctx->frame = up; \
|
f853b8 | 2001-07-19 | Martin Stjernholm | | FRAME_DEPTH_MSG ("%*s%O frame_depth decrease line %d\n", \
ctx->frame_depth, "", this_object(), \
__LINE__); \
|
02a656 | 2001-07-09 | Martin Stjernholm | | ctx->frame_depth--; \
} while (0)
|
f853b8 | 2001-07-19 | Martin Stjernholm | | CLEANUP;
|
02a656 | 2001-07-09 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Done%s\n",
flags & FLAG_DONT_CACHE_RESULT ?
" (don't cache result)" : "");
|
02a656 | 2001-07-09 | Martin Stjernholm | | TRACE_LEAVE ("");
return conv_result;
}) {
THIS_TAG_DEBUG_LEAVE_SCOPE (ctx, this_object());
LEAVE_SCOPE (ctx, this_object());
unwind:
if (objectp (err) && ([object] err)->thrown_at_unwind)
#ifdef MODULE_DEBUG
if (eval_state == EVSTAT_NONE)
fatal_error ("Can't save parser state when evaluating arguments.\n");
else
#endif
{
string action;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | UNWIND_STATE ustate = ctx->unwind_state;
if (!ustate) ustate = ctx->unwind_state = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef DEBUG
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (ustate[this_object()])
fatal_error ("Frame already has an unwind state.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (ustate->exec_left) {
exec = [array] ustate->exec_left;
m_delete (ustate, "exec_left");
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (err == this_object() || exec && sizeof (exec) && err == exec[0])
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
if (evaler->read && evaler->unwind_safe) {
mixed piece = evaler->read();
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (err = catch {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (type->sequential)
SET_SEQUENTIAL (ustate->stream_piece, piece, "stream piece");
else
SET_NONSEQUENTIAL (ustate->stream_piece, piece, type, "stream piece");
}) break unwind;
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (err == this_object()) err = 0;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (orig_tag_set) ctx->tag_set = orig_tag_set, orig_tag_set = 0;
action = "break";
THIS_TAG_TOP_DEBUG ("Breaking to parent frame to do streaming\n");
}
else {
m_delete (ustate, "stream_piece");
action = "continue";
THIS_TAG_TOP_DEBUG ("Not streaming since the parser "
"doesn't allow that\n");
}
else if (!zero_type (ustate->stream_piece)) {
piece = ustate->stream_piece;
|
b48338 | 2000-06-30 | Martin Stjernholm | | m_delete (ustate, "stream_piece");
action = "continue";
|
e9ff83 | 2001-06-27 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Continuing with stream piece.\n");
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | | else {
action = "break";
THIS_TAG_TOP_DEBUG ("Interrupted\n");
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | ustate[this_object()] = ({err, eval_state, in_args, in_content, iter,
subevaler, piece, exec, orig_tag_set,
ctx->new_runtime_tags, orig_make_p_code,
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
02a656 | 2001-07-09 | Martin Stjernholm | | debug_iter,
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
02a656 | 2001-07-09 | Martin Stjernholm | | });
|
d52f8f | 2001-05-19 | Martin Stjernholm | | TRACE_LEAVE (action);
|
02a656 | 2001-07-09 | Martin Stjernholm | | switch (action) {
case "break":
|
56532d | 1999-12-19 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
02a656 | 2001-07-09 | Martin Stjernholm | | if (!evaler->unwind_state)
fatal_error ("Trying to unwind inside an evaluator "
"that isn't unwind safe.\n");
|
56532d | 1999-12-19 | Martin Stjernholm | | #endif
|
02a656 | 2001-07-09 | Martin Stjernholm | | throw (this_object());
case "continue":
continue process_tag;
}
fatal_error ("Should not get here.\n");
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
6dfc81 | 2001-07-20 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Exception%s\n",
flags & FLAG_DONT_CACHE_RESULT ?
" (don't cache result)" : "");
|
02a656 | 2001-07-09 | Martin Stjernholm | | TRACE_LEAVE ("exception");
|
f853b8 | 2001-07-19 | Martin Stjernholm | | err = catch {
ctx->handle_exception (err, evaler);
};
CLEANUP;
if (err) throw (err);
|
02a656 | 2001-07-09 | Martin Stjernholm | | return result = nil;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | fatal_error ("Should not get here.\n");
}
fatal_error ("Should not get here.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
02a656 | 2001-07-09 | Martin Stjernholm | | array _save()
{
|
968672 | 2001-07-25 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Saving persistent state\n");
|
02a656 | 2001-07-09 | Martin Stjernholm | | return ({args, content, flags, content_type, result_type,
this_object()->raw_tag_text,
this_object()->save && this_object()->save()});
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | void _restore (array saved)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
02a656 | 2001-07-09 | Martin Stjernholm | | [args, content, flags, content_type, result_type,
string raw_tag_text, mixed user_saved] = saved;
if (raw_tag_text) this_object()->raw_tag_text = raw_tag_text;
if (user_saved) restore (user_saved);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
fc7549 | 2001-06-22 | Marcus Comstedt | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | Frame _clone_empty()
|
fc7549 | 2001-06-22 | Marcus Comstedt | | {
|
02a656 | 2001-07-09 | Martin Stjernholm | | Frame new = object_program (this_object())();
new->flags = flags;
new->tag = tag;
return new;
|
fc7549 | 2001-06-22 | Marcus Comstedt | | }
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
02a656 | 2001-07-09 | Martin Stjernholm | | MARK_OBJECT;
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
02a656 | 2001-07-09 | Martin Stjernholm | |
string _sprintf()
|
fc7549 | 2001-06-22 | Marcus Comstedt | | {
|
02a656 | 2001-07-09 | Martin Stjernholm | | return "RXML.Frame(" + (tag && [string] tag->name) + ")" + OBJ_COUNT;
|
fc7549 | 2001-06-22 | Marcus Comstedt | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
5c7a6b | 2001-06-25 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
f134b9 | 2000-11-27 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
74fa38 | 2001-07-25 | Martin Stjernholm | | final mixed get_var (string|array(string|int) var, void|string scope_name,
void|Type want_type)
|
be7327 | 2001-06-18 | Martin Stjernholm | | {return RXML_CONTEXT->get_var (var, scope_name, want_type);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final mixed user_get_var (string var, void|string scope_name, void|Type want_type)
|
be7327 | 2001-06-18 | Martin Stjernholm | | {return RXML_CONTEXT->user_get_var (var, scope_name, want_type);}
|
74fa38 | 2001-07-25 | Martin Stjernholm | | final mixed set_var (string|array(string|int) var, mixed val, void|string scope_name)
|
be7327 | 2001-06-18 | Martin Stjernholm | | {return RXML_CONTEXT->set_var (var, val, scope_name);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final mixed user_set_var (string var, mixed val, void|string scope_name)
|
be7327 | 2001-06-18 | Martin Stjernholm | | {return RXML_CONTEXT->user_set_var (var, val, scope_name);}
|
74fa38 | 2001-07-25 | Martin Stjernholm | | final void delete_var (string|array(string|int) var, void|string scope_name)
|
be7327 | 2001-06-18 | Martin Stjernholm | | {RXML_CONTEXT->delete_var (var, scope_name);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void user_delete_var (string var, void|string scope_name)
|
be7327 | 2001-06-18 | Martin Stjernholm | | {RXML_CONTEXT->user_delete_var (var, scope_name);}
|
5ad529 | 2000-03-09 | Martin Stjernholm | |
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void run_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (sizeof (args)) msg = sprintf (msg, @args);
|
51f88b | 2000-06-23 | Martin Stjernholm | | array bt = backtrace();
|
be7327 | 2001-06-18 | Martin Stjernholm | | throw (Backtrace ("run", msg, RXML_CONTEXT, bt[..sizeof (bt) - 2]));
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void parse_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (sizeof (args)) msg = sprintf (msg, @args);
|
51f88b | 2000-06-23 | Martin Stjernholm | | array bt = backtrace();
|
be7327 | 2001-06-18 | Martin Stjernholm | | throw (Backtrace ("parse", msg, RXML_CONTEXT, bt[..sizeof (bt) - 2]));
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void fatal_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (sizeof (args)) msg = sprintf (msg, @args);
array bt = backtrace();
throw_fatal (({msg, bt[..sizeof (bt) - 2]}));
}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void throw_fatal (mixed err)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
{
if (arrayp (err) && sizeof (err) == 2 ||
objectp (err) && !err->is_RXML_Backtrace && err->is_generic_error) {
string msg;
if (catch (msg = err[0])) throw (err);
if (stringp (msg) && !has_value (msg, "\nRXML frame backtrace:\n")) {
|
c64acf | 2000-02-17 | Martin Stjernholm | | string descr = Backtrace (0, 0)->describe_rxml_backtrace (1);
|
5ed013 | 2000-02-13 | Martin Stjernholm | | if (sizeof (descr)) {
if (sizeof (msg) && msg[-1] != '\n') msg += "\n";
msg += "RXML frame backtrace:\n" + descr;
catch (err[0] = msg);
}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
}
throw (err);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | final mixed rxml_index (mixed val, string|int|array(string|int) index,
string scope_name, Context ctx, void|Type want_type)
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
112b01 | 2001-08-10 | Martin Nilsson | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
if (arrayp (index) ? !sizeof (index) : !(stringp (index) || intp (index)))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid index specifier.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | int scope_got_type = 0;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) idxpath;
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | if (arrayp (index)) idxpath = index, index = index[0];
else idxpath = ({0});
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | for (int i = 1;; i++) {
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
if( arrayp( val ) )
if (intp (index) && index)
if( (index > sizeof( val ))
|| ((index < 0) && (-index > sizeof( val ) )) )
parse_error( "Index %d out of range for array of size %d in %s.\n",
index, sizeof (val), scope_name );
else if( index < 0 )
val = val[index];
else
val = val[index-1];
else
|
a835e8 | 2001-07-25 | Martin Stjernholm | | parse_error( "Cannot index the array in %s with %s.\n",
scope_name, format_short (index) );
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | else if (val == nil)
|
a835e8 | 2001-07-25 | Martin Stjernholm | | parse_error ("%s produced no value to index with %s.\n",
scope_name, format_short (index));
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | else if( objectp( val ) && val->`[] ) {
|
fe628d | 2001-03-01 | Martin Stjernholm | | #ifdef MODULE_DEBUG
Scope scope = [object(Scope)] val;
#endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | if (zero_type (
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | val = ([object(Scope)] val)->`[](
index, ctx, scope_name,
i == sizeof (idxpath) && (scope_got_type = 1, want_type))))
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | val = nil;
|
fe628d | 2001-03-01 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
2531fa | 2001-03-23 | Martin Stjernholm | | else if (mixed err = scope_got_type && want_type && val != nil &&
|
0c9e5b | 2001-03-13 | Martin Stjernholm | | !(objectp (val) && |