bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / inlinefields.py
blob4b8211c86a62534b050fd48944d93bd153e323e5
1 #!/usr/bin/python
3 import sys
4 import re
5 import io
7 definitionToSourceLocationMap = dict() # dict of tuple(parentClass, fieldName) to sourceLocation
8 definitionSet = set()
9 excludedSet = set()
10 deletedInDestructorSet = set()
11 newedInConstructorSet = set();
13 # clang does not always use exactly the same numbers in the type-parameter vars it generates
14 # so I need to substitute them to ensure we can match correctly.
15 normalizeTypeParamsRegex = re.compile(r"type-parameter-\d+-\d+")
16 def normalizeTypeParams( line ):
17 return normalizeTypeParamsRegex.sub("type-parameter-?-?", line)
19 # reading as binary (since we known it is pure ascii) is much faster than reading as unicode
20 with io.open("workdir/loplugin.inlinefields.log", "rb", buffering=1024*1024) as txt:
21 for line in txt:
22 tokens = line.strip().split("\t")
23 if tokens[0] == "definition:":
24 parentClass = normalizeTypeParams(tokens[1])
25 fieldName = normalizeTypeParams(tokens[2])
26 sourceLocation = tokens[3]
27 fieldInfo = (parentClass, fieldName)
28 definitionSet.add(fieldInfo)
29 definitionToSourceLocationMap[fieldInfo] = sourceLocation
30 elif tokens[0] == "excluded:":
31 parentClass = normalizeTypeParams(tokens[1])
32 fieldName = normalizeTypeParams(tokens[2])
33 fieldInfo = (parentClass, fieldName)
34 excludedSet.add(fieldInfo)
35 elif tokens[0] == "deletedInDestructor:":
36 parentClass = normalizeTypeParams(tokens[1])
37 fieldName = normalizeTypeParams(tokens[2])
38 fieldInfo = (parentClass, fieldName)
39 deletedInDestructorSet.add(fieldInfo)
40 elif tokens[0] == "newedInConstructor:":
41 parentClass = normalizeTypeParams(tokens[1])
42 fieldName = normalizeTypeParams(tokens[2])
43 fieldInfo = (parentClass, fieldName)
44 newedInConstructorSet.add(fieldInfo)
45 else:
46 print( "unknown line: " + line)
48 tmp1list = list()
49 for d in definitionSet:
50 # TODO see comment in InlineFields::VisitCXXDeleteExpr
51 # if d in excludedSet or d not in deletedInDestructorSet or d not in newedInConstructorSet:
52 if d in excludedSet or d not in newedInConstructorSet:
53 continue
54 srcLoc = definitionToSourceLocationMap[d];
55 tmp1list.append((d[0] + " " + d[1], srcLoc))
57 # sort results by filename:lineno
58 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
59 return [int(text) if text.isdigit() else text.lower()
60 for text in re.split(_nsre, s)]
61 tmp1list.sort(key=lambda v: natural_sort_key(v[1]))
63 # print out the results
64 with open("loplugin.inlinefields.report", "wt") as f:
65 for v in tmp1list:
66 f.write(v[1] + "\n")
67 f.write(" " + v[0] + "\n")