xensik / gsc-tool

A utility to compile & decompile IW engine game scripts.
GNU General Public License v3.0
214 stars 40 forks source link

[preprocessor]: Unable to work with methods #202

Closed diamante0018 closed 3 months ago

diamante0018 commented 3 months ago
#define METHOD_TEST( ent ) \
    if ( ent isHost() ) \
    { \
        continue; \
    }

main()
{
    thread onPlayerConnect();
}

onPlayerConnect()
{
    while ( true )
    {
        level waittill( "connected", player );

        METHOD_TEST( player );
    }
}

Expected behaviour: Compilation succeeds because ent isHost() is a GSC method and should be replaced correctly when the macro expands

Unexpected behaviour:

 .\gsc-tool.exe -m comp -g iw5 -s pc .\a.gsc
GSC Tool 1.4.3.297-prod created by xensik
[ERROR]:compiler:./a.gsc:2:14: missing ';' ? at ./a.gsc

Manually fixed version which proves something is wrong with the preprocessor

main()
{
    thread onPlayerConnect();
}

onPlayerConnect()
{
    while ( true )
    {
        level waittill( "connected", player );

        if ( player isHost() )
        {
            continue;
        }
    }
}
.\gsc-tool.exe -m comp -g iw5 -s pc .\a.gsc
GSC Tool 1.4.3.297-prod created by xensik
compiled iw5/a.gscbin
diamante0018 commented 3 months ago

Another example

main()
{
    thread onPlayerConnect();
}

#define PLAYER_NOTIFY_CMD(ent, str, action) ent notifyOnPlayerCommand( str, action )
onPlayerConnect()
{
    while ( true )
    {
        level waittill( "connected", player );

        if ( player isHost() )
        {
            continue;
        }

        PLAYER_NOTIFY_CMD( player, "load_saved_pos", "+activate" );
    }
}
 .\gsc-tool.exe -m comp -g iw5 -s pc .\a.gsc
GSC Tool 1.4.3.297-prod created by xensik
[ERROR]:compiler:./a.gsc:6:49: missing ';' ? at ./a.gsc
diamante0018 commented 3 months ago

Smaller example:

#define TEST_FUNC(num) myfunc( num )
#define TEST_METHOD( ent, num ) ent mymeth( num )

myfunc( num )
{
    print( num );
}

mymeth( num )
{
    print( num );
}

main()
{
    TEST_FUNC( 5 );
    TEST_METHOD( level, 6 );
}
.\gsc-tool.exe -m comp -g iw5 -s pc .\a.gsc
GSC Tool 1.4.3.297-prod created by xensik
[ERROR]:compiler:./a.gsc:2:37: missing ';' ? at ./a.gsc
xensik commented 3 months ago

need to add preprocess command to dump pre-parse token to file output