re2c: Fix yyaccept warnings.

svn path=/trunk/yasm/; revision=1274
0.5.0rc2
Peter Johnson 20 years ago
parent 1702e9d833
commit ccec93a51e
  1. 102
      tools/re2c/code.c
  2. 3
      tools/re2c/globals.h
  3. 9
      tools/re2c/main.c
  4. 962
      tools/re2c/scanner.c
  5. 17
      tools/re2c/scanner.re

@ -215,12 +215,26 @@ static void indent(FILE *o, unsigned int i){
static void need(FILE *o, unsigned int n, int *readCh)
{
unsigned int fillIndex;
int hasFillIndex = (0<=vFillIndexes);
if (hasFillIndex) {
fillIndex = vFillIndexes++;
fprintf(o, "\tYYSETSTATE(%u);\n", fillIndex);
++oline;
}
if(n == 1) {
fputs("\tif(YYLIMIT == YYCURSOR) YYFILL(1);\n", o); oline++;
} else {
fprintf(o, "\tif((YYLIMIT - YYCURSOR) < %u) YYFILL(%u);\n", n, n);
oline++;
}
if (hasFillIndex) {
fprintf(o, "yyFillLabel%u:\n", fillIndex);
++oline;
}
fputs("\tyych = *YYCURSOR;\n", o); oline++;
*readCh = 0;
}
@ -262,7 +276,10 @@ Action_emit(Action *a, FILE *o, int *readCh)
}
break;
case SAVEMATCHACT:
fprintf(o, "\tyyaccept = %u;\n", a->d.selector); oline++;
if (bUsedYYAccept) {
fprintf(o, "\tyyaccept = %u;\n", a->d.selector);
oline++;
}
if(a->state->link){
fputs("\tYYMARKER = ++YYCURSOR;\n", o); oline++;
need(o, a->state->depth, readCh);
@ -278,6 +295,7 @@ Action_emit(Action *a, FILE *o, int *readCh)
if(a->d.Accept.saves[i] != ~0u){
if(first){
first = 0;
bUsedYYAccept = 1;
fputs("\tYYCURSOR = YYMARKER;\n", o);
fputs("\tswitch(yyaccept){\n", o); oline+=2;
}
@ -614,8 +632,11 @@ static unsigned int maxDist(State *s){
State *t = s->go.span[i].to;
if(t){
unsigned int m = 1;
if(!t->link)
m += maxDist(t);
if(!t->link) {
if (t->depth == -1)
t->depth = maxDist(t);
m += t->depth;
}
if(m > mm)
mm = m;
}
@ -677,7 +698,7 @@ void DFA_split(DFA *d, State *s){
void DFA_emit(DFA *d, FILE *o){
static unsigned int label = 0;
State *s;
unsigned int i;
unsigned int i, bitmap_brace = 0;
unsigned int nRules = 0;
unsigned int nSaves = 0;
unsigned int *saves;
@ -686,14 +707,21 @@ void DFA_emit(DFA *d, FILE *o){
State *accept = NULL;
Span *span;
FILE *tmpo;
int hasFillLabels;
int maxFillIndexes, orgVFillIndexes;
unsigned int start_label;
DFA_findSCCs(d);
d->head->link = d->head;
d->head->depth = maxDist(d->head);
for(s = d->head; s; s = s->next)
maxFill = 1;
for(s = d->head; s; s = s->next) {
s->depth = maxDist(s);
if (maxFill < s->depth)
maxFill = s->depth;
if(s->rule && s->rule->d.RuleOp.accept >= nRules)
nRules = s->rule->d.RuleOp.accept + 1;
}
saves = malloc(sizeof(unsigned int)*nRules);
memset(saves, ~0, (nRules)*sizeof(unsigned int));
@ -783,38 +811,84 @@ void DFA_emit(DFA *d, FILE *o){
free(d->head->action);
oline++;
fprintf(o, "\n#line %u \"%s\"\n", ++oline, outputFileName);
if(bFlag) {
fputs("{\n", o);
oline++;
bitmap_brace = 1;
BitMap_gen(o, d->lbChar, d->ubChar);
}
fputs("{\n\tYYCTYPE yych;\n\tunsigned int yyaccept;\n", o); oline+=3;
bUsedYYAccept = 0;
if(bFlag)
BitMap_gen(o, d->lbChar, d->ubChar);
start_label = label;
fprintf(o, "\tgoto yy%u;\n", label); oline++;
useLabel(label);
Action_new_Enter(d->head, label++);
for(s = d->head; s; s = s->next)
s->label = label++;
nOrgOline = oline;
maxFillIndexes = vFillIndexes;
orgVFillIndexes = vFillIndexes;
tmpo = fopen("re2c.tmp", "wt");
for(s = d->head; s; s = s->next){
int readCh = 0;
State_emit(s, tmpo, &readCh);
Go_genGoto(&s->go, o, s, s->next, &readCh);
Go_genGoto(&s->go, tmpo, s, s->next, &readCh);
}
fclose(tmpo);
unlink("re2c.tmp");
maxFillIndexes = vFillIndexes;
vFillIndexes = orgVFillIndexes;
oline = nOrgOline;
hasFillLabels = (0<=vFillIndexes);
oline++;
fprintf(o, "\n#line %u \"%s\"\n", ++oline, outputFileName);
if (!hasFillLabels) {
fputs("{\n\tYYCTYPE yych;\n", o);
oline += 2;
if (bUsedYYAccept) {
fputs("\tunsigned int yyaccept;\n", o);
oline++;
}
} else {
fputs("{\n\n", o);
oline += 2;
}
if (!hasFillLabels) {
fprintf(o, "\tgoto yy%u;\n", start_label);
oline++;
useLabel(label);
} else {
unsigned int i;
fputs("\tswitch(YYGETSTATE()) {\n", o);
fputs("\t\tcase -1: goto yy0;\n", o);
for (i=0; i<maxFillIndexes; ++i)
fprintf(o, "\t\tcase %u: goto yyFillLabel%u;\n", i, i);
fputs("\t\tdefault: /* abort() */;\n", o);
fputs("\t}\n", o);
fputs("yyNext:\n", o);
oline += maxFillIndexes;
oline += 5;
}
for(s = d->head; s; s = s->next){
int readCh = 0;
State_emit(s, o, &readCh);
Go_genGoto(&s->go, o, s, s->next, &readCh);
}
fputs("}\n", o); oline++;
if (bitmap_brace) {
fputs("}\n", o);
oline++;
}
BitMap_first = NULL;

@ -7,7 +7,10 @@ extern const char *fileName;
extern const char *outputFileName;
extern int sFlag;
extern int bFlag;
extern int bUsedYYAccept;
extern unsigned int oline;
extern unsigned int maxFill;
extern int vFillIndexes;
extern unsigned char *vUsedLabels;
extern unsigned int vUsedLabelAlloc;

@ -10,7 +10,10 @@ const char *fileName = 0;
const char *outputFileName = 0;
int sFlag = 0;
int bFlag = 0;
int bUsedYYAccept = 0;
unsigned int oline = 1;
unsigned int maxFill = 1;
int vFillIndexes = -1;
unsigned char *vUsedLabels;
unsigned int vUsedLabelAlloc = 1000;
@ -23,6 +26,7 @@ static const mbo_opt_struct OPTIONS[] = {
{'e', 0, "ecb"},
{'h', 0, "help"},
{'s', 0, "nested-ifs"},
{'f', 0, "storable-state"},
{'o', 1, "output"},
{'v', 0, "version"},
{'-', 0, NULL} /* end of args */
@ -46,6 +50,8 @@ static void usage()
"-s --nested-ifs Generate nested ifs for some switches. Many compilers\n"
" need this assist to generate better code.\n"
"\n"
"-f --storable-state Generate a scanner with support for storable state\n"
"\n"
"-o --output=output Specify the output file instead of stdout\n"
"\n"
"-v --version Show version information.\n"
@ -77,6 +83,9 @@ int main(int argc, char *argv[])
case 's':
sFlag = 1;
break;
case 'f':
vFillIndexes = 0;
break;
case 'o':
outputFileName = opt_arg;
break;

File diff suppressed because it is too large Load Diff

@ -4,6 +4,7 @@
#include "tools/re2c/parse.h"
#include "tools/re2c/globals.h"
#include "re2c-parser.h"
#include "globals.h"
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
@ -81,6 +82,7 @@ int
Scanner_echo(Scanner *s, FILE *out)
{
unsigned char *cursor = s->cur;
int ignore_eoc = 0;
/* Catch EOF */
if (s->eof && cursor == s->eof)
@ -92,6 +94,21 @@ echo:
"/*!re2c" { fwrite(s->tok, 1, &cursor[-7] - s->tok, out);
s->tok = cursor;
RETURN(1); }
"/*!max:re2c" {
fprintf(out, "#define YYMAXFILL %u\n", maxFill);
s->tok = s->pos = cursor;
ignore_eoc = 1;
goto echo;
}
"*" "/" {
if (ignore_eoc) {
ignore_eoc = 0;
} else {
fwrite(s->tok, 1, cursor - s->tok, out);
}
s->tok = s->pos = cursor;
goto echo;
}
"\n" { fwrite(s->tok, 1, cursor - s->tok, out);
s->tok = s->pos = cursor; s->cline++; oline++;
goto echo; }

Loading…
Cancel
Save