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

List:       kde-commits
Subject:    KDE/kdelibs/kjsembed
From:       Matt Broadstone <mbroadst () gmail ! com>
Date:       2006-10-06 4:03:29
Message-ID: 1160107409.199207.18304.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 592886 by mbroadst:

OK, big change here is we check for 'problematic types' - a method was added to \
util.js to check for this - currently it has int* qreal* and bool* (before you freak \
out bunce, bool* was just so I could keep compiling, not permanent). Also changed \
copyHeaders.sh so it was more likely to work on YOUR system, not just mine. Also \
added the kind of scary extractString to binding_support, perhaps this should use \
UString.qstring().toUtf8() as we talked about the other day? Probably some other \
things I forgot..

 M  +25 -1     autobind/shared/util.js  
 M  +3 -3      autobind/values/copyHeaders.sh  
 M  +2 -13     autobind/values/generate.js  
 M  +31 -29    autobind/values/generatebinding.js  
 M  +19 -0     kjsembed/binding_support.h  


--- trunk/KDE/kdelibs/kjsembed/autobind/shared/util.js #592885:592886
@@ -157,8 +157,9 @@
     return (compoundEnums[paramType]);
 }
 
-// function isCompoundEnum( paramType )
+// function isEnum( paramType )
 //   paramType - The parameter type to check (preferably sans embellishments).
+//   globalEnums - Associative array of Qt:: namesapce enum types
 //   compoundEnums - Associative array of enum types to containing objects
 // Returns true if the paramType is any known enum type.
 function isEnum( paramType, globalEnums, compoundEnums )
@@ -167,3 +168,26 @@
             compoundEnums[paramType]);
 }
 
+// function hasNoProblematicTypes( memberElement )
+//   memberElement - element of compound member
+// This function temporarily checks for paramters we can't handle right
+// now due to limitations in KJS. Potentially will be fixed soon.
+// returns true if it has no problematic types
+function hasNoProblematicTypes( memberElement )
+{
+    var memberArgList = memberElement.elementsByTagName('param');
+    for ( i = 0; i < memberArgList.count(); ++i )
+    {
+        var param = memberArgList.item(i).toElement();
+        var paramElement = param.firstChildElement('type').toElement();
+        var paramType = paramElement.toString();
+
+        if ( contains(paramType,'int *') ||
+             contains(paramType, 'qreal *') ||
+             contains(paramType, 'bool *') )
+            return false;
+    }
+    return true;
+}
+
+
--- trunk/KDE/kdelibs/kjsembed/autobind/values/copyHeaders.sh #592885:592886
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-QTDIR=/home/kde4/kdesvn/qt-copy
+HEADERDIR=$QTDIR
 HEADERS="qbitarray.h   qbytearray.h  qcursor.h      qicon.h
          qline.h       qpalette.h    qpoint.h       qregexp.h
          qsizepolicy.h qurl.h        qbitmap.h      qchar.h
@@ -8,11 +8,11 @@
          qpolygon.h    qregion.h     qstring.h      qbrush.h
          qcolor.h      qfont.h       qkeysequence.h qmatrix.h
          qpixmap.h     qrect.h       qsize.h        qtextformat.h
-         qmatrix.h qnamespace.h qglobal.h"
+         qmatrix.h     qnamespace.h  qglobal.h      qrgb.h"
 
 for header in $HEADERS
 do
-    cp -Lv $QTDIR/include/Qt/$header ./input
+    cp -Lv $HEADERDIR/include/Qt/$header ./input
 done
 
 
--- trunk/KDE/kdelibs/kjsembed/autobind/values/generate.js #592885:592886
@@ -130,8 +130,8 @@
     var compoundElement = nodeList.item(x).toElement();
     var compoundKind = compoundElement.attribute('kind');
     if (( compoundKind == 'class' ) ||
-	( compoundKind == 'struct' ) ||
-	( compoundKind == 'namespace' ))
+        ( compoundKind == 'struct' ) ||
+        ( compoundKind == 'namespace' ))
     {
         var classRootElement = process_class( compoundElement );
         var compoundDef = \
classRootElement.firstChildElement('compounddef').toElement(); @@ -147,17 +147,6 @@
                 var qualifiedEnum = compoundName + "::" + enumName;
                 enum_array[qualifiedEnum] = true;
                 println("   Added enum " + qualifiedEnum);
- 
-/*
-                var enumList = memberElement.elementsByTagName( "enumvalue" );
-                for ( z = 0; z < enumList.length(); ++z )
-                {
-                    var enumValue = \
                enumList.item(z).toElement().firstChildElement('name').toElement().toString();
                
-                    var qualifiedEnum = enumName + "::" + enumValue;
-                    enum_array[qualifiedEnum] = 1;
-                    println( "   Added enum " + qualifiedEnum );
-                }
-*/
             }
         }
     }
--- trunk/KDE/kdelibs/kjsembed/autobind/values/generatebinding.js #592885:592886
@@ -52,18 +52,18 @@
 */
     else if ( isInteger(coreParamType) )  // integer value
     {
-	extracted +=
-	    '        ' + coreParamType + ' ' + paramVar + ' = KJSEmbed::extractInteger<' + \
coreParamType + '>(exec, args, ' + paramIdx; 	             '       bool ok = \
                KJSEmbed::extractBool(exec, args, ' + paramIdx;
-        
-        if (!paramDefault.isNull()) 	 
-            extracted += ', ' + paramDefault.toString() + ');\n'; 	 
-        else 	 
-            extracted += ');\n'; 	 
-        
-        return extracted;    
+        extracted +=
+            '        ' + coreParamType + ' ' + paramVar + ' = \
KJSEmbed::extractInteger<' + coreParamType + '>(exec, args, ' + paramIdx; 	           \
'       bool ok = KJSEmbed::extractBool(exec, args, ' + paramIdx; +
+        if (!paramDefault.isNull())
+            extracted += ', ' + paramDefault.toString() + ');\n';
+        else
+            extracted += ');\n';
+
+        return extracted;
     }
     else if ( isNumber(coreParamType) )  // integral value
-	{
+    {
         extracted +=
             '        ' + coreParamType + ' ' + paramVar + ' = \
KJSEmbed::extractNumber<' + coreParamType + '>(exec, args, ' + paramIdx;  
@@ -272,7 +272,7 @@
     else {
         enums = 'const Enumerator KJSEmbed::' + compound.data + '::p_enums[] = {{0, \
0 }};\n';  }
- 
+
     return enums;
 }
 
@@ -310,7 +310,7 @@
             //            println( '          Found ' + overloadList[args].length + \
' override with ' + args + ' arguments' );  }
     }
-     
+
     return overloadList;
 }
 
@@ -329,9 +329,9 @@
         '//  ' + memberName  + '\n' +
         'KJS::JSValue *'+ memberName + '( KJS::ExecState *exec, KJS::JSObject *self, \
const KJS::List &args ) \n' +  '{ \n';
-    
+
     method += '    Q_UNUSED(args); \n';
-            
+
     method +=
         '    KJS::JSValue *result = KJS::Null(); \n' +
         '    KJSEmbed::' + compound.bindingBase + ' *imp = \
KJSEmbed::extractBindingImp<KJSEmbed::' + compound.bindingBase + '>(exec, self); \n' \
+ @@ -339,7 +339,7 @@
         '        return KJS::throwError(exec, KJS::GeneralError, "No implementation? \
Huh?");\n' +  '\n' +
         '    ' + compound.name + ' value = imp->value<' + compound.name + '>();\n';
-        
+
     for (var idx = 0; idx < overloadList.length; ++idx)
     {
         if (!overloadList[idx])
@@ -378,7 +378,7 @@
             funcCallStart +=
                 methodType + ' tmp = value.' + memberName + '(';
             if ( compound.globalEnums[coreMethodType] ||  // Enum Value
-		 isInteger(coreMethodType) )
+                 isInteger(coreMethodType) )
             {
                 funcCallEnd += indent +
                     '        result = KJS::Number( tmp );\n';
@@ -420,13 +420,13 @@
                     paramVar = 'arg' + paramIdx;
                 tmpArgs += paramVar + ', ';
             }
-        
+
             if (tmpArgs != '') 
             {
                 var tmpIdx = tmpArgs.lastIndexOf(',');
                 tmpArgs = tmpArgs.substr(0, tmpIdx);
             }
-        
+
             method += construct_parameters(compound, overloadList[idx], idx, \
funcCallStart, funcCallEnd);  }
         else
@@ -470,7 +470,8 @@
              ( memberProt == 'public' ) &&
              ( memberName.indexOf('operator') == -1 ) &&     // Make sure this is \
                not an operator.
              ( memberName.indexOf(compound.name) == -1 ) &&  // Not a ctor
-             ( contains(memberStatic, 'no') ))               // Not a static method
+             ( contains(memberStatic, 'no') ) &&             // Not a static method
+             ( hasNoProblematicTypes(memberElement) ) )
         {
             if (processed[memberName])
             {
@@ -518,12 +519,12 @@
         var numParams = memberElement.elementsByTagName("param").count();
         if ( ( memberKind == 'function' ) &&
              ( memberProt == 'public' ) &&
-             ( memberName.indexOf('operator') == -1 ) &&     // Make sure this is \
                not an operator.
-             ( memberName.indexOf(compound.name) == -1 ) &&  // Make sure this is \
                not a ctor or dtor
-             ( contains(memberStatic, "no") ) )              // Not a static method
+             ( memberName.indexOf('operator') == -1 ) &&     // Not an operator.
+             ( memberName.indexOf(compound.name) == -1 ) &&  // Not a ctor or dtor
+             ( contains(memberStatic, "no") ) &&             // Not a static method
+             ( hasNoProblematicTypes(memberElement) ) )
         {
-            // make sure only one lut entry per member
-            var memberCacheId = memberName + numParams;
+            var memberCacheId = memberName + numParams;      // Only one entry per \
member  if (processed[memberCacheId])
                 continue;
             processed[memberCacheId] = true;
@@ -560,11 +561,12 @@
         var memberKind = memberElement.attribute( 'kind' );
         var memberProt = memberElement.attribute('prot');
         var memberName = \
                memberElement.firstChildElement('name').toElement().toString();
-        if (( memberKind == 'function' ) && // Constructor is a function
-            ( memberProt == 'public' ) && // Make sure it is public
-            ( memberName.indexOf('operator') == -1 ) && // Make sure this is not an \
                operator.
-            ( memberName.indexOf(compound.name) != -1 ) && // This _is_ a ctor
-            ( memberName.indexOf('~') == -1 )) // This is _not_ a dtor
+        if (( memberKind == 'function' ) &&                 // Is a function
+            ( memberProt == 'public' ) &&                   // Is public
+            ( memberName.indexOf('operator') == -1 ) &&     // Not an operator.
+            ( memberName.indexOf(compound.name) != -1 ) &&  // Is a ctor
+            ( memberName.indexOf('~') == -1 ) &&            // Not a dtor
+            ( hasNoProblematicTypes(memberElement) ))
         {
             var memberArgList = memberElement.elementsByTagName('param');
             var args = memberArgList.count();
--- trunk/KDE/kdelibs/kjsembed/kjsembed/binding_support.h #592885:592886
@@ -245,6 +245,25 @@
     KJS::JSValue* createQByteArray( KJS::ExecState *exec, const QByteArray &value );
 
 
+    template<typename T>
+    inline T KJSEMBED_EXPORT extractString(KJS::ExecState *exec, KJS::JSValue \
*value, T defaultValue = T()) +    {
+        if (!value || !value->isString())
+		return defaultValue;
+
+	return (T)(value->toString(exec).ascii());
+    }
+
+    template<typename T>
+    inline T KJSEMBED_EXPORT extractString(KJS::ExecState *exec, const KJS::List \
&args, int idx, T defaultValue = T()) +    {
+        if (args.size() >= idx)
+	    return extractString<T>(exec, args[idx], defaultValue);
+	else
+	    return defaultValue;
+    }
+    
+
    /**
      * Extract a number from a value. If the value cannot convert to an integer or \
                is not present defaultValue is returned
      */


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

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