1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (C) 2020-2023 Free Software Foundation, Inc.
// This file is part of GCC.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#ifndef RUST_MACRO_BUILTINS_H
#define RUST_MACRO_BUILTINS_H
#include "rust-ast.h"
#include "rust-ast-fragment.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
{
public:
static AST::Fragment assert_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment file_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment column_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment include_bytes_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment include_str_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment compile_error_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment concat_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment env_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment cfg_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment include_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
static AST::Fragment line_handler (Location invoc_locus,
AST::MacroInvocData &invoc);
};
} // namespace Rust
#endif // RUST_MACRO_BUILTINS_H
|