[Kde-bindings] KDE/kdebindings/kalyptus
Arno Rehn
kde at arnorehn.de
Sat Jun 28 18:51:42 UTC 2008
SVN commit 825590 by arnorehn:
* Resolve typedefs in kalyptus.
CCMAIL: kde-bindings at kde.org
M +4 -0 ChangeLog
M +2 -6 kalyptusCxxToSmoke.pm
M +86 -15 kalyptusDataDict.pm
--- trunk/KDE/kdebindings/kalyptus/ChangeLog #825589:825590
@@ -1,3 +1,7 @@
+2008-06-28 Arno Rehn <arno at arnorehn.de>
+
+ * Resolve typedefs in kalyptus.
+
2008-06-19 Arno Rehn <arno at arnorehn.de>
* Prefer const methods over non-const methods in csharp, too.
--- trunk/KDE/kdebindings/kalyptus/kalyptusCxxToSmoke.pm #825589:825590
@@ -113,13 +113,11 @@
# but that one would need to be separated (builtins vs normal classes)
%typedeflist =
(
- 'Akonadi::Collection::Id' => 'long',
- 'Collection::Id' => 'long',
- 'Akonadi::Entity::Id' => 'long',
'GLenum' => 'int',
'GLint' => 'int',
'GLuint' => 'uint',
'ksocklen_t' => 'uint',
+ 'long long' => 'long',
'mode_t' => 'long',
'MSG*' => 'void*',
'pid_t' => 'int',
@@ -162,6 +160,7 @@
'unsigned char' => 'uchar',
'unsigned int' => 'uint',
'unsigned long int' => 'ulong',
+ 'unsigned long long' => 'ulong',
'unsigned long' => 'ulong',
'unsigned short int' => 'ushort',
'unsigned short' => 'ushort',
@@ -705,9 +704,6 @@
# Resolve type in full, e.g. for QSessionManager::RestartHint
# (x_QSessionManager doesn't inherit QSessionManager)
$arg->{ArgType} = kalyptusDataDict::resolveType($arg->{ArgType}, $classNode, $rootnode);
- # hack. I think there is a better place for this, but where? and how? kalyptusDataDict maybe?
- $arg->{ArgType} = 'Akonadi::Collection::Id' if ($arg->{ArgType} eq 'Collection::Id');
-
# Only add the type if the class using it is not defined in another module.
# If the method is virtual, add the type anyway. A class in the current module might reimplement
# that method.
--- trunk/KDE/kdebindings/kalyptus/kalyptusDataDict.pm #825589:825590
@@ -2851,27 +2851,39 @@
{
my ( $argType, $contextClass, $rootnode ) = @_;
- #print "resolveTypeInternal type:'$argType' context:'$contextClass->{astNodeName}' ($contextClass)\n";
-
my $contextClassName = join( "::", kdocAstUtil::heritage($contextClass) );
+ #print "resolveTypeInternal type:'$argType' context:'$contextClassName' ($contextClass)\n";
+
# 'A' resolves to 'A' in context 'A' ;) (i.e. classname itself)
- return $contextClassName if ( $argType eq $contextClass->{astNodeName} );
+ return $contextClassName if ( $argType eq $contextClass->{astNodeName}
+ && $contextClass->{NodeType} ne 'namespace' );
# Try as an identifier of contextClass
#print "Trying as ".$contextClassName."::".$argType."\n";
my $node = kdocAstUtil::findRef( $rootnode, $contextClassName."::".$argType );
- #print "Found as $node->{NodeType}\n" if $node;
+ #print "Found as $node->{NodeType}, full name: $contextClassName" . "::$argType, given: $argType, context: $contextClassName\n" if $node;
return $contextClassName."::".$argType if ( $node
+ && $node->{NodeType} ne 'namespace'
&& $node->{NodeType} ne 'method'
&& $node->{NodeType} ne 'deleted'
&& $node->{NodeType} ne 'var' );
my $found;
+ # Look in the heritage outer lexical scopes, and try for each one
+ Iter::Heritage( $contextClass,
+ sub {
+ my ( $outer, $name, $type, $template ) = @_;
+ unless ($found) {
+ $found = resolveTypeInternal( $argType, $outer, $rootnode );
+ }
+ }
+ );
+
# Then look at ancestors, and try for each one
Iter::Ancestors( $contextClass, $rootnode, undef, undef,
sub {
@@ -2883,16 +2895,6 @@
undef
);
- # Look in the heritage outer lexical scopes, and try for each one
- Iter::Heritage( $contextClass,
- sub {
- my ( $outer, $name, $type, $template ) = @_;
- unless ($found) {
- $found = resolveTypeInternal( $argType, $outer, $rootnode );
- }
- }
- );
-
return $found;
}
@@ -2905,7 +2907,7 @@
=cut
-sub resolveType($$$)
+sub resolveTypeInHierarchy($$$)
{
my ( $argType, $contextClass, $rootnode ) = @_;
$argType =~ s/\s*(\*)\s*$/$1/g; # remove space before *
@@ -2954,4 +2956,73 @@
return $prefix.$argType.$suffix;
}
+=head2
+
+ Look up a type via resolveTypeInHierarchy and resolve
+ the typedef, if it's one.
+
+=cut
+
+sub resolveType {
+ my ( $argType, $contextClass, $rootnode, $r ) = @_;
+ $argType = resolveTypeInHierarchy( $argType, $contextClass, $rootnode );
+
+ my $prefix = $argType =~ s/^const\s+// ? 'const ' : '';
+ my $suffix = $argType =~ s/\s*([\&\*]+)$// ? $1 : '';
+ $argType =~ s/\s+$//;
+
+ return $r if ($r eq $argType); # oops, some strange recursion here
+ # if the type the typedef points to is private or protected, this value is returned
+ $r = $argType unless defined $r;
+
+ my $node = kdocAstUtil::findRef($rootnode, $argType);
+ if (!$node && $argType =~ /::/ && $argType !~ /<.*>/) { # don't try for templates
+ # remove the last ::Foo from the type and try again, with
+ # the resulting thing as a context node
+ my @list = split('::', $argType);
+ my $type = pop(@list);
+ my $context = join('::', @list);
+ my $contextNode = kdocAstUtil::findRef($rootnode, $context);
+ my $ret = resolveType( $argType, $contextNode, $rootnode, $argType ) if $contextNode;
+ if ($ret ne $argType && $ret ne '') {
+ return $prefix.$ret.$suffix;
+ } else { # ok, this didn't work, too
+ # this time try with the thing that was stripped off before as $argType
+ $ret = resolveType( $type, $contextNode, $rootnode, $type );
+ if ($ret ne $type && $ret ne '') {
+ return $prefix.$ret.$suffix
+ } else {
+ # Try to prepend the outer lexical scopes of the context node.
+ # Useful if $argType is a type addressed through a subclass of the class
+ # in which it was defined and not fully qualified.
+ # example: $argType is 'Collection::Id' in context of namespace 'Akonadi'.
+ # 'Id' is a typedef defined in Akonadi::Entity, which is a superclass of
+ # Akonadi::Collection
+ my $found;
+ Iter::Heritage( $contextClass,
+ sub {
+ my ( $outer, $name, $type, $template ) = @_;
+ unless ($found) {
+ my $ret = resolveType( $name.'::'.$argType, undef, $rootnode, $argType );
+ $found = $ret if ($ret ne $argType && $ret ne '');
+ }
+ },
+ undef );
+ return $prefix.$found.$suffix if $found;
+ }
+ }
+ }
+ return $r if ($node->{Access} eq 'private' || $node->{Access} eq 'protected' || $argType eq 'enum');
+ if ( $node && $node->{NodeType} eq 'typedef'
+ && $argType !~ /Display/
+ && $argType !~ /KMD5::Digest/
+ && $argType !~ /K_UID/
+ && $argType !~ /K_GID/ )
+ {
+ return $prefix.resolveType($node->{Type}, $node, $rootnode, $argType).$suffix;
+ } else {
+ return $prefix.$argType.$suffix;
+ }
+}
+
1;
More information about the Kde-bindings
mailing list