@@ -158,74 +158,15 @@ HIRCompileBase::handle_attribute_proc_macro_attribute_on_fndecl (
158
158
ctx->collect_attribute_proc_macro (fndecl);
159
159
}
160
160
161
- static std::vector<std::string>
162
- get_attributes (const AST::Attribute &attr)
163
- {
164
- std::vector<std::string> result;
165
-
166
- rust_assert (attr.get_attr_input ().get_attr_input_type ()
167
- == Rust::AST::AttrInput::TOKEN_TREE);
168
- const auto &tt
169
- = static_cast <const AST::DelimTokenTree &> (attr.get_attr_input ());
170
-
171
- // TODO: Should we rely on fixed index ? Should we search for the
172
- // attribute tokentree instead ?
173
-
174
- // Derive proc macros have the following format:
175
- // #[proc_macro_derive(TraitName, attributes(attr1, attr2, attr3))]
176
- // -~~~~~~~~ - ~~~~~~~~~~---------------------
177
- // ^0 ^1 ^2 ^3 ^4
178
- // - "attributes" is stored at position 3 in the token tree
179
- // - attribute are stored in the delimited token tree in position 4
180
- constexpr size_t attr_kw_pos = 3 ;
181
- constexpr size_t attribute_list_pos = 4 ;
182
-
183
- if (tt.get_token_trees ().size () > attr_kw_pos)
184
- {
185
- rust_assert (tt.get_token_trees ()[attr_kw_pos]->as_string ()
186
- == " attributes" );
187
-
188
- auto attributes = static_cast <const AST::DelimTokenTree *> (
189
- tt.get_token_trees ()[attribute_list_pos].get ());
190
-
191
- auto &token_trees = attributes->get_token_trees ();
192
-
193
- for (auto i = token_trees.cbegin () + 1 ; // Skip opening parenthesis
194
- i < token_trees.cend ();
195
- i += 2 ) // Skip comma and closing parenthesis
196
- {
197
- result.push_back ((*i)->as_string ());
198
- }
199
- }
200
- return result;
201
- }
202
-
203
- static std::string
204
- get_trait_name (const AST::Attribute &attr)
205
- {
206
- // Derive proc macros have the following format:
207
- // #[proc_macro_derive(TraitName, attributes(attr1, attr2, attr3))]
208
- // -~~~~~~~~ - ~~~~~~~~~~---------------------
209
- // ^0 ^1 ^2 ^3 ^4
210
- // - The trait name is stored at position 1
211
- constexpr size_t trait_name_pos = 1 ;
212
-
213
- rust_assert (attr.get_attr_input ().get_attr_input_type ()
214
- == Rust::AST::AttrInput::TOKEN_TREE);
215
- const auto &tt
216
- = static_cast <const AST::DelimTokenTree &> (attr.get_attr_input ());
217
- return tt.get_token_trees ()[trait_name_pos]->as_string ();
218
- }
219
-
220
161
void
221
162
HIRCompileBase::handle_derive_proc_macro_attribute_on_fndecl (
222
163
tree fndecl, const AST::Attribute &attr)
223
164
{
224
165
handle_proc_macro_common (fndecl, attr);
225
166
226
167
attr.get_attr_input ().parse_to_meta_item ();
227
- CustomDeriveInfo macro
228
- = {fndecl, get_trait_name (attr), get_attributes (attr)};
168
+ CustomDeriveInfo macro = {fndecl, Analysis::Attributes::get_trait_name (attr),
169
+ Analysis::Attributes:: get_attributes (attr)};
229
170
ctx->collect_derive_proc_macro (macro);
230
171
}
231
172
0 commit comments