[Kde-bindings] KDE/kdebindings

Arno Rehn kde at arnorehn.de
Sat Jun 7 11:13:54 UTC 2008


SVN commit 817998 by arnorehn:

* C++ namespaces are now mapped to C# namespaces. If a class is in no namespace, it
  is put into 'Kimono' (or 'Qyoto' for Qt).
* The functions within a namespace are put into a class called 'Global' in the C#
  namespace.
* Added the qxmlstream.h header.

CCMAIL: kde-bindings at kde.org



 M  +7 -0      kalyptus/ChangeLog  
 M  +67 -45    kalyptus/kalyptusCxxToKimono.pm  
 M  +1 -0      smoke/qt/header_list  


--- trunk/KDE/kdebindings/kalyptus/ChangeLog #817997:817998
@@ -1,3 +1,10 @@
+2008-06-07  Arno Rehn  <arno at arnorehn.de>
+
+	* C++ namespaces are now mapped to C# namespaces. If a class is in no namespace, it
+	  is put into 'Kimono' (or 'Qyoto' for Qt).
+	* The functions within a namespace are put into a class called 'Global' in the C#
+	  namespace.
+
 2008-05-31  Arno Rehn  <arno at arnorehn.de>
 
 	* Added classlist support for the kimono target.
--- trunk/KDE/kdebindings/kalyptus/kalyptusCxxToKimono.pm #817997:817998
@@ -122,7 +122,7 @@
    'qint16' => 'short',
    'Q_INT16' => 'short',
    'qint32' => 'int',
-   'qint32&' => 'int&',
+   'qint32&' => 'int',
    'Q_INT32' => 'int',
    'qint8' => 'char',
    'Q_INT8' => 'char',
@@ -173,6 +173,7 @@
 # with the 'partial' modifier in the class definition
 %partial_classes =
 (
+   'KConfigGroup' => '1',
    'QAbstractItemModel' => '1',
    'QApplication' => '1',
    'QBrush' => '1',
@@ -393,6 +394,8 @@
     'QStringList' => 'List<string>',
     'QStringList*' => 'List<string>',
     'QStringList&' => 'List<string>',
+    'QVariantList' => 'List<QVariant>',
+    'QVariantList*' => 'List<QVariant>',
     'QVariantList&' => 'List<QVariant>',
     'QVector<QColor>' => 'List<QColor>',
     'QVector<QColor>&' => 'List<QColor>',
@@ -527,8 +530,6 @@
 	} elsif ( kalyptusDataDict::ctypemap($cplusplusType) =~ /^\s*(unsigned )?short\s*\*/ ) {
 #		return "short";
 		return "ref short";
-	} elsif ( $cplusplusType =~ /KCmdLineOptions/ ) {
-		return "string[][]";	
 	} elsif ( $maptypeslist{$cplusplusType} ) {
 		return $maptypeslist{$cplusplusType};
 	} elsif ( $arraytypeslist{$cplusplusType} ) {
@@ -617,6 +618,7 @@
 			$node = kdocAstUtil::findRef( $rootnode, $1 );
 			$item = kdocAstUtil::findRef( $node, $2 ) if defined $node;
 			if (defined $item && $item->{NodeType} eq 'enum') {
+				return $2 if ($1 eq 'Qt' or $1 eq 'KDE');
 				if ($2 eq 'Type') {
 					return "$1.TypeOf";
 				} else {
@@ -671,7 +673,7 @@
 
 	print STDERR "Preparsing...\n";
 
-	# Preparse everything, to prepare some additional data in the classes and methods
+	# Preparse flags
 	Iter::LocalCompounds( $rootnode, sub { preParseFlags( shift ); } );
 
 	# Preparse everything, to prepare some additional data in the classes and methods
@@ -759,7 +761,6 @@
 			|| $className eq 'KAccelGen'
 			|| $className eq 'KAccelGen'
 			|| $className eq 'KDateTime::Spec'
-			|| $className eq 'KDE'
 			|| $className eq 'KDEDModule'
 			|| $className eq 'KDialogButtonBox'
 			|| $className eq 'KDirOperator'
@@ -1192,7 +1193,7 @@
 			undef
 		);
         
-	my ($methodCode, $staticMethodCode, $interfaceCode, $proxyInterfaceCode, $signalCode, $extraCode, $notConverted) = generateAllMethods( $node, $#ancestors + 1, 
+	my ($methodCode, $staticMethodCode, $interfaceCode, $proxyInterfaceCode, $signalCode, $extraCode, $enumCode, $notConverted) = generateAllMethods( $node, $#ancestors + 1, 
 																		\%csharpMethods, 
 																		$node, 
 																		1, 
@@ -1203,10 +1204,11 @@
 	# Add method calls for the interfaces implemented by the class
 	foreach my $ancestor_node ( @ancestor_nodes ) {
 		if ( defined $interfacemap{$ancestor_node->{astNodeName}} && ($#ancestors > 0) ) {
-			my ($meth, $static, $interf, $proxyInterf, $sig, $extra, $notconv) = generateAllMethods( $ancestor_node, 0, \%csharpMethods, $node, 0, $addImport );
+			my ($meth, $static, $interf, $proxyInterf, $sig, $extra, $enum, $notconv) = generateAllMethods( $ancestor_node, 0, \%csharpMethods, $node, 0, $addImport );
 			$methodCode .= $meth;
 			$staticMethodCode .= $static;
 			$extraCode .= $extra;
+			$enumCode .= $enum;
 			$interfaceCode .= $interf;
 			$proxyInterfaceCode .= $proxyInterf;
 			$notConverted .= $notconv;
@@ -1214,10 +1216,11 @@
 	}
 	
 	my $globalSpace = kdocAstUtil::findRef( $rootnode, $main::globalSpaceClassName );
-	my ($meth, $static, $interf, $proxyInterf, $sig, $extra, $notconv) = generateAllMethods( $globalSpace, 0, \%csharpMethods, $node, 0, $addImport );
+	my ($meth, $static, $interf, $proxyInterf, $sig, $extra, $enum, $notconv) = generateAllMethods( $globalSpace, 0, \%csharpMethods, $node, 0, $addImport );
 	$methodCode .= $meth;
 	$staticMethodCode .= $static;
 	$extraCode .= $extra;
+	$enumCode .= $enum;
 	$interfaceCode .= $interf;
 	$proxyInterfaceCode .= $proxyInterf;
 	$notConverted .= $notconv;
@@ -1236,6 +1239,10 @@
 		}
 	}
 
+	$classCode .= "\n$enumCode\n" if ($node->{NodeType} eq 'namespace'
+	                                  && $csharpClassName ne 'Qt'
+	                                  && $csharpClassName ne 'KDE');
+
 	if ( defined $interfacemap{$csharpClassName} ) {
 		$classCode .= "\n$indent\tpublic interface " . $interfacemap{$csharpClassName} . " {\n";
 		$classCode .= $interfaceCode;
@@ -1249,6 +1256,8 @@
 		$classdec .= "\t[SmokeClass(\"$className\")]\n";
 #		$classdec .= "\tnamespace $className {\n";
 
+		$csharpClassName = 'Global' unless ($csharpClassName eq 'Qt' || $csharpClassName eq 'KDE');
+
 		if ( $partial_classes{$csharpClassName} ) {
 			$classdec .= "\tpublic partial class $csharpClassName : Object {\n";
 		} else {
@@ -1355,7 +1364,7 @@
 		$classdec .= " {\n";
 		$classdec .= " \t\tprotected $csharpClassName(Type dummy) : base((Type) null) {}\n";
 	}
-		
+	
 	$classCode .= "\n";
 	if ( $csharpClassName !~ /^Q/ or $signalCode ne '' ) {
 		my $signalLink = '';
@@ -1373,19 +1382,22 @@
 	
 	$classCode .= indentText($indent, $classdec);
 
-    Iter::MembersByType ( $node, undef,
-		sub {	my ($node, $subclassNode ) = @_;
-			if ( $subclassNode->{NodeType} eq 'class' && !defined $subclassNode->{Compound} ) {
-				$classCode .= generateClass($subclassNode, $packagename, $namespace, $indent . "\t", $addImport);
-			}
-		}, undef );
-
-    Iter::MembersByType ( $node, undef,
-		sub {	my ($node, $subclassNode ) = @_;
-			if ( $subclassNode->{NodeType} eq 'class' && $subclassNode->{Compound} ) {
-				$classCode .= generateClass($subclassNode, $packagename, $namespace, $indent . "\t", $addImport);
-			}
-		}, undef );
+	# only generate nested classes
+	if ($node->{NodeType} ne 'namespace') {
+		Iter::MembersByType ( $node, undef,
+			sub {	my ($node, $subclassNode ) = @_;
+				if ( $subclassNode->{NodeType} eq 'class' && !defined $subclassNode->{Compound} ) {
+					$classCode .= generateClass($subclassNode, $packagename, $namespace, $indent . "\t", $addImport);
+				}
+			}, undef );
+	
+		Iter::MembersByType ( $node, undef,
+			sub {	my ($node, $subclassNode ) = @_;
+				if ( $subclassNode->{NodeType} eq 'class' && $subclassNode->{Compound} ) {
+					$classCode .= generateClass($subclassNode, $packagename, $namespace, $indent . "\t", $addImport);
+				}
+			}, undef );
+	}
     
 	if ($methodCode ne '') {
 		if ( $#ancestors < 0 ) {
@@ -1403,7 +1415,10 @@
 		$classCode .= "$indent\t\t}\n";
 	}
 
-	$classCode .= indentText($indent, $extraCode);	
+	$classCode .= indentText("$indent\t", "$enumCode") unless ($node->{NodeType} eq 'namespace'
+	                                                           && $csharpClassName ne 'Qt'
+	                                                           && $csharpClassName ne 'KDE');
+	$classCode .= indentText($indent, $extraCode);
 	$classCode .= indentText($indent, $notConverted);	
 	$classCode .= indentText($indent, $methodCode);	
 	$classCode .= indentText($indent, $staticMethodCode);	
@@ -1466,9 +1481,17 @@
 		$packagename = "Kimono";
 	}
 
-	my $namespace;
-	if ($className =~ /([^:]*)::.*/ && $1 != $packagename) {
-		$namespace = $1;
+	my $namespace, my @parentClasses;
+	my $first = 1;
+	
+	foreach my $n (kdocAstUtil::refHeritage($node)) {
+		if ($n->{NodeType} eq 'namespace') {
+			$namespace .= "." if !$first;
+			$namespace .= "$n->{astNodeName}"
+		} else {
+			push @parentClasses, $n->{astNodeName} if $n != $node;
+		}
+		$first = 0;
 	}
 
 	my %addImport = ();
@@ -1481,9 +1504,12 @@
 	print CLASS "//Auto-generated by kalyptus. DO NOT EDIT.\n";
 #	print CLASS "//Auto-generated by $0. DO NOT EDIT.\n";
 	
-	print CLASS "namespace $packagename {\n\n";
+	$namespace = undef if ($namespace eq 'KDE' or $namespace eq 'Qt');
+	# only the core classes go into the Kimono namespace, others have there own one.
 	if (defined $namespace) {
-		print CLASS "\tnamespace $namespace {\n\n";
+		print CLASS "namespace $namespace {\n\n";
+	} else {
+		print CLASS "namespace $packagename {\n\n";
 	}
 
 	print CLASS "\tusing System;\n";
@@ -1500,10 +1526,6 @@
 
 	print CLASS $classCode;
 
-	if (defined $namespace) {
-		print CLASS "\t}\n";
-	}
-
 	print CLASS "}\n";
 
 	close CLASS;
@@ -2622,7 +2644,7 @@
 	}
 	
 	if ( defined $m->{DocNode} ) {
-		my $csharpdocComment = printCSharpdocComment( $m->{DocNode}, "", "\t\t/// ", "" );
+		my $csharpdocComment = printCSharpdocComment( $m->{DocNode}, "", "\t/// ", "" );
 		$methodCode .=  $csharpdocComment unless $csharpdocComment =~ /^\s*$/;
 	}
 	
@@ -2637,7 +2659,7 @@
 	if ( $m->{astNodeName} eq 'Type') {
 		# Enums and capitalized method names share the same namespace in C#, so add
 		# 'E_' to the front to avoid a clash.
-		$methodCode .= "\t\tpublic enum TypeOf {\n";
+		$methodCode .= "\tpublic enum TypeOf {\n";
 	} elsif ( $m->{astNodeName} eq 'ConversionFlag'
 				|| ($classNode->{astNodeName} eq 'QTextOption' and $m->{astNodeName} eq 'Flag')
 				|| ($classNode->{astNodeName} eq 'Qt' and $m->{astNodeName} eq 'Modifier')
@@ -2645,9 +2667,9 @@
 				|| ($classNode->{astNodeName} eq 'QAccessible' and $m->{astNodeName} eq 'StateFlag')
 				|| ($classNode->{astNodeName} eq 'Qt' and $m->{astNodeName} eq 'KeyboardModifier') )
 	{
-		$methodCode .= "\t\tpublic enum " . $m->{astNodeName} . " : long {\n";
+		$methodCode .= "\tpublic enum " . $m->{astNodeName} . " : long {\n";
 	} else {
-		$methodCode .= "\t\tpublic enum " . $m->{astNodeName} . " {\n";
+		$methodCode .= "\tpublic enum " . $m->{astNodeName} . " {\n";
 	}
 	
 	my @enums = split(",", $m->{Params});
@@ -2669,7 +2691,7 @@
 #		$enum =~ s/Qt::ControlModifier/Qt.KeyboardModifier.ControlModifier/;
 #		$enum =~ s/Qt::AltModifier/Qt.KeyboardModifier.AltModifier/;
 		if ($m->{astNodeName} ne 'KeyboardModifier') {
-			$enum =~ s/KeyboardModifierMask/Qt.KeyboardModifier.KeyboardModifierMask/;
+			$enum =~ s/KeyboardModifierMask/KeyboardModifier.KeyboardModifierMask/;
 		}
 		if ($m->{astNodeName} ne 'PolicyFlag') {
 			$enum =~ s/GrowFlag/PolicyFlag.GrowFlag/;
@@ -2681,12 +2703,13 @@
 		$enum =~ s/\s//g;
 		$enum =~ s/::/./g;
 		$enum =~ s/::([a-z])/./g;
+		$enum =~ s/\.\././g;
 		$enum =~ s/\(mode_t\)//;
 		$enum =~ s/internal/_internal/;
 		$enum =~ s/fixed/_fixed/;
 		$enum =~ s/sizeof\(void\*\)/4/;
 		if ( $enum =~ /(.*)=([-0-9]+)$/ ) {
-			$methodCode .= "\t\t\t$1 = $2,\n";
+			$methodCode .= "\t\t$1 = $2,\n";
 			$enumCount = $2;
 			$enumCount++;
 		} elsif ( $enum =~ /(.*)=(.*)/ ) {
@@ -2700,17 +2723,17 @@
 				$value =~ s/^SH_/QStyle.StyleHint.SH_/;
 			}
 
-			$methodCode .= "\t\t\t$name = $value,\n";
+			$methodCode .= "\t\t$name = $value,\n";
 			if ($value =~ /(0xf0000000)|(0xffffffff)/) {
 				$methodCode =~ s/enum ((E_)?[^\s]*)/enum $1 : uint/;
 			}
 		} else {
-			$methodCode .= "\t\t\t$enum = $enumCount,\n";
+			$methodCode .= "\t\t$enum = $enumCount,\n";
 			$enumCount++;
 		}
 	}
 		
-	$methodCode .= "\t\t}\n";
+	$methodCode .= "\t}\n";
 	$methodNumber++;
 		
     return ( $methodCode );
@@ -2882,6 +2905,7 @@
     my $signalCode = '';
     my $notConverted = '';
     my $extraCode = '';
+    my $enumCode = '';
     $methodNumber = 0;
     #my $className = $classNode->{astNodeName};
     my $className = join( "::", kdocAstUtil::heritage($classNode) );
@@ -2924,7 +2948,7 @@
 				
 	if ( $methodNode->{NodeType} eq 'enum' and $classNode->{astNodeName} eq $mainClassNode->{astNodeName} ) {
 	    my ($code) = generateEnum( $classNode, $methodNode, 0 );
-	    $extraCode .= $code;
+	    $enumCode .= $code;
 	}
 				}, undef );
 	
@@ -3026,7 +3050,7 @@
 			$methodNumber++;
     }
                                                                
-    return ( $methodCode, $staticMethodCode, $interfaceCode, $proxyInterfaceCode, $signalCode, $extraCode, $notConverted );
+    return ( $methodCode, $staticMethodCode, $interfaceCode, $proxyInterfaceCode, $signalCode, $extraCode, $enumCode, $notConverted );
 }
 
 # Return 0 if the class has no virtual dtor, 1 if it has, 2 if it's private
@@ -4212,7 +4236,6 @@
 		$line =~ s/KTrader::OfferList/ArrayList/g;
 		$line =~ s/QString::null/null/g;
 		$line =~ s/(const )?QC?String(\s*&)?/string/g;
-		$line =~ s/(const )?KCmdLineOptions\s*(\w+)\[\]/string[][] $2/;
 		$line =~ s/KCmdLineLastOption//g;
 		$line =~ s/virtual //g;
 		$line =~ s/~\w+\(\)((\s*{\s*})|;)//g;
@@ -4317,7 +4340,6 @@
 	$returntext =~ s/QStringList/List<string>/g;
 	$returntext =~ s/([Aa]) ArrayList/$1n ArrayList/g;
 	$returntext =~ s/QString/string/g;
-	$returntext =~ s/KCmdLineOptions/string[][]/;
 	$returntext =~ s!\\note!<b>Note:<\b>!g;
 	$returntext =~ s!\\(code|verbatim)!<pre>!g;
 	$returntext =~ s!\\(endcode|endverbatim)!</pre>!g;
--- trunk/KDE/kdebindings/smoke/qt/header_list #817997:817998
@@ -314,6 +314,7 @@
 qsvgwidget.h
 qdom.h
 qxml.h
+qxmlstream.h
 qdbusabstractadaptor.h
 qdbusabstractinterface.h
 qdbusargument.h



More information about the Kde-bindings mailing list