pike.git / lib / modules / Tools.pmod / Standalone.pmod / autodoc_to_html.pike

version» Context lines:

pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:494:    if( min_text == "" )    return type+"(.."+max_text+")";    if( max_text == "" )    return type+"("+min_text+"..)";       int low = (int)min_text;    int high = (int)max_text;       if( low == 0 && high && (high+1)->popcount() == 1 )    { +  if( high == 1 && type == "int" ) +  return "bool";    return type+"("+strlen((high)->digits(2))+"bit)";    }    return type+"("+low+".."+high+")";   }      //! Typically called with a <group/> node or a sub-node that is a container.   string parse_text(Node n, void|String.Buffer ret) {    if(n->get_node_type()==XML_TEXT && n->get_text()) {    if(ret)    ret->add(quote(n->get_text()));
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:1185:    case "source-position":    position->update(c);    continue;       case "method":    if(method++) ret += "<br />\n";   #if 0    if(!c->get_first_element("returntype"))    error( "No returntype element in method element.\n" );   #endif -  switch( string method = c->get_attributes()->name ) +  +  void emit_default_func()    { -  +  ret += "<tt>"; +  cc = c->get_first_element("modifiers"); +  if(cc) ret += map(cc->get_children(), parse_type)*" " + " "; +  ret += parse_type(get_first_element(c->get_first_element("returntype"))); +  ret += " "; +  ret += c->get_attributes()->class_path; +  ret += "<b><font color='#000066'>" + c->get_attributes()->name + "</font>(</b>"; +  ret += parse_not_doc( c->get_first_element("arguments") ); +  ret += "<b>)</b>"; +  ret += "</tt>"; +  }; +  if( class_name == "" ) +  { +  emit_default_func(); +  } +  else switch( string method = c->get_attributes()->name ) +  { +  case "_get_iterator": +  ret += "<tt><font color='#202020'>"+class_name+"</font> <font color='#000066'>a</font>;<br/>\n"; +  /* NOTE: We could get index and value types from the +  iterator type here. Doing so might be somewhat hard, +  however. +  */ +  ret += "foreach( a; index; value ) or<br></tt>"; +  emit_default_func(); +  break; +  +  case "pow": +  ret += "<tt>"+parse_type(get_first_element(c->get_first_element("returntype"))); +  ret += " res = "+method+"(<font color='#000066'>["+class_name+"]a</font>, b) or <br></tt>"; +  emit_default_func(); +  break; +  +  case "sqrt": +  ret += "<tt>"+parse_type(get_first_element(c->get_first_element("returntype"))); +  ret += " res = "+method+"(<font color='#000066'>["+class_name+"]a</font>) or <br></tt>"; +  emit_default_func(); +  break; + /* +  case "_is_type": +  overloads all the TYPEp() functions and cast. +  +  ret += "<tt>bool stringp(["+class_name+"])a</font>) or <br></tt>"; +  emit_default_func(); +  break; + */    case "create":    ret += "<tt>" +class_name; // Check for more children    ret += " ";    ret += class_name+"<b>(</b>";    ret += parse_not_doc( c->get_first_element("arguments") );    ret += "<b>)</b></tt>";    break;       case "__hash": -  method = method[1..]; +  method = "_hash_value"; +     case "_random": -  +  case "_sqrt":    case "_sizeof":    case "_indices":    case "_values":    /* simple overload type lfuns. */    ret += "<tt>";    ret += parse_type(get_first_element(c->get_first_element("returntype")));    ret += " ";    ret += "<b><font color='#000066'>"+method[1..]+"</font>(</b> ";    ret += "<font color='#202020'>"+class_name+"</font> <font color='#f000f0'>arg</font>";    ret += " <b>)</b>";
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:1231:    case "_sprintf":    ret += "<tt>";    ret += "<font color='#202020'>string</font> ";    ret += ("<b><font color='#000066'>sprintf</font>("    "</b><font color='#202020'>string</font> "    "<font color='#F000F0'>format</font>, ... <font color='#202020'>"    +class_name+"</font> <font color='#F000F0'>"    "arg</font> ... <b>)</b>");    break;    +  case "_decode": +  ret += "<tt>"; +  ret += "<font color='#202020'>"+class_name+"</font> "; +  ret += ("<b><font color='#000066'>decode_value</font>(" +  "</b><font color='#202020'>string(8bit)</font> " +  "<font color='#F000F0'>data</font>)</b>"); +  break; +  case "_encode": +  ret += "<tt>"; +  ret += "<font color='#202020'>string(8bit)</font> "; +  ret += ("<b><font color='#000066'>encode_value</font>(" +  "</b><font color='#202020'>"+class_name+"</font> " +  "<font color='#F000F0'>data</font>)</b>"); +  break; +  +  case "cast": +  { +  ret += "<tt>"; +  +  string base = +  "<b>(</b>_@_TYPE_@_<b>)</b><font color='#202020'>"+class_name+"</font>()"; +  +  multiset seen = (<>); +  void add_typed( string type ) +  { +  if( type == "mixed" ) +  { +  add_typed("int"); ret +="<br>"; +  add_typed("float"); ret +="<br>"; +  add_typed("string"); ret +="<br>"; +  add_typed("array"); ret +="<br>"; +  add_typed("mapping"); ret +="<br>"; +  add_typed("multiset"); +  return; +  } +  if( !seen[type]++ ) +  ret += replace(base,"_@_TYPE_@_", type); +  }; +  +  void output_from_type(Node x, bool toplevel ) +  { +  if( x->get_node_type() != XML_ELEMENT ) return; +  switch( x->get_any_name() ) +  { +  case "object": /*add_typed("object"); */break; /* this is a no-op.. */ +  case "int": +  case "float": +  case "array": +  case "mapping": +  case "string": +  case "function": +  add_typed(parse_type(x)); +  if( !toplevel ) +  ret += "<br>"; +  break; +  case "mixed": +  add_typed("mixed"); +  if( !toplevel ) +  ret += "<br>"; +  break; +  case "or": +  if( toplevel ) +  map( x->get_children(), output_from_type, false ); +  } +  }; +  output_from_type(get_first_element(c->get_first_element("returntype")), +  true); +  if( !sizeof(seen) ) +  add_typed("mixed"); +  }; +  break; +     default: -  +  if( string pat = Tools.AutoDoc.PikeObjects.lfuns[method] ) +  { +  Node a = c->get_first_element("arguments") ; +  array(Node) args = a->get_elements("argument"); +  mapping repl = (["OBJ":"<font color='#000066'>"+class_name+"()</font>"]); +  /* there are a few cases: obj OP arg - we do not want types +  RET func(op,ARG) - we do want types. +  +  This code should only be triggered for the first case. +  Hence, no types wanted. +  */ +  if( sizeof(args) > 0 ) +  { +  repl->x = "<font color='#005080'>"+args[0]->get_attributes()->name+"</font>"; +  } +  if( sizeof(args) > 1 ) +  { +  repl->y = "<font color='#005080'>"+args[1]->get_attributes()->name+"</font>"; +  } +     ret += "<tt>"; -  cc = c->get_first_element("modifiers"); -  if(cc) ret += map(cc->get_children(), parse_type)*" " + " "; +  if( method != "`+=" && method != "`[]=" && method != "`->=") +  {    ret += parse_type(get_first_element(c->get_first_element("returntype"))); -  ret += " "; -  ret += c->get_attributes()->class_path; -  ret += "<b><font color='#000066'>" + c->get_attributes()->name + "</font>(</b>"; -  ret += parse_not_doc( c->get_first_element("arguments") ); -  ret += "<b>)</b></tt>"; +  ret += " res = "; +  } +  ret += replace( pat, repl ); +  ret += "</tt>";    break;    } -  +  emit_default_func( );    break; -  +  } +  break;       case "argument":    if(argument++) ret += ", ";    cc = c->get_first_element("value");    if(cc) ret += "<font color='green'>" + cc->value_of_node() + "</font>";    else if( !c->count_children() );    else if( get_first_element(c)->get_any_name()=="type") {    ret += parse_type(get_first_element(get_first_element(c)));    if(c->get_attributes()->name)    ret += " <font color='#005080'>" +