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.
14 # This module redef Mclassdef to add new collect methods.
16 module mclassdef_collect
18 # We usualy need specific phases
19 # NOTE: `frontend` is sufficent in most case (it is often too much)
25 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
26 fun collect_intro_mproperties
(view
: ModelView): Set[MProperty] do
27 var set
= new HashSet[MProperty]
28 for mprop
in self.intro_mproperties
do
29 if not view
.accept_mentity
(mprop
) then continue
35 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
36 fun collect_intro_mmethods
(view
: ModelView): Set[MMethod] do
37 var res
= new HashSet[MMethod]
38 for mproperty
in collect_intro_mproperties
(view
) do
39 if not view
.accept_mentity
(mproperty
) then continue
40 if mproperty
isa MMethod then res
.add
(mproperty
)
45 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
46 fun collect_redef_mmethods
(view
: ModelView): Set[MMethod] do
47 var res
= new HashSet[MMethod]
48 for mproperty
in collect_redef_mproperties
(view
) do
49 if not view
.accept_mentity
(mproperty
) then continue
50 if mproperty
isa MMethod then res
.add
(mproperty
)
55 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
56 fun collect_redef_mattributes
(view
: ModelView): Set[MAttribute] do
57 var res
= new HashSet[MAttribute]
58 for mproperty
in collect_redef_mproperties
(view
) do
59 if not view
.accept_mentity
(mproperty
) then continue
60 if mproperty
isa MAttribute then res
.add
(mproperty
)
65 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
66 fun collect_intro_mattributes
(view
: ModelView): Set[MAttribute] do
67 var res
= new HashSet[MAttribute]
68 for mproperty
in collect_intro_mproperties
(view
) do
69 if not view
.accept_mentity
(mproperty
) then continue
70 if mproperty
isa MAttribute then res
.add
(mproperty
)
75 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
76 fun collect_redef_mproperties
(view
: ModelView): Set[MProperty] do
77 var set
= new HashSet[MProperty]
78 for mpropdef
in self.mpropdefs
do
79 if not view
.accept_mentity
(mpropdef
) then continue
80 if mpropdef
.mproperty
.intro_mclassdef
.mclass
== self then continue
81 set
.add
(mpropdef
.mproperty
)
86 # Collect mmethods inherited by 'self' if accepted by `view`.
87 fun collect_inherited_mmethods
(view
: ModelView): Set[MMethod] do
88 var res
= new HashSet[MMethod]
89 for mproperty
in collect_inherited_mproperties
(view
) do
90 if not view
.accept_mentity
(mproperty
) then continue
91 if mproperty
isa MMethod then res
.add
(mproperty
)
96 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
97 fun collect_local_mproperties
(view
: ModelView): Set[MProperty] do
98 var set
= new HashSet[MProperty]
99 set
.add_all collect_intro_mproperties
(view
)
100 set
.add_all collect_redef_mproperties
(view
)
104 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
105 fun collect_inherited_mproperties
(view
: ModelView): Set[MProperty] do
106 var set
= new HashSet[MProperty]
107 for parent
in collect_parents
(view
) do
108 set
.add_all
(parent
.collect_intro_mproperties
(view
))
109 set
.add_all
(parent
.collect_inherited_mproperties
(view
))
114 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
115 fun collect_inherited_mattributes
(view
: ModelView): Set[MAttribute] do
116 var res
= new HashSet[MAttribute]
117 for mproperty
in collect_inherited_mproperties
(view
) do
118 if not view
.accept_mentity
(mproperty
) then continue
119 if mproperty
isa MAttribute then res
.add
(mproperty
)
124 # Collect all mmethod inehrited,intro and redef
125 fun collect_all_methods
(view
: ModelView): Set[MMethod] do
126 var set
= new HashSet[MMethod]
127 set
.add_all collect_intro_mmethods
(view
)
128 set
.add_all collect_redef_mmethods
(view
)
129 set
.add_all collect_inherited_mmethods
(view
)
133 # Collect all mattributs inehrited,intro and redef
134 fun collect_all_mattributes
(view
: ModelView): Set[MAttribute] do
135 var set
= new HashSet[MAttribute]
136 set
.add_all collect_redef_mattributes
(view
)
137 set
.add_all collect_intro_mattributes
(view
)
138 set
.add_all collect_inherited_mattributes
(view
)
142 # Collect intro and redef mmethods
143 fun collect_intro_and_redef_methods
(view
: ModelView): Set[MMethod] do
144 var set
= new HashSet[MMethod]
145 set
.add_all collect_intro_mmethods
(view
)
146 set
.add_all collect_redef_mmethods
(view
)
150 # Collect intro and redef mattributs
151 fun collect_intro_and_redef_mattributes
(view
: ModelView): Set[MAttribute] do
152 var set
= new HashSet[MAttribute]
153 set
.add_all collect_redef_mattributes
(view
)
154 set
.add_all collect_intro_mattributes
(view
)
158 # Collect intro and redef mpropdefs
159 fun collect_intro_and_redef_mpropdefs
(view
: ModelView): Set[MPropDef] do
160 var set
= new HashSet[MPropDef]
161 set
.add_all collect_intro_mpropdefs
(view
)
162 set
.add_all collect_redef_mpropdefs
(view
)
166 # Collect intro abstract mmethodDef
167 fun collect_abstract_methods
(view
: ModelView): Set[MMethodDef] do
168 var set
= new HashSet[MMethodDef]
169 var mpropdefs
= collect_intro_mpropdefs
(view
)
170 for mpropdef
in mpropdefs
do
171 if mpropdef
isa MMethodDef then
172 if mpropdef
.is_abstract
then set
.add
(mpropdef
)
178 # Collect not defined properties
179 fun collect_not_define_properties
(view
: ModelView):Set[MMethodDef] do
180 var set
= new HashSet[MMethodDef]
181 for mpropdef
in collect_abstract_methods
(view
) do
183 for mprop
in mpropdef
.mproperty
.mpropdefs
do
184 if mprop
.is_abstract
then continue
187 if redef_count
== 0 then set
.add
(mpropdef
)