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
90ed4824
Kaydet (Commit)
90ed4824
authored
Mar 31, 2015
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reduce to static_cast any reinterpret_cast from void pointers
Change-Id: I514e183571e4ac109f59c4bdfccdc553c36c26ee
üst
698a6d4a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
3 deletions
+51
-3
redundantcast.cxx
compilerplugins/clang/redundantcast.cxx
+51
-3
No files found.
compilerplugins/clang/redundantcast.cxx
Dosyayı görüntüle @
90ed4824
...
@@ -36,10 +36,11 @@ bool isVoidPointer(QualType type) {
...
@@ -36,10 +36,11 @@ bool isVoidPointer(QualType type) {
}
}
class
RedundantCast
:
class
RedundantCast
:
public
RecursiveASTVisitor
<
RedundantCast
>
,
public
loplugin
::
Plugin
public
RecursiveASTVisitor
<
RedundantCast
>
,
public
loplugin
::
Rewrite
Plugin
{
{
public
:
public
:
explicit
RedundantCast
(
InstantiationData
const
&
data
)
:
Plugin
(
data
)
{}
explicit
RedundantCast
(
InstantiationData
const
&
data
)
:
RewritePlugin
(
data
)
{}
virtual
void
run
()
override
{
virtual
void
run
()
override
{
if
(
compiler
.
getLangOpts
().
CPlusPlus
)
{
if
(
compiler
.
getLangOpts
().
CPlusPlus
)
{
...
@@ -49,6 +50,8 @@ public:
...
@@ -49,6 +50,8 @@ public:
bool
VisitImplicitCastExpr
(
ImplicitCastExpr
const
*
expr
);
bool
VisitImplicitCastExpr
(
ImplicitCastExpr
const
*
expr
);
bool
VisitCXXReinterpretCastExpr
(
CXXReinterpretCastExpr
const
*
expr
);
bool
VisitCallExpr
(
CallExpr
const
*
expr
);
bool
VisitCallExpr
(
CallExpr
const
*
expr
);
bool
VisitCXXDeleteExpr
(
CXXDeleteExpr
const
*
expr
);
bool
VisitCXXDeleteExpr
(
CXXDeleteExpr
const
*
expr
);
...
@@ -159,6 +162,51 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
...
@@ -159,6 +162,51 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
return
true
;
return
true
;
}
}
bool
RedundantCast
::
VisitCXXReinterpretCastExpr
(
CXXReinterpretCastExpr
const
*
expr
)
{
if
(
ignoreLocation
(
expr
)
||
!
expr
->
getSubExpr
()
->
getType
()
->
isVoidPointerType
())
{
return
true
;
}
auto
t
=
expr
->
getType
()
->
getAs
<
PointerType
>
();
if
(
t
==
nullptr
||
!
t
->
getPointeeType
()
->
isObjectType
())
{
return
true
;
}
if
(
rewriter
!=
nullptr
)
{
auto
loc
=
expr
->
getLocStart
();
while
(
compiler
.
getSourceManager
().
isMacroArgExpansion
(
loc
))
{
loc
=
compiler
.
getSourceManager
().
getImmediateMacroCallerLoc
(
loc
);
}
if
(
compat
::
isMacroBodyExpansion
(
compiler
,
loc
))
{
auto
loc2
=
expr
->
getLocEnd
();
while
(
compiler
.
getSourceManager
().
isMacroArgExpansion
(
loc2
))
{
loc2
=
compiler
.
getSourceManager
().
getImmediateMacroCallerLoc
(
loc2
);
}
if
(
compat
::
isMacroBodyExpansion
(
compiler
,
loc2
))
{
//TODO: check loc, loc2 are in same macro body expansion
loc
=
compiler
.
getSourceManager
().
getSpellingLoc
(
loc
);
}
}
auto
s
=
compiler
.
getSourceManager
().
getCharacterData
(
loc
);
auto
n
=
Lexer
::
MeasureTokenLength
(
loc
,
compiler
.
getSourceManager
(),
compiler
.
getLangOpts
());
std
::
string
tok
(
s
,
n
);
if
(
tok
==
"reinterpret_cast"
&&
replaceText
(
loc
,
n
,
"static_cast"
))
{
return
true
;
}
}
report
(
DiagnosticsEngine
::
Warning
,
"reinterpret_cast from %0 to %1 can be simplified to static_cast"
,
expr
->
getExprLoc
())
<<
expr
->
getSubExprAsWritten
()
->
getType
()
<<
expr
->
getType
()
<<
expr
->
getSourceRange
();
return
true
;
}
bool
RedundantCast
::
VisitCallExpr
(
CallExpr
const
*
expr
)
{
bool
RedundantCast
::
VisitCallExpr
(
CallExpr
const
*
expr
)
{
if
(
ignoreLocation
(
expr
))
{
if
(
ignoreLocation
(
expr
))
{
return
true
;
return
true
;
...
@@ -229,7 +277,7 @@ bool RedundantCast::visitBinOp(BinaryOperator const * expr) {
...
@@ -229,7 +277,7 @@ bool RedundantCast::visitBinOp(BinaryOperator const * expr) {
return
true
;
return
true
;
}
}
loplugin
::
Plugin
::
Registration
<
RedundantCast
>
X
(
"redundantcast"
);
loplugin
::
Plugin
::
Registration
<
RedundantCast
>
X
(
"redundantcast"
,
true
);
}
}
...
...
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