2017-02-03 11:28:17 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import io
|
|
|
|
|
|
|
|
definitionSet = set()
|
|
|
|
definitionToSourceLocationMap = dict()
|
|
|
|
readSet = set()
|
|
|
|
writeSet = set()
|
|
|
|
sourceLocationSet = set()
|
|
|
|
|
|
|
|
# clang does not always use exactly the same numbers in the type-parameter vars it generates
|
|
|
|
# so I need to substitute them to ensure we can match correctly.
|
|
|
|
normalizeTypeParamsRegex = re.compile(r"type-parameter-\d+-\d+")
|
|
|
|
def normalizeTypeParams( line ):
|
|
|
|
return normalizeTypeParamsRegex.sub("type-parameter-?-?", line)
|
|
|
|
|
|
|
|
def parseFieldInfo( tokens ):
|
|
|
|
if len(tokens) == 3:
|
|
|
|
return (normalizeTypeParams(tokens[1]), tokens[2])
|
|
|
|
else:
|
|
|
|
return (normalizeTypeParams(tokens[1]), "")
|
|
|
|
|
|
|
|
# The parsing here is designed to avoid grabbing stuff which is mixed in from gbuild.
|
|
|
|
# I have not yet found a way of suppressing the gbuild output.
|
|
|
|
with io.open("loplugin.unusedenumconstants.log", "rb", buffering=1024*1024) as txt:
|
|
|
|
for line in txt:
|
|
|
|
tokens = line.strip().split("\t")
|
|
|
|
if tokens[0] == "definition:":
|
|
|
|
fieldInfo = (normalizeTypeParams(tokens[1]), tokens[2])
|
|
|
|
srcLoc = tokens[3]
|
|
|
|
# ignore external source code
|
|
|
|
if (srcLoc.startswith("external/")):
|
|
|
|
continue
|
|
|
|
# ignore build folder
|
|
|
|
if (srcLoc.startswith("workdir/")):
|
|
|
|
continue
|
|
|
|
definitionSet.add(fieldInfo)
|
|
|
|
definitionToSourceLocationMap[fieldInfo] = srcLoc
|
|
|
|
elif tokens[0] == "read:":
|
|
|
|
readSet.add(parseFieldInfo(tokens))
|
|
|
|
elif tokens[0] == "write:":
|
|
|
|
writeSet.add(parseFieldInfo(tokens))
|
|
|
|
else:
|
|
|
|
print( "unknown line: " + line)
|
|
|
|
|
|
|
|
# Invert the definitionToSourceLocationMap
|
|
|
|
# If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
|
|
|
|
# and we should just ignore
|
|
|
|
sourceLocationToDefinitionMap = {}
|
|
|
|
for k, v in definitionToSourceLocationMap.iteritems():
|
|
|
|
sourceLocationToDefinitionMap[v] = sourceLocationToDefinitionMap.get(v, [])
|
|
|
|
sourceLocationToDefinitionMap[v].append(k)
|
|
|
|
for k, definitions in sourceLocationToDefinitionMap.iteritems():
|
|
|
|
if len(definitions) > 1:
|
|
|
|
for d in definitions:
|
|
|
|
definitionSet.remove(d)
|
|
|
|
|
|
|
|
def startswith_one_of( srcLoc, fileSet ):
|
|
|
|
for f in fileSet:
|
|
|
|
if srcLoc.startswith(f):
|
|
|
|
return True;
|
|
|
|
return False;
|
|
|
|
|
|
|
|
untouchedSet = set()
|
|
|
|
for d in definitionSet:
|
|
|
|
if d in readSet or d in writeSet:
|
|
|
|
continue
|
|
|
|
srcLoc = definitionToSourceLocationMap[d];
|
|
|
|
if startswith_one_of(srcLoc,
|
|
|
|
[
|
|
|
|
# this is all representations of on-disk or external data structures
|
|
|
|
"basic/source/inc/filefmt.hxx",
|
|
|
|
"basic/source/sbx/sbxscan.cxx",
|
|
|
|
"cppcanvas/source/mtfrenderer/emfpbrush.hxx",
|
|
|
|
"filter/source/graphicfilter/ipcd/ipcd.cxx",
|
|
|
|
"filter/source/t602/t602filter.hxx",
|
|
|
|
"include/filter/msfilter/escherex.hxx",
|
|
|
|
"include/filter/msfilter/svdfppt.hxx",
|
|
|
|
"hwpfilter/",
|
|
|
|
"include/registry/types.hxx",
|
|
|
|
"lotuswordpro/",
|
|
|
|
"include/sot/formats.hxx",
|
|
|
|
"include/svx/msdffdef.hxx",
|
|
|
|
"sc/source/filter/inc/xlconst.hxx",
|
|
|
|
"include/unotools/saveopt.hxx",
|
|
|
|
"sw/inc/fldbas.hxx",
|
|
|
|
"sw/source/filter/inc/wwstyles.hxx",
|
|
|
|
"sw/source/filter/ww8/fields.hxx",
|
|
|
|
"vcl/source/fontsubset/cff.cxx",
|
2017-02-03 15:59:06 +02:00
|
|
|
"include/vcl/settings.hxx", # stored in a setting, can't remove it without potentially triggering UBSAN
|
2017-02-06 08:54:44 +02:00
|
|
|
"basic/source/inc/opcodes.hxx", # can't touch this without breaking unit tests, not sure why
|
2017-02-06 11:42:25 +02:00
|
|
|
"include/unotools/securityoptions.hxx", # comes from the UI
|
2017-02-06 14:03:46 +02:00
|
|
|
"sot/source/sdstor/stgelem.hxx",
|
|
|
|
"sd/source/filter/eppt/epptbase.hxx",
|
|
|
|
"include/registry/refltype.hxx",
|
|
|
|
"include/registry/version.h",
|
|
|
|
"include/svtools/rtftoken.h",
|
2017-02-07 09:06:00 +02:00
|
|
|
"sc/source/filter/inc/xltracer.hxx",
|
2017-02-07 14:51:40 +02:00
|
|
|
"writerfilter/source/dmapper/FieldTypes.hxx",
|
2017-02-08 10:40:28 +02:00
|
|
|
"vcl/source/fontsubset/cff.cxx",
|
|
|
|
"vcl/source/filter/wmf/winmtf.hxx",
|
|
|
|
"vcl/source/filter/sgvmain.hxx",
|
|
|
|
"vcl/source/filter/jpeg/transupp.h",
|
2017-02-08 12:00:27 +02:00
|
|
|
"include/vcl/bitmapex.hxx", # TransparentType
|
2017-02-08 13:04:44 +02:00
|
|
|
"vcl/inc/sft.hxx", # CompositeFlags, WidthClass, WeightClass
|
2017-02-08 13:37:50 +02:00
|
|
|
"vcl/inc/CommonSalLayout.hxx", # VerticalOrientation
|
2017-02-09 16:30:15 +02:00
|
|
|
"include/tools/fontenum.hxx", # part of GDI file format
|
2017-02-13 11:06:07 +02:00
|
|
|
"svx/inc/galobj.hxx", # GalSoundType
|
2017-02-14 09:49:14 +02:00
|
|
|
"include/svx/msdffdef.hxx",
|
2017-02-14 14:46:58 +02:00
|
|
|
"include/svtools/rtftoken.h", # RTF_TOKEN_IDS
|
2017-02-14 15:36:53 +02:00
|
|
|
"starmath/source/mathtype.hxx", # MathType::MTOKENS
|
2017-02-15 09:36:42 +02:00
|
|
|
"sd/source/filter/eppt/epptbase.hxx", # PPTExTextAttr
|
2017-02-15 11:27:08 +02:00
|
|
|
"sc/source/filter/inc/tokstack.hxx", # E_TYPE
|
2017-02-16 10:32:45 +02:00
|
|
|
"filter/source/graphicfilter/icgm/cgmtypes.hxx",
|
2017-02-16 13:45:37 +02:00
|
|
|
":basic/source/inc/filefmt.hxx", # FileOffset
|
2017-02-03 11:28:17 +02:00
|
|
|
# unit test code
|
|
|
|
"cppu/source/uno/check.cxx",
|
|
|
|
# general weird nonsense going on
|
|
|
|
"framework/inc/helper/mischelper.hxx"
|
|
|
|
"include/sfx2/shell.hxx",
|
2017-02-06 09:15:51 +02:00
|
|
|
"framework/inc/helper/mischelper.hxx",
|
2017-02-06 11:42:25 +02:00
|
|
|
"include/svtools/htmltokn.h",
|
|
|
|
"include/sfx2/shell.hxx",
|
2017-02-06 13:51:47 +02:00
|
|
|
"sw/inc/iodetect.hxx",
|
|
|
|
"sw/inc/fmtfordr.hxx",
|
|
|
|
"sw/inc/flddat.hxx",
|
2017-02-10 10:45:28 +02:00
|
|
|
"sw/source/uibase/config/modcfg.cxx", # InsertConfigProp
|
2017-02-13 10:34:45 +02:00
|
|
|
"sw/inc/calc.hxx", # SwCalcOper
|
2017-02-14 10:00:24 +02:00
|
|
|
"svtools/source/config/helpopt.cxx", # HelpProperty
|
2017-02-14 15:20:49 +02:00
|
|
|
"include/svtools/htmltokn.h",
|
2017-02-14 16:20:50 +02:00
|
|
|
"include/sfx2/sidebar/Theme.hxx", # ThemeItem
|
2017-02-15 11:05:37 +02:00
|
|
|
"sc/source/ui/docshell/impex.cxx", # SylkVersion
|
2017-02-15 15:34:00 +02:00
|
|
|
"include/rsc/rsc-vcl-shared-types.hxx", # KeyFuncType
|
|
|
|
"include/i18nutil/paper.hxx", # Paper
|
2017-02-16 10:55:46 +02:00
|
|
|
"cppcanvas/source/mtfrenderer/emfplus.cxx", # EmfPlusCombineMode
|
|
|
|
"cppcanvas/source/mtfrenderer/emfpbrush.hxx", # EmfPlusHatchStyle
|
|
|
|
"include/filter/msfilter/svdfppt.hxx", # PptPlaceholder, PptSlideLayout
|
|
|
|
"include/filter/msfilter/escherex.hxx", # various
|
2017-02-16 13:45:37 +02:00
|
|
|
"basic/source/inc/opcodes.hxx", # SbiOpcode
|
|
|
|
"basic/source/inc/token.hxx", # SbiToken
|
|
|
|
"binaryurp/source/specialfunctionids.hxx", # binaryurp::SpecialFunctionIds
|
2017-02-03 11:28:17 +02:00
|
|
|
# Windows or OSX only
|
|
|
|
"include/canvas/rendering/icolorbuffer.hxx",
|
|
|
|
"include/vcl/commandevent.hxx",
|
2017-02-03 15:59:06 +02:00
|
|
|
"vcl/inc/unx/gendata.hxx",
|
2017-02-08 10:40:28 +02:00
|
|
|
"vcl/inc/salwtype.hxx",
|
|
|
|
"include/vcl/svapp.hxx",
|
|
|
|
"include/vcl/salbtype.hxx",
|
2017-02-08 12:00:27 +02:00
|
|
|
"include/vcl/commandevent.hxx", # CommandEvent, MediaCommand, ShowDialogId
|
2017-02-03 11:28:17 +02:00
|
|
|
# must match some other enum
|
|
|
|
"include/editeng/bulletitem.hxx",
|
|
|
|
"include/editeng/svxenum.hxx",
|
|
|
|
"include/formula/opcode.hxx",
|
|
|
|
"include/i18nutil/paper.hxx",
|
|
|
|
"include/oox/drawingml/shapepropertymap.hxx",
|
|
|
|
"include/svl/nfkeytab.hx",
|
|
|
|
"include/svl/zforlist.hxx",
|
2017-02-06 14:03:46 +02:00
|
|
|
"include/svtools/svtabbx.hxx",
|
2017-02-08 12:00:27 +02:00
|
|
|
"include/vcl/print.hxx", # NupOrderType, from UI combobox
|
2017-02-10 10:15:43 +02:00
|
|
|
"sw/source/uibase/inc/swcont.hxx", # RegionMode, from UI; ContentTypeId, from UI(registry)
|
2017-02-10 11:15:26 +02:00
|
|
|
"sw/inc/toxe.hxx", # ToxAuthorityType (from UI)
|
2017-02-13 11:51:28 +02:00
|
|
|
"include/svx/sxekitm.hxx", # SdrEdgeKind (from UI)
|
2017-02-14 09:49:14 +02:00
|
|
|
"include/svx/paraprev.hxx", # SvxPrevLineSpace (from UI)
|
2017-02-14 09:56:43 +02:00
|
|
|
"include/svx/ctredlin.hxx", # SvxRedlinDateMode (from UI)
|
2017-02-15 09:36:42 +02:00
|
|
|
"sd/source/ui/inc/animobjs.hxx", # BitmapAdjustment (from UI)
|
|
|
|
"sd/source/ui/dlg/PhotoAlbumDialog.hxx", # SlideImageLayout (from UI)
|
|
|
|
"sd/inc/pres.hxx", # AutoLayout (from UI)
|
2017-02-15 11:02:09 +02:00
|
|
|
"sc/source/ui/inc/scuitphfedit.hxx", # ScHFEntryId (from UI)
|
2017-02-15 15:44:07 +02:00
|
|
|
"include/i18nlangtag/languagetag.hxx", # LanguageTag::ScriptType
|
2017-02-16 10:32:45 +02:00
|
|
|
"extensions/source/scanner/grid.hxx", # ResetType (from UI)
|
2017-02-16 10:55:46 +02:00
|
|
|
"dbaccess/source/inc/dsntypes.hxx", # dbaccess::DATASOURCE_TYPE (from UI)
|
|
|
|
"cui/source/tabpages/tparea.cxx", # FillType (from UI)
|
|
|
|
"include/editeng/svxenum.hxx", # css::style::NumberingType
|
2017-02-16 12:30:13 +02:00
|
|
|
"include/editeng/bulletitem.hxx", # css::style::NumberingType
|
2017-02-16 13:45:37 +02:00
|
|
|
":basic/source/sbx/sbxdec.hxx", # SbxDecimal::CmpResult, must match some Windows API
|
2017-02-03 11:28:17 +02:00
|
|
|
# represents constants from an external API
|
|
|
|
"opencl/inc/opencl_device_selection.h",
|
|
|
|
"vcl/inc/sft.hxx",
|
|
|
|
"vcl/inc/unx/XIM.h",
|
|
|
|
"vcl/unx/gtk/xid_fullscreen_on_all_monitors.c",
|
2017-02-08 10:40:28 +02:00
|
|
|
"vcl/unx/gtk/salnativewidgets-gtk.cxx",
|
2017-02-15 14:12:03 +02:00
|
|
|
"sc/inc/callform.hxx", # ParamType
|
2017-02-15 15:44:07 +02:00
|
|
|
"include/i18nlangtag/applelangid.hxx", # AppleLanguageId
|
2017-02-03 11:28:17 +02:00
|
|
|
]):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if d[1] == "UNKNOWN" or d[1].endswith("NONE") or d[1].endswith("None") or d[1].endswith("EQUAL_SIZE"): continue
|
|
|
|
|
|
|
|
untouchedSet.add((d[0] + " " + d[1], srcLoc))
|
|
|
|
|
|
|
|
writeonlySet = set()
|
|
|
|
for d in writeSet:
|
|
|
|
if d in readSet:
|
|
|
|
continue
|
|
|
|
srcLoc = definitionToSourceLocationMap[d];
|
|
|
|
writeonlySet.add((d[0] + " " + d[1], srcLoc))
|
|
|
|
|
|
|
|
readonlySet = set()
|
|
|
|
for d in readSet:
|
|
|
|
if d in writeSet:
|
|
|
|
continue
|
|
|
|
srcLoc = definitionToSourceLocationMap[d];
|
|
|
|
readonlySet.add((d[0] + " " + d[1], srcLoc))
|
|
|
|
|
|
|
|
# sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
|
|
|
|
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
|
|
|
|
return [int(text) if text.isdigit() else text.lower()
|
|
|
|
for text in re.split(_nsre, s)]
|
|
|
|
|
|
|
|
# sort results by name and line number
|
|
|
|
tmp1list = sorted(untouchedSet, key=lambda v: natural_sort_key(v[1]))
|
|
|
|
tmp2list = sorted(writeonlySet, key=lambda v: natural_sort_key(v[1]))
|
|
|
|
tmp3list = sorted(readonlySet, key=lambda v: natural_sort_key(v[1]))
|
|
|
|
|
|
|
|
# print out the results
|
|
|
|
with open("loplugin.unusedenumconstants.report-untouched", "wt") as f:
|
|
|
|
for t in tmp1list:
|
|
|
|
f.write( t[1] + "\n" )
|
|
|
|
f.write( " " + t[0] + "\n" )
|
|
|
|
with open("loplugin.unusedenumconstants.report-writeonly", "wt") as f:
|
|
|
|
for t in tmp2list:
|
|
|
|
f.write( t[1] + "\n" )
|
|
|
|
f.write( " " + t[0] + "\n" )
|
|
|
|
with open("loplugin.unusedenumconstants.report-readonly", "wt") as f:
|
|
|
|
for t in tmp3list:
|
|
|
|
f.write( t[1] + "\n" )
|
|
|
|
f.write( " " + t[0] + "\n" )
|
|
|
|
|
|
|
|
|