1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
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 # Tracks which modules has public header code that must be imported
19 module header_dependency
24 redef class ToolContext
25 var header_dependancy_phase
: Phase = new HeaderDependancyPhase(self, [ffi_language_assignation_phase
, modelize_class_phase
])
29 private fun has_public_c_header
: Bool do
30 for code_block
in n_extern_code_blocks
do if code_block
.is_c_header
then return true
36 # Modules with public foreign code blocks (C header)
37 var header_dependencies
: nullable HashSet[MModule] = null
39 private fun compute_header_dependencies
(v
: HeaderDependancyPhase)
41 if header_dependencies
!= null then return
43 var header_dependencies
= new HashSet[MModule]
45 # gather from importation
46 for m
in in_importation
.direct_greaters
do
47 m
.compute_header_dependencies v
49 # does the super module has inherited dependencies?
50 var hd
= m
.header_dependencies
52 if not hd
.is_empty
then
53 header_dependencies
.add_all hd
56 # does the super module itself has extern dependencies?
57 var amodule
= v
.toolcontext
.modelbuilder
.mmodule2node
(m
)
58 if amodule
!= null and amodule
.has_public_c_header
then header_dependencies
.add
(m
)
61 self.header_dependencies
= header_dependencies
65 private class HeaderDependancyPhase
68 redef fun process_nmodule
(nmodule
)
70 var mmodule
= nmodule
.mmodule
71 mmodule
.compute_header_dependencies
(self)