1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Example of simple module that aims to do some specific work on nit programs.
17 # Fast prototypes can just start with this skeletton.
18 module test_test_phase
20 # We need the framework that perfoms standard code for the main-program
23 # We usualy need specific phases
24 # NOTE: `frontend` is sufficent in most case (it is often too much)
27 # The body of the specific work.
28 # The main entry point is provided by `test_phase`,
29 # This function is then automatically (unless errors where found).
30 redef fun do_work
(mainmodule
, given_mmodules
, modelbuilder
)
33 var model
= modelbuilder
.model
34 print
"I have {model.mprojects.length} projects"
35 print
"I have {model.mmodules.length} modules"
36 var mclasses
= mainmodule
.flatten_mclass_hierarchy
37 print
"I have {mclasses.length} classes"
42 for m
in mainmodule
.in_importation
.greaters
do
43 for cd
in m
.mclassdefs
do
45 for pd
in cd
.mpropdefs
do
46 if pd
isa MMethodDef then
48 if pd
.is_intro
then m_cpt
+= 1
53 print
"For {cd_cpt} definitions of classes"
54 print
"I have {m_cpt} methods"
55 print
"For {md_cpt} definitions of methods"