Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Values for enum YYCONDTYPE are not generated when default rules with conditions are used #145

Closed
sirzooro opened this issue Jun 24, 2016 · 5 comments
Assignees
Milestone

Comments

@sirzooro
Copy link

@sirzooro sirzooro commented Jun 24, 2016

Following code generates empty enum YYCONDTYPE (no values), so compilation fails. When I changed it to use single default rule for all conditions, enum values were generated as expected.

I use re2c 0.16 compiled using gcc 5.3.0 on Cygwin x86_64.

#include <stdio.h>

/*!types:re2c*/

int test(const char* str)
{
    const unsigned char* YYCURSOR = (const unsigned char*)str;
    const unsigned char* YYMARKER;
    const unsigned char *YYCTXMARKER;
    int c = yycinit;

    /*!re2c
        re2c:define:YYCTYPE = "unsigned char";
        re2c:yyfill:enable = 0;
        re2c:define:YYGETCONDITION = "c";
        re2c:define:YYGETCONDITION:naked = 1;
        re2c:define:YYSETCONDITION = "c = @@;";
        re2c:define:YYSETCONDITION:naked = 1;

        //<*>* { return 0; }
        <init>* { return 0; }
        <init>"A" :=> C2
        <C2>* { return 0; }
        <C2>"B" { return 1; }
    */
}

int main()
{
    printf("%d\n", test("AB"));
    return 0;
}
@skvadrik
Copy link
Owner

@skvadrik skvadrik commented Jun 24, 2016

Confirmed, this is a bug and it is reproducible with HEAD. I've simplified the test case a bit:

/*!types:re2c*/
/*!re2c
    <c> * {}
*/

Expected result of re2c -ci:

enum YYCONDTYPE {
        yycc,
};



{
        YYCTYPE yych;
        switch (YYGETCONDITION()) {
        case yycc: goto yyc_c;
        }
/* *********************************** */
yyc_c:
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        ++YYCURSOR;
        {}
}

Actual result:

enum YYCONDTYPE {
};



{
        YYCTYPE yych;
        switch (YYGETCONDITION()) {
        }
/* *********************************** */
yyc_c:
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        ++YYCURSOR;
        {}
}

Loading

@skvadrik skvadrik self-assigned this Jun 24, 2016
@skvadrik skvadrik added this to the 0.17 milestone Jun 24, 2016
@skvadrik
Copy link
Owner

@skvadrik skvadrik commented Jun 24, 2016

As a workaround one can use [^] instead of defautl rule * (see however http://re2c.org/manual/warnings/undefined_control_flow/wundefined_control_flow.html#difference-between-and). The problem stems from special (delayed) handling of default rule.

Loading

skvadrik added a commit that referenced this issue Jun 24, 2016
when default rules with conditions are used".

Default rule is handled in a special (delayed) way;
re2c uses different code for default rule than for normal rules.
This special code simply forgot to add condition name to the list
of conditions.

Thanks to sirzooro for bug report.
@skvadrik
Copy link
Owner

@skvadrik skvadrik commented Jun 24, 2016

Fixed in master.

Loading

@skvadrik
Copy link
Owner

@skvadrik skvadrik commented Jun 25, 2016

Did you try the fix?

Loading

@sirzooro
Copy link
Author

@sirzooro sirzooro commented Jun 25, 2016

Yes, it works for me. Thanks :)

Loading

@skvadrik skvadrik closed this Jun 25, 2016
skvadrik added a commit that referenced this issue Jul 30, 2017
when default rules with conditions are used".

Default rule is handled in a special (delayed) way;
re2c uses different code for default rule than for normal rules.
This special code simply forgot to add condition name to the list
of conditions.

Thanks to sirzooro for bug report.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants