bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / singlevalfields.py
blob7d42a0f6bbc64e479fa90bbd832a44415d8f4503
1 #!/usr/bin/python
3 import sys
4 import re
5 import io
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:
19 for line in 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])
32 if len(tokens) > 3:
33 assignValue = tokens[3]
34 else:
35 assignValue = ""
36 fieldInfo = (parentClass, fieldName)
37 if not fieldInfo in fieldAssignDict:
38 fieldAssignDict[fieldInfo] = set()
39 fieldAssignDict[fieldInfo].add(assignValue)
40 else:
41 print( "unknown line: " + line)
43 # look for stuff also has a single value
44 tmp1list = list()
45 # look for things which have two values - zero and one
46 tmp2list = list()
47 for fieldInfo, assignValues in fieldAssignDict.iteritems():
48 v0 = fieldInfo[0] + " " + fieldInfo[1]
49 v1 = (",".join(assignValues))
50 v2 = ""
51 if fieldInfo not in definitionToSourceLocationMap:
52 continue
53 v2 = definitionToSourceLocationMap[fieldInfo]
54 if len(assignValues) > 2:
55 continue
56 if "?" in assignValues:
57 continue
58 #if len(assignValues - set(["0", "1", "-1", "nullptr"])) > 0:
59 # continue
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":
63 continue
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"]:
68 continue
69 if v2.startswith("hwpfilter/source"):
70 continue
71 # ignore things which are representations of structures from external code
72 if v2.startswith("desktop/unx/source/splashx.c"):
73 continue
74 # Windows-only
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"]:
78 continue
79 if v2.startswith("include/svl/svdde.hxx") or v2.startswith("embeddedobj/source/inc/oleembobj.hxx"):
80 continue
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"]:
83 continue
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))
89 else:
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:
101 for v in tmp1list:
102 f.write(v[2] + "\n")
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:
106 for v in tmp2list:
107 f.write(v[2] + "\n")
108 f.write(" " + v[0] + "\n")
109 f.write(" " + v[3] + "\n")