[patch] minor dcopidl2cpp indentation level cleanups

Alexander Kellett lypanov at kde.org
Wed Apr 9 23:14:00 BST 2003


hiya matthias / -core-devel,

the attached patch decreases the 
overall indentation level of the
various .cpp files in dcop/dcopidl2cpp
using a few simple code tranforms.

(basically, "if (b) { blah }"
         -> "if (!b) continue;
             blah;"

various other redundant comment removals
code formatting consistancy changes, 
and some minor code changes were also 
made. in fact, i noticed that one
method (isIntType) is missing a static.

the patch is completely untested, in 
fact uncompiled even, its the idea 
that i'd like some feedback on.

reasoning behind the changes is to 
make room for a bunch of minor extensions 
to the "k_dcop_signals" which i wrote 
back in 2001. more on this to come
after replies to this email though.

i'd prefer not to add yet more cruft 
to the already heavly duplicated code 
base, therefore, this is just a first 
stage nano-refactor. and hopefully
i'll produce more patches to further
decrease the duplication after adding
the extensions.

mvg,
Alex

p.s: i've tried to keep to qt style
indentation but i'm really not used
to using it vim so maybe i mucked up 
in some places.
-------------- next part --------------
? blah.patch
Index: skel.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/skel.cpp,v
retrieving revision 1.22
diff -u -p -B -w -r1.22 skel.cpp
--- skel.cpp	15 Jan 2003 10:09:00 -0000	1.22
+++ skel.cpp	9 Apr 2003 22:14:01 -0000
@@ -59,9 +59,6 @@ struct Function
 };
 
 
-/**
- * Writes the skeleton
- */
 void generateSkel( const QString& idl, const QString& filename, QDomElement de )
 {
     QFile skel( filename );
@@ -70,13 +67,13 @@ void generateSkel( const QString& idl, c
 
     QTextStream str( &skel );
 
-    str << "/****************************************************************************" << endl;
+    str << "/***********************************************************************" << endl;
     str << "**" << endl;
     str << "** DCOP Skeleton created by dcopidl2cpp from " << idl << endl;
     str << "**" << endl;
     str << "** WARNING! All changes made in this file will be lost!" << endl;
     str << "**" << endl;
-    str << "*****************************************************************************/" << endl;
+    str << "************************************************************************/" << endl;
     str << endl;
 
     QDomElement e = de.firstChild().toElement();
@@ -85,7 +82,9 @@ void generateSkel( const QString& idl, c
     }
 
     for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
-	if ( e.tagName() == "CLASS" ) {
+	if ( e.tagName() != "CLASS" )
+	    continue;
+
 	    QDomElement n = e.firstChild().toElement();
 	    Q_ASSERT( n.tagName() == "NAME" );
 	    QString className = n.firstChild().toText().data();
@@ -101,7 +100,8 @@ void generateSkel( const QString& idl, c
 	    QValueList<Function> functions;
 	    s = n.nextSibling().toElement();
 	    for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
-		if ( s.tagName() == "FUNC" ) {
+	    if ( s.tagName() != "FUNC" )
+		continue;
 		    QDomElement r = s.firstChild().toElement();
 		    Q_ASSERT( r.tagName() == "TYPE" );
 		    QString funcType = r.firstChild().toText().data();
@@ -148,7 +148,6 @@ void generateSkel( const QString& idl, c
 		    fullFuncName += ')';
 		    functions.append( Function( funcType, funcName, fullFuncName ) );
 		}
-	    }
 
 	    // create static tables
 	
@@ -174,8 +173,7 @@ void generateSkel( const QString& idl, c
             str << endl;
             for(;;) {
                 int pos = namespace_tmp.find( "::" );
-                if( pos < 0 )
-                    {
+	    if( pos < 0 ) {
                     className = namespace_tmp;
                     break;
                     }
@@ -189,20 +187,24 @@ void generateSkel( const QString& idl, c
 	    if ( useHashing ) {
 		str << "static const int " << className << "_fhash = " << fhash << ";" << endl;
 	    }
-	    str << "static const char* const " << className << "_ftable[" << functions.count() + 1 << "][3] = {" << endl;
-	    for( QValueList<Function>::Iterator it = functions.begin(); it != functions.end(); ++it ){
-		str << "    { \"" << (*it).type << "\", \"" << (*it).name << "\", \"" << (*it).fullName << "\" }," << endl;
-	    }
+	str << "static const char* const " << className << "_ftable[" 
+	    << functions.count() + 1 << "][3] = {" << endl;
+	for( QValueList<Function>::Iterator it = functions.begin(); 
+	     it != functions.end(); 
+	     ++it )
+	    str << "    { \"" << (*it).type << "\", \"" << (*it).name 
+		<< "\", \"" << (*it).fullName << "\" }," << endl;
 	    str << "    { 0, 0, 0 }" << endl;
 	    str << "};" << endl;
 	
 	    str << endl;
 	
-	
 	    // Write dispatcher
 	    str << "bool " << className;
-	    str << "::process(const QCString &fun, const QByteArray &data, QCString& replyType, QByteArray &replyData)" << endl;
+	str << "::process(const QCString &fun, const QByteArray &data, "
+	    <<           "QCString& replyType, QByteArray &replyData)" << endl;
 	    str << "{" << endl;
+
 	    if ( useHashing ) {
 		str << "    static QAsciiDict<int>* fdict = 0;" << endl;
 	
@@ -219,7 +221,8 @@ void generateSkel( const QString& idl, c
 	    int fcount = 0; // counter of written functions
 	    bool firstFunc = TRUE;
 	    for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
-		if ( s.tagName() == "FUNC" ) {
+	    if ( s.tagName() != "FUNC" )
+		continue;
 		    QDomElement r = s.firstChild().toElement();
 		    Q_ASSERT( r.tagName() == "TYPE" );
 		    QString funcType = r.firstChild().toText().data();
@@ -253,9 +256,11 @@ void generateSkel( const QString& idl, c
 			str << "    case " << fcount << ": { // " << funcType << " " << funcName << endl;
 		    } else {
 			if ( firstFunc )
-			    str << "    if ( fun == " << className << "_ftable[" << fcount << "][1] ) { // " << funcType << " " << funcName << endl;
+		    str << "    if ( fun == " << className << "_ftable[" << fcount 
+			<< "][1] ) { // " << funcType << " " << funcName << endl;
 			else
-			    str << " else if ( fun == " << className << "_ftable[" << fcount << "][1] ) { // " << funcType << " " << funcName << endl;
+		    str << " else if ( fun == " << className << "_ftable[" << fcount 
+			<< "][1] ) { // " << funcType << " " << funcName << endl;
 			firstFunc = FALSE;
 		    }
 		    if ( !args.isEmpty() ) {
@@ -280,7 +285,9 @@ void generateSkel( const QString& idl, c
 		    }
 
 		    first = TRUE;
-		    for ( QStringList::Iterator args_count = args.begin(); args_count != args.end(); ++args_count ){
+	    for ( QStringList::Iterator args_count = args.begin(); 
+		  args_count != args.end(); 
+		  ++args_count ) {
 			if ( !first )
 			    str << ", ";
 			first = FALSE;
@@ -293,7 +300,6 @@ void generateSkel( const QString& idl, c
 			str << "    }";
 		    }
 		}
-	    }
 
             // only open an 'else' clause if there were one or more functions
 	    if ( fcount > 0 ) {
@@ -306,7 +312,8 @@ void generateSkel( const QString& idl, c
 	    
 	    // if no DCOP function was called, delegate the request to the parent
 	    if (!DCOPParent.isEmpty()) {
-		str << "\treturn " << DCOPParent << "::process( fun, data, replyType, replyData );" << endl;
+	    str << "\treturn " << DCOPParent 
+		<< "::process( fun, data, replyType, replyData );" << endl;
 	    } else {
 		str << "\treturn FALSE;" << endl;
 	    }
@@ -356,7 +363,8 @@ void generateSkel( const QString& idl, c
 
 	    // Go over all children of the CLASS tag
 	    for(s = e.firstChild().toElement(); !s.isNull(); s = s.nextSibling().toElement() ) {
-	        if (s.tagName() == "SIGNAL") {
+	    if (s.tagName() != "SIGNAL")
+		continue;
 		    QDomElement r = s.firstChild().toElement();
 		    QString result = writeType( str, r );
 
@@ -414,20 +422,13 @@ void generateSkel( const QString& idl, c
 		    }
 
                     str << "    emitDCOPSignal( \"" << funcName << "\", data );" << endl;
-
 		    str << "}" << endl << endl;
+	}
 	        
-	        } // if SIGNAL tag
-	    } // for each class function 
-
-            for(;
-                 namespace_count > 0;
-                 --namespace_count )
+	for(; namespace_count > 0; --namespace_count )
                 str << "} // namespace" << endl;
             str << endl;
-
-	} // if CLASS tag
-    } // for each CLASS-level tag
+    }
 	
     skel.close();
 }
Index: stub.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/stub.cpp,v
retrieving revision 1.14
diff -u -p -B -w -r1.14 stub.cpp
--- stub.cpp	1 Apr 2003 10:56:43 -0000	1.14
+++ stub.cpp	9 Apr 2003 22:14:01 -0000
@@ -44,13 +44,13 @@ void generateStub( const QString& idl, c
 	
     QTextStream str( &stub );
 
-    str << "/****************************************************************************" << endl;
+    str << "/***********************************************************************" << endl;
     str << "**" << endl;
     str << "** DCOP Stub Definition created by dcopidl2cpp from " << idl << endl;
     str << "**" << endl;
     str << "** WARNING! All changes made in this file will be lost!" << endl;
     str << "**" << endl;
-    str << "*****************************************************************************/" << endl;
+    str << "************************************************************************/" << endl;
     str << endl;
 
     QString ifdefstring = idl.upper();
@@ -68,8 +68,9 @@ void generateStub( const QString& idl, c
     QDomElement e = de.firstChild().toElement();
     for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
 	if ( e.tagName() == "INCLUDE" ) {
-            // dcopidl lists the includes in reversed order because of the used yacc/bison gramatic
-            // so let's reverse it back, as the order may be important
+            // dcopidl lists the includes in reversed order because 
+	    // of the used yacc/bison gramatic so let's reverse it back, 
+	    // as the order may be important
 	    includeslist.prepend( e.firstChild().toText().data());
             continue;
 	}
@@ -82,13 +83,15 @@ void generateStub( const QString& idl, c
             }
             includeslist.clear();
         }
-        if ( e.tagName() == "CLASS" ) {
+        if ( e.tagName() != "CLASS" ) {
+	    continue;
+	}
+
 	    str << endl;
 	
 	    QDomElement n = e.firstChild().toElement();
 	    Q_ASSERT( n.tagName() == "NAME" );
-	    QString className = n.firstChild().toText().data() 
-                         + ( "_stub" );
+	QString className = n.firstChild().toText().data() + "_stub";
 	
 	    // find dcop parent ( rightmost super class )
 	    QString DCOPParent;
@@ -98,12 +101,14 @@ void generateStub( const QString& idl, c
 		    DCOPParent = s.firstChild().toText().data();
 	    }
 
-            if( DCOPParent != "DCOPObject" ) { // we need to include the .h file for the base stub
+	if( DCOPParent != "DCOPObject" ) { 
+	    // we need to include the .h file for the base stub
                 if( all_includes.contains( DCOPParent + ".h" ))
                     str << "#include <" << DCOPParent << "_stub.h>" << endl;
                 else if( all_includes.contains( DCOPParent.lower() + ".h" ))
                     str << "#include <" << DCOPParent.lower() << "_stub.h>" << endl;
-                else {// damn ... let's assume it's the last include
+	    else {
+		// damn ... let's assume it's the last include
                     QString stub_h = all_includes.last();
                     unsigned int pos = stub_h.find( ".h" );
                     if( pos > 0 ) {
@@ -115,14 +120,15 @@ void generateStub( const QString& idl, c
                 }
             }
 
-            QString classNameFull = className; // class name with possible namespaces prepended
+	// class name with possible namespaces prepended
                                                // namespaces will be removed from className now
+	QString classNameFull = className;
+
             int namespace_count = 0;
             QString namespace_tmp = className;
             for(;;) {
                 int pos = namespace_tmp.find( "::" );
-                if( pos < 0 )
-                    {
+	    if( pos < 0 ) {
                     className = namespace_tmp;
                     break;
                     }
@@ -155,9 +161,13 @@ void generateStub( const QString& idl, c
 
 	    s = e.firstChild().toElement();
 	    for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
-		if (s.tagName() == "FUNC") {
+	    if (s.tagName() != "FUNC") {
+		continue;
+	    }
+
 		    QDomElement r = s.firstChild().toElement();
-		    str << "    virtual "; // KDE4 - I really don't think these need to be virtual
+	    // KDE4 - I really don't think these need to be virtual
+	    str << "    virtual "; 
 		    writeType( str, r );
 
 		    r = r.nextSibling().toElement();
@@ -188,7 +198,6 @@ void generateStub( const QString& idl, c
 			//str << " " << s.attribute("qual");
 		    str << ";" << endl;
 		}
-	    }
 
             // needed for inherited stubs
 	    str << "protected:" << endl;
@@ -197,13 +206,9 @@ void generateStub( const QString& idl, c
 	    str << "};" << endl;
 	    str << endl;
 
-            for(;
-                 namespace_count > 0;
-                 --namespace_count )
+	for(; namespace_count > 0; --namespace_count )
                 str << "} // namespace" << endl;
             str << endl;
-
-	}
     }
 
     str << "#endif" << endl;
Index: stubimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopidl2cpp/stubimpl.cpp,v
retrieving revision 1.23
diff -u -p -B -w -r1.23 stubimpl.cpp
--- stubimpl.cpp	1 Apr 2003 10:56:43 -0000	1.23
+++ stubimpl.cpp	9 Apr 2003 22:14:01 -0000
@@ -33,9 +33,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 #include "main.h"
 #include "type.h"
 
-int isIntType( const QString& t)
+static bool isIntType( const QString& t )
 {
-  if ((t == "int")
+  return ((t == "int")
       || (t == "signed int")
       || (t == "unsigned int")
       || (t == "uint")
@@ -56,15 +56,14 @@ int isIntType( const QString& t)
       || (t == "ulong")
       || (t == "char")
       || (t == "signed char")
-      || (t == "unsigned char"))
-    return 1;
-  return 0;
+       || (t == "unsigned char"));
 }
 
 /**
  * Writes the stub implementation
  */
-void generateStubImpl( const QString& idl, const QString& header, const QString& /*headerBase*/, const QString& filename, QDomElement de )
+void generateStubImpl( const QString& idl, const QString& header, const QString& /*headerBase*/, 
+                       const QString& filename, QDomElement de )
 {
     QFile impl( filename );
     if ( !impl.open( IO_WriteOnly ) )
@@ -72,13 +71,13 @@ void generateStubImpl( const QString& id
 
     QTextStream str( &impl );
 
-    str << "/****************************************************************************" << endl;
+    str << "/***********************************************************************" << endl;
     str << "**" << endl;
     str << "** DCOP Stub Implementation created by dcopidl2cpp from " << idl << endl;
     str << "**" << endl;
     str << "** WARNING! All changes made in this file will be lost!" << endl;
     str << "**" << endl;
-    str << "*****************************************************************************/" << endl;
+    str << "************************************************************************/" << endl;
     str << endl;
 
     str << "#include \"" << header << "\"" << endl;
@@ -87,21 +86,24 @@ void generateStubImpl( const QString& id
 
     QDomElement e = de.firstChild().toElement();
     for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
-	if ( e.tagName() == "CLASS" ) {
+	if ( e.tagName() != "CLASS" )
+            continue;
+
 	    QDomElement n = e.firstChild().toElement();
 	    Q_ASSERT( n.tagName() == "NAME" );
   	    QString classNameBase = n.firstChild().toText().data();
   	    QString className_stub = classNameBase + "_stub";
 	
-            QString classNameFull = className_stub; // class name with possible namespaces prepended
+        // class name with possible namespaces prepended
                                                // namespaces will be removed from className now
+        QString classNameFull = className_stub; 
+
             int namespace_count = 0;
             QString namespace_tmp = className_stub;
             str << endl;
             for(;;) {
                 int pos = namespace_tmp.find( "::" );
-                if( pos < 0 )
-                    {
+            if( pos < 0 ) {
                     className_stub = namespace_tmp;
                     break;
                     }
@@ -123,7 +125,9 @@ void generateStubImpl( const QString& id
             str << "{" << endl;
             str << "}" << endl << endl;
 
-            str << className_stub << "::" << className_stub << "( DCOPClient* client, const QCString& app, const QCString& obj )" << endl;
+        str << className_stub << "::" << className_stub 
+            << "( DCOPClient* client, const QCString& app, const QCString& obj )" 
+            << endl;
             str << "  : ";
         
             str << "DCOPStub( client, app, obj )" << endl;
@@ -142,7 +146,9 @@ void generateStubImpl( const QString& id
 	    // Write marshalling code
 	    QDomElement s = e.firstChild().toElement();
 	    for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
-		if (s.tagName() == "FUNC") {
+            if (s.tagName() != "FUNC")
+                continue;
+
 		    QDomElement r = s.firstChild().toElement();
 		    Q_ASSERT( r.tagName() == "TYPE" );
 		    QString result = r.firstChild().toText().data();
@@ -186,7 +193,6 @@ void generateStubImpl( const QString& id
 		
 		    str << "{" << endl ;
 
-		
 		    funcName += "(";
 		    first = TRUE;
 		    for( QStringList::Iterator it = argtypes.begin(); it != argtypes.end(); ++it ){
@@ -207,10 +212,11 @@ void generateStubImpl( const QString& id
 			str << "    QByteArray data;" << endl;
 			if ( !args.isEmpty() ) {
 			    str << "    QDataStream arg( data, IO_WriteOnly );" << endl;
-			    for( QStringList::Iterator args_count = args.begin(); args_count != args.end(); ++args_count ){
+                    for( QStringList::Iterator args_count = args.begin(); 
+                         args_count != args.end(); 
+                         ++args_count )
 				str << "    arg << " << *args_count << ";" << endl;
 			    }
-			}
 
                         str << "    dcopClient()->send( app(), obj(), \"" << funcName << "\", data );" << endl;
                         str << "    setStatus( CallSucceeded );" << endl;
@@ -237,10 +242,11 @@ void generateStubImpl( const QString& id
 		
 			if ( !args.isEmpty() ) {
 			    str << "    QDataStream arg( data, IO_WriteOnly );" << endl;
-			    for( QStringList::Iterator args_count = args.begin(); args_count != args.end(); ++args_count ){
+                    for( QStringList::Iterator args_count = args.begin(); 
+                         args_count != args.end(); 
+                         ++args_count )
 				str << "    arg << " << *args_count << ";" << endl;
 			    }
-			}
 			str << "    if ( dcopClient()->call( app(), obj(), \"" << funcName << "\",";
 			str << " data, replyType, replyData ) ) {" << endl;
 			if ( result != "void" ) {
@@ -262,14 +268,10 @@ void generateStubImpl( const QString& id
 		    }
 		    str << "}" << endl << endl;
 		}
-	    }
 
-            for(;
-                 namespace_count > 0;
-                 --namespace_count )
+        for( ; namespace_count > 0; --namespace_count )
                 str << "} // namespace" << endl;
             str << endl;
-	}
     }
     impl.close();
 }


More information about the kde-core-devel mailing list