22 const char *search_tail =
nullptr;
24 bool preorder(
const IR::Path *p)
override {
25 if (look_for.startsWith(p->name.name)) {
26 search_tail = look_for.c_str() + p->name.name.size();
27 if (*search_tail == 0 || *search_tail ==
'.' || *search_tail ==
'[') result =
true;
32 bool preorder(
const IR::Primitive *p)
override {
33 if (p->name == look_for) result =
true;
37 bool preorder(
const IR::Expression *)
override {
return !result; }
39 void postorder(
const IR::Member *m)
override {
40 if (result && search_tail && *search_tail) {
41 if (*search_tail ==
'.') search_tail++;
42 if (
cstring(search_tail).startsWith(m->member.name)) {
43 search_tail += m->member.name.size();
44 if (*search_tail == 0 || *search_tail ==
'.' || *search_tail ==
'[')
return;
46 search_tail =
nullptr;
47 if (!m->expr->type->is<IR::Type_HeaderUnion>()) {
52 void postorder(
const IR::ArrayIndex *m)
override {
53 if (result && search_tail && *search_tail) {
54 if (*search_tail ==
'.' || *search_tail ==
'[') search_tail++;
55 if (isdigit(*search_tail)) {
56 int idx = strtol(search_tail,
const_cast<char **
>(&search_tail), 10);
57 if (*search_tail ==
']') search_tail++;
58 if (
auto k = m->right->to<IR::Constant>()) {
59 if (k->asInt() == idx)
return;
65 search_tail =
nullptr;
68 void postorder(
const IR::PathExpression *)
override {}
69 void postorder(
const IR::Expression *)
override { search_tail =
nullptr; }
72 exprUses(
const IR::Expression *e,
cstring n) : look_for(n) {
76 explicit operator bool()
const {
return result; }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13