Skip to content

Commit

Permalink
Fix Lexer idiocy.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 3, 2018
1 parent e50c505 commit 6834aba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 8 additions & 0 deletions include/click/lexer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ class Lexer { public:
#endif
String name;
int next;

inline Compound* compound() const {
if (factory == compound_element_factory)
return reinterpret_cast<Compound*>(thunk);
else
return 0;
}
};
HashTable<String, int> _element_type_map;
Vector<ElementType> _element_types;
Expand Down Expand Up @@ -195,6 +202,7 @@ class Lexer { public:
int make_compound_element(int);
void expand_compound_element(int, VariableEnvironment &);
void add_router_connections(int, const Vector<int> &);
static Element* compound_element_factory(uintptr_t);

void yport(bool isoutput);
void yelement_name();
Expand Down
19 changes: 8 additions & 11 deletions lib/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ error_element_factory(uintptr_t)
return new ErrorElement;
}

static Element *
compound_element_factory(uintptr_t)
Element*
Lexer::compound_element_factory(uintptr_t)
{
assert(0);
return 0;
Expand Down Expand Up @@ -543,10 +543,8 @@ Lexer::~Lexer()

// get rid of nonscoped element types
for (int t = 0; t < _element_types.size(); t++)
if (_element_types[t].factory == compound_element_factory) {
Lexer::Compound *compound = (Lexer::Compound *) _element_types[t].thunk;
compound->unuse();
}
if (Compound* c = _element_types[t].compound())
c->unuse();
}

int
Expand Down Expand Up @@ -577,7 +575,8 @@ Lexer::end_parse(int cookie)
}
_tunnels.clear();

_c->unuse();
if (_c)
_c->unuse();
_c = 0;
delete _ps;
_ps = 0;
Expand Down Expand Up @@ -1032,10 +1031,8 @@ Lexer::remove_element_type(int removed, int *prev_hint)
}

// remove stuff
if (_element_types[removed].factory == compound_element_factory) {
Lexer::Compound *compound = (Lexer::Compound *) _element_types[removed].thunk;
compound->unuse();
}
if (Lexer::Compound* c = _element_types[removed].compound())
c->unuse();
_element_types[removed].factory = 0;
_element_types[removed].name = String();
_element_types[removed].next = _free_element_type;
Expand Down

0 comments on commit 6834aba

Please sign in to comment.