1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012-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.
19 import native_interface
20 import syntax
# TODO move extern_implementation to MM
24 fun accept_ffi_visitor
( v
: FFIVisitor ) do end
27 redef class ExternCode
30 # last resort for extern method
31 # assumes this is a code block in the root of a module
32 # should never be called if the extern method is implemented inline by a known language
33 redef fun accept_ffi_visitor
( v
)
35 var language
= self.language
36 if language
!= null then
37 v
.tc
.warning
( null, "language \"{language}\
" used to implement a code block in {v.mmmodule} is unknown." )
39 v
.tc
.warning
( null, "please specify a language to implement code blocks in {v.mmmodule}." ) # is ok with spec as of now, won't be raised
43 var language_lowered
: nullable String = null
45 redef init ( language
, code
, loc
)
48 if language
!= null then language_lowered
= language
.to_lower
55 # last resort for extern method
56 # should never be called if the extern method is implemented inline by a known language
57 redef fun accept_ffi_visitor
( v
)
59 if extern_implementation
!= null then
60 var language
= extern_implementation
.language
61 if language
!= null then
62 v
.tc
.warning
( null, "language \"{language}\
" used to implement {full_name} is unknown." )
64 v
.tc
.warning
( null, "please specify a language to implement {full_name}." ) # is ok with spec as of now, won't be raised
70 # set of extern imports in a language to be used by a module
71 # FIXME move to native_interface or MM?
73 # set of imported functions, cached to avoid repetitions
74 var callbacks
: Set[ MMExplicitImport ] = new HashSet[ MMExplicitImport ]
76 # set of imported functions, cached to avoid repetitions
77 var supers
: Set[ MMExplicitImport ] = new HashSet[ MMExplicitImport ]
79 # set of relevant types, cached to avoid repetitions
80 var types
: Set[ MMType ] = new HashSet[ MMType ]
82 # set of imported casts and as, cached to avoid repetitions
83 var casts
: Set[ MMImportedCast ] = new HashSet[ MMImportedCast ]
86 redef class MMLocalClass
89 fun c_type
: nullable String do return null
95 redef fun accept_ffi_visitor
( v
)
97 for local_class
in local_classes
do
98 # if class is extern and defined here first
99 if local_class
.global
.intro
== local_class
and
100 local_class
.global
.is_extern
then
101 local_class
.accept_ffi_visitor
( v
)
104 for prop
in local_class
.local_local_properties
do
105 # if defined of redefined in this module and is extern
106 if prop
.mmmodule
== self and prop
isa MMMethod and prop
.is_extern
and
107 prop
.extern_implementation
!= null then
108 prop
.accept_ffi_visitor
( v
)
114 for block
in extern_code_blocks
do block
.accept_ffi_visitor
( v
)
121 # module being visited
122 var mmmodule
: MMModule
124 var compilation_unit
= new CCompilationUnit