From: nuffer Date: Mon, 1 Nov 2004 04:35:57 +0000 (+0000) Subject: Modified the code to be in namespace re2c, this should prevent problems with typedefs... X-Git-Tag: 0.13.6~684 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5dedd4c44e5ad9e12bf32e61bf47270160fbf274;p=re2c Modified the code to be in namespace re2c, this should prevent problems with typedefs for uint, uchar, etc. --- diff --git a/actions.cc b/actions.cc index 5bd98be1..eacedbbd 100644 --- a/actions.cc +++ b/actions.cc @@ -9,6 +9,9 @@ #include "parser.h" #include "dfa.h" +namespace re2c +{ + Symbol *Symbol::first = NULL; Symbol::Symbol(const SubStr &str) : next(first), name(str), re(NULL) @@ -810,3 +813,6 @@ void genCode(std::ostream& o, RegExp *re) delete dfa; delete [] ins; } + +} // end namespace re2c + diff --git a/basics.h b/basics.h index a1233879..2e186277 100644 --- a/basics.h +++ b/basics.h @@ -6,6 +6,9 @@ #include "config.h" #endif +namespace re2c +{ + #if SIZEOF_CHAR == 1 typedef unsigned char byte; #elif SIZEOF_SHORT == 1 @@ -42,20 +45,11 @@ typedef unsigned long dword; typedef unsigned long dword; #endif -#ifndef HAVE_UINT typedef unsigned int uint; -#endif - -#ifndef HAVE_UCHAR typedef unsigned char uchar; -#endif - -#ifndef HAVE_USHORT typedef unsigned short ushort; -#endif - -#ifndef HAVE_ULONG typedef unsigned long ulong; -#endif + +} // end namespace re2c #endif diff --git a/bootstrap/scanner.cc b/bootstrap/scanner.cc index 61dc3ff6..2d641bbb 100644 --- a/bootstrap/scanner.cc +++ b/bootstrap/scanner.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.9.4 on Mon Jul 26 23:14:20 2004 */ +/* Generated by re2c 0.9.4 on Sun Oct 31 21:27:49 2004 */ #line 1 "scanner.re" /* $Id$ */ #include @@ -24,6 +24,8 @@ extern YYSTYPE yylval; #define RETURN(i) {cur = cursor; return i;} +namespace re2c +{ Scanner::Scanner(std::istream& i) : in(i), bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL), @@ -62,7 +64,7 @@ char *Scanner::fill(char *cursor){ return cursor; } -#line 72 "scanner.re" +#line 74 "scanner.re" int Scanner::echo(std::ostream &out){ @@ -92,13 +94,13 @@ yy2: yyaccept = 0; if(yych == '*') goto yy7; goto yy3; yy3: -#line 91 "scanner.re" +#line 93 "scanner.re" { goto echo; } #line 26 "scanner.cc" yy4: ++YYCURSOR; goto yy5; yy5: -#line 87 "scanner.re" +#line 89 "scanner.re" { if(cursor == eof) RETURN(0); out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); tok = pos = cursor; cline++; @@ -128,13 +130,13 @@ yy12: yych = *++YYCURSOR; yy13: ++YYCURSOR; goto yy14; yy14: -#line 84 "scanner.re" +#line 86 "scanner.re" { out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); tok = cursor; RETURN(1); } #line 64 "scanner.cc" } -#line 92 "scanner.re" +#line 94 "scanner.re" } @@ -210,7 +212,7 @@ yy17: yyaccept = 0; if(yych <= '9') goto yy63; goto yy18; yy18: -#line 105 "scanner.re" +#line 107 "scanner.re" { depth = 1; goto code; } @@ -219,14 +221,14 @@ yy19: ++YYCURSOR; if((yych = *YYCURSOR) == '*') goto yy61; goto yy20; yy20: -#line 131 "scanner.re" +#line 133 "scanner.re" { RETURN(*tok); } #line 141 "scanner.cc" yy21: ++YYCURSOR; if((yych = *YYCURSOR) == '/') goto yy59; goto yy22; yy22: -#line 133 "scanner.re" +#line 135 "scanner.re" { yylval.op = *tok; RETURN(CLOSE); } #line 149 "scanner.cc" @@ -235,7 +237,7 @@ yy23: yyaccept = 1; if(yych != 0x0A) goto yy55; goto yy24; yy24: -#line 122 "scanner.re" +#line 124 "scanner.re" { fatal("unterminated string constant (missing \")"); } #line 157 "scanner.cc" yy25: yyaccept = 2; @@ -243,7 +245,7 @@ yy25: yyaccept = 2; if(yych != 0x0A) goto yy50; goto yy26; yy26: -#line 123 "scanner.re" +#line 125 "scanner.re" { fatal("unterminated string constant (missing ')"); } #line 165 "scanner.cc" yy27: yyaccept = 3; @@ -251,7 +253,7 @@ yy27: yyaccept = 3; if(yych != 0x0A) goto yy44; goto yy28; yy28: -#line 129 "scanner.re" +#line 131 "scanner.re" { fatal("unterminated range (missing ])"); } #line 173 "scanner.cc" yy29: yych = *++YYCURSOR; @@ -262,7 +264,7 @@ yy31: ++YYCURSOR; yych = *YYCURSOR; goto yy42; yy32: -#line 148 "scanner.re" +#line 150 "scanner.re" { cur = cursor; yylval.symbol = Symbol::find(token()); return ID; } @@ -271,13 +273,13 @@ yy33: ++YYCURSOR; yych = *YYCURSOR; goto yy40; yy34: -#line 152 "scanner.re" +#line 154 "scanner.re" { goto scan; } #line 191 "scanner.cc" yy35: ++YYCURSOR; goto yy36; yy36: -#line 154 "scanner.re" +#line 156 "scanner.re" { if(cursor == eof) RETURN(0); pos = cursor; cline++; goto scan; @@ -286,7 +288,7 @@ yy36: yy37: ++YYCURSOR; goto yy38; yy38: -#line 159 "scanner.re" +#line 161 "scanner.re" { std::cerr << "unexpected character: " << *tok << std::endl; goto scan; } @@ -339,7 +341,7 @@ yy46: ++YYCURSOR; yy47: ++YYCURSOR; goto yy48; yy48: -#line 125 "scanner.re" +#line 127 "scanner.re" { cur = cursor; yylval.regexp = ranToRE(token()); return RANGE; } @@ -364,7 +366,7 @@ yy51: ++YYCURSOR; yy52: ++YYCURSOR; goto yy53; yy53: -#line 118 "scanner.re" +#line 120 "scanner.re" { cur = cursor; yylval.regexp = strToCaseInsensitiveRE(token()); return STRING; } @@ -389,7 +391,7 @@ yy56: ++YYCURSOR; yy57: ++YYCURSOR; goto yy58; yy58: -#line 114 "scanner.re" +#line 116 "scanner.re" { cur = cursor; yylval.regexp = strToRE(token()); return STRING; } @@ -397,14 +399,14 @@ yy58: yy59: ++YYCURSOR; goto yy60; yy60: -#line 111 "scanner.re" +#line 113 "scanner.re" { tok = cursor; RETURN(0); } #line 326 "scanner.cc" yy61: ++YYCURSOR; goto yy62; yy62: -#line 108 "scanner.re" +#line 110 "scanner.re" { depth = 1; goto comment; } #line 333 "scanner.cc" @@ -423,7 +425,7 @@ yy64: if(yych <= '/'){ yy65: ++YYCURSOR; goto yy66; yy66: -#line 136 "scanner.re" +#line 138 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = atoi((char *)tok+1); RETURN(CLOSESIZE); } @@ -434,7 +436,7 @@ yy67: yych = *++YYCURSOR; yy68: ++YYCURSOR; goto yy69; yy69: -#line 144 "scanner.re" +#line 146 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = -1; RETURN(CLOSESIZE); } @@ -450,13 +452,13 @@ yy71: if(yych <= '/') goto yy45; yy72: ++YYCURSOR; goto yy73; yy73: -#line 140 "scanner.re" +#line 142 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1)); RETURN(CLOSESIZE); } #line 382 "scanner.cc" } -#line 162 "scanner.re" +#line 164 "scanner.re" code: @@ -491,7 +493,7 @@ yy74: yy76: ++YYCURSOR; goto yy77; yy77: -#line 166 "scanner.re" +#line 168 "scanner.re" { if(--depth == 0){ cur = cursor; yylval.token = new Token(token(), tline); @@ -502,14 +504,14 @@ yy77: yy78: ++YYCURSOR; goto yy79; yy79: -#line 172 "scanner.re" +#line 174 "scanner.re" { ++depth; goto code; } #line 430 "scanner.cc" yy80: ++YYCURSOR; goto yy81; yy81: -#line 174 "scanner.re" +#line 176 "scanner.re" { if(cursor == eof) fatal("missing '}'"); pos = cursor; cline++; goto code; @@ -518,7 +520,7 @@ yy81: yy82: ++YYCURSOR; goto yy83; yy83: -#line 178 "scanner.re" +#line 180 "scanner.re" { goto code; } #line 445 "scanner.cc" yy84: yyaccept = 0; @@ -568,7 +570,7 @@ yy92: ++YYCURSOR; if(yych == 0x0A) goto yy88; goto yy90; } -#line 179 "scanner.re" +#line 181 "scanner.re" comment: @@ -594,7 +596,7 @@ yy95: ++YYCURSOR; if((yych = *YYCURSOR) == '/') goto yy103; goto yy96; yy96: -#line 193 "scanner.re" +#line 195 "scanner.re" { goto comment; } #line 522 "scanner.cc" yy97: yych = *++YYCURSOR; @@ -603,7 +605,7 @@ yy97: yych = *++YYCURSOR; yy98: ++YYCURSOR; goto yy99; yy99: -#line 189 "scanner.re" +#line 191 "scanner.re" { if(cursor == eof) RETURN(0); tok = pos = cursor; cline++; goto comment; @@ -614,21 +616,21 @@ yy100: yych = *++YYCURSOR; yy101: ++YYCURSOR; goto yy102; yy102: -#line 187 "scanner.re" +#line 189 "scanner.re" { ++depth; goto comment; } #line 543 "scanner.cc" yy103: ++YYCURSOR; goto yy104; yy104: -#line 183 "scanner.re" +#line 185 "scanner.re" { if(--depth == 0) goto scan; else goto comment; } #line 552 "scanner.cc" } -#line 194 "scanner.re" +#line 196 "scanner.re" } @@ -637,3 +639,6 @@ void Scanner::fatal(char *msg){ << msg << std::endl; exit(1); } + +} // end namespace re2c + diff --git a/code.cc b/code.cc index e708d696..13198019 100644 --- a/code.cc +++ b/code.cc @@ -9,6 +9,9 @@ #include "dfa.h" #include "parser.h" +namespace re2c +{ + // there must be at least one span in list; all spans must cover // same range @@ -1133,3 +1136,6 @@ void DFA::emit(std::ostream &o) delete [] saves; delete [] rules; } + +} // end namespace re2c + diff --git a/configure.in b/configure.in index 207ba0c5..ac42ce40 100644 --- a/configure.in +++ b/configure.in @@ -41,19 +41,6 @@ AC_CHECK_SIZEOF([short]) AC_CHECK_SIZEOF([int]) AC_CHECK_SIZEOF([long]) -AC_CHECK_TYPE([uchar], [ - AC_DEFINE([HAVE_UCHAR], [1], [Define to 1 if you have uchar type definition]) -]) -AC_CHECK_TYPE([ushort], [ - AC_DEFINE([HAVE_USHORT], [1], [Define to 1 if you have ushort type definition]) -]) -AC_CHECK_TYPE([uint], [ - AC_DEFINE([HAVE_UINT], [1], [Define to 1 if you have uint type definition]) -]) -AC_CHECK_TYPE([ulong], [ - AC_DEFINE([HAVE_ULONG], [1], [Define to 1 if you have ulong type definition]) -]) - AC_CONFIG_FILES([\ Makefile \ README \ diff --git a/dfa.cc b/dfa.cc index 27cdb05d..77b14572 100644 --- a/dfa.cc +++ b/dfa.cc @@ -5,6 +5,9 @@ #include "substr.h" #include "dfa.h" +namespace re2c +{ + inline char octCh(uint c) { return '0' + c % 8; @@ -355,3 +358,6 @@ unmarkAll: return s; } + +} // end namespace re2c + diff --git a/dfa.h b/dfa.h index 1d3ffc73..032d80c8 100644 --- a/dfa.h +++ b/dfa.h @@ -5,6 +5,9 @@ #include #include "re.h" +namespace re2c +{ + extern void prtCh(std::ostream&, uchar); extern void prtChOrHex(std::ostream&, uchar); extern void printSpan(std::ostream&, uint, uint); @@ -223,4 +226,6 @@ inline std::ostream& operator<<(std::ostream &o, const DFA *dfa) return o << *dfa; } +} // end namespace re2c + #endif diff --git a/globals.h b/globals.h index ee1703ea..8a59104d 100644 --- a/globals.h +++ b/globals.h @@ -4,6 +4,9 @@ #include "basics.h" +namespace re2c +{ + extern char *fileName; extern char *outputFileName; extern bool sFlag; @@ -15,4 +18,6 @@ extern uchar ebc2asc[256]; extern uchar *xlat, *talx; +} // end namespace re2c + #endif diff --git a/ins.h b/ins.h index 4fec59b9..5700121b 100644 --- a/ins.h +++ b/ins.h @@ -4,6 +4,9 @@ #include "basics.h" +namespace re2c +{ + const uint nChars = 256; typedef uchar Char; @@ -49,4 +52,6 @@ inline void unmark(Ins *i) i->i.marked = false; } +} // end namespace re2c + #endif diff --git a/main.cc b/main.cc index e57aa740..f64bf19f 100644 --- a/main.cc +++ b/main.cc @@ -13,6 +13,9 @@ #include "dfa.h" #include "mbo_getopt.h" +namespace re2c +{ + char *fileName = 0; char *outputFileName = 0; bool sFlag = false; @@ -60,6 +63,10 @@ static void usage() "-v --version Show version information.\n"; } +} // end namespace re2c + +using namespace re2c; + int main(int argc, char *argv[]) { int c; @@ -168,3 +175,4 @@ int main(int argc, char *argv[]) return 0; } + diff --git a/mbo_getopt.cc b/mbo_getopt.cc index 870b9fff..385b10c3 100755 --- a/mbo_getopt.cc +++ b/mbo_getopt.cc @@ -13,6 +13,8 @@ #define OPTERRNF (2) #define OPTERRARG (3) +namespace re2c +{ static int mbo_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) { @@ -194,3 +196,6 @@ int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct opts[], char ** assert(0); return (0); /* never reached */ } + +} // end namespace re2c + diff --git a/mbo_getopt.h b/mbo_getopt.h index acbc15ae..96cf5669 100755 --- a/mbo_getopt.h +++ b/mbo_getopt.h @@ -8,6 +8,12 @@ * If short_open is '-' this is the last option. */ +#ifndef RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ +#define RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ + +namespace re2c +{ + typedef struct _mbo_opt_struct { const char opt_char; @@ -18,3 +24,8 @@ typedef struct _mbo_opt_struct mbo_opt_struct; int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct opts[], char **optarg, int *optind, int show_err); + +} // end namespace re2c + +#endif + diff --git a/parser.h b/parser.h index 82238960..ceb94656 100644 --- a/parser.h +++ b/parser.h @@ -6,6 +6,9 @@ #include "re.h" #include +namespace re2c +{ + class Symbol { @@ -23,4 +26,6 @@ public: void line_source(unsigned int, std::ostream&); void parse(std::istream&, std::ostream&); +} // end namespace re2c + #endif diff --git a/parser.tab.h b/parser.tab.h index f07debe7..1932bb74 100644 --- a/parser.tab.h +++ b/parser.tab.h @@ -3,9 +3,9 @@ #ifndef YYSTYPE typedef union { - Symbol *symbol; - RegExp *regexp; - Token *token; + re2c::Symbol *symbol; + re2c::RegExp *regexp; + re2c::Token *token; char op; } yystype; # define YYSTYPE yystype diff --git a/parser.y b/parser.y index 8c9bbc60..31d06b33 100644 --- a/parser.y +++ b/parser.y @@ -13,6 +13,9 @@ #include "globals.h" #include "parser.h" +#include "basics.h" + +using namespace re2c; extern "C" { @@ -21,7 +24,7 @@ int yylex(); void yyerror(char*); } -static uint accept; +static re2c::uint accept; static RegExp *spec; static Scanner *in; @@ -51,11 +54,11 @@ static char* strdup(const char* s) %start spec %union { - Symbol *symbol; - RegExp *regexp; - Token *token; + re2c::Symbol *symbol; + re2c::RegExp *regexp; + re2c::Token *token; char op; - ExtOp extop; + re2c::ExtOp extop; }; %token CLOSESIZE CLOSE ID CODE RANGE STRING @@ -167,6 +170,9 @@ int yylex(){ } } // end extern "C" +namespace re2c +{ + void line_source(unsigned int line, std::ostream& o) { char * fnamebuf; @@ -209,3 +215,6 @@ void parse(std::istream& i, std::ostream &o){ line_source(in->line(), o); } } + +} // end namespace re2c + diff --git a/re.h b/re.h index c19942d4..ea52e644 100644 --- a/re.h +++ b/re.h @@ -6,6 +6,9 @@ #include "token.h" #include "ins.h" +namespace re2c +{ + typedef struct extop { char op; @@ -293,4 +296,6 @@ extern RegExp *strToRE(SubStr); extern RegExp *ranToRE(SubStr); extern RegExp *strToCaseInsensitiveRE(SubStr s); +} // end namespace re2c + #endif diff --git a/scanner.h b/scanner.h index 55a37a18..d252e2cf 100644 --- a/scanner.h +++ b/scanner.h @@ -5,6 +5,9 @@ #include #include "token.h" +namespace re2c +{ + class Scanner { @@ -37,4 +40,6 @@ inline uint Scanner::line() return cline; } +} // end namespace re2c + #endif diff --git a/scanner.re b/scanner.re index 88a9bb8a..1ab6433b 100644 --- a/scanner.re +++ b/scanner.re @@ -22,6 +22,8 @@ extern YYSTYPE yylval; #define RETURN(i) {cur = cursor; return i;} +namespace re2c +{ Scanner::Scanner(std::istream& i) : in(i), bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL), @@ -199,3 +201,6 @@ void Scanner::fatal(char *msg){ << msg << std::endl; exit(1); } + +} // end namespace re2c + diff --git a/substr.cc b/substr.cc index b7f8f72f..5fdaeacd 100644 --- a/substr.cc +++ b/substr.cc @@ -3,6 +3,9 @@ #include "substr.h" #include "globals.h" +namespace re2c +{ + void SubStr::out(std::ostream& o) const { o.write(str, len); @@ -42,3 +45,6 @@ Str::~Str() str = (char*) - 1; len = (uint) - 1; } + +} // end namespace re2c + diff --git a/substr.h b/substr.h index 476d39a8..c7ff3b93 100644 --- a/substr.h +++ b/substr.h @@ -5,6 +5,9 @@ #include #include "basics.h" +namespace re2c +{ + class SubStr { @@ -53,4 +56,6 @@ inline SubStr::SubStr(const SubStr &s) : str(s.str), len(s.len) { } +} // end namespace re2c + #endif diff --git a/token.h b/token.h index debb1714..330e541a 100644 --- a/token.h +++ b/token.h @@ -4,6 +4,9 @@ #include "substr.h" +namespace re2c +{ + class Token { @@ -20,4 +23,6 @@ inline Token::Token(SubStr t, uint l) : text(t), line(l) ; } +} // end namespace re2c + #endif diff --git a/translate.cc b/translate.cc index 9331a485..c8b73a42 100644 --- a/translate.cc +++ b/translate.cc @@ -1,6 +1,9 @@ /* $Id$ */ #include "globals.h" +namespace re2c +{ + uchar asc2asc[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, @@ -63,3 +66,6 @@ uchar ebc2asc[256] = 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f }; + +} // end namespace re2c +