Results 1 to 9 of 9

Thread: slice2cpp produces bad code

  1. #1
    Sheff is offline Registered User
    Name: Stanislav Vorobiov
    Organization: FocusMedia
    Project: Object System
    Join Date
    Nov 2008
    Posts
    13

    slice2cpp produces bad code

    slice2cpp generates bad C++ code while compiling the following Slice:

    Code:
    module Foo
    {
        class while
        {
        };
    }

  2. #2
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    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.

  3. #3
    Sheff is offline Registered User
    Name: Stanislav Vorobiov
    Organization: FocusMedia
    Project: Object System
    Join Date
    Nov 2008
    Posts
    13
    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.

  4. #4
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    It would help to provide the exact compiler version, operating system, and finally compilation errors that you are getting.

  5. #5
    Andreas Scherer is offline Registered User
    Name: Andreas Scherer
    Organization: Private Linux Site
    Project: Evaluating Ice-C++, Ice-Java, Ice-Python, Ice-Ruby
    Join Date
    Mar 2005
    Location
    Berlin, Germany
    Posts
    50
    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. )
    Last edited by Andreas Scherer; 01-27-2009 at 01:45 PM.

  6. #6
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    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:

    Code:
    static ::Foo::_cpp_while__staticInit _while_init;
    should instead be

    Code:
    static ::Foo::while__staticInit _while_init;
    Cheers,

    Michi.
    Last edited by michi; 01-27-2009 at 03:06 PM.

  7. #7
    Sheff is offline Registered User
    Name: Stanislav Vorobiov
    Organization: FocusMedia
    Project: Object System
    Join Date
    Nov 2008
    Posts
    13
    By the way, C++ identifier in module name also produces bad code if
    that module contain classes.

  8. #8
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Here is a patch that fixes the class name problem:

    Code:
    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.

  9. #9
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Thanks for the bug report. Here is a patch that fixes it:

    Code:
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. slice2cpp generate bad string literals
    By jbrouault in forum Bug Reports
    Replies: 4
    Last Post: 12-30-2011, 10:35 AM
  2. uncompilable code generated by slice2cpp
    By srxavi in forum Bug Reports
    Replies: 6
    Last Post: 03-26-2010, 11:44 AM
  3. slice2cpp generated code and Ice versions
    By phil++ in forum Help Center
    Replies: 1
    Last Post: 08-01-2008, 02:41 PM
  4. Compiling slice2cpp-generated-code on Win. XP Pro
    By catalin in forum Help Center
    Replies: 21
    Last Post: 10-29-2003, 09:56 PM
  5. "make" produces 1 GB directory
    By A. Guru in forum Help Center
    Replies: 3
    Last Post: 09-15-2003, 03:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •