11 def parseFieldInfo( tokens
):
12 return (tokens
[1].strip(), tokens
[2].strip())
14 with io
.open("workdir/loplugin.unusedvarsglobal.log", "r", buffering
=16*1024*1024) as txt
:
17 tokens
= line
.strip().split("\t")
18 if tokens
[0] == "definition:":
20 # ignore external source code
21 if (srcLoc
.startswith("external/")):
24 if (srcLoc
.startswith("workdir/")):
26 varname
= tokens
[1].strip()
27 vartype
= tokens
[2].strip()
28 if vartype
.startswith("const "):
30 if vartype
.startswith("class "):
32 if vartype
.startswith("struct "):
34 if vartype
.startswith("::"):
36 fieldInfo
= (srcLoc
, varname
)
37 definitionSet
.add(fieldInfo
)
38 defToTypeMap
[fieldInfo
] = vartype
39 elif tokens
[0] == "read:":
41 readFromSet
.add(parseFieldInfo(tokens
))
42 elif tokens
[0] == "write:":
44 writeToSet
.add(parseFieldInfo(tokens
))
46 print( "unknown line: " + line
)
48 print("problem with line " + line
.strip())
51 definitionSet2
= set()
52 for d
in definitionSet
:
54 vartype
= defToTypeMap
[d
]
57 if varname
.startswith("autoRegister"): # auto-generated CPPUNIT stuff
59 if vartype
in ["css::uno::ContextLayer", "SolarMutexGuard", "SolarMutexReleaser", "OpenGLZone"]:
61 if vartype
in ["PreDefaultWinNoOpenGLZone", "SchedulerGuard", "SkiaZone", "OpenGLVCLContextZone"]:
63 if vartype
in ["SwXDispatchProviderInterceptor::DispatchMutexLock_Impl", "SfxObjectShellLock", "OpenCLZone"]:
65 if vartype
in ["OpenCLInitialZone", "pyuno::PyThreadDetach", "SortRefUpdateSetter", "oglcanvas::TransformationPreserver"]:
67 if vartype
in ["StackHack", "osl::MutexGuard", "accessibility::SolarMethodGuard"]:
69 if vartype
in ["osl::ClearableMutexGuard", "comphelper::OExternalLockGuard", "osl::Guard< ::osl::Mutex>"]:
71 if vartype
in ["comphelper::OContextEntryGuard", "Guard<class osl::Mutex>", "basic::LibraryContainerMethodGuard"]:
73 if vartype
in ["canvas::CanvasBase::MutexType"]:
79 for d
in definitionSet2
:
80 if d
in readFromSet
or d
in writeToSet
:
88 for d
in definitionSet2
:
89 if d
in readFromSet
or d
in untouchedSet
:
92 vartype
= defToTypeMap
[d
]
93 if "Alive" in varname
:
97 if vartype
.endswith(" &"):
102 for d
in definitionSet2
:
103 if d
in writeToSet
or d
in untouchedSet
:
106 vartype
= defToTypeMap
[d
]
107 if "Dummy" in varname
:
109 if "Empty" in varname
:
111 if varname
in ["aOldValue", "aNewValue"]:
113 if "Exception" in vartype
and vartype
.endswith(" &"):
115 if "exception" in vartype
and vartype
.endswith(" &"):
117 # TODO for now, focus on the simple stuff
118 if not (vartype
in ["rtl::OUString", "Bool"]):
122 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
123 def natural_sort_key(s
, _nsre
=re
.compile('([0-9]+)')):
124 return [int(text
) if text
.isdigit() else text
.lower()
125 for text
in re
.split(_nsre
, s
)]
126 # sort by both the source-line and the datatype, so the output file ordering is stable
127 # when we have multiple items on the same source line
129 return natural_sort_key(v
[0]) + [v
[1]]
131 # sort results by name and line number
132 tmp1list
= sorted(untouchedSet
, key
=lambda v
: v_sort_key(v
))
133 tmp2list
= sorted(writeonlySet
, key
=lambda v
: v_sort_key(v
))
134 tmp3list
= sorted(readonlySet
, key
=lambda v
: v_sort_key(v
))
136 # print out the results
137 with
open("compilerplugins/clang/unusedvarsglobal.untouched.results", "wt") as f
:
139 f
.write( t
[0] + "\n" )
140 f
.write( " " + defToTypeMap
[t
] + " " + t
[1] + "\n" )
141 with
open("compilerplugins/clang/unusedvarsglobal.writeonly.results", "wt") as f
:
143 f
.write( t
[0] + "\n" )
144 f
.write( " " + defToTypeMap
[t
] + " " + t
[1] + "\n" )
145 with
open("compilerplugins/clang/unusedvarsglobal.readonly.results", "wt") as f
:
147 f
.write( t
[0] + "\n" )
148 f
.write( " " + defToTypeMap
[t
] + " " + t
[1] + "\n" )