Commit 9f57dbb0 authored by Peter Eastman's avatar Peter Eastman
Browse files

Handle overloaded functions in C and Fortran wrappers

parent 5e392f97
...@@ -257,6 +257,7 @@ class CHeaderGenerator(WrapperGenerator): ...@@ -257,6 +257,7 @@ class CHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -268,6 +269,13 @@ class CHeaderGenerator(WrapperGenerator): ...@@ -268,6 +269,13 @@ class CHeaderGenerator(WrapperGenerator):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
returnType = self.getType(getText("type", methodNode)) returnType = self.getType(getText("type", methodNode))
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
self.out.write("extern OPENMM_EXPORT_AMOEBA %s %s_%s(" % (returnType, typeName, methodName)) self.out.write("extern OPENMM_EXPORT_AMOEBA %s %s_%s(" % (returnType, typeName, methodName))
isInstanceMethod = (methodNode.attrib['static'] != 'yes') isInstanceMethod = (methodNode.attrib['static'] != 'yes')
if isInstanceMethod: if isInstanceMethod:
...@@ -438,6 +446,7 @@ class CSourceGenerator(WrapperGenerator): ...@@ -438,6 +446,7 @@ class CSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -448,6 +457,13 @@ class CSourceGenerator(WrapperGenerator): ...@@ -448,6 +457,13 @@ class CSourceGenerator(WrapperGenerator):
if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList): if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
methodType = getText("type", methodNode) methodType = getText("type", methodNode)
returnType = self.getType(methodType) returnType = self.getType(methodType)
if methodType in self.classesByShortName: if methodType in self.classesByShortName:
...@@ -474,7 +490,7 @@ class CSourceGenerator(WrapperGenerator): ...@@ -474,7 +490,7 @@ class CSourceGenerator(WrapperGenerator):
self.out.write('%s*>(target)->' % className) self.out.write('%s*>(target)->' % className)
else: else:
self.out.write('%s::' % className) self.out.write('%s::' % className)
self.out.write('%s(' % methodName) self.out.write('%s(' % methodNames[methodNode])
self.writeInvocationArguments(methodNode, False) self.writeInvocationArguments(methodNode, False)
self.out.write(');\n') self.out.write(');\n')
if returnType != 'void': if returnType != 'void':
...@@ -758,6 +774,7 @@ class FortranHeaderGenerator(WrapperGenerator): ...@@ -758,6 +774,7 @@ class FortranHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -768,6 +785,13 @@ class FortranHeaderGenerator(WrapperGenerator): ...@@ -768,6 +785,13 @@ class FortranHeaderGenerator(WrapperGenerator):
if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList): if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
returnType = self.getType(getText("type", methodNode)) returnType = self.getType(getText("type", methodNode))
hasReturnValue = (returnType in ('integer*4', 'real*8')) hasReturnValue = (returnType in ('integer*4', 'real*8'))
hasReturnArg = not (hasReturnValue or returnType == 'void') hasReturnArg = not (hasReturnValue or returnType == 'void')
...@@ -973,6 +997,7 @@ class FortranSourceGenerator(WrapperGenerator): ...@@ -973,6 +997,7 @@ class FortranSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -985,6 +1010,13 @@ class FortranSourceGenerator(WrapperGenerator): ...@@ -985,6 +1010,13 @@ class FortranSourceGenerator(WrapperGenerator):
if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList): if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
functionName = "%s_%s" % (typeName, methodName) functionName = "%s_%s" % (typeName, methodName)
self.writeOneMethod(classNode, methodNode, functionName, functionName.lower()+'_') self.writeOneMethod(classNode, methodNode, functionName, functionName.lower()+'_')
self.writeOneMethod(classNode, methodNode, functionName, functionName.upper()) self.writeOneMethod(classNode, methodNode, functionName, functionName.upper())
......
...@@ -267,6 +267,7 @@ class CHeaderGenerator(WrapperGenerator): ...@@ -267,6 +267,7 @@ class CHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -278,6 +279,13 @@ class CHeaderGenerator(WrapperGenerator): ...@@ -278,6 +279,13 @@ class CHeaderGenerator(WrapperGenerator):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
returnType = self.getType(getText("type", methodNode)) returnType = self.getType(getText("type", methodNode))
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
self.out.write("extern OPENMM_EXPORT %s %s_%s(" % (returnType, typeName, methodName)) self.out.write("extern OPENMM_EXPORT %s %s_%s(" % (returnType, typeName, methodName))
isInstanceMethod = (methodNode.attrib['static'] != 'yes') isInstanceMethod = (methodNode.attrib['static'] != 'yes')
if isInstanceMethod: if isInstanceMethod:
...@@ -526,6 +534,7 @@ class CSourceGenerator(WrapperGenerator): ...@@ -526,6 +534,7 @@ class CSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -536,6 +545,13 @@ class CSourceGenerator(WrapperGenerator): ...@@ -536,6 +545,13 @@ class CSourceGenerator(WrapperGenerator):
if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList): if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
methodType = getText("type", methodNode) methodType = getText("type", methodNode)
returnType = self.getType(methodType) returnType = self.getType(methodType)
if methodType in self.classesByShortName: if methodType in self.classesByShortName:
...@@ -562,7 +578,7 @@ class CSourceGenerator(WrapperGenerator): ...@@ -562,7 +578,7 @@ class CSourceGenerator(WrapperGenerator):
self.out.write('%s*>(target)->' % className) self.out.write('%s*>(target)->' % className)
else: else:
self.out.write('%s::' % className) self.out.write('%s::' % className)
self.out.write('%s(' % methodName) self.out.write('%s(' % methodNames[methodNode])
self.writeInvocationArguments(methodNode, False) self.writeInvocationArguments(methodNode, False)
self.out.write(');\n') self.out.write(');\n')
if returnType != 'void': if returnType != 'void':
...@@ -982,6 +998,7 @@ class FortranHeaderGenerator(WrapperGenerator): ...@@ -982,6 +998,7 @@ class FortranHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -992,6 +1009,13 @@ class FortranHeaderGenerator(WrapperGenerator): ...@@ -992,6 +1009,13 @@ class FortranHeaderGenerator(WrapperGenerator):
if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList): if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
returnType = self.getType(getText("type", methodNode)) returnType = self.getType(getText("type", methodNode))
hasReturnValue = (returnType in ('integer*4', 'real*8')) hasReturnValue = (returnType in ('integer*4', 'real*8'))
hasReturnArg = not (hasReturnValue or returnType == 'void') hasReturnArg = not (hasReturnValue or returnType == 'void')
...@@ -1539,6 +1563,7 @@ class FortranSourceGenerator(WrapperGenerator): ...@@ -1539,6 +1563,7 @@ class FortranSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1] methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods # Write other methods
nameCount = {}
for methodNode in methodList: for methodNode in methodList:
methodName = methodNames[methodNode] methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName): if methodName in (shortClassName, destructorName):
...@@ -1551,6 +1576,13 @@ class FortranSourceGenerator(WrapperGenerator): ...@@ -1551,6 +1576,13 @@ class FortranSourceGenerator(WrapperGenerator):
if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList): if isConstMethod and any(methodNames[m] == methodName and m.attrib['const'] == 'no' for m in methodList):
# There are two identical methods that differ only in whether they are const. Skip the const one. # There are two identical methods that differ only in whether they are const. Skip the const one.
continue continue
if methodName in nameCount:
# There are multiple methods with the same name.
count = nameCount[methodName]
methodName = "%s_%d" % (methodName, count)
nameCount[methodName] = count+1
else:
nameCount[methodName] = 1
functionName = "%s_%s" % (typeName, methodName) functionName = "%s_%s" % (typeName, methodName)
truncatedName = functionName[:63] truncatedName = functionName[:63]
self.writeOneMethod(classNode, methodNode, functionName, truncatedName.lower()+'_') self.writeOneMethod(classNode, methodNode, functionName, truncatedName.lower()+'_')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment