From 4b5828d4be02ffbd7ff84a4585bfacdf2b3df6fb Mon Sep 17 00:00:00 2001 From: helly Date: Fri, 21 Mar 2008 21:23:07 +0000 Subject: [PATCH] - Added re2c:yyfill:check inplace configuration. - Added re2c:define:YYSETSTATE:naked inplace configuration. --- re2c/CHANGELOG | 2 ++ re2c/code.cc | 19 ++++++++++++++-- re2c/globals.h | 2 ++ re2c/htdocs/index.html | 2 ++ re2c/htdocs/manual.html | 5 +++++ re2c/main.cc | 2 ++ re2c/re2c.1.in | 7 ++++++ re2c/test/config4g.ifs.c | 47 +++++++++++++++++++++++++++++++++++++++ re2c/test/config4g.ifs.re | 31 ++++++++++++++++++++++++++ 9 files changed, 115 insertions(+), 2 deletions(-) create mode 100755 re2c/test/config4g.ifs.c create mode 100755 re2c/test/config4g.ifs.re diff --git a/re2c/CHANGELOG b/re2c/CHANGELOG index 6130bbd4..9d074004 100644 --- a/re2c/CHANGELOG +++ b/re2c/CHANGELOG @@ -1,5 +1,7 @@ Version 0.13.4 (2008-??-??) --------------------------- +- Added re2c:yyfill:check inplace configuration. +- Added re2c:define:YYSETSTATE:naked inplace configuration. Version 0.13.3 (2008-03-14) --------------------------- diff --git a/re2c/code.cc b/re2c/code.cc index 326b60e4..510fcc4a 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -420,14 +420,21 @@ static void need(std::ostream &o, uint ind, uint n, bool & readCh, bool bSetMark if (bUseYYFill && n > 0) { + o << indent(ind); if (n == 1) { - o << indent(ind) << "if (" << mapCodeName["YYLIMIT"] << " == " << mapCodeName["YYCURSOR"] << ") "; + if (bUseYYFillCheck) + { + o << "if (" << mapCodeName["YYLIMIT"] << " == " << mapCodeName["YYCURSOR"] << ") "; + } genYYFill(o, ind, n); } else { - o << indent(ind) << "if ((" << mapCodeName["YYLIMIT"] << " - " << mapCodeName["YYCURSOR"] << ") < " << n << ") "; + if (bUseYYFillCheck) + { + o << "if ((" << mapCodeName["YYLIMIT"] << " - " << mapCodeName["YYCURSOR"] << ") < " << n << ") "; + } genYYFill(o, ind, n); } } @@ -2115,6 +2122,10 @@ void Scanner::config(const Str& cfg, int num) { bUseYYFillParam = num != 0; } + else if (cfg.to_string() == "yyfill:check") + { + bUseYYFillCheck = num != 0; + } else if (cfg.to_string() == "cgoto:threshold") { cGotoThreshold = num; @@ -2148,6 +2159,10 @@ void Scanner::config(const Str& cfg, int num) { bUseYYGetStateNaked = num != 0; } + else if (cfg.to_string() == "define:YYSETSTATE:naked") + { + bUseYYSetStateNaked = num != 0; + } else { std::string msg = "unrecognized configuration name '"; diff --git a/re2c/globals.h b/re2c/globals.h index f5c887bb..d94ec071 100644 --- a/re2c/globals.h +++ b/re2c/globals.h @@ -69,10 +69,12 @@ extern bool bUseStateAbort; extern bool bUseStateNext; extern bool bUseYYFill; extern bool bUseYYFillParam; +extern bool bUseYYFillCheck; extern bool bUseYYFillNaked; extern bool bUseYYSetConditionParam; extern bool bUseYYGetConditionNaked; extern bool bUseYYSetStateParam; +extern bool bUseYYSetStateNaked; extern bool bUseYYGetStateNaked; extern bool bWroteGetState; extern bool bWroteCondCheck; diff --git a/re2c/htdocs/index.html b/re2c/htdocs/index.html index bd1caa72..8d913f3e 100755 --- a/re2c/htdocs/index.html +++ b/re2c/htdocs/index.html @@ -81,6 +81,8 @@ fixes which were incorporated.

Changelog

2008-??-??: 0.13.4

+
  • Added re2c:yyfill:check inplace configuration.
  • +
  • Added re2c:define:YYSETSTATE:naked inplace configuration.
  • 2008-03-14: 0.13.3

    diff --git a/re2c/htdocs/manual.html b/re2c/htdocs/manual.html index c2ff8331..1c6834cd 100755 --- a/re2c/htdocs/manual.html +++ b/re2c/htdocs/manual.html @@ -508,6 +508,9 @@ will be generated.
    Set this to zero to suppress generation of YYFILL(n). When using this be sure to verify that the generated scanner does not read behind input. Allowing this behavior might introduce sever security issues to you programs.
    +
    re2c:yyfill:check = 1 ;
    +
    This can be set 0 to suppress output of the pre condition using YYCURSOR and +YYLIMIT which becomes usefull when YYLIMIT + max(YYFILL) is always accessible.
    re2c:yyfill:parameter = 1 ;
    Allows to suppress parameter passing to YYFILL calls. If set to zero then no parameter is passed to YYFILL. However define:YYFILL@LEN @@ -597,6 +600,8 @@ inside YYSETCONDITION will be replaced with the actual new condition valu
    re2c:define:YYSETSTATE = YYSETSTATE ;
    Allows to overwrite the define YYSETSTATE and thus avoiding it by setting the value to the actual code needed.
    +
    re2c:define:YYSETSTATE:naked = 0 ;
    +
    Wehn set to 1 neither braces, parameter nor semicolon gets emitted.
    re2c:define:YYSETSTATE@state = @@ ;
    When using re2c:define:YYSETSTATE then any occurence of this text inside YYSETSTATE will be replaced with the actual new state value.
    diff --git a/re2c/main.cc b/re2c/main.cc index 22c270af..b33ace15 100644 --- a/re2c/main.cc +++ b/re2c/main.cc @@ -53,10 +53,12 @@ bool bUseStartLabel = false; bool bUseStateNext = false; bool bUseYYFill = true; bool bUseYYFillParam = true; +bool bUseYYFillCheck = true; bool bUseYYFillNaked = false; bool bUseYYSetConditionParam = true; bool bUseYYGetConditionNaked = false; bool bUseYYSetStateParam = true; +bool bUseYYSetStateNaked = false; bool bUseYYGetStateNaked = false; std::string startLabelName; diff --git a/re2c/re2c.1.in b/re2c/re2c.1.in index a9640ab5..1088a935 100644 --- a/re2c/re2c.1.in +++ b/re2c/re2c.1.in @@ -613,6 +613,10 @@ Set this to zero to suppress generation of YYFILL(n). When using this be sure to verify that the generated scanner does not read behind input. Allowing this behavior might introduce sever security issues to you programs. .TP +\fIre2c:yyfill:check\fP \fB=\fP 1 \fB;\fP +This can be set 0 to suppress output of the pre condition using YYCURSOR and +YYLIMIT which becomes usefull when YYLIMIT + max(YYFILL) is always accessible. +.TP \fIre2c:yyfill:parameter\fP \fB=\fP 1 \fB;\fP Allows to suppress parameter passing to \fBYYFILL\fP calls. If set to zero then no parameter is passed to \fBYYFILL\fP. However \fBdefine:YYFILL@LEN\fP @@ -726,6 +730,9 @@ inside \fBYYSETCONDITION\fP will be replaced with the actual new condition value Allows to overwrite the define \fBYYSETSTATE\fP and thus avoiding it by setting the value to the actual code needed. .TP +\fIre2c:define:YYSETSTATE:naked\fP \fB=\fP 0 \fB;\fP +Wehn set to 1 neither braces, parameter nor semicolon gets emitted. +.TP \fIre2c:define:YYSETSTATE@state\fP \fB=\fP @@ \fB;\fP When using \fIre2c:define:YYSETSTATE\fP then any occurence of this text inside \fBYYSETSTATE\fP will be replaced with the actual new state value. diff --git a/re2c/test/config4g.ifs.c b/re2c/test/config4g.ifs.c new file mode 100755 index 00000000..e7aa0020 --- /dev/null +++ b/re2c/test/config4g.ifs.c @@ -0,0 +1,47 @@ +/* Generated by re2c */ +#define NULL ((char*) 0) + +const unsigned char *scan(const unsigned char *p, unsigned int len, int *state) +{ + unsigned char c; + const unsigned char *q; + const unsigned char * const e = p + len; + + switch (*state) { + default: goto yy0; + case 0: goto yyFillLabel0; + case 1: goto yyFillLabel1; + } + + +yy0: + *state = 0; + if (p >= e) { + return NULL; + } +yyFillLabel0: + c = *p; + if (c <= '/') goto yy4; + if (c >= ':') goto yy4; + ++p; + c = *p; + goto yy7; +yy3: + { return p; } +yy4: + ++p; + { return NULL; } +yy6: + ++p; + *state = 1; + if (p >= e) { + return NULL; + } +yyFillLabel1: + c = *p; +yy7: + if (c <= '/') goto yy3; + if (c <= '9') goto yy6; + goto yy3; + +} diff --git a/re2c/test/config4g.ifs.re b/re2c/test/config4g.ifs.re new file mode 100755 index 00000000..4d17b339 --- /dev/null +++ b/re2c/test/config4g.ifs.re @@ -0,0 +1,31 @@ +#define NULL ((char*) 0) + +const unsigned char *scan(const unsigned char *p, unsigned int len, int *state) +{ + unsigned char c; + const unsigned char *q; + const unsigned char * const e = p + len; +/*!re2c +re2c:variable:yych = c; +re2c:indent:top = 1; +re2c:state:abort = 0; +re2c:state:nextlabel = 0; +re2c:define:YYCTYPE = char; +re2c:define:YYCURSOR = p; +re2c:define:YYLIMIT = e; +re2c:define:YYMARKER = q; +re2c:yyfill:check = 0; +re2c:define:YYFILL:naked = 1; +re2c:define:YYFILL = "if (p >= e) {\n\t\treturn NULL;\n\t}"; +re2c:define:YYSETSTATE = "*state = @;"; +re2c:define:YYSETSTATE:naked = 1; +re2c:define:YYSETSTATE@state = "@"; +re2c:define:YYGETSTATE = "*state"; +re2c:define:YYGETSTATE:naked = 1; +*/ +/*!getstate:re2c */ +/*!re2c + [0-9]+ { return p; } + [\000-\377] { return NULL; } +*/ +} -- 2.40.0