Skip to main content

Preprocessor

Struct Preprocessor 

Source
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

Source

pub fn new() -> Preprocessor

A preprocessor with an empty macro table.

Source

pub fn macros(&self) -> &MacroTable

The macros defined so far.

Source

pub fn macros_mut(&mut self) -> &mut MacroTable

The macro table, for the driver to seed with -D and the predefined set.

Source

pub fn diagnostics(&self) -> &[Diagnostic]

Everything reported so far.

Source

pub fn take_diagnostics(&mut self) -> Vec<Diagnostic>

Takes the diagnostics, leaving the preprocessor able to carry on.

Source

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.

Source

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.

Source

pub fn run(&mut self, file: FileId, cx: &mut Context<'_>) -> Vec<Tok>

Runs phase 4 over file and everything it includes.

The result is the tokens that survived the conditionals, with macros expanded. Nothing is thrown away silently: an unterminated #if and a stray #endif are both reported.

Trait Implementations§

Source§

impl Debug for Preprocessor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Preprocessor

Source§

fn default() -> Preprocessor

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.