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.
15 # Preprocessing of input files
24 # Options for the C preprocessor
25 var opt_gcc_options
= new OptionString("C Preprocessor options to add to `gcc -E file`", "-p")
29 # Read file at `self` and preprocess its content through `gcc -E`, `header_keeper` and `header_static`
30 fun preprocess_content
: String
34 # GCC C preprocessor, to apply macros and includes
35 var gcc_opts
= opt_gcc_options
.value
or else ""
36 var cmd
= "gcc -E {path} {gcc_opts}"
37 var gcc_proc
= new ProcessReader("sh", "-c", cmd
)
39 # header_keeper, to keep only the target file (path)
40 var o
= new StringWriter
41 header_keeper
(gcc_proc
, o
, path
)
44 if gcc_proc
.status
!= 0 then
45 print_error
"Fatal Error: call to gcc failed, the command was: {cmd}"
49 # header_static, strip lines unsupported by our parser
50 var i
= new StringReader(o
.to_s
)