lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r1220359 - in /lucene/pylucene/trunk/jcc: CHANGES jcc/cpp.py jcc/python.py
Date Sun, 18 Dec 2011 09:41:09 GMT
Author: vajda
Date: Sun Dec 18 09:41:09 2011
New Revision: 1220359

URL: http://svn.apache.org/viewvc?rev=1220359&view=rev
Log:
 - fixed bug with name collision between method and static field of same name

Modified:
    lucene/pylucene/trunk/jcc/CHANGES
    lucene/pylucene/trunk/jcc/jcc/cpp.py
    lucene/pylucene/trunk/jcc/jcc/python.py

Modified: lucene/pylucene/trunk/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=1220359&r1=1220358&r2=1220359&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/CHANGES (original)
+++ lucene/pylucene/trunk/jcc/CHANGES Sun Dec 18 09:41:09 2011
@@ -1,3 +1,7 @@
+Version 2.12 ->
+---------------
+ - fixed bug with name collision between method and static field of same name
+ - 
 
 Version 2.11 -> 2.12
 --------------------

Modified: lucene/pylucene/trunk/jcc/jcc/cpp.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/cpp.py?rev=1220359&r1=1220358&r2=1220359&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/cpp.py (original)
+++ lucene/pylucene/trunk/jcc/jcc/cpp.py Sun Dec 18 09:41:09 2011
@@ -98,6 +98,9 @@ RESERVED = set(['delete', 'and', 'or', '
                 'const', 'bool', 'operator', 'typeof', 'asm',
                 'NULL', 'DOMAIN', 'IGNORE'])
 
+RENAME_METHOD_SUFFIX = '_'
+RENAME_FIELD_SUFFIX = '__'
+
 def cppname(name):
 
     if name in RESERVED:
@@ -598,7 +601,7 @@ def jcc(args):
                 line(out_h, 0, '#define %s_H', '_'.join(names))
 
                 (superCls, constructors, methods, protectedMethods,
-                 fields, instanceFields, declares) = \
+                 methodNames, fields, instanceFields, declares) = \
                     header(env, out_h, cls, typeset, packages, excludes,
                            generics, _dll_export)
 
@@ -607,13 +610,13 @@ def jcc(args):
                 names, superNames = code(env, out_cpp,
                                          cls, superCls, constructors,
                                          methods, protectedMethods,
-                                         fields, instanceFields, 
+                                         methodNames, fields, instanceFields, 
                                          declares, typeset)
                 if moduleName:
                     python(env, out_h, out_cpp,
                            cls, superCls, names, superNames,
                            constructors, methods, protectedMethods,
-                           fields, instanceFields,
+                           methodNames, fields, instanceFields,
                            mappings.get(className), sequences.get(className),
                            renames.get(className),
                            declares, typeset, moduleName, generics,
@@ -762,6 +765,7 @@ def header(env, out, cls, typeset, packa
 
     methods = methods.values()
     sort(methods, fn=_compare)
+    methodNames = set([cppname(method.getName()) for method in methods])
 
     for constructor in constructors:
         if generics:
@@ -874,6 +878,9 @@ def header(env, out, cls, typeset, packa
         for field in fields:
             fieldType = field.getType()
             fieldName = cppname(field.getName())
+            if fieldName in methodNames:
+                print >>sys.stderr, "  Warning: renaming static variable '%s' on class
%s to '%s%s' since it is shadowed by a method of same name." %(fieldName, '.'.join(names),
fieldName, RENAME_FIELD_SUFFIX)
+                fieldName += RENAME_FIELD_SUFFIX
             if fieldType.isPrimitive():
                 line(out, indent, 'static %s %s;',
                      typename(fieldType, cls, False), fieldName)
@@ -925,11 +932,11 @@ def header(env, out, cls, typeset, packa
         line(out, indent, '}')
 
     return (superCls, constructors, methods, protectedMethods,
-            fields, instanceFields, declares)
+            methodNames, fields, instanceFields, declares)
 
 
 def code(env, out, cls, superCls, constructors, methods, protectedMethods,
-         fields, instanceFields, declares, typeset):
+         methodNames, fields, instanceFields, declares, typeset):
 
     className = cls.getName()
     names = className.split('.')
@@ -964,6 +971,8 @@ def code(env, out, cls, superCls, constr
     for field in fields:
         fieldType = field.getType()
         fieldName = cppname(field.getName())
+        if fieldName in methodNames:
+            fieldName += RENAME_FIELD_SUFFIX
         typeName = typename(fieldType, cls, False)
         if fieldType.isPrimitive():
             line(out, indent, '%s %s::%s = (%s) 0;',
@@ -1027,15 +1036,18 @@ def code(env, out, cls, superCls, constr
         for field in fields:
             fieldType = field.getType()
             fieldName = field.getName()
+            cppFieldName = cppname(fieldName)
+            if cppFieldName in methodNames:
+                cppFieldName += RENAME_FIELD_SUFFIX
             if fieldType.isPrimitive():
                 line(out, indent + 2,
                      '%s = env->getStatic%sField(cls, "%s");',
-                     cppname(fieldName), fieldType.getName().capitalize(),
+                     cppFieldName, fieldType.getName().capitalize(),
                      fieldName)
             else:
                 line(out, indent + 2,
                      '%s = new %s(env->getStaticObjectField(cls, "%s", "%s"));',
-                     cppname(fieldName), typename(fieldType, cls, False),
+                     cppFieldName, typename(fieldType, cls, False),
                      fieldName, signature(field))
 
     line(out, indent + 1, '}')

Modified: lucene/pylucene/trunk/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/python.py?rev=1220359&r1=1220358&r2=1220359&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/python.py (original)
+++ lucene/pylucene/trunk/jcc/jcc/python.py Sun Dec 18 09:41:09 2011
@@ -16,6 +16,7 @@ import os, sys, platform, shutil, _jcc
 from itertools import izip
 
 from cpp import PRIMITIVES, INDENT, HALF_INDENT
+from cpp import RENAME_METHOD_SUFFIX, RENAME_FIELD_SUFFIX
 from cpp import cppname, cppnames, absname, typename, findClass
 from cpp import line, signature, find_method, split_pkg, sort
 from cpp import Modifier, Class, Method
@@ -540,7 +541,8 @@ def extension(env, out, indent, cls, nam
 
 
 def python(env, out_h, out, cls, superCls, names, superNames,
-           constructors, methods, protectedMethods, fields, instanceFields,
+           constructors, methods, protectedMethods,
+           methodNames, fields, instanceFields,
            mapping, sequence, rename, declares, typeset, moduleName, generics,
            _dll_export):
 
@@ -664,18 +666,18 @@ def python(env, out_h, out, cls, superCl
                     if name in allMethods:
                         if Modifier.isStatic(allMethods[name][0].getModifiers()):
                             allMethods[name].append(method)
-                        elif name + '_' in allMethods:
-                            allMethods[name + '_'].append(method)
+                        elif name + RENAME_METHOD_SUFFIX in allMethods:
+                            allMethods[name + RENAME_METHOD_SUFFIX].append(method)
                         else:
-                            print >>sys.stderr, "  Warning: renaming static method
'%s' on class %s to '%s_' since it is shadowed by non-static method of same name." %(name,
'.'.join(names), name)
-                            allMethods[name + '_'] = [method]
+                            print >>sys.stderr, "  Warning: renaming static method
'%s' on class %s to '%s%s' since it is shadowed by non-static method of same name." %(name,
'.'.join(names), name, RENAME_METHOD_SUFFIX)
+                            allMethods[name + RENAME_METHOD_SUFFIX] = [method]
                     else:
                         allMethods[name] = [method]
                 else:
                     if name in allMethods:
                         if Modifier.isStatic(allMethods[name][0].getModifiers()):
-                            print >>sys.stderr, "  Warning: renaming static method
'%s' on class %s to '%s_' since it is shadowed by non-static method of same name." %(name,
'.'.join(names), name)
-                            allMethods[name + '_'] = allMethods[name]
+                            print >>sys.stderr, "  Warning: renaming static method
'%s' on class %s to '%s%s' since it is shadowed by non-static method of same name." %(name,
'.'.join(names), name, RENAME_METHOD_SUFFIX)
+                            allMethods[name + RENAME_METHOD_SUFFIX] = allMethods[name]
                             allMethods[name] = [method]
                         else:
                             allMethods[name].append(method)
@@ -1090,7 +1092,11 @@ def python(env, out_h, out, cls, superCl
     for field in fields:
         fieldType = field.getType()
         fieldName = field.getName()
-        value = '%s::%s' %(cppname(names[-1]), cppname(fieldName))
+        cppFieldName = cppname(fieldName)
+        if cppFieldName in methodNames:
+            fieldName += RENAME_FIELD_SUFFIX
+            cppFieldName += RENAME_FIELD_SUFFIX
+        value = '%s::%s' %(cppname(names[-1]), cppFieldName)
         value = fieldValue(cls, value, fieldType)
         line(out, indent + 1, 'PyDict_SetItemString(PY_TYPE(%s).tp_dict, "%s", make_descriptor(%s));',
              names[-1], fieldName, value)



Mime
View raw message