mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 18:17:09 +00:00
parser: rename uchar to transchar
Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
parent
daa10d3ce1
commit
72f93d9aba
@ -257,7 +257,7 @@ void *aare_rules::create_dfa(size_t *size, int *min_match_len, dfaflags_t flags)
|
|||||||
if (flags & DFA_DUMP_GRAPH)
|
if (flags & DFA_DUMP_GRAPH)
|
||||||
dfa.dump_dot_graph(cerr);
|
dfa.dump_dot_graph(cerr);
|
||||||
|
|
||||||
map<uchar, uchar> eq;
|
map<transchar, transchar> eq;
|
||||||
if (flags & DFA_CONTROL_EQUIV) {
|
if (flags & DFA_CONTROL_EQUIV) {
|
||||||
eq = dfa.equivalence_classes(flags);
|
eq = dfa.equivalence_classes(flags);
|
||||||
dfa.apply_equivalence_classes(eq);
|
dfa.apply_equivalence_classes(eq);
|
||||||
|
@ -49,7 +49,7 @@ void CHFA::init_free_list(vector<pair<size_t, size_t> > &free_list,
|
|||||||
/**
|
/**
|
||||||
* new Construct the transition table.
|
* new Construct the transition table.
|
||||||
*/
|
*/
|
||||||
CHFA::CHFA(DFA &dfa, map<uchar, uchar> &eq, dfaflags_t flags): eq(eq)
|
CHFA::CHFA(DFA &dfa, map<transchar, transchar> &eq, dfaflags_t flags): eq(eq)
|
||||||
{
|
{
|
||||||
if (flags & DFA_DUMP_TRANS_PROGRESS)
|
if (flags & DFA_DUMP_TRANS_PROGRESS)
|
||||||
fprintf(stderr, "Compressing HFA:\r");
|
fprintf(stderr, "Compressing HFA:\r");
|
||||||
@ -63,7 +63,7 @@ CHFA::CHFA(DFA &dfa, map<uchar, uchar> &eq, dfaflags_t flags): eq(eq)
|
|||||||
max_eq = 255;
|
max_eq = 255;
|
||||||
else {
|
else {
|
||||||
max_eq = 0;
|
max_eq = 0;
|
||||||
for (map<uchar, uchar>::iterator i = eq.begin();
|
for (map<transchar, transchar>::iterator i = eq.begin();
|
||||||
i != eq.end(); i++) {
|
i != eq.end(); i++) {
|
||||||
if (i->second > max_eq)
|
if (i->second > max_eq)
|
||||||
max_eq = i->second;
|
max_eq = i->second;
|
||||||
@ -291,7 +291,7 @@ void CHFA::dump(ostream &os)
|
|||||||
if (eq.size())
|
if (eq.size())
|
||||||
os << offs;
|
os << offs;
|
||||||
else
|
else
|
||||||
os << (uchar) offs;
|
os << (transchar) offs;
|
||||||
}
|
}
|
||||||
os << "\n";
|
os << "\n";
|
||||||
}
|
}
|
||||||
@ -379,7 +379,7 @@ void CHFA::flex_table(ostream &os, const char *name)
|
|||||||
vector<uint8_t> equiv_vec;
|
vector<uint8_t> equiv_vec;
|
||||||
if (eq.size()) {
|
if (eq.size()) {
|
||||||
equiv_vec.resize(256);
|
equiv_vec.resize(256);
|
||||||
for (map<uchar, uchar>::iterator i = eq.begin(); i != eq.end(); i++) {
|
for (map<transchar, transchar>::iterator i = eq.begin(); i != eq.end(); i++) {
|
||||||
equiv_vec[i->first.c] = i->second.c;
|
equiv_vec[i->first.c] = i->second.c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class CHFA {
|
|||||||
typedef vector<pair<const State *, size_t> > DefaultBase;
|
typedef vector<pair<const State *, size_t> > DefaultBase;
|
||||||
typedef vector<pair<const State *, const State *> > NextCheck;
|
typedef vector<pair<const State *, const State *> > NextCheck;
|
||||||
public:
|
public:
|
||||||
CHFA(DFA &dfa, map<uchar, uchar> &eq, dfaflags_t flags);
|
CHFA(DFA &dfa, map<transchar, transchar> &eq, dfaflags_t flags);
|
||||||
void dump(ostream & os);
|
void dump(ostream & os);
|
||||||
void flex_table(ostream &os, const char *name);
|
void flex_table(ostream &os, const char *name);
|
||||||
void init_free_list(vector<pair<size_t, size_t> > &free_list,
|
void init_free_list(vector<pair<size_t, size_t> > &free_list,
|
||||||
@ -52,8 +52,8 @@ class CHFA {
|
|||||||
DefaultBase default_base;
|
DefaultBase default_base;
|
||||||
NextCheck next_check;
|
NextCheck next_check;
|
||||||
map<const State *, size_t> num;
|
map<const State *, size_t> num;
|
||||||
map<uchar, uchar> &eq;
|
map<transchar, transchar> &eq;
|
||||||
uchar max_eq;
|
transchar max_eq;
|
||||||
size_t first_free;
|
size_t first_free;
|
||||||
unsigned int chfaflags;
|
unsigned int chfaflags;
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
/* Use a single static EpsNode as it carries no node specific information */
|
/* Use a single static EpsNode as it carries no node specific information */
|
||||||
EpsNode epsnode;
|
EpsNode epsnode;
|
||||||
|
|
||||||
ostream &operator<<(ostream &os, uchar c)
|
ostream &operator<<(ostream &os, transchar c)
|
||||||
{
|
{
|
||||||
const char *search = "\a\033\f\n\r\t|*+[](). ",
|
const char *search = "\a\033\f\n\r\t|*+[](). ",
|
||||||
*replace = "aefnrt|*+[](). ", *s;
|
*replace = "aefnrt|*+[](). ", *s;
|
||||||
|
@ -45,38 +45,38 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class uchar {
|
class transchar {
|
||||||
public:
|
public:
|
||||||
short c;
|
short c;
|
||||||
|
|
||||||
uchar(unsigned char a): c((unsigned short) a) {}
|
transchar(unsigned char a): c((unsigned short) a) {}
|
||||||
uchar(const uchar &a): c(a.c) {}
|
transchar(const transchar &a): c(a.c) {}
|
||||||
uchar(): c(0) {}
|
transchar(): c(0) {}
|
||||||
|
|
||||||
bool operator==(const uchar &rhs) const {
|
bool operator==(const transchar &rhs) const {
|
||||||
return this->c == rhs.c;
|
return this->c == rhs.c;
|
||||||
}
|
}
|
||||||
bool operator==(const int &rhs) const {
|
bool operator==(const int &rhs) const {
|
||||||
return this->c == rhs;
|
return this->c == rhs;
|
||||||
}
|
}
|
||||||
bool operator!=(const uchar &rhs) const {
|
bool operator!=(const transchar &rhs) const {
|
||||||
return this->c != rhs.c;
|
return this->c != rhs.c;
|
||||||
}
|
}
|
||||||
bool operator>(const uchar &rhs) const {
|
bool operator>(const transchar &rhs) const {
|
||||||
return this->c > rhs.c;
|
return this->c > rhs.c;
|
||||||
}
|
}
|
||||||
bool operator<(const uchar &rhs) const {
|
bool operator<(const transchar &rhs) const {
|
||||||
return this->c < rhs.c;
|
return this->c < rhs.c;
|
||||||
}
|
}
|
||||||
bool operator<=(const uchar &rhs) const {
|
bool operator<=(const transchar &rhs) const {
|
||||||
return this->c <= rhs.c;
|
return this->c <= rhs.c;
|
||||||
}
|
}
|
||||||
uchar &operator++() { // prefix
|
transchar &operator++() { // prefix
|
||||||
(this->c)++;
|
(this->c)++;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
uchar operator++(int) { // postfix
|
transchar operator++(int) { // postfix
|
||||||
uchar tmp(*this);
|
transchar tmp(*this);
|
||||||
(this->c)++;
|
(this->c)++;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@ -85,9 +85,9 @@ public:
|
|||||||
|
|
||||||
class Chars {
|
class Chars {
|
||||||
public:
|
public:
|
||||||
set<uchar> chars;
|
set<transchar> chars;
|
||||||
|
|
||||||
typedef set<uchar>::iterator iterator;
|
typedef set<transchar>::iterator iterator;
|
||||||
iterator begin() { return chars.begin(); }
|
iterator begin() { return chars.begin(); }
|
||||||
iterator end() { return chars.end(); }
|
iterator end() { return chars.end(); }
|
||||||
|
|
||||||
@ -101,23 +101,23 @@ public:
|
|||||||
{
|
{
|
||||||
return chars.size();
|
return chars.size();
|
||||||
}
|
}
|
||||||
iterator find(const uchar &key)
|
iterator find(const transchar &key)
|
||||||
{
|
{
|
||||||
return chars.find(key);
|
return chars.find(key);
|
||||||
}
|
}
|
||||||
pair<iterator,bool> insert(uchar c)
|
pair<iterator,bool> insert(transchar c)
|
||||||
{
|
{
|
||||||
return chars.insert(c);
|
return chars.insert(c);
|
||||||
}
|
}
|
||||||
pair<iterator,bool> insert(char c)
|
pair<iterator,bool> insert(char c)
|
||||||
{
|
{
|
||||||
uchar tmp(c);
|
transchar tmp(c);
|
||||||
return chars.insert(tmp);
|
return chars.insert(tmp);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ostream &operator<<(ostream &os, uchar c);
|
ostream &operator<<(ostream &os, transchar c);
|
||||||
|
|
||||||
/* Compute the union of two sets. */
|
/* Compute the union of two sets. */
|
||||||
template<class T> set<T> operator+(const set<T> &a, const set<T> &b)
|
template<class T> set<T> operator+(const set<T> &a, const set<T> &b)
|
||||||
@ -151,12 +151,12 @@ ostream &operator<<(ostream &os, const NodeSet &state);
|
|||||||
* enumerating all the explicit tranitions for default matches.
|
* enumerating all the explicit tranitions for default matches.
|
||||||
*/
|
*/
|
||||||
typedef struct Cases {
|
typedef struct Cases {
|
||||||
typedef map<uchar, NodeSet *>::iterator iterator;
|
typedef map<transchar, NodeSet *>::iterator iterator;
|
||||||
iterator begin() { return cases.begin(); }
|
iterator begin() { return cases.begin(); }
|
||||||
iterator end() { return cases.end(); }
|
iterator end() { return cases.end(); }
|
||||||
|
|
||||||
Cases(): otherwise(0) { }
|
Cases(): otherwise(0) { }
|
||||||
map<uchar, NodeSet *> cases;
|
map<transchar, NodeSet *> cases;
|
||||||
NodeSet *otherwise;
|
NodeSet *otherwise;
|
||||||
} Cases;
|
} Cases;
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ public:
|
|||||||
/* Match one specific character (/c/). */
|
/* Match one specific character (/c/). */
|
||||||
class CharNode: public CNode {
|
class CharNode: public CNode {
|
||||||
public:
|
public:
|
||||||
CharNode(uchar c): c(c) { }
|
CharNode(transchar c): c(c) { }
|
||||||
void follow(Cases &cases)
|
void follow(Cases &cases)
|
||||||
{
|
{
|
||||||
NodeSet **x = &cases.cases[c];
|
NodeSet **x = &cases.cases[c];
|
||||||
@ -370,7 +370,7 @@ public:
|
|||||||
|
|
||||||
bool contains_null() { return c == 0; }
|
bool contains_null() { return c == 0; }
|
||||||
|
|
||||||
uchar c;
|
transchar c;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Match a set of characters (/[abc]/). */
|
/* Match a set of characters (/[abc]/). */
|
||||||
|
@ -1160,10 +1160,10 @@ void DFA::dump_dot_graph(ostream & os)
|
|||||||
* Compute character equivalence classes in the DFA to save space in the
|
* Compute character equivalence classes in the DFA to save space in the
|
||||||
* transition table.
|
* transition table.
|
||||||
*/
|
*/
|
||||||
map<uchar, uchar> DFA::equivalence_classes(dfaflags_t flags)
|
map<transchar, transchar> DFA::equivalence_classes(dfaflags_t flags)
|
||||||
{
|
{
|
||||||
map<uchar, uchar> classes;
|
map<transchar, transchar> classes;
|
||||||
uchar next_class = 1;
|
transchar next_class = 1;
|
||||||
|
|
||||||
for (Partition::iterator i = states.begin(); i != states.end(); i++) {
|
for (Partition::iterator i = states.begin(); i != states.end(); i++) {
|
||||||
/* Group edges to the same next state together */
|
/* Group edges to the same next state together */
|
||||||
@ -1174,28 +1174,28 @@ map<uchar, uchar> DFA::equivalence_classes(dfaflags_t flags)
|
|||||||
for (map<const State *, Chars>::iterator j = node_sets.begin();
|
for (map<const State *, Chars>::iterator j = node_sets.begin();
|
||||||
j != node_sets.end(); j++) {
|
j != node_sets.end(); j++) {
|
||||||
/* Group edges to the same next state together by class */
|
/* Group edges to the same next state together by class */
|
||||||
map<uchar, Chars> node_classes;
|
map<transchar, Chars> node_classes;
|
||||||
bool class_used = false;
|
bool class_used = false;
|
||||||
for (Chars::iterator k = j->second.begin();
|
for (Chars::iterator k = j->second.begin();
|
||||||
k != j->second.end(); k++) {
|
k != j->second.end(); k++) {
|
||||||
pair<map<uchar, uchar>::iterator, bool> x = classes.insert(make_pair(*k, next_class));
|
pair<map<transchar, transchar>::iterator, bool> x = classes.insert(make_pair(*k, next_class));
|
||||||
if (x.second)
|
if (x.second)
|
||||||
class_used = true;
|
class_used = true;
|
||||||
pair<map<uchar, Chars>::iterator, bool> y = node_classes.insert(make_pair(x.first->second, Chars()));
|
pair<map<transchar, Chars>::iterator, bool> y = node_classes.insert(make_pair(x.first->second, Chars()));
|
||||||
y.first->second.insert(*k);
|
y.first->second.insert(*k);
|
||||||
}
|
}
|
||||||
if (class_used) {
|
if (class_used) {
|
||||||
next_class++;
|
next_class++;
|
||||||
class_used = false;
|
class_used = false;
|
||||||
}
|
}
|
||||||
for (map<uchar, Chars>::iterator k = node_classes.begin();
|
for (map<transchar, Chars>::iterator k = node_classes.begin();
|
||||||
k != node_classes.end(); k++) {
|
k != node_classes.end(); k++) {
|
||||||
/**
|
/**
|
||||||
* If any other characters are in the same class, move
|
* If any other characters are in the same class, move
|
||||||
* the characters in this class into their own new
|
* the characters in this class into their own new
|
||||||
* class
|
* class
|
||||||
*/
|
*/
|
||||||
map<uchar, uchar>::iterator l;
|
map<transchar, transchar>::iterator l;
|
||||||
for (l = classes.begin(); l != classes.end(); l++) {
|
for (l = classes.begin(); l != classes.end(); l++) {
|
||||||
if (l->second == k->first &&
|
if (l->second == k->first &&
|
||||||
k->second.find(l->first) == k->second.end()) {
|
k->second.find(l->first) == k->second.end()) {
|
||||||
@ -1224,16 +1224,16 @@ map<uchar, uchar> DFA::equivalence_classes(dfaflags_t flags)
|
|||||||
/**
|
/**
|
||||||
* Text-dump the equivalence classes (for debugging).
|
* Text-dump the equivalence classes (for debugging).
|
||||||
*/
|
*/
|
||||||
void dump_equivalence_classes(ostream &os, map<uchar, uchar> &eq)
|
void dump_equivalence_classes(ostream &os, map<transchar, transchar> &eq)
|
||||||
{
|
{
|
||||||
map<uchar, Chars> rev;
|
map<transchar, Chars> rev;
|
||||||
|
|
||||||
for (map<uchar, uchar>::iterator i = eq.begin(); i != eq.end(); i++) {
|
for (map<transchar, transchar>::iterator i = eq.begin(); i != eq.end(); i++) {
|
||||||
Chars &chars = rev.insert(make_pair(i->second, Chars())).first->second;
|
Chars &chars = rev.insert(make_pair(i->second, Chars())).first->second;
|
||||||
chars.insert(i->first);
|
chars.insert(i->first);
|
||||||
}
|
}
|
||||||
os << "(eq):" << "\n";
|
os << "(eq):" << "\n";
|
||||||
for (map<uchar, Chars>::iterator i = rev.begin(); i != rev.end(); i++) {
|
for (map<transchar, Chars>::iterator i = rev.begin(); i != rev.end(); i++) {
|
||||||
os << i->first.c << ':';
|
os << i->first.c << ':';
|
||||||
Chars &chars = i->second;
|
Chars &chars = i->second;
|
||||||
for (Chars::iterator j = chars.begin(); j != chars.end(); j++) {
|
for (Chars::iterator j = chars.begin(); j != chars.end(); j++) {
|
||||||
@ -1247,14 +1247,14 @@ void dump_equivalence_classes(ostream &os, map<uchar, uchar> &eq)
|
|||||||
* Replace characters with classes (which are also represented as
|
* Replace characters with classes (which are also represented as
|
||||||
* characters) in the DFA transition table.
|
* characters) in the DFA transition table.
|
||||||
*/
|
*/
|
||||||
void DFA::apply_equivalence_classes(map<uchar, uchar> &eq)
|
void DFA::apply_equivalence_classes(map<transchar, transchar> &eq)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Note: We only transform the transition table; the nodes continue to
|
* Note: We only transform the transition table; the nodes continue to
|
||||||
* contain the original characters.
|
* contain the original characters.
|
||||||
*/
|
*/
|
||||||
for (Partition::iterator i = states.begin(); i != states.end(); i++) {
|
for (Partition::iterator i = states.begin(); i != states.end(); i++) {
|
||||||
map<uchar, State *> tmp;
|
map<transchar, State *> tmp;
|
||||||
tmp.swap((*i)->trans);
|
tmp.swap((*i)->trans);
|
||||||
for (StateTrans::iterator j = tmp.begin(); j != tmp.end(); j++)
|
for (StateTrans::iterator j = tmp.begin(); j != tmp.end(); j++)
|
||||||
(*i)->trans.insert(make_pair(eq[j->first], j->second));
|
(*i)->trans.insert(make_pair(eq[j->first], j->second));
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
class State;
|
class State;
|
||||||
|
|
||||||
typedef map<uchar, State *> StateTrans;
|
typedef map<transchar, State *> StateTrans;
|
||||||
typedef list<State *> Partition;
|
typedef list<State *> Partition;
|
||||||
|
|
||||||
#include "../immunix.h"
|
#include "../immunix.h"
|
||||||
@ -212,7 +212,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
State *next(uchar c) {
|
State *next(transchar c) {
|
||||||
State *state = this;
|
State *state = this;
|
||||||
do {
|
do {
|
||||||
StateTrans::iterator i = state->trans.find(c);
|
StateTrans::iterator i = state->trans.find(c);
|
||||||
@ -326,8 +326,8 @@ public:
|
|||||||
void dump_dot_graph(ostream &os);
|
void dump_dot_graph(ostream &os);
|
||||||
void dump_uniq_perms(const char *s);
|
void dump_uniq_perms(const char *s);
|
||||||
|
|
||||||
map<uchar, uchar> equivalence_classes(dfaflags_t flags);
|
map<transchar, transchar> equivalence_classes(dfaflags_t flags);
|
||||||
void apply_equivalence_classes(map<uchar, uchar> &eq);
|
void apply_equivalence_classes(map<transchar, transchar> &eq);
|
||||||
|
|
||||||
unsigned int diffcount;
|
unsigned int diffcount;
|
||||||
Node *root;
|
Node *root;
|
||||||
@ -335,6 +335,6 @@ public:
|
|||||||
Partition states;
|
Partition states;
|
||||||
};
|
};
|
||||||
|
|
||||||
void dump_equivalence_classes(ostream &os, map<uchar, uchar> &eq);
|
void dump_equivalence_classes(ostream &os, map<transchar, transchar> &eq);
|
||||||
|
|
||||||
#endif /* __LIBAA_RE_HFA_H */
|
#endif /* __LIBAA_RE_HFA_H */
|
||||||
|
@ -38,17 +38,17 @@ void regex_error(Node **, const char *, const char *);
|
|||||||
#define YYLEX_PARAM &text
|
#define YYLEX_PARAM &text
|
||||||
int regex_lex(YYSTYPE *, const char **);
|
int regex_lex(YYSTYPE *, const char **);
|
||||||
|
|
||||||
static inline Chars *insert_char(Chars* cset, uchar a)
|
static inline Chars *insert_char(Chars* cset, transchar a)
|
||||||
{
|
{
|
||||||
cset->insert(a);
|
cset->insert(a);
|
||||||
return cset;
|
return cset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Chars* insert_char_range(Chars* cset, uchar a, uchar b)
|
static inline Chars* insert_char_range(Chars* cset, transchar a, transchar b)
|
||||||
{
|
{
|
||||||
if (a > b)
|
if (a > b)
|
||||||
swap(a, b);
|
swap(a, b);
|
||||||
for (uchar i = a; i <= b; i++)
|
for (transchar i = a; i <= b; i++)
|
||||||
cset->insert(i);
|
cset->insert(i);
|
||||||
return cset;
|
return cset;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user