pub struct MacroDefinition {
    pub name: String,
    pub parameters: Vec<String>,
    pub body: String,
}Expand description
Represents a C macro definition (#define).
C macros come in two forms:
- Object-like: Simple text replacement (e.g., 
#define MAX 100) - Function-like: Parameterized text replacement (e.g., 
#define SQR(x) ((x) * (x))) 
§Examples
use decy_parser::parser::{CParser, MacroDefinition};
// Parse a simple object-like macro
let parser = CParser::new()?;
let ast = parser.parse("#define MAX 100\nint main() { return 0; }")?;
assert_eq!(ast.macros().len(), 1);
assert_eq!(ast.macros()[0].name(), "MAX");
assert!(ast.macros()[0].is_object_like());
// Parse a function-like macro
let ast2 = parser.parse("#define SQR(x) ((x) * (x))\nint main() { return 0; }")?;
assert_eq!(ast2.macros()[0].name(), "SQR");
assert!(ast2.macros()[0].is_function_like());
assert_eq!(ast2.macros()[0].parameters(), &["x"]);§Reference
K&R §4.11, ISO C99 §6.10.3
Fields§
§name: StringMacro name
parameters: Vec<String>Parameters (empty for object-like macros)
body: StringMacro body (unparsed, tokenized without spaces)
Implementations§
Source§impl MacroDefinition
 
impl MacroDefinition
Sourcepub fn new_object_like(name: String, body: String) -> Self
 
pub fn new_object_like(name: String, body: String) -> Self
Create a new object-like macro.
Sourcepub fn new_function_like(
    name: String,
    parameters: Vec<String>,
    body: String,
) -> Self
 
pub fn new_function_like( name: String, parameters: Vec<String>, body: String, ) -> Self
Create a new function-like macro.
Sourcepub fn parameters(&self) -> &[String]
 
pub fn parameters(&self) -> &[String]
Get the macro parameters.
Sourcepub fn is_function_like(&self) -> bool
 
pub fn is_function_like(&self) -> bool
Check if this is a function-like macro.
Sourcepub fn is_object_like(&self) -> bool
 
pub fn is_object_like(&self) -> bool
Check if this is an object-like macro.
Trait Implementations§
Source§impl Clone for MacroDefinition
 
impl Clone for MacroDefinition
Source§fn clone(&self) -> MacroDefinition
 
fn clone(&self) -> MacroDefinition
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from 
source. Read moreSource§impl Debug for MacroDefinition
 
impl Debug for MacroDefinition
Source§impl PartialEq for MacroDefinition
 
impl PartialEq for MacroDefinition
impl StructuralPartialEq for MacroDefinition
Auto Trait Implementations§
impl Freeze for MacroDefinition
impl RefUnwindSafe for MacroDefinition
impl Send for MacroDefinition
impl Sync for MacroDefinition
impl Unpin for MacroDefinition
impl UnwindSafe for MacroDefinition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more