329d9a36e18f760b9451880c898578bf11dd54d5
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.
17 # Handles C inline code
18 # Wraps all code in a thin wrapper.
23 redef class ExternCode
24 fun is_c
: Bool do return language
== null or
25 language_lowered
== "c" or language_lowered
.has_prefix
( "c " )
27 fun is_c_body
: Bool do return language
== null or
28 language_lowered
== "c" or language_lowered
== "c body"
30 fun is_c_header
: Bool do return language_lowered
== "c header"
32 redef fun accept_ffi_visitor
( v
)
35 v
.compilation_unit
.header_custom
.add
( code
)
36 else if is_c_body
then
37 v
.compilation_unit
.body_custom
.add
( code
)
43 redef fun accept_ffi_visitor
( v
)
45 if extern_implementation
.is_c
then
46 var fc
= new CFunction( impl_csignature
)
47 fc
.decls
.add
( extern_implementation
.location
.as_line_pragma
)
48 fc
.exprs
.add
( extern_implementation
.code
)
49 v
.compilation_unit
.add_exported_function
( fc
)
57 fun as_line_pragma
: String
59 return "#line {line_start} \"{file.filename}\
"\n"