3 instantiatedSet
= set()
6 definitionToFileDict
= {}
8 with
open("workdir/loplugin.mergeclasses.log") as txt
:
10 tokens
= line
.strip().split("\t")
15 elif tokens
[0] == "instantiated:":
17 if (clazzName
.startswith("const ")):
18 clazzName
= clazzName
[6:]
19 if (clazzName
.startswith("class ")):
20 clazzName
= clazzName
[6:]
21 if (clazzName
.startswith("::")):
22 clazzName
= clazzName
[2:]
23 instantiatedSet
.add(clazzName
)
25 elif tokens
[0] == "definition:":
27 # the 1.. is so we skip the leading /
28 fileName
= tokens
[2][1:]
29 definitionSet
.add(clazzName
)
30 definitionToFileDict
[clazzName
] = fileName
32 elif tokens
[0] == "has-subclass:":
35 if (parent
.startswith("class ")):
37 elif (parent
.startswith("struct ")):
39 if (child
.startswith("class ")):
41 elif (child
.startswith("struct ")):
43 if (parent
not in parentChildDict
):
44 parentChildDict
[parent
] = set()
45 parentChildDict
[parent
].add(child
)
47 def extractModuleName(clazz
):
48 filename
= definitionToFileDict
[clazz
]
49 if filename
.startswith("include/"):
50 filename
= filename
[8:]
51 idx
= filename
.find("/")
54 with
open("compilerplugins/clang/mergeclasses.results", "wt") as f
:
55 # loop over defined, but not instantiated classes
56 for clazz
in sorted(definitionSet
- instantiatedSet
):
57 # ignore classes without any children, and classes with more than one child
58 if (clazz
not in parentChildDict
) or (len(parentChildDict
[clazz
]) != 1):
60 # exclude some common false positives
61 a
= ['Dialog', 'Dlg', 'com::sun']
62 if any(x
in clazz
for x
in a
):
64 # ignore base class that contain the word "mutex", they are normally there to
65 # help with the WeakComponentImpl template magic
66 if ("mutex" in clazz
) or ("Mutex" in clazz
):
68 subclazz
= next(iter(parentChildDict
[clazz
]))
69 # if the other class has more than child, it is not a candidate for merging
70 #if (otherclazz in parentChildDict) and (len(parentChildDict[otherclazz]) != 1):
72 # Combinations that span modules we often use those to make cross-module dependencies more manageable,
73 # so mark them with maybe.
74 module1
= extractModuleName(clazz
)
75 module2
= extractModuleName(subclazz
)
76 if module1
!= module2
:
77 f
.write( "maybe merge " + clazz
+ " with " + subclazz
+ ", in modules " + module1
+ " and " + module2
+ "\n" )
79 f
.write( "merge " + clazz
+ " with " + subclazz
+ "\n" )