pub struct MacroTable { /* private fields */ }Expand description
Every macro currently defined.
Implementations§
Source§impl MacroTable
impl MacroTable
Sourcepub fn new() -> MacroTable
pub fn new() -> MacroTable
An empty table.
Sourcepub fn is_defined(&self, name: Symbol) -> bool
pub fn is_defined(&self, name: Symbol) -> bool
Whether name is defined, which is what #ifdef and defined ask.
Sourcepub fn define(
&mut self,
def: MacroDef,
interner: &Interner,
) -> Option<Diagnostic>
pub fn define( &mut self, def: MacroDef, interner: &Interner, ) -> Option<Diagnostic>
Adds a definition, returning a warning if it replaces a different one.
Redefining a macro to the same thing is legal and extremely common, because a header included twice through two paths does it. Redefining it to something else is a constraint violation, which GCC reports as a warning and accepts, and we match that because rejecting it would break real builds.
Sourcepub fn define_builtin(&mut self, name: Symbol, builtin: Builtin, span: Span)
pub fn define_builtin(&mut self, name: Symbol, builtin: Builtin, span: Span)
Defines one of the macros whose value is a question.
span is where to say the macro came from, which is the start of <built-in>, so that
a warning about redefining __FILE__ has somewhere to point.
Sourcepub fn undef(&mut self, name: Symbol) -> Option<MacroDef>
pub fn undef(&mut self, name: Symbol) -> Option<MacroDef>
Removes a definition. Undefining a macro that is not defined is legal and silent.
Sourcepub fn push_macro(&mut self, name: Symbol)
pub fn push_macro(&mut self, name: Symbol)
Puts the current definition of name aside, per #pragma push_macro.
A name with no definition pushes the absence, because the pragma is about restoring the state and “not defined” is a state. This is what lets the idiom work at all: a header pushes a name, defines it for its own use, and pops it, and the caller gets back exactly what it had whether that was a definition or nothing.
Sourcepub fn pop_macro(&mut self, name: Symbol)
pub fn pop_macro(&mut self, name: Symbol)
Restores what the last #pragma push_macro on name put aside.
A pop with nothing pushed does nothing and says nothing, which is what gcc does. The pragma is written in pairs across headers that do not know about each other, so a diagnostic here would fire on code that is not wrong.