Branch: Tag:

2001-07-09

2001-07-09 04:08:09 by Martin Stjernholm <mast@lysator.liu.se>

Use p-code in defined tags. Share the sub-tag sets between module
instances. Note that it assumes that the tags in those tag sets
doesn't use any module variables or call any functions in the module
instance. Fixed a frame reuse bug in the <default> tag in the <cond>
tag.

Rev: server/modules/tags/rxmltags.pike:1.252

7:   #define _rettext RXML_CONTEXT->misc[" _rettext"]   #define _ok RXML_CONTEXT->misc[" _ok"]    - constant cvs_version = "$Id: rxmltags.pike,v 1.251 2001/07/08 19:49:58 nilsson Exp $"; + constant cvs_version = "$Id: rxmltags.pike,v 1.252 2001/07/09 04:08:09 mast Exp $";   constant thread_safe = 1;   constant language = roxen->language;   
1384:    }       RXML.TagSet internal = -  RXML.TagSet(module_identifier() + "/maketag", ({ TagAttrib() }) ); +  RXML.shared_tag_set ("/rxmltags/maketag", ({ TagAttrib() }) );       class Frame {    inherit RXML.Frame;
2061:    {    inherit RXML.Frame;    constant is_user_tag_contents = 1; +  RXML.Frame frame; +     array do_return()    { -  +  RXML.Frame upframe; +  if (frame) upframe = frame->up; +  else {    int nest = 1; -  RXML.Frame frame = up; -  for (; frame; frame = frame->up) -  if (frame->is_user_tag) { +  upframe = up; +  for (; upframe; frame = upframe, upframe = upframe->up) +  if (upframe->is_user_tag) {    if (!--nest) break;    } -  else if (frame->is_user_tag_contents) nest++; -  if (!frame) +  else if (upframe->is_user_tag_contents) nest++; +  } +  if (!upframe)    parse_error ("No associated defined tag to get contents from.\n"); -  return ({frame->user_tag_contents || ""}); +  +  if (upframe->compile) flags |= RXML.FLAG_COMPILE_RESULT; +  return upframe->user_tag_contents;    }    }   }      private RXML.TagSet user_tag_contents_tag_set = -  RXML.TagSet (module_identifier() + "/user_tag", ({UserTagContents()})); +  RXML.shared_tag_set ("/rxmltags/user_tag", ({UserTagContents()}));      class UserTag {    inherit RXML.Tag;    string name, lookup_name; -  int flags = 0; +  int flags = RXML.FLAG_COMPILE_RESULT;    RXML.Type content_type = RXML.t_xml;    array(RXML.Type) result_types = ({ RXML.t_any(RXML.PXml) });   
2095:    // changes in loops etc.       void create(string _name, int tag) { +  if (_name) {    name=_name;    lookup_name = "tag\0" + name;    if(tag) flags |= RXML.FLAG_EMPTY_ELEMENT;    } -  +  }       mixed _encode()    { -  return ({ name, lookup_name, flags }); +  return ({ name, flags });    }       void _decode(mixed v)    { -  [name, lookup_name, flags] = v; +  [name, flags] = v; +  lookup_name = "tag\0" + name;    }       class Frame {    inherit RXML.Frame;    RXML.TagSet additional_tags = user_tag_contents_tag_set;    mapping vars; -  string content; -  string def; -  mapping defaults; -  string def_scope_name, scope_name; +  string content_text; +  string raw_tag_text; +  array tagdef; +  string scope_name;    constant is_user_tag = 1; -  string user_tag_contents; +  array(string|RXML.PCode) user_tag_contents; +  int do_iterate; +  int compile;       array do_enter (RequestID id)    { -  if (array tagdef = RXML_CONTEXT->misc[lookup_name]) -  [def, defaults, def_scope_name, UserTag ignored] = tagdef; -  else -  def = 0; +  if ((tagdef = RXML_CONTEXT->misc[lookup_name]) && tagdef[0]) { +  do_iterate = content_text ? -1 : 1;    return 0;    } -  +  do_iterate = -1; +  return ({propagate_tag()}); +  }       array do_return(RequestID id) { -  if (!def) return ({propagate_tag()}); -  -  mapping nargs = defaults+args; -  id->misc->last_tag_args = nargs; +  [array(string|RXML.PCode) def, mapping defaults, +  string def_scope_name, UserTag ignored] = tagdef; +  id->misc->last_tag_args = vars = defaults+args;    scope_name = def_scope_name || name; -  vars = nargs; +     -  +  if (content_text) +  // A previously evaluated tag was restored. +  content = content_text; +  else {    if(content && args->trimwhites)    content = String.trim_all_whites(content);    -  +  if (stringp (def[0])) {   #if ROXEN_COMPAT <= 1.3    if(id->conf->old_rxml_compat) {    array replace_from, replace_to;    if (flags & RXML.FLAG_EMPTY_ELEMENT) { -  replace_from = map(indices(nargs),Roxen.make_entity)+({"#args#"}); -  replace_to = values(nargs)+({ Roxen.make_tag_attributes(nargs)[1..] }); +  replace_from = map(indices(vars),Roxen.make_entity)+ +  ({"#args#"}); +  replace_to = values(vars)+ +  ({ Roxen.make_tag_attributes(vars)[1..] });    }    else { -  replace_from = map(indices(nargs),Roxen.make_entity)+({"#args#", "<contents>"}); -  replace_to = values(nargs)+({ Roxen.make_tag_attributes(nargs)[1..], content }); +  replace_from = map(indices(vars),Roxen.make_entity)+ +  ({"#args#", "<contents>"}); +  replace_to = values(vars)+ +  ({ Roxen.make_tag_attributes(vars)[1..], content });    }    string c2; -  c2 = replace(def, replace_from, replace_to); -  if(c2!=def) { +  c2 = replace(def[0], replace_from, replace_to); +  if(c2!=def[0]) {    vars=([]);    return ({c2});    }    }   #endif -  +  } +  content_text = content; +  user_tag_contents = ({content || ""}); +  compile = RXML_CONTEXT->make_p_code; +  }    -  vars->args = Roxen.make_tag_attributes(nargs)[1..]; +  vars->args = Roxen.make_tag_attributes(vars)[1..];    vars["rest-args"] = Roxen.make_tag_attributes(args - defaults)[1..]; -  user_tag_contents = vars->contents = content; -  return ({ def }); +  vars->contents = content_text; +  return def;    } -  +  +  array save() {return ({content_text, user_tag_contents});} +  void restore (array saved) {[content_text, user_tag_contents] = saved;}    }   }   
2178:       class Frame {    inherit RXML.Frame; +  array(string|RXML.PCode) def; +  mapping defaults; +  int do_iterate;       array do_enter(RequestID id) { -  +  if (def) +  // A previously evaluated tag was restored. +  do_iterate = -1; +  else { +  do_iterate = 1;    if(args->preparse)    m_delete(args, "preparse");    else    content_type = RXML.t_xml; -  +  }    return 0;    }   
2208:    } else    m_delete(args, "container");    -  mapping defaults=([]); +  if (!def) { +  defaults=([]);      #if ROXEN_COMPAT <= 1.3    if(id->conf->old_rxml_compat)
2262:    }      #if ROXEN_COMPAT <= 1.3 -  if(id->conf->old_rxml_compat) content = replace( content, indices(args), values(args) ); +  if(id->conf->old_rxml_compat) +  content = replace( content, indices(args), values(args) );   #endif -  +  def = ({content}); +  }       UserTag user_tag = UserTag (n, tag); -  ctx->misc["tag\0" + n] = ({content, defaults, args->scope, user_tag}); +  ctx->misc["tag\0" + n] = ({def, defaults, args->scope, user_tag});    ctx->add_runtime_tag(user_tag);    return 0;    }
2284:       parse_error("No tag, variable, if or container specified.\n");    } +  +  array save() {return ({def, defaults});} +  void restore (array saved) {[def, defaults] = saved;}    }   }   
2781:    class Frame    {    inherit RXML.Frame; -  int do_iterate = 1; +  int do_iterate;       array do_enter()    {
2789:    do_iterate = -1;    return 0;    } +  do_iterate = 1;    content_type = up->result_type (RXML.PNone);    return 0;    }
2802:    }       RXML.TagSet cond_tags = -  RXML.TagSet (module_identifier() + "/cond", ({TagCase(), TagDefault()})); +  RXML.shared_tag_set ("/rxmltags/cond", ({TagCase(), TagDefault()}));       class Frame    {
2894:    }       RXML.TagSet internal = -  RXML.TagSet(module_identifier() + "/emit", ({ TagDelimiter() }) ); +  RXML.shared_tag_set ("/rxmltags/emit", ({ TagDelimiter() }) );       // A slightly modified Array.dwim_sort_func    // used as emits sort function.