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 if clazz
== "svl::IUndoManager": print(parentChildDict
[clazz
])
58 # ignore classes without any children, and classes with more than one child
59 if (clazz
not in parentChildDict
) or (len(parentChildDict
[clazz
]) != 1):
61 # exclude some common false positives
62 a
= ['Dialog', 'Dlg', 'com::sun']
63 if any(x
in clazz
for x
in a
):
65 # ignore base class that contain the word "mutex", they are normally there to
66 # help with the WeakComponentImpl template magic
67 if ("mutex" in clazz
) or ("Mutex" in clazz
):
69 otherclazz
= next(iter(parentChildDict
[clazz
]))
70 if clazz
== "svl::IUndoManager": print(extractModuleName(clazz
))
71 if otherclazz
== "svl::IUndoManager": print(extractModuleName(otherclazz
))
72 # exclude combinations that span modules because we often use those to make cross-module dependencies more manageable.
73 if extractModuleName(clazz
) != extractModuleName(otherclazz
):
75 f
.write( "merge " + clazz
+ " with " + otherclazz
+ "\n" )