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
78bd5d5f
Kaydet (Commit)
78bd5d5f
authored
Şub 12, 2018
tarafından
Noel Grandin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
loplugin:changerectanglegetref also fix Point and Size
Change-Id: I373af0a62e3785c4abc2d27b0b31121c9d596ca3
üst
fc809193
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
18 deletions
+55
-18
changerectanglegetref.cxx
compilerplugins/clang/changerectanglegetref.cxx
+55
-18
No files found.
compilerplugins/clang/changerectanglegetref.cxx
Dosyayı görüntüle @
78bd5d5f
...
...
@@ -36,11 +36,12 @@ public:
bool
VisitCXXMemberCallExpr
(
CXXMemberCallExpr
const
*
call
);
private
:
bool
ChangeAssignment
(
Stmt
const
*
parent
,
std
::
string
const
&
methodName
);
bool
ChangeAssignment
(
Stmt
const
*
parent
,
std
::
string
const
&
methodName
,
std
::
string
const
&
setPrefix
);
bool
ChangeBinaryOperator
(
BinaryOperator
const
*
parent
,
CXXMemberCallExpr
const
*
call
,
std
::
string
const
&
methodName
);
std
::
string
const
&
methodName
,
std
::
string
const
&
setPrefix
);
bool
ChangeUnaryOperator
(
UnaryOperator
const
*
parent
,
CXXMemberCallExpr
const
*
call
,
std
::
string
const
&
methodName
);
std
::
string
const
&
methodName
,
std
::
string
const
&
setPrefix
);
std
::
string
extractCode
(
SourceLocation
startLoc
,
SourceLocation
endLoc
);
};
...
...
@@ -60,14 +61,47 @@ bool ChangeRectangleGetRef::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call
return
true
;
auto
dc
=
loplugin
::
DeclCheck
(
func
);
std
::
string
methodName
;
std
::
string
setPrefix
;
if
(
dc
.
Function
(
"Top"
).
Class
(
"Rectangle"
).
Namespace
(
"tools"
).
GlobalNamespace
())
{
methodName
=
"Top"
;
setPrefix
=
"Set"
;
}
else
if
(
dc
.
Function
(
"Bottom"
).
Class
(
"Rectangle"
).
Namespace
(
"tools"
).
GlobalNamespace
())
{
methodName
=
"Bottom"
;
setPrefix
=
"Set"
;
}
else
if
(
dc
.
Function
(
"Left"
).
Class
(
"Rectangle"
).
Namespace
(
"tools"
).
GlobalNamespace
())
{
methodName
=
"Left"
;
setPrefix
=
"Set"
;
}
else
if
(
dc
.
Function
(
"Right"
).
Class
(
"Rectangle"
).
Namespace
(
"tools"
).
GlobalNamespace
())
{
methodName
=
"Right"
;
setPrefix
=
"Set"
;
}
else
if
(
dc
.
Function
(
"X"
).
Class
(
"Point"
).
GlobalNamespace
())
{
methodName
=
"X"
;
setPrefix
=
"set"
;
}
else
if
(
dc
.
Function
(
"Y"
).
Class
(
"Point"
).
GlobalNamespace
())
{
methodName
=
"Y"
;
setPrefix
=
"set"
;
}
else
if
(
dc
.
Function
(
"Width"
).
Class
(
"Size"
).
GlobalNamespace
())
{
methodName
=
"Width"
;
setPrefix
=
"set"
;
}
else
if
(
dc
.
Function
(
"Height"
).
Class
(
"Size"
).
GlobalNamespace
())
{
methodName
=
"Height"
;
setPrefix
=
"set"
;
}
else
return
true
;
if
(
!
loplugin
::
TypeCheck
(
func
->
getReturnType
()).
LvalueReference
())
...
...
@@ -78,7 +112,7 @@ bool ChangeRectangleGetRef::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call
return
true
;
if
(
auto
unaryOp
=
dyn_cast
<
UnaryOperator
>
(
parent
))
{
if
(
!
ChangeUnaryOperator
(
unaryOp
,
call
,
methodName
))
if
(
!
ChangeUnaryOperator
(
unaryOp
,
call
,
methodName
,
setPrefix
))
report
(
DiagnosticsEngine
::
Warning
,
"Could not fix this one1"
,
call
->
getLocStart
());
return
true
;
}
...
...
@@ -92,21 +126,22 @@ bool ChangeRectangleGetRef::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call
auto
opcode
=
binaryOp
->
getOpcode
();
if
(
opcode
==
BO_Assign
)
{
if
(
!
ChangeAssignment
(
parent
,
methodName
))
if
(
!
ChangeAssignment
(
parent
,
methodName
,
setPrefix
))
report
(
DiagnosticsEngine
::
Warning
,
"Could not fix this one4"
,
call
->
getLocStart
());
return
true
;
}
if
(
opcode
==
BO_RemAssign
||
opcode
==
BO_AddAssign
||
opcode
==
BO_SubAssign
||
opcode
==
BO_MulAssign
||
opcode
==
BO_DivAssign
)
{
if
(
!
ChangeBinaryOperator
(
binaryOp
,
call
,
methodName
))
if
(
!
ChangeBinaryOperator
(
binaryOp
,
call
,
methodName
,
setPrefix
))
report
(
DiagnosticsEngine
::
Warning
,
"Could not fix this one5"
,
call
->
getLocStart
());
return
true
;
}
return
true
;
}
bool
ChangeRectangleGetRef
::
ChangeAssignment
(
Stmt
const
*
parent
,
std
::
string
const
&
methodName
)
bool
ChangeRectangleGetRef
::
ChangeAssignment
(
Stmt
const
*
parent
,
std
::
string
const
&
methodName
,
std
::
string
const
&
setPrefix
)
{
// Look for expressions like
// aRect.Left() = ...;
...
...
@@ -124,7 +159,7 @@ bool ChangeRectangleGetRef::ChangeAssignment(Stmt const* parent, std::string con
auto
originalLength
=
callText
.
size
();
auto
newText
=
std
::
regex_replace
(
callText
,
std
::
regex
(
methodName
+
"
\\
(
\\
) *="
),
"Set"
+
methodName
+
"("
);
setPrefix
+
methodName
+
"("
);
if
(
newText
==
callText
)
return
false
;
newText
+=
" )"
;
...
...
@@ -134,7 +169,8 @@ bool ChangeRectangleGetRef::ChangeAssignment(Stmt const* parent, std::string con
bool
ChangeRectangleGetRef
::
ChangeBinaryOperator
(
BinaryOperator
const
*
binaryOp
,
CXXMemberCallExpr
const
*
call
,
std
::
string
const
&
methodName
)
std
::
string
const
&
methodName
,
std
::
string
const
&
setPrefix
)
{
// Look for expressions like
// aRect.Left() += ...;
...
...
@@ -182,14 +218,14 @@ bool ChangeRectangleGetRef::ChangeBinaryOperator(BinaryOperator const* binaryOp,
auto
implicitObjectText
=
extractCode
(
call
->
getImplicitObjectArgument
()
->
getExprLoc
(),
call
->
getImplicitObjectArgument
()
->
getExprLoc
());
auto
newText
=
std
::
regex_replace
(
callText
,
std
::
regex
(
methodName
+
"
\\
(
\\
) *"
+
regexOpname
),
"Set"
+
methodName
+
"( "
+
implicitObjectText
+
".Get
"
setPrefix
+
methodName
+
"( "
+
implicitObjectText
+
".
"
+
methodName
+
"() "
+
replaceOpname
+
" "
);
if
(
newText
==
callText
)
return
false
;
// sometimes we end up with duplicate spaces after the opname
newText
=
std
::
regex_replace
(
newText
,
std
::
regex
(
"Get"
+
methodName
+
"
\\
(
\\
)
\\
"
+
replaceOpname
+
" "
),
"Get"
+
methodName
+
"() "
+
replaceOpname
+
" "
);
newText
=
std
::
regex_replace
(
newText
,
std
::
regex
(
methodName
+
"
\\
(
\\
)
\\
"
+
replaceOpname
+
" "
),
methodName
+
"() "
+
replaceOpname
+
" "
);
newText
+=
" )"
;
return
replaceText
(
startLoc
,
originalLength
,
newText
);
...
...
@@ -197,7 +233,8 @@ bool ChangeRectangleGetRef::ChangeBinaryOperator(BinaryOperator const* binaryOp,
bool
ChangeRectangleGetRef
::
ChangeUnaryOperator
(
UnaryOperator
const
*
unaryOp
,
CXXMemberCallExpr
const
*
call
,
std
::
string
const
&
methodName
)
std
::
string
const
&
methodName
,
std
::
string
const
&
setPrefix
)
{
// Look for expressions like
// aRect.Left()++;
...
...
@@ -238,16 +275,16 @@ bool ChangeRectangleGetRef::ChangeUnaryOperator(UnaryOperator const* unaryOp,
{
auto
newText
=
std
::
regex_replace
(
callText
,
std
::
regex
(
methodName
+
"
\\
(
\\
) *"
+
regexOpname
),
"Set"
+
methodName
+
"( "
+
replaceOpname
+
implicitObjectText
+
".
Get
"
+
methodName
+
"()"
);
setPrefix
+
methodName
+
"( "
+
replaceOpname
+
implicitObjectText
+
"."
+
methodName
+
"()"
);
return
replaceText
(
startLoc
,
originalLength
,
newText
);
}
else
{
auto
newText
=
std
::
regex_replace
(
callText
,
std
::
regex
(
regexOpname
+
" *"
+
methodName
+
"
\\
(
\\
)"
),
"Set"
+
methodName
+
"( "
+
replaceOpname
+
implicitObjectText
+
".
Get
"
+
methodName
+
"()"
);
setPrefix
+
methodName
+
"( "
+
replaceOpname
+
implicitObjectText
+
"."
+
methodName
+
"()"
);
return
replaceText
(
startLoc
,
originalLength
,
newText
);
}
}
...
...
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