parser: rename uchar to transchar

Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2019-08-08 00:41:57 -07:00
parent daa10d3ce1
commit 72f93d9aba
8 changed files with 53 additions and 53 deletions

View file

@ -257,7 +257,7 @@ void *aare_rules::create_dfa(size_t *size, int *min_match_len, dfaflags_t flags)
if (flags & DFA_DUMP_GRAPH)
dfa.dump_dot_graph(cerr);
map<uchar, uchar> eq;
map<transchar, transchar> eq;
if (flags & DFA_CONTROL_EQUIV) {
eq = dfa.equivalence_classes(flags);
dfa.apply_equivalence_classes(eq);

View file

@ -49,7 +49,7 @@ void CHFA::init_free_list(vector<pair<size_t, size_t> > &free_list,
/**
* 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)
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;
else {
max_eq = 0;
for (map<uchar, uchar>::iterator i = eq.begin();
for (map<transchar, transchar>::iterator i = eq.begin();
i != eq.end(); i++) {
if (i->second > max_eq)
max_eq = i->second;
@ -291,7 +291,7 @@ void CHFA::dump(ostream &os)
if (eq.size())
os << offs;
else
os << (uchar) offs;
os << (transchar) offs;
}
os << "\n";
}
@ -379,7 +379,7 @@ void CHFA::flex_table(ostream &os, const char *name)
vector<uint8_t> equiv_vec;
if (eq.size()) {
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;
}
}

View file

@ -36,7 +36,7 @@ class CHFA {
typedef vector<pair<const State *, size_t> > DefaultBase;
typedef vector<pair<const State *, const State *> > NextCheck;
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 flex_table(ostream &os, const char *name);
void init_free_list(vector<pair<size_t, size_t> > &free_list,
@ -52,8 +52,8 @@ class CHFA {
DefaultBase default_base;
NextCheck next_check;
map<const State *, size_t> num;
map<uchar, uchar> &eq;
uchar max_eq;
map<transchar, transchar> &eq;
transchar max_eq;
size_t first_free;
unsigned int chfaflags;
};

View file

@ -41,7 +41,7 @@
/* Use a single static EpsNode as it carries no node specific information */
EpsNode epsnode;
ostream &operator<<(ostream &os, uchar c)
ostream &operator<<(ostream &os, transchar c)
{
const char *search = "\a\033\f\n\r\t|*+[](). ",
*replace = "aefnrt|*+[](). ", *s;

View file

@ -45,38 +45,38 @@
using namespace std;
class uchar {
class transchar {
public:
short c;
uchar(unsigned char a): c((unsigned short) a) {}
uchar(const uchar &a): c(a.c) {}
uchar(): c(0) {}
transchar(unsigned char a): c((unsigned short) a) {}
transchar(const transchar &a): c(a.c) {}
transchar(): c(0) {}
bool operator==(const uchar &rhs) const {
bool operator==(const transchar &rhs) const {
return this->c == rhs.c;
}
bool operator==(const int &rhs) const {
return this->c == rhs;
}
bool operator!=(const uchar &rhs) const {
bool operator!=(const transchar &rhs) const {
return this->c != rhs.c;
}
bool operator>(const uchar &rhs) const {
bool operator>(const transchar &rhs) const {
return this->c > rhs.c;
}
bool operator<(const uchar &rhs) const {
bool operator<(const transchar &rhs) const {
return this->c < rhs.c;
}
bool operator<=(const uchar &rhs) const {
bool operator<=(const transchar &rhs) const {
return this->c <= rhs.c;
}
uchar &operator++() { // prefix
transchar &operator++() { // prefix
(this->c)++;
return *this;
}
uchar operator++(int) { // postfix
uchar tmp(*this);
transchar operator++(int) { // postfix
transchar tmp(*this);
(this->c)++;
return tmp;
}
@ -85,9 +85,9 @@ public:
class Chars {
public:
set<uchar> chars;
set<transchar> chars;
typedef set<uchar>::iterator iterator;
typedef set<transchar>::iterator iterator;
iterator begin() { return chars.begin(); }
iterator end() { return chars.end(); }
@ -101,23 +101,23 @@ public:
{
return chars.size();
}
iterator find(const uchar &key)
iterator find(const transchar &key)
{
return chars.find(key);
}
pair<iterator,bool> insert(uchar c)
pair<iterator,bool> insert(transchar c)
{
return chars.insert(c);
}
pair<iterator,bool> insert(char c)
{
uchar tmp(c);
transchar tmp(c);
return chars.insert(tmp);
}
};
ostream &operator<<(ostream &os, uchar c);
ostream &operator<<(ostream &os, transchar c);
/* Compute the union of two sets. */
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.
*/
typedef struct Cases {
typedef map<uchar, NodeSet *>::iterator iterator;
typedef map<transchar, NodeSet *>::iterator iterator;
iterator begin() { return cases.begin(); }
iterator end() { return cases.end(); }
Cases(): otherwise(0) { }
map<uchar, NodeSet *> cases;
map<transchar, NodeSet *> cases;
NodeSet *otherwise;
} Cases;
@ -334,7 +334,7 @@ public:
/* Match one specific character (/c/). */
class CharNode: public CNode {
public:
CharNode(uchar c): c(c) { }
CharNode(transchar c): c(c) { }
void follow(Cases &cases)
{
NodeSet **x = &cases.cases[c];
@ -370,7 +370,7 @@ public:
bool contains_null() { return c == 0; }
uchar c;
transchar c;
};
/* Match a set of characters (/[abc]/). */

View file

@ -1160,10 +1160,10 @@ void DFA::dump_dot_graph(ostream & os)
* Compute character equivalence classes in the DFA to save space in the
* transition table.
*/
map<uchar, uchar> DFA::equivalence_classes(dfaflags_t flags)
map<transchar, transchar> DFA::equivalence_classes(dfaflags_t flags)
{
map<uchar, uchar> classes;
uchar next_class = 1;
map<transchar, transchar> classes;
transchar next_class = 1;
for (Partition::iterator i = states.begin(); i != states.end(); i++) {
/* 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();
j != node_sets.end(); j++) {
/* Group edges to the same next state together by class */
map<uchar, Chars> node_classes;
map<transchar, Chars> node_classes;
bool class_used = false;
for (Chars::iterator k = j->second.begin();
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)
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);
}
if (class_used) {
next_class++;
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++) {
/**
* If any other characters are in the same class, move
* the characters in this class into their own new
* class
*/
map<uchar, uchar>::iterator l;
map<transchar, transchar>::iterator l;
for (l = classes.begin(); l != classes.end(); l++) {
if (l->second == k->first &&
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).
*/
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.insert(i->first);
}
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 << ':';
Chars &chars = i->second;
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
* 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
* contain the original characters.
*/
for (Partition::iterator i = states.begin(); i != states.end(); i++) {
map<uchar, State *> tmp;
map<transchar, State *> tmp;
tmp.swap((*i)->trans);
for (StateTrans::iterator j = tmp.begin(); j != tmp.end(); j++)
(*i)->trans.insert(make_pair(eq[j->first], j->second));

View file

@ -37,7 +37,7 @@
class State;
typedef map<uchar, State *> StateTrans;
typedef map<transchar, State *> StateTrans;
typedef list<State *> Partition;
#include "../immunix.h"
@ -212,7 +212,7 @@ public:
}
};
State *next(uchar c) {
State *next(transchar c) {
State *state = this;
do {
StateTrans::iterator i = state->trans.find(c);
@ -326,8 +326,8 @@ public:
void dump_dot_graph(ostream &os);
void dump_uniq_perms(const char *s);
map<uchar, uchar> equivalence_classes(dfaflags_t flags);
void apply_equivalence_classes(map<uchar, uchar> &eq);
map<transchar, transchar> equivalence_classes(dfaflags_t flags);
void apply_equivalence_classes(map<transchar, transchar> &eq);
unsigned int diffcount;
Node *root;
@ -335,6 +335,6 @@ public:
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 */

View file

@ -38,17 +38,17 @@ void regex_error(Node **, const char *, const char *);
#define YYLEX_PARAM &text
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);
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)
swap(a, b);
for (uchar i = a; i <= b; i++)
for (transchar i = a; i <= b; i++)
cset->insert(i);
return cset;
}