android: Reuse launcher icon in activities
[LibreOffice.git] / compilerplugins / clang / mergeclasses.py
blobbbd46972421858aea4bf386e4636dc07ee7ce2c5
1 #!/usr/bin/python3
3 instantiatedSet = set()
4 definitionSet = set()
5 parentChildDict = {}
6 definitionToFileDict = {}
8 with open("workdir/loplugin.mergeclasses.log") as txt:
9 for line in txt:
10 tokens = line.strip().split("\t")
12 if len(tokens) == 1:
13 pass
15 elif tokens[0] == "instantiated:":
16 clazzName = tokens[1]
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:":
26 clazzName = tokens[1]
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:":
33 child = tokens[1]
34 parent = tokens[2]
35 if (parent.startswith("class ")):
36 parent = parent[6:]
37 elif (parent.startswith("struct ")):
38 parent = parent[7:]
39 if (child.startswith("class ")):
40 child = child[6:]
41 elif (child.startswith("struct ")):
42 child = child[7:]
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("/")
52 return filename[:idx]
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):
60 continue
61 # exclude some common false positives
62 a = ['Dialog', 'Dlg', 'com::sun']
63 if any(x in clazz for x in a):
64 continue
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):
68 continue
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):
74 continue
75 f.write( "merge " + clazz + " with " + otherclazz + "\n" )