The first part of the PR cleanup and factorize some things related to the operators in the grammar and the AST.
Then the four bitwise operators are added.
Close #1271 unless some more thing is added to it (like generalized unary operators)
Note: as usual, github is useless when the parser is regenerated, so review the individual commits if you prefer.
Pull-Request: #1295
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
var key = self.key / achievement.key
if game.store.has_key(key) then return
stats.inc("achievements")
- achievement.save_in(self)
+ achievement.save_in(self.key)
save
end
redef class GameEntity
# Saves `event` in `self`.
- fun add_event(event: GameEvent) do event.save_in(self)
+ fun add_event(event: GameEvent) do event.save_in(self.key)
# List all events registered in this entity.
#
# Date are stored under `self.key`.
fun save do game.store.store_object(key, to_json)
- # Saves `self` state into `target` key data.
+ # Saves `self` state under `key` data.
#
- # Data are stored under `target.key / self.key`.
- fun save_in(target: GameEntity) do
- game.store.store_object(target.key / key, to_json)
+ # Data are stored under `key / self.key`.
+ fun save_in(key: String) do
+ game.store.store_object(key / self.key, to_json)
end
# Json representation of `self`.
redef class GameEntity
- # Statistics for this entity.
- fun stats: GameStats is abstract
-
- # Load statistics for this `MEntity` if any.
- fun load_statistics: nullable GameStats do
- var key = self.key / "statistics"
- if not game.store.has_key(key) then return null
- var json = game.store.load_object(key)
- return new GameStats.from_json(game, json)
- end
+ # Statistics manager for this entity.
+ fun stats: GameStatsManager is abstract
end
redef class Game
- redef var stats is lazy do
- return load_statistics or else new GameStats(game)
- end
+ redef var stats is lazy do return new GameStatsManager(game, self)
redef fun save do
super
- stats.save_in(self)
+ stats.save_in(self.key)
end
redef fun pretty do
redef class Player
- redef var stats is lazy do
- return load_statistics or else new GameStats(game)
- end
+ redef var stats is lazy do return new GameStatsManager(game, self)
redef fun save do
super
- stats.save_in(self)
+ stats.save_in(self.key)
end
+ redef fun nitcoins do return stats["nitcoins"]
+ redef fun nitcoins=(nc) do stats["nitcoins"] = nc
+
redef fun pretty do
var res = new FlatBuffer
res.append super
end
end
+# Store game stats for defined period.
+class GameStatsManager
+ super GameEntity
+ super Counter[String]
+
+ redef var game
+
+ # The GameEntity monitored by these statistics.
+ var owner: GameEntity
+
+ redef var key = "stats"
+
+ # Returns the `GameStats` instance for the overall statistics.
+ var overall: GameStats is lazy do
+ return load_stats_for("all")
+ end
+
+ # Returns the `GameStats` instance for the current year statistics.
+ var yearly: GameStats is lazy do
+ var date = new Tm.gmtime
+ var key = date.strftime("%Y")
+ return load_stats_for(key)
+ end
+
+ # Returns the `GameStats` instance for the current month statistics.
+ var monthly: GameStats is lazy do
+ var date = new Tm.gmtime
+ var key = date.strftime("%Y-%m")
+ return load_stats_for(key)
+ end
+
+ # Returns the `GameStats` instance for the current day statistics.
+ var daily: GameStats is lazy do
+ var date = new Tm.gmtime
+ var key = date.strftime("%Y-%m-%d")
+ return load_stats_for(key)
+ end
+
+ # Returns the `GameStats` instance for the current week statistics.
+ var weekly: GameStats is lazy do
+ var date = new Tm.gmtime
+ var key = date.strftime("%Y-W%U")
+ return load_stats_for(key)
+ end
+
+ # Load statistics for a `period` key.
+ fun load_stats_for(period: String): GameStats do
+ var key = owner.key / self.key / period
+ if not game.store.has_key(key) then
+ return new GameStats(game, period)
+ end
+ var json = game.store.load_object(key)
+ return new GameStats.from_json(game, period, json)
+ end
+
+ redef fun [](key) do return overall[key]
+
+ redef fun []=(key, value) do
+ overall[key] = value
+ yearly[key] = value
+ monthly[key] = value
+ daily[key] = value
+ weekly[key] = value
+ end
+
+ redef fun inc(e) do
+ overall.inc(e)
+ yearly.inc(e)
+ monthly.inc(e)
+ daily.inc(e)
+ weekly.inc(e)
+ end
+
+ redef fun dec(e) do
+ overall.dec(e)
+ yearly.dec(e)
+ monthly.dec(e)
+ daily.dec(e)
+ weekly.dec(e)
+ end
+
+ redef fun save_in(key) do
+ overall.save_in(key / self.key)
+ yearly.save_in(key / self.key)
+ monthly.save_in(key / self.key)
+ daily.save_in(key / self.key)
+ weekly.save_in(key / self.key)
+ end
+
+ redef fun pretty do return overall.pretty
+end
+
# Game statistics structure that can be saved as a `GameEntity`.
class GameStats
super GameEntity
redef var game
- redef var key = "statistics"
+ # The pedriod these stats are about.
+ var period: String
+
+ redef fun key do return period
- # Load `self` from saved data
- init from_json(game: Game, json: JsonObject) do
- self.game = game
+ # Load `self` from saved data.
+ init from_json(game: Game, period: String, json: JsonObject) do
for k, v in json do self[k] = v.as(Int)
end
return obj
end
- # Decrements the value of `key` statistic entry by 1.
- fun dec(key: String) do
- if not has_key(key) then
- self[key] = 0
- else
- self[key] -= 1
- end
- end
-
redef fun pretty do
var res = new FlatBuffer
for k, v in self do
redef fun render_title do
add "<span class=\"glyphicon glyphicon-check\"></span> "
- add "Review pull requests to gain nitcoins!"
+ add "Review pull requests and comment issues to gain nitcoins!"
end
redef fun render_body do
var q = "is:open label:need_review sort:updated-asc " +
"-involves:{player.name}"
- var issues = game.repo.search_issues(q)
+ var q2 = "is:open label:request_for_comments sort:updated-asc " +
+ "-involves:{player.name}"
+
+ var issues = new ArraySet[Issue]
+ issues.add_all game.repo.search_issues(q).as(not null)
+ issues.add_all game.repo.search_issues(q2).as(not null)
+ if issues.is_empty then
+ add "<em>No pull request or issue to review yet...</em>"
+ return
+ end
+ for issue in issues do
+ var user = issue.user
+ var uplay = user.player(game)
+ add """<div class="media">
+ <a class="media-left" href="{{{uplay.url}}}">
+ <img class=\"img-circle\" style="width:50px"
+ src="{{{user.avatar_url}}}" alt="{{{uplay.name}}}">
+ </a>
+ <div class="media-body">
+ <h4 class="media-heading">
+ {{{issue.link}}} {{{issue.title}}}
+ </h4>
+ <span class="text-muted">opened by </span>
+ {{{uplay.link}}}
+ </div>
+ </div>"""
+ end
+ end
+end
+
+# A `Panel` that displays the work assigned or tagged.
+class PlayerWorkPanel
+ super Panel
+
+ # Repo to display.
+ var game: Game
+
+ # Player to display customized list for.
+ var player: Player
+
+ redef fun render_title do
+ add "<span class=\"glyphicon glyphicon-check\"></span> "
+ add "Do your tasks to gain nitcoins!"
+ end
+
+ redef fun render_body do
+ var q = "is:open label:need_work sort:updated-asc author:{player.name}"
+ var q2 = "is:open sort:updated-asc assignee:{player.name}"
+
+ var issues = new ArraySet[Issue]
+ issues.add_all game.repo.search_issues(q).as(not null)
+ issues.add_all game.repo.search_issues(q2).as(not null)
if issues.is_empty then
- add "<em>No pull request to review yet...</em>"
+ add "<em>No work to do yet...</em>"
return
end
for issue in issues do
page.side_panels.clear
page.side_panels.add new PlayerStatusPanel(game, player)
page.flow_panels.add new PlayerReviewsPanel(game, player)
+ page.flow_panels.add new PlayerWorkPanel(game, player)
page.flow_panels.add new AchievementsListPanel(player)
page.flow_panels.add new EventListPanel(player, list_limit, list_from)
rsp.body = page.write_to_string
for e in es do inc(e)
end
+ # Decrement the value of `e` by 1
+ fun dec(e: E) do
+ if not has_key(e) then
+ self.map[e] = 0
+ else
+ self.map[e] = self[e] - 1
+ sum += - 1
+ end
+ end
+
+ # Decrement the value for each element of `es`
+ fun dec_all(es: Collection[E])
+ do
+ for e in es do dec(e)
+ end
+
# A new Counter initialized with `inc_all`.
init from(es: Collection[E])
do
redef fun compare(a, b) do return a <=> b
end
+# This comparator uses the operator `<=>` to compare objects in a reverse order.
+#
+# See `default_reverse_comparator` for an easy-to-use general stateless reverse
+# default comparator.
+class DefaultReverseComparator
+ super Comparator
+
+ redef type COMPARED: Comparable
+
+ # Returns `b <=> a`.
+ redef fun compare(a, b) do return b <=> a
+end
+
# Easy-to-use general stateless default comparator that uses `<=>` to compare things.
fun default_comparator: DefaultComparator do return once new DefaultComparator
+
+# Easy-to-use general stateless default reverse comparator.
+#
+# Does the same as `default_comparator` but in reverse order.
+fun default_reverse_comparator: DefaultReverseComparator do
+ return once new DefaultReverseComparator
+end
var sarticle = mproject.tpl_article
sarticle.subtitle = mproject.html_declaration
sarticle.content = mproject.tpl_definition
- var mdoc = mproject.mdoc_or_fallback
- if mdoc != null then
- sarticle.content = mdoc.tpl_short_comment
+ var comment = mproject.html_short_comment
+ if comment != null then
+ sarticle.content = comment
end
ssection.add_child sarticle
end
if mentity isa MPropDef then
article.source_link = v.tpl_showsource(mentity.location)
end
- if not mentity isa MVirtualTypeProp then
- # article.content = mentity.tpl_comment
- end
end
for child in children do
child.render(v, doc, page, article)
article.title_classes.add "signature"
article.summary_title = "{mprop.html_name}"
article.subtitle = mpropdef.html_namespace
- if mpropdef.mdoc_or_fallback != null then
- article.content = mpropdef.mdoc_or_fallback.tpl_comment
+ var comment = mpropdef.html_comment
+ if comment != null then
+ article.content = comment
end
# TODO move in its own phase? let's see after doc_template refactoring.
# Add linearization
parent.add_child article
end
end
+
+redef class Location
+ # Github url based on this location
+ fun github(gitdir: String): String do
+ var base_dir = getcwd.join_path(gitdir).simplify_path
+ var file_loc = getcwd.join_path(file.filename).simplify_path
+ var gith_loc = file_loc.substring(base_dir.length + 1, file_loc.length)
+ return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
+ end
+end
+
+redef class MEntity
+ # A template article that briefly describe the entity
+ fun tpl_short_article: TplArticle do
+ var tpl = tpl_article
+ var comment = html_short_comment
+ if comment != null then
+ tpl.content = comment
+ end
+ return tpl
+ end
+
+ # A template article that describe the entity
+ fun tpl_article: TplArticle do
+ var tpl = new TplArticle.with_title(nitdoc_id, tpl_title)
+ tpl.title_classes.add "signature"
+ tpl.subtitle = html_namespace
+ tpl.summary_title = html_name
+ return tpl
+ end
+
+ # A template definition of the mentity
+ # include name, sysnopsys, comment and namespace
+ fun tpl_definition: TplDefinition is abstract
+
+ # A li element that can go in a list
+ fun tpl_list_item: TplListItem do
+ var lnk = new Template
+ lnk.add new TplLabel.with_classes(tpl_css_classes)
+ lnk.add html_link
+ var comment = html_short_comment
+ if comment != null then
+ lnk.add ": "
+ lnk.add comment
+ end
+ return new TplListItem.with_content(lnk)
+ end
+
+ var tpl_css_classes = new Array[String]
+
+ # Box title for this mentity
+ fun tpl_title: Template do
+ var title = new Template
+ title.add tpl_icon
+ title.add html_namespace
+ return title
+ end
+
+ # Icon that will be displayed before the title
+ fun tpl_icon: TplIcon do
+ var icon = new TplIcon.with_icon("tag")
+ icon.css_classes.add_all(tpl_css_classes)
+ return icon
+ end
+end
+
+redef class MConcern
+ # Return a li element for `self` that can be displayed in a concern list
+ private fun tpl_concern_item: TplListItem do
+ var lnk = new Template
+ lnk.add html_link_to_anchor
+ var comment = html_short_comment
+ if comment != null then
+ lnk.add ": "
+ lnk.add comment
+ end
+ return new TplListItem.with_content(lnk)
+ end
+end
+
+redef class MProject
+ redef fun tpl_definition do
+ var tpl = new TplDefinition
+ var comment = html_comment
+ if comment != null then
+ tpl.comment = comment
+ end
+ return tpl
+ end
+
+ redef fun tpl_css_classes do return ["public"]
+end
+
+redef class MGroup
+ redef fun tpl_definition do
+ var tpl = new TplDefinition
+ var comment = html_comment
+ if comment != null then
+ tpl.comment = comment
+ end
+ return tpl
+ end
+end
+
+redef class MModule
+ redef fun tpl_definition do
+ var tpl = new TplClassDefinition
+ var comment = html_comment
+ if comment != null then
+ tpl.comment = comment
+ end
+ return tpl
+ end
+
+ redef fun tpl_css_classes do return ["public"]
+end
+
+redef class MClass
+ redef fun tpl_definition do return intro.tpl_definition
+
+ redef fun tpl_title do
+ var title = new Template
+ title.add tpl_icon
+ title.add html_link
+ return title
+ end
+
+ redef fun tpl_icon do return intro.tpl_icon
+ redef fun tpl_css_classes do return intro.tpl_css_classes
+end
+
+redef class MClassDef
+ redef fun tpl_article do
+ var tpl = new TplArticle(nitdoc_id)
+ tpl.summary_title = "in {mmodule.html_name}"
+ tpl.title = html_declaration
+ tpl.title_classes.add "signature"
+ var title = new Template
+ title.add "in "
+ title.add mmodule.html_namespace
+ tpl.subtitle = title
+ var comment = html_comment
+ if comment != null then
+ tpl.content = comment
+ end
+ return tpl
+ end
+
+ redef fun tpl_title do
+ var title = new Template
+ title.add tpl_icon
+ title.add html_link
+ return title
+ end
+
+ redef fun tpl_definition do
+ var tpl = new TplClassDefinition
+ var comment = html_comment
+ if comment != null then
+ tpl.comment = comment
+ end
+ return tpl
+ end
+
+ redef fun tpl_css_classes do
+ var set = new HashSet[String]
+ if is_intro then set.add "intro"
+ for m in mclass.intro.modifiers do set.add m.to_cmangle
+ for m in modifiers do set.add m.to_cmangle
+ return set.to_a
+ end
+
+ fun tpl_modifiers: Template do
+ var tpl = new Template
+ for modifier in modifiers do
+ if modifier == "public" then continue
+ tpl.add "{modifier.html_escape} "
+ end
+ return tpl
+ end
+end
+
+redef class MProperty
+ redef fun tpl_title do return intro.tpl_title
+ redef fun tpl_icon do return intro.tpl_icon
+ redef fun tpl_css_classes do return intro.tpl_css_classes
+end
+
+redef class MPropDef
+ redef fun tpl_article do
+ var tpl = new TplArticle(nitdoc_id)
+ tpl.summary_title = "in {mclassdef.html_name}"
+ var title = new Template
+ title.add "in "
+ title.add mclassdef.html_link
+ tpl.title = title
+ tpl.subtitle = html_declaration
+ var comment = html_comment
+ if comment != null then
+ tpl.content = comment
+ end
+ return tpl
+ end
+
+ redef fun tpl_definition do
+ var tpl = new TplDefinition
+ var comment = html_comment
+ if comment != null then
+ tpl.comment = comment
+ end
+ return tpl
+ end
+
+ redef fun tpl_css_classes do
+ var set = new HashSet[String]
+ if is_intro then set.add "intro"
+ for m in mproperty.intro.modifiers do set.add m.to_cmangle
+ for m in modifiers do set.add m.to_cmangle
+ return set.to_a
+ end
+
+ fun tpl_modifiers: Template do
+ var tpl = new Template
+ for modifier in modifiers do
+ if modifier == "public" then continue
+ tpl.add "{modifier.html_escape} "
+ end
+ return tpl
+ end
+
+ redef fun tpl_list_item do
+ var lnk = new Template
+ lnk.add new TplLabel.with_classes(tpl_css_classes.to_a)
+ var atext = html_link.text
+ var ahref = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
+ var atitle = html_link.title
+ var anchor = new Link.with_title(ahref, atext, atitle)
+ lnk.add anchor
+ var comment = html_short_comment
+ if comment != null then
+ lnk.add ": "
+ lnk.add comment
+ end
+ return new TplListItem.with_content(lnk)
+ end
+
+ fun tpl_inheritance_item: TplListItem do
+ var lnk = new Template
+ lnk.add new TplLabel.with_classes(tpl_css_classes.to_a)
+ lnk.add mclassdef.mmodule.html_namespace
+ lnk.add "::"
+ var atext = mclassdef.html_link.text
+ var ahref = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
+ var atitle = mclassdef.html_link.title
+ var anchor = new Link.with_title(ahref, atext, atitle)
+ lnk.add anchor
+ var comment = html_short_comment
+ if comment != null then
+ lnk.add ": "
+ lnk.add comment
+ end
+ var li = new TplListItem.with_content(lnk)
+ li.css_classes.add "signature"
+ return li
+ end
+end
+
+redef class ConcernsTree
+
+ private var seen = new HashSet[MConcern]
+
+ redef fun add(p, e) do
+ if seen.has(e) then return
+ seen.add e
+ super(p, e)
+ end
+
+ fun to_tpl: TplList do
+ var lst = new TplList.with_classes(["list-unstyled", "list-definition"])
+ for r in roots do
+ var li = r.tpl_concern_item
+ lst.add_li li
+ build_list(r, li)
+ end
+ return lst
+ end
+
+ private fun build_list(e: MConcern, li: TplListItem) do
+ if not sub.has_key(e) then return
+ var subs = sub[e]
+ var lst = new TplList.with_classes(["list-unstyled", "list-definition"])
+ for e2 in subs do
+ if e2 isa MGroup and e2.is_root then
+ build_list(e2, li)
+ else
+ var sli = e2.tpl_concern_item
+ lst.add_li sli
+ build_list(e2, sli)
+ end
+ end
+ li.append lst
+ end
+end
+
+redef class MInnerClassDef
+ redef fun tpl_definition do
+ var tpl = new TplClassDefinition
+ var comment = html_comment
+ if comment != null then
+ tpl.comment = comment
+ end
+ return tpl
+ end
+end
import html::bootstrap
import ordered_tree
-redef class Location
- # Github url based on this location
- fun github(gitdir: String): String do
- var base_dir = getcwd.join_path(gitdir).simplify_path
- var file_loc = getcwd.join_path(file.filename).simplify_path
- var gith_loc = file_loc.substring(base_dir.length + 1, file_loc.length)
- return "{gith_loc}:{line_start},{column_start}--{line_end},{column_end}"
- end
-end
-
redef class MEntity
# ID used as a HTML unique ID and in file names.
#
# * MPropdef: `mclassdef:mpropdef`
fun html_namespace: Template is abstract
- # A template article that briefly describe the entity
- fun tpl_short_article: TplArticle do
- var tpl = tpl_article
+ # Returns the comment of this MEntity formatted as HTML.
+ var html_comment: nullable Writable is lazy do
var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.content = mdoc.tpl_short_comment
- end
- return tpl
- end
-
- # A template article that describe the entity
- fun tpl_article: TplArticle do
- var tpl = new TplArticle.with_title(nitdoc_id, tpl_title)
- tpl.title_classes.add "signature"
- tpl.subtitle = html_namespace
- tpl.summary_title = html_name
- return tpl
- end
-
- # A template definition of the mentity
- # include name, sysnopsys, comment and namespace
- fun tpl_definition: TplDefinition is abstract
-
- # A li element that can go in a list
- fun tpl_list_item: TplListItem do
- var lnk = new Template
- lnk.add new TplLabel.with_classes(tpl_css_classes)
- lnk.add html_link
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- lnk.add ": "
- lnk.add mdoc.tpl_short_comment
- end
- return new TplListItem.with_content(lnk)
+ if mdoc == null then return null
+ return mdoc.tpl_comment
end
- var tpl_css_classes = new Array[String]
-
- # Box title for this mentity
- fun tpl_title: Template do
- var title = new Template
- title.add tpl_icon
- title.add html_namespace
- return title
- end
-
- # Icon that will be displayed before the title
- fun tpl_icon: TplIcon do
- var icon = new TplIcon.with_icon("tag")
- icon.css_classes.add_all(tpl_css_classes)
- return icon
- end
-end
-
-redef class MConcern
- # Return a li element for `self` that can be displayed in a concern list
- private fun tpl_concern_item: TplListItem do
- var lnk = new Template
- lnk.add html_link_to_anchor
+ # Returns the comment of this MEntity formatted as HTML.
+ var html_short_comment: nullable Writable is lazy do
var mdoc = mdoc_or_fallback
- if mdoc != null then
- lnk.add ": "
- lnk.add mdoc.tpl_short_comment
- end
- return new TplListItem.with_content(lnk)
+ if mdoc == null then return null
+ return mdoc.tpl_short_comment
end
end
redef fun nitdoc_url do return root.nitdoc_url
redef var html_modifiers = ["project"]
redef fun html_namespace do return html_link
-
- redef fun tpl_definition do
- var tpl = new TplDefinition
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.comment = mdoc.tpl_comment
- end
- return tpl
- end
-
- redef fun tpl_css_classes do return ["public"]
end
redef class MGroup
end
return tpl
end
-
- redef fun tpl_definition do
- var tpl = new TplDefinition
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.comment = mdoc.tpl_comment
- end
- return tpl
- end
end
redef class MModule
tpl.add html_link
return tpl
end
-
- redef fun tpl_definition do
- var tpl = new TplClassDefinition
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.comment = mdoc.tpl_comment
- end
- return tpl
- end
-
- redef fun tpl_css_classes do return ["public"]
end
redef class MClass
# Returns `intro.html_signature`.
fun html_signature: Template do return intro.html_signature
-
- redef fun tpl_definition do return intro.tpl_definition
-
- redef fun tpl_title do
- var title = new Template
- title.add tpl_icon
- title.add html_link
- return title
- end
-
- redef fun tpl_icon do return intro.tpl_icon
- redef fun tpl_css_classes do return intro.tpl_css_classes
end
redef class MClassDef
end
return tpl
end
-
- redef fun tpl_article do
- var tpl = new TplArticle(nitdoc_id)
- tpl.summary_title = "in {mmodule.html_name}"
- tpl.title = html_declaration
- tpl.title_classes.add "signature"
- var title = new Template
- title.add "in "
- title.add mmodule.html_namespace
- tpl.subtitle = title
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.content = mdoc.tpl_comment
- end
- return tpl
- end
-
- redef fun tpl_title do
- var title = new Template
- title.add tpl_icon
- title.add html_link
- return title
- end
-
- redef fun tpl_definition do
- var tpl = new TplClassDefinition
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.comment = mdoc.tpl_comment
- end
- return tpl
- end
-
- redef fun tpl_css_classes do
- var set = new HashSet[String]
- if is_intro then set.add "intro"
- for m in mclass.intro.modifiers do set.add m.to_cmangle
- for m in modifiers do set.add m.to_cmangle
- return set.to_a
- end
-
- fun tpl_modifiers: Template do
- var tpl = new Template
- for modifier in modifiers do
- if modifier == "public" then continue
- tpl.add "{modifier.html_escape} "
- end
- return tpl
- end
end
redef class MProperty
# Returns `intro.html_signature`.
fun html_signature: Template do return intro.html_signature
-
- redef fun tpl_title do return intro.tpl_title
-
- redef fun tpl_icon do return intro.tpl_icon
-
- redef fun tpl_css_classes do return intro.tpl_css_classes
end
redef class MPropDef
# Returns the MPropDef signature with static types.
fun html_signature: Template is abstract
-
- redef fun tpl_article do
- var tpl = new TplArticle(nitdoc_id)
- tpl.summary_title = "in {mclassdef.html_name}"
- var title = new Template
- title.add "in "
- title.add mclassdef.html_link
- tpl.title = title
- tpl.subtitle = html_declaration
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.content = mdoc.tpl_comment
- end
- return tpl
- end
-
- redef fun tpl_definition do
- var tpl = new TplDefinition
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.comment = mdoc.tpl_comment
- end
- return tpl
- end
-
- redef fun tpl_css_classes do
- var set = new HashSet[String]
- if is_intro then set.add "intro"
- for m in mproperty.intro.modifiers do set.add m.to_cmangle
- for m in modifiers do set.add m.to_cmangle
- return set.to_a
- end
-
- fun tpl_modifiers: Template do
- var tpl = new Template
- for modifier in modifiers do
- if modifier == "public" then continue
- tpl.add "{modifier.html_escape} "
- end
- return tpl
- end
-
- redef fun tpl_list_item do
- var lnk = new Template
- lnk.add new TplLabel.with_classes(tpl_css_classes.to_a)
- var atext = html_link.text
- var ahref = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
- var atitle = html_link.title
- var anchor = new Link.with_title(ahref, atext, atitle)
- lnk.add anchor
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- lnk.add ": "
- lnk.add mdoc.tpl_short_comment
- end
- return new TplListItem.with_content(lnk)
- end
-
- fun tpl_inheritance_item: TplListItem do
- var lnk = new Template
- lnk.add new TplLabel.with_classes(tpl_css_classes.to_a)
- lnk.add mclassdef.mmodule.html_namespace
- lnk.add "::"
- var atext = mclassdef.html_link.text
- var ahref = "{mclassdef.mclass.nitdoc_url}#{mproperty.nitdoc_id}"
- var atitle = mclassdef.html_link.title
- var anchor = new Link.with_title(ahref, atext, atitle)
- lnk.add anchor
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- lnk.add ": "
- lnk.add mdoc.tpl_short_comment
- end
- var li = new TplListItem.with_content(lnk)
- li.css_classes.add "signature"
- return li
- end
end
redef class MAttributeDef
end
end
-redef class ConcernsTree
-
- private var seen = new HashSet[MConcern]
-
- redef fun add(p, e) do
- if seen.has(e) then return
- seen.add e
- super(p, e)
- end
-
- fun to_tpl: TplList do
- var lst = new TplList.with_classes(["list-unstyled", "list-definition"])
- for r in roots do
- var li = r.tpl_concern_item
- lst.add_li li
- build_list(r, li)
- end
- return lst
- end
-
- private fun build_list(e: MConcern, li: TplListItem) do
- if not sub.has_key(e) then return
- var subs = sub[e]
- var lst = new TplList.with_classes(["list-unstyled", "list-definition"])
- for e2 in subs do
- if e2 isa MGroup and e2.is_root then
- build_list(e2, li)
- else
- var sli = e2.tpl_concern_item
- lst.add_li sli
- build_list(e2, sli)
- end
- end
- li.append lst
- end
-end
-
-
################################################################################
# Additions to `model_ext`.
redef fun html_link_to_anchor do return inner.html_link_to_anchor
redef fun html_link do return inner.html_link
redef fun html_signature do return inner.html_signature
-
- redef fun tpl_definition do
- var tpl = new TplClassDefinition
- var mdoc = mdoc_or_fallback
- if mdoc != null then
- tpl.comment = mdoc.tpl_comment
- end
- return tpl
- end
end
addn "</nav>"
end
end
+
+redef class DocComposite
+ super Template
+
+ # HTML anchor id
+ var html_id: String is noinit
+
+ # Title to display if any.
+ #
+ # This title can be decorated with HTML.
+ var html_title: nullable Writable is noinit, writable
+
+ # Subtitle to display if any.
+ var html_subtitle: nullable Writable is noinit, writable
+
+ # Render the element title and subtitle.
+ private fun render_title do
+ if html_title != null then
+ addn new Header(hlvl, html_title.write_to_string)
+ end
+ if html_subtitle != null then
+ addn "<div class='info subtitle'>"
+ addn html_subtitle.write_to_string
+ addn "</div>"
+ end
+ end
+
+ # Render the element body.
+ private fun render_body do end
+
+ redef fun rendering do
+ if is_hidden then return
+ render_title
+ render_body
+ end
+
+ # Level <hX> for HTML heading.
+ private fun hlvl: Int do
+ if parent == null then return 1
+ return parent.hlvl + 1
+ end
+
+ # Is `self` not displayed in the page.
+ #
+ # By default, empty elements are hidden.
+ fun is_hidden: Bool do return is_empty
+end
+
+redef class DocSection
+ super BSComponent
+
+ redef fun rendering do
+ if is_hidden then
+ addn "<a id=\"{html_id}\"></a>"
+ return
+ end
+ render_body
+ end
+end
+
+redef class DocArticle
+ super BSComponent
+
+ # Never displays the title for article.
+ #
+ # This is to maintain compatibility with old components, this may change
+ # without notice in further version.
+ redef fun render_title do end
+end
import modelize
redef class ToolContext
+ # Compute MENDEL metrics.
+ #
+ # See `mendel_metrics` module documentation.
var mendel_metrics_phase: Phase = new MendelMetricsPhase(self, null)
end
metrics.collect(mclasses)
if csv then metrics.to_csv.save("{out}/mendel.csv")
- print toolcontext.format_h4("\tlarge mclasses (threshold: {cnblp.threshold})")
- for mclass in cnblp.above_threshold do
- print toolcontext.format_p("\t {mclass.name}: {cnblp.values[mclass]}")
+ var threshold = cnblp.threshold
+ print toolcontext.format_h4("\tlarge mclasses (threshold: {threshold})")
+ for mclass in cnblp.sort do
+ var val = cnblp.values[mclass]
+ if val.to_f < threshold then break
+ print toolcontext.format_p("\t {mclass.name}: {val}")
end
- print toolcontext.format_h4("\tbudding mclasses (threshold: {cnvi.threshold})")
- for mclass in cnvi.above_threshold do
- print toolcontext.format_p("\t {mclass.name}: {cnvi.values[mclass]}")
+ threshold = cnvi.threshold
+ print toolcontext.format_h4("\tbudding mclasses (threshold: {threshold})")
+ for mclass in cnvi.sort do
+ var val = cnvi.values[mclass]
+ if val.to_f < threshold then break
+ print toolcontext.format_p("\t {mclass.name}: {val}")
end
- print toolcontext.format_h4("\tblooming mclasses (threshold: {cnvs.threshold})")
- for mclass in cnvs.above_threshold do
- print toolcontext.format_p("\t {mclass.name}: {cnvs.values[mclass]}")
- end
-
- print toolcontext.format_h4("\tblooming mclasses (threshold: {cnvs.threshold})")
- for mclass in cnvs.above_threshold do
- print toolcontext.format_p("\t {mclass.name}: {cnvs.values[mclass]}")
+ threshold = cnvs.threshold
+ print toolcontext.format_h4("\tblooming mclasses (threshold: {threshold})")
+ for mclass in cnvs.sort do
+ var val = cnvs.values[mclass]
+ if val.to_f < threshold then break
+ print toolcontext.format_p("\t {mclass.name}: {val}")
end
if csv then
redef fun name do return "cbms"
redef fun desc do return "branch mean size, mean number of introduction available among ancestors"
+ # Mainmodule used to compute class hierarchy.
var mainmodule: MModule
- init(mainmodule: MModule) do self.mainmodule = mainmodule
redef fun collect(mclasses) do
for mclass in mclasses do
redef fun name do return "cnvi"
redef fun desc do return "class novelty index, contribution of the class to its branch in term of introductions"
+ # Mainmodule used to compute class hierarchy.
var mainmodule: MModule
- init(mainmodule: MModule) do self.mainmodule = mainmodule
redef fun collect(mclasses) do
var cbms = new CBMS(mainmodule)
redef fun name do return "cnvs"
redef fun desc do return "class novelty score, importance of the contribution of the class to its branch"
+ # Mainmodule used to compute class hierarchy.
var mainmodule: MModule
- init(mainmodule: MModule) do self.mainmodule = mainmodule
redef fun collect(mclasses) do
var cnvi = new CNVI(mainmodule)
var opt_generate_hyperdoc = new OptionBool("Generate Hyperdoc", "--generate_hyperdoc")
# --poset
var opt_poset = new OptionBool("Complete metrics on posets", "--poset")
-
# --no-colors
var opt_nocolors = new OptionBool("Disable colors in console outputs", "--no-colors")
-
-
+ # --dir
var opt_dir = new OptionString("Directory where some statistics files are generated", "-d", "--dir")
+
+ # Output directory for metrics files.
var output_dir: String = "."
redef init
end
end
- # colorize heading 1 for console output
+ # Format and colorize a string heading of level 1 for console output.
+ #
+ # Default style is yellow and bold.
fun format_h1(str: String): String do
if opt_nocolors.value then return str
return str.yellow.bold
end
+ # Format and colorize a string heading of level 2 for console output.
+ #
+ # Default style is white and bold.
fun format_h2(str: String): String do
if opt_nocolors.value then return str
return str.bold
end
+ # Format and colorize a string heading of level 3 for console output.
+ #
+ # Default style is white and nobold.
fun format_h3(str: String): String do
if opt_nocolors.value then return str
return str
end
+ # Format and colorize a string heading of level 4 for console output.
+ #
+ # Default style is green.
fun format_h4(str: String): String do
if opt_nocolors.value then return str
return str.green
end
+ # Format and colorize a string heading of level 5 for console output.
+ #
+ # Default style is light gray.
fun format_p(str: String): String do
if opt_nocolors.value then return str
return str.light_gray
#
# The concept is reified here for a better organization and documentation
interface Metric
+
+ # Type of elements measured by this metric.
type ELM: Object
+
+ # Type of values used to measure elements.
type VAL: Object
+
+ # Type of data representation used to associate elements and values.
type RES: Map[ELM, VAL]
+ # The name of this metric (generally an acronym about the metric).
fun name: String is abstract
+
+ # A long and understandable description about what is measured by this metric.
fun desc: String is abstract
# Clear all results for this metric
end
end
+ # The sum of all the values.
+ fun sum: VAL is abstract
+
# The values standard derivation
fun std_dev: Float is abstract
# The set of element above the threshold
fun above_threshold: Set[ELM] is abstract
+
+ # Sort the metric keys by values
+ fun sort: Array[ELM] do
+ return values.keys_sorted_by_values(default_reverse_comparator)
+ end
end
# A Metric that collects integer data
redef type VAL: Int
redef type RES: Counter[ELM]
+ # `IntMetric` uses a Counter to store values in intern.
protected var values_cache = new Counter[ELM]
+
redef fun values do return values_cache
redef fun clear do values_cache.clear
- fun sum: Int do return values_cache.sum
+ redef fun sum do return values_cache.sum
redef fun max do
assert not values_cache.is_empty
end
# Values average
- redef fun avg: Float do return values_cache.avg
+ redef fun avg do return values_cache.avg
- redef fun std_dev: Float do return values_cache.std_dev
+ redef fun std_dev do return values_cache.std_dev
redef fun above_threshold do
var above = new HashSet[ELM]
redef type VAL: Float
+ # `FloatMetric` uses a Map to store values in intern.
protected var values_cache = new HashMap[ELM, VAL]
+
redef fun values do return values_cache
redef fun clear do values_cache.clear
- fun sum: Float do
+
+ redef fun sum do
var sum = 0.0
for v in values.values do sum += v
return sum
return sum / values.length.to_f
end
- redef fun std_dev: Float do
+ redef fun std_dev do
var sum = 0.0
for value in values.values do
sum += (value - avg).pow(2.to_f)
print "{"\t" * indent} sum: {sum}"
end
end
-
end
# A MetricSet is a metric holder
#
# It purpose is to be extended with a metric collect service
class MetricSet
+
+ # Type of element measured by this `MetricSet`.
type ELM: Object
# Metrics to compute
model.mmodule_importation_hierarchy.sort(mmodules)
var nmodules = new Array[AModule]
for mm in mmodules do
+ if mm.is_fictive then continue
nmodules.add(mmodule2node(mm).as(not null))
end
toolcontext.run_phases(nmodules)
# Registration of the nclassdef associated to each mclassdef
private var mclassdef2nclassdef = new HashMap[MClassDef, AClassdef]
+
+ # Retrieve the associated AST node of a mclassdef.
+ #
+ # This method is used to associate model entity with syntactic entities.
+ # If the class definition is not associated with a node, returns `null`.
+ fun mclassdef2node(mclassdef: MClassDef): nullable AClassdef do
+ return mclassdef2nclassdef.get_or_null(mclassdef)
+ end
end
redef class AModule
if vararg_rank >= 0 then
var paramtype = msignature.mparameters[vararg_rank].mtype
var first = args[vararg_rank]
- if vararg_decl == 0 and first isa AVarargExpr then
+ if vararg_decl == 0 then
var mclass = get_mclass(node, "Array")
if mclass == null then return null # Forward error
var array_mtype = mclass.get_mtype([paramtype])
- self.visit_expr_subtype(first.n_expr, array_mtype)
- first.mtype = first.n_expr.mtype
+ if first isa AVarargExpr then
+ self.visit_expr_subtype(first.n_expr, array_mtype)
+ first.mtype = first.n_expr.mtype
+ else
+ # only one vararg, maybe `...` was forgot, so be gentle!
+ var t = visit_expr(first)
+ if t == null then return null # Forward error
+ if not is_subtype(t, paramtype) and is_subtype(t, array_mtype) then
+ # Not acceptable but could be a `...`
+ error(first, "Type Error: expected `{paramtype}`, got `{t}`. Is an ellipsis `...` missing on the argument?")
+ return null
+ end
+ # Standard valid vararg, finish the job
+ map.vararg_decl = 1
+ self.visit_expr_subtype(first, paramtype)
+ end
else
map.vararg_decl = vararg_decl + 1
for i in [vararg_rank..vararg_rank+vararg_decl] do
-alt/base_vararg3_alt1.nit:41,7--13: Type Error: expected `Int`, got `Array[Int]`.
+alt/base_vararg3_alt1.nit:41,7--13: Type Error: expected `Int`, got `Array[Int]`. Is an ellipsis `...` missing on the argument?
-alt/base_vararg3_alt3.nit:33,9: Type Error: expected `Int`, got `Array[Int]`.
+alt/base_vararg3_alt3.nit:33,9: Type Error: expected `Int`, got `Array[Int]`. Is an ellipsis `...` missing on the argument?
Sys: 4.0
blooming mclasses (threshold: 12.0)
Sys: 16.0
- blooming mclasses (threshold: 12.0)
- Sys: 16.0
--- Detection of the usage of covariance static type conformance ---
-- Total --
- Kinds of the subtype -