12 def parseFieldInfo( tokens
):
13 return (tokens
[1].strip(), tokens
[2].strip())
15 with io
.open("workdir/loplugin.unusedvarsglobal.log", "rb", buffering
=1024*1024) as txt
:
18 tokens
= line
.strip().split("\t")
19 if tokens
[0] == "definition:":
21 # ignore external source code
22 if (srcLoc
.startswith("external/")):
25 if (srcLoc
.startswith("workdir/")):
27 varname
= tokens
[1].strip()
28 vartype
= tokens
[2].strip()
29 if vartype
.startswith("const "):
31 if vartype
.startswith("class "):
33 if vartype
.startswith("struct "):
35 if vartype
.startswith("::"):
37 fieldInfo
= (srcLoc
, varname
)
38 definitionSet
.add(fieldInfo
)
39 defToTypeMap
[fieldInfo
] = vartype
40 elif tokens
[0] == "read:":
42 readFromSet
.add(parseFieldInfo(tokens
))
43 elif tokens
[0] == "write:":
45 writeToSet
.add(parseFieldInfo(tokens
))
47 print( "unknown line: " + line
)
49 print "problem with line " + line
.strip()
52 definitionSet2
= set()
53 for d
in definitionSet
:
55 vartype
= defToTypeMap
[d
]
58 if varname
.startswith("autoRegister"): # auto-generated CPPUNIT stuff
60 if vartype
in ["css::uno::ContextLayer", "SolarMutexGuard", "SolarMutexReleaser", "OpenGLZone"]:
62 if vartype
in ["PreDefaultWinNoOpenGLZone", "SchedulerGuard", "SkiaZone", "OpenGLVCLContextZone"]:
64 if vartype
in ["SwXDispatchProviderInterceptor::DispatchMutexLock_Impl", "SfxObjectShellLock", "OpenCLZone"]:
66 if vartype
in ["OpenCLInitialZone", "pyuno::PyThreadDetach", "SortRefUpdateSetter", "oglcanvas::TransformationPreserver"]:
68 if vartype
in ["StackHack", "osl::MutexGuard", "accessibility::SolarMethodGuard"]:
70 if vartype
in ["osl::ClearableMutexGuard", "comphelper::OExternalLockGuard", "osl::Guard< ::osl::Mutex>"]:
72 if vartype
in ["comphelper::OContextEntryGuard", "Guard<class osl::Mutex>", "basic::LibraryContainerMethodGuard"]:
74 if vartype
in ["canvas::CanvasBase::MutexType"]:
80 for d
in definitionSet2
:
81 if d
in readFromSet
or d
in writeToSet
:
89 for d
in definitionSet2
:
90 if d
in readFromSet
or d
in untouchedSet
:
93 vartype
= defToTypeMap
[d
]
94 if "Alive" in varname
:
98 if vartype
.endswith(" &"):
103 for d
in definitionSet2
:
104 if d
in writeToSet
or d
in untouchedSet
:
107 vartype
= defToTypeMap
[d
]
108 if "Dummy" in varname
:
110 if "Empty" in varname
:
112 if varname
in ["aOldValue", "aNewValue"]:
114 if "Exception" in vartype
and vartype
.endswith(" &"):
116 if "exception" in vartype
and vartype
.endswith(" &"):
118 # TODO for now, focus on the simple stuff
119 if not (vartype
in ["rtl::OUString", "Bool"]):
123 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
124 def natural_sort_key(s
, _nsre
=re
.compile('([0-9]+)')):
125 return [int(text
) if text
.isdigit() else text
.lower()
126 for text
in re
.split(_nsre
, s
)]
127 # sort by both the source-line and the datatype, so the output file ordering is stable
128 # when we have multiple items on the same source line
130 return natural_sort_key(v
[0]) + [v
[1]]
132 # sort results by name and line number
133 tmp1list
= sorted(untouchedSet
, key
=lambda v
: v_sort_key(v
))
134 tmp2list
= sorted(writeonlySet
, key
=lambda v
: v_sort_key(v
))
135 tmp3list
= sorted(readonlySet
, key
=lambda v
: v_sort_key(v
))
137 # print out the results
138 with
open("compilerplugins/clang/unusedvarsglobal.untouched.results", "wt") as f
:
140 f
.write( t
[0] + "\n" )
141 f
.write( " " + defToTypeMap
[t
] + " " + t
[1] + "\n" )
142 with
open("compilerplugins/clang/unusedvarsglobal.writeonly.results", "wt") as f
:
144 f
.write( t
[0] + "\n" )
145 f
.write( " " + defToTypeMap
[t
] + " " + t
[1] + "\n" )
146 with
open("compilerplugins/clang/unusedvarsglobal.readonly.results", "wt") as f
:
148 f
.write( t
[0] + "\n" )
149 f
.write( " " + defToTypeMap
[t
] + " " + t
[1] + "\n" )