@@ -361,9 +361,26 @@ class MacroRulesDefinition : public MacroItem
361
361
DelimType delim_type;
362
362
// MacroRules rules;
363
363
std::vector<MacroRule> rules; // inlined form
364
-
365
364
Location locus;
366
365
366
+ std::function<ASTFragment (Location, MacroInvocData &)>
367
+ associated_transcriber;
368
+ // Since we can't compare std::functions, we need to use an extra boolean
369
+ bool is_builtin_rule;
370
+
371
+ /* *
372
+ * Default function to use as an associated transcriber. This function should
373
+ * never be called, hence the gcc_unreachable().
374
+ * If this function is used, then the macro is not builtin and the compiler
375
+ * should make use of the actual rules. If the macro is builtin, then another
376
+ * associated transcriber should be used
377
+ */
378
+ static ASTFragment dummy_builtin (Location, MacroInvocData &)
379
+ {
380
+ gcc_unreachable ();
381
+ return ASTFragment::create_empty ();
382
+ }
383
+
367
384
/* NOTE: in rustc, macro definitions are considered (and parsed as) a type
368
385
* of macro, whereas here they are considered part of the language itself.
369
386
* I am not aware of the implications of this decision. The rustc spec does
@@ -377,7 +394,17 @@ class MacroRulesDefinition : public MacroItem
377
394
std::vector<MacroRule> rules,
378
395
std::vector<Attribute> outer_attrs, Location locus)
379
396
: outer_attrs (std::move (outer_attrs)), rule_name (std::move (rule_name)),
380
- delim_type (delim_type), rules (std::move (rules)), locus (locus)
397
+ delim_type (delim_type), rules (std::move (rules)), locus (locus),
398
+ associated_transcriber (dummy_builtin), is_builtin_rule (false )
399
+ {}
400
+
401
+ MacroRulesDefinition (Identifier builtin_name, DelimType delim_type,
402
+ std::function<ASTFragment (Location, MacroInvocData &)>
403
+ associated_transcriber)
404
+ : outer_attrs (std::vector<Attribute> ()), rule_name (builtin_name),
405
+ delim_type (delim_type), rules (std::vector<MacroRule> ()),
406
+ locus (Location ()), associated_transcriber (associated_transcriber),
407
+ is_builtin_rule (true )
381
408
{}
382
409
383
410
void accept_vis (ASTVisitor &vis) override ;
@@ -400,6 +427,20 @@ class MacroRulesDefinition : public MacroItem
400
427
std::vector<MacroRule> &get_rules () { return rules; }
401
428
const std::vector<MacroRule> &get_rules () const { return rules; }
402
429
430
+ bool is_builtin () const { return is_builtin_rule; }
431
+ const std::function<ASTFragment (Location, MacroInvocData &)> &
432
+ get_builtin_transcriber () const
433
+ {
434
+ rust_assert (is_builtin ());
435
+ return associated_transcriber;
436
+ }
437
+ void set_builtin_transcriber (
438
+ std::function<ASTFragment (Location, MacroInvocData &)> transcriber)
439
+ {
440
+ associated_transcriber = transcriber;
441
+ is_builtin_rule = true ;
442
+ }
443
+
403
444
protected:
404
445
/* Use covariance to implement clone function as returning this object rather
405
446
* than base */
0 commit comments