7 definitionToSourceLocationMap
= dict() # dict of tuple(parentClass, fieldName) to sourceLocation
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
:
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
)
46 print( "unknown line: " + line
)
48 # Invert the definitionToSourceLocationMap
49 # If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
50 # and we should just ignore it
51 sourceLocationToDefinitionMap
= {}
52 for k
, v
in definitionToSourceLocationMap
.iteritems():
53 sourceLocationToDefinitionMap
[v
] = sourceLocationToDefinitionMap
.get(v
, [])
54 sourceLocationToDefinitionMap
[v
].append(k
)
55 for k
, definitions
in sourceLocationToDefinitionMap
.iteritems():
56 if len(definitions
) > 1:
58 definitionSet
.remove(d
)
61 for d
in definitionSet
:
62 # TODO see comment in InlineFields::VisitCXXDeleteExpr
63 # if d in excludedSet or d not in deletedInDestructorSet or d not in newedInConstructorSet:
64 if d
in excludedSet
or d
not in newedInConstructorSet
:
66 srcLoc
= definitionToSourceLocationMap
[d
];
67 tmp1list
.append((d
[0] + " " + d
[1], srcLoc
))
69 # sort results by filename:lineno
70 def natural_sort_key(s
, _nsre
=re
.compile('([0-9]+)')):
71 return [int(text
) if text
.isdigit() else text
.lower()
72 for text
in re
.split(_nsre
, s
)]
73 tmp1list
.sort(key
=lambda v
: natural_sort_key(v
[1]))
75 # print out the results
76 with
open("loplugin.inlinefields.report", "wt") as f
:
79 f
.write(" " + v
[0] + "\n")