[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs
From:       Pino Toscano <pino () kde ! org>
Date:       2009-08-03 0:32:37
Message-ID: 1249259557.674124.15146.nullmailer () svn ! kde ! org
[Download RAW message or body]

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)]


--- trunk/KDE/kdelibs/kdecore/kconfig_compiler/kconfig_compiler.cpp #1006087:1006088
@@ -1212,7 +1212,31 @@
     return result;
 }
 
+// adds as many 'namespace foo {' lines to p_out as
+// there are namespaces in p_ns
+void beginNamespaces(const QString &p_ns, QTextStream &p_out) 
+{
+  if ( !p_ns.isEmpty() ) {
+    const QStringList nameSpaces = p_ns.split( "::" );
+    foreach (const QString &ns, nameSpaces )
+      p_out << "namespace " << ns << " {" << endl;
+    p_out << endl;
+  }
+}
 
+// adds as many '}' lines to p_out as
+// there are namespaces in p_ns
+void endNamespaces(const QString &p_ns, QTextStream &p_out)
+{
+  if ( !p_ns.isEmpty() ) {
+    const int namespaceCount = p_ns.count( "::" ) + 1;
+    for ( int i = 0; i < namespaceCount; ++i )
+      p_out << "}" << endl;
+    p_out << endl;
+  }
+}
+
+
 int main( int argc, char **argv )
 {
   QCoreApplication app(argc, argv);
@@ -1406,9 +1430,9 @@
   h << "// This file is generated by kconfig_compiler from " << \
QFileInfo(inputFilename).fileName() << "." << endl;  h << "// All changes you do to \
this file will be lost." << endl;  
-  h << "#ifndef " << ( !nameSpace.isEmpty() ? QString(nameSpace.toUpper() + '_') : \
"" ) +  h << "#ifndef " << ( !nameSpace.isEmpty() ? QString(nameSpace).replace( "::", \
"_" ).toUpper() + '_' : "" )  << className.toUpper() << "_H" << endl;
-  h << "#define " << ( !nameSpace.isEmpty() ? QString(nameSpace.toUpper() + '_') : \
"" ) +  h << "#define " << ( !nameSpace.isEmpty() ? QString(nameSpace).replace( "::", \
"_" ).toUpper() + '_' : "" )  << className.toUpper() << "_H" << endl << endl;
 
   // Includes
@@ -1436,8 +1460,7 @@
       h << "#include <" << *it << ">" << endl;
   }
 
-  if ( !nameSpace.isEmpty() )
-    h << "namespace " << nameSpace << " {" << endl << endl;
+  beginNamespaces(nameSpace, h);
 
   // Private class declaration
   if ( dpointer )
@@ -1805,7 +1828,7 @@
 
   h << "};" << endl << endl;
 
-  if ( !nameSpace.isEmpty() ) h << "}" << endl << endl;
+  endNamespaces(nameSpace, h);
 
   h << "#endif" << endl << endl;
 
@@ -1852,8 +1875,7 @@
   // private class implementation
   if ( dpointer )
   {
-    if ( !nameSpace.isEmpty() )
-      cpp << "namespace " << nameSpace << " {" << endl;
+    beginNamespaces(nameSpace, cpp);
     cpp << "class " << className << "Private" << endl;
     cpp << "{" << endl;
     cpp << "  public:" << endl;
@@ -1881,14 +1903,12 @@
     }
 
     cpp << "};" << endl << endl;
-    if ( !nameSpace.isEmpty() )
-      cpp << "}" << endl << endl;
+    endNamespaces(nameSpace, cpp);
   }
 
   // Singleton implementation
   if ( singleton ) {
-    if( !nameSpace.isEmpty() )
-      cpp << "namespace " << nameSpace << " {" << endl;
+    beginNamespaces(nameSpace, cpp);
     cpp << "class " << className << "Helper" << endl;
     cpp << '{' << endl;
     cpp << "  public:" << endl;
@@ -1896,8 +1916,7 @@
     cpp << "    ~" << className << "Helper() { delete q; }" << endl;
     cpp << "    " << className << " *q;" << endl;
     cpp << "};" << endl;
-    if( !nameSpace.isEmpty() )
-      cpp << "}" << endl;
+    endNamespaces(nameSpace, cpp);
     cpp << "K_GLOBAL_STATIC(" << className << "Helper, s_global" << className << ")" \
<< endl;  
     cpp << className << " *" << className << "::self()" << endl;
--- trunk/KDE/kdelibs/kdeui/tests/kconfig_compiler/CMakeLists.txt #1006087:1006088
@@ -58,6 +58,18 @@
 
 ########### next target ###############
 
+set(test3a_SRCS test3amain.cpp )
+
+
+gen_kcfg_test_source(test3a test3a_SRCS)
+
+kde4_add_executable(test3a TEST ${test3a_SRCS})
+
+target_link_libraries(test3a  ${KDE4_KDEUI_LIBS} )
+
+
+########### next target ###############
+
 set(test4_SRCS test4main.cpp )
 
 
--- trunk/KDE/kdelibs/kdeui/tests/kconfig_compiler/kconfigcompiler_test.cpp \
#1006087:1006088 @@ -32,6 +32,7 @@
 	"test1.cpp", "test1.h",
 	"test2.cpp", "test2.h",
 	"test3.cpp", "test3.h",
+	"test3a.cpp", "test3a.h",
 	"test4.cpp", "test4.h",
 	"test5.cpp", "test5.h",
 	"test6.cpp", "test6.h",
@@ -51,6 +52,7 @@
     "test1",
     "test2",
     "test3",
+    "test3a",
     "test4",
     "test5",
     "test6",


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic