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
impl Expander
Sourcepub fn new() -> Expander
pub fn new() -> Expander
A fresh expander, whose __FILE__ is the name the file was found under.
Sourcepub fn with_prefix_map(map: PrefixMap) -> Expander
pub fn with_prefix_map(map: PrefixMap) -> Expander
The same, with __FILE__ rewritten by map.
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 expander empty.
Sourcepub fn hide_sets(&self) -> usize
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.
Sourcepub fn expand(
&mut self,
tokens: &[PpToken],
macros: &MacroTable,
interner: &mut Interner,
sources: &SourceMap,
) -> Vec<Tok>
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.
Sourcepub fn expand_toks(
&mut self,
tokens: Vec<Tok>,
macros: &MacroTable,
interner: &mut Interner,
sources: &SourceMap,
) -> Vec<Tok>
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.
Sourcepub fn expand_condition(
&mut self,
tokens: Vec<Tok>,
macros: &MacroTable,
interner: &mut Interner,
sources: &SourceMap,
condition: Condition,
) -> Vec<Tok>
pub fn expand_condition( &mut self, tokens: Vec<Tok>, macros: &MacroTable, interner: &mut Interner, sources: &SourceMap, condition: Condition, ) -> Vec<Tok>
Expands the tokens of a #if or #elif line.
The one difference from Expander::expand_toks is defined, which on such a line is an
operator that happens to be spelled like an identifier, and whose operand is not expanded.
A line that says defined(X) where the caller has already dealt with it never reaches
here, so what this is for is the defined a macro body wrote.