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;
31 bool preorder(
const IR::Primitive *p)
override {
32 if (p->name == look_for) result =
true;
35 bool preorder(
const IR::Expression *)
override {
return !result; }
37 void postorder(
const IR::Member *m)
override {
38 if (result && search_tail && *search_tail) {
39 if (*search_tail ==
'.') search_tail++;
40 if (
cstring(search_tail).startsWith(m->member.name)) {
41 search_tail += m->member.name.size();
42 if (*search_tail == 0 || *search_tail ==
'.' || *search_tail ==
'[')
return;
44 search_tail =
nullptr;
45 if (!m->expr->type->is<IR::Type_HeaderUnion>()) {
50 void postorder(
const IR::ArrayIndex *m)
override {
51 if (result && search_tail && *search_tail) {
52 if (*search_tail ==
'.' || *search_tail ==
'[') search_tail++;
53 if (isdigit(*search_tail)) {
54 int idx = strtol(search_tail,
const_cast<char **
>(&search_tail), 10);
55 if (*search_tail ==
']') search_tail++;
56 if (
auto k = m->right->to<IR::Constant>()) {
57 if (k->asInt() == idx)
return;
63 search_tail =
nullptr;
66 void postorder(
const IR::PathExpression *)
override {}
67 void postorder(
const IR::Expression *)
override { search_tail =
nullptr; }
70 exprUses(
const IR::Expression *e,
cstring n) : look_for(n) {
74 explicit operator bool()
const {
return result; }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13