slice2cpp generates bad C++ code while compiling the following Slice:
Code:module Foo { class while { }; }
|
|
slice2cpp generates bad C++ code while compiling the following Slice:
Code:module Foo { class while { }; }
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.
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.
It would help to provide the exact compiler version, operating system, and finally compilation errors that you are getting.
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:
The associated class definition in line 374 is called while__staticInit and not _cpp_while__staticInit.In file included from sl.cpp:13:
./sl.h:381: Fehler: »_cpp_while__staticInit« in Namensbereich »Foo« bezeichnet keinen Typ
(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.
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:
should instead beCode:static ::Foo::_cpp_while__staticInit _while_init;
Cheers,Code:static ::Foo::while__staticInit _while_init;
Michi.
Last edited by michi; 01-27-2009 at 03:06 PM.
By the way, C++ identifier in module name also produces bad code if
that module contain classes.
Here is a patch that fixes the class name problem:
I'll have a look at the module name issue as well, thanks!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())
Cheers,
Michi.
Thanks for the bug report. Here is a patch that fixes it:
Cheers,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();
Michi.
There are currently 1 users browsing this thread. (0 members and 1 guests)