diff --git a/tools/re2c/actions.c b/tools/re2c/actions.c index 9160e478..890422d5 100644 --- a/tools/re2c/actions.c +++ b/tools/re2c/actions.c @@ -310,7 +310,7 @@ Range_out(FILE *o, const Range *r) Range_out(o, r->next); } -Range *doUnion(Range *r1, Range *r2){ +static Range *doUnion(Range *r1, Range *r2){ Range *r, **rP = &r; for(;;){ Range *s; @@ -357,7 +357,7 @@ Range *doUnion(Range *r1, Range *r2){ return r; } -Range *doDiff(Range *r1, Range *r2){ +static Range *doDiff(Range *r1, Range *r2){ Range *r, *s, **rP = &r; for(; r1; r1 = r1->next){ uint lb = r1->lb; @@ -397,7 +397,7 @@ RegExp *mkDiff(RegExp *e1, RegExp *e2){ return r? RegExp_new_MatchOp(r) : RegExp_new_NullOp(); } -RegExp *doAlt(RegExp *e1, RegExp *e2){ +static RegExp *doAlt(RegExp *e1, RegExp *e2){ if(!e1) return e2; if(!e2) @@ -423,7 +423,7 @@ RegExp *mkAlt(RegExp *e1, RegExp *e2){ return doAlt(merge(m1, m2), doAlt(e1, e2)); } -uchar unescape(SubStr *s){ +static uchar unescape(SubStr *s){ uchar c; uchar v; s->len--; @@ -456,7 +456,7 @@ uchar unescape(SubStr *s){ } } -Range *getRange(SubStr *s){ +static Range *getRange(SubStr *s){ uchar lb = unescape(s), ub; if(s->len < 2 || *s->str != '-'){ ub = lb; @@ -471,7 +471,7 @@ Range *getRange(SubStr *s){ return Range_new(lb, ub+1); } -RegExp *matchChar(uint c){ +static RegExp *matchChar(uint c){ return RegExp_new_MatchOp(Range_new(c, c+1)); } @@ -510,9 +510,7 @@ RegExp_new_RuleOp(RegExp *e, RegExp *c, Token *t, uint a) return r; } -extern void printSpan(FILE *, uint, uint); - -void optimize(Ins *i){ +static void optimize(Ins *i){ while(!isMarked(i)){ mark(i); if(i->i.tag == CHAR){ diff --git a/tools/re2c/code.c b/tools/re2c/code.c index c3b5b2d4..4dbda04a 100644 --- a/tools/re2c/code.c +++ b/tools/re2c/code.c @@ -46,7 +46,7 @@ void Go_unmap(Go *g, Go *base, State *x){ g->nSpans = s - g->span; } -void doGen(Go *g, State *s, uchar *bm, uchar m){ +static void doGen(Go *g, State *s, uchar *bm, uchar m){ Span *b = g->span, *e = &b[g->nSpans]; uint lb = 0; for(; b < e; ++b){ @@ -55,8 +55,8 @@ void doGen(Go *g, State *s, uchar *bm, uchar m){ lb = b->ub; } } - -void prt(FILE *o, Go *g, State *s){ +#if 0 +static void prt(FILE *o, Go *g, State *s){ Span *b = g->span, *e = &b[g->nSpans]; uint lb = 0; for(; b < e; ++b){ @@ -65,8 +65,8 @@ void prt(FILE *o, Go *g, State *s){ lb = b->ub; } } - -int matches(Go *g1, State *s1, Go *g2, State *s2){ +#endif +static int matches(Go *g1, State *s1, Go *g2, State *s2){ Span *b1 = g1->span, *e1 = &b1[g1->nSpans]; uint lb1 = 0; Span *b2 = g2->span, *e2 = &b2[g2->nSpans]; @@ -165,17 +165,17 @@ void BitMap_stats(void){ } #endif -void genGoTo(FILE *o, State *to){ +static void genGoTo(FILE *o, State *to){ fprintf(o, "\tgoto yy%u;\n", to->label); } -void genIf(FILE *o, const char *cmp, uint v){ +static void genIf(FILE *o, const char *cmp, uint v){ fprintf(o, "\tif(yych %s '", cmp); prtCh(o, v); fputs("')", o); } -void indent(FILE *o, uint i){ +static void indent(FILE *o, uint i){ while(i-- > 0) fputc('\t', o); } @@ -263,7 +263,7 @@ Action_new_Accept(State *x, uint n, uint *s, State **r) return a; } -void doLinear(FILE *o, uint i, Span *s, uint n, State *next){ +static void doLinear(FILE *o, uint i, Span *s, uint n, State *next){ for(;;){ State *bg = s[0].to; while(n >= 3 && s[2].to == bg && (s[1].ub - s[0].ub) == 1){ @@ -295,7 +295,7 @@ Go_genLinear(Go *g, FILE *o, State *next){ doLinear(o, 0, g->span, g->nSpans, next); } -void genCases(FILE *o, uint lb, Span *s){ +static void genCases(FILE *o, uint lb, Span *s){ if(lb < s->ub){ for(;;){ fputs("\tcase '", o); prtCh(o, lb); fputs("':", o); @@ -346,7 +346,7 @@ Go_genSwitch(Go *g, FILE *o, State *next){ } } -void doBinary(FILE *o, uint i, Span *s, uint n, State *next){ +static void doBinary(FILE *o, uint i, Span *s, uint n, State *next){ if(n <= 4){ doLinear(o, i, s, n, next); } else { @@ -524,7 +524,7 @@ static void SCC_traverse(SCC *s, State *x){ } while(*s->top != x); } -uint maxDist(State *s){ +static uint maxDist(State *s){ uint mm = 0, i; for(i = 0; i < s->go.nSpans; ++i){ State *t = s->go.span[i].to; @@ -539,7 +539,7 @@ uint maxDist(State *s){ return mm; } -void calcDepth(State *head){ +static void calcDepth(State *head){ State *t, *s; for(s = head; s; s = s->next){ if(s->link == s){ diff --git a/tools/re2c/dfa.c b/tools/re2c/dfa.c index f1ffb3d7..057ef661 100644 --- a/tools/re2c/dfa.c +++ b/tools/re2c/dfa.c @@ -146,11 +146,11 @@ DFA_new(Ins *ins, uint ni, uint lb, uint ub, Char *rep) s->rule = NULL; for(iP = s->kernel; (i = *iP); ++iP){ if(i->i.tag == CHAR){ - Ins *j; - for(j = i + 1; j < (Ins*) i->i.link; ++j){ - if(!(j->c.link = goTo[j->c.value - lb].to)) - goTo[nGoTos++].ch = j->c.value; - goTo[j->c.value - lb].to = j; + Ins *j2; + for(j2 = i + 1; j2 < (Ins*) i->i.link; ++j2){ + if(!(j2->c.link = goTo[j2->c.value - lb].to)) + goTo[nGoTos++].ch = j2->c.value; + goTo[j2->c.value - lb].to = j2; } } else if(i->i.tag == TERM){ if(!s->rule || ((RegExp *)i->i.link)->d.RuleOp.accept < s->rule->d.RuleOp.accept) diff --git a/tools/re2c/globals.h b/tools/re2c/globals.h index f42735cf..a9e5eb73 100644 --- a/tools/re2c/globals.h +++ b/tools/re2c/globals.h @@ -3,7 +3,7 @@ #include "tools/re2c/basics.h" -extern char *fileName; +extern const char *fileName; extern int sFlag; extern int bFlag; diff --git a/tools/re2c/re2c-parser.y b/tools/re2c/re2c-parser.y index c41170f5..d2d5406e 100644 --- a/tools/re2c/re2c-parser.y +++ b/tools/re2c/re2c-parser.y @@ -7,9 +7,10 @@ #include #include "tools/re2c/globals.h" #include "tools/re2c/parse.h" -int yyparse(); -int yylex(); -void yyerror(char*); +int yylex(void); +void yyerror(const char*); + +static char *mystrdup(const char *str); static uint accept; static RegExp *spec; @@ -120,7 +121,7 @@ primary : ID %% -void yyerror(char* s){ +void yyerror(const char* s){ Scanner_fatal(in, s); } @@ -128,7 +129,7 @@ int yylex(){ return Scanner_scan(in); } -char * +static char * mystrdup(const char *str) { size_t len; diff --git a/tools/re2c/re2c.c b/tools/re2c/re2c.c index 0eece4a7..412e59e3 100644 --- a/tools/re2c/re2c.c +++ b/tools/re2c/re2c.c @@ -7,7 +7,7 @@ #include "tools/re2c/parse.h" #include "tools/re2c/dfa.h" -char *fileName; +const char *fileName; int sFlag = 0; int bFlag = 0; diff --git a/tools/re2c/scanner.c b/tools/re2c/scanner.c index aeb205f8..4f520d6e 100644 --- a/tools/re2c/scanner.c +++ b/tools/re2c/scanner.c @@ -1,6 +1,6 @@ -/* Generated by re2c 0.9.1-C on Fri Aug 9 17:42:28 2002 +/* Generated by re2c 0.9.1-C on Thu Aug 15 22:11:10 2002 */ -#line 1 "scanner.re" +#line 1 "tools/re2c/scanner.re" #include #include @@ -9,8 +9,6 @@ #include "tools/re2c/parse.h" #include "re2c-parser.h" -extern YYSTYPE yylval; - #define BSIZE 8192 #define YYCTYPE uchar @@ -67,7 +65,7 @@ fill(Scanner *s, uchar *cursor) return cursor; } -#line 76 +#line 74 int @@ -90,11 +88,11 @@ yy0: yych = *(YYMARKER = ++YYCURSOR); if(yych == '*') goto yy7; yy3: -#line 92 +#line 90 { goto echo; } yy4: yych = *++YYCURSOR; -#line 88 +#line 86 { if(cursor == s->eof) RETURN(0); fwrite(s->tok, 1, cursor - s->tok, out); s->tok = s->pos = cursor; s->cline++; @@ -117,12 +115,12 @@ yy9: yych = *++YYCURSOR; if(yych != 'c') goto yy8; yych = *++YYCURSOR; -#line 85 +#line 83 { fwrite(s->tok, 1, &cursor[-7] - s->tok, out); s->tok = cursor; RETURN(1); } } -#line 93 +#line 91 } @@ -192,32 +190,32 @@ yy15: } yy17: yych = *++YYCURSOR; -#line 108 +#line 106 { depth = 1; goto code; } yy19: yych = *++YYCURSOR; if(yych == '*') goto yy54; yy20: -#line 127 +#line 125 { RETURN(*s->tok); } yy21: yych = *++YYCURSOR; if(yych == '/') goto yy52; yy22: -#line 129 +#line 127 { yylval.op = *s->tok; RETURN(CLOSE); } yy23: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if(yych != '\n') goto yy48; yy24: -#line 120 +#line 118 { Scanner_fatal(s, "bad string"); } yy25: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); if(yych != '\n') goto yy42; yy26: -#line 125 +#line 123 { Scanner_fatal(s, "bad character constant"); } yy27: yych = *++YYCURSOR; goto yy20; @@ -226,7 +224,7 @@ yy28: yych = *++YYCURSOR; yy29: yych = *++YYCURSOR; goto yy40; yy30: -#line 132 +#line 130 { SubStr substr; s->cur = cursor; substr = Scanner_token(s); @@ -235,18 +233,18 @@ yy30: yy31: yych = *++YYCURSOR; goto yy38; yy32: -#line 138 +#line 136 { goto scan; } yy33: yych = *++YYCURSOR; -#line 140 +#line 138 { if(cursor == s->eof) RETURN(0); s->pos = cursor; s->cline++; goto scan; } yy35: yych = *++YYCURSOR; -#line 145 +#line 143 { fprintf(stderr, "unexpected character: '%c'\n", *s->tok); goto scan; } @@ -291,7 +289,7 @@ yy44: ++YYCURSOR; goto yy41; yy45: yych = *++YYCURSOR; -#line 122 +#line 120 { s->cur = cursor; yylval.regexp = ranToRE(Scanner_token(s)); return RANGE; } @@ -312,22 +310,22 @@ yy48: if(yych <= '!'){ goto yy47; yy50: yych = *++YYCURSOR; -#line 117 +#line 115 { s->cur = cursor; yylval.regexp = strToRE(Scanner_token(s)); return STRING; } yy52: yych = *++YYCURSOR; -#line 114 +#line 112 { s->tok = cursor; RETURN(0); } yy54: yych = *++YYCURSOR; -#line 111 +#line 109 { depth = 1; goto comment; } } -#line 148 +#line 146 code: @@ -358,7 +356,7 @@ yy56: } yych = *++YYCURSOR; -#line 152 +#line 150 { if(--depth == 0){ s->cur = cursor; yylval.token = Token_new(Scanner_token(s), s->tline); @@ -367,19 +365,19 @@ yy56: goto code; } yy60: yych = *++YYCURSOR; -#line 158 +#line 156 { ++depth; goto code; } yy62: yych = *++YYCURSOR; -#line 160 +#line 158 { if(cursor == s->eof) Scanner_fatal(s, "missing '}'"); s->pos = cursor; s->cline++; goto code; } yy64: yych = *++YYCURSOR; yy65: -#line 164 +#line 162 { goto code; } yy66: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); @@ -424,7 +422,7 @@ yy73: if(yych <= '!'){ if(yych == '\n') goto yy70; goto yy72; } -#line 165 +#line 163 comment: @@ -447,14 +445,14 @@ yy75: yy77: yych = *++YYCURSOR; if(yych == '/') goto yy85; yy78: -#line 179 +#line 177 { goto comment; } yy79: yych = *++YYCURSOR; if(yych == '*') goto yy83; goto yy78; yy80: yych = *++YYCURSOR; -#line 175 +#line 173 { if(cursor == s->eof) RETURN(0); s->tok = s->pos = cursor; s->cline++; goto comment; @@ -463,23 +461,23 @@ yy82: yych = *++YYCURSOR; goto yy78; yy83: yych = *++YYCURSOR; -#line 173 +#line 171 { ++depth; goto comment; } yy85: yych = *++YYCURSOR; -#line 169 +#line 167 { if(--depth == 0) goto scan; else goto comment; } } -#line 180 +#line 178 } void -Scanner_fatal(Scanner *s, char *msg) +Scanner_fatal(Scanner *s, const char *msg) { fprintf(stderr, "line %d, column %d: %s\n", s->tline, s->tchar + 1, msg); exit(1); diff --git a/tools/re2c/scanner.h b/tools/re2c/scanner.h index a76c4dd4..2c2d0200 100644 --- a/tools/re2c/scanner.h +++ b/tools/re2c/scanner.h @@ -15,7 +15,7 @@ static inline Scanner *Scanner_new(FILE *); int Scanner_echo(Scanner*, FILE *); int Scanner_scan(Scanner*); -void Scanner_fatal(Scanner*, char*); +void Scanner_fatal(Scanner*, const char*); static inline SubStr Scanner_token(Scanner*); static inline uint Scanner_line(Scanner*); diff --git a/tools/re2c/scanner.re b/tools/re2c/scanner.re index a058fe76..4b94ed47 100644 --- a/tools/re2c/scanner.re +++ b/tools/re2c/scanner.re @@ -6,8 +6,6 @@ #include "tools/re2c/parse.h" #include "re2c-parser.h" -extern YYSTYPE yylval; - #define BSIZE 8192 #define YYCTYPE uchar @@ -181,7 +179,7 @@ comment: } void -Scanner_fatal(Scanner *s, char *msg) +Scanner_fatal(Scanner *s, const char *msg) { fprintf(stderr, "line %d, column %d: %s\n", s->tline, s->tchar + 1, msg); exit(1);