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):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -268,6 +269,13 @@ class CHeaderGenerator(WrapperGenerator):
# There are two identical methods that differ only in whether they are const. Skip the const one.
continue
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))
isInstanceMethod = (methodNode.attrib['static'] != 'yes')
if isInstanceMethod:
......@@ -438,6 +446,7 @@ class CSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -448,6 +457,13 @@ class CSourceGenerator(WrapperGenerator):
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.
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)
returnType = self.getType(methodType)
if methodType in self.classesByShortName:
......@@ -474,7 +490,7 @@ class CSourceGenerator(WrapperGenerator):
self.out.write('%s*>(target)->' % className)
else:
self.out.write('%s::' % className)
self.out.write('%s(' % methodName)
self.out.write('%s(' % methodNames[methodNode])
self.writeInvocationArguments(methodNode, False)
self.out.write(');\n')
if returnType != 'void':
......@@ -758,6 +774,7 @@ class FortranHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -768,6 +785,13 @@ class FortranHeaderGenerator(WrapperGenerator):
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.
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))
hasReturnValue = (returnType in ('integer*4', 'real*8'))
hasReturnArg = not (hasReturnValue or returnType == 'void')
......@@ -973,6 +997,7 @@ class FortranSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -985,6 +1010,13 @@ class FortranSourceGenerator(WrapperGenerator):
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.
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)
self.writeOneMethod(classNode, methodNode, functionName, functionName.lower()+'_')
self.writeOneMethod(classNode, methodNode, functionName, functionName.upper())
......
......@@ -267,6 +267,7 @@ class CHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -278,6 +279,13 @@ class CHeaderGenerator(WrapperGenerator):
# There are two identical methods that differ only in whether they are const. Skip the const one.
continue
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))
isInstanceMethod = (methodNode.attrib['static'] != 'yes')
if isInstanceMethod:
......@@ -526,6 +534,7 @@ class CSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -536,6 +545,13 @@ class CSourceGenerator(WrapperGenerator):
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.
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)
returnType = self.getType(methodType)
if methodType in self.classesByShortName:
......@@ -562,7 +578,7 @@ class CSourceGenerator(WrapperGenerator):
self.out.write('%s*>(target)->' % className)
else:
self.out.write('%s::' % className)
self.out.write('%s(' % methodName)
self.out.write('%s(' % methodNames[methodNode])
self.writeInvocationArguments(methodNode, False)
self.out.write(');\n')
if returnType != 'void':
......@@ -982,6 +998,7 @@ class FortranHeaderGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -992,6 +1009,13 @@ class FortranHeaderGenerator(WrapperGenerator):
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.
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))
hasReturnValue = (returnType in ('integer*4', 'real*8'))
hasReturnArg = not (hasReturnValue or returnType == 'void')
......@@ -1539,6 +1563,7 @@ class FortranSourceGenerator(WrapperGenerator):
methodNames[methodNode] = shortMethodDefinition.split()[-1]
# Write other methods
nameCount = {}
for methodNode in methodList:
methodName = methodNames[methodNode]
if methodName in (shortClassName, destructorName):
......@@ -1551,6 +1576,13 @@ class FortranSourceGenerator(WrapperGenerator):
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.
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)
truncatedName = functionName[:63]
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