Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 : #ifndef RUST_ATTRIBUTES_H
19 : #define RUST_ATTRIBUTES_H
20 :
21 : #include "rust-ast.h"
22 : #include "optional.h"
23 :
24 : namespace Rust {
25 : namespace Analysis {
26 :
27 : class Attributes
28 : {
29 : public:
30 : enum class AttributeKnowledge
31 : {
32 : /**
33 : * Built-in attribute
34 : */
35 : Known,
36 : /**
37 : * Tool attribute, to be handled by the specified tool rather than the
38 : * compiler
39 : */
40 : Tool,
41 : /**
42 : * Unknown attribute
43 : */
44 : Unknown,
45 : };
46 :
47 : static AttributeKnowledge is_known (const std::string &attribute_path);
48 : static bool valid_outer_attribute (const std::string &attribute_path);
49 : static tl::optional<std::string>
50 : extract_string_literal (const AST::Attribute &attr);
51 : };
52 :
53 : enum CompilerPass
54 : {
55 : UNKNOWN,
56 :
57 : EXPANSION,
58 : NAME_RESOLUTION,
59 : HIR_LOWERING,
60 : TYPE_CHECK,
61 : STATIC_ANALYSIS,
62 : CODE_GENERATION,
63 :
64 : // External Rust tooling attributes, like #[rustfmt::skip]
65 : EXTERNAL,
66 :
67 : // Do we need to add something here for const fns?
68 : };
69 :
70 495627 : struct BuiltinAttrDefinition
71 : {
72 : std::string name;
73 : CompilerPass handler;
74 :
75 2 : static BuiltinAttrDefinition get_error ()
76 : {
77 2 : return BuiltinAttrDefinition{"", UNKNOWN};
78 : }
79 :
80 4 : static BuiltinAttrDefinition &error_node ()
81 : {
82 8 : static BuiltinAttrDefinition error_node = get_error ();
83 4 : return error_node;
84 : }
85 :
86 3758496 : bool is_error () const { return name.empty (); }
87 : };
88 :
89 : class BuiltinAttributeMappings
90 : {
91 : public:
92 : static BuiltinAttributeMappings *get ();
93 :
94 : const BuiltinAttrDefinition &
95 : lookup_builtin (const std::string &attr_name) const;
96 :
97 : private:
98 : BuiltinAttributeMappings ();
99 :
100 : std::map<std::string, const BuiltinAttrDefinition> mappings;
101 : };
102 :
103 : tl::optional<BuiltinAttrDefinition>
104 : lookup_builtin (const AST::Attribute &attribute);
105 :
106 : } // namespace Analysis
107 : } // namespace Rust
108 :
109 : #endif /* ! RUST_ATTRIBUTES_H */
|