2015-09-08 08:07:33 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
instantiatedSet = set()
|
|
|
|
definitionSet = set()
|
|
|
|
parentChildDict = {}
|
|
|
|
definitionToFileDict = {}
|
|
|
|
|
2016-07-25 13:22:38 +02:00
|
|
|
with open("loplugin.mergeclasses.log") as txt:
|
2015-09-08 08:07:33 +02:00
|
|
|
for line in txt:
|
2016-09-15 08:49:53 +02:00
|
|
|
tokens = line.strip().split("\t")
|
2015-09-08 08:07:33 +02:00
|
|
|
|
2016-09-15 08:49:53 +02:00
|
|
|
if tokens[0] == "instantiated:":
|
|
|
|
clazzName = tokens[1]
|
2015-09-08 08:07:33 +02:00
|
|
|
if (clazzName.startswith("const ")):
|
|
|
|
clazzName = clazzName[6:]
|
|
|
|
if (clazzName.startswith("class ")):
|
|
|
|
clazzName = clazzName[6:]
|
|
|
|
if (clazzName.endswith(" &")):
|
|
|
|
clazzName = clazzName[:len(clazzName)-3]
|
|
|
|
instantiatedSet.add(clazzName)
|
|
|
|
|
2016-09-15 08:49:53 +02:00
|
|
|
elif tokens[0] == "definition:":
|
|
|
|
clazzName = tokens[1]
|
|
|
|
# the 1.. is so we skip the leading /
|
|
|
|
fileName = tokens[1][1..]
|
2015-09-08 08:07:33 +02:00
|
|
|
definitionSet.add(clazzName)
|
|
|
|
definitionToFileDict[clazzName] = fileName
|
|
|
|
|
2016-09-15 08:49:53 +02:00
|
|
|
elif tokens[0] == "has-subclass:":
|
|
|
|
child = tokens[1]
|
|
|
|
parent = tokens[2]
|
2015-09-08 08:07:33 +02:00
|
|
|
if (parent.startswith("class ")):
|
|
|
|
parent = parent[6:]
|
|
|
|
elif (parent.startswith("struct ")):
|
|
|
|
parent = parent[7:]
|
|
|
|
if (child.startswith("class ")):
|
|
|
|
child = child[6:]
|
|
|
|
elif (child.startswith("struct ")):
|
|
|
|
child = child[7:]
|
|
|
|
if (parent not in parentChildDict):
|
|
|
|
parentChildDict[parent] = set()
|
|
|
|
parentChildDict[parent].add(child)
|
|
|
|
|
|
|
|
def extractModuleName(clazz):
|
|
|
|
filename = definitionToFileDict[clazz]
|
|
|
|
if filename.startswith("include/"):
|
|
|
|
filename = filename[8:]
|
|
|
|
idx = filename.find("/")
|
|
|
|
return filename[:idx]
|
|
|
|
|
2016-07-25 13:22:38 +02:00
|
|
|
with open("loplugin.mergeclasses.report", "wt") as f:
|
2015-09-08 08:07:33 +02:00
|
|
|
for clazz in sorted(definitionSet - instantiatedSet):
|
|
|
|
# find uninstantiated classes without any subclasses
|
|
|
|
if (not(clazz in parentChildDict)) or (len(parentChildDict[clazz]) != 1):
|
|
|
|
continue
|
|
|
|
# exclude some common false positives
|
|
|
|
a = ['Dialog', 'Dlg', 'com::sun', 'Base']
|
|
|
|
if any(x in clazz for x in a):
|
|
|
|
continue
|
|
|
|
# ignore base class that contain the word "mutex", they are normally there to
|
|
|
|
# help with the WeakComponentImpl template magic
|
2015-10-09 10:31:13 +02:00
|
|
|
if ("mutex" in clazz) or ("Mutex" in clazz):
|
2015-09-08 08:07:33 +02:00
|
|
|
continue
|
|
|
|
otherclazz = next(iter(parentChildDict[clazz]))
|
2015-10-07 10:00:59 +02:00
|
|
|
# exclude combinations that span modules because we often use those to make cross-module dependencies more manageable.
|
2015-09-08 08:07:33 +02:00
|
|
|
if extractModuleName(clazz) != extractModuleName(otherclazz):
|
|
|
|
continue
|
2016-07-25 13:22:38 +02:00
|
|
|
f.write( "merge" + clazz + "with" + otherclazz + "\n" )
|
2015-09-08 08:07:33 +02:00
|
|
|
|