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 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 line_directives(&self) -> &[LineDirective]
pub fn line_directives(&self) -> &[LineDirective]
The #line directives seen, in the order they appeared.
They are recorded rather than applied. Applying one means the source map presenting a
different name and a different line for a stretch of a file it holds the real ones
for, and __LINE__ and __FILE__ reading the presented pair rather than the real
one. That is a change to the map rather than to the preprocessor, and it lands with
the -E output work that needs the same machinery for line markers.
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.