EVerest / cbexigen

cbExiGen - The V2GTP EXI codec generator for cbV2G
Apache License 2.0
32 stars 18 forks source link

Current main state does not build anymore #40

Closed SebaLukas closed 1 year ago

SebaLukas commented 1 year ago

Hi :)

I checked out the current state 82976af today to add the latest improvements to my project. Now the generated code for the ISO20 decoders and encoders no longer builds.

Here is an snippet of the error message from g++/ninja:

[20/224] Building C object src/exi/cb/CMakeFiles/cb_iso20.dir/iso-20/iso20_AC_Encoder.c.o
FAILED: src/exi/cb/CMakeFiles/cb_iso20.dir/iso-20/iso20_AC_Encoder.c.o 
/usr/bin/cc  -I/home/sebalukas/containers/everest_fedora/test/include/exi/cb -I/home/sebalukas/containers/everest_fedora/test/include  -MD -MT src/exi/cb/CMakeFiles/cb_iso20.dir/iso-20/iso20_AC_Encoder.c.o -MF src/exi/cb/CMakeFiles/cb_iso20.dir/iso-20/iso20_AC_Encoder.c.o.d -o src/exi/cb/CMakeFiles/cb_iso20.dir/iso-20/iso20_AC_Encoder.c.o -c /home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c
/home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c:2581:13: error: expected identifier or ‘(’ before ‘}’ token
 2581 |             }
      |             ^
/home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c:2582:13: error: expected identifier or ‘(’ before ‘break’
 2582 |             break;
      |             ^~~~~
/home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c:2583:9: error: expected identifier or ‘(’ before ‘case’
 2583 |         case 51:
      |         ^~~~
/home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c:2586:13: error: expected identifier or ‘(’ before ‘if’
 2586 |             if (error == EXI_ERROR__NO_ERROR)
      |             ^~
/home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c:2601:25: error: expected identifier or ‘(’ before ‘}’ token
 2601 |                         }
      |                         ^
/home/sebalukas/containers/everest_fedora/test/src/exi/cb/iso-20/iso20_AC_Encoder.c:2602:21: error: expected identifier or ‘(’ before ‘}’ token
 2602 |                     }
      |                     ^

Can you please take a look?

There seems to be something wrong with the generation of the decode and encode function of arrays.

Attached I have also added the generated code. Generated_c_ISO_20.zip

SebaLukas commented 1 year ago

Example from generated code:

switch(eventCode)
{
case 0:
    // Event: START (Reference, ReferenceType (ReferenceType)); next=106
    // decode: element array
    if (SignedInfoType->Reference.arrayLen < iso20_ReferenceType_4_ARRAY_SIZE)
    {
        error = decode_iso20_ReferenceType(stream, &SignedInfoType->Reference.array[SignedInfoType->Reference.arrayLen++]);
    }
    else
    {
        error = EXI_ERROR__ARRAY_OUT_OF_BOUNDS;
    }
        grammar_id = 106;
        grammar_id = 106;
    }
    grammar_id = 106;
    }
    break;
default:
    error = EXI_ERROR__UNKNOWN_EVENT_CODE;
    break;
}

3x grammar_id = 106 and too many braces

barsnick commented 1 year ago

Do you happen to have old local fixes to the cbexigen code base which you forgot to revert? Is src/config.py clean?

Indeed, ReferenceType used to be a single scalar, now it's corrected to an array.

I cannot reproduce this, and the code I produce (with Python 3.8.10, xmlschema 1.11.2, jinja2 3.1.2) does not show these artifacts, and compiles without warnings. (Still issues with WPT and ACDP though.)

I don't see the issues in your attached ZIP file, BTW:

        case 105:
            // Grammar: ID=105; read/write bits=1; START (Reference)
            error = exi_basetypes_decoder_nbit_uint(stream, 1, &eventCode);
            if (error == 0)
            {
                switch(eventCode)
                {
                case 0:
                    // Event: START (Reference, ReferenceType (ReferenceType)); next=106
                    // decode: element array
                    if (SignedInfoType->Reference.arrayLen < iso20_ReferenceType_4_ARRAY_SIZE)
                    {
                        error = decode_iso20_ReferenceType(stream, &SignedInfoType->Reference.array[SignedInfoType->Reference.arrayLen++]);
                    }
                    else
                    {
                        error = EXI_ERROR__ARRAY_OUT_OF_BOUNDS;
                    }
                    grammar_id = 106;
                    break;
                default:
                    error = EXI_ERROR__UNKNOWN_EVENT_CODE;
                    break;
                }
            }
            break;

And your attached files compile cleanly, using:

clang -c -ggdb -fPIC -Wall -Wextra -Werror=unused-value -Werror=uninitialized $(for d in {common,iso-20}; do echo "-I$d"; done) {common,iso-20}/*.c

which corresponds to

clang -c -ggdb -fPIC -Wall -Wextra -Werror=unused-value -Werror=uninitialized -Icommon -Iiso-20 common/exi_basetypes.c common/exi_basetypes_decoder.c common/exi_basetypes_encoder.c common/exi_bitstream.c common/exi_header.c common/exi_types_decoder.c iso-20/iso20_AC_Datatypes.c iso-20/iso20_AC_Decoder.c iso-20/iso20_AC_Encoder.c iso-20/iso20_CommonMessages_Datatypes.c iso-20/iso20_CommonMessages_Decoder.c iso-20/iso20_CommonMessages_Encoder.c iso-20/iso20_DC_Datatypes.c iso-20/iso20_DC_Decoder.c iso-20/iso20_DC_Encoder.c
SebaLukas commented 1 year ago

Thank you for your fast response :) I think i know the problem. Vscode does things it shouldn't do. Like messing with local changes and revert and combine too many things together.

Let me check that quick.

SebaLukas commented 1 year ago

Yes it builds again :smile: By reverting through vscode there was a very weird code mix here, which of course does not build. I actually only wanted to revert the includes in the source files, since we split the includes and src files into separate folders.

Many thanks Moritz!!!