31 const char *search_tail =
nullptr;
33 bool preorder(
const IR::Path *p)
override {
34 if (look_for.startsWith(p->name.name)) {
35 search_tail = look_for.c_str() + p->name.name.size();
36 if (*search_tail == 0 || *search_tail ==
'.' || *search_tail ==
'[') result =
true;
40 bool preorder(
const IR::Primitive *p)
override {
41 if (p->name == look_for) result =
true;
44 bool preorder(
const IR::Expression *)
override {
return !result; }
46 void postorder(
const IR::Member *m)
override {
47 if (result && search_tail && *search_tail) {
48 if (*search_tail ==
'.') search_tail++;
49 if (
cstring(search_tail).startsWith(m->member.name)) {
50 search_tail += m->member.name.size();
51 if (*search_tail == 0 || *search_tail ==
'.' || *search_tail ==
'[')
return;
53 search_tail =
nullptr;
54 if (!m->expr->type->is<IR::Type_HeaderUnion>()) {
59 void postorder(
const IR::ArrayIndex *m)
override {
60 if (result && search_tail && *search_tail) {
61 if (*search_tail ==
'.' || *search_tail ==
'[') search_tail++;
62 if (isdigit(*search_tail)) {
63 int idx = strtol(search_tail,
const_cast<char **
>(&search_tail), 10);
64 if (*search_tail ==
']') search_tail++;
65 if (
auto k = m->right->to<IR::Constant>()) {
66 if (k->asInt() == idx)
return;
72 search_tail =
nullptr;
75 void postorder(
const IR::PathExpression *)
override {}
76 void postorder(
const IR::Expression *)
override { search_tail =
nullptr; }
83 explicit operator bool()
const {
return result; }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24