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)
24 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
25 fun collect_intro_mproperties
(filter
: ModelFilter): Set[MProperty] do
26 var set
= new HashSet[MProperty]
27 for mprop
in self.intro_mproperties
do
28 if not filter
.accept_mentity
(mprop
) then continue
34 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
35 fun collect_intro_mmethods
(filter
: ModelFilter): Set[MMethod] do
36 var res
= new HashSet[MMethod]
37 for mproperty
in collect_intro_mproperties
(filter
) do
38 if not filter
.accept_mentity
(mproperty
) then continue
39 if mproperty
isa MMethod then res
.add
(mproperty
)
44 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
45 fun collect_redef_mmethods
(filter
: ModelFilter): Set[MMethod] do
46 var res
= new HashSet[MMethod]
47 for mproperty
in collect_redef_mproperties
(filter
) do
48 if not filter
.accept_mentity
(mproperty
) then continue
49 if mproperty
isa MMethod then res
.add
(mproperty
)
54 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
55 fun collect_redef_mattributes
(filter
: ModelFilter): Set[MAttribute] do
56 var res
= new HashSet[MAttribute]
57 for mproperty
in collect_redef_mproperties
(filter
) do
58 if not filter
.accept_mentity
(mproperty
) then continue
59 if mproperty
isa MAttribute then res
.add
(mproperty
)
64 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
65 fun collect_intro_mattributes
(filter
: ModelFilter): Set[MAttribute] do
66 var res
= new HashSet[MAttribute]
67 for mproperty
in collect_intro_mproperties
(filter
) do
68 if not filter
.accept_mentity
(mproperty
) then continue
69 if mproperty
isa MAttribute then res
.add
(mproperty
)
74 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
75 fun collect_redef_mproperties
(filter
: ModelFilter): Set[MProperty] do
76 var set
= new HashSet[MProperty]
77 for mpropdef
in self.mpropdefs
do
78 if not filter
.accept_mentity
(mpropdef
) then continue
79 if mpropdef
.mproperty
.intro_mclassdef
.mclass
== self then continue
80 set
.add
(mpropdef
.mproperty
)
85 # Collect mmethods inherited by 'self' if accepted by `filter`.
86 fun collect_inherited_mmethods
(mainmodule
: MModule, filter
: ModelFilter): Set[MMethod] do
87 var res
= new HashSet[MMethod]
88 for mproperty
in collect_inherited_mproperties
(mainmodule
, filter
) do
89 if not filter
.accept_mentity
(mproperty
) then continue
90 if mproperty
isa MMethod then res
.add
(mproperty
)
95 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
96 fun collect_local_mproperties
(filter
: ModelFilter): Set[MProperty] do
97 var set
= new HashSet[MProperty]
98 set
.add_all collect_intro_mproperties
(filter
)
99 set
.add_all collect_redef_mproperties
(filter
)
103 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
104 fun collect_inherited_mproperties
(mainmodule
: MModule, filter
: ModelFilter): Set[MProperty] do
105 var set
= new HashSet[MProperty]
106 for parent
in collect_parents
(mainmodule
, filter
) do
107 set
.add_all
(parent
.collect_intro_mproperties
(filter
))
108 set
.add_all
(parent
.collect_inherited_mproperties
(mainmodule
, filter
))
113 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
114 fun collect_inherited_mattributes
(mainmodule
: MModule, filter
: ModelFilter): Set[MAttribute] do
115 var res
= new HashSet[MAttribute]
116 for mproperty
in collect_inherited_mproperties
(mainmodule
, filter
) do
117 if not filter
.accept_mentity
(mproperty
) then continue
118 if mproperty
isa MAttribute then res
.add
(mproperty
)
123 # Collect all mmethod inehrited,intro and redef
124 fun collect_all_methods
(mainmodule
: MModule, filter
: ModelFilter): Set[MMethod] do
125 var set
= new HashSet[MMethod]
126 set
.add_all collect_intro_mmethods
(filter
)
127 set
.add_all collect_redef_mmethods
(filter
)
128 set
.add_all collect_inherited_mmethods
(mainmodule
, filter
)
132 # Collect all mattributs inehrited,intro and redef
133 fun collect_all_mattributes
(mainmodule
: MModule, filter
: ModelFilter): Set[MAttribute] do
134 var set
= new HashSet[MAttribute]
135 set
.add_all collect_redef_mattributes
(filter
)
136 set
.add_all collect_intro_mattributes
(filter
)
137 set
.add_all collect_inherited_mattributes
(mainmodule
, filter
)
141 # Collect intro and redef mmethods
142 fun collect_intro_and_redef_methods
(filter
: ModelFilter): Set[MMethod] do
143 var set
= new HashSet[MMethod]
144 set
.add_all collect_intro_mmethods
(filter
)
145 set
.add_all collect_redef_mmethods
(filter
)
149 # Collect intro and redef mattributs
150 fun collect_intro_and_redef_mattributes
(filter
: ModelFilter): Set[MAttribute] do
151 var set
= new HashSet[MAttribute]
152 set
.add_all collect_redef_mattributes
(filter
)
153 set
.add_all collect_intro_mattributes
(filter
)
157 # Collect intro and redef mpropdefs
158 fun collect_intro_and_redef_mpropdefs
(filter
: ModelFilter): Set[MPropDef] do
159 var set
= new HashSet[MPropDef]
160 set
.add_all collect_intro_mpropdefs
(filter
)
161 set
.add_all collect_redef_mpropdefs
(filter
)
165 # Collect intro abstract mmethodDef
166 fun collect_abstract_methods
(filter
: ModelFilter): Set[MMethodDef] do
167 var set
= new HashSet[MMethodDef]
168 var mpropdefs
= collect_intro_mpropdefs
(filter
)
169 for mpropdef
in mpropdefs
do
170 if mpropdef
isa MMethodDef then
171 if mpropdef
.is_abstract
then set
.add
(mpropdef
)
177 # Collect not defined properties
178 fun collect_not_define_properties
(filter
: ModelFilter):Set[MMethodDef] do
179 var set
= new HashSet[MMethodDef]
180 for mpropdef
in collect_abstract_methods
(filter
) do
182 for mprop
in mpropdef
.mproperty
.mpropdefs
do
183 if mprop
.is_abstract
then continue
186 if redef_count
== 0 then set
.add
(mpropdef
)