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