diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-11 14:19:56 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-11 14:19:56 +0100 |
commit | c62e9eb5ee3be6e321a1bf725cbc797ba7fda593 (patch) | |
tree | 8ec3199309d6906885453407274f8b0142a3d796 /gcc | |
parent | 6e64e6636ef823ac97ad889b71bb792fbe510580 (diff) | |
download | gcc-c62e9eb5ee3be6e321a1bf725cbc797ba7fda593.zip gcc-c62e9eb5ee3be6e321a1bf725cbc797ba7fda593.tar.gz gcc-c62e9eb5ee3be6e321a1bf725cbc797ba7fda593.tar.bz2 |
builtin-macros: Add more documentation for defining builtins
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins.h b/gcc/rust/expand/rust-macro-builtins.h index ee42fe1..37923cf 100644 --- a/gcc/rust/expand/rust-macro-builtins.h +++ b/gcc/rust/expand/rust-macro-builtins.h @@ -22,6 +22,43 @@ #include "rust-ast.h" #include "rust-location.h" +/** + * This class provides a list of builtin macros implemented by the compiler. + * The functions defined are called "builtin transcribers" in that they replace + * the transcribing part of a macro definition. + * + * Like regular macro transcribers, they are responsible for building and + * returning an AST fragment: basically a vector of AST nodes put together. + * + * Unlike regular declarative macros where each match arm has its own associated + * transcriber, builtin transcribers are responsible for handling all match arms + * of the macro. This means that you should take extra care when implementing a + * builtin containing multiple match arms: You will probably need to do some + * lookahead in order to determine which match arm the user intended to use. + * + * An example of this is the `assert!()` macro: + * + * ``` + * macro_rules! assert { + * ($cond:expr $(,)?) => {{ ... }}; + * ($cond : expr, $ ($arg : tt) +) = > {{ ... }}; + * } + * ``` + * + * If more tokens exist beyond the optional comma, they need to be handled as + * a token-tree for a custom panic message. + * + * These builtin macros with empty transcribers are defined in the standard + * library. They are marked with a special attribute, `#[rustc_builtin_macro]`. + * When this attribute is present on a macro definition, the compiler should + * look for an associated transcriber in the mappings. Meaning that you must + * remember to insert your transcriber in the `builtin_macros` map of the + *`Mappings`. + * + * This map is built as a static variable in the `insert_macro_def()` method + * of the `Mappings` class. + */ + namespace Rust { class MacroBuiltin { |