From f704960bccdb457d35ed1855035b16c487d6819c Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 20 Apr 2015 23:38:32 +0100 Subject: [PATCH] Added portable version of , converted the whole project. --- re2c/Makefile.am | 2 +- re2c/actions.cc | 114 +++++++++--------- re2c/basics.h | 57 --------- re2c/bootstrap/parser.cc | 6 +- re2c/bootstrap/scanner.cc | 4 +- re2c/c99_stdint.h | 237 ++++++++++++++++++++++++++++++++++++++ re2c/code.cc | 134 ++++++++++----------- re2c/code.h | 6 +- re2c/dfa.cc | 14 +-- re2c/dfa.h | 62 +++++----- re2c/enc.cc | 22 ++-- re2c/enc.h | 34 +++--- re2c/globals.h | 25 ++-- re2c/go.h | 70 +++++------ re2c/go_construct.cc | 60 +++++----- re2c/go_destruct.cc | 2 +- re2c/go_emit.cc | 50 ++++---- re2c/go_used_labels.cc | 6 +- re2c/indent.h | 2 +- re2c/input_api.cc | 22 ++-- re2c/input_api.h | 24 ++-- re2c/ins.h | 24 ++-- re2c/main.cc | 12 +- re2c/output.cc | 28 ++--- re2c/output.h | 34 +++--- re2c/parser.y | 6 +- re2c/print.cc | 10 +- re2c/print.h | 10 +- re2c/range.cc | 6 +- re2c/range.h | 8 +- re2c/range_suffix.h | 8 +- re2c/re.h | 58 +++++----- re2c/scanner.h | 24 ++-- re2c/scanner.re | 2 +- re2c/skeleton.cc | 68 +++++------ re2c/skeleton.h | 32 ++--- re2c/substr.h | 23 ++-- re2c/token.h | 10 +- re2c/translate.cc | 4 +- re2c/utf16.cc | 8 +- re2c/utf16.h | 20 ++-- re2c/utf16_range.cc | 18 +-- re2c/utf16_range.h | 6 +- re2c/utf16_regexp.cc | 4 +- re2c/utf8.cc | 6 +- re2c/utf8.h | 10 +- re2c/utf8_range.cc | 16 +-- re2c/utf8_range.h | 4 +- re2c/utf8_regexp.cc | 2 +- 49 files changed, 801 insertions(+), 613 deletions(-) delete mode 100644 re2c/basics.h create mode 100644 re2c/c99_stdint.h diff --git a/re2c/Makefile.am b/re2c/Makefile.am index baeb3835..fa5facbe 100755 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -6,7 +6,7 @@ re2c_SOURCES = code.cc code_names.cc dfa.cc go_construct.cc go_destruct.cc go_em 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 diff --git a/re2c/actions.cc b/re2c/actions.cc index f5c4f741..44654167 100644 --- a/re2c/actions.cc +++ b/re2c/actions.cc @@ -82,12 +82,12 @@ const Ins* showIns(std::ostream &o, const Ins &i, const Ins &base) 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; @@ -99,12 +99,12 @@ void NullOp::calcSize(Char*) size = 0; } -uint NullOp::fixedLength() +uint32_t NullOp::fixedLength() { return 0; } -uint NullOp::compile(Char*, Ins*) +uint32_t NullOp::compile(Char*, Ins*) { return 0; } @@ -145,17 +145,17 @@ void MatchOp::calcSize(Char *rep) 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); @@ -166,11 +166,11 @@ uint MatchOp::compile(Char *rep, Ins *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) { @@ -197,7 +197,7 @@ void MatchOp::split(CharSet &s) { 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; @@ -319,10 +319,10 @@ void AltOp::calcSize(Char *rep) 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; @@ -330,7 +330,7 @@ uint AltOp::fixedLength() 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); @@ -339,11 +339,11 @@ uint AltOp::compile(Char *rep, Ins *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) @@ -376,9 +376,9 @@ void CatOp::calcSize(Char *rep) 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) @@ -387,7 +387,7 @@ uint CatOp::fixedLength() 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); @@ -395,8 +395,8 @@ uint CatOp::compile(Char *rep, Ins *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(); @@ -427,7 +427,7 @@ void CloseOp::calcSize(Char *rep) 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); @@ -440,7 +440,7 @@ uint CloseOp::compile(Char *rep, Ins *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(); @@ -476,7 +476,7 @@ void CloseVOp::calcSize(Char *rep) } } -uint CloseVOp::compile(Char *rep, Ins *i) +uint32_t CloseVOp::compile(Char *rep, Ins *i) { if (ins_cache) return compile_goto(ins_cache, i); @@ -486,7 +486,7 @@ uint CloseVOp::compile(Char *rep, Ins *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; @@ -494,7 +494,7 @@ uint CloseVOp::compile(Char *rep, Ins *i) 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) { @@ -504,7 +504,7 @@ uint CloseVOp::compile(Char *rep, Ins *i) } } - const uint sz = i - ins_cache; + const uint32_t sz = i - ins_cache; if (ins_access == PRIVATE) decompile(); @@ -528,13 +528,13 @@ void CloseVOp::split(CharSet &s) 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) { @@ -574,8 +574,8 @@ uint Scanner::unescape(SubStr &s) const 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; } @@ -589,7 +589,7 @@ uint Scanner::unescape(SubStr &s) const return ~0u; } - uint l = 0; + uint32_t l = 0; if (s.str[0] == '0') { l++; @@ -605,8 +605,8 @@ uint Scanner::unescape(SubStr &s) const 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++; } } @@ -658,10 +658,10 @@ uint Scanner::unescape(SubStr &s) const 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()) @@ -710,7 +710,7 @@ uint Scanner::unescape(SubStr &s) const 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; } @@ -727,7 +727,7 @@ std::string& Scanner::unescape(SubStr& str_in, std::string& str_out) const while(str_in.len) { - uint c = unescape(str_in); + uint32_t c = unescape(str_in); if (c > 0xFF) { @@ -742,7 +742,7 @@ std::string& Scanner::unescape(SubStr& str_in, std::string& str_out) const Range * Scanner::getRange(SubStr &s) const { - uint lb = unescape(s), ub; + uint32_t lb = unescape(s), ub; if (s.len < 2 || *s.str != '-') { @@ -755,7 +755,7 @@ Range * Scanner::getRange(SubStr &s) const ub = unescape(s); if (ub < lb) { - uint tmp = lb; + uint32_t tmp = lb; lb = ub; ub = tmp; } @@ -767,7 +767,7 @@ Range * Scanner::getRange(SubStr &s) const 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); @@ -804,7 +804,7 @@ RegExp * Scanner::strToCaseInsensitiveRE(SubStr s) const if (s.len == 0) return new NullOp; - uint c = unescape(s); + uint32_t c = unescape(s); RegExp *re, *reL, *reU; @@ -821,7 +821,7 @@ RegExp * Scanner::strToCaseInsensitiveRE(SubStr s) const while (s.len > 0) { - uint c = unescape(s); + uint32_t c = unescape(s); if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { @@ -885,7 +885,7 @@ RegExp * Scanner::invToRE(SubStr s) const 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); @@ -910,7 +910,7 @@ RegExp * Scanner::mkDefault() const 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) @@ -921,7 +921,7 @@ RuleOp::RuleOp(RegExp *e, RegExp *c, Token *t, uint a, InsAccess access) 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); @@ -934,7 +934,7 @@ void RuleOp::calcSize(Char *rep) 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); @@ -954,7 +954,7 @@ uint RuleOp::compile(Char *rep, Ins *i) i->i.link = this; ++i; - const uint sz = i - ins_cache; + const uint32_t sz = i - ins_cache; if (ins_access == PRIVATE) decompile(); @@ -1028,7 +1028,7 @@ CharSet::CharSet() , 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 */ @@ -1047,14 +1047,14 @@ CharSet::~CharSet() delete[] ptn; } -smart_ptr genCode(RegExp *re, Output & output, uint ind) +smart_ptr 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; @@ -1062,7 +1062,7 @@ smart_ptr genCode(RegExp *re, Output & output, uint ind) 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]; @@ -1073,7 +1073,7 @@ smart_ptr genCode(RegExp *re, Output & output, uint ind) 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; @@ -1086,7 +1086,7 @@ smart_ptr genCode(RegExp *re, Output & output, uint ind) } */ - for (uint j = 0; j < size;) + for (uint32_t j = 0; j < size;) { unmark(&ins[j]); diff --git a/re2c/basics.h b/re2c/basics.h deleted file mode 100644 index f160ce24..00000000 --- a/re2c/basics.h +++ /dev/null @@ -1,57 +0,0 @@ -/* $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 diff --git a/re2c/bootstrap/parser.cc b/re2c/bootstrap/parser.cc index 79c665ea..bba1a4cf 100644 --- a/re2c/bootstrap/parser.cc +++ b/re2c/bootstrap/parser.cc @@ -83,7 +83,7 @@ #include "globals.h" #include "parser.h" -#include "basics.h" +#include "c99_stdint.h" #include "dfa.h" #include "smart_ptr.h" @@ -98,7 +98,7 @@ int yylex(); 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; @@ -2422,7 +2422,7 @@ void parse(Scanner& i, Output & o) } if (specMap.size() < ruleSetupMap.size()) { - uint line = in->get_cline(); + uint32_t line = in->get_cline(); itRuleSetup = ruleSetupMap.find("*"); if (itRuleSetup != ruleSetupMap.end()) { diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index 41ec86a6..a528f9cd 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -1,4 +1,4 @@ -/* 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 #include #include @@ -543,7 +543,7 @@ yy109: int Scanner::scan() { char *cursor = cur; - uint depth; + uint32_t depth; scan: tchar = cursor - pos; diff --git a/re2c/c99_stdint.h b/re2c/c99_stdint.h new file mode 100644 index 00000000..44843c2d --- /dev/null +++ b/re2c/c99_stdint.h @@ -0,0 +1,237 @@ +// 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 +#else + +#ifndef _MSC_STDINT_H_ // [ +#define _MSC_STDINT_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// For Visual Studio 6 in C++ mode wrap 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 +#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 +#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 diff --git a/re2c/code.cc b/re2c/code.cc index 7cc21c34..804a8175 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -44,7 +44,7 @@ std::string replaceParam(std::string str, const std::string& param, const _Ty& v return str; } -static void genYYFill(OutputFile & o, uint, uint need) +static void genYYFill(OutputFile & o, uint32_t, uint32_t need) { if (bUseYYFillParam) { @@ -90,7 +90,7 @@ static std::string genGetCondition() } } -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) { @@ -102,10 +102,10 @@ static void genSetCondition(OutputFile & o, uint ind, const std::string& newcond } } -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) { @@ -164,13 +164,13 @@ const BitMap *BitMap::find(const State *x) 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) { @@ -178,13 +178,13 @@ void BitMap::gen(OutputFile & o, uint ind, uint lb, uint ub) } 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; @@ -197,7 +197,7 @@ void BitMap::gen(OutputFile & o, uint ind, uint lb, uint ub) 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) { @@ -210,7 +210,7 @@ void BitMap::gen(OutputFile & o, uint ind, uint lb, uint ub) } else { - o.write_uint_width (bm[j], 3); + o.write_uint32_t_width (bm[j], 3); } o << ", "; } @@ -222,7 +222,7 @@ void BitMap::gen(OutputFile & o, uint ind, uint lb, uint ub) } } -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) { @@ -240,14 +240,14 @@ static void genGoTo(OutputFile & o, uint ind, const State *from, const State *to 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) { @@ -302,7 +302,7 @@ static void need(OutputFile & o, uint ind, uint n, bool & readCh, bool bSetMarke } } -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; @@ -333,7 +333,7 @@ void Match::emit(Output & output, uint ind, bool &readCh, const std::string&) co } } -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; @@ -382,7 +382,7 @@ void Initial::emit(Output & output, uint ind, bool &readCh, const std::string&) } } -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; @@ -415,14 +415,14 @@ void Save::emit(Output & output, uint ind, bool &readCh, const std::string&) con } } -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) { @@ -431,11 +431,11 @@ void Accept::genRuleMap() } } -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); @@ -449,7 +449,7 @@ void Accept::emitBinary(OutputFile & o, uint ind, uint l, uint r, bool &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; @@ -529,7 +529,7 @@ void Accept::emit(Output & output, uint ind, bool &readCh, const std::string &) } } -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; @@ -539,7 +539,7 @@ void Rule::emit(Output & output, uint ind, bool &, const std::string& condName) return; } - uint back = rule->ctx->fixedLength(); + uint32_t back = rule->ctx->fixedLength(); if (back != 0u && !DFlag) { @@ -579,7 +579,7 @@ void Rule::emit(Output & output, uint ind, bool &, const std::string& condName) 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; @@ -598,10 +598,10 @@ void State::emit(Output & output, uint ind, bool &readCh, const std::string& con 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 @@ -673,7 +673,7 @@ static uint merge(Span *x0, State *fg, State *bg) } } -static const uint cInfinity = ~0u; +static const uint32_t cInfinity = ~0u; class SCC { @@ -682,7 +682,7 @@ public: State **top, **stk; public: - SCC(uint); + SCC(uint32_t); ~SCC(); void traverse(State*); @@ -701,7 +701,7 @@ private: #endif }; -SCC::SCC(uint size) +SCC::SCC(uint32_t size) : top(new State * [size]) , stk(top) { @@ -715,10 +715,10 @@ SCC::~SCC() 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; @@ -761,7 +761,7 @@ static bool state_is_in_non_trivial_SCC(const State* s) // 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; @@ -774,22 +774,22 @@ static bool state_is_in_non_trivial_SCC(const State* s) 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 { @@ -883,14 +883,14 @@ void DFA::findBaseState() { 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) { @@ -909,17 +909,17 @@ void DFA::findBaseState() 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) { @@ -934,8 +934,8 @@ void DFA::prepare(uint & max_fill) } } - 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 @@ -1052,7 +1052,7 @@ void DFA::prepare(uint & max_fill) } } -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; @@ -1064,13 +1064,13 @@ void DFA::emit(Output & output, uint& ind, const RegExpMap* specMap, const std:: // 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); @@ -1096,7 +1096,7 @@ void DFA::emit(Output & output, uint& ind, const RegExpMap* specMap, const std:: // 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) @@ -1233,7 +1233,7 @@ void DFA::emit(Output & output, uint& ind, const RegExpMap* specMap, const std:: 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) { @@ -1258,7 +1258,7 @@ static void output_state_goto_sub (std::ostream & o, uint ind, uint start_label, } } -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) { @@ -1326,7 +1326,7 @@ void output_state_goto (std::ostream & o, uint ind, uint start_label) } } -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()) { @@ -1347,7 +1347,7 @@ void genCondTable(OutputFile & o, uint ind, const RegExpMap& specMap) } } -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) { @@ -1355,7 +1355,7 @@ static void genCondGotoSub(OutputFile & o, uint ind, RegExpIndices& vCondList, u } 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); @@ -1365,7 +1365,7 @@ static void genCondGotoSub(OutputFile & o, uint ind, RegExpIndices& vCondList, u } } -void genCondGoto(OutputFile & o, uint ind, const RegExpMap& specMap) +void genCondGoto(OutputFile & o, uint32_t ind, const RegExpMap& specMap) { if (cFlag && !bWroteCondCheck && specMap.size()) { @@ -1418,7 +1418,7 @@ void genTypes(Output & output, const RegExpMap& specMap) } } -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) { @@ -1426,7 +1426,7 @@ void output_yyaccept_init (std::ostream & o, uint ind, bool 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) { @@ -1434,12 +1434,12 @@ void output_yyaccept_selector (std::ostream & o, uint ind, bool used_yyaccept, u } } -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) { @@ -1447,7 +1447,7 @@ void output_line_info (std::ostream & o, uint line_number, const char * file_nam } } -void output_types (std::ostream & o, uint ind, const std::vector & types) +void output_types (std::ostream & o, uint32_t ind, const std::vector & types) { o << indent (ind++) << "enum " << mapCodeName["YYCONDTYPE"] << " {\n"; for (unsigned int i = 0; i < types.size (); ++i) @@ -1747,11 +1747,11 @@ Scanner::Scanner (Input & i, OutputFile & o) , 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) @@ -1774,7 +1774,7 @@ char *Scanner::fill(char *cursor, uint need) { need = BSIZE; } - if (static_cast(top - lim) < need) + if (static_cast(top - lim) < need) { char *buf = new char[(lim - bot) + need]; if (!buf) @@ -1810,7 +1810,7 @@ void Scanner::set_in_parse(bool new_in_parse) 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) << ": " @@ -1818,12 +1818,12 @@ void Scanner::fatal_at(uint line, uint ofs, const char *msg) const 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]; @@ -1861,7 +1861,7 @@ Scanner::~Scanner() } } -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) { diff --git a/re2c/code.h b/re2c/code.h index d1687075..a0b6894b 100755 --- a/re2c/code.h +++ b/re2c/code.h @@ -18,13 +18,13 @@ public: 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(); diff --git a/re2c/dfa.cc b/re2c/dfa.cc index d9abf63b..249358a9 100644 --- a/re2c/dfa.cc +++ b/re2c/dfa.cc @@ -20,9 +20,9 @@ std::ostream& operator<<(std::ostream &o, const State &s) 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); } @@ -91,7 +91,7 @@ struct GoTo 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) @@ -102,7 +102,7 @@ DFA::DFA(Ins *ins, uint ni, uint lb, uint ub, const Char *rep) , 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)); @@ -114,8 +114,8 @@ DFA::DFA(Ins *ins, uint ni, uint lb, uint ub, const Char *rep) toDo = s->link; Ins **cP, **iP, *i; - uint nGoTos = 0; - uint j; + uint32_t nGoTos = 0; + uint32_t j; s->rule = NULL; @@ -209,7 +209,7 @@ void DFA::addState(State **a, State *s) tail = &s->next; } -State *DFA::findState(Ins **kernel, uint kCount) +State *DFA::findState(Ins **kernel, uint32_t kCount) { Ins **cP, **iP, *i; State *s; diff --git a/re2c/dfa.h b/re2c/dfa.h index fa5878ae..501be0d7 100644 --- a/re2c/dfa.h +++ b/re2c/dfa.h @@ -35,7 +35,7 @@ public: 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 @@ -58,29 +58,29 @@ class Match: public Action { 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 @@ -88,24 +88,24 @@ 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 RuleMap; + typedef std::map 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 @@ -133,7 +133,7 @@ public: 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: @@ -154,12 +154,12 @@ class State { 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; @@ -170,7 +170,7 @@ public: 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*); @@ -201,9 +201,9 @@ class DFA { 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; @@ -211,20 +211,20 @@ public: 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*); @@ -267,12 +267,12 @@ inline Match::Match(State *s) : Action(s) 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; } @@ -282,7 +282,7 @@ inline Move::Move(State *s) : Action(s) 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; diff --git a/re2c/enc.cc b/re2c/enc.cc index ddf389aa..4d7eb7d0 100644 --- a/re2c/enc.cc +++ b/re2c/enc.cc @@ -2,11 +2,11 @@ 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, @@ -26,7 +26,7 @@ const uint Enc::asc2ebc[256] = 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, @@ -58,7 +58,7 @@ const uint Enc::ebc2asc[256] = * by current policy, otherwise returns true. * Overwrites code point. */ -bool Enc::encode(uint & c) const +bool Enc::encode(uint32_t & c) const { switch (type) { @@ -95,7 +95,7 @@ bool Enc::encode(uint & c) const * 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) { @@ -124,7 +124,7 @@ uint Enc::decodeUnsafe(uint c) const * 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) @@ -136,11 +136,11 @@ Range * Enc::encodeRange(uint l, uint h) const 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; diff --git a/re2c/enc.h b/re2c/enc.h index bc7d0edf..cf04a723 100644 --- a/re2c/enc.h +++ b/re2c/enc.h @@ -1,7 +1,7 @@ #ifndef _enc_h #define _enc_h -#include "basics.h" +#include "c99_stdint.h" #include "range.h" namespace re2c { @@ -50,11 +50,11 @@ public: }; 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; @@ -67,10 +67,10 @@ public: 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); @@ -78,13 +78,13 @@ public: 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) { @@ -98,7 +98,7 @@ inline uint Enc::nCodePoints() const return ~0; // to silence gcc warning } -inline uint Enc::nCodeUnits() const +inline uint32_t Enc::nCodeUnits() const { switch (type) { @@ -113,7 +113,7 @@ inline uint Enc::nCodeUnits() const } // returns *maximal* code point size for encoding -inline uint Enc::szCodePoint() const +inline uint32_t Enc::szCodePoint() const { switch (type) { @@ -127,7 +127,7 @@ inline uint Enc::szCodePoint() const return ~0; // to silence gcc warning } -inline uint Enc::szCodeUnit() const +inline uint32_t Enc::szCodeUnit() const { switch (type) { diff --git a/re2c/globals.h b/re2c/globals.h index b1feab48..20a74784 100644 --- a/re2c/globals.h +++ b/re2c/globals.h @@ -2,10 +2,11 @@ #ifndef _globals_h #define _globals_h -#include "basics.h" #include #include #include + +#include "c99_stdint.h" #include "code_names.h" #include "enc.h" #include "input_api.h" @@ -46,11 +47,11 @@ extern std::string yyFillLength; 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; @@ -70,20 +71,20 @@ extern bool bWroteCondCheck; 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 vUsedLabels; +extern uint32_t next_fill_index; +extern uint32_t last_fill_index; +extern std::set 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 diff --git a/re2c/go.h b/re2c/go.h index 15ae8431..cf311166 100644 --- a/re2c/go.h +++ b/re2c/go.h @@ -4,7 +4,7 @@ #include #include -#include "basics.h" +#include "c99_stdint.h" #include "code.h" namespace re2c @@ -15,35 +15,35 @@ struct If; // forward 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 > ranges; + std::vector > 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 @@ -51,18 +51,18 @@ 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 > 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 (); }; @@ -78,9 +78,9 @@ struct If 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 (); }; @@ -96,9 +96,9 @@ struct SwitchIf 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 (); }; @@ -108,19 +108,19 @@ struct Bitmap 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 (); }; @@ -128,9 +128,9 @@ struct Cpgoto { 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 (); }; @@ -138,14 +138,14 @@ struct Dot { 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 { @@ -166,20 +166,20 @@ struct Go 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 diff --git a/re2c/go_construct.cc b/re2c/go_construct.cc index f999d324..692aab1c 100644 --- a/re2c/go_construct.cc +++ b/re2c/go_construct.cc @@ -4,21 +4,21 @@ 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) { @@ -31,24 +31,24 @@ void Cases::add (uint lb, uint ub, State * 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 (;;) @@ -90,7 +90,7 @@ Linear::Linear (const Span * s, uint n, const State * next) } } -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 () { @@ -105,7 +105,7 @@ If::If (type_t t, const Span * sp, uint nsp, const State * next) } } -SwitchIf::SwitchIf (const Span * sp, uint nsp, const State * next) +SwitchIf::SwitchIf (const Span * sp, uint32_t nsp, const State * next) : type (IF) , info () { @@ -124,27 +124,27 @@ SwitchIf::SwitchIf (const Span * sp, uint nsp, const State * next) } } -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) { @@ -153,12 +153,12 @@ CpgotoTable::CpgotoTable (const Span * span, uint nSpans) } } -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)) {} @@ -178,9 +178,9 @@ void Go::init (const State * from) } // 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) { @@ -191,10 +191,10 @@ void Go::init (const State * from) } // 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) { @@ -211,7 +211,7 @@ void Go::init (const State * from) } } - const uint dSpans = nSpans - hSpans - nBitmaps; + const uint32_t dSpans = nSpans - hSpans - nBitmaps; if (DFlag) { type = DOT; @@ -236,12 +236,12 @@ void Go::init (const State * from) } // 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 (;;) { @@ -277,10 +277,10 @@ bool matches(const Span * b1, uint n1, const State * s1, const Span * b2, uint n * 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) { diff --git a/re2c/go_destruct.cc b/re2c/go_destruct.cc index 6b91d391..e419ef96 100644 --- a/re2c/go_destruct.cc +++ b/re2c/go_destruct.cc @@ -18,7 +18,7 @@ Binary::~Binary () Linear::~Linear () { - for (uint i = 0; i < branches.size (); ++i) + for (uint32_t i = 0; i < branches.size (); ++i) { delete branches[i].first; } diff --git a/re2c/go_emit.cc b/re2c/go_emit.cc index 2ec1d832..cd8ca240 100644 --- a/re2c/go_emit.cc +++ b/re2c/go_emit.cc @@ -6,7 +6,7 @@ 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; @@ -26,14 +26,14 @@ std::string output_yych (bool & readCh) } } -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) { @@ -43,7 +43,7 @@ void output_goto (OutputFile & o, uint ind, bool & readCh, uint to) 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) @@ -60,7 +60,7 @@ std::string output_hgo (OutputFile & o, uint ind, bool & readCh, SwitchIf * hgo) 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 << " "; @@ -76,18 +76,18 @@ uint Span::show (std::ostream & o, uint lb) const 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) << " */"; } @@ -100,10 +100,10 @@ void Case::emit (OutputFile & o, uint ind) } } -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) { @@ -116,7 +116,7 @@ void Cases::emit (OutputFile & o, uint ind, bool & readCh) 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"; @@ -126,9 +126,9 @@ void Binary::emit (OutputFile & o, uint ind, bool & readCh) 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) { @@ -142,7 +142,7 @@ void Linear::emit (OutputFile & o, uint ind, bool & readCh) } } -void If::emit (OutputFile & o, uint ind, bool & readCh) +void If::emit (OutputFile & o, uint32_t ind, bool & readCh) { switch (type) { @@ -155,7 +155,7 @@ void If::emit (OutputFile & o, uint ind, bool & readCh) } } -void SwitchIf::emit (OutputFile & o, uint ind, bool & readCh) +void SwitchIf::emit (OutputFile & o, uint32_t ind, bool & readCh) { switch (type) { @@ -168,7 +168,7 @@ void SwitchIf::emit (OutputFile & o, uint ind, bool & readCh) } } -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 << "] & "; @@ -178,7 +178,7 @@ void Bitmap::emit (OutputFile & o, uint ind, bool & readCh) } else { - o << (uint) bitmap->m; + o << (uint32_t) bitmap->m; } o << ") {\n"; output_goto (o, ind + 1, readCh, bitmap_state->label); @@ -189,11 +189,11 @@ void Bitmap::emit (OutputFile & o, uint ind, bool & readCh) } } -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) @@ -212,7 +212,7 @@ void CpgotoTable::emit (OutputFile & o, uint ind) 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"; @@ -223,17 +223,17 @@ void Cpgoto::emit (OutputFile & o, uint ind, bool & readCh) 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); } @@ -242,7 +242,7 @@ void Dot::emit (OutputFile & o) } } -void Go::emit (OutputFile & o, uint ind, bool & readCh) +void Go::emit (OutputFile & o, uint32_t ind, bool & readCh) { switch (type) { diff --git a/re2c/go_used_labels.cc b/re2c/go_used_labels.cc index e59184c6..55e8b5ce 100644 --- a/re2c/go_used_labels.cc +++ b/re2c/go_used_labels.cc @@ -6,7 +6,7 @@ namespace re2c 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); } @@ -20,7 +20,7 @@ void Binary::used_labels () 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); } @@ -67,7 +67,7 @@ void Bitmap::used_labels () 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); } diff --git a/re2c/indent.h b/re2c/indent.h index 4bf41a26..473f0e5f 100644 --- a/re2c/indent.h +++ b/re2c/indent.h @@ -7,7 +7,7 @@ namespace re2c { -inline std::string indent (uint ind) +inline std::string indent (uint32_t ind) { std::string str; diff --git a/re2c/input_api.cc b/re2c/input_api.cc index 3fe20dbc..7ee35693 100644 --- a/re2c/input_api.cc +++ b/re2c/input_api.cc @@ -32,12 +32,12 @@ std::string InputAPI::expr_peek_save () 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) @@ -52,7 +52,7 @@ std::string InputAPI::stmt_skip (uint ind) 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) @@ -67,7 +67,7 @@ std::string InputAPI::stmt_backup (uint ind) 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) @@ -83,7 +83,7 @@ std::string InputAPI::stmt_backupctx (uint ind) 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) @@ -98,7 +98,7 @@ std::string InputAPI::stmt_restore (uint ind) 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) @@ -114,28 +114,28 @@ std::string InputAPI::stmt_restorectx (uint ind) 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" @@ -149,7 +149,7 @@ std::string InputAPI::expr_lessthan_one () : expr_lessthan (1); } -std::string InputAPI::expr_lessthan (uint n) +std::string InputAPI::expr_lessthan (uint32_t n) { std::ostringstream s; switch (type) diff --git a/re2c/input_api.h b/re2c/input_api.h index 2db31269..2c87b3bb 100644 --- a/re2c/input_api.h +++ b/re2c/input_api.h @@ -4,7 +4,7 @@ #include #include -#include "basics.h" +#include "c99_stdint.h" namespace re2c { @@ -24,18 +24,18 @@ public: 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 diff --git a/re2c/ins.h b/re2c/ins.h index 05e5b7e1..e86ef3f7 100644 --- a/re2c/ins.h +++ b/re2c/ins.h @@ -2,25 +2,25 @@ #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; } @@ -28,9 +28,9 @@ union Ins { struct { - uint value; - uint bump; - void *link; + uint32_t value; + uint32_t bump; + void *link; } c; diff --git a/re2c/main.cc b/re2c/main.cc index 6d7b2a5f..45fd9fe3 100644 --- a/re2c/main.cc +++ b/re2c/main.cc @@ -61,10 +61,10 @@ std::string yyFillLength("@@"); 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; @@ -76,9 +76,9 @@ bool bCaseInverted = false; Enc encoding; InputAPI input_api; -uint next_fill_index = 0; -uint last_fill_index = 0; -std::set vUsedLabels; +uint32_t next_fill_index = 0; +uint32_t last_fill_index = 0; +std::set vUsedLabels; CodeNames mapCodeName; free_list RegExp::vFreeList; diff --git a/re2c/output.cc b/re2c/output.cc index b2945d52..e37c8e2e 100644 --- a/re2c/output.cc +++ b/re2c/output.cc @@ -8,19 +8,19 @@ 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') { @@ -89,27 +89,27 @@ void OutputFile::write (const char * s, std::streamsize 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); } @@ -119,7 +119,7 @@ void OutputFile::write_version_time () output_version_time (stream ()); } -OutputFile & operator << (OutputFile & u, uint n) +OutputFile & operator << (OutputFile & u, uint32_t n) { u.stream () << n; return u; @@ -154,7 +154,7 @@ void OutputFile::insert_line_info () 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) { @@ -172,13 +172,13 @@ void OutputFile::insert_types () 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; @@ -210,7 +210,7 @@ void OutputFile::new_block () void OutputFile::emit ( const std::vector & types - , uint max_fill + , uint32_t max_fill ) { if (file != NULL) diff --git a/re2c/output.h b/re2c/output.h index a3d81d37..f61da8ea 100644 --- a/re2c/output.h +++ b/re2c/output.h @@ -6,7 +6,7 @@ #include #include -#include "basics.h" +#include "c99_stdint.h" namespace re2c { @@ -28,16 +28,16 @@ struct OutputFragment 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 @@ -59,34 +59,34 @@ struct OutputFile 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 & types, uint max_fill); + void emit (const std::vector & types, uint32_t max_fill); private: const char * file_name; FILE * file; std::vector blocks; - uint prolog_label; + uint32_t prolog_label; std::ostream & stream (); void insert_code (); @@ -121,7 +121,7 @@ struct Output HeaderFile header; DataFile data; std::vector types; - uint max_fill; + uint32_t max_fill; Output (const char * source_name, const char * header_name); ~Output (); diff --git a/re2c/parser.y b/re2c/parser.y index bdf8ca4b..f3582769 100644 --- a/re2c/parser.y +++ b/re2c/parser.y @@ -15,7 +15,7 @@ #include "globals.h" #include "parser.h" -#include "basics.h" +#include "c99_stdint.h" #include "dfa.h" #include "smart_ptr.h" @@ -30,7 +30,7 @@ int yylex(); 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; @@ -702,7 +702,7 @@ void parse(Scanner& i, Output & o) } if (specMap.size() < ruleSetupMap.size()) { - uint line = in->get_cline(); + uint32_t line = in->get_cline(); itRuleSetup = ruleSetupMap.find("*"); if (itRuleSetup != ruleSetupMap.end()) { diff --git a/re2c/print.cc b/re2c/print.cc index a2017b33..e3ae8f0f 100644 --- a/re2c/print.cc +++ b/re2c/print.cc @@ -6,7 +6,7 @@ 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))) { @@ -20,7 +20,7 @@ void prtChOrHex(std::ostream& o, uint c) } } -void prtHex(std::ostream& o, uint c) +void prtHex(std::ostream& o, uint32_t c) { int oc = (int)(c); @@ -52,7 +52,7 @@ void prtHex(std::ostream& o, uint c) } } -void prtCh(std::ostream& o, uint c) +void prtCh(std::ostream& o, uint32_t c) { if (encoding.is(Enc::EBCDIC)) { @@ -135,7 +135,7 @@ void prtCh(std::ostream& o, uint c) } } -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 != ']')) { @@ -147,7 +147,7 @@ void prtChOrHexForSpan(std::ostream& o, uint c) } } -void printSpan(std::ostream& o, uint lb, uint ub) +void printSpan(std::ostream& o, uint32_t lb, uint32_t ub) { if (lb > ub) { diff --git a/re2c/print.h b/re2c/print.h index a66f60d2..483ae819 100644 --- a/re2c/print.h +++ b/re2c/print.h @@ -3,15 +3,15 @@ #include -#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 diff --git a/re2c/range.cc b/re2c/range.cc index 2a9dfb7d..8f4624f7 100644 --- a/re2c/range.cc +++ b/re2c/range.cc @@ -57,7 +57,7 @@ Range *doUnion(Range *r1, Range *r2) if (!(r1 = r1->next)) { - uint ub = 0; + uint32_t ub = 0; for (; r2 && r2->lb <= s->ub; r2 = r2->next) ub = r2->ub; @@ -80,7 +80,7 @@ Range *doUnion(Range *r1, Range *r2) if (!(r2 = r2->next)) { - uint ub = 0; + uint32_t ub = 0; for (; r1 && r1->lb <= s->ub; r1 = r1->next) ub = r1->ub; @@ -106,7 +106,7 @@ Range *doDiff(Range *r1, Range *r2) for (; r1; r1 = r1->next) { - uint lb = r1->lb; + uint32_t lb = r1->lb; for (; r2 && r2->ub <= r1->lb; r2 = r2->next) diff --git a/re2c/range.h b/re2c/range.h index a1f52842..a6a0e0f0 100644 --- a/re2c/range.h +++ b/re2c/range.h @@ -3,7 +3,7 @@ #include -#include "basics.h" +#include "c99_stdint.h" #include "free_list.h" namespace re2c @@ -13,13 +13,13 @@ class Range { public: - Range *next; - uint lb, ub; // [lb,ub) + Range *next; + uint32_t lb, ub; // [lb,ub) static free_list 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); } diff --git a/re2c/range_suffix.h b/re2c/range_suffix.h index 82c6065b..f29f95b1 100644 --- a/re2c/range_suffix.h +++ b/re2c/range_suffix.h @@ -3,7 +3,7 @@ #include // NULL -#include "basics.h" +#include "c99_stdint.h" #include "free_list.h" namespace re2c { @@ -15,12 +15,12 @@ class RangeSuffix static free_list 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) diff --git a/re2c/re.h b/re2c/re.h index f4219fcd..43ea0569 100644 --- a/re2c/re.h +++ b/re2c/re.h @@ -31,7 +31,7 @@ ExtOp; struct CharPtn { - uint card; + uint32_t card; CharPtn *fix; CharPtn *nxt; }; @@ -53,7 +53,7 @@ class RegExp { public: - uint size; + uint32_t size; /* * There're several different cases when the same regexp @@ -97,8 +97,8 @@ public: 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&); @@ -122,8 +122,8 @@ class NullOp: public 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 { @@ -144,8 +144,8 @@ 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&) const; @@ -173,12 +173,12 @@ private: 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() { @@ -187,13 +187,13 @@ public: 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: @@ -234,8 +234,8 @@ 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 { @@ -278,8 +278,8 @@ 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 { @@ -316,7 +316,7 @@ public: void split(CharSet&); void calcSize(Char*); - uint compile(Char*, Ins*); + uint32_t compile(Char*, Ins*); void decompile(); void display(std::ostream &o) const { @@ -357,7 +357,7 @@ public: void split(CharSet&); void calcSize(Char*); - uint compile(Char*, Ins*); + uint32_t compile(Char*, Ins*); void decompile(); void display(std::ostream &o) const { @@ -385,24 +385,24 @@ typedef std::pair NRegExp; typedef std::map RegExpMap; typedef std::vector RegExpIndices; typedef std::list RuleOpList; -typedef std::pair LineCode; +typedef std::pair LineCode; typedef std::map SetupMap; typedef std::map DefaultMap; class DFA; -extern smart_ptr genCode(RegExp*, Output & output, uint ind); -extern void genCondTable(OutputFile &, uint, const RegExpMap&); -extern void genCondGoto(OutputFile &, uint, const RegExpMap&); +extern smart_ptr 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 &); +extern void output_state_goto (std::ostream &, uint32_t, uint32_t); +extern void output_types (std::ostream &, uint32_t, const std::vector &); 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*); diff --git a/re2c/scanner.h b/re2c/scanner.h index fdf23725..8271aeb7 100644 --- a/re2c/scanner.h +++ b/re2c/scanner.h @@ -19,7 +19,7 @@ struct ScannerState 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; }; @@ -30,7 +30,7 @@ private: 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); @@ -54,29 +54,29 @@ public: 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; @@ -97,7 +97,7 @@ inline const std::string & Scanner::get_fname () const return in.file_name; } -inline uint Scanner::get_cline() const +inline uint32_t Scanner::get_cline() const { return cline; } @@ -118,7 +118,7 @@ inline SubStr Scanner::token() const 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); diff --git a/re2c/scanner.re b/re2c/scanner.re index 791416cd..354aa61e 100644 --- a/re2c/scanner.re +++ b/re2c/scanner.re @@ -207,7 +207,7 @@ echo: int Scanner::scan() { char *cursor = cur; - uint depth; + uint32_t depth; scan: tchar = cursor - pos; diff --git a/re2c/skeleton.cc b/re2c/skeleton.cc index 30dcfe89..5e13b466 100644 --- a/re2c/skeleton.cc +++ b/re2c/skeleton.cc @@ -5,13 +5,13 @@ 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 m; m[NULL] = &states[states_count - 1]; // default state @@ -27,8 +27,8 @@ Skeleton::Skeleton (const DFA & dfa) 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); @@ -51,7 +51,7 @@ Skeleton::~Skeleton () 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 ()) { @@ -60,17 +60,17 @@ uint Skeleton::estimate_paths_count (SkeletonState * s, uint count) 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; @@ -91,7 +91,7 @@ void generate_paths_all (SkeletonState * s, const std::vector & prefixes, { 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); @@ -103,9 +103,9 @@ void generate_paths_all (SkeletonState * s, const std::vector & prefixes, for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i) { std::vector 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]); @@ -121,7 +121,7 @@ void generate_paths_cover (SkeletonState * s, const std::vector & prefixes { 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]); } @@ -132,7 +132,7 @@ void generate_paths_cover (SkeletonState * s, const std::vector & prefixes if (s->path != NULL) { std::vector zs (prefixes); - for (uint i = 0; i < zs.size (); ++i) + for (uint32_t i = 0; i < zs.size (); ++i) { zs[i].append (s->path); } @@ -140,16 +140,16 @@ void generate_paths_cover (SkeletonState * s, const std::vector & prefixes } 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 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]); @@ -157,7 +157,7 @@ void generate_paths_cover (SkeletonState * s, const std::vector & prefixes generate_paths_cover (i->first, zs, results); if (s->path == NULL && i->first->path != NULL) { - s->path = new Path (std::vector (1, i->second[0]), 0, s->rule); + s->path = new Path (std::vector (1, i->second[0]), 0, s->rule); s->path->append (i->first->path); } } @@ -169,22 +169,22 @@ void generate_paths_cover (SkeletonState * s, const std::vector & prefixes void Skeleton::generate_paths (std::vector & results) { std::vector prefixes; - prefixes.push_back (Path (std::vector (), 0, ~0)); + prefixes.push_back (Path (std::vector (), 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 (), 0, states[i].rule); + states[i].path = new Path (std::vector (), 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; } @@ -197,7 +197,7 @@ void Skeleton::generate_paths (std::vector & results) void Skeleton::emit_data (DataFile & o) { - uint ind = 0; + uint32_t ind = 0; std::string yyctype; switch (encoding.szCodeUnit ()) @@ -230,20 +230,20 @@ void Skeleton::emit_data (DataFile & o) std::vector 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 << ","; @@ -251,7 +251,7 @@ void Skeleton::emit_data (DataFile & o) 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,"; } @@ -261,7 +261,7 @@ void Skeleton::emit_data (DataFile & o) 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"; @@ -270,7 +270,7 @@ void Skeleton::emit_data (DataFile & o) 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 (); @@ -283,7 +283,7 @@ void Skeleton::emit_data (DataFile & o) 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 \n"; o << indent (ind) << "#include \"" << data_name << "\"\n"; @@ -293,7 +293,7 @@ void skeleton_emit_prolog (OutputFile & o, uint ind, const char * data_name) 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"; diff --git a/re2c/skeleton.h b/re2c/skeleton.h index f2ea6c5c..e4c45ae8 100644 --- a/re2c/skeleton.h +++ b/re2c/skeleton.h @@ -4,7 +4,7 @@ #include #include -#include "basics.h" +#include "c99_stdint.h" #include "dfa.h" namespace re2c @@ -12,15 +12,15 @@ namespace re2c struct Path { - std::vector chars; - uint length; - uint rule; - inline Path (const std::vector & cs, uint l, uint r) + std::vector chars; + uint32_t length; + uint32_t rule; + inline Path (const std::vector & 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) { @@ -28,7 +28,7 @@ struct Path rule = r; } } - inline void extend (uint r, uint c) + inline void extend (uint32_t r, uint32_t c) { update (r); chars.push_back (c); @@ -40,7 +40,7 @@ struct Path 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]); } @@ -49,10 +49,10 @@ struct Path struct SkeletonState { - typedef std::map > go_t; + typedef std::map > go_t; go_t go; - uint rule; - uchar visited; + uint32_t rule; + uint8_t visited; Path * path; inline SkeletonState () @@ -76,19 +76,19 @@ struct 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 & 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 & prefixes, std::vector & results); void generate_paths_cover (SkeletonState * s, const std::vector & prefixes, std::vector & results); diff --git a/re2c/substr.h b/re2c/substr.h index d7aadbd3..f8813532 100644 --- a/re2c/substr.h +++ b/re2c/substr.h @@ -5,7 +5,14 @@ #include #include #include -#include "basics.h" + +#include "c99_stdint.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#elif defined(_WIN32) +#include "config_w32.h" +#endif namespace re2c { @@ -15,18 +22,18 @@ class SubStr 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: @@ -54,11 +61,11 @@ inline std::ostream& operator<<(std::ostream& o, const SubStr* s) 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) { } @@ -78,7 +85,7 @@ inline std::string SubStr::to_string() const return str && len ? std::string(str, len) : std::string(); } -inline uint SubStr::ofs() const +inline uint32_t SubStr::ofs() const { return str - org; } diff --git a/re2c/token.h b/re2c/token.h index c7410797..022658d3 100644 --- a/re2c/token.h +++ b/re2c/token.h @@ -13,17 +13,17 @@ public: 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) @@ -33,7 +33,7 @@ inline Token::Token(const SubStr& t, const std::string& s, uint l) ; } -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) diff --git a/re2c/translate.cc b/re2c/translate.cc index 9e7a737f..7c245e73 100644 --- a/re2c/translate.cc +++ b/re2c/translate.cc @@ -4,14 +4,14 @@ 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]; } diff --git a/re2c/utf16.cc b/re2c/utf16.cc index c8e1f56d..fff40159 100644 --- a/re2c/utf16.cc +++ b/re2c/utf16.cc @@ -2,9 +2,9 @@ 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 diff --git a/re2c/utf16.h b/re2c/utf16.h index 02ba6217..c6613915 100644 --- a/re2c/utf16.h +++ b/re2c/utf16.h @@ -1,33 +1,33 @@ #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; } diff --git a/re2c/utf16_range.cc b/re2c/utf16_range.cc index 97841634..eac41720 100644 --- a/re2c/utf16_range.cc +++ b/re2c/utf16_range.cc @@ -6,7 +6,7 @@ namespace re2c { /* * 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 (;;) @@ -29,7 +29,7 @@ void UTF16addContinuous1(RangeSuffix * & root, ushort l, ushort h) * 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 (;;) @@ -90,7 +90,7 @@ void UTF16addContinuous2(RangeSuffix * & root, ushort l_ld, ushort h_ld, ushort * 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) { @@ -125,16 +125,16 @@ void UTF16splitByRuneLength(RangeSuffix * & root, utf16::rune l, utf16::rune h) 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); } } diff --git a/re2c/utf16_range.h b/re2c/utf16_range.h index 7470c1d2..ad211b3b 100644 --- a/re2c/utf16_range.h +++ b/re2c/utf16_range.h @@ -6,9 +6,9 @@ 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 diff --git a/re2c/utf16_regexp.cc b/re2c/utf16_regexp.cc index a19ea95c..02c8e6c4 100644 --- a/re2c/utf16_regexp.cc +++ b/re2c/utf16_regexp.cc @@ -10,8 +10,8 @@ RegExp * UTF16Symbol(utf16::rune r) 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))); } } diff --git a/re2c/utf8.cc b/re2c/utf8.cc index c396ee95..a32c0738 100644 --- a/re2c/utf8.cc +++ b/re2c/utf8.cc @@ -2,7 +2,7 @@ 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 @@ -57,7 +57,7 @@ uint utf8::rune_to_bytes(uchar *str, rune c) 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; @@ -65,7 +65,7 @@ uint utf8::rune_length(rune r) return r <= MAX_3BYTE_RUNE ? 3 : 4; } -utf8::rune utf8::max_rune(uint i) +utf8::rune utf8::max_rune(uint32_t i) { switch (i) { diff --git a/re2c/utf8.h b/re2c/utf8.h index ef87d5eb..8e6e9b07 100644 --- a/re2c/utf8.h +++ b/re2c/utf8.h @@ -1,14 +1,14 @@ #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 */ @@ -32,13 +32,13 @@ public: }; /* 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 diff --git a/re2c/utf8_range.cc b/re2c/utf8_range.cc index afe1c0ce..3cca7a16 100644 --- a/re2c/utf8_range.cc +++ b/re2c/utf8_range.cc @@ -7,10 +7,10 @@ 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); @@ -62,11 +62,11 @@ void UTF8addContinuous(RangeSuffix * & root, utf8::rune l, utf8::rune h, uint n) * 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) @@ -97,8 +97,8 @@ void UTF8splitByContinuity(RangeSuffix * & root, utf8::rune l, utf8::rune h, uin */ 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); diff --git a/re2c/utf8_range.h b/re2c/utf8_range.h index 01fa15eb..a624c110 100644 --- a/re2c/utf8_range.h +++ b/re2c/utf8_range.h @@ -6,8 +6,8 @@ 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 diff --git a/re2c/utf8_regexp.cc b/re2c/utf8_regexp.cc index a7f654e5..22f08659 100644 --- a/re2c/utf8_regexp.cc +++ b/re2c/utf8_regexp.cc @@ -6,7 +6,7 @@ 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) -- 2.40.0