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 fieldInfo
not 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 # ignore some random noise, no idea why this does not get filtered out by the normal checks in the C++
60 if v2
.startswith("ux-gnu/") or v2
.startswith(":") or v2
.startswith(".h:") or v2
.startswith("bxml/"):
62 if v2
.startswith("ib.h:") or v2
.startswith("freetype/") or v2
.startswith("k/") or v2
.startswith("n.h"):
64 if v2
.startswith("pango/") or v2
.startswith("t.h") or v2
.startswith("h:"):
66 #if len(assignValues - set(["0", "1", "-1", "nullptr"])) > 0:
68 # ignore things which are locally declared but are actually redeclarations of things from 3rd party code
69 containingClass
= fieldInfo
[0]
70 if containingClass
== "_mwmhints":
72 # ignore things which are representations of on-disk structures
73 if containingClass
in ["SEPr", "WW8Dop", "BmpInfoHeader", "BmpFileHeader", "Exif::ExifIFD",
74 "sw::WW8FFData", "FFDataHeader", "INetURLHistory_Impl::head_entry", "ImplPPTParaPropSet", "SvxSwAutoFormatFlags",
75 "T602ImportFilter::T602ImportFilter::format602struct", "DataNode"]:
77 if v2
.startswith("hwpfilter/source"):
79 # ignore things which are representations of structures from external code
80 if v2
.startswith("desktop/unx/source/splashx.c"):
83 if containingClass
in ["SfxAppData_Impl", "sfx2::ImplDdeItem", "SvFileStream",
84 "DdeService", "DdeTopic", "DdeItem", "DdeConnection", "connectivity::sdbcx::OUser", "connectivity::sdbcx::OGroup", "connectivity::sdbcx::OCatalog",
85 "cairocanvas::SpriteHelper"]:
87 if v2
.startswith("include/svl/svdde.hxx") or v2
.startswith("embeddedobj/source/inc/oleembobj.hxx"):
89 # Some of our supported compilers don't do constexpr, which means o3tl::typed_flags can't be 'static const'
90 if containingClass
in ["WaitWindow_Impl"]:
92 if len(assignValues
) == 2:
93 if "0" in assignValues
and "1" in assignValues
:
94 fieldType
= definitionToTypeMap
[fieldInfo
]
95 if "_Bool" not in fieldType
and "enum " not in fieldType
and "boolean" not in fieldType
:
96 tmp2list
.append((v0
,v1
,v2
,fieldType
))
97 elif len(assignValues
) == 1:
99 if not("Idle" in v1
or "Timer" in v1
):
100 tmp1list
.append((v0
,v1
,v2
))
102 tmp1list
.append((v0
,v1
,v2
))
104 # sort results by filename:lineno
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 tmp1list
.sort(key
=lambda v
: natural_sort_key(v
[2]))
109 tmp2list
.sort(key
=lambda v
: natural_sort_key(v
[2]))
111 # print out the results
112 with
open("compilerplugins/clang/singlevalfields.results", "wt") as f
:
115 f
.write(" " + v
[0] + "\n")
116 f
.write(" " + v
[1] + "\n")
117 with
open("compilerplugins/clang/singlevalfields.could-be-bool.results", "wt") as f
:
120 f
.write(" " + v
[0] + "\n")
121 f
.write(" " + v
[3] + "\n")