3709192002-03-20Martin Nilsson #pike __REAL_VERSION__
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! This module contains classes to represent Pike objects such as //! classes, modules, methods, variables ... //! The classes can produce XML representations of themselves.
35eee72001-01-08David Norlin 
7115032002-10-29Martin Nilsson // #pragma strict_types
3f97b32001-04-11David Norlin #include "./debug.h"
35eee72001-01-08David Norlin 
9eaf1d2008-06-28Martin Nilsson protected inherit "module.pmod"; protected inherit Parser.XML.Tree;
3f97b32001-04-11David Norlin 
df19812014-08-12Per Hedbor constant lfuns = ([ "`+": "OBJ + x", "`-": "OBJ - x", "`&": "OBJ & x", "`|": "OBJ | x", "`^": "OBJ ^ x", "`<<":"OBJ << x", "`>>":"OBJ >> x", "`*": "OBJ * x",
e98fc62016-05-30Per Hedbor  "`**": "OBJ ** x",
df19812014-08-12Per Hedbor  "`/": "OBJ / x", "`%": "OBJ % x", "`~": "~OBJ", "`==": "OBJ == x", "`<": "OBJ < x", "`>": "OBJ > x",
e894cb2014-08-25Per Hedbor  "__hash":"hash_value(OBJ)",
df19812014-08-12Per Hedbor  "cast":"(cast)OBJ", "`!": "!OBJ",
e894cb2014-08-25Per Hedbor  "`[]":"OBJ[ x ]", "`->":"OBJ->X",
df19812014-08-12Per Hedbor  "_sizeof":"sizeof(OBJ)", "_indices":"indices(OBJ)", "_values":"values(OBJ)",
e894cb2014-08-25Per Hedbor  "_size_object":"Debug.size_object(OBJ)",
df19812014-08-12Per Hedbor  "`()":"OBJ()", "``+":"x + OBJ", "``-":"x - OBJ", "``&":"x & OBJ", "``|":"x | OBJ", "``^":"x ^ OBJ", "``<<":"x << OBJ", "``>>":"x >> OBJ", "``*":"x * OBJ",
e98fc62016-05-30Per Hedbor  "``**":"x ** OBJ",
df19812014-08-12Per Hedbor  "``/":"x / OBJ", "``%":"x % OBJ",
e894cb2014-08-25Per Hedbor  "`->=":"OBJ->X = y", "`[]=":"OBJ[ x ] = y", "`+=":"OBJ += x", /* not really all that nice looking... */
df19812014-08-12Per Hedbor  "`-=":"NOTIMPL", "`&=":"NOTIMPL", "`|=":"NOTIMPL", "`^=":"NOTIMPL", "`<<=":"NOTIMPL", "`>>=":"NOTIMPL", "`*=":"NOTIMPL", "`/=":"NOTIMPL", "`%=":"NOTIMPL", "`~=":"NOTIMPL", "`<=":"NOTIMPL", "`>=":"NOTIMPL", "`!=":"NOTIMPL",
e894cb2014-08-25Per Hedbor  "_is_type":"is_type(OBJ)",/* requires more work..*/
df19812014-08-12Per Hedbor  "_sprintf":"sprintf(...,OBJ)", "_equal":"equal(OBJ,x)", "_m_delete":"m_delete(OBJ,x)", "_get_iterator":"foreach(OBJ;...)",
e894cb2014-08-25Per Hedbor  "`[..]":"OBJ[start..end]",
df19812014-08-12Per Hedbor  /* NOTE: After this point there are only fake lfuns. */
ef67552014-08-25Per Hedbor  "_search":"search(OBJ,x)",
df19812014-08-12Per Hedbor  "_random":"random(OBJ)",
ef67552014-08-25Per Hedbor  /* "_types",
df19812014-08-12Per Hedbor  "_serialize", "_deserialize", "_size_object", */
e894cb2014-08-25Per Hedbor  // "sqrt":"sqrt(OBJ)", // "pow":"pow(OBJ)",
ef67552014-08-25Per Hedbor  "_decode":"OBJ = decode_value(...)", "_encode":"str = encode_value(OBJ)",
df19812014-08-12Per Hedbor ]);
35eee72001-01-08David Norlin  //======================================================================== // REPRESENTATION OF TYPES //========================================================================
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The base class for representing types.
35eee72001-01-08David Norlin class Type(string name) {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns a string with a Pike-syntax representation of the type.
35eee72001-01-08David Norlin  string print() { return name; }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns a string with an XML representation of the type.
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return xmltag(name);}
35eee72001-01-08David Norlin }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing array types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class ArrayType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The @[Type] of the array elements.
35eee72001-01-08David Norlin  Type valuetype;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("array"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { if (valuetype) return "array(" + valuetype->print() + ")"; else return "array"; }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  if (!valuetype)
14fcb52011-12-04Henrik Grubbström (Grubba)  return ::xml(flags);
35eee72001-01-08David Norlin  return xmltag("array",
c615cd2011-12-18Henrik Grubbström (Grubba)  xmltag("valuetype", valuetype->xml(flags)));
35eee72001-01-08David Norlin  } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing program (aka class) types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class ProgramType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The name of the class (if any).
3818392003-02-05Martin Nilsson  string classname;
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
3818392003-02-05Martin Nilsson  string print() { if(classname) return "program(" + classname + ")"; else return "program"; } // FIXME xml() needs to be overridden.
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("program"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing the float type. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class FloatType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("float"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing integer types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class IntType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The minimum and maximum range limits for the integer type.
35eee72001-01-08David Norlin  string min, max;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("int"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { if (min || max) return "int(" + (min ? min : "") + ".." + (max ? max : "") + ")"; else return "int"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  if (min || max) return xmltag("int", xmltag("min", min) + xmltag("max", max)); return xmltag("int"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing string types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class StringType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The minimum value for characters in the string.
94ddcc2007-06-02Martin Bähr  string min;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The maximum value for characters in the string.
94ddcc2007-06-02Martin Bähr  string max;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("string"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
84108b2007-03-04Martin Nilsson  string print() {
94ddcc2007-06-02Martin Bähr  if (min||max) return "string(" + (min ? min : "") + ".." + (max ? max : "") + ")";
84108b2007-03-04Martin Nilsson  else return "string"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
94ddcc2007-06-02Martin Bähr  if (min||max)
3524712015-05-26Martin Nilsson  return xmltag("string", xmltag("min", min) +
94ddcc2007-06-02Martin Bähr  xmltag("max", max));
84108b2007-03-04Martin Nilsson  return xmltag("string"); }
35eee72001-01-08David Norlin }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing the mixed type. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class MixedType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("mixed"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing function types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class FunctionType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! An array with types for the arguments to the function.
35eee72001-01-08David Norlin  array(Type) argtypes;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The type for the return value of the function.
35eee72001-01-08David Norlin  Type returntype;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("function"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { if (argtypes && returntype) { return "function(" + map(argtypes, lambda(Type t) { return t->print(); }) * ", " + " : " + returntype->print() + ")"; } else return "function"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  string s = ""; if (argtypes) foreach(argtypes, Type t)
14fcb52011-12-04Henrik Grubbström (Grubba)  s += xmltag("argtype", t->xml(flags));
35eee72001-01-08David Norlin  if (returntype)
14fcb52011-12-04Henrik Grubbström (Grubba)  s += xmltag("returntype", returntype->xml(flags));
35eee72001-01-08David Norlin  return xmltag("function", s); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing mapping types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class MappingType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The types for the indices and values of the mapping.
35eee72001-01-08David Norlin  Type indextype, valuetype;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("mapping"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { if (indextype && valuetype) { return "mapping(" + indextype->print() + " : " + valuetype->print() + ")"; } else return "mapping"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  if (indextype && valuetype) return xmltag("mapping",
14fcb52011-12-04Henrik Grubbström (Grubba)  xmltag("indextype", indextype->xml(flags)) + xmltag("valuetype", valuetype->xml(flags)));
35eee72001-01-08David Norlin  else return xmltag("mapping"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing multiset types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class MultisetType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The type for the indices of the multiset.
35eee72001-01-08David Norlin  Type indextype;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("multiset"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { if (indextype) { return "multiset(" + indextype->print() + ")"; } else return "multiset"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  if (indextype) return xmltag("multiset",
14fcb52011-12-04Henrik Grubbström (Grubba)  xmltag("indextype", indextype->xml(flags)));
35eee72001-01-08David Norlin  return xmltag("multiset"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing object types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class ObjectType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The name of the class for the object.
35eee72001-01-08David Norlin  string classname;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("object"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { if (classname) return "object(" + classname + ")"; else return "object"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  return xmltag("object", classname); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing type types. //! //! @seealso //! @[Type]
05f6432002-12-30Henrik Grubbström (Grubba) class TypeType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
05f6432002-12-30Henrik Grubbström (Grubba)  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The subtype of the type.
05f6432002-12-30Henrik Grubbström (Grubba)  Type subtype = MixedType();
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
05f6432002-12-30Henrik Grubbström (Grubba)  void create() { ::create("type"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
05f6432002-12-30Henrik Grubbström (Grubba)  string print() { if (subtype->name != "mixed") { return "type(" + subtype->print() + ")"; } return "type"; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return xmltag("type", subtype->xml(flags));
05f6432002-12-30Henrik Grubbström (Grubba)  } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing the void type. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class VoidType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("void"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing the zero type. //! //! @seealso //! @[Type]
05f6432002-12-30Henrik Grubbström (Grubba) class ZeroType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
05f6432002-12-30Henrik Grubbström (Grubba)  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
05f6432002-12-30Henrik Grubbström (Grubba)  void create() { ::create("zero"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing union types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class OrType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! An array with the types that are member of the union.
35eee72001-01-08David Norlin  array(Type) types;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create() { ::create("or"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { return map(types, lambda(Type t) { return t->print(); }) * " | "; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
35eee72001-01-08David Norlin  string s = ""; foreach(types, Type t)
14fcb52011-12-04Henrik Grubbström (Grubba)  s += t->xml(flags);
35eee72001-01-08David Norlin  return xmltag("or", s); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing varargs types. //! //! @seealso //! @[Type]
35eee72001-01-08David Norlin class VarargsType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The type that is varargs.
35eee72001-01-08David Norlin  Type type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  void create(Type t) { ::create("varargs"); type = t; }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
35eee72001-01-08David Norlin  string print() { return type->print() + " ..."; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return xmltag("varargs", type->xml(flags)); }
35eee72001-01-08David Norlin }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The class for representing attributed types. //! //! @seealso //! @[Type]
7bf3cc2008-04-07Henrik Grubbström (Grubba) class AttributeType {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
7bf3cc2008-04-07Henrik Grubbström (Grubba)  inherit Type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The name of the attribute.
7bf3cc2008-04-07Henrik Grubbström (Grubba)  string attribute;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The type that is attributed.
7bf3cc2008-04-07Henrik Grubbström (Grubba)  Type subtype;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Flag indicating: //! @int //! @value 0 //! The attribute is on the type. //! @value 1 //! The attribute is a prefix and acts as a modifier. //! This is only used for functions. //! @endint
7bf3cc2008-04-07Henrik Grubbström (Grubba)  int prefix;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
7bf3cc2008-04-07Henrik Grubbström (Grubba)  void create() { ::create("__attribute__"); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
7bf3cc2008-04-07Henrik Grubbström (Grubba)  string print() { if (attribute == "\"deprecated\"") { return prefix?"__deprecated__ " + subtype->print(): "__deprecated__(" + subtype->print() + ")"; } else { return prefix?"__attribute__(" + attribute + ") " + subtype->print(): "__attribute__(" + attribute + ", " + subtype->print() + ")"; } }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
7bf3cc2008-04-07Henrik Grubbström (Grubba)  return xmltag("attribute", (prefix?xmltag("prefix"):"") + xmltag("attribute", attribute) +
14fcb52011-12-04Henrik Grubbström (Grubba)  xmltag("subtype", subtype->xml(flags)));
7bf3cc2008-04-07Henrik Grubbström (Grubba)  } }
35eee72001-01-08David Norlin //======================================================================== // DOCUMENTATION OBJECT //========================================================================
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The base class for documentation strings. //! //! @seealso //! @[DocGroup]
cef0292002-12-06Henrik Grubbström (Grubba) class Documentation(string|void text, string|void xml, SourcePosition|void position) {}
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The empty @[Documentation].
9eaf1d2008-06-28Martin Nilsson protected Documentation EmptyDoc =
cef0292002-12-06Henrik Grubbström (Grubba)  Documentation("", "\n", SourcePosition(__FILE__, __LINE__, __LINE__));
35eee72001-01-08David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! A class associating a piece of @[Documentation] //! with a set of @[PikeObject]s.
35eee72001-01-08David Norlin class DocGroup {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The set of @[PikeObject]s that are documented.
35eee72001-01-08David Norlin  array(PikeObject) objects = ({ });
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The @[Documentation] for the @[objects].
35eee72001-01-08David Norlin  Documentation documentation = 0;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
9eaf1d2008-06-28Martin Nilsson  protected void create(array(PikeObject) objs, Documentation doc) {
35eee72001-01-08David Norlin  documentation = doc; objects = objs; }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Relocation information.
35eee72001-01-08David Norlin  string appears = 0; string belongs = 0;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns a string with an XML representation of the documentation.
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
46b75b2001-01-08Henrik Grubbström (Grubba)  mapping(string:string) m = ([]);
35eee72001-01-08David Norlin  if (appears) m->appears = appears; if (belongs) m->belongs = belongs;
8510d42001-01-25David Norlin  // Check if homogeneous mapping (string:int) types = ([]); mapping (string:int) names = ([]); foreach(objects, PikeObject obj) { types[obj->objtype] = 1; if (obj->name) names[obj->name] = 1; } if (sizeof(types) == 1) { m["homogen-type"] = indices(types)[0]; if (sizeof(names) == 1) m["homogen-name"] = objects[0]->name; }
35eee72001-01-08David Norlin  string res = opentag("docgroup", m); if (documentation)
46c5622001-01-11Henrik Grubbström (Grubba)  res += xmltag("doc", documentation->xml) + "\n";
793b472001-05-15David Norlin  foreach(objects, PikeObject obj)
14fcb52011-12-04Henrik Grubbström (Grubba)  res += obj->xml(flags) + "\n";
46c5622001-01-11Henrik Grubbström (Grubba)  return res + closetag("docgroup") + "\n";
35eee72001-01-08David Norlin  } } //======================================================================== // REPRESENTATION OF PIKES LEXICAL OBJECTS (class, function, variable ...) //========================================================================
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Base class for representing a documentable Pike lexical entity. //! //! This class is inherited by classes for representing //! classes, functions, variables, etc. //! //! @seealso //! @[Inherit], @[Import], @[Class], @[Module], @[NameSpace], @[AutoDoc], //! @[Modifier], @[Method], @[Constant], @[Typedef], @[EnumConstant], //! @[Enum], @[Variable]
35eee72001-01-08David Norlin class PikeObject {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The set of modifiers affecting this entity.
35eee72001-01-08David Norlin  array(string) modifiers = ({ });
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The name of the entity.
246a8a2001-10-03Martin Nilsson  string name;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The object type identifier.
246a8a2001-10-03Martin Nilsson  constant objtype = "pikeobject";
35eee72001-01-08David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The source position where the entity was found.
35eee72001-01-08David Norlin  SourcePosition position;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Relocation information.
246a8a2001-10-03Martin Nilsson  string appears; string belongs;
35eee72001-01-08David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  Documentation squeezedInDoc;
35eee72001-01-08David Norlin 
b987c72016-08-03Henrik Grubbström (Grubba)  int containsDoc() { if (squeezedInDoc && squeezedInDoc != EmptyDoc) return 1; return 0; }
14fcb52011-12-04Henrik Grubbström (Grubba)  protected string standardTags(.Flags|void flags) {
d47c322001-03-06David Norlin  string s = ""; if (position)
14fcb52011-12-04Henrik Grubbström (Grubba)  s += position->xml(flags);
d47c322001-03-06David Norlin  if (sizeof(modifiers)) s += xmltag("modifiers", map(modifiers, xmltag) * ""); return s;
35eee72001-01-08David Norlin  }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns a string with an XML representation of the entity.
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return standardStart(flags) + standardEnd(flags);
35eee72001-01-08David Norlin  }
14fcb52011-12-04Henrik Grubbström (Grubba)  protected mapping(string:string) standardAttributes(.Flags|void flags) {
46b75b2001-01-08Henrik Grubbström (Grubba)  mapping(string:string) m = ([]);
35eee72001-01-08David Norlin  if (name) m->name = name; if (appears) m->appears = appears; if (belongs) m->belongs = belongs; return m; }
14fcb52011-12-04Henrik Grubbström (Grubba)  protected string standardStart(.Flags|void flags) { return opentag(objtype, standardAttributes(flags)); } protected string standardEnd(.Flags|void flags) { return closetag(objtype); }
35eee72001-01-08David Norlin 
9eaf1d2008-06-28Martin Nilsson  protected string printModifiers() {
35eee72001-01-08David Norlin  return modifiers * " " + (sizeof(modifiers) ? " " : ""); }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns a string with a Pike syntax representation of the entity.
35eee72001-01-08David Norlin  string print() { return printModifiers() + objtype; } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Representation of an inherit.
35eee72001-01-08David Norlin class Inherit {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "inherit";
35eee72001-01-08David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Name of the class that is inherited.
35eee72001-01-08David Norlin  string classname;
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return standardStart(flags) + standardTags(flags) +
35eee72001-01-08David Norlin  xmltag("classname", classname) +
14fcb52011-12-04Henrik Grubbström (Grubba)  standardEnd(flags);
35eee72001-01-08David Norlin  } string print() { return ::print() + " " + classname + (name ? "" : " : " + name); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Representation of an import.
dc7a9f2001-04-19David Norlin class Import {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
7dc6982003-11-08Henrik Grubbström (Grubba)  inherit Inherit;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "import";
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
7dc6982003-11-08Henrik Grubbström (Grubba)  string print() { return ::print() + " " + classname; }
dc7a9f2001-04-19David Norlin }
2110692012-02-05Henrik Grubbström (Grubba) //! Representation of an inherit. class CppDirective { //! inherit PikeObject; //! constant objtype = "directive"; protected void create(string directive) { name = directive; } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Base class for representing classes, modules and namespaces. //! //! @seealso //! @[Class], @[Module], @[NameSpace], @[AutoDoc], @[Modifier]
35eee72001-01-08David Norlin class _Class_or_Module {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit PikeObject; string directory = 0; string file = 0;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @note //! The documentation appears as a child of the <class> or <module>
35eee72001-01-08David Norlin  Documentation documentation;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @[Inherit]s and @[Import]s that affect the symbol lookup //! for the entity.
7dc6982003-11-08Henrik Grubbström (Grubba)  array(Inherit|Import) inherits = ({ });
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Entities that are children to this entity.
35eee72001-01-08David Norlin  array(_Class_or_Module) children = ({ });
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Documented entities that are children to this entity.
35eee72001-01-08David Norlin  array(DocGroup) docGroups = ({ });
df19812014-08-12Per Hedbor  void fixGettersSetters() { mapping(string:array(PikeObject)) found = ([]); mapping(string:mapping(string:Documentation)) docs = ([]); foreach( docGroups;int index; DocGroup doge ) { foreach( doge->objects; int subindex; PikeObject o ) {
e8a38c2014-08-16Per Hedbor  if( lfuns[o->name] == "NOTIMPL" && objtype != "namespace")
df19812014-08-12Per Hedbor  { werror("WARNING: Dropping documentation for %s. " "There is no such operator\n" "Found in documentation for %s\n", o->name,o->position?->filename||name); doge->objects[subindex] = 0; } else if( o->name[0..0] == "`" && !lfuns[o->name] ) { string key = o->name[1..]-"="; found[key] += ({ o }); doge->objects[subindex] = 0; if(!docs[key] ) docs[key] = ([]); if( doge->documentation ) if( o->name[-1] == '=' ) docs[key]->set = doge->documentation; else docs[key]->get = doge->documentation; } } doge->objects -= ({0}); if( sizeof( doge->objects ) == 0 ) { docGroups[index]=0; } } docGroups -= ({0}); foreach( found; string key; array(PikeObject) o ) { Variable nvar = Variable(); Documentation outdoc=Documentation(); DocGroup ngroup = DocGroup(({nvar}),outdoc); string extra; docGroups += ({ ngroup }); if( sizeof( o ) == 1 ) { if( o[0]->name[-1] == '=' ) extra = "Write only"; else extra = "Read only"; } nvar->name = key; nvar->type = o[0]->returntype; nvar->position = o[0]->position; outdoc->position = o[0]->position; mapping(string:Documentation) doc = docs[key]; if( doc?->set?->text && doc?->get?->text && strlen(doc->set->text) && strlen(doc->get->text) && doc->set->text != doc->get->text ) {
e8a38c2014-08-16Per Hedbor  outdoc->text = "Getting\n\n"
699eff2014-08-12Per Hedbor  "\n"+doc->get->text+"\n\n"+
e8a38c2014-08-16Per Hedbor  "Setting\n\n"+
699eff2014-08-12Per Hedbor  doc->get->text+"\n\n";
df19812014-08-12Per Hedbor  } else { if( doc?->set?->text && strlen(doc->set->text) ) { outdoc->text = doc->set->text; } else if( doc?->get?->text && strlen(doc->get->text) ) { outdoc->text = doc->get->text; } else outdoc->text=""; } if( extra ) outdoc->text += "\n@note\n"+extra; object p = master()->resolv("Tools.AutoDoc.DocParser.Parse") (outdoc->text, SourcePosition(__FILE__, __LINE__, __LINE__)); p->metadata(); outdoc->xml = p->doc("_method"); } }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns @expr{1@} if there is any documentation //! at all for this entity.
b987c72016-08-03Henrik Grubbström (Grubba)  int containsDoc() { if (documentation && documentation != EmptyDoc) return 1; if (::containsDoc()) return 1; foreach(docGroups, DocGroup dg) { if (dg->documentation && dg->documentation != EmptyDoc) return 1; } foreach(children, _Class_or_Module c) { if (c->containsDoc()) return 1; } return 0; }
35eee72001-01-08David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Adds @[p] to the set of @[inherits].
d31e5b2016-08-04Henrik Grubbström (Grubba)  void addInherit(PikeObject p) {
c82d9c2003-11-07Henrik Grubbström (Grubba)  inherits += ({ p }); }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Adds @[c] to the set of @[children].
d31e5b2016-08-04Henrik Grubbström (Grubba)  void addChild(_Class_or_Module c) { children += ({ c }); }
35eee72001-01-08David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns the first child with the name @[name] if any.
5340fa2001-05-04David Norlin  PikeObject findChild(string name) { int a = Array.search_array(children, lambda(PikeObject o, string n) { return o->name == n; }, name); if (a < 0) return 0; return children[a]; }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @returns //! Returns the first @[DocGroup] that documents an entity //! with the name @[name] if any. DocGroup findObject(string name) {
c475882007-06-11Martin Bähr  int a = Array.search_array(docGroups, lambda(DocGroup d, string n) { return (search(d->objects->name, n) >= 0); }, name); if (a < 0) return 0; return docGroups[a]; }
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Adds @[d] to the set of @[docGroups].
d31e5b2016-08-04Henrik Grubbström (Grubba)  void addGroup(DocGroup d) {
35eee72001-01-08David Norlin  docGroups += ({ d }); }
df19812014-08-12Per Hedbor 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
df19812014-08-12Per Hedbor  fixGettersSetters();
14fcb52011-12-04Henrik Grubbström (Grubba)  string contents = standardTags(flags);
35eee72001-01-08David Norlin  if (documentation && documentation->xml != "") contents += xmltag("doc", documentation->xml);
5f8b732001-08-23Martin Nilsson  children -= ({ 0 }); // FIXME
35eee72001-01-08David Norlin  foreach (children, _Class_or_Module c)
14fcb52011-12-04Henrik Grubbström (Grubba)  contents += c->xml(flags);
cef0292002-12-06Henrik Grubbström (Grubba)  foreach (inherits, Inherit in) { // Wrap the undocumented inherits in docgroups. DocGroup dg = DocGroup(({in}), EmptyDoc);
14fcb52011-12-04Henrik Grubbström (Grubba)  contents += dg->xml(flags);
cef0292002-12-06Henrik Grubbström (Grubba)  }
35eee72001-01-08David Norlin  foreach (docGroups, DocGroup dg)
14fcb52011-12-04Henrik Grubbström (Grubba)  contents += dg->xml(flags); mapping(string:string) m = standardAttributes(flags);
35eee72001-01-08David Norlin  if (file) m["file"] = file; if (directory) m["directory"] = directory;
14fcb52011-12-04Henrik Grubbström (Grubba)  return "\n" + opentag(objtype, m) + contents + standardEnd(flags) + "\n";
35eee72001-01-08David Norlin  } string print() { string s = ::print() + " " + name + " {\n"; foreach(docGroups, DocGroup dg) {
d7e6d72001-01-11Henrik Grubbström (Grubba)  if (dg->documentation->position) { s += sprintf("doc [%d..%d]:\n", dg->documentation->position->firstline, dg->documentation->position->lastline); } else { s += "doc [..]:\n"; }
35eee72001-01-08David Norlin  s += dg->documentation->text + "\n";
d7e6d72001-01-11Henrik Grubbström (Grubba)  foreach(dg->objects, PikeObject p) { if (p->position) { s += sprintf("%s [%d..%d]\n", p->print(), p->position->firstline, p->position->lastline); } else { s += sprintf("%s [..]\n", p->print()); } }
35eee72001-01-08David Norlin  } return s + "\n}"; }
d7e6d72001-01-11Henrik Grubbström (Grubba) 
9eaf1d2008-06-28Martin Nilsson  protected string _sprintf(int c)
d7e6d72001-01-11Henrik Grubbström (Grubba)  {
4507e92002-11-29Martin Nilsson  switch(c) { case 's': return xml(); case 'O': return sprintf("%O(%O)", this_program, name); }
d7e6d72001-01-11Henrik Grubbström (Grubba)  }
35eee72001-01-08David Norlin }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a class.
35eee72001-01-08David Norlin class Class {
ef67552014-08-25Per Hedbor 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit _Class_or_Module;
ef67552014-08-25Per Hedbor 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "class";
35eee72001-01-08David Norlin }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a module.
35eee72001-01-08David Norlin class Module {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit _Class_or_Module;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "module";
35eee72001-01-08David Norlin }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a name space, eg: @expr{predef::@} or @expr{lfun::@}.
29ce9e2002-12-09Henrik Grubbström (Grubba) class NameSpace {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
29ce9e2002-12-09Henrik Grubbström (Grubba)  inherit _Class_or_Module;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
29ce9e2002-12-09Henrik Grubbström (Grubba)  constant objtype = "namespace"; }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The top-level container. //! This container should only contain namespaces, //! and they in turn contain modules etc.
29ce9e2002-12-09Henrik Grubbström (Grubba) class AutoDoc {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
29ce9e2002-12-09Henrik Grubbström (Grubba)  inherit _Class_or_Module;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
29ce9e2002-12-09Henrik Grubbström (Grubba)  constant objtype = "autodoc";
19d0a32012-01-29Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { // Add an XML header and encode the result as UTF-8. return string_to_utf8("<?xml version='1.0' encoding='utf-8'?>\n" + ::xml(flags) + "\n"); }
29ce9e2002-12-09Henrik Grubbström (Grubba) }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! A modifier range, e.g.: //! @code
4b7f6b2014-08-15Martin Nilsson //! final protected {
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! ... //! <<declarations>> //! ... //! } //! @endcode
ba53cd2001-04-21Henrik Grubbström (Grubba) class Modifier {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
ba53cd2001-04-21Henrik Grubbström (Grubba)  inherit _Class_or_Module;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "modifier";
ba53cd2001-04-21Henrik Grubbström (Grubba) }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a function.
35eee72001-01-08David Norlin class Method {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The names of the arguments.
35eee72001-01-08David Norlin  array(string) argnames;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The types for the arguments.
35eee72001-01-08David Norlin  array(Type) argtypes;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The return type for the function.
35eee72001-01-08David Norlin  Type returntype;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "method";
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { string s = standardTags(flags) + "\n";
35eee72001-01-08David Norlin  string args = ""; for(int i = 0; i < sizeof(argnames); ++i) {
c748382001-01-11David Norlin  if (argtypes[i]) args += xmltag("argument",
7ac43f2003-11-16Henrik Grubbström (Grubba)  argnames[i]&&([ "name" : argnames[i] ]),
14fcb52011-12-04Henrik Grubbström (Grubba)  xmltag("type", argtypes[i]->xml(flags)));
c748382001-01-11David Norlin  else args += xmltag("argument", xmltag("value", argnames[i]));
35eee72001-01-08David Norlin  }
46c5622001-01-11Henrik Grubbström (Grubba)  s += xmltag("arguments", args) + "\n" +
14fcb52011-12-04Henrik Grubbström (Grubba)  xmltag("returntype", returntype->xml(flags)) + "\n"; return standardStart(flags) + s + standardEnd(flags);
35eee72001-01-08David Norlin  } string print() { array(string) args = ({ }); for(int i = 0; i < sizeof(argnames); ++i) args += ({ argtypes[i]->print() + " " + argnames[i] }); return printModifiers() + name + "(" + args * ", " + ")"; } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a named constant.
35eee72001-01-08David Norlin class Constant {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "constant";
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
01dc2a2011-01-26Martin Stjernholm  //! The type of the constant, if known. Type type;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Typedef @[Type] if it is a typedef. Type typedefType = 0;
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return standardStart(flags) + standardTags(flags) + (type ? xmltag ("type", type->xml(flags)) : "") + (typedefType ? xmltag("typevalue", typedefType->xml(flags)) : "") + standardEnd(flags);
35eee72001-01-08David Norlin  } string print() { return ::print() + " " + name; } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a typedef.
3f97b32001-04-11David Norlin class Typedef {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
3f97b32001-04-11David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "typedef";
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Typedef @[Type].
3f97b32001-04-11David Norlin  Type type = 0;
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return standardStart(flags) + standardTags(flags) + xmltag("type", type->xml(flags)) + standardEnd(flags);
3f97b32001-04-11David Norlin  } string print() { return ::print() + (type ? " " + type->print() + " " : "") + name; } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The values inside @expr{enum Foo { ... }@}
3f97b32001-04-11David Norlin class EnumConstant {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
3f97b32001-04-11David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "constant";
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { mapping m = ([]) + standardAttributes(flags); return opentag(objtype, m) + standardTags(flags) + standardEnd(flags);
3f97b32001-04-11David Norlin  } string print() { return "constant"; // for now... } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! The enum container.
3f97b32001-04-11David Norlin class Enum {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
3f97b32001-04-11David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "enum";
3f97b32001-04-11David Norlin 
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Mimic the @expr{class { ... }@} behaviour.
3f97b32001-04-11David Norlin  Documentation documentation;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! The set of children.
3f97b32001-04-11David Norlin  array(DocGroup) children = ({ });
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! Adds @[c] to the set of @[children].
d31e5b2016-08-04Henrik Grubbström (Grubba)  void addChild(DocGroup c) { children += ({ c }); }
46a28a2016-08-04Henrik Grubbström (Grubba)  //! Adds @[c] to the set of @[children].
d31e5b2016-08-04Henrik Grubbström (Grubba)  void addGroup(DocGroup c) { children += ({ c }); }
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
b987c72016-08-03Henrik Grubbström (Grubba)  //! @returns //! Returns @expr{1@} if there is any documentation //! at all for this entity. int containsDoc() { if (documentation && documentation != EmptyDoc) return 1; if (::containsDoc()) return 1; foreach(children, DocGroup c) { if (c->documentation && c->documentation != EmptyDoc) return 1; } return 0; }
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) {
3f97b32001-04-11David Norlin  // need some special handling to make this look as if it // were produced by some other stuff
14fcb52011-12-04Henrik Grubbström (Grubba)  string s = standardStart(flags) + standardTags(flags);
8b3b7c2004-07-08Henrik Grubbström (Grubba)  array(SimpleNode) inDocGroups = ({});
3f97b32001-04-11David Norlin  if (documentation && documentation->xml != "") { // Have to handle all xpath:enum/doc/group[constant] // differently, replacing them according to: // // <group> // <constant name="foo"/> // <text>....</text> // </group> // // Becomes: // // <docgroup homogen-type="constant" homogen-name="foo"> // <constant name="foo"/> // <doc> // <text> // </text> // </doc> // </docgroup>
8b3b7c2004-07-08Henrik Grubbström (Grubba)  SimpleNode doc = simple_parse_input("<doc>"+documentation->xml+"</doc>")->
adc0df2003-04-10Henrik Grubbström (Grubba)  get_first_element();
3f97b32001-04-11David Norlin 
8b3b7c2004-07-08Henrik Grubbström (Grubba)  foreach (doc->get_children(), SimpleNode group) {
3f97b32001-04-11David Norlin  if (group->get_node_type() == XML_ELEMENT && group->get_any_name() == "group") { int constants = 0; string homogenName = 0;
8b3b7c2004-07-08Henrik Grubbström (Grubba)  SimpleNode docGroupNode = SimpleNode(XML_ELEMENT, "docgroup", ([ "homogen-type" : "constant" ]), 0); SimpleNode text = 0; foreach (group->get_children(), SimpleNode child)
3f97b32001-04-11David Norlin  if (child->get_node_type() == XML_ELEMENT) if (child->get_any_name() == "constant") { ++constants; if (constants == 1) homogenName = child->get_attributes()["name"]; else homogenName = 0; docGroupNode->add_child(child); } else if (child->get_any_name() == "text") { if (text) throw("<group> had more than one <text> child!!!!"); text = child; } if (constants) { // <group> had at least one <constant> child. // Then it should be transformed into a <docgroup> child // of the <enum> node. doc->remove_child(group); if (homogenName) docGroupNode->get_attributes() ["homogen-name"] = homogenName; if (text) { // wrap the <text> node in a <doc>, // and then put it inside the <docgroup> // together with the <constant>s
8b3b7c2004-07-08Henrik Grubbström (Grubba)  SimpleNode d = SimpleNode(XML_ELEMENT, "doc", ([]), 0);
3f97b32001-04-11David Norlin  d->add_child(text); docGroupNode->add_child(d); } inDocGroups += ({ docGroupNode }); } } }
adc0df2003-04-10Henrik Grubbström (Grubba)  s += doc->html_of_node();
3f97b32001-04-11David Norlin  } foreach (children, DocGroup docGroup)
14fcb52011-12-04Henrik Grubbström (Grubba)  s += docGroup->xml(flags);
8b3b7c2004-07-08Henrik Grubbström (Grubba)  foreach (inDocGroups, SimpleNode n)
3f97b32001-04-11David Norlin  s += n->html_of_node();
14fcb52011-12-04Henrik Grubbström (Grubba)  s += standardEnd(flags);
3f97b32001-04-11David Norlin  return s; } string print() { return "enum"; } }
2b7b4f2010-08-27Henrik Grubbström (Grubba) //! Represents a variable.
35eee72001-01-08David Norlin class Variable {
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
35eee72001-01-08David Norlin  inherit PikeObject;
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //!
246a8a2001-10-03Martin Nilsson  constant objtype = "variable";
2b7b4f2010-08-27Henrik Grubbström (Grubba)  //! @[Type] of the variable.
35eee72001-01-08David Norlin  Type type;
2b7b4f2010-08-27Henrik Grubbström (Grubba) 
14fcb52011-12-04Henrik Grubbström (Grubba)  string xml(.Flags|void flags) { return standardStart(flags) + standardTags(flags) + xmltag("type", type->xml(flags)) + standardEnd(flags);
35eee72001-01-08David Norlin  } string print() { return printModifiers() + type->print() + " " + name; } }