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
d2143eac
Kaydet (Commit)
d2143eac
authored
Eyl 06, 2016
tarafından
Noel Grandin
Kaydeden (comit)
Noel Grandin
Eyl 06, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
teach loplugin constantparam about default param values
Change-Id: I334622bd34d8349f5b3988122d282b1062b225bb
üst
d6906611
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
32 deletions
+52
-32
constantparam.cxx
compilerplugins/clang/constantparam.cxx
+47
-25
constantparam.py
compilerplugins/clang/constantparam.py
+5
-7
No files found.
compilerplugins/clang/constantparam.cxx
Dosyayı görüntüle @
d2143eac
...
@@ -96,11 +96,11 @@ public:
...
@@ -96,11 +96,11 @@ public:
bool
VisitDeclRefExpr
(
const
DeclRefExpr
*
);
bool
VisitDeclRefExpr
(
const
DeclRefExpr
*
);
bool
VisitCXXConstructExpr
(
const
CXXConstructExpr
*
);
bool
VisitCXXConstructExpr
(
const
CXXConstructExpr
*
);
private
:
private
:
MyCallSiteInfo
niceName
(
const
FunctionDecl
*
functionDecl
,
int
paramIndex
,
const
ParmVarDecl
*
parmVarDecl
,
const
std
::
string
&
callValue
);
MyCallSiteInfo
niceName
(
const
FunctionDecl
*
functionDecl
,
int
paramIndex
,
llvm
::
StringRef
paramName
,
const
std
::
string
&
callValue
);
std
::
string
getCallValue
(
const
Expr
*
arg
);
std
::
string
getCallValue
(
const
Expr
*
arg
);
};
};
MyCallSiteInfo
ConstantParam
::
niceName
(
const
FunctionDecl
*
functionDecl
,
int
paramIndex
,
const
ParmVarDecl
*
parmVarDecl
,
const
std
::
string
&
callValue
)
MyCallSiteInfo
ConstantParam
::
niceName
(
const
FunctionDecl
*
functionDecl
,
int
paramIndex
,
llvm
::
StringRef
paramName
,
const
std
::
string
&
callValue
)
{
{
if
(
functionDecl
->
getInstantiatedFromMemberFunction
())
if
(
functionDecl
->
getInstantiatedFromMemberFunction
())
functionDecl
=
functionDecl
->
getInstantiatedFromMemberFunction
();
functionDecl
=
functionDecl
->
getInstantiatedFromMemberFunction
();
...
@@ -133,7 +133,7 @@ MyCallSiteInfo ConstantParam::niceName(const FunctionDecl* functionDecl, int par
...
@@ -133,7 +133,7 @@ MyCallSiteInfo ConstantParam::niceName(const FunctionDecl* functionDecl, int par
if
(
isa
<
CXXMethodDecl
>
(
functionDecl
)
&&
dyn_cast
<
CXXMethodDecl
>
(
functionDecl
)
->
isConst
())
{
if
(
isa
<
CXXMethodDecl
>
(
functionDecl
)
&&
dyn_cast
<
CXXMethodDecl
>
(
functionDecl
)
->
isConst
())
{
aInfo
.
nameAndParams
+=
" const"
;
aInfo
.
nameAndParams
+=
" const"
;
}
}
aInfo
.
paramName
=
par
mVarDecl
->
getName
()
;
aInfo
.
paramName
=
par
amName
;
aInfo
.
paramIndex
=
paramIndex
;
aInfo
.
paramIndex
=
paramIndex
;
aInfo
.
callValue
=
callValue
;
aInfo
.
callValue
=
callValue
;
...
@@ -146,17 +146,24 @@ MyCallSiteInfo ConstantParam::niceName(const FunctionDecl* functionDecl, int par
...
@@ -146,17 +146,24 @@ MyCallSiteInfo ConstantParam::niceName(const FunctionDecl* functionDecl, int par
std
::
string
ConstantParam
::
getCallValue
(
const
Expr
*
arg
)
std
::
string
ConstantParam
::
getCallValue
(
const
Expr
*
arg
)
{
{
arg
=
arg
->
IgnoreParenCasts
();
if
(
isa
<
CXXDefaultArgExpr
>
(
arg
))
{
arg
=
dyn_cast
<
CXXDefaultArgExpr
>
(
arg
)
->
getExpr
();
}
arg
=
arg
->
IgnoreParenCasts
();
arg
=
arg
->
IgnoreParenCasts
();
// ignore this, it seems to trigger an infinite recursion
// ignore this, it seems to trigger an infinite recursion
if
(
isa
<
UnaryExprOrTypeTraitExpr
>
(
arg
))
{
if
(
isa
<
UnaryExprOrTypeTraitExpr
>
(
arg
))
{
return
"unknown"
;
return
"unknown
1
"
;
}
}
APSInt
x1
;
APSInt
x1
;
if
(
arg
->
EvaluateAsInt
(
x1
,
compiler
.
getASTContext
()))
if
(
arg
->
EvaluateAsInt
(
x1
,
compiler
.
getASTContext
()))
{
{
return
x1
.
toString
(
10
);
return
x1
.
toString
(
10
);
}
}
return
"unknown"
;
if
(
isa
<
CXXNullPtrLiteralExpr
>
(
arg
))
{
return
"0"
;
}
return
"unknown2"
;
}
}
bool
ConstantParam
::
VisitCallExpr
(
const
CallExpr
*
callExpr
)
{
bool
ConstantParam
::
VisitCallExpr
(
const
CallExpr
*
callExpr
)
{
...
@@ -193,22 +200,30 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) {
...
@@ -193,22 +200,30 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) {
functionDecl
=
functionDecl
->
getTemplateInstantiationPattern
();
functionDecl
=
functionDecl
->
getTemplateInstantiationPattern
();
#endif
#endif
if
(
!
functionDecl
->
getNameInfo
().
getLoc
().
isValid
()
||
ignoreLocation
(
functionDecl
))
{
return
true
;
}
// ignore stuff that forms part of the stable URE interface
// ignore stuff that forms part of the stable URE interface
if
(
isInUnoIncludeFile
(
compiler
.
getSourceManager
().
getSpellingLoc
(
if
(
isInUnoIncludeFile
(
compiler
.
getSourceManager
().
getSpellingLoc
(
functionDecl
->
getNameInfo
().
getLoc
())))
{
functionDecl
->
getNameInfo
().
getLoc
())))
{
return
true
;
return
true
;
}
}
if
(
functionDecl
->
getNameInfo
().
getLoc
().
isValid
()
&&
ignoreLocation
(
functionDecl
))
{
return
true
;
}
for
(
unsigned
i
=
0
;
i
<
callExpr
->
getNumArgs
();
++
i
)
{
unsigned
len
=
std
::
max
(
callExpr
->
getNumArgs
(),
functionDecl
->
getNumParams
());
if
(
i
>=
functionDecl
->
getNumParams
())
// can happen in template code
for
(
unsigned
i
=
0
;
i
<
len
;
++
i
)
{
break
;
const
Expr
*
valExpr
;
const
Expr
*
arg
=
callExpr
->
getArg
(
i
);
if
(
i
<
callExpr
->
getNumArgs
())
std
::
string
callValue
=
getCallValue
(
arg
);
valExpr
=
callExpr
->
getArg
(
i
);
const
ParmVarDecl
*
parmVarDecl
=
functionDecl
->
getParamDecl
(
i
);
else
if
(
i
<
functionDecl
->
getNumParams
()
&&
functionDecl
->
getParamDecl
(
i
)
->
hasDefaultArg
())
MyCallSiteInfo
funcInfo
=
niceName
(
functionDecl
,
i
,
parmVarDecl
,
callValue
);
valExpr
=
functionDecl
->
getParamDecl
(
i
)
->
getDefaultArg
();
else
// can happen in template code
continue
;
std
::
string
callValue
=
getCallValue
(
valExpr
);
std
::
string
paramName
=
i
<
functionDecl
->
getNumParams
()
?
functionDecl
->
getParamDecl
(
i
)
->
getName
()
:
llvm
::
StringRef
(
"###"
+
std
::
to_string
(
i
));
MyCallSiteInfo
funcInfo
=
niceName
(
functionDecl
,
i
,
paramName
,
callValue
);
callSet
.
insert
(
funcInfo
);
callSet
.
insert
(
funcInfo
);
}
}
return
true
;
return
true
;
...
@@ -224,7 +239,7 @@ bool ConstantParam::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
...
@@ -224,7 +239,7 @@ bool ConstantParam::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
const
FunctionDecl
*
functionDecl
=
dyn_cast
<
FunctionDecl
>
(
decl
);
const
FunctionDecl
*
functionDecl
=
dyn_cast
<
FunctionDecl
>
(
decl
);
for
(
unsigned
i
=
0
;
i
<
functionDecl
->
getNumParams
();
++
i
)
for
(
unsigned
i
=
0
;
i
<
functionDecl
->
getNumParams
();
++
i
)
{
{
MyCallSiteInfo
funcInfo
=
niceName
(
functionDecl
,
i
,
functionDecl
->
getParamDecl
(
i
)
,
"unknown
"
);
MyCallSiteInfo
funcInfo
=
niceName
(
functionDecl
,
i
,
functionDecl
->
getParamDecl
(
i
)
->
getName
(),
"unknown3
"
);
callSet
.
insert
(
funcInfo
);
callSet
.
insert
(
funcInfo
);
}
}
return
true
;
return
true
;
...
@@ -240,18 +255,25 @@ bool ConstantParam::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr
...
@@ -240,18 +255,25 @@ bool ConstantParam::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr
constructorDecl
->
getNameInfo
().
getLoc
())))
{
constructorDecl
->
getNameInfo
().
getLoc
())))
{
return
true
;
return
true
;
}
}
if
(
constructorDecl
->
getNameInfo
().
getLoc
().
isValid
()
&&
ignoreLocation
(
constructorDecl
))
{
if
(
!
constructorDecl
->
getNameInfo
().
getLoc
().
isValid
()
||
ignoreLocation
(
constructorDecl
))
{
return
true
;
return
true
;
}
}
for
(
unsigned
i
=
0
;
i
<
constructExpr
->
getNumArgs
();
++
i
)
unsigned
len
=
std
::
max
(
constructExpr
->
getNumArgs
(),
constructorDecl
->
getNumParams
());
{
for
(
unsigned
i
=
0
;
i
<
len
;
++
i
)
{
if
(
i
>=
constructorDecl
->
getNumParams
())
// can happen in template code
const
Expr
*
valExpr
;
break
;
if
(
i
<
constructExpr
->
getNumArgs
())
const
Expr
*
arg
=
constructExpr
->
getArg
(
i
);
valExpr
=
constructExpr
->
getArg
(
i
);
std
::
string
callValue
=
getCallValue
(
arg
);
else
if
(
i
<
constructorDecl
->
getNumParams
()
&&
constructorDecl
->
getParamDecl
(
i
)
->
hasDefaultArg
())
const
ParmVarDecl
*
parmVarDecl
=
constructorDecl
->
getParamDecl
(
i
);
valExpr
=
constructorDecl
->
getParamDecl
(
i
)
->
getDefaultArg
();
MyCallSiteInfo
funcInfo
=
niceName
(
constructorDecl
,
i
,
parmVarDecl
,
callValue
);
else
// can happen in template code
continue
;
std
::
string
callValue
=
getCallValue
(
valExpr
);
std
::
string
paramName
=
i
<
constructorDecl
->
getNumParams
()
?
constructorDecl
->
getParamDecl
(
i
)
->
getName
()
:
llvm
::
StringRef
(
"###"
+
std
::
to_string
(
i
));
MyCallSiteInfo
funcInfo
=
niceName
(
constructorDecl
,
i
,
paramName
,
callValue
);
callSet
.
insert
(
funcInfo
);
callSet
.
insert
(
funcInfo
);
}
}
return
true
;
return
true
;
...
...
compilerplugins/clang/constantparam.py
Dosyayı görüntüle @
d2143eac
...
@@ -37,16 +37,14 @@ for callInfo, callValues in callParamSet.iteritems():
...
@@ -37,16 +37,14 @@ for callInfo, callValues in callParamSet.iteritems():
nameAndParams
=
callInfo
[
1
]
nameAndParams
=
callInfo
[
1
]
if
len
(
callValues
)
!=
1
:
if
len
(
callValues
)
!=
1
:
continue
continue
if
"unknown"
in
callValues
:
callValue
=
next
(
iter
(
callValues
))
if
"unknown"
in
callValue
:
continue
continue
# ignore anything with only one parameter, normally just setter methods
# try and ignore setter methods
if
nameAndParams
.
find
(
","
)
==
-
1
:
if
(
","
not
in
nameAndParams
)
and
((
"::set"
in
nameAndParams
)
or
(
"::Set"
in
nameAndParams
)):
continue
# if it contains anything other than this set, ignore it
if
len
(
callValues
-
set
([
"0"
,
"1"
,
"-1"
,
"nullptr"
]))
>
0
:
continue
continue
v0
=
callInfo
[
0
]
+
" "
+
callInfo
[
1
]
v0
=
callInfo
[
0
]
+
" "
+
callInfo
[
1
]
v1
=
callInfo
[
2
]
+
" "
+
(
","
.
join
(
callValues
))
v1
=
callInfo
[
2
]
+
" "
+
callValue
v2
=
definitionToSourceLocationMap
[
callInfo
]
v2
=
definitionToSourceLocationMap
[
callInfo
]
tmp1list
.
append
((
v0
,
v1
,
v2
))
tmp1list
.
append
((
v0
,
v1
,
v2
))
...
...
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