Skip to main content

Expander

Struct Expander 

Source
pub struct Expander { /* private fields */ }
Expand description

Macro expansion state that outlives a single expansion.

Hide sets are interned for the whole translation unit, because the same set is produced over and over by the same nest of headers and re-interning it is free while re-allocating it is not.

Implementations§

Source§

impl Expander

Source

pub fn new() -> Expander

A fresh expander.

Source

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

Everything reported so far.

Source

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

Takes the diagnostics, leaving the expander empty.

Source

pub fn hide_sets(&self) -> usize

How many distinct hide sets have been interned, which is the number to watch when this starts costing memory.

Source

pub fn expand( &mut self, tokens: &[PpToken], macros: &MacroTable, interner: &mut Interner, sources: &SourceMap, ) -> Vec<Tok>

Expands a run of lexed tokens.

The input is a directive-free stretch of the file. An Eof token is ignored rather than passed through, because the caller decides where the stream ends.

Source

pub fn expand_toks( &mut self, tokens: Vec<Tok>, macros: &MacroTable, interner: &mut Interner, sources: &SourceMap, ) -> Vec<Tok>

Expands tokens that already carry hide sets, for a caller that is splicing streams together itself.

The source map is needed rather than merely useful: __FILE__ and __LINE__ are answered from where the token turned out to be, and the map is the only thing that knows that once a token has come out of three nested macros in two headers.

Trait Implementations§

Source§

impl Debug for Expander

Source§

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

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

impl Default for Expander

Source§

fn default() -> Expander

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, !>

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.