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 # Metrics on table generation
21 private import metrics_base
23 # Print class tables metrics for the classes of the program main
24 fun compute_tables_metrics
(main
: MModule)
26 var model
= main
.model
28 var nc
= 0 # Number of runtime classes
29 var nl
= 0 # Number of usages of class definitions (a class definition can be used more than once)
30 var nhp
= 0 # Number of usages of properties (a property can be used more than once)
31 var npas
= 0 # Number of usages of properties without lookup (easy easy case, easier that CHA)
33 # Collect the full class hierarchy
34 var hier
= main
.flatten_mclass_hierarchy
36 # Skip classes without direct instances
37 if c
.kind
== interface_kind
or c
.kind
== abstract_kind
then continue
41 # Now, we need to collect all properties defined/inherited/imported
42 # So, visit all definitions of all super-classes
43 for sup
in hier
[c
].greaters
do
44 for cd
in sup
.mclassdefs
do
47 # Now, search properties introduced
48 for p
in cd
.intro_mproperties
do
51 # Select property definition
52 if p
.mpropdefs
.length
== 1 then
55 var sels
= p
.lookup_definitions
(main
, c
.intro
.bound_mtype
)
56 if sels
.length
> 1 then
57 print
"conflict for {p.full_name} in class {c.full_name}: {sels.join(", ")}"
58 else if sels
.is_empty
then
59 print
"ERROR: no property for {p.full_name} in class {c.full_name}!"
67 print
"--- Construction of tables ---"
68 print
"Number of runtime classes: {nc} (excluding interfaces and abstract classes)"
69 print
"Average number of composing class definition by runtime class: {div(nl,nc)}"
70 print
"Total size of tables (classes and instances): {nhp} (not including stuff like info for subtyping or call-next-method)"
71 print
"Average size of table by runtime class: {div(nhp,nc)}"
72 print
"Values never redefined: {npas} ({div(npas*100,nhp)}%)"