Bug 202088

Summary: kconfig_compiler doesn't support nested namespaces
Product: [Frameworks and Libraries] kdelibs Reporter: Olivier Serve <tifauv>
Component: kdecoreAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: frank78ac
Priority: NOR    
Version: 4.2   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Proposed patch against version 4.2.4
Sample kcfg without namespace
Sample kcfg with 1 namespace
Sample kcfg with 2 nested namespaces
Adds nested namespaces support for kconfig_compiler in trunk

Description Olivier Serve 2009-07-31 15:02:03 UTC
Version:            (using KDE 4.2.4)
OS:                Linux
Installed from:    Gentoo Packages

kconfig_compiler produces invalid C++ code when using nested namepaces.

== Sample fooconfig.kcfgc file ==
File=libfoopart_la.kcfg
ClassName=FooPartConfig
Namespace=foo::part
Singleton=true
Mutators=true
========================

kconfig_compiler then produces the following foopartconfig.h and .cpp :

---------- foopartconfig.h ----------
// This file is generated by kconfig_compiler from libfoopart_la.kcfg.
// All changes you do to this file will be lost.
#ifndef FOO::PART_FOOPARTCONFIG_H
#define FOO::PART_FOOPARTCONFIG_H

#include <kconfigskeleton.h>
#include <kdebug.h>

namespace foo::part {

class FooPartConfig : public KConfigSkeleton
{
[...]
};

}

#endif
-------------------------------------

--------- foopartconfig.cpp ---------
// This file is generated by kconfig_compiler from libfoopart_la.kcfg.
// All changes you do to this file will be lost.

#include "foopartconfig.h"

#include <kglobal.h>
#include <QtCore/QFile>

using namespace foo::part;

namespace foo::part {
class FooPartConfigHelper
{
  public:
    FooPartConfigHelper() : q(0) {}
    ~FooPartConfigHelper() { delete q; }
    FooPartConfig *q;
};
}
[...]
-------------------------------------

This doesn't compile at all :
  1. gcc warns about the "::" in the #ifdef/#define of the .h file
  2. gcc fails on the "namespace foo::part" declaration in the .h and .cpp files


I attached 3 sample .kcfgc files :
  1. without namespace
  2. with one namespace
  3. with 2 nested namespaces
They can be used to check the behaviour of the current implementation.

I also propose a patch that fixes that issue on the 4.2.4 branch.
Comment 1 Olivier Serve 2009-07-31 15:04:49 UTC
Created attachment 35753 [details]
Proposed patch against version 4.2.4

This patch adds 2 macros BEGIN_NAMESPACES() and END_NAMESPACES() which take care of adding the "namespace fff {" and "}" statements.

Also modifies the #ifndef/#define declarations to replace the "::" by "_".
Comment 2 Olivier Serve 2009-07-31 15:06:00 UTC
Created attachment 35754 [details]
Sample kcfg without namespace
Comment 3 Olivier Serve 2009-07-31 15:06:24 UTC
Created attachment 35755 [details]
Sample kcfg with 1 namespace
Comment 4 Olivier Serve 2009-07-31 15:06:46 UTC
Created attachment 35756 [details]
Sample kcfg with 2 nested namespaces
Comment 5 Olivier Serve 2009-07-31 15:10:49 UTC
It should be noted that the patch is largely inspired by the one from Shintaro Matsuoka in KDE 3.5 times (2006).

See http://lists.kde.org/?l=kde-core-devel&m=115165296513848&w=2
Comment 6 Frank Reininghaus 2009-08-02 14:56:20 UTC
Thanks for the patch!

I can't comment on the patch because I'm not familiar with the kconfig stuff, but I think it might be better if you file a review request for kdelibs at

http://reviewboard.kde.org/

This is usually the best way to make sure that your patch does not get overlooked (which may happen in bug reports, because it's not guaranteed that the right people will see your patch here).

It might also be better to provide a patch for trunk instead of 4.2.4 because there will be no more KDE 4.2.x releaes.
Comment 7 Olivier Serve 2009-08-02 17:23:06 UTC
Created attachment 35789 [details]
Adds nested namespaces support for kconfig_compiler in trunk
Comment 8 Pino Toscano 2009-08-03 02:32:38 UTC
SVN commit 1006088 by pino:

Fix namespace support, by taking into account possible multiple levels (eg Foo::Bar::Baz::etc) and writing their opening/closing correctly.
Based on a patch by Olivier Serve <tifauv@gmail.com> (thanks!), slightly polished by me (also to give 100% output compatibility).
Add a test3a testcase (basically copied from test3) to the kconfig_compiler test suite for this.
BUG: 202088


 M  +32 -13    kdecore/kconfig_compiler/kconfig_compiler.cpp  
 M  +12 -0     kdeui/tests/kconfig_compiler/CMakeLists.txt  
 M  +2 -0      kdeui/tests/kconfig_compiler/kconfigcompiler_test.cpp  
 A             kdeui/tests/kconfig_compiler/test3a.cpp.ref  
 A             kdeui/tests/kconfig_compiler/test3a.h.ref  
 A             kdeui/tests/kconfig_compiler/test3a.kcfg  
 A             kdeui/tests/kconfig_compiler/test3a.kcfgc  
 A             kdeui/tests/kconfig_compiler/test3amain.cpp   [License: BSD X11 (BSD like)]


WebSVN link: http://websvn.kde.org/?view=rev&revision=1006088