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
44d0e286
Kaydet (Commit)
44d0e286
authored
Ock 08, 2015
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
loplugin:cstylecast: improve detection of C code
Change-Id: Id5dd1ee1a29c4e1c7cb2b58419d6ccb1f032bffe
üst
bb65b096
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
7 deletions
+43
-7
compat.hxx
compilerplugins/clang/compat.hxx
+8
-0
cstylecast.cxx
compilerplugins/clang/cstylecast.cxx
+35
-7
No files found.
compilerplugins/clang/compat.hxx
Dosyayı görüntüle @
44d0e286
...
...
@@ -56,6 +56,14 @@ inline bool isExternCContext(clang::DeclContext const & ctxt) {
#endif
}
inline
bool
isInExternCContext
(
clang
::
FunctionDecl
const
&
decl
)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
return
decl
.
isInExternCContext
();
#else
return
isExternalCContext
(
*
decl
.
getCanonicalDecl
()
->
getDeclContext
());
#endif
}
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
typedef
clang
::
LinkageInfo
LinkageInfo
;
#else
...
...
compilerplugins/clang/cstylecast.cxx
Dosyayı görüntüle @
44d0e286
...
...
@@ -7,6 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <cassert>
#include <string>
#include "plugin.hxx"
#include "compat.hxx"
...
...
@@ -17,6 +18,10 @@
namespace
{
bool
hasCLanguageLinkageType
(
FunctionDecl
const
*
decl
)
{
return
decl
->
isExternC
()
||
compat
::
isInExternCContext
(
*
decl
);
}
QualType
resolvePointers
(
QualType
type
)
{
while
(
type
->
isPointerType
())
{
type
=
type
->
getAs
<
PointerType
>
()
->
getPointeeType
();
...
...
@@ -28,7 +33,9 @@ class CStyleCast:
public
RecursiveASTVisitor
<
CStyleCast
>
,
public
loplugin
::
Plugin
{
public
:
explicit
CStyleCast
(
InstantiationData
const
&
data
)
:
Plugin
(
data
)
{}
explicit
CStyleCast
(
InstantiationData
const
&
data
)
:
Plugin
(
data
),
externCFunction
(
false
)
{}
virtual
void
run
()
override
{
if
(
compiler
.
getLangOpts
().
CPlusPlus
)
{
...
...
@@ -36,7 +43,12 @@ public:
}
}
bool
TraverseFunctionDecl
(
FunctionDecl
*
decl
);
bool
VisitCStyleCastExpr
(
const
CStyleCastExpr
*
expr
);
private
:
bool
externCFunction
;
};
static
const
char
*
recommendedFix
(
clang
::
CastKind
ck
)
{
...
...
@@ -48,6 +60,20 @@ static const char * recommendedFix(clang::CastKind ck) {
}
}
bool
CStyleCast
::
TraverseFunctionDecl
(
FunctionDecl
*
decl
)
{
bool
ext
=
hasCLanguageLinkageType
(
decl
)
&&
decl
->
isThisDeclarationADefinition
();
if
(
ext
)
{
assert
(
!
externCFunction
);
externCFunction
=
true
;
}
bool
ret
=
RecursiveASTVisitor
::
TraverseFunctionDecl
(
decl
);
if
(
ext
)
{
externCFunction
=
false
;
}
return
ret
;
}
bool
CStyleCast
::
VisitCStyleCastExpr
(
const
CStyleCastExpr
*
expr
)
{
if
(
ignoreLocation
(
expr
))
{
return
true
;
...
...
@@ -89,12 +115,14 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) {
if
(
expr
->
getCastKind
()
==
CK_Dependent
)
{
return
true
;
}
SourceLocation
spellingLocation
=
compiler
.
getSourceManager
().
getSpellingLoc
(
expr
->
getLocStart
());
StringRef
filename
=
compiler
.
getSourceManager
().
getFilename
(
spellingLocation
);
// ignore C code
if
(
filename
.
endswith
(
".h"
)
)
{
return
true
;
if
(
externCFunction
||
expr
->
getLocStart
().
isMacroID
())
{
SourceLocation
spellingLocation
=
compiler
.
getSourceManager
().
getSpellingLoc
(
expr
->
getLocStart
());
StringRef
filename
=
compiler
.
getSourceManager
().
getFilename
(
spellingLocation
);
// ignore C code
if
(
filename
.
endswith
(
".h"
)
)
{
return
true
;
}
}
report
(
DiagnosticsEngine
::
Warning
,
...
...
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