bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / unusedenumconstants.py
blob591c73f1cede60acb60a068ed95ce9a0cd366930
1 #!/usr/bin/python
3 import sys
4 import re
5 import io
7 definitionSet = set()
8 definitionToSourceLocationMap = dict()
9 readSet = set()
10 writeSet = set()
11 sourceLocationSet = 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 def parseFieldInfo( tokens ):
20 if len(tokens) == 3:
21 return (normalizeTypeParams(tokens[1]), tokens[2])
22 else:
23 return (normalizeTypeParams(tokens[1]), "")
25 with io.open("workdir/loplugin.unusedenumconstants.log", "rb", buffering=1024*1024) as txt:
26 for line in txt:
27 tokens = line.strip().split("\t")
28 if tokens[0] == "definition:":
29 fieldInfo = (normalizeTypeParams(tokens[1]), tokens[2])
30 srcLoc = tokens[3]
31 # ignore external source code
32 if (srcLoc.startswith("external/")):
33 continue
34 # ignore build folder
35 if (srcLoc.startswith("workdir/")):
36 continue
37 definitionSet.add(fieldInfo)
38 definitionToSourceLocationMap[fieldInfo] = srcLoc
39 elif tokens[0] == "read:":
40 readSet.add(parseFieldInfo(tokens))
41 elif tokens[0] == "write:":
42 writeSet.add(parseFieldInfo(tokens))
43 else:
44 print( "unknown line: " + line)
46 def startswith_one_of( srcLoc, fileSet ):
47 for f in fileSet:
48 if srcLoc.startswith(f):
49 return True;
50 return False;
52 def is_ignore(srcLoc):
53 if startswith_one_of(srcLoc,
55 # this is all representations of on-disk or external data structures
56 "basic/source/inc/filefmt.hxx",
57 "basic/source/sbx/sbxscan.cxx",
58 "cppcanvas/source/mtfrenderer/emfpbrush.hxx",
59 "filter/source/graphicfilter/ipcd/ipcd.cxx",
60 "filter/source/t602/t602filter.hxx",
61 "include/filter/msfilter/escherex.hxx",
62 "include/filter/msfilter/svdfppt.hxx",
63 "hwpfilter/",
64 "include/registry/types.hxx",
65 "lotuswordpro/",
66 "include/sot/formats.hxx",
67 "include/svx/msdffdef.hxx",
68 "sc/source/filter/inc/xlconst.hxx",
69 "include/unotools/saveopt.hxx",
70 "sw/inc/fldbas.hxx",
71 "sw/source/filter/inc/wwstyles.hxx",
72 "sw/source/filter/ww8/fields.hxx",
73 "vcl/source/fontsubset/cff.cxx",
74 "include/vcl/settings.hxx", # stored in a setting, can't remove it without potentially triggering UBSAN
75 "basic/source/inc/opcodes.hxx", # can't touch this without breaking unit tests, not sure why
76 "include/unotools/securityoptions.hxx", # comes from the UI
77 "sot/source/sdstor/stgelem.hxx",
78 "sd/source/filter/eppt/epptbase.hxx",
79 "include/registry/refltype.hxx",
80 "include/registry/version.h",
81 "include/svtools/rtftoken.h",
82 "sc/source/filter/inc/xltracer.hxx",
83 "writerfilter/source/dmapper/FieldTypes.hxx",
84 "vcl/source/fontsubset/cff.cxx",
85 "vcl/source/filter/wmf/winmtf.hxx",
86 "vcl/source/filter/sgvmain.hxx",
87 "vcl/source/filter/jpeg/transupp.h",
88 "include/vcl/bitmapex.hxx", # TransparentType
89 "vcl/inc/sft.hxx", # CompositeFlags, WidthClass, WeightClass
90 "vcl/inc/CommonSalLayout.hxx", # VerticalOrientation
91 "include/tools/fontenum.hxx", # part of GDI file format
92 "svx/inc/galobj.hxx", # GalSoundType
93 "include/svx/msdffdef.hxx",
94 "include/svtools/rtftoken.h", # RTF_TOKEN_IDS
95 "starmath/source/mathtype.hxx", # MathType::MTOKENS
96 "sd/source/filter/eppt/epptbase.hxx", # PPTExTextAttr
97 "sc/source/filter/inc/tokstack.hxx", # E_TYPE
98 "filter/source/graphicfilter/icgm/cgmtypes.hxx",
99 "basic/source/inc/filefmt.hxx", # FileOffset
100 "include/basic/sbxdef.hxx", # SbxDataType
101 "connectivity/source/inc/dbase/DTable.hxx", # ODbaseTable::DBFType
102 "codemaker/source/javamaker/classfile.hxx", # AccessFlags
103 "basic/source/inc/filefmt.hxx", # FileOffset
104 "basic/source/inc/opcodes.hxx", # SbiOpcode
105 "sc/source/filter/inc/flttypes.hxx", # BiffTyp
106 "sc/inc/optutil.hxx", # ScOptionsUtil::KeyBindingType
107 "include/sfx2/chalign.hxx", # SfxChildAlignment
108 "drawinglayer/source/tools/emfpbrush.hxx",
109 "drawinglayer/source/tools/emfppen.cxx",
110 "include/oox/ppt/animationspersist.hxx",
111 "include/vcl/fontcapabilities.hxx",
112 "sw/inc/poolfmt.hxx",
113 # unit test code
114 "cppu/source/uno/check.cxx",
115 # general weird nonsense going on
116 "framework/inc/helper/mischelper.hxx"
117 "include/sfx2/shell.hxx",
118 "framework/inc/helper/mischelper.hxx",
119 "include/svtools/htmltokn.h",
120 "include/sfx2/shell.hxx",
121 "sw/inc/iodetect.hxx",
122 "sw/inc/fmtfordr.hxx",
123 "sw/inc/flddat.hxx",
124 "sw/source/uibase/config/modcfg.cxx", # InsertConfigProp
125 "sw/inc/calc.hxx", # SwCalcOper
126 "svtools/source/config/helpopt.cxx", # HelpProperty
127 "include/svtools/htmltokn.h",
128 "include/sfx2/sidebar/Theme.hxx", # ThemeItem
129 "sc/source/ui/docshell/impex.cxx", # SylkVersion
130 "include/i18nutil/paper.hxx", # Paper
131 "cppcanvas/source/mtfrenderer/emfplus.cxx", # EmfPlusCombineMode
132 "cppcanvas/source/mtfrenderer/emfpbrush.hxx", # EmfPlusHatchStyle
133 "include/filter/msfilter/svdfppt.hxx", # PptPlaceholder, PptSlideLayout
134 "include/filter/msfilter/escherex.hxx", # various
135 "basic/source/inc/opcodes.hxx", # SbiOpcode
136 "basic/source/inc/token.hxx", # SbiToken
137 "binaryurp/source/specialfunctionids.hxx", # binaryurp::SpecialFunctionIds
138 "connectivity/source/inc/odbc/OTools.hxx", # ODBC3SQLFunctionId
139 "include/formula/grammar.hxx", # FormulaGrammar::Grammar
140 "basic/source/sbx/sbxres.hxx", # StringId
141 "sc/source/core/tool/chartpos.cxx", # CellState
142 "sc/source/core/data/global2.cxx", # State
143 "sc/inc/global.hxx", # ScAggregateFunc
144 "registry/source/reflcnst.hxx", #CPInfoTag
145 # Windows or OSX only
146 "include/canvas/rendering/icolorbuffer.hxx",
147 "include/vcl/commandevent.hxx",
148 "vcl/inc/unx/gendata.hxx",
149 "vcl/inc/salwtype.hxx",
150 "include/vcl/svapp.hxx",
151 "include/vcl/salbtype.hxx",
152 "include/vcl/commandevent.hxx", # CommandEvent, MediaCommand, ShowDialogId
153 "include/canvas/rendering/irendermodule.hxx", # canvas::IRenderModule::PrimitiveType
154 "sal/osl/unx/file.cxx", # FileHandle_Impl::Kind
155 # must match some other enum
156 "include/editeng/bulletitem.hxx",
157 "include/editeng/svxenum.hxx",
158 "include/formula/opcode.hxx", # OpCode
159 "include/i18nutil/paper.hxx",
160 "include/oox/drawingml/shapepropertymap.hxx",
161 "include/svl/nfkeytab.hx",
162 "include/svl/zforlist.hxx",
163 "include/vcl/svtabbx.hxx",
164 "include/vcl/print.hxx", # NupOrderType, from UI combobox
165 "sw/source/uibase/inc/swcont.hxx", # RegionMode, from UI; ContentTypeId, from UI(registry)
166 "sw/inc/toxe.hxx", # ToxAuthorityType (from UI)
167 "include/svx/sxekitm.hxx", # SdrEdgeKind (from UI)
168 "include/svx/paraprev.hxx", # SvxPrevLineSpace (from UI)
169 "include/svx/ctredlin.hxx", # SvxRedlinDateMode (from UI)
170 "sd/source/ui/inc/animobjs.hxx", # BitmapAdjustment (from UI)
171 "sd/source/ui/dlg/PhotoAlbumDialog.hxx", # SlideImageLayout (from UI)
172 "sd/inc/pres.hxx", # AutoLayout (from UI)
173 "sc/source/ui/inc/scuitphfedit.hxx", # ScHFEntryId (from UI)
174 "include/i18nlangtag/languagetag.hxx", # LanguageTag::ScriptType
175 "extensions/source/scanner/grid.hxx", # ResetType (from UI)
176 "dbaccess/source/inc/dsntypes.hxx", # dbaccess::DATASOURCE_TYPE (from UI)
177 "cui/source/tabpages/tparea.cxx", # FillType (from UI)
178 "include/editeng/svxenum.hxx", # css::style::NumberingType
179 "include/editeng/bulletitem.hxx", # css::style::NumberingType
180 "basic/source/sbx/sbxdec.hxx", # SbxDecimal::CmpResult, must match some Windows API
181 "codemaker/source/javamaker/javatype.cxx", # TypeInfo::Flags, from UNO
182 "chart2/source/view/inc/AbstractShapeFactory.hxx", # chart::SymbolEnum, called via int UNO param
183 # represents constants from an external API
184 "opencl/inc/opencl_device_selection.h",
185 "vcl/inc/sft.hxx",
186 "vcl/inc/unx/XIM.h",
187 "vcl/unx/gtk/xid_fullscreen_on_all_monitors.c",
188 "vcl/unx/gtk/salnativewidgets-gtk.cxx",
189 "sc/inc/callform.hxx", # ParamType
190 "include/i18nlangtag/applelangid.hxx", # AppleLanguageId
191 "connectivity/source/drivers/firebird/Util.hxx", # firebird::BlobSubtype
193 return True
194 if d[1] == "UNKNOWN" or d[1] == "LAST" or d[1].endswith("NONE") or d[1].endswith("None") or d[1].endswith("EQUAL_SIZE"):
195 return True
196 return False
199 untouchedSet = set()
200 for d in definitionSet:
201 if d in readSet or d in writeSet:
202 continue
203 srcLoc = definitionToSourceLocationMap[d];
204 if (is_ignore(srcLoc)):
205 continue
207 untouchedSet.add((d[0] + " " + d[1], srcLoc))
209 writeonlySet = set()
210 for d in writeSet:
211 if d in readSet:
212 continue
213 # can happen with stuff in workdir or external
214 if d not in definitionSet:
215 continue
216 srcLoc = definitionToSourceLocationMap[d];
217 if (is_ignore(srcLoc)):
218 continue
219 writeonlySet.add((d[0] + " " + d[1], srcLoc))
221 readonlySet = set()
222 for d in readSet:
223 if d in writeSet:
224 continue
225 # can happen with stuff in workdir or external
226 if d not in definitionSet:
227 continue
228 srcLoc = definitionToSourceLocationMap[d];
229 if (is_ignore(srcLoc)):
230 continue
231 readonlySet.add((d[0] + " " + d[1], srcLoc))
233 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
234 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
235 return [int(text) if text.isdigit() else text.lower()
236 for text in re.split(_nsre, s)]
238 # sort results by name and line number
239 tmp1list = sorted(untouchedSet, key=lambda v: natural_sort_key(v[1]))
240 tmp2list = sorted(writeonlySet, key=lambda v: natural_sort_key(v[1]))
241 tmp3list = sorted(readonlySet, key=lambda v: natural_sort_key(v[1]))
243 # print out the results
244 with open("compilerplugins/clang/unusedenumconstants.untouched.results", "wt") as f:
245 for t in tmp1list:
246 f.write( t[1] + "\n" )
247 f.write( " " + t[0] + "\n" )
248 with open("compilerplugins/clang/unusedenumconstants.writeonly.results", "wt") as f:
249 for t in tmp2list:
250 f.write( t[1] + "\n" )
251 f.write( " " + t[0] + "\n" )
252 with open("compilerplugins/clang/unusedenumconstants.readonly.results", "wt") as f:
253 for t in tmp3list:
254 f.write( t[1] + "\n" )
255 f.write( " " + t[0] + "\n" )