src
Classes | Typedefs | Enumerations | Functions | Variables
re2c Namespace Reference

Classes

class  Action
 
class  AltOp
 
struct  Binary
 
class  BitMap
 
struct  Case
 
struct  Cases
 
class  CatOp
 
class  CloseOp
 
struct  Code
 
struct  Cond
 
class  counter_t
 
struct  Cpgoto
 
struct  CpgotoTable
 
class  DFA
 
struct  dfa_state_t
 
struct  dfa_t
 
struct  Dot
 
class  Enc
 
struct  ExtOp
 
class  free_list
 
struct  Go
 
struct  GoBitmap
 
struct  HeaderFile
 
struct  If
 
struct  Initial
 
struct  Input
 
class  InputAPI
 
class  label_t
 
struct  Linear
 
struct  Loc
 
struct  local_increment_t
 
class  MatchOp
 
struct  nfa_state_t
 
struct  nfa_t
 
struct  Node
 
class  NullOp
 
struct  Opt
 
struct  opt_t
 
class  ord_hash_set_t
 
struct  Output
 
struct  OutputBlock
 
struct  OutputFile
 
struct  OutputFragment
 
class  path_t
 
class  Range
 
struct  RangeSuffix
 
class  realopt_t
 
class  RegExp
 
struct  rule_info_t
 
class  rule_rank_t
 
struct  rule_t
 
class  RuleOp
 
class  Scanner
 
struct  ScannerState
 
struct  Skeleton
 
class  smart_ptr
 
struct  Span
 
struct  Spec
 
struct  State
 
struct  static_assert_t
 
struct  static_assert_t< true >
 
struct  SwitchIf
 
class  uniq_vector_t
 
class  useropt_t
 
class  utf16
 
class  utf8
 
class  Warn
 

Typedefs

typedef std::vector< std::string > RegExpIndices
 
typedef uniq_vector_t< const State * > accept_t
 
typedef std::vector< uint32_t > charset_t
 
typedef std::vector< std::pair< uint32_t, uint32_t > > way_arc_t
 
typedef std::vector< const way_arc_t * > way_t
 
typedef std::set< std::string > CondList
 
typedef std::list< RuleOp * > RuleOpList
 
typedef std::map< std::string, SpecSpecMap
 
typedef std::map< std::string, std::pair< uint32_t, std::string > > SetupMap
 
typedef std::map< std::string, const Code * > DefaultMap
 
typedef std::map< std::string, RegExp * > symbol_table_t
 
typedef std::map< rule_rank_t, rule_info_trules_t
 

Enumerations

enum  parse_opts_t { OK, EXIT_OK, EXIT_FAIL }
 
enum  dfa_minimization_t { DFA_MINIMIZATION_TABLE, DFA_MINIMIZATION_MOORE }
 
enum  empty_class_policy_t { EMPTY_CLASS_MATCH_EMPTY, EMPTY_CLASS_MATCH_NONE, EMPTY_CLASS_ERROR }
 

Functions

static void doGen (const Go *g, const State *s, uint32_t *bm, uint32_t f, uint32_t m)
 
bool matches (const Span *b1, uint32_t n1, const State *s1, const Span *b2, uint32_t n2, const State *s2)
 
void emit_action (const Action &action, OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const std::string &condName, const Skeleton *skeleton, const std::set< label_t > &used_labels, bool save_yyaccept)
 
void genGoTo (OutputFile &o, uint32_t ind, const State *from, const State *to, bool &readCh)
 
template<typename _Ty >
std::string replaceParam (std::string str, const std::string &param, const _Ty &value)
 
static void need (OutputFile &o, uint32_t ind, bool &readCh, size_t n, bool bSetMarker)
 
static void emit_match (OutputFile &o, uint32_t ind, bool &readCh, const State *const s)
 
static void emit_initial (OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const Initial &init, const std::set< label_t > &used_labels)
 
static void emit_save (OutputFile &o, uint32_t ind, bool &readCh, const State *const s, uint32_t save, bool save_yyaccept)
 
static void emit_accept_binary (OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const accept_t &accept, size_t l, size_t r)
 
static void emit_accept (OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const accept_t &accept)
 
static void emit_rule (OutputFile &o, uint32_t ind, const State *const s, const RuleOp *const rule, const std::string &condName, const Skeleton *skeleton)
 
static void genYYFill (OutputFile &o, size_t need)
 
static void genSetCondition (OutputFile &o, uint32_t ind, const std::string &newcond)
 
static void genSetState (OutputFile &o, uint32_t ind, uint32_t fillIndex)
 
static std::string genGetCondition ()
 
static void genCondGotoSub (OutputFile &o, uint32_t ind, const std::vector< std::string > &condnames, uint32_t cMin, uint32_t cMax)
 
static void genCondTable (OutputFile &o, uint32_t ind, const std::vector< std::string > &condnames)
 
static void genCondGoto (OutputFile &o, uint32_t ind, const std::vector< std::string > &condnames)
 
static void emit_state (OutputFile &o, uint32_t ind, const State *s, bool used_label)
 
static uint32_t unmap (Span *new_span, const Span *old_span, uint32_t old_nspans, const State *x)
 
static void output_if (OutputFile &o, uint32_t ind, bool &readCh, const std::string &compare, uint32_t value)
 
static void output_goto (OutputFile &o, uint32_t ind, bool &readCh, label_t to)
 
static std::string output_yych (bool &readCh)
 
static std::string output_hgo (OutputFile &o, uint32_t ind, bool &readCh, SwitchIf *hgo)
 
std::string indent (uint32_t ind)
 
std::ostream & operator<< (std::ostream &o, label_t l)
 
void output_state_goto (std::ostream &o, uint32_t ind, uint32_t start_label)
 
void output_yyaccept_init (std::ostream &o, uint32_t ind, bool used_yyaccept)
 
void output_yymaxfill (std::ostream &o, size_t max_fill)
 
void output_line_info (std::ostream &o, uint32_t line_number, const char *file_name)
 
void output_types (std::ostream &o, uint32_t ind, const std::vector< std::string > &types)
 
void output_version_time (std::ostream &o)
 
std::string output_get_state ()
 
bool is_print (uint32_t c)
 
bool is_space (uint32_t c)
 
char hexCh (uint32_t c)
 
void prtChOrHex (std::ostream &o, uint32_t c)
 
void prtHex (std::ostream &o, uint32_t c)
 
void prtCh (std::ostream &o, uint32_t c)
 
void prtChOrHexForSpan (std::ostream &o, uint32_t c)
 
void printSpan (std::ostream &o, uint32_t lb, uint32_t ub)
 
void error (const char *fmt,...)
 
void error_encoding ()
 
void error_arg (const char *option)
 
void warning_start (uint32_t line, bool error)
 
void warning_end (const char *type, bool error)
 
void warning (const char *type, uint32_t line, bool error, const char *fmt,...)
 
void usage ()
 
void vernum ()
 
void version ()
 
std::string incond (const std::string &cond)
 
parse_opts_t parse_opts (char **argv, Opt &opts)
 
static uint32_t merge (Span *x0, State *fg, State *bg)
 
static std::string make_name (const std::string &cond, uint32_t line)
 
smart_ptr< DFAcompile (Spec &spec, Output &output, const std::string &cond, uint32_t cunits)
 
static nfa_state_t ** closure (nfa_state_t **cP, nfa_state_t *n)
 
static size_t find_state (nfa_state_t **kernel, nfa_state_t **end, ord_hash_set_t &kernels)
 
void minimization (dfa_t &dfa)
 
void fillpoints (const dfa_t &dfa, std::vector< size_t > &fill)
 
static bool loopback (size_t node, size_t narcs, const size_t *arcs)
 
static void scc (const dfa_t &dfa, std::stack< size_t > &stack, std::vector< size_t > &lowlink, std::vector< bool > &trivial, size_t i)
 
static void calc_fill (const dfa_t &dfa, const std::vector< bool > &trivial, std::vector< size_t > &fill, size_t i)
 
static void minimization_table (size_t *part, const std::vector< dfa_state_t * > &states, size_t nchars)
 
static void minimization_moore (size_t *part, const std::vector< dfa_state_t * > &states, size_t nchars)
 
std::ostream & operator<< (std::ostream &o, const RegExp &re)
 
bool is_alpha (uint32_t c)
 
uint32_t to_lower_unsafe (uint32_t c)
 
uint32_t to_upper_unsafe (uint32_t c)
 
static RegExpemit (RangeSuffix *p, RegExp *re)
 
RegExpto_regexp (RangeSuffix *p)
 
void UTF16addContinuous1 (RangeSuffix *&root, uint32_t l, uint32_t h)
 
void UTF16addContinuous2 (RangeSuffix *&root, uint32_t l_ld, uint32_t h_ld, uint32_t l_tr, uint32_t h_tr)
 
void UTF16splitByContinuity (RangeSuffix *&root, uint32_t l_ld, uint32_t h_ld, uint32_t l_tr, uint32_t h_tr)
 
void UTF16splitByRuneLength (RangeSuffix *&root, utf16::rune l, utf16::rune h)
 
RegExpUTF16Symbol (utf16::rune r)
 
RegExpUTF16Range (const Range *r)
 
void UTF8addContinuous (RangeSuffix *&root, utf8::rune l, utf8::rune h, uint32_t n)
 
void UTF8splitByContinuity (RangeSuffix *&root, utf8::rune l, utf8::rune h, uint32_t n)
 
void UTF8splitByRuneLength (RangeSuffix *&root, utf8::rune l, utf8::rune h)
 
RegExpUTF8Symbol (utf8::rune r)
 
RegExpUTF8Range (const Range *r)
 
static MatchOpmerge (MatchOp *m1, MatchOp *m2)
 
RegExpdoAlt (RegExp *e1, RegExp *e2)
 
RegExpmkAlt (RegExp *e1, RegExp *e2)
 
RegExpdoCat (RegExp *e1, RegExp *e2)
 
RegExprepeat (RegExp *e, uint32_t n)
 
RegExprepeat_from_to (RegExp *e, uint32_t n, uint32_t m)
 
RegExprepeat_from (RegExp *e, uint32_t n)
 
std::ostream & operator<< (std::ostream &o, rule_rank_t r)
 
static void exact_uint (OutputFile &o, size_t width)
 
static void from_le (OutputFile &o, uint32_t ind, size_t size, const char *expr)
 
template<typename cunit_t , typename key_t >
static Node::covers_t cover_one (FILE *input, FILE *keys, const path_t &path)
 
template<typename uintn_t >
static uintn_t to_le (uintn_t n)
 
template<typename key_t >
static void keygen (FILE *f, size_t count, size_t len, size_t len_match, rule_rank_t match)
 
static bool cmp_way_arcs (const way_arc_t *a1, const way_arc_t *a2)
 
static void fprint_way_arc (FILE *f, const way_arc_t &arc)
 
bool cmp_ways (const way_t &w1, const way_t &w2)
 
void fprint_way (FILE *f, const way_t &w)
 
void parse (Scanner &, Output &)
 
void parse_cleanup ()
 
static uint32_t hex_digit (const char c)
 
uint32_t unesc_hex (const char *s, const char *s_end)
 
uint32_t unesc_oct (const char *s, const char *s_end)
 
template<typename T >
T * allocate (size_t n)
 
template<typename T >
smart_ptr< T > make_smart_ptr (T *p)
 

Variables

Opt opts
 
Warn warn
 
bool bUsedYYBitmap = false
 
bool bWroteGetState = false
 
bool bWroteCondCheck = false
 
uint32_t last_fill_index = 0
 
std::string yySetupRule = ""
 
static const size_t INFINITY = std::numeric_limits<size_t>::max()
 
static const size_t UNDEFINED = INFINITY - 1
 

Typedef Documentation

Definition at line 28 of file action.h.

typedef std::vector<uint32_t> re2c::charset_t

Definition at line 16 of file regexp.h.

typedef std::set<std::string> re2c::CondList

Definition at line 19 of file parser.h.

typedef std::map<std::string, const Code *> re2c::DefaultMap

Definition at line 23 of file parser.h.

typedef std::vector<std::string> re2c::RegExpIndices

Definition at line 9 of file emit.h.

typedef std::list<RuleOp*> re2c::RuleOpList

Definition at line 20 of file parser.h.

Definition at line 25 of file rules.h.

typedef std::map<std::string, std::pair<uint32_t, std::string> > re2c::SetupMap

Definition at line 22 of file parser.h.

typedef std::map<std::string, Spec> re2c::SpecMap

Definition at line 21 of file parser.h.

typedef std::map<std::string, RegExp *> re2c::symbol_table_t

Definition at line 24 of file parser.h.

typedef std::vector<std::pair<uint32_t, uint32_t> > re2c::way_arc_t

Definition at line 12 of file way.h.

typedef std::vector<const way_arc_t *> re2c::way_t

Definition at line 13 of file way.h.

Enumeration Type Documentation

Enumerator
DFA_MINIMIZATION_TABLE 
DFA_MINIMIZATION_MOORE 

Definition at line 47 of file dfa.h.

Enumerator
EMPTY_CLASS_MATCH_EMPTY 
EMPTY_CLASS_MATCH_NONE 
EMPTY_CLASS_ERROR 

Definition at line 6 of file empty_class_policy.h.

7 {
8  EMPTY_CLASS_MATCH_EMPTY, // match on empty input
9  EMPTY_CLASS_MATCH_NONE, // fail to match on any input
10  EMPTY_CLASS_ERROR // compilation error
11 };
Enumerator
OK 
EXIT_OK 
EXIT_FAIL 

Definition at line 207 of file opt.h.

208 {
209  OK,
210  EXIT_OK,
211  EXIT_FAIL
212 };
Definition: opt.h:209

Function Documentation

template<typename T >
T* re2c::allocate ( size_t  n)

Definition at line 11 of file allocate.h.

12 {
13  void * p = operator new (n * sizeof (T));
14  return static_cast<T *> (p);
15 }
static void re2c::calc_fill ( const dfa_t dfa,
const std::vector< bool > &  trivial,
std::vector< size_t > &  fill,
size_t  i 
)
static

Definition at line 96 of file fillpoints.cc.

101 {
102  if (fill[i] == UNDEFINED)
103  {
104  fill[i] = 0;
105  const size_t *arcs = dfa.states[i]->arcs;
106  for (size_t c = 0; c < dfa.nchars; ++c)
107  {
108  const size_t j = arcs[c];
109  if (j != dfa_t::NIL)
110  {
111  calc_fill(dfa, trivial, fill, j);
112  size_t max = 1;
113  if (trivial[j])
114  {
115  max += fill[j];
116  }
117  if (max > fill[i])
118  {
119  fill[i] = max;
120  }
121  }
122  }
123  }
124 }
static void calc_fill(const dfa_t &dfa, const std::vector< bool > &trivial, std::vector< size_t > &fill, size_t i)
Definition: fillpoints.cc:96
static const size_t UNDEFINED
Definition: fillpoints.cc:11

Here is the caller graph for this function:

static nfa_state_t** re2c::closure ( nfa_state_t **  cP,
nfa_state_t n 
)
static

Definition at line 44 of file determinization.cc.

45 {
46  if (!n->mark)
47  {
48  n->mark = true;
49  switch (n->type)
50  {
51  case nfa_state_t::ALT:
52  cP = closure(cP, n->value.alt.out2);
53  cP = closure(cP, n->value.alt.out1);
54  n->mark = false;
55  break;
56  case nfa_state_t::CTX:
57  *(cP++) = n;
58  cP = closure(cP, n->value.ctx.out);
59  break;
60  default:
61  *(cP++) = n;
62  break;
63  }
64  }
65 
66  return cP;
67 }
static nfa_state_t ** closure(nfa_state_t **cP, nfa_state_t *n)

Here is the caller graph for this function:

bool re2c::cmp_way_arcs ( const way_arc_t a1,
const way_arc_t a2 
)
static

Definition at line 12 of file way.cc.

13 {
14  return std::lexicographical_compare(a1->begin(), a1->end(), a2->begin(), a2->end());
15 }

Here is the caller graph for this function:

bool re2c::cmp_ways ( const way_t w1,
const way_t w2 
)

Definition at line 20 of file way.cc.

21 {
22  const size_t s1 = w1.size ();
23  const size_t s2 = w2.size ();
24  return (s1 == s2 && std::lexicographical_compare(w1.begin(), w1.end(), w2.begin(), w2.end(), cmp_way_arcs))
25  || s1 < s2;
26 }
static bool cmp_way_arcs(const way_arc_t *a1, const way_arc_t *a2)
Definition: way.cc:12

Here is the call graph for this function:

Here is the caller graph for this function:

smart_ptr< DFA > re2c::compile ( Spec spec,
Output output,
const std::string &  cond,
uint32_t  cunits 
)

Definition at line 29 of file compile.cc.

30 {
31  const uint32_t line = output.source.get_block_line();
32  const std::string name = make_name(cond, line);
33 
34  // The original set of code units (charset) might be very large.
35  // A common trick it is to split charset into disjoint character ranges
36  // and choose a representative of each range (we choose lower bound).
37  // The set of all representatives is the new (compacted) charset.
38  // Don't forget to include zero and upper bound, even if they
39  // do not explicitely apper in ranges.
40  std::set<uint32_t> bounds;
41  spec.re->split(bounds);
42  bounds.insert(0);
43  bounds.insert(cunits);
44  charset_t cs;
45  for (std::set<uint32_t>::const_iterator i = bounds.begin(); i != bounds.end(); ++i)
46  {
47  cs.push_back(*i);
48  }
49 
50  nfa_t nfa(spec.re);
51 
52  dfa_t dfa(nfa, cs, spec.rules);
53 
54  // skeleton must be constructed after DFA construction
55  // but prior to any other DFA transformations
56  Skeleton *skeleton = new Skeleton(dfa, cs, spec.rules, name, cond, line);
57 
58  minimization(dfa);
59 
60  // find YYFILL states and calculate argument to YYFILL
61  std::vector<size_t> fill;
62  fillpoints(dfa, fill);
63 
64  // ADFA stands for 'DFA with actions'
65  DFA *adfa = new DFA(dfa, fill, skeleton, cs, name, cond, line);
66 
67  /*
68  * note [reordering DFA states]
69  *
70  * re2c-generated code depends on the order of states in DFA: simply
71  * flipping two states may change the output significantly.
72  * The order of states is affected by many factors, e.g.:
73  * - flipping left and right subtrees of alternative when constructing
74  * AST (also applies to iteration and counted repetition)
75  * - changing the order in which graph nodes are visited (applies to
76  * any intermediate representation: bytecode, NFA, DFA, etc.)
77  *
78  * To make the resulting code independent of such changes, we hereby
79  * reorder DFA states. The ordering scheme is very simple:
80  *
81  * Starting with DFA root, walk DFA nodes in breadth-first order.
82  * Child nodes are ordered accoding to the (alphabetically) first symbol
83  * leading to each node. Each node must be visited exactly once.
84  * Default state (NULL) is always the last state.
85  */
86  adfa->reorder();
87 
88  // skeleton is constructed, do further DFA transformations
89  adfa->prepare();
90 
91  // finally gather overall DFA statistics
92  adfa->calc_stats();
93 
94  // accumulate global statistics from this particular DFA
95  output.max_fill = std::max (output.max_fill, adfa->max_fill);
96  if (adfa->need_accept)
97  {
98  output.source.set_used_yyaccept ();
99  }
100 
101  return make_smart_ptr(adfa);
102 }
std::vector< uint32_t > charset_t
Definition: regexp.h:16
smart_ptr< T > make_smart_ptr(T *p)
Definition: smart_ptr.h:63
void fillpoints(const dfa_t &dfa, std::vector< size_t > &fill)
Definition: fillpoints.cc:126
static std::string make_name(const std::string &cond, uint32_t line)
Definition: compile.cc:16
void minimization(dfa_t &dfa)

Here is the call graph for this function:

template<typename cunit_t , typename key_t >
static Node::covers_t re2c::cover_one ( FILE *  input,
FILE *  keys,
const path_t path 
)
static

Definition at line 179 of file generate_data.cc.

180 {
181  const size_t len = path.len ();
182 
183  size_t count = 0;
184  for (size_t i = 0; i < len; ++i)
185  {
186  count = std::max (count, path[i]->size ());
187  }
188 
189  const Node::covers_t size = Node::covers_t::from64(len) * Node::covers_t::from64(count);
190  if (!size.overflow ())
191  {
192  // input
193  const size_t buffer_size = size.uint32 ();
194  cunit_t * buffer = new cunit_t [buffer_size];
195  for (size_t i = 0; i < len; ++i)
196  {
197  const std::vector<uint32_t> & arc = *path[i];
198  const size_t width = arc.size ();
199  for (size_t j = 0; j < count; ++j)
200  {
201  const size_t k = j % width;
202  buffer[j * len + i] = to_le<cunit_t>(static_cast<cunit_t> (arc[k]));
203  }
204  }
205  fwrite (buffer, sizeof (cunit_t), buffer_size, input);
206  delete [] buffer;
207 
208  // keys
209  keygen<key_t> (keys, count, len, path.len_matching (), path.match ());
210  }
211 
212  return size;
213 }

Here is the call graph for this function:

RegExp * re2c::doAlt ( RegExp e1,
RegExp e2 
)

Definition at line 27 of file regexp.cc.

28 {
29  if (!e1)
30  {
31  return e2;
32  }
33  if (!e2)
34  {
35  return e1;
36  }
37  return new AltOp (e1, e2);
38 }

Here is the caller graph for this function:

RegExp * re2c::doCat ( RegExp e1,
RegExp e2 
)

Definition at line 98 of file regexp.cc.

99 {
100  if (!e1)
101  {
102  return e2;
103  }
104  if (!e2)
105  {
106  return e1;
107  }
108  return new CatOp (e1, e2);
109 }

Here is the caller graph for this function:

static void re2c::doGen ( const Go g,
const State s,
uint32_t *  bm,
uint32_t  f,
uint32_t  m 
)
static

Definition at line 56 of file bitmap.cc.

57 {
58  Span *b = g->span, *e = &b[g->nSpans];
59  uint32_t lb = 0;
60 
61  for (; b < e; ++b)
62  {
63  if (b->to == s)
64  {
65  for (; lb < b->ub && lb < 256; ++lb)
66  {
67  bm[lb-f] |= m;
68  }
69  }
70 
71  lb = b->ub;
72  }
73 }

Here is the caller graph for this function:

RegExp * re2c::emit ( RangeSuffix p,
RegExp re 
)
static

Definition at line 22 of file range_suffix.cc.

23 {
24  if (p == NULL)
25  return re;
26  else
27  {
28  RegExp * regexp = NULL;
29  for (; p != NULL; p = p->next)
30  {
31  RegExp * re1 = doCat(new MatchOp(Range::ran (p->l, p->h + 1)), re);
32  regexp = doAlt(regexp, emit(p->child, re1));
33  }
34  return regexp;
35  }
36 }
RegExp * doAlt(RegExp *e1, RegExp *e2)
Definition: regexp.cc:27
static RegExp * emit(RangeSuffix *p, RegExp *re)
Definition: range_suffix.cc:22
RegExp * doCat(RegExp *e1, RegExp *e2)
Definition: regexp.cc:98

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_accept ( OutputFile o,
uint32_t  ind,
bool &  readCh,
const State *const  s,
const accept_t accept 
)
static

Definition at line 189 of file emit_action.cc.

190 {
191  const size_t accepts_size = accepts.size ();
192  if (accepts_size > 0)
193  {
194  if (opts->target != opt_t::DOT)
195  {
196  o.wstring(opts->input_api.stmt_restore (ind));
197  }
198 
199  if (readCh) // shouldn't be necessary, but might become at some point
200  {
201  o.wstring(opts->input_api.stmt_peek (ind));
202  readCh = false;
203  }
204 
205  if (accepts_size > 1)
206  {
207  if (opts->gFlag && accepts_size >= opts->cGotoThreshold)
208  {
209  o.wind(ind++).ws("{\n");
210  o.wind(ind++).ws("static void *").wstring(opts->yytarget).ws("[").wu64(accepts_size).ws("] = {\n");
211  for (uint32_t i = 0; i < accepts_size; ++i)
212  {
213  o.wind(ind).ws("&&").wstring(opts->labelPrefix).wlabel(accepts[i]->label).ws(",\n");
214  }
215  o.wind(--ind).ws("};\n");
216  o.wind(ind).ws("goto *").wstring(opts->yytarget).ws("[").wstring(opts->yyaccept).ws("];\n");
217  o.wind(--ind).ws("}\n");
218  }
219  else if (opts->sFlag || (accepts_size == 2 && opts->target != opt_t::DOT))
220  {
221  emit_accept_binary (o, ind, readCh, s, accepts, 0, accepts_size - 1);
222  }
223  else if (opts->target == opt_t::DOT)
224  {
225  for (uint32_t i = 0; i < accepts_size; ++i)
226  {
227  o.wlabel(s->label).ws(" -> ").wlabel(accepts[i]->label);
228  o.ws(" [label=\"yyaccept=").wu32(i).ws("\"]\n");
229  }
230  }
231  else
232  {
233  o.wind(ind).ws("switch (").wstring(opts->yyaccept).ws(") {\n");
234  for (uint32_t i = 0; i < accepts_size - 1; ++i)
235  {
236  o.wind(ind).ws("case ").wu32(i).ws(": \t");
237  genGoTo(o, 0, s, accepts[i], readCh);
238  }
239  o.wind(ind).ws("default:\t");
240  genGoTo(o, 0, s, accepts[accepts_size - 1], readCh);
241  o.wind(ind).ws("}\n");
242  }
243  }
244  else
245  {
246  // no need to write if statement here since there is only case 0.
247  genGoTo(o, ind, s, accepts[0], readCh);
248  }
249  }
250 }
std::string yytarget
Definition: opt.h:118
InputAPI input_api
Definition: opt.h:118
std::string stmt_restore(uint32_t ind) const
Definition: input_api.cc:95
static void emit_accept_binary(OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const accept_t &accept, size_t l, size_t r)
Definition: emit_action.cc:172
bool sFlag
Definition: opt.h:118
uint32_t cGotoThreshold
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
bool gFlag
Definition: opt.h:118
std::string yyaccept
Definition: opt.h:118
std::string labelPrefix
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
void genGoTo(OutputFile &o, uint32_t ind, const State *from, const State *to, bool &readCh)
Definition: emit_dfa.cc:37
std::string stmt_peek(uint32_t ind) const
Definition: input_api.cc:45

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_accept_binary ( OutputFile o,
uint32_t  ind,
bool &  readCh,
const State *const  s,
const accept_t accept,
size_t  l,
size_t  r 
)
static

Definition at line 172 of file emit_action.cc.

173 {
174  if (l < r)
175  {
176  const size_t m = (l + r) >> 1;
177  o.wind(ind).ws("if (").wstring(opts->yyaccept).ws(r == l+1 ? " == " : " <= ").wu64(m).ws(") {\n");
178  emit_accept_binary (o, ++ind, readCh, s, accepts, l, m);
179  o.wind(--ind).ws("} else {\n");
180  emit_accept_binary (o, ++ind, readCh, s, accepts, m + 1, r);
181  o.wind(--ind).ws("}\n");
182  }
183  else
184  {
185  genGoTo(o, ind, s, accepts[l], readCh);
186  }
187 }
static void emit_accept_binary(OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const accept_t &accept, size_t l, size_t r)
Definition: emit_action.cc:172
std::string yyaccept
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
void genGoTo(OutputFile &o, uint32_t ind, const State *from, const State *to, bool &readCh)
Definition: emit_dfa.cc:37

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_action ( const Action action,
OutputFile o,
uint32_t  ind,
bool &  readCh,
const State *const  s,
const std::string &  condName,
const Skeleton skeleton,
const std::set< label_t > &  used_labels,
bool  save_yyaccept 
)

Definition at line 36 of file emit_action.cc.

46 {
47  switch (action.type)
48  {
49  case Action::MATCH:
50  emit_match (o, ind, readCh, s);
51  break;
52  case Action::INITIAL:
53  emit_initial (o, ind, readCh, s, * action.info.initial, used_labels);
54  break;
55  case Action::SAVE:
56  emit_save (o, ind, readCh, s, action.info.save, save_yyaccept);
57  break;
58  case Action::MOVE:
59  break;
60  case Action::ACCEPT:
61  emit_accept (o, ind, readCh, s, * action.info.accepts);
62  break;
63  case Action::RULE:
64  emit_rule (o, ind, s, action.info.rule, condName, skeleton);
65  break;
66  }
67  if (s->isPreCtxt && opts->target != opt_t::DOT)
68  {
69  o.wstring(opts->input_api.stmt_backupctx (ind));
70  }
71 }
InputAPI input_api
Definition: opt.h:118
static void emit_initial(OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const Initial &init, const std::set< label_t > &used_labels)
Definition: emit_action.cc:105
opt_t::target_t target
Definition: opt.h:118
static void emit_match(OutputFile &o, uint32_t ind, bool &readCh, const State *const s)
Definition: emit_action.cc:73
std::string stmt_backupctx(uint32_t ind) const
Definition: input_api.cc:80
static void emit_accept(OutputFile &o, uint32_t ind, bool &readCh, const State *const s, const accept_t &accept)
Definition: emit_action.cc:189
Opt opts
Definition: opt.cc:7
static void emit_save(OutputFile &o, uint32_t ind, bool &readCh, const State *const s, uint32_t save, bool save_yyaccept)
Definition: emit_action.cc:148
static void emit_rule(OutputFile &o, uint32_t ind, const State *const s, const RuleOp *const rule, const std::string &condName, const Skeleton *skeleton)
Definition: emit_action.cc:252

Here is the call graph for this function:

void re2c::emit_initial ( OutputFile o,
uint32_t  ind,
bool &  readCh,
const State *const  s,
const Initial init,
const std::set< label_t > &  used_labels 
)
static

Definition at line 105 of file emit_action.cc.

106 {
107  if (opts->target == opt_t::DOT)
108  {
109  return;
110  }
111 
112  if (used_labels.count(s->label))
113  {
114  if (s->fill != 0)
115  {
116  o.wstring(opts->input_api.stmt_skip (ind));
117  }
118  else
119  {
120  o.wstring(opts->input_api.stmt_skip_peek (ind));
121  }
122  }
123 
124  if (used_labels.count(initial.label))
125  {
126  o.wstring(opts->labelPrefix).wlabel(initial.label).ws(":\n");
127  }
128 
129  if (opts->dFlag)
130  {
131  o.wind(ind).wstring(opts->yydebug).ws("(").wlabel(initial.label).ws(", *").wstring(opts->yycursor).ws(");\n");
132  }
133 
134  if (s->fill != 0)
135  {
136  need(o, ind, readCh, s->fill, initial.setMarker);
137  }
138  else
139  {
140  if (initial.setMarker)
141  {
142  o.wstring(opts->input_api.stmt_backup (ind));
143  }
144  readCh = false;
145  }
146 }
static void need(OutputFile &o, uint32_t ind, bool &readCh, size_t n, bool bSetMarker)
Definition: emit_action.cc:299
InputAPI input_api
Definition: opt.h:118
std::string yycursor
Definition: opt.h:118
bool dFlag
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
std::string stmt_skip(uint32_t ind) const
Definition: input_api.cc:50
std::string stmt_skip_peek(uint32_t ind) const
Definition: input_api.cc:125
std::string labelPrefix
Definition: opt.h:118
std::string stmt_backup(uint32_t ind) const
Definition: input_api.cc:65
Opt opts
Definition: opt.cc:7
std::string yydebug
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_match ( OutputFile o,
uint32_t  ind,
bool &  readCh,
const State *const  s 
)
static

Definition at line 73 of file emit_action.cc.

74 {
75  if (opts->target == opt_t::DOT)
76  {
77  return;
78  }
79 
80  const bool read_ahead = s
81  && s->next
82  && s->next->action.type != Action::RULE;
83  if (s->fill != 0)
84  {
85  o.wstring(opts->input_api.stmt_skip (ind));
86  }
87  else if (!read_ahead)
88  {
89  /* do not read next char if match */
90  o.wstring(opts->input_api.stmt_skip (ind));
91  readCh = true;
92  }
93  else
94  {
95  o.wstring(opts->input_api.stmt_skip_peek (ind));
96  readCh = false;
97  }
98 
99  if (s->fill != 0)
100  {
101  need(o, ind, readCh, s->fill, false);
102  }
103 }
static void need(OutputFile &o, uint32_t ind, bool &readCh, size_t n, bool bSetMarker)
Definition: emit_action.cc:299
InputAPI input_api
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
std::string stmt_skip(uint32_t ind) const
Definition: input_api.cc:50
std::string stmt_skip_peek(uint32_t ind) const
Definition: input_api.cc:125
Opt opts
Definition: opt.cc:7

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_rule ( OutputFile o,
uint32_t  ind,
const State *const  s,
const RuleOp *const  rule,
const std::string &  condName,
const Skeleton skeleton 
)
static

Definition at line 252 of file emit_action.cc.

253 {
254  if (opts->target == opt_t::DOT)
255  {
256  o.wlabel(s->label);
257  if (rule->code)
258  {
259  o.ws(" [label=\"").wstring(rule->code->loc.filename).ws(":").wu32(rule->code->loc.line).ws("\"]");
260  }
261  o.ws("\n");
262  return;
263  }
264 
265  uint32_t back = rule->ctx->fixedLength();
266  if (back != 0u && opts->target != opt_t::DOT)
267  {
268  o.wstring(opts->input_api.stmt_restorectx (ind));
269  }
270 
271  if (opts->target == opt_t::SKELETON)
272  {
273  skeleton->emit_action (o, ind, rule->rank);
274  }
275  else
276  {
277  if (!rule->newcond.empty () && condName != rule->newcond)
278  {
279  genSetCondition(o, ind, rule->newcond);
280  }
281 
282  if (rule->code)
283  {
284  if (!yySetupRule.empty ())
285  {
286  o.wind(ind).wstring(yySetupRule).ws("\n");
287  }
288  o.wline_info(rule->code->loc.line, rule->code->loc.filename.c_str ())
289  .wind(ind).wstring(rule->code->text).ws("\n")
290  .wdelay_line_info ();
291  }
292  else if (!rule->newcond.empty ())
293  {
294  o.wind(ind).wstring(replaceParam(opts->condGoto, opts->condGotoParam, opts->condPrefix + rule->newcond)).ws("\n");
295  }
296  }
297 }
std::string replaceParam(std::string str, const std::string &param, const _Ty &value)
Definition: emit.h:26
std::string condPrefix
Definition: opt.h:118
std::string stmt_restorectx(uint32_t ind) const
Definition: input_api.cc:110
InputAPI input_api
Definition: opt.h:118
std::string yySetupRule
Definition: main.cc:20
opt_t::target_t target
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string condGotoParam
Definition: opt.h:118
static void genSetCondition(OutputFile &o, uint32_t ind, const std::string &newcond)
Definition: emit_action.cc:368
std::string condGoto
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_save ( OutputFile o,
uint32_t  ind,
bool &  readCh,
const State *const  s,
uint32_t  save,
bool  save_yyaccept 
)
static

Definition at line 148 of file emit_action.cc.

149 {
150  if (opts->target == opt_t::DOT)
151  {
152  return;
153  }
154 
155  if (save_yyaccept)
156  {
157  o.wind(ind).wstring(opts->yyaccept).ws(" = ").wu32(save).ws(";\n");
158  }
159 
160  if (s->fill != 0)
161  {
162  o.wstring(opts->input_api.stmt_skip_backup (ind));
163  need(o, ind, readCh, s->fill, false);
164  }
165  else
166  {
167  o.wstring(opts->input_api.stmt_skip_backup_peek (ind));
168  readCh = false;
169  }
170 }
static void need(OutputFile &o, uint32_t ind, bool &readCh, size_t n, bool bSetMarker)
Definition: emit_action.cc:299
InputAPI input_api
Definition: opt.h:118
std::string stmt_skip_backup(uint32_t ind) const
Definition: input_api.cc:132
opt_t::target_t target
Definition: opt.h:118
std::string yyaccept
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string stmt_skip_backup_peek(uint32_t ind) const
Definition: input_api.cc:146

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::emit_state ( OutputFile o,
uint32_t  ind,
const State s,
bool  used_label 
)
static

Definition at line 54 of file emit_dfa.cc.

55 {
56  if (opts->target != opt_t::DOT)
57  {
58  if (used_label)
59  {
60  o.wstring(opts->labelPrefix).wlabel(s->label).ws(":\n");
61  }
62  if (opts->dFlag && (s->action.type != Action::INITIAL))
63  {
64  o.wind(ind).wstring(opts->yydebug).ws("(").wlabel(s->label).ws(", ").wstring(opts->input_api.expr_peek ()).ws(");\n");
65  }
66  }
67 }
std::string expr_peek() const
Definition: input_api.cc:25
InputAPI input_api
Definition: opt.h:118
bool dFlag
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
std::string labelPrefix
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string yydebug
Definition: opt.h:118

Here is the call graph for this function:

void re2c::error ( const char *  fmt,
  ... 
)

Definition at line 10 of file msg.cc.

11 {
12  fprintf (stderr, "re2c: error: ");
13 
14  va_list args;
15  va_start (args, fmt);
16  vfprintf (stderr, fmt, args);
17  va_end (args);
18 
19  fprintf (stderr, "\n");
20 }

Here is the caller graph for this function:

void re2c::error_arg ( const char *  option)

Definition at line 27 of file msg.cc.

28 {
29  error ("expected argument to option %s", option);
30 }
void error(const char *fmt,...)
Definition: msg.cc:10

Here is the call graph for this function:

void void re2c::error_encoding ( )

Definition at line 22 of file msg.cc.

23 {
24  error ("only one of switches -e, -w, -x, -u and -8 must be set");
25 }
void error(const char *fmt,...)
Definition: msg.cc:10

Here is the call graph for this function:

static void re2c::exact_uint ( OutputFile o,
size_t  width 
)
static

Definition at line 18 of file generate_code.cc.

19 {
20  if (width == sizeof (char))
21  {
22  o.ws("unsigned char");
23  }
24  else if (width == sizeof (short))
25  {
26  o.ws("unsigned short");
27  }
28  else if (width == sizeof (int))
29  {
30  o.ws("unsigned int");
31  }
32  else if (width == sizeof (long))
33  {
34  o.ws("unsigned long");
35  }
36  else
37  {
38  o.ws("uint").wu64 (width * 8).ws("_t");
39  }
40 }

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::fillpoints ( const dfa_t dfa,
std::vector< size_t > &  fill 
)

Definition at line 126 of file fillpoints.cc.

127 {
128  const size_t size = dfa.states.size();
129 
130  // find DFA states that belong to non-trivial SCC
131  std::stack<size_t> stack;
132  std::vector<size_t> lowlink(size, UNDEFINED);
133  std::vector<bool> trivial(size, false);
134  scc(dfa, stack, lowlink, trivial, 0);
135 
136  // for each DFA state, calculate YYFILL argument:
137  // maximal path length to the next YYFILL state
138  fill.resize(size, UNDEFINED);
139  calc_fill(dfa, trivial, fill, 0);
140 
141  // The following states must trigger YYFILL:
142  // - inital state
143  // - all states in non-trivial SCCs
144  // for other states, reset YYFILL argument to zero
145  for (size_t i = 1; i < size; ++i)
146  {
147  if (trivial[i])
148  {
149  fill[i] = 0;
150  }
151  }
152 }
static void scc(const dfa_t &dfa, std::stack< size_t > &stack, std::vector< size_t > &lowlink, std::vector< bool > &trivial, size_t i)
Definition: fillpoints.cc:49
static void calc_fill(const dfa_t &dfa, const std::vector< bool > &trivial, std::vector< size_t > &fill, size_t i)
Definition: fillpoints.cc:96
static const size_t UNDEFINED
Definition: fillpoints.cc:11

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t re2c::find_state ( nfa_state_t **  kernel,
nfa_state_t **  end,
ord_hash_set_t kernels 
)
static

Definition at line 70 of file determinization.cc.

74 {
75  // zero-sized kernel corresponds to default state
76  if (kernel == end)
77  {
78  return dfa_t::NIL;
79  }
80 
81  // see note [marking DFA states]
82  for (nfa_state_t **p = kernel; p != end; ++p)
83  {
84  (*p)->mark = false;
85  }
86 
87  // sort kernel states: we need this to get stable hash
88  // and to compare states with simple 'memcmp'
89  std::sort(kernel, end);
90  const size_t size = static_cast<size_t>(end - kernel) * sizeof(nfa_state_t*);
91  return kernels.insert(kernel, size);
92 }

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::fprint_way ( FILE *  f,
const way_t w 
)

Definition at line 28 of file way.cc.

29 {
30  fprintf (f, "'");
31  const size_t len = w.size ();
32  for (size_t i = 0 ; i < len; ++i)
33  {
34  if (i > 0)
35  {
36  fprintf (f, " ");
37  }
38  if (w[i] == NULL)
39  {
40  fprintf (stderr, "(nil)");
41  }
42  else
43  {
44  fprint_way_arc (stderr, *w[i]);
45  }
46  }
47  fprintf (f, "'");
48 }
static void fprint_way_arc(FILE *f, const way_arc_t &arc)
Definition: way.cc:50

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::fprint_way_arc ( FILE *  f,
const way_arc_t arc 
)
static

Definition at line 50 of file way.cc.

51 {
52  const size_t ranges = arc.size ();
53  if (ranges == 1 && arc[0].first == arc[0].second)
54  {
55  fprintf (f, "\\x%X", arc[0].first);
56  }
57  else
58  {
59  fprintf (f, "[");
60  for (size_t i = 0; i < ranges; ++i)
61  {
62  const uint32_t l = arc[i].first;
63  const uint32_t u = arc[i].second;
64  fprintf (f, "\\x%X", l);
65  if (l != u)
66  {
67  fprintf (f, "-\\x%X", u);
68  }
69  }
70  fprintf (f, "]");
71  }
72 }

Here is the caller graph for this function:

static void re2c::from_le ( OutputFile o,
uint32_t  ind,
size_t  size,
const char *  expr 
)
static

Definition at line 42 of file generate_code.cc.

43 {
44  o.ws("\n").wind(ind).ws("/* from little-endian to host-endian */");
45  o.ws("\n").wind(ind).ws("unsigned char *p = (unsigned char*)&").ws(expr).ws(";");
46  o.ws("\n").wind(ind).ws(expr).ws(" = p[0]");
47  for (uint32_t i = 1; i < size; ++i)
48  {
49  o.ws(" + (p[").wu32(i).ws("] << ").wu32(i * 8).ws("u)");
50  }
51  o.ws(";");
52 }

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::genCondGoto ( OutputFile o,
uint32_t  ind,
const std::vector< std::string > &  condnames 
)
static

Definition at line 309 of file emit_dfa.cc.

310 {
311  const size_t conds = condnames.size ();
312  if (opts->target == opt_t::DOT)
313  {
314  o.warn_condition_order = false; // see note [condition order]
315  for (size_t i = 0; i < conds; ++i)
316  {
317  const std::string cond = condnames[i];
318  o.ws("0 -> ").wstring(cond).ws(" [label=\"state=").wstring(cond).ws("\"]\n");
319  }
320  }
321  else if (opts->gFlag)
322  {
323  o.wind(ind).ws("goto *").wstring(opts->yyctable).ws("[").wstring(genGetCondition()).ws("];\n");
324  }
325  else if (opts->sFlag)
326  {
327  if (conds == 1)
328  {
329  o.warn_condition_order = false; // see note [condition order]
330  }
331  genCondGotoSub(o, ind, condnames, 0, static_cast<uint32_t> (conds) - 1);
332  }
333  else
334  {
335  o.warn_condition_order = false; // see note [condition order]
336  o.wind(ind).ws("switch (").wstring(genGetCondition()).ws(") {\n");
337  for (size_t i = 0; i < conds; ++i)
338  {
339  const std::string & cond = condnames[i];
340  o.wind(ind).ws("case ").wstring(opts->condEnumPrefix).wstring(cond).ws(": goto ").wstring(opts->condPrefix).wstring(cond).ws(";\n");
341  }
342  o.wind(ind).ws("}\n");
343  }
344  o.wdelay_warn_condition_order ();
345  bWroteCondCheck = true;
346 }
std::string condPrefix
Definition: opt.h:118
static void genCondGotoSub(OutputFile &o, uint32_t ind, const std::vector< std::string > &condnames, uint32_t cMin, uint32_t cMax)
Definition: emit_dfa.cc:268
bool bWroteCondCheck
Definition: main.cc:18
bool sFlag
Definition: opt.h:118
std::string condEnumPrefix
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
bool gFlag
Definition: opt.h:118
std::string yyctable
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
static std::string genGetCondition()
Definition: emit_dfa.cc:30

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::genCondGotoSub ( OutputFile o,
uint32_t  ind,
const std::vector< std::string > &  condnames,
uint32_t  cMin,
uint32_t  cMax 
)
static

Definition at line 268 of file emit_dfa.cc.

269 {
270  if (cMin == cMax)
271  {
272  o.wind(ind).ws("goto ").wstring(opts->condPrefix).wstring(condnames[cMin]).ws(";\n");
273  }
274  else
275  {
276  uint32_t cMid = cMin + ((cMax - cMin + 1) / 2);
277 
278  o.wind(ind).ws("if (").wstring(genGetCondition()).ws(" < ").wu32(cMid).ws(") {\n");
279  genCondGotoSub(o, ind + 1, condnames, cMin, cMid - 1);
280  o.wind(ind).ws("} else {\n");
281  genCondGotoSub(o, ind + 1, condnames, cMid, cMax);
282  o.wind(ind).ws("}\n");
283  }
284 }
std::string condPrefix
Definition: opt.h:118
static void genCondGotoSub(OutputFile &o, uint32_t ind, const std::vector< std::string > &condnames, uint32_t cMin, uint32_t cMax)
Definition: emit_dfa.cc:268
Opt opts
Definition: opt.cc:7
static std::string genGetCondition()
Definition: emit_dfa.cc:30

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::genCondTable ( OutputFile o,
uint32_t  ind,
const std::vector< std::string > &  condnames 
)
static

Definition at line 257 of file emit_dfa.cc.

258 {
259  const size_t conds = condnames.size ();
260  o.wind(ind++).ws("static void *").wstring(opts->yyctable).ws("[").wu64(conds).ws("] = {\n");
261  for (size_t i = 0; i < conds; ++i)
262  {
263  o.wind(ind).ws("&&").wstring(opts->condPrefix).wstring(condnames[i]).ws(",\n");
264  }
265  o.wind(--ind).ws("};\n");
266 }
std::string condPrefix
Definition: opt.h:118
std::string yyctable
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the call graph for this function:

Here is the caller graph for this function:

std::string re2c::genGetCondition ( )
static

Definition at line 30 of file emit_dfa.cc.

31 {
32  return opts->cond_get_naked
33  ? opts->cond_get
34  : opts->cond_get + "()";
35 }
std::string cond_get
Definition: opt.h:118
bool cond_get_naked
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the caller graph for this function:

void re2c::genGoTo ( OutputFile o,
uint32_t  ind,
const State from,
const State to,
bool &  readCh 
)

Definition at line 37 of file emit_dfa.cc.

38 {
39  if (opts->target == opt_t::DOT)
40  {
41  o.wlabel(from->label).ws(" -> ").wlabel(to->label).ws("\n");
42  return;
43  }
44 
45  if (readCh && from->next != to)
46  {
47  o.wstring(opts->input_api.stmt_peek (ind));
48  readCh = false;
49  }
50 
51  o.wind(ind).ws("goto ").wstring(opts->labelPrefix).wlabel(to->label).ws(";\n");
52 }
InputAPI input_api
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
std::string labelPrefix
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string stmt_peek(uint32_t ind) const
Definition: input_api.cc:45

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::genSetCondition ( OutputFile o,
uint32_t  ind,
const std::string &  newcond 
)
static

Definition at line 368 of file emit_action.cc.

369 {
370  o.wind(ind).wstring(replaceParam (opts->cond_set, opts->cond_set_arg, opts->condEnumPrefix + newcond));
371  if (!opts->cond_set_naked)
372  {
373  o.ws("(").wstring(opts->condEnumPrefix).wstring(newcond).ws(");");
374  }
375  o.ws("\n");
376 }
std::string replaceParam(std::string str, const std::string &param, const _Ty &value)
Definition: emit.h:26
bool cond_set_naked
Definition: opt.h:118
std::string condEnumPrefix
Definition: opt.h:118
std::string cond_set
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string cond_set_arg
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::genSetState ( OutputFile o,
uint32_t  ind,
uint32_t  fillIndex 
)
static

Definition at line 378 of file emit_action.cc.

379 {
380  o.wind(ind).wstring(replaceParam (opts->state_set, opts->state_set_arg, fillIndex));
381  if (!opts->state_set_naked)
382  {
383  o.ws("(").wu32(fillIndex).ws(");");
384  }
385  o.ws("\n");
386 }
std::string replaceParam(std::string str, const std::string &param, const _Ty &value)
Definition: emit.h:26
std::string state_set
Definition: opt.h:118
bool state_set_naked
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string state_set_arg
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::genYYFill ( OutputFile o,
size_t  need 
)
static

Definition at line 354 of file emit_action.cc.

355 {
356  o.wstring(replaceParam (opts->fill, opts->fill_arg, need));
357  if (!opts->fill_naked)
358  {
359  if (opts->fill_arg_use)
360  {
361  o.ws("(").wu64(need).ws(")");
362  }
363  o.ws(";");
364  }
365  o.ws("\n");
366 }
std::string replaceParam(std::string str, const std::string &param, const _Ty &value)
Definition: emit.h:26
static void need(OutputFile &o, uint32_t ind, bool &readCh, size_t n, bool bSetMarker)
Definition: emit_action.cc:299
bool fill_naked
Definition: opt.h:118
std::string fill_arg
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string fill
Definition: opt.h:118
bool fill_arg_use
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

static uint32_t re2c::hex_digit ( const char  c)
inlinestatic

Definition at line 6 of file unescape.cc.

7 {
8  switch (c)
9  {
10  case '0': return 0;
11  case '1': return 1;
12  case '2': return 2;
13  case '3': return 3;
14  case '4': return 4;
15  case '5': return 5;
16  case '6': return 6;
17  case '7': return 7;
18  case '8': return 8;
19  case '9': return 9;
20  case 'a':
21  case 'A': return 0xA;
22  case 'b':
23  case 'B': return 0xB;
24  case 'c':
25  case 'C': return 0xC;
26  case 'd':
27  case 'D': return 0xD;
28  case 'e':
29  case 'E': return 0xE;
30  case 'f':
31  case 'F': return 0xF;
32  default: return ~0u; // unexpected
33  }
34 }

Here is the caller graph for this function:

char re2c::hexCh ( uint32_t  c)

Definition at line 32 of file print.cc.

33 {
34  static const char * sHex = "0123456789ABCDEF";
35  return sHex[c & 0x0F];
36 }

Here is the caller graph for this function:

std::string re2c::incond ( const std::string &  cond)

Definition at line 242 of file msg.cc.

243 {
244  std::string s;
245  if (!cond.empty ())
246  {
247  s += "in condition '";
248  s += cond;
249  s += "' ";
250  }
251  return s;
252 }

Here is the caller graph for this function:

std::string re2c::indent ( uint32_t  ind)
inline

Definition at line 11 of file indent.h.

12 {
13  std::string str;
14 
15  while (opts->target != opt_t::DOT && ind-- > 0)
16  {
17  str += opts->indString;
18  }
19  return str;
20 }
std::string indString
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the caller graph for this function:

bool re2c::is_alpha ( uint32_t  c)
inline

Definition at line 13 of file case.h.

14 {
15  return (c >= 'a' && c <= 'z')
16  || (c >= 'A' && c <= 'Z');
17 }
bool re2c::is_print ( uint32_t  c)

Definition at line 11 of file print.cc.

12 {
13  return c >= 0x20 && c < 0x7F;
14 }

Here is the caller graph for this function:

bool re2c::is_space ( uint32_t  c)

Definition at line 16 of file print.cc.

17 {
18  switch (c)
19  {
20  case '\t':
21  case '\f':
22  case '\v':
23  case '\n':
24  case '\r':
25  case ' ':
26  return true;
27  default:
28  return false;
29  }
30 }

Here is the caller graph for this function:

template<typename key_t >
static void re2c::keygen ( FILE *  f,
size_t  count,
size_t  len,
size_t  len_match,
rule_rank_t  match 
)
static

Definition at line 162 of file generate_data.cc.

163 {
164  const key_t m = Skeleton::rule2key<key_t> (match);
165 
166  const size_t keys_size = 3 * count;
167  key_t * keys = new key_t [keys_size];
168  for (uint32_t i = 0; i < keys_size;)
169  {
170  keys[i++] = to_le<key_t>(static_cast<key_t> (len));
171  keys[i++] = to_le<key_t>(static_cast<key_t> (len_match));
172  keys[i++] = to_le<key_t>(m);
173  }
174  fwrite (keys, sizeof (key_t), keys_size, f);
175  delete [] keys;
176 }
static bool re2c::loopback ( size_t  node,
size_t  narcs,
const size_t *  arcs 
)
static

Definition at line 13 of file fillpoints.cc.

14 {
15  for (size_t i = 0; i < narcs; ++i)
16  {
17  if (arcs[i] == node)
18  {
19  return true;
20  }
21  }
22  return false;
23 }

Here is the caller graph for this function:

static std::string re2c::make_name ( const std::string &  cond,
uint32_t  line 
)
static

Definition at line 16 of file compile.cc.

17 {
18  std::ostringstream os;
19  os << "line" << line;
20  std::string name = os.str();
21  if (!cond.empty ())
22  {
23  name += "_";
24  name += cond;
25  }
26  return name;
27 }

Here is the caller graph for this function:

template<typename T >
smart_ptr<T> re2c::make_smart_ptr ( T *  p)

Definition at line 63 of file smart_ptr.h.

64  {
65  return smart_ptr<T>(p);
66  }

Here is the caller graph for this function:

bool re2c::matches ( const Span b1,
uint32_t  n1,
const State s1,
const Span b2,
uint32_t  n2,
const State s2 
)

Definition at line 134 of file bitmap.cc.

135 {
136  const Span * e1 = &b1[n1];
137  uint32_t lb1 = 0;
138  const Span * e2 = &b2[n2];
139  uint32_t lb2 = 0;
140 
141  for (;;)
142  {
143  for (; b1 < e1 && b1->to != s1; ++b1)
144  {
145  lb1 = b1->ub;
146  }
147  for (; b2 < e2 && b2->to != s2; ++b2)
148  {
149  lb2 = b2->ub;
150  }
151  if (b1 == e1)
152  {
153  return b2 == e2;
154  }
155  if (b2 == e2)
156  {
157  return false;
158  }
159  if (lb1 != lb2 || b1->ub != b2->ub)
160  {
161  return false;
162  }
163  ++b1;
164  ++b2;
165  }
166 }

Here is the caller graph for this function:

MatchOp * re2c::merge ( MatchOp m1,
MatchOp m2 
)
static

Definition at line 84 of file regexp.cc.

85 {
86  if (!m1)
87  {
88  return m2;
89  }
90  if (!m2)
91  {
92  return m1;
93  }
94  MatchOp * m = new MatchOp (Range::add (m1->match, m2->match));
95  return m;
96 }
re2c::Range * add(uint32_t n1, uint32_t n2)
Definition: test-impl.h:37

Here is the call graph for this function:

static uint32_t re2c::merge ( Span x0,
State fg,
State bg 
)
static

Definition at line 31 of file prepare.cc.

32 {
33  Span *x = x0, *f = fg->go.span, *b = bg->go.span;
34  uint32_t nf = fg->go.nSpans, nb = bg->go.nSpans;
35  State *prev = NULL, *to;
36  // NB: we assume both spans are for same range
37 
38  for (;;)
39  {
40  if (f->ub == b->ub)
41  {
42  to = f->to == b->to ? bg : f->to;
43 
44  if (to == prev)
45  {
46  --x;
47  }
48  else
49  {
50  x->to = prev = to;
51  }
52 
53  x->ub = f->ub;
54  ++x;
55  ++f;
56  --nf;
57  ++b;
58  --nb;
59 
60  if (nf == 0 && nb == 0)
61  {
62  return static_cast<uint32_t> (x - x0);
63  }
64  }
65 
66  while (f->ub < b->ub)
67  {
68  to = f->to == b->to ? bg : f->to;
69 
70  if (to == prev)
71  {
72  --x;
73  }
74  else
75  {
76  x->to = prev = to;
77  }
78 
79  x->ub = f->ub;
80  ++x;
81  ++f;
82  --nf;
83  }
84 
85  while (b->ub < f->ub)
86  {
87  to = b->to == f->to ? bg : f->to;
88 
89  if (to == prev)
90  {
91  --x;
92  }
93  else
94  {
95  x->to = prev = to;
96  }
97 
98  x->ub = b->ub;
99  ++x;
100  ++b;
101  --nb;
102  }
103  }
104 }

Here is the caller graph for this function:

void re2c::minimization ( dfa_t dfa)

Definition at line 199 of file minimization.cc.

200 {
201  const size_t count = dfa.states.size();
202 
203  size_t *part = new size_t[count];
204 
205  switch (opts->dfa_minimization)
206  {
208  minimization_table(part, dfa.states, dfa.nchars);
209  break;
211  minimization_moore(part, dfa.states, dfa.nchars);
212  break;
213  }
214 
215  size_t *compact = new size_t[count];
216  for (size_t i = 0, j = 0; i < count; ++i)
217  {
218  if (i == part[i])
219  {
220  compact[i] = j++;
221  }
222  }
223 
224  size_t new_count = 0;
225  for (size_t i = 0; i < count; ++i)
226  {
227  dfa_state_t *s = dfa.states[i];
228  if (i == part[i])
229  {
230  size_t *arcs = s->arcs;
231  for (size_t c = 0; c < dfa.nchars; ++c)
232  {
233  if (arcs[c] != dfa_t::NIL)
234  {
235  arcs[c] = compact[part[arcs[c]]];
236  }
237  }
238  dfa.states[new_count++] = s;
239  }
240  else
241  {
242  delete s;
243  }
244  }
245  dfa.states.resize(new_count);
246 
247  delete[] compact;
248  delete[] part;
249 }
static void minimization_moore(size_t *part, const std::vector< dfa_state_t * > &states, size_t nchars)
static void minimization_table(size_t *part, const std::vector< dfa_state_t * > &states, size_t nchars)
Definition: minimization.cc:28
Opt opts
Definition: opt.cc:7
dfa_minimization_t dfa_minimization
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

static void re2c::minimization_moore ( size_t *  part,
const std::vector< dfa_state_t * > &  states,
size_t  nchars 
)
static

Definition at line 113 of file minimization.cc.

117 {
118  const size_t count = states.size();
119 
120  size_t *next = new size_t[count];
121 
122  std::map<std::pair<RuleOp*, bool>, size_t> init;
123  for (size_t i = 0; i < count; ++i)
124  {
125  dfa_state_t *s = states[i];
126  std::pair<RuleOp*, bool> key(s->rule, s->ctx);
127  if (init.insert(std::make_pair(key, i)).second)
128  {
129  part[i] = i;
130  next[i] = dfa_t::NIL;
131  }
132  else
133  {
134  const size_t j = init[key];
135  part[i] = j;
136  next[i] = next[j];
137  next[j] = i;
138  }
139  }
140 
141  size_t *out = new size_t[nchars * count];
142  size_t *diff = new size_t[count];
143  for (bool loop = true; loop;)
144  {
145  loop = false;
146  for (size_t i = 0; i < count; ++i)
147  {
148  if (i != part[i] || next[i] == dfa_t::NIL)
149  {
150  continue;
151  }
152 
153  for (size_t j = i; j != dfa_t::NIL; j = next[j])
154  {
155  size_t *o = &out[j * nchars];
156  size_t *a = states[j]->arcs;
157  for (size_t c = 0; c < nchars; ++c)
158  {
159  o[c] = a[c] == dfa_t::NIL
160  ? dfa_t::NIL
161  : part[a[c]];
162  }
163  }
164 
165  size_t diff_count = 0;
166  for (size_t j = i; j != dfa_t::NIL;)
167  {
168  const size_t j_next = next[j];
169  size_t n = 0;
170  for (; n < diff_count; ++n)
171  {
172  size_t k = diff[n];
173  if (memcmp(&out[j * nchars],
174  &out[k * nchars],
175  nchars * sizeof(size_t)) == 0)
176  {
177  part[j] = k;
178  next[j] = next[k];
179  next[k] = j;
180  break;
181  }
182  }
183  if (n == diff_count)
184  {
185  diff[diff_count++] = j;
186  part[j] = j;
187  next[j] = dfa_t::NIL;
188  }
189  j = j_next;
190  }
191  loop |= diff_count > 1;
192  }
193  }
194  delete[] out;
195  delete[] diff;
196  delete[] next;
197 }
static int32_t diff(const re2c::Range *r1, const re2c::Range *r2, const re2c::Range *op1, const re2c::Range *op2, const char *op)
Definition: test.cc:43

Here is the call graph for this function:

Here is the caller graph for this function:

static void re2c::minimization_table ( size_t *  part,
const std::vector< dfa_state_t * > &  states,
size_t  nchars 
)
static

Definition at line 28 of file minimization.cc.

32 {
33  const size_t count = states.size();
34 
35  bool **tbl = new bool*[count];
36  tbl[0] = new bool[count * (count - 1) / 2];
37  for (size_t i = 0; i < count - 1; ++i)
38  {
39  tbl[i + 1] = tbl[i] + i;
40  }
41 
42  for (size_t i = 0; i < count; ++i)
43  {
44  dfa_state_t *s1 = states[i];
45  for (size_t j = 0; j < i; ++j)
46  {
47  dfa_state_t *s2 = states[j];
48  tbl[i][j] = s1->ctx != s2->ctx
49  || s1->rule != s2->rule;
50  }
51  }
52 
53  for (bool loop = true; loop;)
54  {
55  loop = false;
56  for (size_t i = 0; i < count; ++i)
57  {
58  for (size_t j = 0; j < i; ++j)
59  {
60  if (!tbl[i][j])
61  {
62  for (size_t k = 0; k < nchars; ++k)
63  {
64  size_t oi = states[i]->arcs[k];
65  size_t oj = states[j]->arcs[k];
66  if (oi < oj)
67  {
68  std::swap(oi, oj);
69  }
70  if (oi != oj &&
71  (oi == dfa_t::NIL ||
72  oj == dfa_t::NIL ||
73  tbl[oi][oj]))
74  {
75  tbl[i][j] = true;
76  loop = true;
77  break;
78  }
79  }
80  }
81  }
82  }
83  }
84 
85  for (size_t i = 0; i < count; ++i)
86  {
87  part[i] = i;
88  for (size_t j = 0; j < i; ++j)
89  {
90  if (!tbl[i][j])
91  {
92  part[i] = j;
93  break;
94  }
95  }
96  }
97 
98  delete[] tbl[0];
99  delete[] tbl;
100 }

Here is the caller graph for this function:

RegExp * re2c::mkAlt ( RegExp e1,
RegExp e2 
)

Definition at line 40 of file regexp.cc.

41 {
42  AltOp * a;
43  MatchOp * m1;
44  MatchOp * m2;
45 
46  a = dynamic_cast<AltOp*> (e1);
47  if (a != NULL)
48  {
49  m1 = dynamic_cast<MatchOp*> (a->exp1);
50  if (m1 != NULL)
51  {
52  e1 = a->exp2;
53  }
54  }
55  else
56  {
57  m1 = dynamic_cast<MatchOp*> (e1);
58  if (m1 != NULL)
59  {
60  e1 = NULL;
61  }
62  }
63  a = dynamic_cast<AltOp*> (e2);
64  if (a != NULL)
65  {
66  m2 = dynamic_cast<MatchOp*> (a->exp1);
67  if (m2 != NULL)
68  {
69  e2 = a->exp2;
70  }
71  }
72  else
73  {
74  m2 = dynamic_cast<MatchOp*> (e2);
75  if (m2 != NULL)
76  {
77  e2 = NULL;
78  }
79  }
80 
81  return doAlt (merge (m1, m2), doAlt (e1, e2));
82 }
RegExp * doAlt(RegExp *e1, RegExp *e2)
Definition: regexp.cc:27
static MatchOp * merge(MatchOp *m1, MatchOp *m2)
Definition: regexp.cc:84

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::need ( OutputFile o,
uint32_t  ind,
bool &  readCh,
size_t  n,
bool  bSetMarker 
)
static

Definition at line 299 of file emit_action.cc.

300 {
301  if (opts->target == opt_t::DOT)
302  {
303  return;
304  }
305 
306  uint32_t fillIndex = last_fill_index;
307 
308  if (opts->fFlag)
309  {
310  last_fill_index++;
311  genSetState (o, ind, fillIndex);
312  }
313 
314  if (opts->fill_use && n > 0)
315  {
316  o.wind(ind);
317  if (n == 1)
318  {
319  if (opts->fill_check)
320  {
321  o.ws("if (").wstring(opts->input_api.expr_lessthan_one ()).ws(") ");
322  }
323  genYYFill(o, n);
324  }
325  else
326  {
327  if (opts->fill_check)
328  {
329  o.ws("if (").wstring(opts->input_api.expr_lessthan (n)).ws(") ");
330  }
331  genYYFill(o, n);
332  }
333  }
334 
335  if (opts->fFlag)
336  {
337  o.wstring(opts->yyfilllabel).wu32(fillIndex).ws(":\n");
338  }
339 
340  if (n > 0)
341  {
342  if (bSetMarker)
343  {
344  o.wstring(opts->input_api.stmt_backup_peek (ind));
345  }
346  else
347  {
348  o.wstring(opts->input_api.stmt_peek (ind));
349  }
350  readCh = false;
351  }
352 }
InputAPI input_api
Definition: opt.h:118
std::string expr_lessthan_one() const
Definition: input_api.cc:153
std::string stmt_backup_peek(uint32_t ind) const
Definition: input_api.cc:139
static void genYYFill(OutputFile &o, size_t need)
Definition: emit_action.cc:354
opt_t::target_t target
Definition: opt.h:118
bool fill_use
Definition: opt.h:118
static void genSetState(OutputFile &o, uint32_t ind, uint32_t fillIndex)
Definition: emit_action.cc:378
bool fFlag
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string stmt_peek(uint32_t ind) const
Definition: input_api.cc:45
uint32_t last_fill_index
Definition: main.cc:19
std::string expr_lessthan(size_t n) const
Definition: input_api.cc:160
std::string yyfilllabel
Definition: opt.h:118
bool fill_check
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

std::ostream& re2c::operator<< ( std::ostream &  o,
const RegExp re 
)

Definition at line 14 of file display.cc.

15 {
16  re.display (o);
17  return o;
18 }

Here is the call graph for this function:

std::ostream& re2c::operator<< ( std::ostream &  o,
label_t  l 
)

Definition at line 36 of file label.cc.

37 {
38  o << l.value;
39  return o;
40 }
std::ostream& re2c::operator<< ( std::ostream &  o,
rule_rank_t  r 
)

Definition at line 57 of file rule_rank.cc.

58 {
59  o << r.value;
60  return o;
61 }
std::string re2c::output_get_state ( )

Definition at line 458 of file output.cc.

459 {
460  return opts->state_get_naked
461  ? opts->state_get
462  : opts->state_get + "()";
463 }
bool state_get_naked
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string state_get
Definition: opt.h:118

Here is the caller graph for this function:

void re2c::output_goto ( OutputFile o,
uint32_t  ind,
bool &  readCh,
label_t  to 
)
static

Definition at line 44 of file go_emit.cc.

45 {
46  if (readCh)
47  {
48  o.wstring(opts->input_api.stmt_peek (ind));
49  readCh = false;
50  }
51  o.wind(ind).ws("goto ").wstring(opts->labelPrefix).wlabel(to).ws(";\n");
52 }
InputAPI input_api
Definition: opt.h:118
std::string labelPrefix
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
std::string stmt_peek(uint32_t ind) const
Definition: input_api.cc:45

Here is the call graph for this function:

Here is the caller graph for this function:

std::string re2c::output_hgo ( OutputFile o,
uint32_t  ind,
bool &  readCh,
SwitchIf hgo 
)
static

Definition at line 54 of file go_emit.cc.

55 {
56  std::string yych = output_yych (readCh);
57  if (hgo != NULL)
58  {
59  o.wind(ind).ws("if (").wstring(yych).ws(" & ~0xFF) {\n");
60  hgo->emit (o, ind + 1, readCh);
61  o.wind(ind).ws("} else ");
62  yych = opts->yych;
63  }
64  else
65  {
66  o.wind(ind);
67  }
68  return yych;
69 }
std::string yych
Definition: opt.h:118
static std::string output_yych(bool &readCh)
Definition: go_emit.cc:26
Opt opts
Definition: opt.cc:7

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::output_if ( OutputFile o,
uint32_t  ind,
bool &  readCh,
const std::string &  compare,
uint32_t  value 
)
static

Definition at line 39 of file go_emit.cc.

40 {
41  o.wind(ind).ws("if (").wstring(output_yych (readCh)).ws(" ").wstring(compare).ws(" ").wc_hex (value).ws(") ");
42 }
static std::string output_yych(bool &readCh)
Definition: go_emit.cc:26

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::output_line_info ( std::ostream &  o,
uint32_t  line_number,
const char *  file_name 
)

Definition at line 424 of file output.cc.

425 {
426  if (!opts->iFlag)
427  {
428  o << "#line " << line_number << " \"" << file_name << "\"\n";
429  }
430 }
bool iFlag
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the caller graph for this function:

void re2c::output_state_goto ( std::ostream &  o,
uint32_t  ind,
uint32_t  start_label 
)

Definition at line 388 of file output.cc.

389 {
390  o << indent(ind) << "switch (" << output_get_state() << ") {\n";
391  if (opts->bUseStateAbort)
392  {
393  o << indent(ind) << "default: abort();\n";
394  o << indent(ind) << "case -1: goto " << opts->labelPrefix << start_label << ";\n";
395  }
396  else
397  {
398  o << indent(ind) << "default: goto " << opts->labelPrefix << start_label << ";\n";
399  }
400  for (uint32_t i = 0; i < last_fill_index; ++i)
401  {
402  o << indent(ind) << "case " << i << ": goto " << opts->yyfilllabel << i << ";\n";
403  }
404  o << indent(ind) << "}\n";
405  if (opts->bUseStateNext)
406  {
407  o << opts->yynext << ":\n";
408  }
409 }
std::string indent(uint32_t ind)
Definition: indent.h:11
bool bUseStateNext
Definition: opt.h:118
std::string yynext
Definition: opt.h:118
bool bUseStateAbort
Definition: opt.h:118
std::string labelPrefix
Definition: opt.h:118
std::string output_get_state()
Definition: output.cc:458
Opt opts
Definition: opt.cc:7
uint32_t last_fill_index
Definition: main.cc:19
std::string yyfilllabel
Definition: opt.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::output_types ( std::ostream &  o,
uint32_t  ind,
const std::vector< std::string > &  types 
)

Definition at line 432 of file output.cc.

433 {
434  o << indent (ind++) << "enum " << opts->yycondtype << " {\n";
435  for (unsigned int i = 0; i < types.size (); ++i)
436  {
437  o << indent (ind) << opts->condEnumPrefix << types[i] << ",\n";
438  }
439  o << indent (--ind) << "};\n";
440 }
std::string yycondtype
Definition: opt.h:118
std::string indent(uint32_t ind)
Definition: indent.h:11
std::string condEnumPrefix
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::output_version_time ( std::ostream &  o)

Definition at line 442 of file output.cc.

443 {
444  o << "/* Generated by re2c";
445  if (opts->version)
446  {
447  o << " " << PACKAGE_VERSION;
448  }
449  if (!opts->bNoGenerationDate)
450  {
451  o << " on ";
452  time_t now = time (NULL);
453  o.write (ctime (&now), 24);
454  }
455  o << " */" << "\n";
456 }
bool version
Definition: opt.h:118
bool bNoGenerationDate
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the caller graph for this function:

void re2c::output_yyaccept_init ( std::ostream &  o,
uint32_t  ind,
bool  used_yyaccept 
)

Definition at line 411 of file output.cc.

412 {
413  if (used_yyaccept)
414  {
415  o << indent (ind) << "unsigned int " << opts->yyaccept << " = 0;\n";
416  }
417 }
std::string indent(uint32_t ind)
Definition: indent.h:11
std::string yyaccept
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the call graph for this function:

Here is the caller graph for this function:

std::string re2c::output_yych ( bool &  readCh)
static

Definition at line 26 of file go_emit.cc.

27 {
28  if (readCh)
29  {
30  readCh = false;
31  return "(" + opts->input_api.expr_peek_save () + ")";
32  }
33  else
34  {
35  return opts->yych;
36  }
37 }
InputAPI input_api
Definition: opt.h:118
std::string yych
Definition: opt.h:118
std::string expr_peek_save() const
Definition: input_api.cc:40
Opt opts
Definition: opt.cc:7

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::output_yymaxfill ( std::ostream &  o,
size_t  max_fill 
)

Definition at line 419 of file output.cc.

420 {
421  o << "#define YYMAXFILL " << max_fill << "\n";
422 }

Here is the caller graph for this function:

void re2c::parse ( Scanner ,
Output  
)

Here is the caller graph for this function:

void re2c::parse_cleanup ( )
parse_opts_t re2c::parse_opts ( char **  argv,
Opt opts 
)

Here is the caller graph for this function:

void re2c::printSpan ( std::ostream &  o,
uint32_t  lb,
uint32_t  ub 
)

Definition at line 139 of file print.cc.

140 {
141  o << "[";
142  if ((ub - lb) == 1)
143  {
144  prtChOrHexForSpan(o, lb);
145  }
146  else
147  {
148  prtChOrHexForSpan(o, lb);
149  o << "-";
150  prtChOrHexForSpan(o, ub - 1);
151  }
152  o << "]";
153 }
void prtChOrHexForSpan(std::ostream &o, uint32_t c)
Definition: print.cc:125

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::prtCh ( std::ostream &  o,
uint32_t  c 
)

Definition at line 73 of file print.cc.

74 {
75  const bool dot = opts->target == opt_t::DOT;
76 
77  switch (c)
78  {
79  case '\'':
80  o << (dot ? "'" : "\\'");
81  break;
82 
83  case '"':
84  o << (dot ? "\\\"" : "\"");
85  break;
86 
87  case '\n':
88  o << (dot ? "\\\\n" : "\\n");
89  break;
90 
91  case '\t':
92  o << (dot ? "\\\\t" : "\\t");
93  break;
94 
95  case '\v':
96  o << (dot ? "\\\\v" : "\\v");
97  break;
98 
99  case '\b':
100  o << (dot ? "\\\\b" : "\\b");
101  break;
102 
103  case '\r':
104  o << (dot ? "\\\\r" : "\\r");
105  break;
106 
107  case '\f':
108  o << (dot ? "\\\\f" : "\\f");
109  break;
110 
111  case '\a':
112  o << (dot ? "\\\\a" :"\\a");
113  break;
114 
115  case '\\':
116  o << "\\\\"; // both .dot and C/C++ code expect "\\"
117  break;
118 
119  default:
120  o << static_cast<char> (c);
121  break;
122  }
123 }
opt_t::target_t target
Definition: opt.h:118
Opt opts
Definition: opt.cc:7

Here is the caller graph for this function:

void re2c::prtChOrHex ( std::ostream &  o,
uint32_t  c 
)

Definition at line 38 of file print.cc.

39 {
40  if (opts->encoding.type () != Enc::EBCDIC
41  && (is_print (c) || is_space (c)))
42  {
43  o << '\'';
44  prtCh(o, c);
45  o << '\'';
46  }
47  else
48  {
49  prtHex(o, c);
50  }
51 }
void prtCh(std::ostream &o, uint32_t c)
Definition: print.cc:73
type_t type() const
Definition: enc.h:185
bool is_space(uint32_t c)
Definition: print.cc:16
bool is_print(uint32_t c)
Definition: print.cc:11
Enc encoding
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
void prtHex(std::ostream &o, uint32_t c)
Definition: print.cc:53

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::prtChOrHexForSpan ( std::ostream &  o,
uint32_t  c 
)

Definition at line 125 of file print.cc.

126 {
127  if (opts->encoding.type () != Enc::EBCDIC
128  && is_print (c)
129  && (c != ']'))
130  {
131  prtCh(o, c);
132  }
133  else
134  {
135  prtHex(o, c);
136  }
137 }
void prtCh(std::ostream &o, uint32_t c)
Definition: print.cc:73
type_t type() const
Definition: enc.h:185
bool is_print(uint32_t c)
Definition: print.cc:11
Enc encoding
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
void prtHex(std::ostream &o, uint32_t c)
Definition: print.cc:53

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::prtHex ( std::ostream &  o,
uint32_t  c 
)

Definition at line 53 of file print.cc.

54 {
55  o << "0x";
56  const uint32_t cunit_size = opts->encoding.szCodeUnit ();
57  if (cunit_size >= 4)
58  {
59  o << hexCh (c >> 28u)
60  << hexCh (c >> 24u)
61  << hexCh (c >> 20u)
62  << hexCh (c >> 16u);
63  }
64  if (cunit_size >= 2)
65  {
66  o << hexCh (c >> 12u)
67  << hexCh (c >> 8u);
68  }
69  o << hexCh (c >> 4u)
70  << hexCh (c);
71 }
uint32_t szCodeUnit() const
Definition: enc.h:152
Enc encoding
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
char hexCh(uint32_t c)
Definition: print.cc:32

Here is the call graph for this function:

Here is the caller graph for this function:

RegExp * re2c::repeat ( RegExp e,
uint32_t  n 
)

Definition at line 211 of file regexp.cc.

212 {
213  RegExp * r = NULL;
214  for (uint32_t i = 0; i < n; ++i)
215  {
216  r = doCat (r, e);
217  }
218  return r;
219 }
RegExp * doCat(RegExp *e1, RegExp *e2)
Definition: regexp.cc:98

Here is the call graph for this function:

Here is the caller graph for this function:

RegExp * re2c::repeat_from ( RegExp e,
uint32_t  n 
)

Definition at line 234 of file regexp.cc.

235 {
236  RegExp * r1 = repeat (e, n);
237  RegExp * r2 = new CloseOp (e);
238  return doCat (r1, r2);
239 }
RegExp * repeat(RegExp *e, uint32_t n)
Definition: regexp.cc:211
RegExp * doCat(RegExp *e1, RegExp *e2)
Definition: regexp.cc:98

Here is the call graph for this function:

RegExp * re2c::repeat_from_to ( RegExp e,
uint32_t  n,
uint32_t  m 
)

Definition at line 222 of file regexp.cc.

223 {
224  RegExp * r1 = repeat (e, n);
225  RegExp * r2 = NULL;
226  for (uint32_t i = n; i < m; ++i)
227  {
228  r2 = mkAlt (new NullOp, doCat (e, r2));
229  }
230  return doCat (r1, r2);
231 }
RegExp * repeat(RegExp *e, uint32_t n)
Definition: regexp.cc:211
RegExp * doCat(RegExp *e1, RegExp *e2)
Definition: regexp.cc:98
RegExp * mkAlt(RegExp *e1, RegExp *e2)
Definition: regexp.cc:40

Here is the call graph for this function:

template<typename _Ty >
std::string re2c::replaceParam ( std::string  str,
const std::string &  param,
const _Ty &  value 
)

Definition at line 26 of file emit.h.

27 {
28  if (!param.empty ())
29  {
30  std::ostringstream strValue;
31  strValue << value;
32  std::string::size_type pos;
33  while((pos = str.find(param)) != std::string::npos)
34  {
35  str.replace(pos, param.length(), strValue.str());
36  }
37  }
38  return str;
39 }

Here is the caller graph for this function:

static void re2c::scc ( const dfa_t dfa,
std::stack< size_t > &  stack,
std::vector< size_t > &  lowlink,
std::vector< bool > &  trivial,
size_t  i 
)
static

Definition at line 49 of file fillpoints.cc.

55 {
56  const size_t link = stack.size();
57  lowlink[i] = link;
58  stack.push(i);
59 
60  const size_t *arcs = dfa.states[i]->arcs;
61  for (size_t c = 0; c < dfa.nchars; ++c)
62  {
63  const size_t j = arcs[c];
64  if (j != dfa_t::NIL)
65  {
66  if (lowlink[j] == UNDEFINED)
67  {
68  scc(dfa, stack, lowlink, trivial, j);
69  }
70  if (lowlink[j] < lowlink[i])
71  {
72  lowlink[i] = lowlink[j];
73  }
74  }
75  }
76 
77  if (lowlink[i] == link)
78  {
79  // SCC is non-trivial (has loops) iff it either:
80  // - consists of multiple nodes (they all must be interconnected)
81  // - consists of single node which loops back to itself
82  trivial[i] = i == stack.top()
83  && !loopback(i, dfa.nchars, arcs);
84 
85  size_t j;
86  do
87  {
88  j = stack.top();
89  stack.pop();
90  lowlink[j] = INFINITY;
91  }
92  while (j != i);
93  }
94 }
static void scc(const dfa_t &dfa, std::stack< size_t > &stack, std::vector< size_t > &lowlink, std::vector< bool > &trivial, size_t i)
Definition: fillpoints.cc:49
static const size_t UNDEFINED
Definition: fillpoints.cc:11
static const size_t INFINITY
Definition: fillpoints.cc:10
static bool loopback(size_t node, size_t narcs, const size_t *arcs)
Definition: fillpoints.cc:13

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename uintn_t >
static uintn_t re2c::to_le ( uintn_t  n)
static

Definition at line 150 of file generate_data.cc.

151 {
152  uintn_t m;
153  uint8_t *p = reinterpret_cast<uint8_t*>(&m);
154  for (size_t i = 0; i < sizeof(uintn_t); ++i)
155  {
156  p[i] = static_cast<uint8_t>(n >> (i * 8));
157  }
158  return m;
159 }
uint32_t re2c::to_lower_unsafe ( uint32_t  c)
inline

Definition at line 19 of file case.h.

20 {
21  return c | 0x20u;
22 }
RegExp * re2c::to_regexp ( RangeSuffix p)

Definition at line 12 of file range_suffix.cc.

13 {
14  return p
15  ? emit (p, NULL)
16  : new MatchOp (NULL);
17 }
static RegExp * emit(RangeSuffix *p, RegExp *re)
Definition: range_suffix.cc:22

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t re2c::to_upper_unsafe ( uint32_t  c)
inline

Definition at line 24 of file case.h.

25 {
26  return c & ~0x20u;
27 }
uint32_t re2c::unesc_hex ( const char *  s,
const char *  s_end 
)

Definition at line 37 of file unescape.cc.

38 {
39  uint32_t n = 0;
40  for (s += 2; s != s_end; ++s)
41  {
42  n <<= 4;
43  n += hex_digit (*s);
44  }
45  return n;
46 }
static uint32_t hex_digit(const char c)
Definition: unescape.cc:6

Here is the call graph for this function:

uint32_t re2c::unesc_oct ( const char *  s,
const char *  s_end 
)

Definition at line 49 of file unescape.cc.

50 {
51  uint32_t n = 0;
52  for (++s; s != s_end; ++s)
53  {
54  n <<= 3;
55  n += static_cast<uint8_t> (*s - '0');
56  }
57  return n;
58 }
uint32_t re2c::unmap ( Span new_span,
const Span old_span,
uint32_t  old_nspans,
const State x 
)
static

Definition at line 262 of file go_construct.cc.

263 {
264  uint32_t new_nspans = 0;
265  for (uint32_t i = 0; i < old_nspans; ++i)
266  {
267  if (old_span[i].to != x)
268  {
269  if (new_nspans > 0 && new_span[new_nspans - 1].to == old_span[i].to)
270  new_span[new_nspans - 1].ub = old_span[i].ub;
271  else
272  {
273  new_span[new_nspans].to = old_span[i].to;
274  new_span[new_nspans].ub = old_span[i].ub;
275  ++new_nspans;
276  }
277  }
278  }
279  if (new_nspans > 0)
280  new_span[new_nspans - 1].ub = old_span[old_nspans - 1].ub;
281  return new_nspans;
282 }

Here is the caller graph for this function:

void void re2c::usage ( )

Definition at line 60 of file msg.cc.

61 {
62  fprintf (stderr,
63  "usage: re2c [-bcdDefFghirsuvVwx18] [-o of] [-t th] file\n"
64  "\n"
65  "-? -h --help Display this info.\n"
66  "\n"
67  "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n"
68  " coax better code out of the compiler. Most useful for\n"
69  " specifications with more than a few keywords (e.g. for\n"
70  " most programming languages).\n"
71  "\n"
72  "-c --conditions Require start conditions.\n"
73  "\n"
74  "-d --debug-output Creates a parser that dumps information during\n"
75  " about the current position and in which state the\n"
76  " parser is.\n"
77  "\n"
78  "-D --emit-dot Emit a Graphviz dot view of the DFA graph\n"
79  "\n"
80  "-e --ecb Generate a parser that supports EBCDIC. The generated code\n"
81  " can deal with any character up to 0xFF. In this mode re2c\n"
82  " assumes that input character size is 1 byte. This switch is\n"
83  " incompatible with -w, -u, -x and -8\n"
84  "\n"
85  "-f --storable-state Generate a scanner that supports storable states.\n"
86  "\n"
87  "-F --flex-syntax Partial support for flex syntax.\n"
88  "\n"
89  "-g --computed-gotos Implies -b. Generate computed goto code (only useable\n"
90  " with gcc).\n"
91  "\n"
92  "-i --no-debug-info Do not generate '#line' info (useful for versioning).\n"
93  "\n"
94  "-o of --output=of Specify the output file (of) instead of stdout\n"
95  "\n"
96  "-r --reusable Allow reuse of scanner definitions.\n"
97  "\n"
98  "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n"
99  " need this assist to generate better code.\n"
100  "\n"
101  "-t th --type-header=th Generate a type header file (th) with type definitions.\n"
102  "\n"
103  "-u --unicode Generate a parser that supports UTF-32. The generated code\n"
104  " can deal with any valid Unicode character up to 0x10FFFF.\n"
105  " In this mode re2c assumes that input character size is 4 bytes.\n"
106  " This switch is incompatible with -e, -w, -x and -8. It implies -s.\n"
107  "\n"
108  "-v --version Show version information.\n"
109  "\n"
110  "-V --vernum Show version as one number.\n"
111  "\n"
112  "-w --wide-chars Generate a parser that supports UCS-2. The generated code can\n"
113  " deal with any valid Unicode character up to 0xFFFF. In this mode\n"
114  " re2c assumes that input character size is 2 bytes. This switch is\n"
115  " incompatible with -e, -x, -u and -8. It implies -s."
116  "\n"
117  "-x --utf-16 Generate a parser that supports UTF-16. The generated code can\n"
118  " deal with any valid Unicode character up to 0x10FFFF. In this mode\n"
119  " re2c assumes that input character size is 2 bytes. This switch is\n"
120  " incompatible with -e, -w, -u and -8. It implies -s."
121  "\n"
122  "-8 --utf-8 Generate a parser that supports UTF-8. The generated code can\n"
123  " deal with any valid Unicode character up to 0x10FFFF. In this mode\n"
124  " re2c assumes that input character size is 1 byte. This switch is\n"
125  " incompatible with -e, -w, -x and -u."
126  "\n"
127  "--no-generation-date Suppress date output in the generated file.\n"
128  "\n"
129  "--no-version Suppress version output in the generated file.\n"
130  "\n"
131  "--case-insensitive All strings are case insensitive, so all \"-expressions\n"
132  " are treated in the same way '-expressions are.\n"
133  "\n"
134  "--case-inverted Invert the meaning of single and double quoted strings.\n"
135  " With this switch single quotes are case sensitive and\n"
136  " double quotes are case insensitive.\n"
137  "\n"
138  "--encoding-policy ep Specify what re2c should do when given bad code unit.\n"
139  " ep can be one of the following: fail, substitute, ignore.\n"
140  "\n"
141  "--input i Specify re2c input API.\n"
142  " i can be one of the following: default, custom.\n"
143  "\n"
144  "--skeleton Instead of embedding re2c-generated code into C/C++ source,\n"
145  " generate a self-contained program for the same DFA.\n"
146  " Most useful for correctness and performance testing.\n"
147  "\n"
148  "--empty-class policy What to do if user inputs empty character class. policy can be\n"
149  " one of the following: 'match-empty' (match empty input, default),\n"
150  " 'match-none' (fail to match on any input), 'error' (compilation\n"
151  " error). Note that there are various ways to construct empty class,\n"
152  " e.g: [], [^\\x00-\\xFF], [\\x00-\\xFF]\\[\\x00-\\xFF].\n"
153  "\n"
154  "--dfa-minimization <table | moore>\n"
155  " Internal algorithm used by re2c to minimize DFA (defaults to\n"
156  " 'moore'). Both table filling and Moore's algorithms should\n"
157  " produce identical DFA (up to states relabelling). Table filling\n"
158  " algorithm is much simpler and slower; it serves as a reference\n"
159  " implementation.\n"
160  "\n"
161  "-1 --single-pass Deprecated and does nothing (single pass is by default now).\n"
162  "\n"
163  "-W Turn on all warnings.\n"
164  "\n"
165  "-Werror Turn warnings into errors. Note that this option along doesn't\n"
166  " turn on any warnings, it only affects those warnings that have\n"
167  " been turned on so far or will be turned on later.\n"
168  "\n"
169  "-W<warning> Turn on individual warning.\n"
170  "\n"
171  "-Wno-<warning> Turn off individual warning.\n"
172  "\n"
173  "-Werror-<warning> Turn on individual warning and treat it as error (this implies\n"
174  " '-W<warning>').\n"
175  "\n"
176  "-Wno-error-<warning> Don't treat this particular warning as error. This doesn't turn\n"
177  " off the warning itself.\n"
178  "\n"
179  "Warnings:\n"
180  "\n"
181  "-Wcondition-order Warn if the generated program makes implicit assumptions about\n"
182  " condition numbering. One should use either '-t, --type-header'\n"
183  " option or '/*!types:re2c*/' directive to generate mapping of\n"
184  " condition names to numbers and use autogenerated condition names.\n"
185  "\n"
186  "-Wempty-character-class Warn if regular expression contains empty character class. From\n"
187  " the rational point of view trying to match empty character class\n"
188  " makes no sense: it should always fail. However, for backwards\n"
189  " compatibility reasons re2c allows empty character class and treats\n"
190  " it as empty string. Use '--empty-class' option to change default\n"
191  " behaviour.\n"
192  "\n"
193  "-Wmatch-empty-string Warn if regular expression in a rule is nullable (matches empty\n"
194  " string). If DFA runs in a loop and empty match is unintentional\n"
195  " (input position in not advanced manually), lexer may get stuck\n"
196  " in eternal loop.\n"
197  "\n"
198  "-Wswapped-range Warn if range lower bound is greater that upper bound. Default\n"
199  " re2c behaviour is to silently swap range bounds.\n"
200  "\n"
201  "-Wundefined-control-flow\n"
202  " Warn if some input strings cause undefined control flow in lexer\n"
203  " (the faulty patterns are reported). This is the most dangerous\n"
204  " and common mistake. It can be easily fixed by adding default rule\n"
205  " '*' (this rule has the lowest priority, matches any code unit\n"
206  " and consumes exactly one code unit).\n"
207  "\n"
208  "-Wuseless-escape Warn if a symbol is escaped when it shouldn't be. By default re2c\n"
209  " silently ignores escape, but this may as well indicate a typo\n"
210  " or an error in escape sequence.\n"
211  "\n"
212  );
213 }
void re2c::UTF16addContinuous1 ( RangeSuffix *&  root,
uint32_t  l,
uint32_t  h 
)

Definition at line 9 of file utf16_range.cc.

10 {
11  RangeSuffix ** p = &root;
12  for (;;)
13  {
14  if (*p == NULL)
15  {
16  *p = new RangeSuffix(l, h);
17  break;
18  }
19  else if ((*p)->l == l && (*p)->h == h)
20  {
21  break;
22  }
23  else
24  p = &(*p)->next;
25  }
26 }

Here is the caller graph for this function:

void re2c::UTF16addContinuous2 ( RangeSuffix *&  root,
uint32_t  l_ld,
uint32_t  h_ld,
uint32_t  l_tr,
uint32_t  h_tr 
)

Definition at line 32 of file utf16_range.cc.

33 {
34  RangeSuffix ** p = &root;
35  for (;;)
36  {
37  if (*p == NULL)
38  {
39  *p = new RangeSuffix(l_tr, h_tr);
40  p = &(*p)->child;
41  break;
42  }
43  else if ((*p)->l == l_tr && (*p)->h == h_tr)
44  {
45  p = &(*p)->child;
46  break;
47  }
48  else
49  p = &(*p)->next;
50  }
51  for (;;)
52  {
53  if (*p == NULL)
54  {
55  *p = new RangeSuffix(l_ld, h_ld);
56  break;
57  }
58  else if ((*p)->l == l_ld && (*p)->h == h_ld)
59  {
60  break;
61  }
62  else
63  p = &(*p)->next;
64  }
65 }

Here is the caller graph for this function:

RegExp * re2c::UTF16Range ( const Range r)

Definition at line 30 of file utf16_regexp.cc.

31 {
32  RangeSuffix * root = NULL;
33  for (; r != NULL; r = r->next ())
34  UTF16splitByRuneLength(root, r->lower (), r->upper () - 1);
35  return to_regexp (root);
36 }
RegExp * to_regexp(RangeSuffix *p)
Definition: range_suffix.cc:12
void UTF16splitByRuneLength(RangeSuffix *&root, utf16::rune l, utf16::rune h)
Definition: utf16_range.cc:120

Here is the call graph for this function:

void re2c::UTF16splitByContinuity ( RangeSuffix *&  root,
uint32_t  l_ld,
uint32_t  h_ld,
uint32_t  l_tr,
uint32_t  h_tr 
)

Definition at line 93 of file utf16_range.cc.

94 {
95  if (l_ld != h_ld)
96  {
97  if (l_tr > utf16::MIN_TRAIL_SURR)
98  {
99  UTF16splitByContinuity(root, l_ld, l_ld, l_tr, utf16::MAX_TRAIL_SURR);
100  UTF16splitByContinuity(root, l_ld + 1, h_ld, utf16::MIN_TRAIL_SURR, h_tr);
101  return;
102  }
103  if (h_tr < utf16::MAX_TRAIL_SURR)
104  {
105  UTF16splitByContinuity(root, l_ld, h_ld - 1, l_tr, utf16::MAX_TRAIL_SURR);
106  UTF16splitByContinuity(root, h_ld, h_ld, utf16::MIN_TRAIL_SURR, h_tr);
107  return;
108  }
109  }
110  UTF16addContinuous2(root, l_ld, h_ld, l_tr, h_tr);
111 }
void UTF16addContinuous2(RangeSuffix *&root, uint32_t l_ld, uint32_t h_ld, uint32_t l_tr, uint32_t h_tr)
Definition: utf16_range.cc:32
void UTF16splitByContinuity(RangeSuffix *&root, uint32_t l_ld, uint32_t h_ld, uint32_t l_tr, uint32_t h_tr)
Definition: utf16_range.cc:93

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::UTF16splitByRuneLength ( RangeSuffix *&  root,
utf16::rune  l,
utf16::rune  h 
)

Definition at line 120 of file utf16_range.cc.

121 {
122  if (l <= utf16::MAX_1WORD_RUNE)
123  {
124  if (h <= utf16::MAX_1WORD_RUNE)
125  {
126  UTF16addContinuous1(root, l, h);
127  }
128  else
129  {
130  UTF16addContinuous1(root, l, utf16::MAX_1WORD_RUNE);
131  const uint32_t h_ld = utf16::lead_surr(h);
132  const uint32_t h_tr = utf16::trail_surr(h);
133  UTF16splitByContinuity(root, utf16::MIN_LEAD_SURR, h_ld, utf16::MIN_TRAIL_SURR, h_tr);
134  }
135  }
136  else
137  {
138  const uint32_t l_ld = utf16::lead_surr(l);
139  const uint32_t l_tr = utf16::trail_surr(l);
140  const uint32_t h_ld = utf16::lead_surr(h);
141  const uint32_t h_tr = utf16::trail_surr(h);
142  UTF16splitByContinuity(root, l_ld, h_ld, l_tr, h_tr);
143  }
144 }
void UTF16addContinuous1(RangeSuffix *&root, uint32_t l, uint32_t h)
Definition: utf16_range.cc:9
void UTF16splitByContinuity(RangeSuffix *&root, uint32_t l_ld, uint32_t h_ld, uint32_t l_tr, uint32_t h_tr)
Definition: utf16_range.cc:93

Here is the call graph for this function:

Here is the caller graph for this function:

RegExp * re2c::UTF16Symbol ( utf16::rune  r)

Definition at line 12 of file utf16_regexp.cc.

13 {
14  if (r <= utf16::MAX_1WORD_RUNE)
15  return new MatchOp(Range::sym (r));
16  else
17  {
18  const uint32_t ld = utf16::lead_surr(r);
19  const uint32_t tr = utf16::trail_surr(r);
20  return new CatOp(new MatchOp(Range::sym (ld)), new MatchOp(Range::sym (tr)));
21  }
22 }

Here is the call graph for this function:

void re2c::UTF8addContinuous ( RangeSuffix *&  root,
utf8::rune  l,
utf8::rune  h,
uint32_t  n 
)

Definition at line 10 of file utf8_range.cc.

11 {
12  uint32_t lcs[utf8::MAX_RUNE_LENGTH];
13  uint32_t hcs[utf8::MAX_RUNE_LENGTH];
14  utf8::rune_to_bytes(lcs, l);
15  utf8::rune_to_bytes(hcs, h);
16 
17  RangeSuffix ** p = &root;
18  for (uint32_t i = 1; i <= n; ++i)
19  {
20  const uint32_t lc = lcs[n - i];
21  const uint32_t hc = hcs[n - i];
22  for (;;)
23  {
24  if (*p == NULL)
25  {
26  *p = new RangeSuffix(lc, hc);
27  p = &(*p)->child;
28  break;
29  }
30  else if ((*p)->l == lc && (*p)->h == hc)
31  {
32  p = &(*p)->child;
33  break;
34  }
35  else
36  p = &(*p)->next;
37  }
38  }
39 }

Here is the call graph for this function:

Here is the caller graph for this function:

RegExp * re2c::UTF8Range ( const Range r)

Definition at line 28 of file utf8_regexp.cc.

29 {
30  RangeSuffix * root = NULL;
31  for (; r != NULL; r = r->next ())
32  UTF8splitByRuneLength(root, r->lower (), r->upper () - 1);
33  return to_regexp (root);
34 }
RegExp * to_regexp(RangeSuffix *p)
Definition: range_suffix.cc:12
void UTF8splitByRuneLength(RangeSuffix *&root, utf8::rune l, utf8::rune h)
Definition: utf8_range.cc:100

Here is the call graph for this function:

void re2c::UTF8splitByContinuity ( RangeSuffix *&  root,
utf8::rune  l,
utf8::rune  h,
uint32_t  n 
)

Definition at line 67 of file utf8_range.cc.

68 {
69  for (uint32_t i = 1; i < n; ++i)
70  {
71  uint32_t m = (1u << (6u * i)) - 1u; // last i bytes of a UTF-8 sequence
72  if ((l & ~m) != (h & ~m))
73  {
74  if ((l & m) != 0)
75  {
76  UTF8splitByContinuity(root, l, l | m, n);
77  UTF8splitByContinuity(root, (l | m) + 1, h, n);
78  return;
79  }
80  if ((h & m) != m)
81  {
82  UTF8splitByContinuity(root, l, (h & ~m) - 1, n);
83  UTF8splitByContinuity(root, h & ~m, h, n);
84  return;
85  }
86  }
87  }
88  UTF8addContinuous(root, l, h, n);
89 }
void UTF8addContinuous(RangeSuffix *&root, utf8::rune l, utf8::rune h, uint32_t n)
Definition: utf8_range.cc:10
void UTF8splitByContinuity(RangeSuffix *&root, utf8::rune l, utf8::rune h, uint32_t n)
Definition: utf8_range.cc:67

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::UTF8splitByRuneLength ( RangeSuffix *&  root,
utf8::rune  l,
utf8::rune  h 
)

Definition at line 100 of file utf8_range.cc.

101 {
102  const uint32_t nh = utf8::rune_length(h);
103  for (uint32_t nl = utf8::rune_length(l); nl < nh; ++nl)
104  {
105  utf8::rune r = utf8::max_rune(nl);
106  UTF8splitByContinuity(root, l, r, nl);
107  l = r + 1;
108  }
109  UTF8splitByContinuity(root, l, h, nh);
110 }
void UTF8splitByContinuity(RangeSuffix *&root, utf8::rune l, utf8::rune h, uint32_t n)
Definition: utf8_range.cc:67

Here is the call graph for this function:

Here is the caller graph for this function:

RegExp * re2c::UTF8Symbol ( utf8::rune  r)

Definition at line 12 of file utf8_regexp.cc.

13 {
14  uint32_t chars[utf8::MAX_RUNE_LENGTH];
15  const uint32_t chars_count = utf8::rune_to_bytes(chars, r);
16  RegExp * re = new MatchOp(Range::sym (chars[0]));
17  for (uint32_t i = 1; i < chars_count; ++i)
18  re = new CatOp(re, new MatchOp(Range::sym (chars[i])));
19  return re;
20 }

Here is the call graph for this function:

void re2c::vernum ( )

Definition at line 215 of file msg.cc.

216 {
217  std::string vernum (PACKAGE_VERSION);
218  if (vernum[1] == '.')
219  {
220  vernum.insert(0, "0");
221  }
222  vernum.erase(2, 1);
223  if (vernum[3] == '.')
224  {
225  vernum.insert(2, "0");
226  }
227  vernum.erase(4, 1);
228  if (vernum.length() < 6 || vernum[5] < '0' || vernum[5] > '9')
229  {
230  vernum.insert(4, "0");
231  }
232  vernum.resize(6, '0');
233 
234  printf ("%s\n", vernum.c_str ());
235 }
void vernum()
Definition: msg.cc:215
void re2c::version ( )

Definition at line 237 of file msg.cc.

238 {
239  printf ("re2c %s\n", PACKAGE_VERSION);
240 }
void re2c::warning ( const char *  type,
uint32_t  line,
bool  error,
const char *  fmt,
  ... 
)

Definition at line 48 of file msg.cc.

49 {
50  warning_start (line, error);
51 
52  va_list args;
53  va_start (args, fmt);
54  vfprintf (stderr, fmt, args);
55  va_end (args);
56 
57  warning_end (type, error);
58 }
void error(const char *fmt,...)
Definition: msg.cc:10
void warning_start(uint32_t line, bool error)
Definition: msg.cc:32
void warning_end(const char *type, bool error)
Definition: msg.cc:38

Here is the call graph for this function:

Here is the caller graph for this function:

void re2c::warning_end ( const char *  type,
bool  error 
)

Definition at line 38 of file msg.cc.

39 {
40  if (type != NULL)
41  {
42  const char * prefix = error ? "error-" : "";
43  fprintf (stderr, " [-W%s%s]", prefix, type);
44  }
45  fprintf (stderr, "\n");
46 }
void error(const char *fmt,...)
Definition: msg.cc:10

Here is the caller graph for this function:

void re2c::warning_start ( uint32_t  line,
bool  error 
)

Definition at line 32 of file msg.cc.

33 {
34  static const char * msg = error ? "error" : "warning";
35  fprintf (stderr, "re2c: %s: line %u: ", msg, line);
36 }
void error(const char *fmt,...)
Definition: msg.cc:10

Here is the caller graph for this function:

Variable Documentation

bool re2c::bUsedYYBitmap = false

Definition at line 16 of file main.cc.

bool re2c::bWroteCondCheck = false

Definition at line 18 of file main.cc.

bool re2c::bWroteGetState = false

Definition at line 17 of file main.cc.

const size_t re2c::INFINITY = std::numeric_limits<size_t>::max()
static

Definition at line 10 of file fillpoints.cc.

uint32_t re2c::last_fill_index = 0

Definition at line 19 of file main.cc.

Opt re2c::opts

Definition at line 7 of file opt.cc.

const size_t re2c::UNDEFINED = INFINITY - 1
static

Definition at line 11 of file fillpoints.cc.

Warn re2c::warn

Definition at line 11 of file warn.cc.

std::string re2c::yySetupRule = ""

Definition at line 20 of file main.cc.