pub struct Preprocessor { /* private fields */ }Expand description
Translation phase 4 over one file.
Holds the macro table and the conditional stack, so a single instance processes a whole translation unit and the definitions a header makes are visible after it.
Implementations§
Source§impl Preprocessor
impl Preprocessor
Sourcepub fn new() -> Preprocessor
pub fn new() -> Preprocessor
A preprocessor with an empty macro table.
Sourcepub fn with_prefix_map(map: PrefixMap) -> Preprocessor
pub fn with_prefix_map(map: PrefixMap) -> Preprocessor
The same, with __FILE__ and __BASE_FILE__ rewritten by map.
Handed in at construction rather than set afterwards because it is fixed for the whole
translation unit: the command line cannot change its mind halfway through a file, and a
__FILE__ that answered differently at the top of a header than at the bottom would be a
worse bug than not having the flag.
Sourcepub fn macros(&self) -> &MacroTable
pub fn macros(&self) -> &MacroTable
The macros defined so far.
Sourcepub fn macros_mut(&mut self) -> &mut MacroTable
pub fn macros_mut(&mut self) -> &mut MacroTable
The macro table, for the driver to seed with -D and the predefined set.
Sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
Everything reported so far.
Sourcepub fn take_diagnostics(&mut self) -> Vec<Diagnostic>
pub fn take_diagnostics(&mut self) -> Vec<Diagnostic>
Takes the diagnostics, leaving the preprocessor able to carry on.
Sourcepub fn dependencies(&self) -> &[Dependency]
pub fn dependencies(&self) -> &[Dependency]
Every file an #include found, in the order they were first reached.
What the -M family writes into a make rule. The source file itself is not in here,
since nothing included it, and the caller that knows its name puts it first.
Sourcepub fn line_directives(&self) -> &[LineDirective]
pub fn line_directives(&self) -> &[LineDirective]
The #line directives seen, in the order they appeared.
Each one is also applied, to the source map, as it is read. This is the record of them rather than the mechanism: what a caller wants it for is reporting on the directives themselves, and asking the map is how to find out where anything is.
Sourcepub fn predefine(
&mut self,
target: &TargetInfo,
opts: &Predef,
cx: &mut Context<'_>,
) -> Result<(), SourceMapFull>
pub fn predefine( &mut self, target: &TargetInfo, opts: &Predef, cx: &mut Context<'_>, ) -> Result<(), SourceMapFull>
Defines the predefined macro set, and then -D and -U from the command line.
Called before Preprocessor::run, because a predefined macro is a macro like any
other by the time the source file is read. The set arrives as two synthetic files
rather than as a list of definitions, so a diagnostic about one of them points at
<built-in> or <command-line> the way GCC’s does, and so that -dM has something
to print. The reasoning is in crate::predef.
§Errors
When the source map has no room left for the two synthetic files.
Sourcepub fn preinclude(
&mut self,
files: &[Preinclude],
out: &mut Vec<Tok>,
cx: &mut Context<'_>,
) -> Result<(), SourceMapFull>
pub fn preinclude( &mut self, files: &[Preinclude], out: &mut Vec<Tok>, cx: &mut Context<'_>, ) -> Result<(), SourceMapFull>
Reads the files -imacros and -include named, before the source file is opened.
Called between Preprocessor::predefine and Preprocessor::run, with the tokens the
-include files produce going in front of the ones the source file produces. That is what
the flags mean: the definitions arrive before the first line of the source, so a header
the source has no #include for is nevertheless in scope throughout it.
Every -imacros file is read before every -include file, whatever order the command line
wrote them in, which is GCC’s behaviour and is measured rather than read: two command lines
with the two flags the other way round produce the same output byte for byte. The text an
-imacros file produces is thrown away and only its definitions are kept, which is the
whole difference between the two flags.
Each name is looked for the way a quoted include is looked for, starting from the working
directory rather than from the directory of the source file. A source in sub/ and a
-include of a header sitting beside it is an error, not a file found, because the command
line is not written in sub/.
§Errors
When the source map has no room left for the record of the flags.