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
415d4347
Kaydet (Commit)
415d4347
authored
Eki 20, 2015
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make loplugin:defaultparams work for multiple default params per function
Change-Id: I0aa3841e1ac3375f519384f3012450bc683d1c51
üst
c4e8c39e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
36 deletions
+46
-36
defaultparams.cxx
compilerplugins/clang/defaultparams.cxx
+46
-36
No files found.
compilerplugins/clang/defaultparams.cxx
Dosyayı görüntüle @
415d4347
...
@@ -32,51 +32,61 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
...
@@ -32,51 +32,61 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
if
(
ignoreLocation
(
callExpr
))
{
if
(
ignoreLocation
(
callExpr
))
{
return
true
;
return
true
;
}
}
if
(
callExpr
->
getNumArgs
()
==
0
)
{
return
true
;
}
if
(
callExpr
->
getDirectCallee
()
==
nullptr
)
{
if
(
callExpr
->
getDirectCallee
()
==
nullptr
)
{
return
true
;
return
true
;
}
}
const
FunctionDecl
*
functionDecl
=
callExpr
->
getDirectCallee
()
->
getCanonicalDecl
();
const
FunctionDecl
*
functionDecl
=
callExpr
->
getDirectCallee
()
->
getCanonicalDecl
();
unsigned
i
=
callExpr
->
getNumArgs
()
-
1
;
auto
n
=
functionDecl
->
getNumParams
();
Expr
*
arg
=
callExpr
->
getArg
(
i
);
if
(
n
==
0
||
!
functionDecl
->
getParamDecl
(
n
-
1
)
->
hasDefaultArg
())
{
// variadic functions
if
(
i
>=
functionDecl
->
getNumParams
())
{
return
true
;
}
if
(
arg
->
isDefaultArgument
())
{
return
true
;
}
// ignore this, it seems to trigger an infinite recursion
if
(
isa
<
UnaryExprOrTypeTraitExpr
>
(
arg
))
return
true
;
const
ParmVarDecl
*
parmVarDecl
=
functionDecl
->
getParamDecl
(
i
);
if
(
!
parmVarDecl
->
hasDefaultArg
()
||
parmVarDecl
->
hasUninstantiatedDefaultArg
())
{
return
true
;
return
true
;
}
}
const
Expr
*
defaultArgExpr
=
parmVarDecl
->
getDefaultArg
();
if
(
callExpr
->
getNumArgs
()
>
n
){
if
(
defaultArgExpr
&&
report
(
defaultArgExpr
->
getType
()
->
isIntegralType
(
compiler
.
getASTContext
()))
DiagnosticsEngine
::
Warning
,
"TODO %0 != %1"
,
callExpr
->
getLocStart
())
{
<<
callExpr
->
getNumArgs
()
<<
n
<<
callExpr
->
getSourceRange
();
callExpr
->
dump
();
return
true
;
}
assert
(
callExpr
->
getNumArgs
()
<=
n
);
// can be < in template code
for
(
unsigned
i
=
callExpr
->
getNumArgs
();
i
!=
0
;)
{
--
i
;
Expr
*
arg
=
callExpr
->
getArg
(
i
);
if
(
arg
->
isDefaultArgument
())
{
continue
;
}
// ignore this, it seems to trigger an infinite recursion
if
(
isa
<
UnaryExprOrTypeTraitExpr
>
(
arg
))
break
;
const
ParmVarDecl
*
parmVarDecl
=
functionDecl
->
getParamDecl
(
i
);
if
(
!
parmVarDecl
->
hasDefaultArg
()
||
parmVarDecl
->
hasUninstantiatedDefaultArg
())
{
break
;
}
const
Expr
*
defaultArgExpr
=
parmVarDecl
->
getDefaultArg
();
if
(
!
(
defaultArgExpr
&&
defaultArgExpr
->
getType
()
->
isIntegralType
(
compiler
.
getASTContext
())))
{
break
;
}
APSInt
x1
,
x2
;
APSInt
x1
,
x2
;
if
(
arg
->
EvaluateAsInt
(
x1
,
compiler
.
getASTContext
())
&&
if
(
!
(
arg
->
EvaluateAsInt
(
x1
,
compiler
.
getASTContext
())
&&
defaultArgExpr
->
EvaluateAsInt
(
x2
,
compiler
.
getASTContext
())
&&
defaultArgExpr
->
EvaluateAsInt
(
x2
,
compiler
.
getASTContext
())
&&
x1
==
x2
)
x1
==
x2
)
)
{
{
report
(
break
;
DiagnosticsEngine
::
Warning
,
"not necessary to pass this argument, it defaults to the same value"
,
arg
->
getSourceRange
().
getBegin
())
<<
arg
->
getSourceRange
();
/*report(
DiagnosticsEngine::Warning,
"default method parameter declaration here",
parmVarDecl->getSourceRange().getBegin())
<< parmVarDecl->getSourceRange();*/
}
}
report
(
DiagnosticsEngine
::
Warning
,
"not necessary to pass this argument, it defaults to the same value"
,
arg
->
getSourceRange
().
getBegin
())
<<
arg
->
getSourceRange
();
report
(
DiagnosticsEngine
::
Note
,
"default method parameter declaration here"
,
parmVarDecl
->
getSourceRange
().
getBegin
())
<<
parmVarDecl
->
getSourceRange
();
}
}
return
true
;
return
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