1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Helpers for various statistics tools.
24 redef class ToolContext
27 var opt_all
= new OptionBool("Compute all metrics", "--all")
30 var opt_inheritance
= new OptionBool("Compute metrics about inheritance usage", "--inheritance")
32 var opt_refinement
= new OptionBool("Compute metrics about refinement usage", "--refinement")
34 var opt_self
= new OptionBool("Compute metrics about the usage of explicit and implicit self", "--self")
36 var opt_nullables
= new OptionBool("Compute metrics on nullables send", "--nullables")
38 var opt_static_types
= new OptionBool("Compute explicit static types metrics", "--static-types")
40 var opt_tables
= new OptionBool("Compute tables metrics", "--tables")
42 var opt_rta
= new OptionBool("Compute RTA metrics", "--rta")
44 var opt_generate_csv
= new OptionBool("Generate CVS format metrics", "--generate-csv")
46 var opt_generate_hyperdoc
= new OptionBool("Generate Hyperdoc", "--generate_hyperdoc")
48 var opt_poset
= new OptionBool("Complete metrics on posets", "--poset")
50 var opt_dir
= new OptionString("Directory where some statistics files are generated", "-d", "--dir")
51 var output_dir
: String = "."
56 self.option_context
.add_option
(opt_all
)
57 self.option_context
.add_option
(opt_inheritance
)
58 self.option_context
.add_option
(opt_refinement
)
59 self.option_context
.add_option
(opt_self
)
60 self.option_context
.add_option
(opt_nullables
)
61 self.option_context
.add_option
(opt_static_types
)
62 self.option_context
.add_option
(opt_tables
)
63 self.option_context
.add_option
(opt_rta
)
64 self.option_context
.add_option
(opt_generate_csv
)
65 self.option_context
.add_option
(opt_generate_hyperdoc
)
66 self.option_context
.add_option
(opt_poset
)
67 self.option_context
.add_option
(opt_dir
)
70 redef fun process_options
73 var val
= self.opt_dir
.value
75 val
= val
.simplify_path
84 # List of modules in std lib
85 # FIXME this is quite ugly, find a dynamic way...
86 fun std_modules
: Set[String] do
87 if self.std_modules_cache
== null then
88 self.std_modules_cache
= new HashSet[String]
89 self.std_modules_cache
.add
("collection")
90 self.std_modules_cache
.add
("abstract_collection")
91 self.std_modules_cache
.add
("array")
92 self.std_modules_cache
.add
("hash_collection")
93 self.std_modules_cache
.add
("list")
94 self.std_modules_cache
.add
("range")
95 self.std_modules_cache
.add
("sorter")
96 self.std_modules_cache
.add
("environ")
97 self.std_modules_cache
.add
("exec")
98 self.std_modules_cache
.add
("file")
99 self.std_modules_cache
.add
("gc")
100 self.std_modules_cache
.add
("hash")
101 self.std_modules_cache
.add
("kernel")
102 self.std_modules_cache
.add
("math")
103 self.std_modules_cache
.add
("standard")
104 self.std_modules_cache
.add
("stream")
105 self.std_modules_cache
.add
("string")
106 self.std_modules_cache
.add
("string_search")
107 self.std_modules_cache
.add
("time")
109 return self.std_modules_cache
.as(not null)
111 private var std_modules_cache
: nullable Set[String]
115 fun is_class
: Bool do
116 return self.kind
== concrete_kind
or self.kind
== abstract_kind
119 fun is_interface
: Bool do
120 return self.kind
== interface_kind
124 return self.kind
== enum_kind
127 fun is_abstract
: Bool do
128 return self.kind
== abstract_kind
131 fun is_user_defined
: Bool do
132 return self.intro_mmodule
.is_user_defined
137 fun is_user_defined
: Bool do
138 return not self.model
.std_modules
.has
(self.name
)