[ragel-users] Bad code generation for C# ?

Denis Naumov alexander.me at gmail.com
Fri Mar 25 08:16:31 UTC 2011


Hi Adrian,

To solve problem with alphtype... i search ragel source code and found
string CSharpFsmCodeGen::ALPHA_KEY( Key key ) in cscodegen.cpp

is this the the only place where ALPHA constants generates? or is
where any one else?

C# type is sbyte, byte, short, ushort, char, int, uint, long, ulong
from common.cpp

and for only for 'char' type ragel must generate '\u****' constants.
for all other types it must generate number.

simple patch:

==================================================================
 FILE     => cscodegen.cpp
 FUNCTION => string CSharpFsmCodeGen::ALPHA_KEY( Key key )
==================================================================
---- OLD CODE ----------------------------------------------------

string CSharpFsmCodeGen::ALPHA_KEY( Key key )
{
    ostringstream ret;
    if (key.getVal() > 0xFFFF) {
        ret << key.getVal();
    } else {
        ret << "'\\u" << std::hex << std::setw(4) << std::setfill('0') <<
            key.getVal() << "'";
    }
    //ret << "(char) " << key.getVal();
    return ret.str();
}

---- NEW CODE ----------------------------------------------------

string CSharpFsmCodeGen::ALPHA_KEY( Key key )
{
    ostringstream ret;
    if (key.getVal() > 0xFFFF) {
        ret << key.getVal();
    } else {
        if (strcmp(keyOps->alphType->data1, "char") == 0)
            ret << "'\\u" << std::hex << std::setw(4) <<
std::setfill('0') << key.getVal() << "'";
        else
            ret << key.getVal();
    }
    //ret << "(char) " << key.getVal();
    return ret.str();
}

---- END ---------------------------------------------------------



==================================================================
 FILE     => cstable.cpp
 FUNCTION => std::ostream &CSharpTabCodeGen::KEYS()
==================================================================
---- OLD CODE (at the end of function) ---------------------------

    /* Output one last number so we don't have to figure out when the last
     * entry is and avoid writing a comma. */
    out << "(char) " << 0 << "\n";
    return out;

---- NEW CODE ----------------------------------------------------

    /* Output one last number so we don't have to figure out when the last
     * entry is and avoid writing a comma. */
    if (strcmp(keyOps->alphType->data1, "char") == 0)
        out << "(char) " << 0 << "\n";
    else
        out << 0 << "\n";
    return out;

---- END ---------------------------------------------------------



==================================================================
 FILE     => csflat.cpp
 FUNCTION => std::ostream &CSharpFlatCodeGen::KEYS()
 FUNCTION => std::ostream &CSharpFlatCodeGen::COND_KEYS()
==================================================================
---- OLD CODE (at the end of functions) --------------------------

    /* Output one last number so we don't have to figure out when the last
     * entry is and avoid writing a comma. */
    out << "(char) " << 0 << "\n";
    return out;

---- NEW CODE ----------------------------------------------------

    /* Output one last number so we don't have to figure out when the last
     * entry is and avoid writing a comma. */
    if (strcmp(keyOps->alphType->data1, "char") == 0)
        out << "(char) " << 0 << "\n";
    else
    out << 0 << "\n";
    return out;

---- END ---------------------------------------------------------

Please, check this code. Is it right ? or i forgot something?


Best regards,
Denis Naumov.



2011/3/24 Denis Naumov <alexander.me at gmail.com>:
> Hi Adrian,
>
> I found that Alphtype Statement probably not work for C#.
>
> By default type is 'char'
>
> and ragel generate
>     static readonly char[] _test_trans_keys =  new ushort [] { '\u0022' .... }
>
> for -T0 mode and
>
>    switch( data[(      _ctx.current)] )
>        {  case '\u0009': goto tr0;  ...  }
>
> for -G0 mode
>
> it's ok.
>
> but if i use "alphtype byte;" ragel generate
>
>     static readonly byte[] _test_trans_keys =  new ushort [] { '\u0022' .... }
>
> for -T0 mode and
>
>    switch( data[(      _ctx.current)] )
>        {  case '\u0009': goto tr0;  ...  }
>
> for -G0 mode
>
> it's wrong. It must be
>     static readonly byte[] _test_trans_keys =  new ushort [] { 22, .... }
> and
>    switch( data[(      _ctx.current)] )
>        {  case 9: goto tr0;  ...  }
>
> it seems to be that ragel generate '\u****' constants for all alphtypes.
>
>
> Best regards,
> Denis Naumov.
>

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users



More information about the ragel-users mailing list