main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
translate.cc scanner.cc skeleton.cc mbo_getopt.cc print.cc input.cc input_api.cc output.cc \
enc.cc utf8.cc utf8_range.cc utf8_regexp.cc utf16.cc utf16_range.cc utf16_regexp.cc range_suffix.cc \
- basics.h code.h code_names.h dfa.h go.h enc.h indent.h input.h input_api.h free_list.h globals.h ins.h \
+ code.h code_names.h dfa.h go.h enc.h indent.h input.h input_api.h free_list.h globals.h ins.h \
mbo_getopt.h parser.h print.h range.h range_suffix.h re.h \
scanner.h skeleton.h smart_ptr.h substr.h token.h output.h \
utf16.h utf16_range.h utf16_regexp.h utf8.h utf8_range.h utf8_regexp.h
return ret;
}
-uint RegExp::fixedLength()
+uint32_t RegExp::fixedLength()
{
return ~0u;
}
-uint compile_goto(Ins *ins, Ins *i)
+uint32_t compile_goto(Ins *ins, Ins *i)
{
i->i.tag = GOTO;
i->i.link = ins;
size = 0;
}
-uint NullOp::fixedLength()
+uint32_t NullOp::fixedLength()
{
return 0;
}
-uint NullOp::compile(Char*, Ins*)
+uint32_t NullOp::compile(Char*, Ins*)
{
return 0;
}
size = 1;
for (Range *r = match; r; r = r->next)
- for (uint c = r->lb; c < r->ub; ++c)
+ for (uint32_t c = r->lb; c < r->ub; ++c)
if (rep[c] == c)
++size;
}
-uint MatchOp::fixedLength()
+uint32_t MatchOp::fixedLength()
{
return 1;
}
-uint MatchOp::compile(Char *rep, Ins *i)
+uint32_t MatchOp::compile(Char *rep, Ins *i)
{
if (ins_cache)
return compile_goto(ins_cache, i);
i->i.tag = CHAR;
i->i.link = &i[size];
Ins *j = &i[1];
- uint bump = size;
+ uint32_t bump = size;
for (Range *r = match; r; r = r->next)
{
- for (uint c = r->lb; c < r->ub; ++c)
+ for (uint32_t c = r->lb; c < r->ub; ++c)
{
if (rep[c] == c)
{
{
for (Range *r = match; r; r = r->next)
{
- for (uint c = r->lb; c < r->ub; ++c)
+ for (uint32_t c = r->lb; c < r->ub; ++c)
{
CharPtn *x = s.rep[c], *a = x->nxt;
size = exp1->size + exp2->size + 2;
}
-uint AltOp::fixedLength()
+uint32_t AltOp::fixedLength()
{
- uint l1 = exp1->fixedLength();
- uint l2 = exp1->fixedLength();
+ uint32_t l1 = exp1->fixedLength();
+ uint32_t l2 = exp1->fixedLength();
if (l1 != l2 || l1 == ~0u)
return ~0u;
return l1;
}
-uint AltOp::compile(Char *rep, Ins *i)
+uint32_t AltOp::compile(Char *rep, Ins *i)
{
if (ins_cache)
return compile_goto(ins_cache, i);
ins_cache = i;
i->i.tag = FORK;
- const uint sz1 = exp1->compile(rep, &i[1]);
+ const uint32_t sz1 = exp1->compile(rep, &i[1]);
Ins * const j = &i[sz1 + 1];
i->i.link = &j[1];
j->i.tag = GOTO;
- const uint sz2 = exp2->compile(rep, &j[1]);
+ const uint32_t sz2 = exp2->compile(rep, &j[1]);
j->i.link = &j[sz2 + 1];
if (ins_access == PRIVATE)
size = exp1->size + exp2->size;
}
-uint CatOp::fixedLength()
+uint32_t CatOp::fixedLength()
{
- uint l1, l2;
+ uint32_t l1, l2;
if ((l1 = exp1->fixedLength()) != ~0u )
if ((l2 = exp2->fixedLength()) != ~0u)
return ~0u;
}
-uint CatOp::compile(Char *rep, Ins *i)
+uint32_t CatOp::compile(Char *rep, Ins *i)
{
if (ins_cache)
return compile_goto(ins_cache, i);
{
ins_cache = i;
- const uint sz1 = exp1->compile(rep, &i[0]);
- const uint sz2 = exp2->compile(rep, &i[sz1]);
+ const uint32_t sz1 = exp1->compile(rep, &i[0]);
+ const uint32_t sz2 = exp2->compile(rep, &i[sz1]);
if (ins_access == PRIVATE)
decompile();
size = exp->size + 1;
}
-uint CloseOp::compile(Char *rep, Ins *i)
+uint32_t CloseOp::compile(Char *rep, Ins *i)
{
if (ins_cache)
return compile_goto(ins_cache, i);
i->i.link = ins_cache;
++i;
- const uint sz = i - ins_cache;
+ const uint32_t sz = i - ins_cache;
if (ins_access == PRIVATE)
decompile();
}
}
-uint CloseVOp::compile(Char *rep, Ins *i)
+uint32_t CloseVOp::compile(Char *rep, Ins *i)
{
if (ins_cache)
return compile_goto(ins_cache, i);
for (int st = min; st < max; st++)
{
- const uint sz = exp->compile(rep, &i[1]);
+ const uint32_t sz = exp->compile(rep, &i[1]);
i->i.tag = FORK;
i->i.link = ins_cache + (1 + sz) * (max - min);
i += sz + 1;
for (int st = 0; st < min; st++)
{
- const uint sz = exp->compile(rep, &i[0]);
+ const uint32_t sz = exp->compile(rep, &i[0]);
i += sz;
if (max < 0 && st == 0)
{
}
}
- const uint sz = i - ins_cache;
+ const uint32_t sz = i - ins_cache;
if (ins_access == PRIVATE)
decompile();
RegExp *expr(Scanner &);
-uint Scanner::unescape(SubStr &s) const
+uint32_t Scanner::unescape(SubStr &s) const
{
static const char * hex = "0123456789abcdef";
static const char * oct = "01234567";
s.len--;
- uint c, ucb = 0;
+ uint32_t c, ucb = 0;
if ((c = *s.str++) != '\\' || s.len == 0)
{
s.len -= 2;
s.str += 2;
- uint v = (uint)((p1 - hex) << 4)
- + (uint)((p2 - hex));
+ uint32_t v = (uint32_t)((p1 - hex) << 4)
+ + (uint32_t)((p2 - hex));
return v;
}
return ~0u;
}
- uint l = 0;
+ uint32_t l = 0;
if (s.str[0] == '0')
{
l++;
const char *u4 = strchr(hex, tolower(s.str[3]));
if (u3 && u4)
{
- ucb = (uint)((u3 - hex) << 20)
- + (uint)((u4 - hex) << 16);
+ ucb = (uint32_t)((u3 - hex) << 20)
+ + (uint32_t)((u4 - hex) << 16);
l++;
}
}
s.len -= 4;
s.str += 4;
- uint v = (uint)((p1 - hex) << 12)
- + (uint)((p2 - hex) << 8)
- + (uint)((p3 - hex) << 4)
- + (uint)((p4 - hex))
+ uint32_t v = (uint32_t)((p1 - hex) << 12)
+ + (uint32_t)((p2 - hex) << 8)
+ + (uint32_t)((p3 - hex) << 4)
+ + (uint32_t)((p4 - hex))
+ ucb;
if (v >= encoding.nCodePoints())
s.len -= 2;
s.str += 2;
- uint v = (uint)((p0 - oct) << 6) + (uint)((p1 - oct) << 3) + (uint)(p2 - oct);
+ uint32_t v = (uint32_t)((p0 - oct) << 6) + (uint32_t)((p1 - oct) << 3) + (uint32_t)(p2 - oct);
return v;
}
while(str_in.len)
{
- uint c = unescape(str_in);
+ uint32_t c = unescape(str_in);
if (c > 0xFF)
{
Range * Scanner::getRange(SubStr &s) const
{
- uint lb = unescape(s), ub;
+ uint32_t lb = unescape(s), ub;
if (s.len < 2 || *s.str != '-')
{
ub = unescape(s);
if (ub < lb)
{
- uint tmp = lb;
+ uint32_t tmp = lb;
lb = ub;
ub = tmp;
}
return r;
}
-RegExp * Scanner::matchSymbol(uint c) const
+RegExp * Scanner::matchSymbol(uint32_t c) const
{
if (!encoding.encode(c))
fatalf("Bad code point: '0x%X'", c);
if (s.len == 0)
return new NullOp;
- uint c = unescape(s);
+ uint32_t c = unescape(s);
RegExp *re, *reL, *reU;
while (s.len > 0)
{
- uint c = unescape(s);
+ uint32_t c = unescape(s);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
RegExp * Scanner::mkDot() const
{
Range * full = encoding.fullRange();
- uint c = '\n';
+ uint32_t c = '\n';
if (!encoding.encode(c))
fatalf("Bad code point: '0x%X'", c);
Range * ran = new Range(c, c + 1);
return new MatchOp(def);
}
-RuleOp::RuleOp(RegExp *e, RegExp *c, Token *t, uint a, InsAccess access)
+RuleOp::RuleOp(RegExp *e, RegExp *c, Token *t, uint32_t a, InsAccess access)
: exp(e)
, ctx(c)
, ins(NULL)
ins_access = access;
}
-RuleOp* RuleOp::copy(uint a) const
+RuleOp* RuleOp::copy(uint32_t a) const
{
Token *token = new Token(*code);
return new RuleOp(exp, ctx, token, a, ins_access);
size = exp->size + (ctx->size ? ctx->size + 2 : 1);
}
-uint RuleOp::compile(Char *rep, Ins *i)
+uint32_t RuleOp::compile(Char *rep, Ins *i)
{
if (ins_cache)
return compile_goto(ins_cache, i);
i->i.link = this;
++i;
- const uint sz = i - ins_cache;
+ const uint32_t sz = i - ins_cache;
if (ins_access == PRIVATE)
decompile();
, rep(new CharPtr[encoding.nCodeUnits()])
, ptn(new CharPtn[encoding.nCodeUnits()])
{
- for (uint j = 0; j < encoding.nCodeUnits(); ++j)
+ for (uint32_t j = 0; j < encoding.nCodeUnits(); ++j)
{
rep[j] = &ptn[0];
ptn[j].nxt = &ptn[j + 1]; /* wrong for j=encoding.nCodeUnits() - 1 but will be corrected below */
delete[] ptn;
}
-smart_ptr<DFA> genCode(RegExp *re, Output & output, uint ind)
+smart_ptr<DFA> genCode(RegExp *re, Output & output, uint32_t ind)
{
CharSet cs;
re->split(cs);
- /*for(uint k = 0; k < encoding.nCodeUnits();)
+ /*for(uint32_t k = 0; k < encoding.nCodeUnits();)
{
- uint j;
+ uint32_t j;
for(j = k; ++k < encoding.nCodeUnits() && cs.rep[k] == cs.rep[j];);
printSpan(std::cerr, j, k);
std::cerr << "\t" << cs.rep[j] - &cs.ptn[0] << std::endl;
Char *rep = new Char[encoding.nCodeUnits()];
- for (uint j = 0; j < encoding.nCodeUnits(); ++j)
+ for (uint32_t j = 0; j < encoding.nCodeUnits(); ++j)
{
if (!cs.rep[j]->nxt)
cs.rep[j]->nxt = &cs.ptn[j];
re->calcSize(rep);
Ins *ins = new Ins[re->size + 1];
memset(ins, 0, (re->size + 1)*sizeof(Ins));
- const uint size = re->compile(rep, ins);
+ const uint32_t size = re->compile(rep, ins);
Ins *eoi = &ins[size];
eoi->i.tag = GOTO;
eoi->i.link = eoi;
}
*/
- for (uint j = 0; j < size;)
+ for (uint32_t j = 0; j < size;)
{
unmark(&ins[j]);
+++ /dev/null
-/* $Id$ */
-#ifndef _basics_h
-#define _basics_h
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#elif defined(_WIN32)
-#include "config_w32.h"
-#endif
-
-namespace re2c
-{
-
-#if SIZEOF_CHAR == 1
-typedef unsigned char byte;
-#elif SIZEOF_SHORT == 1
-typedef unsigned short byte;
-#elif SIZEOF_INT == 1
-typedef unsigned int byte;
-#elif SIZEOF_LONG == 1
-typedef unsigned long byte;
-#else
-typedef unsigned char byte;
-#endif
-
-#if SIZEOF_CHAR == 2
-typedef unsigned char word;
-#elif SIZEOF_SHORT == 2
-typedef unsigned short word;
-#elif SIZEOF_INT == 2
-typedef unsigned int word;
-#elif SIZEOF_LONG == 2
-typedef unsigned long word;
-#else
-typedef unsigned short word;
-#endif
-
-#if SIZEOF_CHAR == 4
-typedef unsigned char dword;
-#elif SIZEOF_SHORT == 4
-typedef unsigned short dword;
-#elif SIZEOF_INT == 4
-typedef unsigned int dword;
-#elif SIZEOF_LONG == 4
-typedef unsigned long dword;
-#else
-typedef unsigned long dword;
-#endif
-
-typedef unsigned int uint;
-typedef unsigned char uchar;
-typedef unsigned short ushort;
-typedef unsigned long ulong;
-
-} // end namespace re2c
-
-#endif
#include "globals.h"
#include "parser.h"
-#include "basics.h"
+#include "c99_stdint.h"
#include "dfa.h"
#include "smart_ptr.h"
void yyerror(const char*);
}
-static re2c::uint accept;
+static uint32_t accept;
static re2c::RegExpMap specMap;
static RegExp *spec = NULL, *specNone = NULL;
static RuleOpList specStar;
}
if (specMap.size() < ruleSetupMap.size())
{
- uint line = in->get_cline();
+ uint32_t line = in->get_cline();
itRuleSetup = ruleSetupMap.find("*");
if (itRuleSetup != ruleSetupMap.end())
{
-/* Generated by re2c 0.14.1.dev on Tue Mar 31 13:52:34 2015*/
+/* Generated by re2c 0.14.1.dev on Mon Apr 20 23:30:58 2015*/
#include <stdlib.h>
#include <string.h>
#include <iostream>
int Scanner::scan()
{
char *cursor = cur;
- uint depth;
+ uint32_t depth;
scan:
tchar = cursor - pos;
--- /dev/null
+// taken from:
+// http://groups.csail.mit.edu/cis/md6/submitted-2008-10-27/Optimized_64bit/
+
+// ISO C9x compliant stdint.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006 Alexander Chemeris
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// 3. The name of the author may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUC__
+# define __STDINT_H_IS_PRESENT
+#endif /* __GNUC__ */
+
+#ifdef _MSC_VER
+# if _MSC_VER >= 1600
+# define __STDINT_H_IS_PRESENT
+# endif
+#endif /* _MSC_VER */
+
+#ifdef __STDINT_H_IS_PRESENT // [
+// c99 compliant compiler
+#include <stdint.h>
+#else
+
+#ifndef _MSC_STDINT_H_ // [
+#define _MSC_STDINT_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include <limits.h>
+
+// For Visual Studio 6 in C++ mode wrap <wchar.h> include with 'extern "C++" {}'
+// or compiler give many errors like this:
+// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
+#if (_MSC_VER < 1300) && defined(__cplusplus)
+ extern "C++" {
+#endif
+# include <wchar.h>
+#if (_MSC_VER < 1300) && defined(__cplusplus)
+ }
+#endif
+
+// 7.18.1 Integer types
+
+// 7.18.1.1 Exact-width integer types
+typedef signed __int8 int8_t;
+typedef signed __int16 int16_t;
+typedef signed __int32 int32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+
+// 7.18.1.2 Minimum-width integer types
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+// 7.18.1.3 Fastest minimum-width integer types
+typedef int8_t int_fast8_t;
+typedef int16_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef int64_t int_fast64_t;
+typedef uint8_t uint_fast8_t;
+typedef uint16_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+
+// 7.18.1.4 Integer types capable of holding object pointers
+#ifdef _WIN64 // [
+ typedef __int64 intptr_t;
+ typedef unsigned __int64 uintptr_t;
+#else // _WIN64 ][
+ typedef int intptr_t;
+ typedef unsigned int uintptr_t;
+#endif // _WIN64 ]
+
+// 7.18.1.5 Greatest-width integer types
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+
+
+// 7.18.2 Limits of specified-width integer types
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
+
+// 7.18.2.1 Limits of exact-width integer types
+#define INT8_MIN ((int8_t)_I8_MIN)
+#define INT8_MAX _I8_MAX
+#define INT16_MIN ((int16_t)_I16_MIN)
+#define INT16_MAX _I16_MAX
+#define INT32_MIN ((int32_t)_I32_MIN)
+#define INT32_MAX _I32_MAX
+#define INT64_MIN ((int64_t)_I64_MIN)
+#define INT64_MAX _I64_MAX
+#define UINT8_MAX _UI8_MAX
+#define UINT16_MAX _UI16_MAX
+#define UINT32_MAX _UI32_MAX
+#define UINT64_MAX _UI64_MAX
+
+// 7.18.2.2 Limits of minimum-width integer types
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+// 7.18.2.3 Limits of fastest minimum-width integer types
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+// 7.18.2.4 Limits of integer types capable of holding object pointers
+#ifdef _WIN64 // [
+# define INTPTR_MIN INT64_MIN
+# define INTPTR_MAX INT64_MAX
+# define UINTPTR_MAX UINT64_MAX
+#else // _WIN64 ][
+# define INTPTR_MIN INT32_MIN
+# define INTPTR_MAX INT32_MAX
+# define UINTPTR_MAX UINT32_MAX
+#endif // _WIN64 ]
+
+// 7.18.2.5 Limits of greatest-width integer types
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+// 7.18.3 Limits of other integer types
+
+#ifdef _WIN64 // [
+# define PTRDIFF_MIN _I64_MIN
+# define PTRDIFF_MAX _I64_MAX
+#else // _WIN64 ][
+# define PTRDIFF_MIN _I32_MIN
+# define PTRDIFF_MAX _I32_MAX
+#endif // _WIN64 ]
+
+#define SIG_ATOMIC_MIN INT_MIN
+#define SIG_ATOMIC_MAX INT_MAX
+
+#ifndef SIZE_MAX // [
+# ifdef _WIN64 // [
+# define SIZE_MAX _UI64_MAX
+# else // _WIN64 ][
+# define SIZE_MAX _UI32_MAX
+# endif // _WIN64 ]
+#endif // SIZE_MAX ]
+
+// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
+#ifndef WCHAR_MIN // [
+# define WCHAR_MIN 0
+#endif // WCHAR_MIN ]
+#ifndef WCHAR_MAX // [
+# define WCHAR_MAX _UI16_MAX
+#endif // WCHAR_MAX ]
+
+#define WINT_MIN 0
+#define WINT_MAX _UI16_MAX
+
+#endif // __STDC_LIMIT_MACROS ]
+
+
+// 7.18.4 Limits of other integer types
+
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
+
+// 7.18.4.1 Macros for minimum-width integer constants
+
+#define INT8_C(val) val##i8
+#define INT16_C(val) val##i16
+#define INT32_C(val) val##i32
+#define INT64_C(val) val##i64
+
+#define UINT8_C(val) val##ui8
+#define UINT16_C(val) val##ui16
+#define UINT32_C(val) val##ui32
+#define UINT64_C(val) val##ui64
+
+// 7.18.4.2 Macros for greatest-width integer constants
+#define INTMAX_C INT64_C
+#define UINTMAX_C UINT64_C
+
+#endif // __STDC_CONSTANT_MACROS ]
+
+
+#endif // _MSC_STDINT_H_ ]
+#endif
return str;
}
-static void genYYFill(OutputFile & o, uint, uint need)
+static void genYYFill(OutputFile & o, uint32_t, uint32_t need)
{
if (bUseYYFillParam)
{
}
}
-static void genSetCondition(OutputFile & o, uint ind, const std::string& newcond)
+static void genSetCondition(OutputFile & o, uint32_t ind, const std::string& newcond)
{
if (bUseYYSetConditionParam)
{
}
}
-static void doGen(const Go *g, const State *s, uint *bm, uint f, uint m)
+static void doGen(const Go *g, const State *s, uint32_t *bm, uint32_t f, uint32_t m)
{
Span *b = g->span, *e = &b[g->nSpans];
- uint lb = 0;
+ uint32_t lb = 0;
for (; b < e; ++b)
{
return NULL;
}
-void BitMap::gen(OutputFile & o, uint ind, uint lb, uint ub)
+void BitMap::gen(OutputFile & o, uint32_t ind, uint32_t lb, uint32_t ub)
{
if (first && bUsedYYBitmap)
{
o << indent(ind) << "static const unsigned char " << mapCodeName["yybm"] << "[] = {";
- uint c = 1, n = ub - lb;
+ uint32_t c = 1, n = ub - lb;
const BitMap *cb = first;
while((cb = cb->next) != NULL) {
}
BitMap *b = first;
- uint *bm = new uint[n];
+ uint32_t *bm = new uint32_t[n];
- for (uint i = 0, t = 1; b; i += n, t += 8)
+ for (uint32_t i = 0, t = 1; b; i += n, t += 8)
{
- memset(bm, 0, n * sizeof(uint));
+ memset(bm, 0, n * sizeof(uint32_t));
- for (uint m = 0x80; b && m; m >>= 1)
+ for (uint32_t m = 0x80; b && m; m >>= 1)
{
b->i = i;
b->m = m;
o << "\n" << indent(ind+1) << "/* table " << t << " .. " << std::min(c, t+7) << ": " << i << " */";
}
- for (uint j = 0; j < n; ++j)
+ for (uint32_t j = 0; j < n; ++j)
{
if (j % 8 == 0)
{
}
else
{
- o.write_uint_width (bm[j], 3);
+ o.write_uint32_t_width (bm[j], 3);
}
o << ", ";
}
}
}
-static void genGoTo(OutputFile & o, uint ind, const State *from, const State *to, bool & readCh)
+static void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, bool & readCh)
{
if (DFlag)
{
vUsedLabels.insert(to->label);
}
-static void need(OutputFile & o, uint ind, uint n, bool & readCh, bool bSetMarker)
+static void need(OutputFile & o, uint32_t ind, uint32_t n, bool & readCh, bool bSetMarker)
{
if (DFlag)
{
return;
}
- uint fillIndex = next_fill_index;
+ uint32_t fillIndex = next_fill_index;
if (fFlag)
{
}
}
-void Match::emit(Output & output, uint ind, bool &readCh, const std::string&) const
+void Match::emit(Output & output, uint32_t ind, bool &readCh, const std::string&) const
{
OutputFile & o = output.source;
}
}
-void Initial::emit(Output & output, uint ind, bool &readCh, const std::string&) const
+void Initial::emit(Output & output, uint32_t ind, bool &readCh, const std::string&) const
{
OutputFile & o = output.source;
}
}
-void Save::emit(Output & output, uint ind, bool &readCh, const std::string&) const
+void Save::emit(Output & output, uint32_t ind, bool &readCh, const std::string&) const
{
OutputFile & o = output.source;
}
}
-void Move::emit(Output &, uint, bool &, const std::string&) const
+void Move::emit(Output &, uint32_t, bool &, const std::string&) const
{
;
}
void Accept::genRuleMap()
{
- for (uint i = 0; i < nRules; ++i)
+ for (uint32_t i = 0; i < nRules; ++i)
{
if (saves[i] != ~0u)
{
}
}
-void Accept::emitBinary(OutputFile & o, uint ind, uint l, uint r, bool &readCh) const
+void Accept::emitBinary(OutputFile & o, uint32_t ind, uint32_t l, uint32_t r, bool &readCh) const
{
if (l < r)
{
- uint m = (l + r) >> 1;
+ uint32_t m = (l + r) >> 1;
o << indent(ind) << "if (" << mapCodeName["yyaccept"] << (r == l+1 ? " == " : " <= ") << m << ") {\n";
emitBinary(o, ++ind, l, m, readCh);
}
}
-void Accept::emit(Output & output, uint ind, bool &readCh, const std::string &) const
+void Accept::emit(Output & output, uint32_t ind, bool &readCh, const std::string &) const
{
OutputFile & o = output.source;
}
}
-void Rule::emit(Output & output, uint ind, bool &, const std::string& condName) const
+void Rule::emit(Output & output, uint32_t ind, bool &, const std::string& condName) const
{
OutputFile & o = output.source;
return;
}
- uint back = rule->ctx->fixedLength();
+ uint32_t back = rule->ctx->fixedLength();
if (back != 0u && !DFlag)
{
o.insert_line_info ();
}
-void State::emit(Output & output, uint ind, bool &readCh, const std::string& condName) const
+void State::emit(Output & output, uint32_t ind, bool &readCh, const std::string& condName) const
{
OutputFile & o = output.source;
action->emit(output, ind, readCh, condName);
}
-static uint merge(Span *x0, State *fg, State *bg)
+static uint32_t merge(Span *x0, State *fg, State *bg)
{
Span *x = x0, *f = fg->go.span, *b = bg->go.span;
- uint nf = fg->go.nSpans, nb = bg->go.nSpans;
+ uint32_t nf = fg->go.nSpans, nb = bg->go.nSpans;
State *prev = NULL, *to;
// NB: we assume both spans are for same range
}
}
-static const uint cInfinity = ~0u;
+static const uint32_t cInfinity = ~0u;
class SCC
{
State **top, **stk;
public:
- SCC(uint);
+ SCC(uint32_t);
~SCC();
void traverse(State*);
#endif
};
-SCC::SCC(uint size)
+SCC::SCC(uint32_t size)
: top(new State * [size])
, stk(top)
{
void SCC::traverse(State *x)
{
*top = x;
- uint k = ++top - stk;
+ uint32_t k = ++top - stk;
x->depth = k;
- for (uint i = 0; i < x->go.nSpans; ++i)
+ for (uint32_t i = 0; i < x->go.nSpans; ++i)
{
State *y = x->go.span[i].to;
// Note: (s->go.spans[i].to == s) is allowed, corresponds to s
// looping back to itself.
//
- for (uint i = 0; i < s->go.nSpans; ++i)
+ for (uint32_t i = 0; i < s->go.nSpans; ++i)
{
const State* t = s->go.span[i].to;
return false;
}
-static uint maxDist(State *s)
+static uint32_t maxDist(State *s)
{
if (s->depth != cInfinity)
{
// Already calculated, just return result.
return s->depth;
}
- uint mm = 0;
+ uint32_t mm = 0;
- for (uint i = 0; i < s->go.nSpans; ++i)
+ for (uint32_t i = 0; i < s->go.nSpans; ++i)
{
State *t = s->go.span[i].to;
if (t)
{
- uint m = 1;
+ uint32_t m = 1;
if (!t->link) // marked as non-key state
{
{
if (!s->link)
{
- for (uint i = 0; i < s->go.nSpans; ++i)
+ for (uint32_t i = 0; i < s->go.nSpans; ++i)
{
State *to = s->go.span[i].to;
if (to->isBase)
{
to = to->go.span[0].to;
- uint nSpans = merge(span, s, to);
+ uint32_t nSpans = merge(span, s, to);
if (nSpans < s->go.nSpans)
{
delete [] span;
}
-void DFA::prepare(uint & max_fill)
+void DFA::prepare(uint32_t & max_fill)
{
State *s;
- uint i;
+ uint32_t i;
bUsedYYBitmap = false;
findSCCs();
head->link = head;
- uint nRules = 0;
+ uint32_t nRules = 0;
for (s = head; s; s = s->next)
{
}
}
- uint nSaves = 0;
- saves = new uint[nRules];
+ uint32_t nSaves = 0;
+ saves = new uint32_t[nRules];
memset(saves, ~0, (nRules)*sizeof(*saves));
// mark backtracking points
}
}
-void DFA::emit(Output & output, uint& ind, const RegExpMap* specMap, const std::string& condName, bool isLastCond, bool& bPrologBrace)
+void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const std::string& condName, bool isLastCond, bool& bPrologBrace)
{
OutputFile & o = output.source;
// start_label corresponds to current condition.
// NOTE: prolog_label must be yy0 because of the !getstate:re2c handling
// in scanner.re
- uint prolog_label = next_label;
+ uint32_t prolog_label = next_label;
if (bProlog && cFlag)
{
next_label++;
}
- uint start_label = next_label;
+ uint32_t start_label = next_label;
(void) new Initial(head, next_label++, bSaveOnHead);
// Save 'next_fill_index' and compute information about code generation
// while writing to null device.
- uint save_fill_index = next_fill_index;
+ uint32_t save_fill_index = next_fill_index;
Output null_dev (NULL, NULL);
for (s = head; s; s = s->next)
bUseStartLabel = false;
}
-static void output_state_goto_sub (std::ostream & o, uint ind, uint start_label, int cMin, int cMax)
+static void output_state_goto_sub (std::ostream & o, uint32_t ind, uint32_t start_label, int cMin, int cMax)
{
if (cMin == cMax)
{
}
}
-void output_state_goto (std::ostream & o, uint ind, uint start_label)
+void output_state_goto (std::ostream & o, uint32_t ind, uint32_t start_label)
{
if (gFlag)
{
}
}
-void genCondTable(OutputFile & o, uint ind, const RegExpMap& specMap)
+void genCondTable(OutputFile & o, uint32_t ind, const RegExpMap& specMap)
{
if (cFlag && !bWroteCondCheck && gFlag && specMap.size())
{
}
}
-static void genCondGotoSub(OutputFile & o, uint ind, RegExpIndices& vCondList, uint cMin, uint cMax)
+static void genCondGotoSub(OutputFile & o, uint32_t ind, RegExpIndices& vCondList, uint32_t cMin, uint32_t cMax)
{
if (cMin == cMax)
{
}
else
{
- uint cMid = cMin + ((cMax - cMin + 1) / 2);
+ uint32_t cMid = cMin + ((cMax - cMin + 1) / 2);
o << indent(ind) << "if (" << genGetCondition() << " < " << cMid << ") {\n";
genCondGotoSub(o, ind + 1, vCondList, cMin, cMid - 1);
}
}
-void genCondGoto(OutputFile & o, uint ind, const RegExpMap& specMap)
+void genCondGoto(OutputFile & o, uint32_t ind, const RegExpMap& specMap)
{
if (cFlag && !bWroteCondCheck && specMap.size())
{
}
}
-void output_yyaccept_init (std::ostream & o, uint ind, bool used_yyaccept)
+void output_yyaccept_init (std::ostream & o, uint32_t ind, bool used_yyaccept)
{
if (used_yyaccept)
{
}
}
-void output_yyaccept_selector (std::ostream & o, uint ind, bool used_yyaccept, uint yyaccept_selector)
+void output_yyaccept_selector (std::ostream & o, uint32_t ind, bool used_yyaccept, uint32_t yyaccept_selector)
{
if (used_yyaccept)
{
}
}
-void output_yymaxfill (std::ostream & o, uint max_fill)
+void output_yymaxfill (std::ostream & o, uint32_t max_fill)
{
o << "#define YYMAXFILL " << max_fill << "\n";
}
-void output_line_info (std::ostream & o, uint line_number, const char * file_name)
+void output_line_info (std::ostream & o, uint32_t line_number, const char * file_name)
{
if (!iFlag)
{
}
}
-void output_types (std::ostream & o, uint ind, const std::vector<std::string> & types)
+void output_types (std::ostream & o, uint32_t ind, const std::vector<std::string> & types)
{
o << indent (ind++) << "enum " << mapCodeName["YYCONDTYPE"] << " {\n";
for (unsigned int i = 0; i < types.size (); ++i)
, out (o)
{}
-char *Scanner::fill(char *cursor, uint need)
+char *Scanner::fill(char *cursor, uint32_t need)
{
if(!eof)
{
- uint cnt;
+ uint32_t cnt;
/* Do not get rid of anything when rFlag is active. Otherwise
* get rid of everything that was already handedout. */
if (!rFlag)
{
need = BSIZE;
}
- if (static_cast<uint>(top - lim) < need)
+ if (static_cast<uint32_t>(top - lim) < need)
{
char *buf = new char[(lim - bot) + need];
if (!buf)
in_parse = new_in_parse;
}
-void Scanner::fatal_at(uint line, uint ofs, const char *msg) const
+void Scanner::fatal_at(uint32_t line, uint32_t ofs, const char *msg) const
{
std::cerr << "re2c: error: "
<< "line " << line << ", column " << (tchar + ofs + 1) << ": "
exit(1);
}
-void Scanner::fatal(uint ofs, const char *msg) const
+void Scanner::fatal(uint32_t ofs, const char *msg) const
{
fatal_at(in_parse ? tline : cline, ofs, msg);
}
-void Scanner::fatalf_at(uint line, const char* fmt, ...) const
+void Scanner::fatalf_at(uint32_t line, const char* fmt, ...) const
{
char szBuf[4096];
}
}
-void Scanner::check_token_length(char *pos, uint len) const
+void Scanner::check_token_length(char *pos, uint32_t len) const
{
if (pos < bot || pos + len > top)
{
const Go *go;
const State *on;
const BitMap *next;
- uint i;
- uint m;
+ uint32_t i;
+ uint32_t m;
public:
static const BitMap *find(const Go*, const State*);
static const BitMap *find(const State*);
- static void gen(OutputFile &, uint ind, uint, uint);
+ static void gen(OutputFile &, uint32_t ind, uint32_t, uint32_t);
BitMap(const Go*, const State*);
~BitMap();
o << "\n";
- uint lb = 0;
+ uint32_t lb = 0;
- for (uint i = 0; i < s.go.nSpans; ++i)
+ for (uint32_t i = 0; i < s.go.nSpans; ++i)
{
lb = s.go.span[i].show(o, lb);
}
void *to;
};
-DFA::DFA(Ins *ins, uint ni, uint lb, uint ub, const Char *rep)
+DFA::DFA(Ins *ins, uint32_t ni, uint32_t lb, uint32_t ub, const Char *rep)
: lbChar(lb)
, ubChar(ub)
, nStates(0)
, free_rep(rep)
{
Ins **work = new Ins * [ni + 1];
- uint nc = ub - lb;
+ uint32_t nc = ub - lb;
GoTo *goTo = new GoTo[nc];
Span *span = new Span[nc];
memset((char*) goTo, 0, nc*sizeof(GoTo));
toDo = s->link;
Ins **cP, **iP, *i;
- uint nGoTos = 0;
- uint j;
+ uint32_t nGoTos = 0;
+ uint32_t j;
s->rule = NULL;
tail = &s->next;
}
-State *DFA::findState(Ins **kernel, uint kCount)
+State *DFA::findState(Ins **kernel, uint32_t kCount)
{
Ins **cP, **iP, *i;
State *s;
Action(State*);
virtual ~Action();
- virtual void emit(Output &, uint, bool&, const std::string&) const = 0;
+ virtual void emit(Output &, uint32_t, bool&, const std::string&) const = 0;
virtual bool readAhead() const;
#ifdef PEDANTIC
{
public:
Match(State*);
- void emit(Output &, uint, bool&, const std::string&) const;
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
};
class Initial: public Action
{
public:
- uint label;
+ uint32_t label;
bool setMarker;
public:
- Initial(State*, uint, bool);
- void emit(Output &, uint, bool&, const std::string&) const;
+ Initial(State*, uint32_t, bool);
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
};
class Save: public Match
{
public:
- uint selector;
+ uint32_t selector;
public:
- Save(State*, uint);
- void emit(Output &, uint, bool&, const std::string&) const;
+ Save(State*, uint32_t);
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
};
class Move: public Action
public:
Move(State*);
- void emit(Output &, uint, bool&, const std::string&) const;
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
};
class Accept: public Action
{
public:
- typedef std::map<uint, State*> RuleMap;
+ typedef std::map<uint32_t, State*> RuleMap;
- uint nRules;
- uint *saves;
+ uint32_t nRules;
+ uint32_t *saves;
State **rules;
RuleMap mapRules;
public:
- Accept(State*, uint, uint*, State**);
- void emit(Output &, uint, bool&, const std::string&) const;
- void emitBinary(OutputFile & o, uint ind, uint l, uint r, bool &readCh) const;
+ Accept(State*, uint32_t, uint32_t*, State**);
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
+ void emitBinary(OutputFile & o, uint32_t ind, uint32_t l, uint32_t r, bool &readCh) const;
void genRuleMap();
#ifdef PEDANTIC
public:
Rule(State*, RuleOp*);
- void emit(Output &, uint, bool&, const std::string&) const;
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
#ifdef PEDANTIC
private:
{
public:
- uint label;
+ uint32_t label;
RuleOp *rule;
State *next;
State *link;
- uint depth; // for finding SCCs
- uint kCount;
+ uint32_t depth; // for finding SCCs
+ uint32_t kCount;
Ins **kernel;
bool isPreCtxt;
public:
State();
~State();
- void emit(Output &, uint, bool&, const std::string&) const;
+ void emit(Output &, uint32_t, bool&, const std::string&) const;
friend std::ostream& operator<<(std::ostream&, const State&);
friend std::ostream& operator<<(std::ostream&, const State*);
{
public:
- uint lbChar;
- uint ubChar;
- uint nStates;
+ uint32_t lbChar;
+ uint32_t ubChar;
+ uint32_t nStates;
State *head, **tail;
State *toDo;
const Ins *free_ins;
protected:
bool bSaveOnHead;
- uint *saves;
+ uint32_t *saves;
State **rules;
public:
- DFA(Ins*, uint, uint, uint, const Char*);
+ DFA(Ins*, uint32_t, uint32_t, uint32_t, const Char*);
~DFA();
void addState(State**, State*);
- State *findState(Ins**, uint);
+ State *findState(Ins**, uint32_t);
void split(State*);
void findSCCs();
void findBaseState();
- void prepare(uint &);
- void emit(Output &, uint&, const RegExpMap*, const std::string&, bool, bool&);
+ void prepare(uint32_t &);
+ void emit(Output &, uint32_t&, const RegExpMap*, const std::string&, bool, bool&);
friend std::ostream& operator<<(std::ostream&, const DFA&);
friend std::ostream& operator<<(std::ostream&, const DFA*);
type = MATCH;
}
-inline Initial::Initial(State *s, uint l, bool b) : Action(s), label(l), setMarker(b)
+inline Initial::Initial(State *s, uint32_t l, bool b) : Action(s), label(l), setMarker(b)
{
type = INITIAL;
}
-inline Save::Save(State *s, uint i) : Match(s), selector(i)
+inline Save::Save(State *s, uint32_t i) : Match(s), selector(i)
{
type = SAVE;
}
type = MOVE;
}
-inline Accept::Accept(State *x, uint n, uint *s, State **r)
+inline Accept::Accept(State *x, uint32_t n, uint32_t *s, State **r)
: Action(x), nRules(n), saves(s), rules(r)
{
type = ACCEPT;
namespace re2c {
-const uint Enc::SURR_MIN = 0xD800;
-const uint Enc::SURR_MAX = 0xDFFF;
-const uint Enc::UNICODE_ERROR = 0xFFFD;
+const uint32_t Enc::SURR_MIN = 0xD800;
+const uint32_t Enc::SURR_MAX = 0xDFFF;
+const uint32_t Enc::UNICODE_ERROR = 0xFFFD;
-const uint Enc::asc2ebc[256] =
+const uint32_t Enc::asc2ebc[256] =
{ /* Based on ISO 8859/1 and Code Page 37 */
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0xae, 0xdf
};
-const uint Enc::ebc2asc[256] =
+const uint32_t Enc::ebc2asc[256] =
{ /* Based on ISO 8859/1 and Code Page 37 */
0x00, 0x01, 0x02, 0x03, 0x9c, 0x09, 0x86, 0x7f, 0x97, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x9d, 0x85, 0x08, 0x87, 0x18, 0x19, 0x92, 0x8f, 0x1c, 0x1d, 0x1e, 0x1f,
* by current policy, otherwise returns true.
* Overwrites code point.
*/
-bool Enc::encode(uint & c) const
+bool Enc::encode(uint32_t & c) const
{
switch (type)
{
* Returns original representation of code point.
* Assumes code point is valid (hence 'unsafe').
*/
-uint Enc::decodeUnsafe(uint c) const
+uint32_t Enc::decodeUnsafe(uint32_t c) const
{
switch (type)
{
* by current policy, otherwise returns pointer to newly
* constructed Range.
*/
-Range * Enc::encodeRange(uint l, uint h) const
+Range * Enc::encodeRange(uint32_t l, uint32_t h) const
{
Range * r = NULL;
switch (type)
break;
case EBCDIC:
{
- const uint el = asc2ebc[l & 0xFF];
+ const uint32_t el = asc2ebc[l & 0xFF];
r = new Range(el, el + 1);
- for (uint c = l + 1; c <= h; ++c)
+ for (uint32_t c = l + 1; c <= h; ++c)
{
- const uint ec = asc2ebc[c & 0xFF];
+ const uint32_t ec = asc2ebc[c & 0xFF];
r = doUnion(r, new Range(ec, ec + 1));
}
break;
#ifndef _enc_h
#define _enc_h
-#include "basics.h"
+#include "c99_stdint.h"
#include "range.h"
namespace re2c {
};
private:
- static const uint asc2ebc[256];
- static const uint ebc2asc[256];
- static const uint SURR_MIN;
- static const uint SURR_MAX;
- static const uint UNICODE_ERROR;
+ static const uint32_t asc2ebc[256];
+ static const uint32_t ebc2asc[256];
+ static const uint32_t SURR_MIN;
+ static const uint32_t SURR_MAX;
+ static const uint32_t UNICODE_ERROR;
type_t type;
policy_t policy;
bool operator != (const Enc & e) const { return type != e.type; }
- inline uint nCodePoints() const;
- inline uint nCodeUnits() const;
- inline uint szCodePoint() const;
- inline uint szCodeUnit() const;
+ inline uint32_t nCodePoints() const;
+ inline uint32_t nCodeUnits() const;
+ inline uint32_t szCodePoint() const;
+ inline uint32_t szCodeUnit() const;
inline bool set(type_t t);
inline void unset(type_t);
inline void setPolicy(policy_t t);
- bool encode(uint & c) const;
- uint decodeUnsafe(uint c) const;
- Range * encodeRange(uint l, uint h) const;
+ bool encode(uint32_t & c) const;
+ uint32_t decodeUnsafe(uint32_t c) const;
+ Range * encodeRange(uint32_t l, uint32_t h) const;
Range * fullRange() const;
};
-inline uint Enc::nCodePoints() const
+inline uint32_t Enc::nCodePoints() const
{
switch (type)
{
return ~0; // to silence gcc warning
}
-inline uint Enc::nCodeUnits() const
+inline uint32_t Enc::nCodeUnits() const
{
switch (type)
{
}
// returns *maximal* code point size for encoding
-inline uint Enc::szCodePoint() const
+inline uint32_t Enc::szCodePoint() const
{
switch (type)
{
return ~0; // to silence gcc warning
}
-inline uint Enc::szCodeUnit() const
+inline uint32_t Enc::szCodeUnit() const
{
switch (type)
{
#ifndef _globals_h
#define _globals_h
-#include "basics.h"
#include <set>
#include <algorithm>
#include <string>
+
+#include "c99_stdint.h"
#include "code_names.h"
#include "enc.h"
#include "input_api.h"
extern std::string yySetConditionParam;
extern std::string yySetStateParam;
extern std::string yySetupRule;
-extern uint next_label;
-extern uint cGotoThreshold;
+extern uint32_t next_label;
+extern uint32_t cGotoThreshold;
/* configurations */
-extern uint topIndent;
+extern uint32_t topIndent;
extern std::string indString;
extern bool yybmHexTable;
extern bool bEmitYYCh;
extern bool bCaseInsensitive;
extern bool bCaseInverted;
-extern const uint asc2asc[256];
-extern const uint asc2ebc[256];
-extern const uint ebc2asc[256];
+extern const uint32_t asc2asc[256];
+extern const uint32_t asc2ebc[256];
+extern const uint32_t ebc2asc[256];
-extern uint next_fill_index;
-extern uint last_fill_index;
-extern std::set<uint> vUsedLabels;
+extern uint32_t next_fill_index;
+extern uint32_t last_fill_index;
+extern std::set<uint32_t> vUsedLabels;
extern CodeNames mapCodeName;
extern Enc encoding;
extern InputAPI input_api;
-extern char octCh(uint c);
-extern char hexCh(uint c);
+extern char octCh(uint32_t c);
+extern char hexCh(uint32_t c);
} // end namespace re2c
#include <iostream>
#include <vector>
-#include "basics.h"
+#include "c99_stdint.h"
#include "code.h"
namespace re2c
struct Span
{
- uint ub;
+ uint32_t ub;
State * to;
- uint show (std::ostream&, uint) const;
+ uint32_t show (std::ostream&, uint32_t) const;
};
struct Case
{
- std::vector<std::pair<uint, uint> > ranges;
+ std::vector<std::pair<uint32_t, uint32_t> > ranges;
const State * to;
- void emit (OutputFile & o, uint ind);
+ void emit (OutputFile & o, uint32_t ind);
};
struct Cases
{
const State * def;
Case * cases;
- uint cases_size;
- void add (uint lb, uint ub, State * to);
- Cases (const Span * s, uint n);
+ uint32_t cases_size;
+ void add (uint32_t lb, uint32_t ub, State * to);
+ Cases (const Span * s, uint32_t n);
~Cases ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
struct Cond
{
std::string compare;
- uint value;
- Cond (const std::string & cmp, uint val);
+ uint32_t value;
+ Cond (const std::string & cmp, uint32_t val);
};
struct Binary
Cond * cond;
If * thn;
If * els;
- Binary (const Span * s, uint n, const State * next);
+ Binary (const Span * s, uint32_t n, const State * next);
~Binary ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
struct Linear
{
std::vector<std::pair<const Cond *, const State *> > branches;
- Linear (const Span * s, uint n, const State * next);
+ Linear (const Span * s, uint32_t n, const State * next);
~Linear ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
Binary * binary;
Linear * linear;
} info;
- If (type_t t, const Span * sp, uint nsp, const State * next);
+ If (type_t t, const Span * sp, uint32_t nsp, const State * next);
~If ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
Cases * cases;
If * ifs;
} info;
- SwitchIf (const Span * sp, uint nsp, const State * next);
+ SwitchIf (const Span * sp, uint32_t nsp, const State * next);
~SwitchIf ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
const State * bitmap_state;
SwitchIf * hgo;
SwitchIf * lgo;
- Bitmap (const Span * span, uint nSpans, const Span * hspan, uint hSpans, const BitMap * bm, const State * bm_state, const State * next);
+ Bitmap (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const BitMap * bm, const State * bm_state, const State * next);
~Bitmap ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
struct CpgotoTable
{
- static const uint TABLE_SIZE;
+ static const uint32_t TABLE_SIZE;
const State ** table;
- CpgotoTable (const Span * span, uint nSpans);
+ CpgotoTable (const Span * span, uint32_t nSpans);
~CpgotoTable ();
- void emit (OutputFile & o, uint ind);
+ void emit (OutputFile & o, uint32_t ind);
void used_labels ();
};
{
SwitchIf * hgo;
CpgotoTable * table;
- Cpgoto (const Span * span, uint nSpans, const Span * hspan, uint hSpans, const State * next);
+ Cpgoto (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const State * next);
~Cpgoto ();
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
{
const State * from;
Cases * cases;
- Dot (const Span * sp, uint nsp, const State * from);
+ Dot (const Span * sp, uint32_t nsp, const State * from);
~Dot ();
void emit (OutputFile & o);
};
struct Go
{
- uint nSpans; // number of spans
+ uint32_t nSpans; // number of spans
Span * span;
enum
{
Go ();
~Go ();
void init (const State * from);
- void emit (OutputFile & o, uint ind, bool & readCh);
+ void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
};
// construct helpers
-bool matches(const Span * b1, uint n1, const State * s1, const Span * b2, uint n2, const State * s2);
-uint unmap (Span * new_span, const Span * old_span, uint old_nspans, const State * x);
+bool matches(const Span * b1, uint32_t n1, const State * s1, const Span * b2, uint32_t n2, const State * s2);
+uint32_t unmap (Span * new_span, const Span * old_span, uint32_t old_nspans, const State * x);
// emit helpers
-std::string space (uint this_label);
+std::string space (uint32_t this_label);
std::string output_yych (bool & readCh);
-void output_if (OutputFile & o, uint ind, bool & readCh, const std::string & compare, uint value);
-void output_goto (OutputFile & o, uint ind, bool & readCh, uint to);
-std::string output_hgo (OutputFile & o, uint ind, bool & readCh, SwitchIf * hgo);
+void output_if (OutputFile & o, uint32_t ind, bool & readCh, const std::string & compare, uint32_t value);
+void output_goto (OutputFile & o, uint32_t ind, bool & readCh, uint32_t to);
+std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * hgo);
} // namespace re2c
namespace re2c
{
-Cases::Cases (const Span * span, uint span_size)
+Cases::Cases (const Span * span, uint32_t span_size)
: def (span_size == 0 ? NULL : span[span_size - 1].to)
, cases (new Case[span_size])
, cases_size (0)
{
- for (uint i = 0, lb = 0; i < span_size; ++ i)
+ for (uint32_t i = 0, lb = 0; i < span_size; ++ i)
{
add (lb, span[i].ub, span[i].to);
lb = span[i].ub;
}
}
-void Cases::add (uint lb, uint ub, State * to)
+void Cases::add (uint32_t lb, uint32_t ub, State * to)
{
- for (uint i = 0; i < cases_size; ++i)
+ for (uint32_t i = 0; i < cases_size; ++i)
{
if (cases[i].to == to)
{
++cases_size;
}
-Cond::Cond (const std::string & cmp, uint val)
+Cond::Cond (const std::string & cmp, uint32_t val)
: compare (cmp)
, value (val)
{}
-Binary::Binary (const Span * s, uint n, const State * next)
+Binary::Binary (const Span * s, uint32_t n, const State * next)
: cond (NULL)
, thn (NULL)
, els (NULL)
{
- const uint l = n / 2;
- const uint h = n - l;
+ const uint32_t l = n / 2;
+ const uint32_t h = n - l;
cond = new Cond ("<=", s[l - 1].ub - 1);
thn = new If (l > 4 ? If::BINARY : If::LINEAR, &s[0], l, next);
els = new If (h > 4 ? If::BINARY : If::LINEAR, &s[l], h, next);
}
-Linear::Linear (const Span * s, uint n, const State * next)
+Linear::Linear (const Span * s, uint32_t n, const State * next)
: branches ()
{
for (;;)
}
}
-If::If (type_t t, const Span * sp, uint nsp, const State * next)
+If::If (type_t t, const Span * sp, uint32_t nsp, const State * next)
: type (t)
, info ()
{
}
}
-SwitchIf::SwitchIf (const Span * sp, uint nsp, const State * next)
+SwitchIf::SwitchIf (const Span * sp, uint32_t nsp, const State * next)
: type (IF)
, info ()
{
}
}
-Bitmap::Bitmap (const Span * span, uint nSpans, const Span * hspan, uint hSpans, const BitMap * bm, const State * bm_state, const State * next)
+Bitmap::Bitmap (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const BitMap * bm, const State * bm_state, const State * next)
: bitmap (bm)
, bitmap_state (bm_state)
, hgo (hSpans == 0 ? NULL : new SwitchIf (hspan, hSpans, next))
, lgo (NULL)
{
Span * bspan = new Span [nSpans];
- uint bSpans = unmap (bspan, span, nSpans, bm_state);
+ uint32_t bSpans = unmap (bspan, span, nSpans, bm_state);
lgo = bSpans == 0
? NULL
: new SwitchIf (bspan, bSpans, next);
delete [] bspan;
}
-const uint CpgotoTable::TABLE_SIZE = 0x100;
+const uint32_t CpgotoTable::TABLE_SIZE = 0x100;
-CpgotoTable::CpgotoTable (const Span * span, uint nSpans)
+CpgotoTable::CpgotoTable (const Span * span, uint32_t nSpans)
: table (new const State * [TABLE_SIZE])
{
- uint c = 0;
- for (uint i = 0; i < nSpans; ++i)
+ uint32_t c = 0;
+ for (uint32_t i = 0; i < nSpans; ++i)
{
for(; c < span[i].ub && c < TABLE_SIZE; ++c)
{
}
}
-Cpgoto::Cpgoto (const Span * span, uint nSpans, const Span * hspan, uint hSpans, const State * next)
+Cpgoto::Cpgoto (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const State * next)
: hgo (hSpans == 0 ? NULL : new SwitchIf (hspan, hSpans, next))
, table (new CpgotoTable (span, nSpans))
{}
-Dot::Dot (const Span * sp, uint nsp, const State * s)
+Dot::Dot (const Span * sp, uint32_t nsp, const State * s)
: from (s)
, cases (new Cases (sp, nsp))
{}
}
// initialize high (wide) spans
- uint hSpans = 0;
+ uint32_t hSpans = 0;
const Span * hspan = NULL;
- for (uint i = 0; i < nSpans; ++i)
+ for (uint32_t i = 0; i < nSpans; ++i)
{
if (span[i].ub > 0x100)
{
}
// initialize bitmaps
- uint nBitmaps = 0;
+ uint32_t nBitmaps = 0;
const BitMap * bitmap = NULL;
const State * bitmap_state = NULL;
- for (uint i = 0; i < nSpans; ++i)
+ for (uint32_t i = 0; i < nSpans; ++i)
{
if (span[i].to->isBase)
{
}
}
- const uint dSpans = nSpans - hSpans - nBitmaps;
+ const uint32_t dSpans = nSpans - hSpans - nBitmaps;
if (DFlag)
{
type = DOT;
}
// All spans in b1 that lead to s1 are pairwise equal to that in b2 leading to s2
-bool matches(const Span * b1, uint n1, const State * s1, const Span * b2, uint n2, const State * s2)
+bool matches(const Span * b1, uint32_t n1, const State * s1, const Span * b2, uint32_t n2, const State * s2)
{
const Span * e1 = &b1[n1];
- uint lb1 = 0;
+ uint32_t lb1 = 0;
const Span * e2 = &b2[n2];
- uint lb2 = 0;
+ uint32_t lb2 = 0;
for (;;)
{
* If input contains single span that maps to the given state,
* then output contains 0 spans.
*/
-uint unmap (Span * new_span, const Span * old_span, uint old_nspans, const State * x)
+uint32_t unmap (Span * new_span, const Span * old_span, uint32_t old_nspans, const State * x)
{
- uint new_nspans = 0;
- for (uint i = 0; i < old_nspans; ++i)
+ uint32_t new_nspans = 0;
+ for (uint32_t i = 0; i < old_nspans; ++i)
{
if (old_span[i].to != x)
{
Linear::~Linear ()
{
- for (uint i = 0; i < branches.size (); ++i)
+ for (uint32_t i = 0; i < branches.size (); ++i)
{
delete branches[i].first;
}
namespace re2c
{
-std::string space(uint this_label)
+std::string space(uint32_t this_label)
{
int nl = next_label > 999999 ? 6 : next_label > 99999 ? 5 : next_label > 9999 ? 4 : next_label > 999 ? 3 : next_label > 99 ? 2 : next_label > 9 ? 1 : 0;
int tl = this_label > 999999 ? 6 : this_label > 99999 ? 5 : this_label > 9999 ? 4 : this_label > 999 ? 3 : this_label > 99 ? 2 : this_label > 9 ? 1 : 0;
}
}
-void output_if (OutputFile & o, uint ind, bool & readCh, const std::string & compare, uint value)
+void output_if (OutputFile & o, uint32_t ind, bool & readCh, const std::string & compare, uint32_t value)
{
o << indent(ind) << "if (" << output_yych (readCh) << " " << compare << " ";
o.write_char_hex (value);
o << ") ";
}
-void output_goto (OutputFile & o, uint ind, bool & readCh, uint to)
+void output_goto (OutputFile & o, uint32_t ind, bool & readCh, uint32_t to)
{
if (readCh)
{
o << indent (ind) << "goto " << labelPrefix << to << ";\n";
}
-std::string output_hgo (OutputFile & o, uint ind, bool & readCh, SwitchIf * hgo)
+std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * hgo)
{
std::string yych = output_yych (readCh);
if (hgo != NULL)
return yych;
}
-uint Span::show (std::ostream & o, uint lb) const
+uint32_t Span::show (std::ostream & o, uint32_t lb) const
{
printSpan(o, lb, ub);
o << " ";
return ub;
}
-void Case::emit (OutputFile & o, uint ind)
+void Case::emit (OutputFile & o, uint32_t ind)
{
- for (uint i = 0; i < ranges.size (); ++i)
+ for (uint32_t i = 0; i < ranges.size (); ++i)
{
- for (uint b = ranges[i].first; b < ranges[i].second; ++b)
+ for (uint32_t b = ranges[i].first; b < ranges[i].second; ++b)
{
o << indent (ind) << "case ";
o.write_char_hex (b);
o << ":";
if (dFlag && encoding.is (Enc::EBCDIC))
{
- const uint c = encoding.decodeUnsafe (b);
+ const uint32_t c = encoding.decodeUnsafe (b);
if (isprint (c))
o << " /* " << std::string (1, c) << " */";
}
}
}
-void Cases::emit (OutputFile & o, uint ind, bool & readCh)
+void Cases::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
o << indent(ind) << "switch (" << output_yych (readCh) << ") {\n";
- for (uint i = 0; i < cases_size; ++i)
+ for (uint32_t i = 0; i < cases_size; ++i)
{
if (cases[i].to != def)
{
o << indent (ind) << "}\n";
}
-void Binary::emit (OutputFile & o, uint ind, bool & readCh)
+void Binary::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
output_if (o, ind, readCh, cond->compare, cond->value);
o << "{\n";
o << indent (ind) << "}\n";
}
-void Linear::emit (OutputFile & o, uint ind, bool & readCh)
+void Linear::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
- for (uint i = 0; i < branches.size (); ++i)
+ for (uint32_t i = 0; i < branches.size (); ++i)
{
if (branches[i].first != NULL)
{
}
}
-void If::emit (OutputFile & o, uint ind, bool & readCh)
+void If::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
switch (type)
{
}
}
-void SwitchIf::emit (OutputFile & o, uint ind, bool & readCh)
+void SwitchIf::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
switch (type)
{
}
}
-void Bitmap::emit (OutputFile & o, uint ind, bool & readCh)
+void Bitmap::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
std::string yych = output_hgo (o, ind, readCh, hgo);
o << "if (" << mapCodeName["yybm"] << "[" << bitmap->i << "+" << yych << "] & ";
}
else
{
- o << (uint) bitmap->m;
+ o << (uint32_t) bitmap->m;
}
o << ") {\n";
output_goto (o, ind + 1, readCh, bitmap_state->label);
}
}
-void CpgotoTable::emit (OutputFile & o, uint ind)
+void CpgotoTable::emit (OutputFile & o, uint32_t ind)
{
o << indent (ind) << "static void *" << mapCodeName["yytarget"] << "[256] = {\n";
o << indent (++ind);
- for (uint i = 0; i < TABLE_SIZE; ++i)
+ for (uint32_t i = 0; i < TABLE_SIZE; ++i)
{
o << "&&" << labelPrefix << table[i]->label;
if (i == TABLE_SIZE - 1)
o << indent (--ind) << "};\n";
}
-void Cpgoto::emit (OutputFile & o, uint ind, bool & readCh)
+void Cpgoto::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
std::string yych = output_hgo (o, ind, readCh, hgo);
o << "{\n";
void Dot::emit (OutputFile & o)
{
- const uint n = cases->cases_size;
+ const uint32_t n = cases->cases_size;
if (n == 1)
{
o << from->label << " -> " << cases->cases[0].to->label << "\n";
}
else
{
- for (uint i = 0; i < n; ++i)
+ for (uint32_t i = 0; i < n; ++i)
{
o << from->label << " -> " << cases->cases[i].to->label << " [label=\"";
- for (uint j = 0; j < cases->cases[i].ranges.size (); ++j)
+ for (uint32_t j = 0; j < cases->cases[i].ranges.size (); ++j)
{
o.write_range (cases->cases[i].ranges[j].first, cases->cases[i].ranges[j].second);
}
}
}
-void Go::emit (OutputFile & o, uint ind, bool & readCh)
+void Go::emit (OutputFile & o, uint32_t ind, bool & readCh)
{
switch (type)
{
void Cases::used_labels ()
{
- for (uint i = 0; i < cases_size; ++i)
+ for (uint32_t i = 0; i < cases_size; ++i)
{
vUsedLabels.insert (cases[i].to->label);
}
void Linear::used_labels ()
{
- for (uint i = 0; i < branches.size (); ++i)
+ for (uint32_t i = 0; i < branches.size (); ++i)
{
vUsedLabels.insert (branches[i].second->label);
}
void CpgotoTable::used_labels ()
{
- for (uint i = 0; i < TABLE_SIZE; ++i)
+ for (uint32_t i = 0; i < TABLE_SIZE; ++i)
{
vUsedLabels.insert (table[i]->label);
}
namespace re2c
{
-inline std::string indent (uint ind)
+inline std::string indent (uint32_t ind)
{
std::string str;
return mapCodeName["yych"] + " = " + yychConversion + expr_peek ();
}
-std::string InputAPI::stmt_peek (uint ind)
+std::string InputAPI::stmt_peek (uint32_t ind)
{
return indent (ind) + expr_peek_save () + ";\n";
}
-std::string InputAPI::stmt_skip (uint ind)
+std::string InputAPI::stmt_skip (uint32_t ind)
{
std::string s;
switch (type)
return indent (ind) + s + ";\n";
}
-std::string InputAPI::stmt_backup (uint ind)
+std::string InputAPI::stmt_backup (uint32_t ind)
{
std::string s;
switch (type)
return indent (ind) + s + ";\n";
}
-std::string InputAPI::stmt_backupctx (uint ind)
+std::string InputAPI::stmt_backupctx (uint32_t ind)
{
std::string s;
switch (type)
return indent (ind) + s + ";\n";
}
-std::string InputAPI::stmt_restore (uint ind)
+std::string InputAPI::stmt_restore (uint32_t ind)
{
std::string s;
switch (type)
return indent (ind) + s + ";\n";
}
-std::string InputAPI::stmt_restorectx (uint ind)
+std::string InputAPI::stmt_restorectx (uint32_t ind)
{
std::string s;
switch (type)
return s;
}
-std::string InputAPI::stmt_skip_peek (uint ind)
+std::string InputAPI::stmt_skip_peek (uint32_t ind)
{
return type == DEFAULT
? indent (ind) + mapCodeName["yych"] + " = " + yychConversion + "*++" + mapCodeName["YYCURSOR"] + ";\n"
: stmt_skip (ind) + stmt_peek (ind);
}
-std::string InputAPI::stmt_skip_backup (uint ind)
+std::string InputAPI::stmt_skip_backup (uint32_t ind)
{
return type == DEFAULT
? indent (ind) + mapCodeName["YYMARKER"] + " = ++" + mapCodeName["YYCURSOR"] + ";\n"
: stmt_skip (ind) + stmt_backup (ind);
}
-std::string InputAPI::stmt_backup_peek (uint ind)
+std::string InputAPI::stmt_backup_peek (uint32_t ind)
{
return type == DEFAULT
? indent (ind) + mapCodeName["yych"] + " = " + yychConversion + "*(" + mapCodeName["YYMARKER"] + " = " + mapCodeName["YYCURSOR"] + ");\n"
: stmt_backup (ind) + stmt_peek (ind);
}
-std::string InputAPI::stmt_skip_backup_peek (uint ind)
+std::string InputAPI::stmt_skip_backup_peek (uint32_t ind)
{
return type == DEFAULT
? indent (ind) + mapCodeName["yych"] + " = " + yychConversion + "*(" + mapCodeName["YYMARKER"] + " = ++" + mapCodeName["YYCURSOR"] + ");\n"
: expr_lessthan (1);
}
-std::string InputAPI::expr_lessthan (uint n)
+std::string InputAPI::expr_lessthan (uint32_t n)
{
std::ostringstream s;
switch (type)
#include <map>
#include <string>
-#include "basics.h"
+#include "c99_stdint.h"
namespace re2c
{
void set (type_t t);
std::string expr_peek ();
std::string expr_peek_save ();
- std::string stmt_peek (uint ind);
- std::string stmt_skip (uint ind);
- std::string stmt_backup (uint ind);
- std::string stmt_backupctx (uint ind);
- std::string stmt_restore (uint ind);
- std::string stmt_restorectx (uint ind);
- std::string stmt_skip_peek (uint ind);
- std::string stmt_skip_backup (uint ind);
- std::string stmt_backup_peek (uint ind);
- std::string stmt_skip_backup_peek (uint ind);
+ std::string stmt_peek (uint32_t ind);
+ std::string stmt_skip (uint32_t ind);
+ std::string stmt_backup (uint32_t ind);
+ std::string stmt_backupctx (uint32_t ind);
+ std::string stmt_restore (uint32_t ind);
+ std::string stmt_restorectx (uint32_t ind);
+ std::string stmt_skip_peek (uint32_t ind);
+ std::string stmt_skip_backup (uint32_t ind);
+ std::string stmt_backup_peek (uint32_t ind);
+ std::string stmt_skip_backup_peek (uint32_t ind);
std::string expr_lessthan_one ();
- std::string expr_lessthan (uint n);
+ std::string expr_lessthan (uint32_t n);
};
} // end namespace re2c
#ifndef _ins_h
#define _ins_h
-#include "basics.h"
+#include "c99_stdint.h"
namespace re2c
{
-typedef uint Char;
+typedef uint32_t Char;
-const uint CHAR = 0;
-const uint GOTO = 1;
-const uint FORK = 2;
-const uint TERM = 3;
-const uint CTXT = 4;
+const uint32_t CHAR = 0;
+const uint32_t GOTO = 1;
+const uint32_t FORK = 2;
+const uint32_t TERM = 3;
+const uint32_t CTXT = 4;
union Ins {
struct
{
- byte tag;
- byte marked;
+ uint8_t tag;
+ uint8_t marked;
void *link;
}
struct
{
- uint value;
- uint bump;
- void *link;
+ uint32_t value;
+ uint32_t bump;
+ void *link;
}
c;
std::string yySetConditionParam("@@");
std::string yySetStateParam("@@");
std::string yySetupRule("");
-uint next_label = 0;
-uint cGotoThreshold = 9;
+uint32_t next_label = 0;
+uint32_t cGotoThreshold = 9;
-uint topIndent = 0;
+uint32_t topIndent = 0;
std::string indString("\t");
bool yybmHexTable = false;
bool bUseStateAbort = false;
Enc encoding;
InputAPI input_api;
-uint next_fill_index = 0;
-uint last_fill_index = 0;
-std::set<uint> vUsedLabels;
+uint32_t next_fill_index = 0;
+uint32_t last_fill_index = 0;
+std::set<uint32_t> vUsedLabels;
CodeNames mapCodeName;
free_list<RegExp*> RegExp::vFreeList;
namespace re2c
{
-OutputFragment::OutputFragment (type_t t, uint i)
+OutputFragment::OutputFragment (type_t t, uint32_t i)
: type (t)
, stream ()
, info ()
, indent (i)
{}
-uint OutputFragment::count_lines ()
+uint32_t OutputFragment::count_lines ()
{
- uint lines = 0;
+ uint32_t lines = 0;
const std::string content = stream.str ();
const char * p = content.c_str ();
- for (uint i = 0; i < content.size (); ++i)
+ for (uint32_t i = 0; i < content.size (); ++i)
{
if (p[i] == '\n')
{
stream ().write (s, n);
}
-void OutputFile::write_hex (uint n)
+void OutputFile::write_hex (uint32_t n)
{
prtHex (stream (), n);
}
-void OutputFile::write_char_hex (uint n)
+void OutputFile::write_char_hex (uint32_t n)
{
prtChOrHex (stream (), n);
}
-void OutputFile::write_range (uint l, uint u)
+void OutputFile::write_range (uint32_t l, uint32_t u)
{
printSpan (stream (), l, u);
}
-void OutputFile::write_uint_width (uint n, uint w)
+void OutputFile::write_uint32_t_width (uint32_t n, uint32_t w)
{
stream () << std::setw (w) << n;
}
-void OutputFile::write_line_info (uint l, const char * fn)
+void OutputFile::write_line_info (uint32_t l, const char * fn)
{
output_line_info (stream (), l, fn);
}
output_version_time (stream ());
}
-OutputFile & operator << (OutputFile & u, uint n)
+OutputFile & operator << (OutputFile & u, uint32_t n)
{
u.stream () << n;
return u;
insert_code ();
}
-void OutputFile::insert_state_goto (uint ind, uint start_label)
+void OutputFile::insert_state_goto (uint32_t ind, uint32_t start_label)
{
if (fFlag && !bWroteGetState)
{
insert_code ();
}
-void OutputFile::insert_yyaccept_init (uint ind)
+void OutputFile::insert_yyaccept_init (uint32_t ind)
{
blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::YYACCEPT_INIT, ind));
insert_code ();
}
-void OutputFile::insert_yyaccept_selector (uint ind, uint selector)
+void OutputFile::insert_yyaccept_selector (uint32_t ind, uint32_t selector)
{
OutputFragment * p = new OutputFragment (OutputFragment::YYACCEPT_SELECTOR, ind);
p->info.yyaccept_selector = selector;
void OutputFile::emit
( const std::vector<std::string> & types
- , uint max_fill
+ , uint32_t max_fill
)
{
if (file != NULL)
#include <string>
#include <vector>
-#include "basics.h"
+#include "c99_stdint.h"
namespace re2c
{
union info_t
{
- uint yyaccept_selector;
+ uint32_t yyaccept_selector;
};
type_t type;
std::ostringstream stream;
info_t info;
- uint indent;
+ uint32_t indent;
- OutputFragment (type_t t, uint i);
- uint count_lines ();
+ OutputFragment (type_t t, uint32_t i);
+ uint32_t count_lines ();
};
struct OutputBlock
void new_block ();
void write (const char * s, std::streamsize n);
- void write_hex (uint n);
- void write_char_hex (uint n);
- void write_range (uint u, uint l);
- void write_uint_width (uint n, uint w);
- void write_line_info (uint l, const char * fn);
+ void write_hex (uint32_t n);
+ void write_char_hex (uint32_t n);
+ void write_range (uint32_t u, uint32_t l);
+ void write_uint32_t_width (uint32_t n, uint32_t w);
+ void write_line_info (uint32_t l, const char * fn);
void write_version_time ();
- friend OutputFile & operator << (OutputFile & o, uint n);
+ friend OutputFile & operator << (OutputFile & o, uint32_t n);
friend OutputFile & operator << (OutputFile & o, const std::string & s);
friend OutputFile & operator << (OutputFile & o, const char * s);
friend OutputFile & operator << (OutputFile & o, const Str & s);
void insert_line_info ();
- void insert_state_goto (uint ind, uint start_label);
+ void insert_state_goto (uint32_t ind, uint32_t start_label);
void insert_types ();
- void insert_yyaccept_init (uint ind);
- void insert_yyaccept_selector (uint ind, uint selector);
+ void insert_yyaccept_init (uint32_t ind);
+ void insert_yyaccept_selector (uint32_t ind, uint32_t selector);
void insert_yymaxfill ();
void set_used_yyaccept ();
bool get_used_yyaccept () const;
- void emit (const std::vector<std::string> & types, uint max_fill);
+ void emit (const std::vector<std::string> & types, uint32_t max_fill);
private:
const char * file_name;
FILE * file;
std::vector<OutputBlock *> blocks;
- uint prolog_label;
+ uint32_t prolog_label;
std::ostream & stream ();
void insert_code ();
HeaderFile header;
DataFile data;
std::vector<std::string> types;
- uint max_fill;
+ uint32_t max_fill;
Output (const char * source_name, const char * header_name);
~Output ();
#include "globals.h"
#include "parser.h"
-#include "basics.h"
+#include "c99_stdint.h"
#include "dfa.h"
#include "smart_ptr.h"
void yyerror(const char*);
}
-static re2c::uint accept;
+static uint32_t accept;
static re2c::RegExpMap specMap;
static RegExp *spec = NULL, *specNone = NULL;
static RuleOpList specStar;
}
if (specMap.size() < ruleSetupMap.size())
{
- uint line = in->get_cline();
+ uint32_t line = in->get_cline();
itRuleSetup = ruleSetupMap.find("*");
if (itRuleSetup != ruleSetupMap.end())
{
namespace re2c
{
-void prtChOrHex(std::ostream& o, uint c)
+void prtChOrHex(std::ostream& o, uint32_t c)
{
if (!encoding.is(Enc::EBCDIC) && (c < 256u) && (isprint(c) || isspace(c)))
{
}
}
-void prtHex(std::ostream& o, uint c)
+void prtHex(std::ostream& o, uint32_t c)
{
int oc = (int)(c);
}
}
-void prtCh(std::ostream& o, uint c)
+void prtCh(std::ostream& o, uint32_t c)
{
if (encoding.is(Enc::EBCDIC))
{
}
}
-void prtChOrHexForSpan(std::ostream& o, uint c)
+void prtChOrHexForSpan(std::ostream& o, uint32_t c)
{
if (!encoding.is(Enc::EBCDIC) && (c < 256u) && isprint(c) && (c != ']'))
{
}
}
-void printSpan(std::ostream& o, uint lb, uint ub)
+void printSpan(std::ostream& o, uint32_t lb, uint32_t ub)
{
if (lb > ub)
{
#include <iosfwd>
-#include "basics.h"
+#include "c99_stdint.h"
namespace re2c
{
-void prtCh(std::ostream&, uint);
-void prtHex(std::ostream&, uint);
-void prtChOrHex(std::ostream&, uint);
-void printSpan(std::ostream&, uint, uint);
+void prtCh(std::ostream&, uint32_t);
+void prtHex(std::ostream&, uint32_t);
+void prtChOrHex(std::ostream&, uint32_t);
+void printSpan(std::ostream&, uint32_t, uint32_t);
} // end namespace re2c
if (!(r1 = r1->next))
{
- uint ub = 0;
+ uint32_t ub = 0;
for (; r2 && r2->lb <= s->ub; r2 = r2->next)
ub = r2->ub;
if (!(r2 = r2->next))
{
- uint ub = 0;
+ uint32_t ub = 0;
for (; r1 && r1->lb <= s->ub; r1 = r1->next)
ub = r1->ub;
for (; r1; r1 = r1->next)
{
- uint lb = r1->lb;
+ uint32_t lb = r1->lb;
for (; r2 && r2->ub <= r1->lb; r2 = r2->next)
#include <iostream>
-#include "basics.h"
+#include "c99_stdint.h"
#include "free_list.h"
namespace re2c
{
public:
- Range *next;
- uint lb, ub; // [lb,ub)
+ Range *next;
+ uint32_t lb, ub; // [lb,ub)
static free_list<Range*> vFreeList;
public:
- Range(uint l, uint u) : next(NULL), lb(l), ub(u)
+ Range(uint32_t l, uint32_t u) : next(NULL), lb(l), ub(u)
{
vFreeList.insert(this);
}
#include <stddef.h> // NULL
-#include "basics.h"
+#include "c99_stdint.h"
#include "free_list.h"
namespace re2c {
static free_list<RangeSuffix *> freeList;
public:
- uint l;
- uint h;
+ uint32_t l;
+ uint32_t h;
RangeSuffix * next;
RangeSuffix * child;
- RangeSuffix (uint lo, uint hi)
+ RangeSuffix (uint32_t lo, uint32_t hi)
: l (lo)
, h (hi)
, next (NULL)
struct CharPtn
{
- uint card;
+ uint32_t card;
CharPtn *fix;
CharPtn *nxt;
};
{
public:
- uint size;
+ uint32_t size;
/*
* There're several different cases when the same regexp
virtual void split(CharSet&) = 0;
virtual void calcSize(Char*) = 0;
- virtual uint fixedLength();
- virtual uint compile(Char*, Ins*) = 0;
+ virtual uint32_t fixedLength();
+ virtual uint32_t compile(Char*, Ins*) = 0;
virtual void decompile() = 0;
virtual void display(std::ostream&) const = 0;
friend std::ostream& operator<<(std::ostream&, const RegExp&);
public:
void split(CharSet&);
void calcSize(Char*);
- uint fixedLength();
- uint compile(Char*, Ins*);
+ uint32_t fixedLength();
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream &o) const
{
void split(CharSet&);
void calcSize(Char*);
- uint fixedLength();
- uint compile(Char*, Ins*);
+ uint32_t fixedLength();
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream&) const;
public:
RegExp *ctx;
Ins *ins;
- uint accept;
+ uint32_t accept;
Token *code;
- uint line;
+ uint32_t line;
public:
- RuleOp(RegExp*, RegExp*, Token*, uint, InsAccess);
+ RuleOp(RegExp*, RegExp*, Token*, uint32_t, InsAccess);
~RuleOp()
{
void split(CharSet&);
void calcSize(Char*);
- uint compile(Char*, Ins*);
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream &o) const
{
o << exp << "/" << ctx << ";";
}
- RuleOp* copy(uint) const;
+ RuleOp* copy(uint32_t) const;
#ifdef PEDANTIC
private:
void split(CharSet&);
void calcSize(Char*);
- uint fixedLength();
- uint compile(Char*, Ins*);
+ uint32_t fixedLength();
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream &o) const
{
void split(CharSet&);
void calcSize(Char*);
- uint fixedLength();
- uint compile(Char*, Ins*);
+ uint32_t fixedLength();
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream &o) const
{
void split(CharSet&);
void calcSize(Char*);
- uint compile(Char*, Ins*);
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream &o) const
{
void split(CharSet&);
void calcSize(Char*);
- uint compile(Char*, Ins*);
+ uint32_t compile(Char*, Ins*);
void decompile();
void display(std::ostream &o) const
{
typedef std::map<std::string, NRegExp> RegExpMap;
typedef std::vector<std::string> RegExpIndices;
typedef std::list<RuleOp*> RuleOpList;
-typedef std::pair<uint, std::string> LineCode;
+typedef std::pair<uint32_t, std::string> LineCode;
typedef std::map<std::string, LineCode> SetupMap;
typedef std::map<std::string, Token*> DefaultMap;
class DFA;
-extern smart_ptr<DFA> genCode(RegExp*, Output & output, uint ind);
-extern void genCondTable(OutputFile &, uint, const RegExpMap&);
-extern void genCondGoto(OutputFile &, uint, const RegExpMap&);
+extern smart_ptr<DFA> genCode(RegExp*, Output & output, uint32_t ind);
+extern void genCondTable(OutputFile &, uint32_t, const RegExpMap&);
+extern void genCondGoto(OutputFile &, uint32_t, const RegExpMap&);
extern void genTypes(Output &, const RegExpMap&);
-extern void output_state_goto (std::ostream &, uint, uint);
-extern void output_types (std::ostream &, uint, const std::vector<std::string> &);
+extern void output_state_goto (std::ostream &, uint32_t, uint32_t);
+extern void output_types (std::ostream &, uint32_t, const std::vector<std::string> &);
extern void output_version_time (std::ostream &);
-extern void output_yyaccept_init (std::ostream &, uint, bool);
-extern void output_yyaccept_selector (std::ostream &, uint, bool, uint);
-extern void output_yymaxfill (std::ostream &, uint);
-extern void output_line_info (std::ostream &, uint, const char *);
+extern void output_yyaccept_init (std::ostream &, uint32_t, bool);
+extern void output_yyaccept_selector (std::ostream &, uint32_t, bool, uint32_t);
+extern void output_yymaxfill (std::ostream &, uint32_t);
+extern void output_line_info (std::ostream &, uint32_t, const char *);
extern RegExp *mkDiff(RegExp*, RegExp*);
extern RegExp *mkAlt(RegExp*, RegExp*);
char *tok, *ptr, *cur, *pos, *ctx; // positioning
char *bot, *lim, *top, *eof; // buffer
- uint tchar, tline, cline, iscfg, buf_size;
+ uint32_t tchar, tline, cline, iscfg, buf_size;
bool in_parse;
};
OutputFile & out;
private:
- char *fill(char*, uint);
+ char *fill(char*, uint32_t);
Scanner(const Scanner&); //unimplemented
Scanner& operator=(const Scanner&); //unimplemented
void set_sourceline(char *& cursor);
void save_state(ScannerState&) const;
void restore_state(const ScannerState&);
- uint get_cline() const;
+ uint32_t get_cline() const;
const std::string & get_fname () const;
void set_in_parse(bool new_in_parse);
- void fatal_at(uint line, uint ofs, const char *msg) const;
- void fatalf_at(uint line, const char*, ...) const;
+ void fatal_at(uint32_t line, uint32_t ofs, const char *msg) const;
+ void fatalf_at(uint32_t line, const char*, ...) const;
void fatalf(const char*, ...) const;
void fatal(const char*) const;
- void fatal(uint, const char*) const;
+ void fatal(uint32_t, const char*) const;
void config(const Str&, int);
void config(const Str&, const Str&);
- void check_token_length(char *pos, uint len) const;
+ void check_token_length(char *pos, uint32_t len) const;
SubStr token() const;
- SubStr token(uint start, uint len) const;
+ SubStr token(uint32_t start, uint32_t len) const;
Str raw_token(std::string enclosure) const;
- uint unescape(SubStr &s) const;
+ uint32_t unescape(SubStr &s) const;
std::string& unescape(SubStr& str_in, std::string& str_out) const;
Range * mkRange(SubStr &s) const;
Range * getRange(SubStr &s) const;
- RegExp * matchSymbol(uint c) const;
+ RegExp * matchSymbol(uint32_t c) const;
RegExp * matchSymbolRange(Range * r) const;
RegExp * strToName(SubStr s) const;
RegExp * strToRE(SubStr s) const;
return in.file_name;
}
-inline uint Scanner::get_cline() const
+inline uint32_t Scanner::get_cline() const
{
return cline;
}
return SubStr(tok, cur - tok);
}
-inline SubStr Scanner::token(uint start, uint len) const
+inline SubStr Scanner::token(uint32_t start, uint32_t len) const
{
check_token_length(tok + start, len);
return SubStr(tok + start, len);
int Scanner::scan()
{
char *cursor = cur;
- uint depth;
+ uint32_t depth;
scan:
tchar = cursor - pos;
namespace re2c
{
-const uint Skeleton::PATHS_OVERFLOW = 1024 * 1024; // 1Mb
+const uint32_t Skeleton::PATHS_OVERFLOW = 1024 * 1024; // 1Mb
Skeleton::Skeleton (const DFA & dfa)
: states_count (dfa.nStates + 1)
, states (new SkeletonState [states_count])
{
- uint i;
+ uint32_t i;
std::map<State *, SkeletonState *> m;
m[NULL] = &states[states_count - 1]; // default state
const bool is_final = s->go.nSpans == 1 && s->go.span[0].to == NULL;
if (!is_final)
{
- uint lb = 0;
- for (uint j = 0; j < s->go.nSpans; ++j)
+ uint32_t lb = 0;
+ for (uint32_t j = 0; j < s->go.nSpans; ++j)
{
SkeletonState * p = m[(s->go.span[j].to)];
states[i].go[p].push_back (lb);
delete [] states;
}
-uint Skeleton::estimate_paths_count (SkeletonState * s, uint count)
+uint32_t Skeleton::estimate_paths_count (SkeletonState * s, uint32_t count)
{
if (s->is_end ())
{
else if (s->visited < 2)
{
++s->visited;
- uint result = 0;
+ uint32_t result = 0;
for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i)
{
- const uint arrows = i->second.size ();
- const uint max_paths = PATHS_OVERFLOW - 1;
+ const uint32_t arrows = i->second.size ();
+ const uint32_t max_paths = PATHS_OVERFLOW - 1;
if (max_paths / arrows < count)
{
result = PATHS_OVERFLOW;
break;
}
- const uint n = estimate_paths_count (i->first, arrows * count);
+ const uint32_t n = estimate_paths_count (i->first, arrows * count);
if (max_paths - result < n)
{
result = PATHS_OVERFLOW;
{
if (s->is_end ())
{
- for (uint i = 0; i < prefixes.size (); ++i)
+ for (uint32_t i = 0; i < prefixes.size (); ++i)
{
results.push_back (prefixes[i]);
results.back ().update (s->rule);
for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i)
{
std::vector<Path> zs;
- for (uint j = 0; j < prefixes.size (); ++j)
+ for (uint32_t j = 0; j < prefixes.size (); ++j)
{
- for (uint k = 0; k < i->second.size (); ++k)
+ for (uint32_t k = 0; k < i->second.size (); ++k)
{
zs.push_back (prefixes[j]);
zs.back ().extend (s->rule, i->second[k]);
{
if (s == NULL)
{
- for (uint i = 0; i < prefixes.size (); ++i)
+ for (uint32_t i = 0; i < prefixes.size (); ++i)
{
results.push_back (prefixes[i]);
}
if (s->path != NULL)
{
std::vector<Path> zs (prefixes);
- for (uint i = 0; i < zs.size (); ++i)
+ for (uint32_t i = 0; i < zs.size (); ++i)
{
zs[i].append (s->path);
}
}
else
{
- const uint in_arrows = prefixes.size ();
- const uint out_states = s->go.size ();
+ const uint32_t in_arrows = prefixes.size ();
+ const uint32_t out_states = s->go.size ();
SkeletonState::go_t::iterator i = s->go.begin ();
- for ( uint in = 0, out = 0
+ for ( uint32_t in = 0, out = 0
; in < in_arrows || out < out_states
; ++out, s->wrap (++i)
)
{
std::vector<Path> zs;
- for (uint j = 0; j < i->second.size (); ++j, ++in)
+ for (uint32_t j = 0; j < i->second.size (); ++j, ++in)
{
zs.push_back (prefixes[in % in_arrows]);
zs[j].extend (s->rule, i->second[j]);
generate_paths_cover (i->first, zs, results);
if (s->path == NULL && i->first->path != NULL)
{
- s->path = new Path (std::vector<uint> (1, i->second[0]), 0, s->rule);
+ s->path = new Path (std::vector<uint32_t> (1, i->second[0]), 0, s->rule);
s->path->append (i->first->path);
}
}
void Skeleton::generate_paths (std::vector<Path> & results)
{
std::vector<Path> prefixes;
- prefixes.push_back (Path (std::vector<uint> (), 0, ~0));
+ prefixes.push_back (Path (std::vector<uint32_t> (), 0, ~0));
if (estimate_paths_count (states, 1) == PATHS_OVERFLOW)
{
// set paths for final states and default state
// (those with zero outgoing arrows)
- for (uint i = 0; i < states_count; ++i)
+ for (uint32_t i = 0; i < states_count; ++i)
{
if (states[i].is_end ())
{
- states[i].path = new Path (std::vector<uint> (), 0, states[i].rule);
+ states[i].path = new Path (std::vector<uint32_t> (), 0, states[i].rule);
}
}
generate_paths_cover (states, prefixes, results);
// cleanup: delete all paths
- for (uint i = 0; i < states_count; ++i)
+ for (uint32_t i = 0; i < states_count; ++i)
{
delete states[i].path;
}
void Skeleton::emit_data (DataFile & o)
{
- uint ind = 0;
+ uint32_t ind = 0;
std::string yyctype;
switch (encoding.szCodeUnit ())
std::vector<Path> ys;
generate_paths (ys);
- const uint count = ys.size ();
+ const uint32_t count = ys.size ();
- uint max_len = 0;
- for (uint i = 0; i < count; ++i)
+ uint32_t max_len = 0;
+ for (uint32_t i = 0; i < count; ++i)
{
if (max_len < ys[i].chars.size ())
{
max_len = ys[i].chars.size ();
}
}
- for (uint i = 0; i < count; ++i)
+ for (uint32_t i = 0; i < count; ++i)
{
o.file << indent (ind + 1);
- for (uint j = 0 ; j < ys[i].chars.size (); ++j)
+ for (uint32_t j = 0 ; j < ys[i].chars.size (); ++j)
{
prtChOrHex (o.file, ys[i].chars[j]);
o.file << ",";
o.file << "\n";
}
o.file << indent (ind + 1);
- for (uint j = 0 ; j < max_len; ++j) // pad with YMAXFILL zeroes
+ for (uint32_t j = 0 ; j < max_len; ++j) // pad with YMAXFILL zeroes
{
o.file << "0,";
}
o.file << indent (ind) << "const unsigned int count = " << count << ";\n";
- uint pos = 0;
+ uint32_t pos = 0;
o.file << indent (ind) << "struct Result {\n";
o.file << indent (ind + 1) << "unsigned int endpos;\n";
o.file << indent (ind + 1) << "unsigned int startpos;\n";
o.file << indent (ind) << "};\n";
o.file << indent (ind) << "Result result [] =\n";
o.file << indent (ind) << "{\n";
- for (uint i = 0; i < count; ++i)
+ for (uint32_t i = 0; i < count; ++i)
{
o.file << indent (ind + 1) << "Result (" << pos + ys[i].length << "," << pos + ys[i].chars.size () << "," << ys[i].rule << "),\n";
pos += ys[i].chars.size ();
o.file << indent (ind) << "const YYCTYPE * const limit = &data[data_size - 1];\n";
}
-void skeleton_emit_prolog (OutputFile & o, uint ind, const char * data_name)
+void skeleton_emit_prolog (OutputFile & o, uint32_t ind, const char * data_name)
{
o << indent (ind) << "#include <stdio.h>\n";
o << indent (ind) << "#include \"" << data_name << "\"\n";
o << indent (ind + 1) << "{\n";
}
-void skeleton_emit_epilog (OutputFile & o, uint ind)
+void skeleton_emit_epilog (OutputFile & o, uint32_t ind)
{
o << indent (ind + 1) << "}\n";
o << indent (ind + 1) << "return 0;\n";
#include <map>
#include <vector>
-#include "basics.h"
+#include "c99_stdint.h"
#include "dfa.h"
namespace re2c
struct Path
{
- std::vector<uint> chars;
- uint length;
- uint rule;
- inline Path (const std::vector<uint> & cs, uint l, uint r)
+ std::vector<uint32_t> chars;
+ uint32_t length;
+ uint32_t rule;
+ inline Path (const std::vector<uint32_t> & cs, uint32_t l, uint32_t r)
: chars (cs)
, length (l)
, rule (r)
{}
- inline void update (uint r)
+ inline void update (uint32_t r)
{
if (r != ~0u)
{
rule = r;
}
}
- inline void extend (uint r, uint c)
+ inline void extend (uint32_t r, uint32_t c)
{
update (r);
chars.push_back (c);
length = chars.size () + p->length;
rule = p->rule;
}
- for (uint i = 0; i < p->chars.size (); ++i)
+ for (uint32_t i = 0; i < p->chars.size (); ++i)
{
chars.push_back (p->chars[i]);
}
struct SkeletonState
{
- typedef std::map<SkeletonState *, std::vector<uint> > go_t;
+ typedef std::map<SkeletonState *, std::vector<uint32_t> > go_t;
go_t go;
- uint rule;
- uchar visited;
+ uint32_t rule;
+ uint8_t visited;
Path * path;
inline SkeletonState ()
struct Skeleton
{
- static const uint PATHS_OVERFLOW;
- const uint states_count;
+ static const uint32_t PATHS_OVERFLOW;
+ const uint32_t states_count;
SkeletonState * states;
Skeleton (const DFA & dfa);
~Skeleton ();
- uint estimate_paths_count (SkeletonState * s, uint count);
+ uint32_t estimate_paths_count (SkeletonState * s, uint32_t count);
void generate_paths (std::vector<Path> & results);
void emit_data (DataFile & o);
};
-void skeleton_emit_prolog (OutputFile & o, uint ind, const char * data_name);
-void skeleton_emit_epilog (OutputFile & o, uint ind);
+void skeleton_emit_prolog (OutputFile & o, uint32_t ind, const char * data_name);
+void skeleton_emit_epilog (OutputFile & o, uint32_t ind);
void generate_paths_all (SkeletonState * s, const std::vector<Path> & prefixes, std::vector<Path> & results);
void generate_paths_cover (SkeletonState * s, const std::vector<Path> & prefixes, std::vector<Path> & results);
#include <iostream>
#include <string>
#include <string.h>
-#include "basics.h"
+
+#include "c99_stdint.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#elif defined(_WIN32)
+#include "config_w32.h"
+#endif
namespace re2c
{
public:
const char * str;
const char * const org;
- uint len;
+ uint32_t len;
public:
friend bool operator==(const SubStr &, const SubStr &);
- SubStr(const uchar*, uint);
- SubStr(const char*, uint);
+ SubStr(const uint8_t *, uint32_t);
+ SubStr(const char*, uint32_t);
explicit SubStr(const char*);
SubStr(const SubStr&);
virtual ~SubStr();
void out(std::ostream&) const;
std::string to_string() const;
- uint ofs() const;
+ uint32_t ofs() const;
#ifdef PEDANTIC
protected:
return o << *s;
}
-inline SubStr::SubStr(const uchar *s, uint l)
+inline SubStr::SubStr(const uint8_t *s, uint32_t l)
: str((char*)s), org((char*)s), len(l)
{ }
-inline SubStr::SubStr(const char *s, uint l)
+inline SubStr::SubStr(const char *s, uint32_t l)
: str(s), org(s), len(l)
{ }
return str && len ? std::string(str, len) : std::string();
}
-inline uint SubStr::ofs() const
+inline uint32_t SubStr::ofs() const
{
return str - org;
}
const Str text;
const std::string newcond;
const std::string source;
- uint line;
+ uint32_t line;
const bool autogen;
public:
- Token(const SubStr&, const std::string&, uint);
- Token(const Token*, const std::string&, uint, const Str*);
+ Token(const SubStr&, const std::string&, uint32_t);
+ Token(const Token*, const std::string&, uint32_t, const Str*);
Token(const Token& oth);
~Token();
};
-inline Token::Token(const SubStr& t, const std::string& s, uint l)
+inline Token::Token(const SubStr& t, const std::string& s, uint32_t l)
: text(t)
, newcond()
, source(s)
;
}
-inline Token::Token(const Token* t, const std::string& s, uint l, const Str *c)
+inline Token::Token(const Token* t, const std::string& s, uint32_t l, const Str *c)
: text(t ? t->text.to_string().c_str() : "")
, newcond(c ? c->to_string() : "")
, source(t ? t->source : s)
namespace re2c
{
-char octCh(uint c)
+char octCh(uint32_t c)
{
return '0' + c % 8;
}
static const char * sHex = "0123456789ABCDEF";
-char hexCh(uint c)
+char hexCh(uint32_t c)
{
return sHex[c & 0x0F];
}
namespace re2c {
-const uint utf16::MAX_1WORD_RUNE = 0xFFFF;
-const uint utf16::MIN_LEAD_SURR = 0xD800;
-const uint utf16::MIN_TRAIL_SURR = 0xDC00;
-const uint utf16::MAX_TRAIL_SURR = 0xDFFF;
+const uint32_t utf16::MAX_1WORD_RUNE = 0xFFFF;
+const uint32_t utf16::MIN_LEAD_SURR = 0xD800;
+const uint32_t utf16::MIN_TRAIL_SURR = 0xDC00;
+const uint32_t utf16::MAX_TRAIL_SURR = 0xDFFF;
} // namespace re2c
#ifndef _re2c_utf16_h
#define _re2c_utf16_h
-#include "basics.h"
+#include "c99_stdint.h"
namespace re2c {
class utf16
{
public:
- typedef uint rune;
+ typedef uint32_t rune;
- static const uint MAX_1WORD_RUNE;
- static const uint MIN_LEAD_SURR;
- static const uint MIN_TRAIL_SURR;
- static const uint MAX_TRAIL_SURR;
+ static const uint32_t MAX_1WORD_RUNE;
+ static const uint32_t MIN_LEAD_SURR;
+ static const uint32_t MIN_TRAIL_SURR;
+ static const uint32_t MAX_TRAIL_SURR;
/* leading surrogate of UTF-16 symbol */
- static inline ushort lead_surr(rune r);
+ static inline uint16_t lead_surr(rune r);
/* trailing surrogate of UTF-16 symbol */
- static inline ushort trail_surr(rune r);
+ static inline uint16_t trail_surr(rune r);
};
-inline ushort utf16::lead_surr(rune r)
+inline uint16_t utf16::lead_surr(rune r)
{
return ((r - 0x10000) / 0x400) + MIN_LEAD_SURR;
}
-inline ushort utf16::trail_surr(rune r)
+inline uint16_t utf16::trail_surr(rune r)
{
return ((r - 0x10000) % 0x400) + MIN_TRAIL_SURR;
}
/*
* Add word range [w1-w2].
*/
-void UTF16addContinuous1(RangeSuffix * & root, ushort l, ushort h)
+void UTF16addContinuous1(RangeSuffix * & root, uint16_t l, uint16_t h)
{
RangeSuffix ** p = &root;
for (;;)
* Now that we have catenation of word ranges [l1-h1],[l2-h2],
* we want to add it to existing range, merging suffixes on the fly.
*/
-void UTF16addContinuous2(RangeSuffix * & root, ushort l_ld, ushort h_ld, ushort l_tr, ushort h_tr)
+void UTF16addContinuous2(RangeSuffix * & root, uint16_t l_ld, uint16_t h_ld, uint16_t l_tr, uint16_t h_tr)
{
RangeSuffix ** p = &root;
for (;;)
* and represents original range as alternation of continuous
* sub-ranges.
*/
-void UTF16splitByContinuity(RangeSuffix * & root, ushort l_ld, ushort h_ld, ushort l_tr, ushort h_tr)
+void UTF16splitByContinuity(RangeSuffix * & root, uint16_t l_ld, uint16_t h_ld, uint16_t l_tr, uint16_t h_tr)
{
if (l_ld != h_ld)
{
else
{
UTF16addContinuous1(root, l, utf16::MAX_1WORD_RUNE);
- const ushort h_ld = utf16::lead_surr(h);
- const ushort h_tr = utf16::trail_surr(h);
+ const uint16_t h_ld = utf16::lead_surr(h);
+ const uint16_t h_tr = utf16::trail_surr(h);
UTF16splitByContinuity(root, utf16::MIN_LEAD_SURR, h_ld, utf16::MIN_TRAIL_SURR, h_tr);
}
else
{
- const ushort l_ld = utf16::lead_surr(l);
- const ushort l_tr = utf16::trail_surr(l);
- const ushort h_ld = utf16::lead_surr(h);
- const ushort h_tr = utf16::trail_surr(h);
+ const uint16_t l_ld = utf16::lead_surr(l);
+ const uint16_t l_tr = utf16::trail_surr(l);
+ const uint16_t h_ld = utf16::lead_surr(h);
+ const uint16_t h_tr = utf16::trail_surr(h);
UTF16splitByContinuity(root, l_ld, h_ld, l_tr, h_tr);
}
}
namespace re2c {
-void UTF16addContinuous1(RangeSuffix * & root, ushort l, ushort h);
-void UTF16addContinuous2(RangeSuffix * & root, ushort l_ld, ushort h_ld, ushort l_tr, ushort h_tr);
-void UTF16splitByContinuity(RangeSuffix * & root, ushort l_ld, ushort h_ld, ushort l_tr, ushort h_tr);
+void UTF16addContinuous1(RangeSuffix * & root, uint16_t l, uint16_t h);
+void UTF16addContinuous2(RangeSuffix * & root, uint16_t l_ld, uint16_t h_ld, uint16_t l_tr, uint16_t h_tr);
+void UTF16splitByContinuity(RangeSuffix * & root, uint16_t l_ld, uint16_t h_ld, uint16_t l_tr, uint16_t h_tr);
void UTF16splitByRuneLength(RangeSuffix * & root, utf16::rune l, utf16::rune h);
} // namespace re2c
return new MatchOp(new Range(r, r + 1));
else
{
- const ushort ld = utf16::lead_surr(r);
- const ushort tr = utf16::trail_surr(r);
+ const uint16_t ld = utf16::lead_surr(r);
+ const uint16_t tr = utf16::trail_surr(r);
return new CatOp(new MatchOp(new Range(ld, ld + 1)), new MatchOp(new Range(tr, tr + 1)));
}
}
namespace re2c {
-uint utf8::rune_to_bytes(uchar *str, rune c)
+uint32_t utf8::rune_to_bytes(uint8_t *str, rune c)
{
/*
* one byte sequence
return 4;
}
-uint utf8::rune_length(rune r)
+uint32_t utf8::rune_length(rune r)
{
if (r <= MAX_2BYTE_RUNE)
return r <= MAX_1BYTE_RUNE ? 1 : 2;
return r <= MAX_3BYTE_RUNE ? 3 : 4;
}
-utf8::rune utf8::max_rune(uint i)
+utf8::rune utf8::max_rune(uint32_t i)
{
switch (i)
{
#ifndef _re2c_utf8_h
#define _re2c_utf8_h
-#include "basics.h"
+#include "c99_stdint.h"
namespace re2c {
class utf8
{
public:
- typedef uint rune;
+ typedef uint32_t rune;
enum { MAX_RUNE_LENGTH = 4 /* maximum characters per rune */
};
/* UTF-8 bytestring for given Unicode rune */
- static uint rune_to_bytes(uchar * s, rune r);
+ static uint32_t rune_to_bytes(uint8_t * s, rune r);
/* length of UTF-8 bytestring for given Unicode rune */
- static uint rune_length(rune r);
+ static uint32_t rune_length(rune r);
/* maximal Unicode rune with given length of UTF-8 bytestring */
- static rune max_rune(uint i);
+ static rune max_rune(uint32_t i);
};
} // namespace re2c
* Now that we have catenation of byte ranges [l1-h1]...[lN-hN],
* we want to add it to existing range, merging suffixes on the fly.
*/
-void UTF8addContinuous(RangeSuffix * & root, utf8::rune l, utf8::rune h, uint n)
+void UTF8addContinuous(RangeSuffix * & root, utf8::rune l, utf8::rune h, uint32_t n)
{
- uchar cl[utf8::MAX_RUNE_LENGTH];
- uchar ch[utf8::MAX_RUNE_LENGTH];
+ uint8_t cl[utf8::MAX_RUNE_LENGTH];
+ uint8_t ch[utf8::MAX_RUNE_LENGTH];
utf8::rune_to_bytes(cl, l);
utf8::rune_to_bytes(ch, h);
* and represents original range as alternation of continuous
* sub-ranges.
*/
-void UTF8splitByContinuity(RangeSuffix * & root, utf8::rune l, utf8::rune h, uint n)
+void UTF8splitByContinuity(RangeSuffix * & root, utf8::rune l, utf8::rune h, uint32_t n)
{
- for (uint i = 1; i < n; ++i)
+ for (uint32_t i = 1; i < n; ++i)
{
- uint m = (1 << (6 * i)) - 1; // last i bytes of a UTF-8 sequence
+ uint32_t m = (1 << (6 * i)) - 1; // last i bytes of a UTF-8 sequence
if ((l & ~m) != (h & ~m))
{
if ((l & m) != 0)
*/
void UTF8splitByRuneLength(RangeSuffix * & root, utf8::rune l, utf8::rune h)
{
- const uint nh = utf8::rune_length(h);
- for (uint nl = utf8::rune_length(l); nl < nh; ++nl)
+ const uint32_t nh = utf8::rune_length(h);
+ for (uint32_t nl = utf8::rune_length(l); nl < nh; ++nl)
{
utf8::rune r = utf8::max_rune(nl);
UTF8splitByContinuity(root, l, r, nl);
namespace re2c {
-void UTF8addContinuous(RangeSuffix * & p, utf8::rune l, utf8::rune h, uint n);
-void UTF8splitByContinuity(RangeSuffix * & p, utf8::rune l, utf8::rune h, uint n);
+void UTF8addContinuous(RangeSuffix * & p, utf8::rune l, utf8::rune h, uint32_t n);
+void UTF8splitByContinuity(RangeSuffix * & p, utf8::rune l, utf8::rune h, uint32_t n);
void UTF8splitByRuneLength(RangeSuffix * & p, utf8::rune l, utf8::rune h);
} // namespace re2c
RegExp * UTF8Symbol(utf8::rune r)
{
- uchar chars[utf8::MAX_RUNE_LENGTH];
+ uint8_t chars[utf8::MAX_RUNE_LENGTH];
const int chars_count = utf8::rune_to_bytes(chars, r);
RegExp * re = new MatchOp(new Range(chars[0], chars[0] + 1));
for (int i = 1; i < chars_count; ++i)