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.mmodules.length} modules"
35 var mclasses
= mainmodule
.flatten_mclass_hierarchy
36 print
"I have also {mclasses.length} classes"
39 for m
in mainmodule
.in_importation
.greaters
do
40 for cd
in m
.mclassdefs
do
41 for pd
in cd
.mpropdefs
do
42 if pd
isa MMethodDef then meth_cpt
+= 1
46 print
"And {meth_cpt} definitions of methods"