2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 18:17:09 +00:00

Rework the code so that update for nodes is now a function

The other changes have made it so that using a macro really isn't justified
so rework the code to get rid of the hiddeous update_for_nodes macro.

Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2010-11-11 16:20:32 -08:00
parent d551a1a9ab
commit 85c133cd84

View File

@ -1463,6 +1463,8 @@ class DFA {
void dump_node_to_dfa(void); void dump_node_to_dfa(void);
State* add_new_state(NodeMap &nodemap, pair <unsigned long, NodeSet *> index, NodeSet *nodes, dfa_stats_t &stats); State* add_new_state(NodeMap &nodemap, pair <unsigned long, NodeSet *> index, NodeSet *nodes, dfa_stats_t &stats);
void update_state_transitions(NodeMap &nodemap, list <State *> &work_queue, State *state, dfa_stats_t &stats); void update_state_transitions(NodeMap &nodemap, list <State *> &work_queue, State *state, dfa_stats_t &stats);
State *find_target_state(NodeMap &nodemap, list <State *> &work_queue,
NodeSet *nodes, dfa_stats_t &stats);
public: public:
DFA(Node *root, dfaflags_t flags); DFA(Node *root, dfaflags_t flags);
virtual ~DFA(); virtual ~DFA();
@ -1491,26 +1493,30 @@ State* DFA::add_new_state(NodeMap &nodemap, pair <unsigned long, NodeSet *> inde
return state; return state;
} }
/* macro to help out with DFA creation, not done as inlined fn as nearly State *DFA::find_target_state(NodeMap &nodemap, list <State *> &work_queue,
* every line uses a different map or variable that would have to be passed NodeSet *nodes, dfa_stats_t &stats)
{
State *target;
pair <unsigned long, NodeSet *> index = make_pair(hash_NodeSet(nodes), nodes);
map<pair <unsigned long, NodeSet *>, State *, deref_less_than>::iterator x = nodemap.find(index);
if (x == nodemap.end()) {
/* set of nodes isn't known so create new state, and nodes to
* state mapping
*/ */
#define update_for_nodes(NODES, TARGET) \ target = add_new_state(nodemap, index, nodes, stats);
do { \ work_queue.push_back(target);
pair <unsigned long, NodeSet *> index = make_pair(hash_NodeSet(NODES), NODES); \ } else {
map<pair <unsigned long, NodeSet *>, State *, deref_less_than>::iterator x = nodemap.find(index); \ /* set of nodes already has a mapping so free this one */
if (x == nodemap.end()) { \ stats.duplicates++;
/* set of nodes isn't known so create new state, and nodes to \ delete (nodes);
* state mapping \ target = x->second;
*/ \ }
(TARGET) = add_new_state(nodemap, index, (NODES), stats); \
work_queue.push_back(TARGET); \ return target;
} else { \ }
/* set of nodes already has a mapping so free this one */ \
stats.duplicates++; \
delete (NODES); \
TARGET = x->second; \
} \
} while (0)
void DFA::update_state_transitions(NodeMap &nodemap, void DFA::update_state_transitions(NodeMap &nodemap,
list <State *> &work_queue, State *state, list <State *> &work_queue, State *state,
@ -1533,18 +1539,19 @@ void DFA::update_state_transitions(NodeMap &nodemap,
*/ */
/* check the default transition first */ /* check the default transition first */
if (cases.otherwise) { if (cases.otherwise)
State *target; state->cases.otherwise = find_target_state(nodemap, work_queue,
update_for_nodes(cases.otherwise, target); cases.otherwise,
state->cases.otherwise = target; stats);;
}
/* For each transition from *from, check if the set of nodes it /* For each transition from *from, check if the set of nodes it
* transitions to already has been mapped to a state * transitions to already has been mapped to a state
*/ */
for (NodeCases::iterator j = cases.begin(); j != cases.end(); j++) { for (NodeCases::iterator j = cases.begin(); j != cases.end(); j++) {
State *target; State *target;
update_for_nodes(j->second, target); target = find_target_state(nodemap, work_queue, j->second,
stats);
/* Don't insert transition that the default transition /* Don't insert transition that the default transition
* already covers * already covers
*/ */