7 definitionToSourceLocationMap
= dict() # dict of tuple(parentClass, fieldName) to sourceLocation
8 definitionToTypeMap
= dict() # dict of tuple(parentClass, fieldName) to field type
9 fieldAssignDict
= dict() # dict of tuple(parentClass, fieldName) to (set of values)
11 # clang does not always use exactly the same numbers in the type-parameter vars it generates
12 # so I need to substitute them to ensure we can match correctly.
13 normalizeTypeParamsRegex
= re
.compile(r
"type-parameter-\d+-\d+")
14 def normalizeTypeParams( line
):
15 return normalizeTypeParamsRegex
.sub("type-parameter-?-?", line
)
17 # reading as binary (since we known it is pure ascii) is much faster than reading as unicode
18 with io
.open("workdir/loplugin.singlevalfields.log", "rb", buffering
=1024*1024) as txt
:
20 tokens
= line
.strip().split("\t")
21 if tokens
[0] == "defn:":
22 parentClass
= normalizeTypeParams(tokens
[1])
23 fieldName
= normalizeTypeParams(tokens
[2])
24 fieldType
= normalizeTypeParams(tokens
[3])
25 sourceLocation
= tokens
[4]
26 fieldInfo
= (parentClass
, fieldName
)
27 definitionToSourceLocationMap
[fieldInfo
] = sourceLocation
28 definitionToTypeMap
[fieldInfo
] = fieldType
29 elif tokens
[0] == "asgn:":
30 parentClass
= normalizeTypeParams(tokens
[1])
31 fieldName
= normalizeTypeParams(tokens
[2])
33 assignValue
= tokens
[3]
36 fieldInfo
= (parentClass
, fieldName
)
37 if not fieldInfo
in fieldAssignDict
:
38 fieldAssignDict
[fieldInfo
] = set()
39 fieldAssignDict
[fieldInfo
].add(assignValue
)
41 print( "unknown line: " + line
)
43 # look for stuff also has a single value
45 # look for things which have two values - zero and one
47 for fieldInfo
, assignValues
in fieldAssignDict
.iteritems():
48 v0
= fieldInfo
[0] + " " + fieldInfo
[1]
49 v1
= (",".join(assignValues
))
51 if fieldInfo
not in definitionToSourceLocationMap
:
53 v2
= definitionToSourceLocationMap
[fieldInfo
]
54 if len(assignValues
) > 2:
56 if "?" in assignValues
:
58 #if len(assignValues - set(["0", "1", "-1", "nullptr"])) > 0:
60 # ignore things which are locally declared but are actually redeclarations of things from 3rd party code
61 containingClass
= fieldInfo
[0]
62 if containingClass
== "_mwmhints":
64 # ignore things which are representations of on-disk structures
65 if containingClass
in ["SEPr", "WW8Dop", "BmpInfoHeader", "BmpFileHeader", "Exif::ExifIFD",
66 "sw::WW8FFData", "FFDataHeader", "INetURLHistory_Impl::head_entry", "ImplPPTParaPropSet", "SvxSwAutoFormatFlags",
67 "T602ImportFilter::T602ImportFilter::format602struct", "DataNode"]:
69 if v2
.startswith("hwpfilter/source"):
71 # ignore things which are representations of structures from external code
72 if v2
.startswith("desktop/unx/source/splashx.c"):
75 if containingClass
in ["SfxAppData_Impl", "sfx2::ImplDdeItem", "SvFileStream",
76 "DdeService", "DdeTopic", "DdeItem", "DdeConnection", "connectivity::sdbcx::OUser", "connectivity::sdbcx::OGroup", "connectivity::sdbcx::OCatalog",
77 "cairocanvas::SpriteHelper"]:
79 if v2
.startswith("include/svl/svdde.hxx") or v2
.startswith("embeddedobj/source/inc/oleembobj.hxx"):
81 # Some of our supported compilers don't do constexpr, which means o3tl::typed_flags can't be 'static const'
82 if containingClass
in ["WaitWindow_Impl"]:
84 if len(assignValues
) == 2:
85 if "0" in assignValues
and "1" in assignValues
:
86 fieldType
= definitionToTypeMap
[fieldInfo
]
87 if not "_Bool" in fieldType
and not "enum " in fieldType
and not "boolean" in fieldType
:
88 tmp2list
.append((v0
,v1
,v2
,fieldType
))
90 tmp1list
.append((v0
,v1
,v2
))
92 # sort results by filename:lineno
93 def natural_sort_key(s
, _nsre
=re
.compile('([0-9]+)')):
94 return [int(text
) if text
.isdigit() else text
.lower()
95 for text
in re
.split(_nsre
, s
)]
96 tmp1list
.sort(key
=lambda v
: natural_sort_key(v
[2]))
97 tmp2list
.sort(key
=lambda v
: natural_sort_key(v
[2]))
99 # print out the results
100 with
open("compilerplugins/clang/singlevalfields.results", "wt") as f
:
103 f
.write(" " + v
[0] + "\n")
104 f
.write(" " + v
[1] + "\n")
105 with
open("compilerplugins/clang/singlevalfields.could-be-bool.results", "wt") as f
:
108 f
.write(" " + v
[0] + "\n")
109 f
.write(" " + v
[3] + "\n")