|
22 | 22 | #include "rust-ast.h"
|
23 | 23 | #include "rust-location.h"
|
24 | 24 |
|
| 25 | +/** |
| 26 | + * This class provides a list of builtin macros implemented by the compiler. |
| 27 | + * The functions defined are called "builtin transcribers" in that they replace |
| 28 | + * the transcribing part of a macro definition. |
| 29 | + * |
| 30 | + * Like regular macro transcribers, they are responsible for building and |
| 31 | + * returning an AST fragment: basically a vector of AST nodes put together. |
| 32 | + * |
| 33 | + * Unlike regular declarative macros where each match arm has its own associated |
| 34 | + * transcriber, builtin transcribers are responsible for handling all match arms |
| 35 | + * of the macro. This means that you should take extra care when implementing a |
| 36 | + * builtin containing multiple match arms: You will probably need to do some |
| 37 | + * lookahead in order to determine which match arm the user intended to use. |
| 38 | + * |
| 39 | + * An example of this is the `assert!()` macro: |
| 40 | + * |
| 41 | + * ``` |
| 42 | + * macro_rules! assert { |
| 43 | + * ($cond:expr $(,)?) => {{ ... }}; |
| 44 | + * ($cond : expr, $ ($arg : tt) +) = > {{ ... }}; |
| 45 | + * } |
| 46 | + * ``` |
| 47 | + * |
| 48 | + * If more tokens exist beyond the optional comma, they need to be handled as |
| 49 | + * a token-tree for a custom panic message. |
| 50 | + * |
| 51 | + * These builtin macros with empty transcribers are defined in the standard |
| 52 | + * library. They are marked with a special attribute, `#[rustc_builtin_macro]`. |
| 53 | + * When this attribute is present on a macro definition, the compiler should |
| 54 | + * look for an associated transcriber in the mappings. Meaning that you must |
| 55 | + * remember to insert your transcriber in the `builtin_macros` map of the |
| 56 | + *`Mappings`. |
| 57 | + * |
| 58 | + * This map is built as a static variable in the `insert_macro_def()` method |
| 59 | + * of the `Mappings` class. |
| 60 | + */ |
| 61 | + |
25 | 62 | namespace Rust {
|
26 | 63 | class MacroBuiltin
|
27 | 64 | {
|
|
0 commit comments