保守支援を目的とした コードクローン情報検索ツールの試作 泉田 聡介†, 植田 泰士†, 神谷 年洋‡, 楠本 真二†, 井上克郎† †大阪大学大学院情報科学研究科 ‡科学技術振興事業団 さきがけ研究21 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science.

Download Report

Transcript 保守支援を目的とした コードクローン情報検索ツールの試作 泉田 聡介†, 植田 泰士†, 神谷 年洋‡, 楠本 真二†, 井上克郎† †大阪大学大学院情報科学研究科 ‡科学技術振興事業団 さきがけ研究21 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science.

保守支援を目的とした
コードクローン情報検索ツールの試作
泉田 聡介†, 植田 泰士†, 神谷 年洋‡,
楠本 真二†, 井上克郎†
†大阪大学大学院情報科学研究科
‡科学技術振興事業団 さきがけ研究21
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
研究の背景(1/2)
コードクローン
ソースコード中に含まれる同一もしくは類似した
コードのこと, いわゆる“重複したコード”
クローン
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
2
研究の背景(2/2)
コードクローンはソフトウェア保守を困難にする
コードクローンにバグがあった場合、全てのコードクローンにつ
いて修正を考慮しなければならない
機能追加の場合も同様
コードクローン検出ツールCCFinder
ソースコードをトークン単位で直接比較することによりクローン
を検出
数百万行規模のシステムにも実用時間で解析可能
実用的に意味のないクローンを検出しない
様々な企業のソフトウェアにも適用している
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
3
コードクローン検出手順
(1)ソースコードを入力し,トークンの列にする
(2)変形ルールにより,トークン列を変形する
(3)パラメータ置換を行う
(4)マッチングアルゴリズムによりコードクローンを検出する
(5)コードクローンの位置(ファイル,行, カラム)を出力す
る
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
4
例題ソースコード
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
static void foo() throws RESyntaxException {
String a[] = new String [] { "123,400", "abc", "orange 100" };
org.apache.regexp.RE pat = new org.apache.regexp.RE("[0-9,]+");
int sum = 0;
for (int i = 0; i < a.length; ++i)
if (pat.match(a[i]))
sum += Sample.parseNumber(pat.getParen(0));
System.out.println("sum = " + sum);
}
static void goo(String [] a) throws RESyntaxException {
RE exp = new RE("[0-9,]+");
int sum = 0;
for (int i = 0; i < a.length; ++i)
if (exp.match(a[i]))
sum += parseNumber(exp.getParen(0));
System.out.println("sum = " + sum);
}
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
5
ステップ(1):ソースコードを入力し,トークンの列にする
1. static void foo (
2. String a
[
]
) throws RESyntaxException {
= new String [
]
{ "123,400" , "abc" , "orange 100" }
;
3. org . apache . regexp . RE pat = new org . apache . regexp . RE ( "[0-9,]+" )
4. int sum =
0
5. for ( int i
6. if
;
;
=
0
;
( pat . match (
i
a
<
[
a
i
. length ; ++ i
]
)
)
)
7. sum += Sample . parseNumber ( pat . getParen (
8. System . out . println ( "sum = " + sum )
0
)
)
;
;
9. }
10. static void goo ( String a
[
]
11. RE exp = new RE ( "[0-9,]+" )
12. int sum =
0
13. for ( int i
14. if
) throws RESyntaxException {
;
;
=
0
;
i
<
a
. length ; ++ i
( exp . match (
a
[
i
]
)
15. sum += parseNumber ( exp . getParen (
)
)
0
16. System . out . println ( "sum = " + sum )
)
)
;
;
17. }
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
6
ステップ(2):変形ルールにより,トークン列を変形する
1. static void foo (
2. String a
[
]
) throws RESyntaxException {
= new String [
]
{ "123,400"
$u } ; , "abc" , "orange 100" }
;
3. RE
org pat. apache
= new RE
. regexp
( "[0-9,]+"
. RE )pat ; = new org . apache . regexp . RE ( "[0-9,]+" )
4. int sum =
0
5. for ( int i
6. if
;
;
=
0
;
( pat . match (
i
a
<
[
a
i
. length ; ++ i
]
)
)
)
7. sum += Sample . parseNumber ( pat . getParen (
8. System . out . println ( "sum = " + sum )
0
)
)
;
;
9. }
10. static void goo ( String a
[
]
11. RE exp = new RE ( "[0-9,]+" )
12. int sum =
0
13. for ( int i
14. if
) throws RESyntaxException {
;
;
=
0
;
i
<
a
. length ; ++ i
( exp . match (
a
[
i
]
)
)
)
15. sum += parseNumber
$p . parseNumber
( exp (. getParen
exp . getParen
( 0 )( )0 ;)
16. System . out . println ( "sum = " + sum )
)
;
;
17. }
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
7
ステップ(3):パラメータ置換を行う
throws$pRESyntaxException
{
1. static void
$p $pfoo ( ( ) ) throws
{
2. String
$p $p a [ [ ] ] = =newnew$pString
[ ] [ { ] $u{ }$u ; }
3. RE
$p pat
$p = new RE
$p ( "[0-9,]+"
$p ) ; )
;
;
4. int
$p sum
$p == $p0 ;;
5. for ( int
i = $p
0 ; $p
i < $p
a . length
; ++
$p $p
$p ; ++
$p i) )
6. if
( pat
$p . match
$p ( ($p a [ [$p i ] ] ) ) ) )
+= $p
Sample
7. sum
$p +=
. $p. parseNumber
( $p . $p ( ( pat$p . ) getParen
) ; (
. out
. println
8. System
$p . $p
. $p
( $p (+ "sum
$p =) " ;+ sum )
0
)
)
;
;
9. }
) throws
{
10. static void
$p $pgoo ( ( $pString
$p [a ][ )] throws
$p RESyntaxException
{
new $p
RE (( $p
"[0-9,]+"
11. RE
$p exp
$p == new
) ; )
;
12. int
$p sum
$p == $p0 ;;
13. for ( int
i = $p
0 ; $p
i < $p
a . length
; ++
$p $p
$p ; ++
$p i) )
14. if
( exp
match( $p
( a[ $p
[ i] ]) )) )
$p . . $p
15. sum
+= $p
$p . . $p
parseNumber
. getParen
$p +=
( $p . ($p exp( $p
) ) ;(
16. System
. out
. println
$p . $p
. $p
( $p (+ "sum
$p =) " ;+ sum )
0
)
)
;
;
17. }
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
8
static
$p
$p
(
)
throws
$p
{
$p
$p
[
]
"="
$p
$p
[
]
{
$u
}
;
$p
$p
"="
new
$p
(
$p
)
;
$p
$p
"="
$p
ステップ(4):
マッチングアル
ゴリズムにより,
コードクローン
を検出
static *
$p
* *
*
* *
* *
* *
*
*
* *
*
$p
* *
*
* *
* *
* *
*
*
* *
*
(
*
*
)
*
*
throws
*
$p
* *
*
* *
* *
* *
*
*
* *
*
{
*
*
$p
* *
*
* *
* *
* *
*
*
* *
*
$p
* *
*
* *
* *
* *
*
*
* *
*
[
*
*
]
*
*
"="
*
*
*
$p
* *
*
* *
* *
* *
*
*
* *
*
$p
* *
*
* *
* *
* *
*
*
* *
*
[
*
*
]
*
*
{
*
*
$u
*
}
*
;
*
*
$p
* *
*
* *
* *
* *
*
*
* *
*
$p
* *
*
* *
* *
* *
*
*
* *
*
"="
*
*
*
new
*
$p
* *
*
* *
* *
* *
*
*
* *
*
(
*
*
$p
* *
*
* *
* *
* *
*
*
* *
*
)
*
*
;
*
*
$p
* *
*
* *
* *
* *
*
*
* *
*
$p
* *
*
* *
* *
* *
*
*
* *
*
H15/09/11
FIT2003
"="
*
*
*
Software Engineering Laboratory,
Department
School *
of Information
Science and Technology,
Osaka
$p
* *of Computer Science,
*
*Graduate
*
*
* *
* University
*
* *
9*
ステップ(4):
マッチングアル
ゴリズムにより,
コードクローン
を検出
H15/09/11
Software Engineering
***
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * * * ** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
*** * **
**
** *** ** * *** * * * * *
* *** *
* * *** ***
* * *** *
*****
* **
**
** ** * ** * * ** * * * * * * * ** * *
* * ** * ** *
* * ** * *
*
*
* *
**
**
*
*
*
*
**
**
*
*
** **
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
**
****
** *
** * * ** *
** * * * * * * * * * *
* * * * * *
* * * * *
** **
****
** *
** * * ** *
** * * * * * * * * * *
* * * * * *
* * * * *
**
* *** ***
** * * ** *
** * * * * *
* * ***
* * * * * *
* * * * *
** ***
* *** ***
** * * ** *
** * * * * *
* * * **
* * * * * *
* * * * *
*
*
*
*
*
*
*
**
* ** ***
*** * * ****
** ** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** * **
*** * * *** *
*** * * * * *
* * * *
* * * * * *
* * * * *
**
* *** ***
** * * ** *
** * * * * *
* * ***
* * * * * *
* * * * *
** ** * * ** * ** *
** * * ** *
** * * * * *
* * * **
* * * * * *
* * * * *
*
*
*
*
*
*
*
*
**
*
*
**
*
**
**
*
*
*
*
**
**
*
*
*
*
**
**
**
*
**
**
** ** ** ** ** ** ** ** ** **
** ** ** ** **
**
** **
**
** ** ** ** ** ** ** ** ** **
** ** ** ** **
**
* **
** ***
**
*** *
* *
* **
****
*
***** ** ** ** **
** **
**
** ***
**
** * ** ** **
** *** **
** *** ** ** ** **
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** *** *
*** * **
**
** *** ** * *** * * * * *
* * * ** * **
* * * ** *
** ***
* **
**
** * ** ** * * ** * * * * * * * ** * *
* * ** * ** *
* * ** * *
*
**
**
*
*
**
**
*
*** * ***** ** ** *** * ** **
* ** * *** ** ** ** ** * * ** **
**
* **
**
* * * *
* * * * * * * * * * * * * ** **
* **
**
* * * *
* * * * * * * * * * * **
**
* ** ***
*** * * ****
**** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** ***
*** * * ****
**** * * * *
* * * *
* * * * * *
* * * * *
**
* **
**
* * * *
* * * * * * * * * * * * * ** **
* **
**
* * * *
* * * * * * ** * * * * *
*** * * *** *** ** ** * * ** *
*** * * *** * ** ** * ** * * * *
* * ** * *
*** * **
**
** *** ** * *** * * * * *
* * ** * ** *
* * ** * *
*** **
* **
**
** ** * ** * * ** * * * * * * * ** * *
* * ** * ** *
* * ** * *
**
* ** ***
*** * * ****
**** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** ***
*** * * *** *
*** * * * * *
* * * *
* * * * * *
* * * * *
**
* **
**
** * * *** ** ** *** * ** *
* * * *
* * * * * * * * * * * * * ** **
* **
**
** * * *** * * ** * ** * * * *
* * * *
* * * * * * ** * * * * *
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
**
* **
**
** * * ** *
** * *** * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * *** * *
* * * *
* * * * * *
* * * * *
** *
** * *
** * ** *
** ** * *
** *
** * *
* * ** * *
* ** * * *
**
* **
**
**
*
*
**
*
**
*
*
*
*
*
*
*
**
**
*
**
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * **
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * * *
* * * *
* * * * * *
* * * * *
* *
*
**
**
**
*
* *
*
**
**
**
*
*
*
*
*
** *** *
** * ** *
*** * **
**
** *** ** * *** * * * * *
* * *** ***
* * *** *
*****
* **
**
** * ** ** * *** * * * * *
* * * ** * **
* * ** * *
**
* **
**
** * * ** *
** * * *** *
*** * *
* ** * ** * *
** ** * * *
** **
* **
**
** * * ** *
** * * ** * *
** * * *
* ** * ** * *
** ** * * *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * ** *
*
*
*
*
*
*
*
**
* ** * ** *
** * * ** *
** * * * * *
* * * ** * * * * * *
* * * * *
** ** * * ** * ** *
** * * ** *
** * * * * *
* * * ** * * * * * *
* * * * *
*
*
**
**
**
**
**
**
**
**
**
**
*
*
**
**
**
**
**
* **
**
** * * ** *
** * * * * *
* * * *
*** * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
** * * * * *
* * * * *
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
**
* **
**
** * * ** *
** * * *** *
* ** * *
* * ** * ** *
* ** ** * *
** **
* **
**
** * * ** *
** * * ** * *
** * * *
* ** * ** * *
** ** * * *
** *** *
** *** *
*** * **
**
** *** ** * *** * * * * *
* * *** ***
* * *** *
*****
* **
**
** *** ** * *** * * * * *
* * *** ***
* * *** *
*
*
*
*
*
*
*
*
*
*
*** * **
**
** *** ** * *** * * * * *
* * * ** * **
* * * ** *
** ***
* **
**
** * ** ** * *** * * * * *
* * * ** * **
* ** ** ** *
** *** *
** * ** *
** * * **
**
** * ** ** *
** * * * * **
* * * * *** * * * * *** * * * * **
** ** * * **
**
** * ** ** *
** * * * * **
* * * * ** * * * * * *** * * * * **
*
*
*
**
**
*
*
*
*
**
**
**
*
*
*
*
*
*
*
*
*
*
*
*
*
* ** * * ** *
** * * * * * ** **
* ** * * ** *
** * * * * *
**
* **
**
** * * * ** *
* ** * *
* * ** * ** *
* **
**
** * * * ** *
* ** * *
* * ** * ** *
* *
* *
**
* **
**
** * * ** *
** * * *** *
*** * *
* *** *** *
***** * *
** **
* **
**
** * * ** *
** * * ** * *
** * * *
* ** * ** * *
** ** * * *
*** * **
**
** *** ** * *** * * * * *
* * *
* * * ** * **
* * * ** *
** ***
* **
**
** * ** ** * *** * * * * *
* * * *
* * * ** * **
* * * ** *
**
**
* **
**
** * * ** *
** * * * * *
* *** *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * * * * ** * *
* * * * * *
* * * * *
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * ***
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * ***
*
**
**
***
**
*
**
**
** *
**
*
*
*
* *
*
*
*
* *
*
*
**
*
*
*
***
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
*** * **
**
** *** ** * *** * * * * *
* * *** ***
* * *** *
*****
* **
**
** *** ** * *** * * * * *
* * *** ** *
* * ** * *
** *** *
** *** *
**
*
**
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
**
*
**
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
**
**
* *
**
**
**
* *
*
*
*
**
**
*
*
*
*
**
**
*
** **
** ** **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
***
*
* * * * *
* **
*
* * * * *
**
*
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
**
*
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
**
**
* *
**
** **
* *
**
* ** ***
*** * * ****
**** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** ***
** * * * ** **
** ** * * * *
* * * *
* * * * * *
* * * * *
**
* *** ***
** * * ** *
** * * * * *
* * * **
* * * * * *
* * * * *
** ** * * ** * ** *
** * * ** *
** * * * * *
* * * **
* * * * * *
* * * * *
*
*
*
*
*
*
*
*
**
*
*
**
*
**
*
*
**
*
*
**
* **
**
** * * *** ** ** *** * ** *
* * * *
* * * * * * * * * * * * * ** **
* **
**
** * * *** * * ** * ** * * * *
* * * *
* * * * * * ** * * * * *
**
* ** ***
*** * * ****
**** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** ***
** * * * ** **
** ** * * * *
* * * *
* * * * * *
* * * * *
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
**** * **
**
** **** ** * *** * * * * ** ** * ** * *** * * ** * **** * * * ** **
** *** * * **
**
** ** ** ** * * ** * * * * ** * * ** * * ** * * ** * ** * ** * * ** * * *
*
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * * *
**
* ** ***
*** * * ****
**** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** ***
*** * * *** *
*** * * * * *
* * * *
* * * * * *
* * * * *
**
* **
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
**
*
**
**
**
*
*
**
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
**
*
*
* * * * * *
** *** *
*** * **
**
** *** ** * *** * * * * *
* * * ** * **
* * * ** *
** ***
* **
**
** * ** ** * *** * * * * * * * ** * *
* * ** * ** *
* * ** * *
**
* ** ***
** * * * ** **
** ** * * * *
* * * *
* * * * * *
* * * * *
** **
* ** ***
** * * * ** **
** ** * * * *
* * * *
* * * * * *
* * * * *
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
*** * * *** ** ** *** * ** *
*** * * *** ** ** *** * ** *
**
* **
**
* * * *
* * * * * * * * * * * * * ** **
* **
**
* * * *
* * * * * * ** * * * * *
**
* **
**
** * * ** *
** * * ** * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * ** * * *
* * * *
* * * * * *
* * * * *
** *
** * *
** *** *
**** * *
** *
** * *
**
* **
**
**
*
*
**
*
**
*
*
*
*
*
*
*
**
**
*
**
**
**
*
*
**
*
**
*
*
*
*
* *** *** * * ***** * * *
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * **
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * **
* * * *
* * * * * *
* * * * *
* *
*
**
**
**
*
* *
*
**
**
**
*
*
*
*
*
*** * **
**
** *** ** * * ** * * * * * * * ** * *
* * ** * ** *
* * ** * *
*** **
* **
**
** ** * ** * * ** * * * * * * * ** * *
* * ** * ** *
* * ** * *
**
* **
**
** * * ** *
** * * *** *
*** * *
* *** *** *
***** * *
** **
* **
**
** * * ** *
** * * * ** *
* ** * *
* * ** * ** *
** ** * * *
* * ** * *
*** * *** ***
** *** ** * *** * * * * *
* * ** * ** *
* * ** * *
*** ***
* *** ***
** ** * ** * * ** * * * * * * * ** * **
* * ** * ** *
* * ** * *
*
**
* ** * ** *
** * * ** *
** * * * * *
* * * ** * * * * * *
* * * * *
** ** * * ** * ** *
** * * ** *
** * * * * *
* * * ** * * * * * *
* * * * *
*
*
*
**
**
**
**
**
**
*
*
*
**
**
**
**
**
**
**
**
* **
**
** * * ** *
** * * * * *
* * * *
*** * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
*** * * * *
* * * * *
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
*
*
*
*
*
*
*
*
*
*
*
*
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * *
** * ** *
*** * **
**
** * ** ** * *** * * * * *
* * * ** * **
* * * ** *
*** **
* **
**
** ** * ** * * ** * * * * * * * ** * *
* * ** * ** *
* * ** * *
** * *
** *** *
**** * *
** *
** * *
** * ** *
*** * **
**
** *** ** * *** * * *** *
*
*
*
*
**
**
*
**
**
**
*
*
**
*
**
*
*
*
*
*
*
* ** ** ** *
*
*
*
*
*
*
*
*
*
*
*
*
** * * **
**
** * ** ** *
** * * * * **
* * * * *** * * * * *** * * * * **
** ** * * **
**
** * ** ** *
** * * * * **
* * * * ** * * * * * *** * * * * * *
*
**
**
** *
**
*
**
**
** *
**
*
*
* *
*
*
* *
**
*
*
**
*
*
**
* **
**
** * * ** *
** * * *** *
*** * *
* *** *** *
***** * *
** **
* **
**
** * * ** *
** * * *** *
*** * *
* *** *** *
***** * *
**
* **
**
** * * ** *
** * * *** *
*** * *
* *** *** *
** ** * * *
** **
* **
**
** * * ** *
** * * ** * *
* ** * *
* * ** * ** *
* ** ** * *
*** * **
**
** *** ** * *** * * * * *
* * *
* * * ** * **
* * * ** *
** ***
* **
**
** * ** ** * *** * * * * *
* * * *
* * * ** * **
* * * ** *
**
**
* **
**
** * * ** *
** * * * * *
* * ** *
* * * * * *
* * * * *
** **
* **
**
** * * ** *
** * * * * * * * ** * *
* * * * * *
* * * * *
**
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * ***
** **
* **
**
** * * ** *
** * * * * *
* * * *
* * * * * *
* * * * **
*
*
*
**
**
*
*
*
*
**
**
**
*
*
*
*
*
*
*
*
*
*
*
*
*
Laboratory, Department
of
Computer
Science,
Graduate
School
of
Information
Science
and
Technology,
Osaka
University
*
*
*
*
*
*
FIT2003
10
ステップ(5):コードクローンの位置を出力する
対象ファイルのID
(file 0 in group 0)
クローンの位置
file 0.0: 3~9行
file 0.0: 11~17行
がクローンである
#version: ccfinder 4.5h
#langspec: JAVA
#option: -b 30,1
#option: -k: #option: -r abcdfikmnprsv
#option: -c wfg
#begin{file description}
0.0 17 92
C:\test1.java
#end{file description}
#begin{syntax error}
#end{syntax error}
#begin{clone}
0.0 3,3,10 10,1,47 0.0
11,3,53 17,1,90 37
#end{clone}
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
11
クローン
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
static void foo() throws RESyntaxException {
String a[] = new String [] { "123,400", "abc", "orange 100" };
org.apache.regexp.RE pat = new org.apache.regexp.RE("[0-9,]+");
int sum = 0;
for (int i = 0; i < a.length; ++i)
if (pat.match(a[i]))
sum += Sample.parseNumber(pat.getParen(0));
System.out.println("sum = " + sum);
}
static void goo(String [] a) throws RESyntaxException {
RE exp = new RE("[0-9,]+");
int sum = 0;
for (int i = 0; i < a.length; ++i)
if (exp.match(a[i]))
sum += parseNumber(exp.getParen(0));
System.out.println("sum = " + sum);
}
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
12
CCFinderの出力
#version: ccfinder 4.5h
#langspec: JAVA
検出結果はクローンの位置情報のみであり、
#option: -b 30,1
#option: -k: その結果を直感的に理解することは困難
#option: -r abcdfikmnprsv
#option: -c wfg
#begin{file description}
ユーザの利用目的に応じた
0.0 17 92
C:\test1.java
#end{file description}
ユーザインタフェースが求められている
#begin{syntax error}
#end{syntax error}
#begin{clone}
0.0 3,3,10 10,1,47 0.0
11,3,53 17,1,90 37
#end{clone}
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
13
研究の目的
CCFinderを利用したコードクローン情報検索ツール
の試作
ユーザが入力したコード片に対して,そのコードクローンを
含むファイルを検索し、提示する
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
14
利用状況の想定
デバッグへの適用
修正箇所の特定
機能を追加
修正箇所に関するクローン
の検索
追加前のコード片のクローン
機能追加時の使用
を検索
発見したクローン全てに対し、
クローン全てについて機
修正コードを適用を検討
能追加の是非を検討
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
15
クローン情報検索ツール
入力: ユーザが指定するコード片
検索対象ファイル名のリスト
出力: ユーザが指定したコード片のクローンを含む
ファイルのリスト
特徴
簡単な操作
検索結果のソースコード上での確認
ハイライト表示等
Javaで実装.サイズは約3千行.
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
16
ツールのインターフェース
ファイルのリストを入力
検索したいコード片
を入力
解析対象言語の選択
解析開始ボタン
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
17
ツールの使用例
起動画面
検索項目
の入力
検索結果
ソースコード
の確認
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
18
ケーススタディ
擬似デバッグへの適用
SourceForge で開発されている日本語入力シ
ステム「かんな」の修正例へ適用
修正の対象となるコード片を検出できるか
実行にかかる時間はどれくらいか
適用環境
CPU Pentium4 2GHz、メインメモリ 512MB
OS WindowsXP HomeEdition SP1
Java VM JDK1.4付属のもの
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
19
「かんな」の修正例
「かんな」のver3.6とver3.6p1間の修正例
セキュリティー問題の修正において、バッファ処理の
前にオーバーフローを調べる処理を追加する.
ほぼ同じ修正を行っている部分が21ヵ所あった.
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
20
評価方法
以下の2つの方法の比較を行う.
grepを用いた検索
修正箇所で使用されている変数“Request.type”で検索
本ツールを用いた検索
入力コード片として,典型的なバッファ処理を行っている2行を与
えて検索
ir_debug(Dmsg(10,”ProcWideReq3 start\n”) );
buf += HEADER_SIZE; Request.type3.context = S2TOS(buf);
検索対象:かんなver3.6の全ソースコード
(約21,000行)
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
21
結果
grep
本ツール
検索結果
243行(58箇所)
17箇所
検索時間
約1秒
約8秒
本ツールでの検索では,実際の修正箇所21
箇所のうち4箇所が検出されず


2行が連続していなかった
検出された17箇所は正しい
grepでの検索結果のうち134行(20箇所)が
修正箇所に関連していた
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
22
f値を用いた比較
f値の定義
完全性 - 必要な情報のうち実際に検索された情報の割合
効率性 - 実際に検索された情報のうち必要な情報の割合
2  完全性  効率性
f値=
完全性  効率性
grep
本ツール
完全性
効率性
f値
95%
81%
34%
100%
0.50
0.90
本ツールでの検索の方が効率的である
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
23
まとめと今後の課題
ユーザが入力したコード片のクローンを検索するツー
ルの試作を行った
「かんな」の修正へ適用した
今後の課題
実際の保守作業への適用
出力する結果の表示方法の検討
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
24
H15/09/11
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
FIT2003
25