6 definitionToSourceLocationMap
= dict() # dict of tuple(parentClass, fieldName) to sourceLocation
9 deletedInDestructorSet
= set()
10 newedInConstructorSet
= set()
12 # clang does not always use exactly the same numbers in the type-parameter vars it generates
13 # so I need to substitute them to ensure we can match correctly.
14 normalizeTypeParamsRegex
= re
.compile(r
"type-parameter-\d+-\d+")
15 def normalizeTypeParams( line
):
16 return normalizeTypeParamsRegex
.sub("type-parameter-?-?", line
)
18 # reading as binary (since we known it is pure ascii) is much faster than reading as unicode
19 with io
.open("workdir/loplugin.inlinefields.log", "rb", buffering
=1024*1024) as txt
:
21 tokens
= line
.strip().split("\t")
22 if tokens
[0] == "definition:":
23 parentClass
= normalizeTypeParams(tokens
[1])
24 fieldName
= normalizeTypeParams(tokens
[2])
25 sourceLocation
= tokens
[3]
26 fieldInfo
= (parentClass
, fieldName
)
27 definitionSet
.add(fieldInfo
)
28 definitionToSourceLocationMap
[fieldInfo
] = sourceLocation
29 elif tokens
[0] == "excluded:":
30 parentClass
= normalizeTypeParams(tokens
[1])
31 fieldName
= normalizeTypeParams(tokens
[2])
32 fieldInfo
= (parentClass
, fieldName
)
33 excludedSet
.add(fieldInfo
)
34 elif tokens
[0] == "deletedInDestructor:":
35 parentClass
= normalizeTypeParams(tokens
[1])
36 fieldName
= normalizeTypeParams(tokens
[2])
37 fieldInfo
= (parentClass
, fieldName
)
38 deletedInDestructorSet
.add(fieldInfo
)
39 elif tokens
[0] == "newedInConstructor:":
40 parentClass
= normalizeTypeParams(tokens
[1])
41 fieldName
= normalizeTypeParams(tokens
[2])
42 fieldInfo
= (parentClass
, fieldName
)
43 newedInConstructorSet
.add(fieldInfo
)
45 print( "unknown line: " + line
)
48 for d
in definitionSet
:
49 # TODO see comment in InlineFields::VisitCXXDeleteExpr
50 # if d in excludedSet or d not in deletedInDestructorSet or d not in newedInConstructorSet:
51 if d
in excludedSet
or d
not in newedInConstructorSet
:
53 srcLoc
= definitionToSourceLocationMap
[d
]
54 tmp1list
.append((d
[0] + " " + d
[1], srcLoc
))
56 # sort results by filename:lineno
57 def natural_sort_key(s
, _nsre
=re
.compile('([0-9]+)')):
58 return [int(text
) if text
.isdigit() else text
.lower()
59 for text
in re
.split(_nsre
, s
)]
60 # sort by both the source-line and the datatype, so the output file ordering is stable
61 # when we have multiple items on the same source line
63 return natural_sort_key(v
[1]) + [v
[0]]
64 tmp1list
.sort(key
=lambda v
: v_sort_key(v
))
66 # print out the results
67 with
open("loplugin.inlinefields.report", "wt") as f
:
70 f
.write(" " + v
[0] + "\n")