Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
86bb6fdf
Kaydet (Commit)
86bb6fdf
authored
Ock 11, 2016
tarafından
Noel Grandin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
update unusedmethods loplugin to update unused return values
Change-Id: I825d022d09282bc9b6cffd9178e40e4090d335da
üst
f7c23897
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
12 deletions
+79
-12
plugin.cxx
compilerplugins/clang/plugin.cxx
+3
-3
unusedmethods.cxx
compilerplugins/clang/unusedmethods.cxx
+32
-6
unusedmethods.py
compilerplugins/clang/unusedmethods.py
+44
-3
No files found.
compilerplugins/clang/plugin.cxx
Dosyayı görüntüle @
86bb6fdf
...
...
@@ -61,8 +61,8 @@ const Stmt* Plugin::parentStmt( const Stmt* stmt )
{
if
(
parents
.
empty
())
buildParents
(
compiler
);
if
(
parents
.
count
(
stmt
)
!=
1
)
stmt
->
dump
();
assert
(
parents
.
count
(
stmt
)
==
1
);
//
if(parents.count(stmt)!=1)stmt->dump();
//
assert( parents.count( stmt ) == 1 );
return
parents
[
stmt
];
}
...
...
@@ -70,7 +70,7 @@ Stmt* Plugin::parentStmt( Stmt* stmt )
{
if
(
parents
.
empty
())
buildParents
(
compiler
);
assert
(
parents
.
count
(
stmt
)
==
1
);
//
assert( parents.count( stmt ) == 1 );
return
const_cast
<
Stmt
*
>
(
parents
[
stmt
]
);
}
...
...
compilerplugins/clang/unusedmethods.cxx
Dosyayı görüntüle @
86bb6fdf
...
...
@@ -59,6 +59,7 @@ struct MyFuncInfo
// try to limit the voluminous output a little
static
std
::
set
<
MyFuncInfo
>
callSet
;
static
std
::
set
<
MyFuncInfo
>
usedReturnSet
;
static
std
::
set
<
MyFuncInfo
>
definitionSet
;
...
...
@@ -82,6 +83,8 @@ public:
std
::
string
output
;
for
(
const
MyFuncInfo
&
s
:
callSet
)
output
+=
"call:
\t
"
+
s
.
returnType
+
"
\t
"
+
s
.
nameAndParams
+
"
\n
"
;
for
(
const
MyFuncInfo
&
s
:
usedReturnSet
)
output
+=
"usedReturn:
\t
"
+
s
.
returnType
+
"
\t
"
+
s
.
nameAndParams
+
"
\n
"
;
for
(
const
MyFuncInfo
&
s
:
definitionSet
)
{
//treat all UNO interfaces as having been called, since they are part of our external ABI
...
...
@@ -100,7 +103,7 @@ public:
bool
VisitFunctionDecl
(
const
FunctionDecl
*
decl
);
bool
VisitDeclRefExpr
(
const
DeclRefExpr
*
);
private
:
void
logCallToRootMethods
(
const
FunctionDecl
*
functionDecl
);
void
logCallToRootMethods
(
const
FunctionDecl
*
functionDecl
,
std
::
set
<
MyFuncInfo
>&
funcSet
);
MyFuncInfo
niceName
(
const
FunctionDecl
*
functionDecl
);
std
::
string
fullyQualifiedName
(
const
FunctionDecl
*
functionDecl
);
};
...
...
@@ -172,7 +175,7 @@ std::string UnusedMethods::fullyQualifiedName(const FunctionDecl* functionDecl)
return
ret
;
}
void
UnusedMethods
::
logCallToRootMethods
(
const
FunctionDecl
*
functionDecl
)
void
UnusedMethods
::
logCallToRootMethods
(
const
FunctionDecl
*
functionDecl
,
std
::
set
<
MyFuncInfo
>&
funcSet
)
{
functionDecl
=
functionDecl
->
getCanonicalDecl
();
bool
bCalledSuperMethod
=
false
;
...
...
@@ -183,7 +186,7 @@ void UnusedMethods::logCallToRootMethods(const FunctionDecl* functionDecl)
for
(
CXXMethodDecl
::
method_iterator
it
=
methodDecl
->
begin_overridden_methods
();
it
!=
methodDecl
->
end_overridden_methods
();
++
it
)
{
logCallToRootMethods
(
*
it
);
logCallToRootMethods
(
*
it
,
funcSet
);
bCalledSuperMethod
=
true
;
}
}
...
...
@@ -191,7 +194,7 @@ void UnusedMethods::logCallToRootMethods(const FunctionDecl* functionDecl)
{
while
(
functionDecl
->
getTemplateInstantiationPattern
())
functionDecl
=
functionDecl
->
getTemplateInstantiationPattern
();
call
Set
.
insert
(
niceName
(
functionDecl
));
func
Set
.
insert
(
niceName
(
functionDecl
));
}
}
...
...
@@ -227,7 +230,29 @@ gotfunc:
if
(
traversedFunctionSet
.
insert
(
fullyQualifiedName
(
calleeFunctionDecl
)).
second
)
TraverseFunctionDecl
(
calleeFunctionDecl
);
logCallToRootMethods
(
calleeFunctionDecl
);
logCallToRootMethods
(
calleeFunctionDecl
,
callSet
);
if
(
calleeFunctionDecl
->
getReturnType
()
->
isVoidType
())
{
return
true
;
}
const
Stmt
*
parent
=
parentStmt
(
expr
);
if
(
!
parent
)
{
return
true
;
}
if
(
isa
<
Expr
>
(
parent
)
||
isa
<
ReturnStmt
>
(
parent
)
||
isa
<
DeclStmt
>
(
parent
)
||
isa
<
IfStmt
>
(
parent
)
||
isa
<
SwitchStmt
>
(
parent
)
||
isa
<
ForStmt
>
(
parent
)
||
isa
<
WhileStmt
>
(
parent
)
||
isa
<
DoStmt
>
(
parent
)
||
isa
<
CXXForRangeStmt
>
(
parent
))
{
logCallToRootMethods
(
calleeFunctionDecl
,
usedReturnSet
);
return
true
;
}
if
(
isa
<
CompoundStmt
>
(
parent
)
||
isa
<
DefaultStmt
>
(
parent
)
||
isa
<
CaseStmt
>
(
parent
)
||
isa
<
LabelStmt
>
(
parent
))
{
return
true
;
}
parent
->
dump
();
return
true
;
}
...
...
@@ -267,7 +292,8 @@ bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
if
(
!
isa
<
FunctionDecl
>
(
functionDecl
))
{
return
true
;
}
logCallToRootMethods
(
dyn_cast
<
FunctionDecl
>
(
functionDecl
)
->
getCanonicalDecl
());
logCallToRootMethods
(
dyn_cast
<
FunctionDecl
>
(
functionDecl
)
->
getCanonicalDecl
(),
callSet
);
logCallToRootMethods
(
dyn_cast
<
FunctionDecl
>
(
functionDecl
)
->
getCanonicalDecl
(),
usedReturnSet
);
return
true
;
}
...
...
compilerplugins/clang/unusedmethods.py
Dosyayı görüntüle @
86bb6fdf
...
...
@@ -7,6 +7,7 @@ import io
definitionSet
=
set
()
definitionToSourceLocationMap
=
dict
()
callSet
=
set
()
returnSet
=
set
()
sourceLocationSet
=
set
()
# things we need to exclude for reasons like :
# - it's a weird template thingy that confuses the plugin
...
...
@@ -125,6 +126,9 @@ with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt:
elif
line
.
startswith
(
"call:
\t
"
):
idx1
=
line
.
find
(
"
\t
"
,
6
)
callSet
.
add
((
normalizeTypeParams
(
line
[
6
:
idx1
]),
normalizeTypeParams
(
line
[
idx1
+
1
:]
.
strip
())))
elif
line
.
startswith
(
"usedReturn:
\t
"
):
idx1
=
line
.
find
(
"
\t
"
,
12
)
returnSet
.
add
((
normalizeTypeParams
(
line
[
12
:
idx1
]),
normalizeTypeParams
(
line
[
idx1
+
1
:]
.
strip
())))
# Invert the definitionToSourceLocationMap
# If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
...
...
@@ -138,6 +142,10 @@ for k, definitions in sourceLocationToDefinitionMap.iteritems():
for
d
in
definitions
:
definitionSet
.
remove
(
d
)
# -------------------------------------------
# Do the "unused methods" part
# -------------------------------------------
tmp1set
=
set
()
for
d
in
definitionSet
:
clazz
=
d
[
0
]
+
" "
+
d
[
1
]
...
...
@@ -228,11 +236,44 @@ def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
tmp1list
=
sorted
(
tmp1set
,
key
=
lambda
v
:
natural_sort_key
(
v
[
1
]))
# print out the results
for
t
in
tmp1list
:
print
t
[
1
]
print
" "
,
t
[
0
]
#for t in tmp1list:
# print t[1]
# print " ", t[0]
# -------------------------------------------
# Do the "unused return types" part
# -------------------------------------------
tmp2set
=
set
()
for
d
in
definitionSet
:
clazz
=
d
[
0
]
+
" "
+
d
[
1
]
if
clazz
in
exclusionSet
:
continue
if
d
in
returnSet
:
continue
if
d
[
0
]
==
"void"
:
continue
# ignore UNO constructor method entrypoints
if
"_get_implementation"
in
d
[
1
]:
continue
# the plugin can't see calls to these
if
"operator new"
in
d
[
1
]:
continue
# unused return type is not a problem here
if
"operator=("
in
d
[
1
]:
continue
# ignore external code
if
definitionToSourceLocationMap
[
d
]
.
startswith
(
"external/"
):
continue
tmp2set
.
add
((
clazz
,
definitionToSourceLocationMap
[
d
]))
# sort results by name and line number
tmp2list
=
sorted
(
tmp2set
,
key
=
lambda
v
:
natural_sort_key
(
v
[
1
]))
for
t
in
tmp2list
:
print
t
[
1
]
print
" "
,
t
[
0
]
# add an empty line at the end to make it easier for the unusedmethodsremove plugin to mmap() the output file
print
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment