diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-10-04 09:29:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-10-04 09:30:37 +0200 |
commit | bd89dff26155800be457735a0252476b670ddbd2 (patch) | |
tree | 11d3397a6f6152a1e469f8747287c9c8a357674d /compilerplugins/clang/mergeclasses.py | |
parent | 9e078db481150fe59ecc5ed576ff341a5a5a42cf (diff) |
loplugin:mergeclasses various fixes
better tracking of templates, ignore more noise in the plugin so the
python has less log to process
Change-Id: I62874236d362529bd566140ac3fcc65e734fd62c
Diffstat (limited to 'compilerplugins/clang/mergeclasses.py')
-rwxr-xr-x | compilerplugins/clang/mergeclasses.py | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/compilerplugins/clang/mergeclasses.py b/compilerplugins/clang/mergeclasses.py index fc2aaa25beca..2af07ee3161d 100755 --- a/compilerplugins/clang/mergeclasses.py +++ b/compilerplugins/clang/mergeclasses.py @@ -11,20 +11,23 @@ with open("loplugin.mergeclasses.log") as txt: for line in txt: tokens = line.strip().split("\t") - if tokens[0] == "instantiated:": + if len(tokens) == 1: + pass + + elif tokens[0] == "instantiated:": clazzName = tokens[1] if (clazzName.startswith("const ")): clazzName = clazzName[6:] if (clazzName.startswith("class ")): clazzName = clazzName[6:] - if (clazzName.endswith(" &")): - clazzName = clazzName[:len(clazzName)-3] + if (clazzName.startswith("::")): + clazzName = clazzName[2:] instantiatedSet.add(clazzName) elif tokens[0] == "definition:": clazzName = tokens[1] # the 1.. is so we skip the leading / - fileName = tokens[1][1..] + fileName = tokens[2][1:] definitionSet.add(clazzName) definitionToFileDict[clazzName] = fileName @@ -42,7 +45,7 @@ with open("loplugin.mergeclasses.log") as txt: if (parent not in parentChildDict): parentChildDict[parent] = set() parentChildDict[parent].add(child) - + def extractModuleName(clazz): filename = definitionToFileDict[clazz] if filename.startswith("include/"): @@ -51,21 +54,22 @@ def extractModuleName(clazz): return filename[:idx] with open("loplugin.mergeclasses.report", "wt") as f: -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 - if ("mutex" in clazz) or ("Mutex" in clazz): - continue - otherclazz = next(iter(parentChildDict[clazz])) - # exclude combinations that span modules because we often use those to make cross-module dependencies more manageable. - if extractModuleName(clazz) != extractModuleName(otherclazz): - continue - f.write( "merge" + clazz + "with" + otherclazz + "\n" ) + # loop over defined, but not instantiated classes + for clazz in sorted(definitionSet - instantiatedSet): + # ignore classes without any children, and classes with more than one child + if (clazz not 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 + if ("mutex" in clazz) or ("Mutex" in clazz): + continue + otherclazz = next(iter(parentChildDict[clazz])) + # exclude combinations that span modules because we often use those to make cross-module dependencies more manageable. + if extractModuleName(clazz) != extractModuleName(otherclazz): + continue + f.write( "merge " + clazz + " with " + otherclazz + "\n" ) |