Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtin-macros: Add more documentation for defining builtins #1018

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions gcc/rust/expand/rust-macro-builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down