lok: getSlideShowInfo: interactions: check that properties are available
[LibreOffice.git] / compilerplugins / clang / fieldcanbelocal.py
blobf5307e7108515bb23841575cd638f72958fb6bb5
1 #!/usr/bin/python3
3 import re
4 import io
6 definitionSet = set()
7 definitionToSourceLocationMap = dict()
8 definitionToTypeMap = dict()
9 touchedMap = dict()
10 excludeSet = set()
11 sourceLocationSet = 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)
20 with io.open("workdir/loplugin.fieldcanbelocal.log", "r", buffering=1024*1024) as txt:
21 for line in txt:
22 tokens = line.strip().split("\t")
23 if tokens[0] == "definition:":
24 fieldInfo = (normalizeTypeParams(tokens[1]), tokens[2])
25 fieldType = tokens[3]
26 srcLoc = tokens[4]
27 # ignore external source code
28 if srcLoc.startswith("external/"):
29 continue
30 # ignore build folder
31 if srcLoc.startswith("workdir/"):
32 continue
33 definitionSet.add(fieldInfo)
34 definitionToTypeMap[fieldInfo] = fieldType
35 definitionToSourceLocationMap[fieldInfo] = srcLoc
36 elif tokens[0] == "touched:":
37 fieldInfo = (normalizeTypeParams(tokens[1]), tokens[2])
38 touchedByFunction = normalizeTypeParams(tokens[3])
39 touchedByFunctionSrcLoc = tokens[4]
40 if fieldInfo in excludeSet:
41 continue
42 if touchedByFunction == "Negative":
43 excludeSet.add(fieldInfo)
44 if fieldInfo in touchedMap:
45 touchedMap.pop(fieldInfo)
46 elif fieldInfo in touchedMap:
47 if touchedMap[fieldInfo] != touchedByFunction:
48 excludeSet.add(fieldInfo)
49 touchedMap.pop(fieldInfo)
50 else:
51 touchedMap[fieldInfo] = touchedByFunction
52 else:
53 print( "unknown line: " + line)
55 outputSet = set()
56 for d in definitionSet:
57 if d not in touchedMap:
58 continue
59 fieldType = definitionToTypeMap[d]
60 # ignore some types that are known false+
61 if (fieldType.startswith("std::unique_ptr<")
62 or fieldType == "std::mutex"
63 or "Mutex" in fieldType
64 or "union" in fieldType
65 or "anonymous namespace" in fieldType
66 or "unnamed struct" in fieldType):
67 continue
68 # ignore some field names that are known false+
69 if (d[1] == "mbDisposing"
70 or d[1] == "bInDispose"
71 or d[1] == "m_bDisposing"
72 or d[1].startswith("m_bIn")):
73 continue
74 srcLoc = definitionToSourceLocationMap[d]
75 # ignore some types in the system libraries we somehow pick up
76 if srcLoc.startswith(".") or srcLoc.startswith("/") or srcLoc.startswith("lib/"):
77 continue
78 # part of the URE
79 if srcLoc.startswith("include/cppuhelper/"):
80 continue
81 # on-disk structures
82 if srcLoc.startswith("hwpfilter/"):
83 continue
84 if srcLoc.startswith("include/osl/"):
85 continue
86 if srcLoc.startswith("include/sal/"):
87 continue
88 if srcLoc.startswith("sw/source/filter/ww8/ww8struc.hxx"):
89 continue
90 if srcLoc.startswith("sd/source/filter/ppt/ppt97animations.hxx"):
91 continue
92 if srcLoc.startswith("lotuswordpro/"):
93 continue
94 if srcLoc.startswith("include/filter/msfilter/svdfppt.hxx"):
95 continue
96 if srcLoc.startswith("filter/source/graphicfilter/icgm/chart.hxx"):
97 continue
98 # most of this code is only compiled on windows, so we don't have decent results
99 if srcLoc.startswith("include/svl/svdde.hxx"):
100 continue
101 touchedByFunction = touchedMap[d]
102 outputSet.add((d[0] + " " + d[1] + " " + definitionToTypeMap[d], srcLoc, touchedByFunction))
104 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
105 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
106 return [int(text) if text.isdigit() else text.lower()
107 for text in re.split(_nsre, s)]
108 # sort by both the source-line and the datatype, so the output file ordering is stable
109 # when we have multiple items on the same source line
110 def v_sort_key(v):
111 return natural_sort_key(v[1]) + [v[0]]
113 # sort results by name and line number
114 tmp1list = sorted(outputSet, key=lambda v: v_sort_key(v))
116 # print out the results
117 with open("compilerplugins/clang/fieldcanbelocal.results", "wt") as f:
118 for t in tmp1list:
119 f.write( t[1] + "\n" )
120 f.write( " " + t[0] + "\n" )
121 f.write( " " + t[2] + "\n" )