7 definitionToSourceLocationMap
= dict()
8 definitionToTypeMap
= dict()
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
:
22 tokens
= line
.strip().split("\t")
23 if tokens
[0] == "definition:":
24 fieldInfo
= (normalizeTypeParams(tokens
[1]), tokens
[2])
27 # ignore external source code
28 if srcLoc
.startswith("external/"):
31 if srcLoc
.startswith("workdir/"):
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
:
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
)
51 touchedMap
[fieldInfo
] = touchedByFunction
53 print( "unknown line: " + line
)
56 for d
in definitionSet
:
57 if d
not in touchedMap
:
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
):
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")):
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/"):
79 if srcLoc
.startswith("include/cppuhelper/"):
82 if srcLoc
.startswith("hwpfilter/"):
84 if srcLoc
.startswith("include/osl/"):
86 if srcLoc
.startswith("include/sal/"):
88 if srcLoc
.startswith("sw/source/filter/ww8/ww8struc.hxx"):
90 if srcLoc
.startswith("sd/source/filter/ppt/ppt97animations.hxx"):
92 if srcLoc
.startswith("lotuswordpro/"):
94 if srcLoc
.startswith("include/filter/msfilter/svdfppt.hxx"):
96 if srcLoc
.startswith("filter/source/graphicfilter/icgm/chart.hxx"):
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"):
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
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
:
119 f
.write( t
[1] + "\n" )
120 f
.write( " " + t
[0] + "\n" )
121 f
.write( " " + t
[2] + "\n" )