Home Bug Reports

slice2cpp produces bad code

SheffSheff Member Stanislav VorobiovOrganization: FocusMediaProject: Object System
slice2cpp generates bad C++ code while compiling the following Slice:
module Foo
{
    class while
    {
    };
}

Comments

  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    You don't show the bad code--what exactly do you think is wrong?

    Because while is a C++ reserved word, it is mapped to _cpp_while. Is that what you are referring to? If so, that is expected; see the client-side C++ mapping in the manual.

    Cheers,

    Michi.
  • SheffSheff Member Stanislav VorobiovOrganization: FocusMediaProject: Object System
    I mean that if I compile such Slice with slice2cpp and then compile the generated
    C++ code with some C++ compiler (gcc4 in my case) it won't compile due to errors.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    It would help to provide the exact compiler version, operating system, and finally compilation errors that you are getting.
  • Andreas SchererAndreas Scherer Member Andreas SchererOrganization: Private Linux SiteProject: Evaluating Ice-C++, Ice-Python, Ice-Ruby ✭✭
    When I compile Sheff's slice code (after adding a semicolon in the last line) with slice2cpp 3.3.0 and try to compile the generated C++ code with g++ 4.2.4 on GNU/Linux (Kubuntu 8.04), the compiler reports the following error in line 381 of the generated header file:
    In file included from sl.cpp:13:
    ./sl.h:381: Fehler: »_cpp_while__staticInit« in Namensbereich »Foo« bezeichnet keinen Typ
    The associated class definition in line 374 is called while__staticInit and not _cpp_while__staticInit.

    (BTW, this looks suspiciously like the bug reported in post 14617 two years ago. ;) )
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    This is a bug in the code generator. Thanks for reporting this. We'll include a fix in the next release. As a work-around in the mean time, you can either rename the Slice symbol so it is no longer a C++ identifier, or you can edit the generated code. The line reading:
    static ::Foo::_cpp_while__staticInit _while_init;
    

    should instead be
    static ::Foo::while__staticInit _while_init;
    

    Cheers,

    Michi.
  • SheffSheff Member Stanislav VorobiovOrganization: FocusMediaProject: Object System
    By the way, C++ identifier in module name also produces bad code if
    that module contain classes.
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    Here is a patch that fixes the class name problem:
    diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
    index 51ea19f..22a0334 100644
    --- a/cpp/src/slice2cpp/Gen.cpp
    +++ b/cpp/src/slice2cpp/Gen.cpp
    @@ -3857,7 +3857,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
             H << sp << nl << scoped << " _init;";
             H << eb << ';';
             _doneStaticSymbol = true;
    -        H << sp << nl << "static " << scoped << "__staticInit _" << p->name() << "_init;";
    +        H << sp << nl << "static " << p->name() << "__staticInit _" << p->name() << "_init;";
         }
     
         if(p->isLocal())
    

    I'll have a look at the module name issue as well, thanks!

    Cheers,

    Michi.
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    Thanks for the bug report. Here is a patch that fixes it:
    diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
    index 22a0334..f990ccd 100644
    --- a/cpp/src/slice2cpp/Gen.cpp
    +++ b/cpp/src/slice2cpp/Gen.cpp
    @@ -4460,7 +4460,8 @@ Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p)
     
         if(!allDataMembers.empty())
         {
    -        C << sp << nl << p->scoped().substr(2) << "::" << fixKwd(p->name()) << spar << allParamDecls << epar << " :";
    +        C << sp << nl << fixKwd(p->scoped()).substr(2) << "::" << fixKwd(p->name())
    +         << spar << allParamDecls << epar << " :";
             C.inc();
     
             DataMemberList dataMembers = p->dataMembers();
    

    Cheers,

    Michi.
Sign In or Register to comment.