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_ast
= new OptionBool("Compute metrics about the usage of nodes and identifiers in the AST", "--ast")
38 var opt_nullables
= new OptionBool("Compute metrics on nullables send", "--nullables")
40 var opt_static_types
= new OptionBool("Compute explicit static types metrics", "--static-types")
42 var opt_tables
= new OptionBool("Compute tables metrics", "--tables")
44 var opt_rta
= new OptionBool("Compute RTA metrics", "--rta")
46 var opt_generate_csv
= new OptionBool("Generate CVS format metrics", "--generate-csv")
48 var opt_generate_hyperdoc
= new OptionBool("Generate Hyperdoc", "--generate_hyperdoc")
50 var opt_poset
= new OptionBool("Complete metrics on posets", "--poset")
52 var opt_dir
= new OptionString("Directory where some statistics files are generated", "-d", "--dir")
53 var output_dir
: String = "."
58 self.option_context
.add_option
(opt_all
)
59 self.option_context
.add_option
(opt_inheritance
)
60 self.option_context
.add_option
(opt_refinement
)
61 self.option_context
.add_option
(opt_self
)
62 self.option_context
.add_option
(opt_ast
)
63 self.option_context
.add_option
(opt_nullables
)
64 self.option_context
.add_option
(opt_static_types
)
65 self.option_context
.add_option
(opt_tables
)
66 self.option_context
.add_option
(opt_rta
)
67 self.option_context
.add_option
(opt_generate_csv
)
68 self.option_context
.add_option
(opt_generate_hyperdoc
)
69 self.option_context
.add_option
(opt_poset
)
70 self.option_context
.add_option
(opt_dir
)
73 redef fun process_options
76 var val
= self.opt_dir
.value
78 val
= val
.simplify_path
87 # List of modules in std lib
88 # FIXME this is quite ugly, find a dynamic way...
89 fun std_modules
: Set[String] do
90 if self.std_modules_cache
== null then
91 self.std_modules_cache
= new HashSet[String]
92 self.std_modules_cache
.add
("collection")
93 self.std_modules_cache
.add
("abstract_collection")
94 self.std_modules_cache
.add
("array")
95 self.std_modules_cache
.add
("hash_collection")
96 self.std_modules_cache
.add
("list")
97 self.std_modules_cache
.add
("range")
98 self.std_modules_cache
.add
("sorter")
99 self.std_modules_cache
.add
("environ")
100 self.std_modules_cache
.add
("exec")
101 self.std_modules_cache
.add
("file")
102 self.std_modules_cache
.add
("gc")
103 self.std_modules_cache
.add
("hash")
104 self.std_modules_cache
.add
("kernel")
105 self.std_modules_cache
.add
("math")
106 self.std_modules_cache
.add
("standard")
107 self.std_modules_cache
.add
("stream")
108 self.std_modules_cache
.add
("string")
109 self.std_modules_cache
.add
("string_search")
110 self.std_modules_cache
.add
("time")
112 return self.std_modules_cache
.as(not null)
114 private var std_modules_cache
: nullable Set[String]
118 fun is_user_defined
: Bool do
119 return self.intro_mmodule
.is_user_defined
124 fun is_user_defined
: Bool do
125 return not self.model
.std_modules
.has
(self.name
)