-
- # Kind of property (fun, attr, etc.)
- fun kind: String is abstract
-
- redef fun short_doc
- do
- var d = doc
- if d != null then
- return d.short
- else if global.intro == self then
- return " "
- else
- return global.intro.short_doc
- end
- end
-
- redef fun doc
- do
- var n = node
- if n == null or not n isa APropdef then
- return null
- end
- var d = n.n_doc
- if d == null then
- return null
- end
- if d.n_comment.is_empty then
- return null
- else
- return d
- end
- end
-
- # The most specific module in the nesting hierarchy that exports the intro of self
- fun intro_module: MMModule
- do
- var m = global.intro.mmmodule
- var mo = m.direct_owner
- while mo != null and mo.visibility_for(m) >= 2 do
- m = mo
- mo = m.direct_owner
- end
- return m
- end
-
- # Is the intro of self exported by the top-level module ?
- fun is_toplevel: Bool
- do
- var m = intro_module
- return m == m.toplevel_owner
- end
-
- # Return true if the global class must be documented according to the visibility configured
- fun require_doc(dctx: DocContext): Bool
- do
- if global.visibility_level == 3 then return false # Private
- if dctx.public_only then
- var m = intro_module
- if m != m.toplevel_owner then return false # Unexported
- end
- return true
- end
-
- # Document the global property in the global class lc
- fun full_documentation(dctx: DocContext, lc: MMLocalClass)
- do
- var visibility: String
- if global.visibility_level == 1 then
- visibility = "public"
- else if global.visibility_level == 2 then
- visibility = "protected"
- else if global.visibility_level == 3 then
- visibility = "private"
- else
- abort
- end
-
- var intro_class = global.intro.local_class
- var is_redef = local_class.global != intro_class.global or local_class.mmmodule.toplevel_owner != intro_class.mmmodule.toplevel_owner
-
- dctx.add("<article id=\"{html_anchor}\" class=\"{kind} {visibility} {if is_redef then "redef" else ""}\">\n")
- dctx.add("<h3 class=\"signature\">{name}{signature.to_html(dctx, true)}</h3>\n")
- dctx.add("<div class=\"info\">\n")
- #dctx.add("<p>LP: {self.mmmodule.html_link(dctx)}::{self.local_class.html_link(dctx)}::{self.html_link(dctx)}</p>")
-
- if is_redef then
- dctx.add("redef ")
- end
- if not is_toplevel then
- dctx.add("(unexported) ")
- end
- if global.visibility_level == 2 then
- dctx.add("protected ")
- else if global.visibility_level == 3 then
- dctx.add("private ")
- end
- dctx.add(kind)
- dctx.add(" {intro_class.mmmodule.toplevel_owner.name}")
- if intro_class.global == lc.global then
- dctx.add("::{lc.name}")
- else
- dctx.add("::{mmmodule[intro_class.global].html_link(dctx)}")
- end
- if is_redef then
- dctx.add("::{mmmodule[intro_class.global][global].html_link(dctx)}")
- else
- dctx.add("::{name}")
- end
- dctx.add("</div>")
-
- dctx.add("<div class=\"description\">")
-
- # Collect all refinement of the global property in the same global property
- var lps = new Array[MMLocalProperty]
- for l in prhe.greaters_and_self do
- lps.add(l)
- end
-
- var introdoc = false
- if global.intro.doc != null then
- for lp in lps do
- if lp.doc == null then introdoc = true
- end
- end
- if introdoc then
- dctx.add("<pre>{global.intro.doc.to_html}</pre>")
- end
-
- var tlmods = new Array[MMModule]
- for lp in lps do
- var bm = lp.mmmodule.toplevel_owner
- var lcm = lc.global.intro.mmmodule
- if lcm.mhe < lp.mmmodule then bm = lcm.toplevel_owner
- if not tlmods.has(bm) then tlmods.add(bm)
- end
-
- for tm in tlmods do
- # Document the top level property for the current top level module
- var tlp
- if tm.global_classes.has(lc.global) then
- tlp = tm[lc.global][self.global]
- assert lps.has(tlp)
- else if tm.global_classes.has(self.local_class.global) then
- # Self is the inherited property. Process it
- tlp = tm[self.local_class.global][self.global]
- assert lps.has(tlp)
- else
- # We skip this module since the props defined by the module is
- continue
- end
-
- var tlcm = lc.global.intro.mmmodule.toplevel_owner
- if not tlcm.mhe <= tm then
- dctx.add("<h4>In module {tm.html_link(dctx)} :</h4>")
- end
-
- #dctx.add("<p>TLP: {tm} x {lc} : {tlp.full_name}</p>")
-
- var doc = tlp.doc
- if doc != null and (not introdoc or global.intro.doc != doc) then
- dctx.add("<pre>{doc.to_html}</pre>")
- end
- dctx.add("<p>")
- if tlp.local_class.global != lc.global then
- dctx.add("inherited from {tlp.local_class.html_link(dctx)} ")
- end
- if tm != tlp.mmmodule then
- dctx.add("defined by the module {tlp.mmmodule.html_link(dctx)} ")
- end
- var n = tlp.node
- if n != null then
- var l = n.location
- dctx.show_source(l)
- end
-
- dctx.open_stage
- dctx.stage(". previously defined by:")
- for lp in lps do
- var tl = lp.mmmodule.toplevel_owner
- if tl != tm then continue
- if lp == tlp then continue
- dctx.add(" {lp.mmmodule.html_link(dctx)}")
- if lp.local_class.global != lc.global then
- dctx.add(" for {lp.local_class.html_link(dctx)}")
- end
-
- n = lp.node
- if n != null then
- var l = n.location
- dctx.show_source(l)
- end
-
- #var doc = lp.doc
- #if doc != null and (not introdoc or global.intro.doc != doc) then
- # dctx.add("<pre>{doc.to_html}</pre>")
- #end
- end
- dctx.close_stage
- dctx.add("</p>")
- end
- dctx.add("</div>")
- dctx.add("</article>")
- end
-end
-redef class MMMethod
- redef fun kind do return if global.is_init then "init" else "fun"
-end
-redef class MMAttribute
- redef fun kind do return "var"
-end
-redef class MMTypeProperty
- redef fun kind do return "type"
-end
-
-redef class Symbol
- # Replace < and > with html entities
- redef fun to_s
- do
- var ret = super.to_s
-
- if(ret.has('<')) then
- var parts = ret.split_with("<")
- ret = ""
-
- for i in [0..parts.length[ do
- ret += parts[i]
-
- if(i < parts.length - 1) then
- ret += "<"
- end
- end
- end
-
- if(ret.has('>')) then
- var parts = ret.split_with(">")
- ret = ""
-
- for i in [0..parts.length[ do
- ret += parts[i]
-
- if(i < parts.length - 1) then
- ret += ">"
- end
- end
- end
-
- return ret
- end
-end
-
-redef class MMSrcModule
- redef fun short_doc
- do
- var d = doc
- if d != null then
- return d.short
- else
- return " "
- end
- end
-
- redef fun doc
- do
- var n = node
- if n.n_moduledecl == null then
- return null
- end
- var np = n.n_moduledecl
- var d = np.n_doc
- if d == null then
- return null
- end
- if d.n_comment.is_empty then
- return null
- else
- return d
- end
- end
-end
-
-redef class ADoc
- # Html transcription of the doc
- fun to_html: String
- do
- var res = new Buffer
- for c in n_comment do
- res.append(c.text.substring_from(1))
- end
- return res.to_s
- end
-
- # Oneliner transcription of the doc
- fun short: String
- do
- return n_comment.first.text.substring_from(1)
- end
-end
-
-redef class MMLocalClass
- super MMEntity
-
- # Anchor of the class description in the module html file
- fun html_anchor: String do return "CLASS_{self}"
-
- fun html_name: String do return "{self}"
-
- redef fun html_link(dctx)
- do
- if not require_doc(dctx) then print "{dctx.filename}: not required {self}"
- return "<a href=\"{html_name}.html\" title=\"{short_doc}\">{self}</a>"
- end
-
- redef fun short_doc do return global.intro.short_doc
-
- redef fun doc do return global.intro.doc
-
- fun kind: String
- do
- if global.is_interface then
- return "interface"
- else if global.is_abstract then
- return "abstract class"
- else if global.is_enum then
- return "enum"
- else
- return "class"
- end
- end
-
- # The most specific module in the nesting hierarchy that exports the intro of self
- fun intro_module: MMModule
- do
- var m = global.intro.mmmodule
- var mo = m.direct_owner
- while mo != null and mo.visibility_for(m) >= 2 do
- m = mo
- mo = m.direct_owner
- end
- return m
- end
-
- fun menu_link(dctx: DocContext, p: MMLocalProperty)
- do
- if p.local_class.global != self.global then
- if p.global.intro.local_class.name == "Object".to_symbol then return
- if p.global.is_init or p isa MMTypeProperty then
- dctx.add("<li class='inherit'><span title='Inherited'>H</span> {p.html_link_special(dctx, self)}</li>\n")
- else
- dctx.add("<li class='inherit'><span title='Inherited'>H</span> {p.html_link(dctx)}</li>\n")
- end
- else if p.global.intro.local_class.global == self.global then
- dctx.add("<li class='intro'><span title='Introduced'>I</span> {p.html_link_special(dctx, self)}</li>\n")
- else
- dctx.add("<li class='redef'><span title='Redefined'>R</span> {p.html_link_special(dctx, self)}</li>\n")
- end
- end
-
- # Return true if the global class must be documented according to the visibility configured
- fun require_doc(dctx: DocContext): Bool
- do
- if global.visibility_level == 3 then return false # Private
- if dctx.public_only then
- var m = intro_module
- if m != m.toplevel_owner then return false # Unexported
- end
- return true
- end
-
- # Fill the body for the page associated to the global class
- fun file_page_doc(dctx: DocContext)
- do
- dctx.add("<div class=\"menu\">\n")
-
- var props = new Array[MMLocalProperty]
- var inh = new HashMap[MMLocalClass, Array[MMLocalProperty]]
- var inhs = new Array[MMLocalClass]
- for g in global_properties do
- var p = self[g]
- if not p.require_doc(dctx) then continue
- if p.local_class.global == global or g.is_init_for(self) or p isa MMTypeProperty then
- props.add(p)
- else
- var lc = mmmodule[p.local_class.global]
- if inh.has_key(lc) then
- inh[lc].add(p)
- else
- inh[lc] = [p]
- inhs.add(lc)
- end
- props.add(p)
- end
- end
- dctx.sort(props)
-
- dctx.add("<nav class=\"properties filterable\">\n")
- dctx.add("<h3>Properties</h3>\n")
- dctx.open_stage
- dctx.stage("<h4>Virtual Types</h4>\n<ul>\n")
- for p in props do
- if p isa MMTypeProperty then
- menu_link(dctx, p)
- end
- end
- dctx.stage("</ul>\n")
- dctx.close_stage
- dctx.open_stage
- dctx.stage("<h4>Constructors</h4>\n<ul>\n")
- for p in props do
- if p.global.is_init_for(self) then
- menu_link(dctx, p)
- end
- end
- dctx.stage("</ul>\n")
- dctx.close_stage
- dctx.open_stage
- dctx.stage("<h4>Methods</h4>\n<ul>\n")
- for p in props do
- if not p.global.is_init and p isa MMMethod then
- menu_link(dctx, p)
- end
- end
- dctx.stage("</ul>\n")
- dctx.close_stage
- dctx.add("</nav>\n")
-
- dctx.add("<nav class=\"inheritance filterable\">\n")
- dctx.add("<h3>Inheritance</h3>\n")
- dctx.add("<h4>Superclasses</h4>\n<ul>\n")
- for lc in cshe.linear_extension do
- if lc == self then continue
- if not lc.require_doc(dctx) then continue
- dctx.add("<li>{lc.html_link(dctx)}</li>\n")
- end
- dctx.add("</ul>\n")
- if cshe.smallers.length == 0 then
- dctx.add("<h4>No Known Subclasses</h4>\n")
- else if cshe.smallers.length <= 100 then
- dctx.add("<h4>Subclasses</h4>\n")
- dctx.add("<ul>\n")
- for lc in cshe.smallers do
- if not lc.require_doc(dctx) then continue
- dctx.add("<li>{lc.html_link(dctx)}</li>\n")
- end
- dctx.add("</ul>\n")
- else if cshe.direct_smallers.length <= 100 then
- dctx.add("<h4>Direct Subclasses Only</h4>\n<ul>\n")
- for lc in cshe.direct_smallers do
- if not lc.require_doc(dctx) then continue
- dctx.add("<li>{lc.html_link(dctx)}</li>\n")
- end
- dctx.add("</ul>\n")
- else
- dctx.add("<h4>Too much Subclasses to list</h4>\n")
- end
- dctx.add("</nav>\n")
-
- dctx.add("</div>\n")
-
-
- dctx.add("<div class=\"content\">\n")
- dctx.add("<h1>{name}</h1>\n")
- dctx.add("<div class='subtitle'>")
- if global.visibility_level == 2 then
- abort
- else if global.visibility_level == 3 then
- dctx.add("private ")
- else if self.global.intro.mmmodule.toplevel_owner.visibility_for(self.global.intro.mmmodule) <= 1 then
- dctx.add("(unexported) ")
- end
- dctx.add("{kind} {global.intro.mmmodule.toplevel_owner.html_link(dctx)}::{name}</div>")
-
- dctx.add("<section class=\"description\">\n")
- var doc = doc
- if doc != null then
- dctx.add("<pre>{doc.to_html}</pre>\n")
- end
-
- var cla = new HashSet[MMLocalClass]
- var sm = new HashSet[MMLocalClass]
- var sm2 = new HashSet[MMLocalClass]
- sm.add(self)
- while cla.length + sm.length < 10 and sm.length > 0 do
- cla.add_all(sm)
- sm2.clear
- for x in sm do
- sm2.add_all(x.cshe.direct_smallers)
- end
- var t = sm
- sm = sm2
- sm2 = t
- end
- cla.add_all(cshe.greaters_and_self)
-
- var op = new Buffer
- op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
- for c in cla do
- if c == self then
- op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
- else
- op.append("\"{c.name}\"[URL=\"{c.html_name}.html\"];\n")
- end
- for c2 in c.cshe.direct_greaters do
- if not cla.has(c2) then continue
- op.append("\"{c.name}\"->\"{c2.name}\";\n")
- end
- if not c.cshe.direct_smallers.is_empty then
- var others = true
- for c2 in c.cshe.direct_smallers do
- if cla.has(c2) then others = false
- end
- if others then
- op.append("\"{c.name}...\"[label=\"\"];\n")
- op.append("\"{c.name}...\"->\"{c.name}\"[style=dotted];\n")
- end
- end
- end
- op.append("\}\n")
- dctx.gen_dot(op.to_s, name.to_s, "Inheritance graph for class {name}")
-
-
- var mods = new Array[MMModule]
- mods.add(global.intro.mmmodule.toplevel_owner)
- for lc in crhe.greaters do
- if not lc isa MMSrcLocalClass then continue
- var m = lc.mmmodule.toplevel_owner
- if not mods.has(m) then mods.add(m)
- end
- dctx.sort(mods)
- for m in mods do
- if m == global.intro.mmmodule.toplevel_owner then
- dctx.add("<p>Introduced by {m.html_link(dctx)}")
- else
- dctx.add("<p>Refined by {m.html_link(dctx)}")
- end
- dctx.open_stage
- dctx.stage(". Definition in:")
- for lc in crhe.greaters do
- if lc.mmmodule.toplevel_owner != m then continue
- dctx.add(" {lc.mmmodule.html_link(dctx)}")
- assert lc isa MMSrcLocalClass
- var n = lc.node
- if n != null then
- dctx.show_source(n.location)
- end
- end
- dctx.close_stage
- dctx.add("</p>\n")
- end
- dctx.add("</section>\n")
-
- dctx.open_stage
- dctx.stage("<section class=\"types\">\n")
- dctx.stage("<h2>Formal and Virtual Types</h2>\n")
- for i in [0..arity[ do
- var f = get_formal(i)
- f.full_documentation(dctx, self)
- end
- for p in props do
- if not p isa MMTypeProperty then continue
- p.full_documentation(dctx, self)
- end
- dctx.stage("</section>\n")
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<section class=\"constructors\">\n")
- dctx.stage("<h2 class=\"section-header\">Constructors</h2>\n")
- for p in props do
- if not p.global.is_init_for(self) then continue
- p.full_documentation(dctx, self)
- end
- dctx.stage("</section>\n")
- dctx.close_stage
-
- dctx.open_stage
- dctx.stage("<section class=\"methods\">\n")
- dctx.stage("<h2 class=\"section-header\">Methods</h2>\n")
- for p in props do
- if p.global.is_init then continue
- if p.local_class.global != self.global then continue
- if not p isa MMMethod then continue
- p.full_documentation(dctx, self)
- end
- if not inhs.is_empty then
- dctx.open_stage
- dctx.stage("<h3>Inherited Methods</h3>\n")
- for lc in inhs do
- dctx.open_stage
- dctx.stage("<p>Defined in {lc.html_link(dctx)}:")
- for p in inh[lc] do
- if p.global.is_init then continue
- if not p isa MMMethod then continue
- dctx.add(" {p.html_link(dctx)}")
- end
- dctx.stage("</p>")
- dctx.close_stage
- end
- dctx.close_stage
- end
- dctx.add("</section>\n")
- dctx.close_stage
- dctx.add("</div> <!-- end class {name} -->\n")
- end
-end
-
-redef class MMSrcLocalClass
- redef fun short_doc
- do
- var d = doc
- if d != null then
- return d.short
- else if global.intro == self then
- return " "
- else
- var bc = global.intro
- return bc.short_doc
- end
- end
-
- redef fun doc
- do
- var n = node
- if not n isa AStdClassdef then
- return null
- end
- var d = n.n_doc
- if d == null then
- return null
- end
- if d.n_comment.is_empty then
- return null
- else
- return d
- end
- end
-end
-
-redef class MMSignature
- # Htlm transcription of the signature (with nested links)
- fun to_html(dctx: DocContext, with_closure: Bool): String
- do
- var res = new Buffer
- if arity > 0 then
- res.append("(")
- res.append(self.params[0].name.to_s)
- res.append(": ")
- res.append(self[0].html_link(dctx))
- for i in [1..arity[ do
- res.append(", ")
- res.append(self.params[i].name.to_s)
- res.append(": ")
- res.append(self[i].html_link(dctx))
- end
- res.append(")")
- end
- if return_type != null then
- res.append(": ")
- res.append(return_type.html_link(dctx))
- end
- if with_closure then
- for c in closures do
- res.append(" ")
- if c.is_optional then res.append("[")
- if c.is_break then res.append("break ")
- res.append("!{c.name}")
- res.append(c.signature.to_html(dctx, false))
- if c.is_optional then res.append("]")
- end
- end
- return res.to_s
- end
-end
-
-redef class MMType
- # Htlm transcription of the type (with nested links)
- fun html_link(dctx: DocContext): String do return to_s
-end
-
-redef class MMTypeSimpleClass
- redef fun html_link(dctx) do return local_class.html_link(dctx)
-end
-
-redef class MMTypeGeneric
- redef fun html_link(dctx)
- do
- var res = new Buffer
- res.append(local_class.html_link(dctx))
- res.append("[")
- res.append(params[0].html_link(dctx))
- for i in [1..params.length[ do
- res.append(", ")
- res.append(params[i].html_link(dctx))
- end
- res.append("]")
- return res.to_s
- end
-end
-
-redef class MMTypeFormalParameter
- fun html_anchor: String
- do
- return "FT_{local_class}_{cmangle(name)}"
- end
- redef fun html_link(dctx)
- do
- return "<a href=\"#{html_anchor}\">{name}</a>"
- end
- fun full_documentation(dctx: DocContext, lc: MMLocalClass)
- do
- dctx.add("<article id=\"{html_anchor}\">\n")
- dctx.add("<h3 class=\"signature\">{name}: {bound.html_link(dctx)}</h3>\n")
- dctx.add("<div class=\"info\">")
- dctx.add("formal generic type")
- dctx.add("</div>")
- dctx.add("</article>")
- end
-end
-
-redef class MMNullableType
- redef fun html_link(dctx) do return "nullable " + as_notnull.html_link(dctx)
-end
-
-redef class MMVirtualType
- redef fun html_link(dctx) do return property.html_link(dctx)