Return the matching rule or NULL if no match and try_match is true.
| 632 | // Return the matching rule or NULL if no match and try_match is true. |
| 633 | // |
| 634 | const rule_match* |
| 635 | match_rule_impl (action a, target& t, |
| 636 | uint64_t options, |
| 637 | const rule* skip, |
| 638 | bool try_match, |
| 639 | match_extra* pme) |
| 640 | { |
| 641 | using fallback_rule = adhoc_rule_pattern::fallback_rule; |
| 642 | |
| 643 | auto adhoc_rule_match = [] (const rule_match& r) |
| 644 | { |
| 645 | return dynamic_cast<const adhoc_rule*> (&r.second.get ()); |
| 646 | }; |
| 647 | |
| 648 | auto fallback_rule_match = [] (const rule_match& r) |
| 649 | { |
| 650 | return dynamic_cast<const fallback_rule*> (&r.second.get ()); |
| 651 | }; |
| 652 | |
| 653 | // Note: we copy the options value to me.new_options after successfully |
| 654 | // matching the rule to make sure rule::match() implementations don't rely |
| 655 | // on it. |
| 656 | // |
| 657 | match_extra& me (pme == nullptr ? t[a].match_extra : *pme); |
| 658 | |
| 659 | if (const target* g = t.group) |
| 660 | { |
| 661 | // If this is a group with dynamic members, then match it with the |
| 662 | // group's rule automatically. See dyndep_rule::inject_group_member() |
| 663 | // for background. |
| 664 | // |
| 665 | if ((g->type ().flags & target_type::flag::dyn_members) == |
| 666 | target_type::flag::dyn_members) |
| 667 | { |
| 668 | if (g->matched (a, memory_order_acquire)) |
| 669 | { |
| 670 | const rule_match* r (g->state[a].rule); |
| 671 | assert (r != nullptr); // Shouldn't happen with dyn_members. |
| 672 | |
| 673 | me.new_options = options; |
| 674 | return r; |
| 675 | } |
| 676 | |
| 677 | // Assume static member and fall through. |
| 678 | } |
| 679 | |
| 680 | // If this is a member of group-based target, then first try to find a |
| 681 | // matching ad hoc recipe/rule by matching (to an ad hoc recipe/rule) |
| 682 | // the group but applying to the member. See adhoc_rule::match() for |
| 683 | // background, including for why const_cast should be safe. |
| 684 | // |
| 685 | // To put it another way, if a group is matched by an ad hoc |
| 686 | // recipe/rule, then we want all the member to be matched to the same |
| 687 | // recipe/rule. |
| 688 | // |
| 689 | // Note that such a group is dyn_members so we would have tried the |
| 690 | // "already matched" case above. |
| 691 | // |
nothing calls this directly
no test coverage detected