JP2014126985A - Source code equivalence verification device, and source code equivalence verification method - Google Patents
Source code equivalence verification device, and source code equivalence verification method Download PDFInfo
- Publication number
- JP2014126985A JP2014126985A JP2012282485A JP2012282485A JP2014126985A JP 2014126985 A JP2014126985 A JP 2014126985A JP 2012282485 A JP2012282485 A JP 2012282485A JP 2012282485 A JP2012282485 A JP 2012282485A JP 2014126985 A JP2014126985 A JP 2014126985A
- Authority
- JP
- Japan
- Prior art keywords
- source code
- change
- information
- refactoring
- normalization
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Abstract
Description
本発明は、ソースコード等価性検証装置、および、ソースコード等価性検証方法に係り、特に、ソフトウェアのリファクタリングにおいて、リファクタリング実施による不具合混入を防ぐために、記号実行の手法により、プログラムとしての振る舞いが等価であることを検証する場合に、計算量の爆発的増加を防止し、迅速にリファクタリングの正当性を検証するのに好適なソースコード等価性検証装置、および、ソースコード等価性検証方法に関する。 The present invention relates to a source code equivalence verification device and a source code equivalence verification method, and in particular, in software refactoring, the behavior as a program is equivalent by a symbol execution technique in order to prevent the introduction of defects due to refactoring. The present invention relates to a source code equivalence verification apparatus and a source code equivalence verification method suitable for preventing explosive increase in the amount of calculation and quickly verifying the validity of refactoring.
近年、情報処理社会が進展することにより、ソフトウェアシステムが一般社会に浸透し、ソフトウェアに求められる信頼性が非常に高度なものになってきている。一方で、ソフトウェアは、長年にわたる差分・派生開発によって複雑化および大規模化の一途をたどり、ソフトウェアの拡張しやすさや理解しやすさといった保守性の低下が問題となっている。 In recent years, with the development of an information processing society, software systems have penetrated the general society, and the reliability required for software has become extremely high. On the other hand, software is becoming increasingly complex and large-scale due to many years of differential / derivative development, and there is a problem of deterioration in maintainability such as ease of software expansion and ease of understanding.
リファクタリングは、非特許文献1に開示されている方法であって、ソフトウェアの振る舞いを変えずに、内部構造を変更することにより、ソフトウェアの設計品質を改善する手法の総称であり、複雑さを軽減し保守性を向上させるものである。
このリファクタリングの手法は、複雑化および大規模化の一途をたどるソフトウェアの保守性を確保するために有望な技術であるが、ソースコードを変更するため新たに不具合を混入してしまう可能性がある。具体的には、リファクタリングには、複数のパターンとして類別される方法が存在し、それぞれソースコードの変更の手順と、その変更によりソフトウェアの振る舞いを変えないことを保証するためのソースコードに対する条件とが、明示的もしくは暗黙的に定められている。この変更の手順に従わずに、ソースコードを変更した場合、または、そのような条件に従っていないソースコードを変更した場合には、対象となっているソフトウェアの振る舞いを変えないことが保証されないため、ソフトウェアに不具合が混入する可能性がある。したがって、ソフトウェア開発者が、ソフトウェアの保守段階において、リファクタリングが原因で正しく動作していたソフトウェアに不具合が混入することをおそれ、リファクタリングをおこなわない判断が有り得る。そのため、ソフトウェアの保守段階において、リファクタリングを積極的におこなうために、リファクタリングによる不具合の混入が無いことを検証する手法が求められる。
Refactoring is a method disclosed in Non-Patent
This refactoring technique is a promising technique for ensuring the maintainability of software that is becoming increasingly complex and large-scale. However, there is a possibility that new defects may be introduced because the source code is changed. . Specifically, there are methods that can be categorized as multiple patterns in refactoring. Each source code change procedure and the conditions for the source code to ensure that the behavior of the software is not changed by the change. Are explicitly or implicitly defined. If the source code is changed without following this change procedure, or if the source code does not comply with such conditions, it is not guaranteed that the behavior of the target software will not change. There may be a bug in the software. Therefore, there is a possibility that the software developer may not perform refactoring because there is a fear that a defect may be mixed in software that has been operating correctly due to the refactoring in the software maintenance stage. Therefore, in order to actively perform refactoring in the software maintenance stage, a method for verifying that there is no problem due to refactoring is required.
非特許文献4では、72種の典型的に用いられるリファクタリングのパターン(以下、単に「リファクタリングパターン」という)が定義されている。
In Non-Patent
本明細書中において、二つのソースコードが外的な振る舞いが同じであることを、すなわち、同じ入力に対して、実行時に、同じ出力が得られることを、各々のソースコードが「等価」であると定義し、リファクタリング実施前のソースコードとリファクタリング実施後のソースコードが、等価であることを検証することを「等価性検証」ということにする。 In this specification, it is stated that each source code is “equivalent” that the two source codes have the same external behavior, that is, the same output can be obtained at the same time for the same input. It is defined that the source code before the refactoring is performed and the source code after the refactoring is verified as “equivalence verification”.
等価性検証の手法として、特許文献1に開示されるソースコード比較によって差異が生じている部分のみテストを実施する手法、非特許文献2に開示されるソースコードをグラフで表現しリファクタリングごとに定めた事前条件をグラフが満たすかを検証する手法、非特許文献3に開示される記号実行を用いて振る舞いが保持されていることを検証する手法がある。
As an equivalence verification method, a method for performing a test only on a portion in which a difference is caused by the source code comparison disclosed in
特許文献1に開示される方法によると、リファクタリング前とリファクタリング後のソースコード上の差異を検出する。そして、検出した差異部分に関するテストを生成し、リファクタリング前と後のソースコードに対して生成したテストを実施し、それらの結果を検証する。これは、リファクタリング実施時に特別なプロセスを必要としない半面、いくつかの問題が存在する。リファクタリング箇所によっては影響が広範囲に波及し、生成したテストのみでは等価性を検証しきれない可能性が残る。また、影響の波及がなく差異部分のみの検証であっても、テストのカバレッジによって、検証漏れが生じる可能性が残る。テストによる等価性検証は、検証漏れなどの可能性のため不完全である。
According to the method disclosed in
非特許文献2では、プログラムのメソッド呼び出し関係をグラフで表現し、リファクタリングごとに定めた事前条件を満たすか否かを検証する手法を開示している。このアプローチは、振る舞いの検証を構造上の検証で実現するため、リファクタリングごとに、その操作を厳密に定義した上で、振る舞いに影響を及ぼさないための条件を網羅している。そのため、事実上、リファクタリングがツールにより自動化されることが必須であり、リファクタリング操作そのものを誤りうる、人手でのリファクタリングの検証には利用できないという問題点がある。 Non-Patent Document 2 discloses a method of expressing a method call relationship of a program in a graph and verifying whether or not a precondition defined for each refactoring is satisfied. In order to realize behavior verification by structural verification, this approach covers the conditions for not affecting the behavior after strictly defining the operation for each refactoring. For this reason, it is essential that the refactoring is automated by a tool, and there is a problem that the refactoring operation itself can be mistaken and cannot be used for verification of manual refactoring.
非特許文献3では、リファクタリング前後のソースコードに対して等価性検証をおこなう技術として、記号実行を用いる手法を開示している。
Non-Patent
記号実行とは、対象のプログラムの入力として、数値を与える代わりに、記号を与えることにより、プログラムの振る舞いを網羅的に解析する手法である。 Symbol execution is a technique for comprehensively analyzing the behavior of a program by giving a symbol instead of giving a numerical value as an input of a target program.
以下、図17を用いて記号実行の一例について説明する。
図17は、記号実行の一例を説明するために、ソースコードとそれより派生するデータ構造について示した図である。
Hereinafter, an example of symbol execution will be described with reference to FIG.
FIG. 17 is a diagram showing a source code and a data structure derived therefrom in order to explain an example of symbol execution.
記号実行においては、入力変数の値を記号変数と呼ばれる記号を用いて表現し、その記号変数がプログラム中でどのように参照・更新されていくかを解析する。ここでは、C言語で記述されたソースコードE001に記載する関数fooを対象に記号実行を実施するものとする。記号実行の対象となるソースコードE001に対して記号実行をおこなうにあたり、先ず、通常のソースコードをコンパイルするときと、同様に字句解析や構文解析を実施する。その結果から、ソースコードE001から制御フローや制御依存グラフ、データ依存グラフなどを抽出した構造グラフE002が得られる。記号実行では、構造グラフE002を用いて、実行木E020を生成していく。実行木E020中の各ノードは、そのノードに到達するための記号変数で表現されたパス制約と、そのノードにおける各変数の値を記号変数で表現した変数状態から構成される。図17の実行木E020では、各ノードの上側にパス制約を、下側に変数状態を表現している。 In symbol execution, the value of an input variable is expressed using a symbol called a symbol variable, and analysis is performed on how the symbol variable is referenced and updated in a program. Here, it is assumed that symbol execution is performed on the function foo described in the source code E001 described in the C language. When performing symbol execution on the source code E001 to be subjected to symbol execution, first, lexical analysis and syntax analysis are performed in the same manner as when compiling normal source code. As a result, a structure graph E002 obtained by extracting a control flow, a control dependency graph, a data dependency graph, and the like from the source code E001 is obtained. In symbol execution, an execution tree E020 is generated using the structure graph E002. Each node in the execution tree E020 is composed of a path constraint expressed by a symbol variable for reaching the node and a variable state in which the value of each variable at that node is expressed by a symbol variable. In the execution tree E020 of FIG. 17, a path constraint is expressed above each node and a variable state is expressed below.
実行木E020の生成過程について以下に詳細を説明する。 Details of the generation process of the execution tree E020 will be described below.
記号実行の開始段階において、ソースコードE001中で、プログラムの入力となる変数に対して記号変数を割当てる。ソースコードE001の例では、グローバル変数a,b,cが入力となる変数であるため、それぞれに対して、α,β,γという記号変数を割当てる。構造グラフE002上では、ノードE003に対応する開始状態においては、実行木E020は、ノードE010の単一のノードのみからなる実行木となる。ノードE010のパス制約E010aは、制約無し(任意の変数状態に対して制約を満たす)を意味するtrueとなり、変数状態E010bは記号変数の割当てに従って、各変数と対応する記号変数が等しいことを示している。 At the start stage of symbol execution, symbol variables are assigned to variables serving as program inputs in the source code E001. In the example of the source code E001, since the global variables a, b, and c are input variables, symbol variables α, β, and γ are assigned to each. On the structure graph E002, in the start state corresponding to the node E003, the execution tree E020 is an execution tree including only a single node of the node E010. The path constraint E010a of the node E010 is true indicating that there is no constraint (the constraint is satisfied for an arbitrary variable state), and the variable state E010b indicates that each variable and the corresponding symbol variable are equal according to the symbol variable assignment. ing.
構造グラフE002上では、ノードE003の次にはノードE004が実行される。それにともなって、実行木においてもE010の子ノードE011が生成される。子ノードE011におけるパス制約E011a、および、変数状態E011bは、親ノードE010のパス制約E010a、および、変数状態E010bがコピーされた上で、構造グラフE002上のノードE004が実行される。 On the structure graph E002, the node E004 is executed next to the node E003. Accordingly, a child node E011 of E010 is also generated in the execution tree. For the path constraint E011a and variable state E011b in the child node E011, the node E004 on the structure graph E002 is executed after the path constraint E010a and variable state E010b of the parent node E010 are copied.
ノードE004においては、変数aに対して0が代入されている。そのため、実行木のノードE011の変数状態E011bにおける、変数aに対する状態はa=0に更新される。 In the node E004, 0 is substituted for the variable a. Therefore, the state for the variable a in the variable state E011b of the node E011 of the execution tree is updated to a = 0.
構造グラフE002上で、ノードE004に次となるノードはE005である。ノードE005においては、変数状態の更新がおこなわれていないため、実行木における新たなノードを生成しない。ノードE005は、if文による条件分岐である。そのため、構造グラフE002の制御フローで次となるノードは、ノードE006とノードE007の二つのノードがある。記号実行においては、取り得る制御フローをすべて網羅するために、条件分岐においては、それぞれの分岐に応じた子ノードを生成する。すなわち、ノードE006に対応して実行木中のノードE011の子ノードとしてE012を生成し、ノードE007に対応して実行木中のノードE011の子ノードとしてE013を生成する。 On the structure graph E002, the node next to the node E004 is E005. In the node E005, since the variable state is not updated, a new node in the execution tree is not generated. Node E005 is a conditional branch by an if statement. Therefore, the next node in the control flow of the structure graph E002 includes two nodes, a node E006 and a node E007. In the symbol execution, in order to cover all possible control flows, in the conditional branch, a child node corresponding to each branch is generated. That is, E012 is generated as a child node of the node E011 in the execution tree corresponding to the node E006, and E013 is generated as a child node of the node E011 in the execution tree corresponding to the node E007.
実行木のノードE012のパス制約E012aは、親ノードのパス制約E011aと条件分岐の分岐条件との論理積(AND、図では、&)になる。ノードE005における分岐条件は、c<0であり、また、変数状態E011bから、変数cを記号変数で表わすとγとなることから、条件分岐が成立するための条件はγ<0であることが分かる。そこで、trueとγ<0との論理積であるγ<0がノードE012におけるパス制約E012aとなる。 The path constraint E012a of the node E012 of the execution tree is a logical product (AND, & in the figure) of the path constraint E011a of the parent node and the branch condition of the conditional branch. The branch condition at the node E005 is c <0, and since the variable c is expressed as a symbol variable from the variable state E011b, it becomes γ. Therefore, the condition for the conditional branch to be satisfied may be γ <0. I understand. Therefore, γ <0, which is the logical product of true and γ <0, becomes the path constraint E012a in the node E012.
次に、子ノードE013のパス制約E013aは、E013が条件分岐の分岐条件が成立しない場合に対応していることから、親ノードのパス制約E011aと条件分岐の分岐条件の否定(NOT、図では、!)との論理積になる。すなわち、trueと!(γ<0)との論理積である!(γ<0)が、子ノードE013のパス制約E013aとなる。 Next, since the path constraint E013a of the child node E013 corresponds to the case where E013 does not satisfy the branch condition of the conditional branch, the path constraint E011a of the parent node and the negation of the branch condition of the conditional branch (NOT, in the figure) ,!) That is, true! AND with (γ <0)! (Γ <0) is the path constraint E013a of the child node E013.
ノードE011の子ノードE012の変数状態E012b、子ノードE013の変数状態E013bは、親ノードE011の変数状態E011bがコピーされた上で、計算が続行される。ノードE012の変数状態E012bは、ノードE006で変数cに0が代入されるため、cに対する変数状態がc=0に更新される。ノードE013の変数状態E013bは、ノードE007で変数aに変数cの値が代入されている。この時点において、変数cの変数状態が記号変数のγとなっているので、変数状態E013bにおいて、変数aの変数状態がa=γに更新される。 The calculation of the variable state E012b of the child node E012 of the node E011 and the variable state E013b of the child node E013 is continued after the variable state E011b of the parent node E011 is copied. In the variable state E012b of the node E012, 0 is substituted for the variable c at the node E006, so the variable state for c is updated to c = 0. In the variable state E013b of the node E013, the value of the variable c is substituted for the variable a in the node E007. At this time, since the variable state of the variable c is the symbol variable γ, the variable state of the variable a is updated to a = γ in the variable state E013b.
以降も上記と同様の手順により実行木を生成していく。制御フロー上においてノードE006の次のノードはE008であり、このE008は条件分岐であるため、実行木においては、ノードE012に対して二つの子ノードE014およびE015が生成される。ノードE008における分岐条件は(b<0)であるが、これを変数状態を用いて記号変数で表現すると(β<0)になる。そのため、子ノードE014、および、E015のパス制約は、親ノードE012のパス制約E012aにそれぞれ(β<0)、および、!(β<0)との論理積をとったものとなる。子ノードE014では、次に制御フロー上のノードE009aが実行される。E009aは変数aにa−bの値を代入するものであり、変数状態から、変数aの状態が0、変数bの状態がβであると分かるので、変数aの状態が−βに更新される。子ノードE015では、次に制御フロー上のノードE009bが実行される。E009bは変数aにa+bの値を代入するものであり、変数状態から、変数aの状態が0、変数bの状態がβと分かるので、変数aの状態がβに更新される。 Thereafter, the execution tree is generated by the same procedure as described above. In the control flow, the node next to the node E006 is E008, and this E008 is a conditional branch. Therefore, in the execution tree, two child nodes E014 and E015 are generated for the node E012. The branch condition at the node E008 is (b <0), and this is expressed as a symbolic variable using a variable state (β <0). Therefore, the path constraints of the child nodes E014 and E015 are (β <0) and! Respectively for the path constraint E012a of the parent node E012. It is a logical product of (β <0). In the child node E014, the node E009a on the control flow is executed next. E009a assigns the value of ab to the variable a, and it can be seen from the variable state that the state of the variable a is 0 and the state of the variable b is β, so the state of the variable a is updated to -β. The In the child node E015, the node E009b on the control flow is executed next. E009b assigns the value of a + b to the variable a. Since the state of the variable a is 0 and the state of the variable b is β from the variable state, the state of the variable a is updated to β.
制御フロー上においてノードE007の次のノードはE008であり、このE008は条件分岐であるため、実行木においては、ノードE013に対して二つの子ノードE016およびE017が生成される。ノードE008における分岐条件は(b<0)であるが、これを変数状態を用いて記号変数で表現すると(β<0)になる。そのため、子ノードE016、および、E017のパス制約は、親ノードE013のパス制約E013aにそれぞれ(β<0)、および、!(β<0)との論理積をとったものとなる。子ノードE016では、次に制御フロー上のノードE009aが実行される。E009aは、変数aにa−bの値を代入するものであり、変数状態から、変数aの状態がγ、変数bの状態がβであると分かるので、変数aの状態がγ−βに更新される。子ノードE017では、次に制御フロー上のノードE009bが実行される。E009bは変数aにa+bの値を代入するものであり、変数状態から、変数aの状態がγ、変数bの状態がβと分かるので、変数aの状態がγ+βに更新される。 In the control flow, the node next to the node E007 is E008, and this E008 is a conditional branch. Therefore, in the execution tree, two child nodes E016 and E017 are generated for the node E013. The branch condition at the node E008 is (b <0), and this is expressed as a symbolic variable using a variable state (β <0). Therefore, the path constraints of the child nodes E016 and E017 are (β <0) and! Respectively for the path constraint E013a of the parent node E013. It is a logical product of (β <0). In the child node E016, the node E009a on the control flow is executed next. E009a substitutes the value of a−b for the variable a, and it can be seen from the variable state that the state of the variable a is γ and the state of the variable b is β, so the state of the variable a is γ−β. Updated. In the child node E017, the node E009b on the control flow is executed next. E009b assigns the value of a + b to the variable a. Since the state of the variable a is γ and the state of the variable b is β from the variable state, the state of the variable a is updated to γ + β.
実行木E020のすべての葉ノードに対して、その制御フローが関数の終了まで到達すると、実行木の生成が終了する。図17の実行木E020は、関数fooに対する記号実行が終了した時点での実行木を示している。記号実行が終了した時点での実行木の各葉ノードを集めたものが記号実行の結果となる(これを「記号実行サマリ」ということにする)。記号変数α,β,γの任意の組合せは、記号実行サマリ中の各葉ノードのうちいずれかのパス制約を満たす。そのノードに含まれる変数状態を用いることによって、入力となる記号変数の値から、プログラム実行後の各変数の値を知ることができる。例えば、関数fooの実行前の変数a,b,cのいずれの値も1である場合、記号変数はα=β=γ=1となり、ノードE017のパス制約を満たす。ノードE017の変数状態から関数foo実行後の変数aの値はa=γ+β=2、b=β=1、c=γ=1となることが分かる。上記のように、記号実行は、プログラムが取り得る制御パスを網羅した上で、プログラム実行前後の変数値の関係を入力値の条件(パス条件)と、出力変数の状態(変数状態)の組の集合である記号実行サマリを求める計算であるということができる。 When the control flow reaches the end of the function for all leaf nodes of the execution tree E020, execution tree generation ends. An execution tree E020 in FIG. 17 indicates an execution tree at the time when the symbol execution for the function foo is completed. The result of symbol execution is a collection of each leaf node of the execution tree at the time when symbol execution is completed (this is referred to as “symbol execution summary”). Any combination of the symbol variables α, β, γ satisfies any path constraint among the leaf nodes in the symbol execution summary. By using the variable state included in the node, the value of each variable after execution of the program can be known from the value of the symbol variable as an input. For example, if the values of variables a, b, and c before execution of function foo are 1, the symbol variable is α = β = γ = 1, which satisfies the path constraint of node E017. It can be seen from the variable state of the node E017 that the values of the variable a after execution of the function foo are a = γ + β = 2, b = β = 1, and c = γ = 1. As described above, symbol execution covers the control paths that a program can take, and the relationship between variable values before and after program execution is a set of input value conditions (path conditions) and output variable states (variable states). It can be said that this is a calculation for obtaining a symbol execution summary that is a set of.
リファクタリング前後のソースコードの構造グラフに対して、それぞれ記号実行し、論理的に等価な記号実行サマリが得られたとき、すなわち、同じ入力に対し同じ出力が得られる場合に、上で定義したように、ソースコードが等価であると判断できる。このように、記号実行は、対象のプログラムの取り得る動作系列を網羅的に解析するため、テストを用いた検証におけるカバレッジの問題や、事前条件の検証におけるツール依存の問題が生じない。その一方で、繰り返し文や再帰構造をもつプログラムでは、実行木が複雑なものになり、計算量が発散し爆発しやすい。計算量を抑えるためには、記号実行の範囲の限定や、事前条件による実行の制限が必要であり、記号実行の利点である検証の完全性が失われる。 Symbol definition is executed for each source graph before and after refactoring, and a logically equivalent symbol execution summary is obtained, that is, when the same output is obtained for the same input, as defined above. In addition, it can be determined that the source code is equivalent. As described above, since symbol execution comprehensively analyzes an action sequence that can be taken by a target program, there is no problem of coverage in verification using a test or tool dependency in verification of a precondition. On the other hand, in a program having a repetitive statement or a recursive structure, the execution tree becomes complicated, the amount of calculation is diverged, and it tends to explode. In order to reduce the amount of calculation, it is necessary to limit the range of symbol execution and to limit execution based on preconditions, and the integrity of verification, which is an advantage of symbol execution, is lost.
非特許文献3では、比較するソースコード間に共通部分が存在する点に着目し、完全性を維持したまま計算量を減らす工夫をしている。変更されていない共通のブロックの実行結果を関数(uninterpreted function)で表現することにより、実行木の上の計算量の発散を防ぐ。しかしながら、差異部分の実行木上の計算量が発散するケースが依然として残り、計算量が爆発する可能性が残る。また、ハードウェア等外界との相互作用を持つプログラムの扱いに対しては言及されていない。
In
本発明は、上記問題点を解決するためになされたもので、その目的は、人手で実施されたリファクタリングに対する等価性検証を、記号実行によりおこなうときに、計算量を爆発させずに、迅速におこなえるようなソースコード等価性検証方法を提供することにある。 The present invention has been made to solve the above-mentioned problems, and its purpose is to quickly perform the verification of equivalence for manually performed refactoring by symbol execution without exploding the amount of calculation. It is to provide a source code equivalence verification method that can be performed.
本発明のソースコード等価性検証装置は、CPUと記憶装置とを有し、記憶装置に記憶されたプログラムをCPUにより実行させることにより、ソースコードの変更の前後の等価性を検証するソースコード等価性検証装置であって、変更前のソースコードと、変更後のソースコードを入力するソースコード入力手段と、ソースコードの変更の変更種別パターン情報を入力する変更種別パターン入力手段と、変更前のソースコードと、変更後のソースコードの各々に対して、変更前ソースコード情報と、変更後ソースコード情報を生成するソースコード情報生成手段と、ソースコード変更種別パターンに対して、定義される正規化情報を参照し、変更前ソースコード情報と、変更後ソースコード情報を正規化し、各々変更前ソースコード正規化情報と、変更後ソースコード正規化情報を生成する正規化手段と、変更前ソースコード正規化情報と、変更後ソースコード正規化情報の構造を比較する構造比較手段と、変更前ソースコード正規化情報と、変更後ソースコード正規化情報を記号実行する記号実行手段と、記号実行手段により記号実行の結果を比較して、変更前ソースコードと変更後ソースコードの等価性を判定する等価性判定手段と、ソースコード情報を抽象化して縮減する抽象化手段とを有するものである。 The source code equivalence verification apparatus of the present invention has a CPU and a storage device, and causes the CPU to execute a program stored in the storage device, thereby verifying equivalence before and after the change of the source code. A source code input means for inputting the source code before the change, the source code after the change, a change type pattern input means for inputting the change type pattern information of the change of the source code, and the pre-change For each of the source code and the changed source code, the source code information before the change, the source code information generating means for generating the changed source code information, and the normal defined for the source code change type pattern Normalization source code information before change and source code information after change are normalized, each source code is normalized Information, normalization means for generating post-change source code normalization information, pre-change source code normalization information, structure comparison means for comparing the structure of post-change source code normalization information, and pre-change source code normalization Information and symbol execution means for symbol-execution of the modified source code normalization information and symbol execution means for comparing the result of symbol execution to determine equivalence between the source code before change and the source code after change And abstraction means for abstracting and reducing the source code information.
そして、構造比較手段により、変更前ソースコード正規化情報と、変更後ソースコード正規化情報の構造が比較され、構造が一致すると判定されたときに、記号実行手段は、変更前ソースコード正規化情報と、変更後ソースコード正規化情報に対して記号実行をおこなわないようにする。 Then, the structure comparison means compares the structure of the source code normalization information before the change with the structure of the source code normalization information after the change, and when it is determined that the structures match, the symbol execution means Do not perform symbol execution on the information and the changed source code normalization information.
一方、構造比較手段により、変更前ソースコード正規化情報と、変更後ソースコード正規化情報の構造が比較され、構造が不一致であると判定されたときに、抽象化手段が、変更前ソースコード正規化情報と、変更後ソースコード正規化情報の各々の抽象化をおこなって、変更前ソースコード抽象化情報と、変更後ソースコード抽象化情報を生成し、記号実行手段は、変更前ソースコード抽象化情報と、変更後ソースコード抽象化情報に対して、記号実行をするようにする。 On the other hand, when the structure comparison means compares the structure of the source code normalization information before the change with the structure of the source code normalization information after the change, and determines that the structures do not match, the abstraction means Normalization information and post-change source code normalization information are abstracted to generate pre-change source code abstraction information and post-change source code abstraction information. Symbol execution is performed on the abstraction information and the changed source code abstraction information.
本発明のソースコード等価性検証装置によれば、リファクタリングパターン情報に対応したソースコード情報正規化を、リファクタリング前ソースコード情報とリファクタリング後ソースコード情報に適用し、構造比較をおこない、構造の一致・不一致により、ソースコードの等価・非等価を判定する。そして、構造比較をおこない構造が一致すると判定されたときには、記号実行をおこなうまでもなく、ソースコードが等価であると判定されるので、計算量が多くなる記号実行の必要がなくなるというメリットがある。また、構造比較において、構造が不一致であると判定された場合は、ソースコード情報の抽象化をおこない、ソースコード情報を縮減して、抽象化をおこなったソースコード情報に対して、記号実行により等価性の検証をおこなうことが可能となる。そのため、本発明によれば、完全性を維持したまま計算量を爆発させずにソースコード等価性検証が可能となる。 According to the source code equivalence verification apparatus of the present invention, the source code information normalization corresponding to the refactoring pattern information is applied to the source code information before refactoring and the source code information after refactoring, the structure is compared, Judge whether source code is equivalent or not by mismatch. Then, when it is determined that the structures match by comparing the structure, it is determined that the source code is equivalent without performing the symbol execution, so that there is an advantage that it is not necessary to execute the symbol which increases the amount of calculation. . In addition, if it is determined in the structure comparison that the structures do not match, the source code information is abstracted, the source code information is reduced, and the abstracted source code information is subjected to symbol execution. It is possible to verify equivalence. Therefore, according to the present invention, it is possible to verify source code equivalence without exploding the amount of calculation while maintaining integrity.
本発明によれば、人手で実施されたリファクタリングに対する等価性検証を、記号実行によりおこなうときに、計算量を爆発させずに、迅速におこなえるようなソースコード等価性検証方法を提供することができる。 According to the present invention, it is possible to provide a source code equivalence verification method that can be performed quickly without exploding the amount of computation when equivalence verification for refactoring performed manually is performed by symbol execution. .
以下、本発明における一実施形態を、図1ないし図16を用いて説明する。 Hereinafter, an embodiment of the present invention will be described with reference to FIGS.
〔ソースコード等価性検証装置の構成と処理〕
以下、図1ないし図9を用いて本発明の一実施形態に係るソースコード等価性検証装置の構成と処理について説明する。
先ず、図1を用いて本発明の一実施形態に係るソースコード等価性検証装置のハードウェア構成について説明する。
図1は、本発明の一実施形態に係るソースコード等価性検証装置のハードウェア構成図である。
[Configuration and processing of source code equivalence verification device]
The configuration and processing of the source code equivalence verification apparatus according to an embodiment of the present invention will be described below with reference to FIGS.
First, the hardware configuration of the source code equivalence verification apparatus according to an embodiment of the present invention will be described with reference to FIG.
FIG. 1 is a hardware configuration diagram of a source code equivalence verification apparatus according to an embodiment of the present invention.
本発明の一実施形態に係るソースコード等価性検証装置のハードウェア構成としては、例えば、図1に示されるような一般的なパーソナルコンピュータで実現される。 The hardware configuration of the source code equivalence verification apparatus according to an embodiment of the present invention is realized by, for example, a general personal computer as shown in FIG.
ソースコード等価性検証装置1000は、CPU(Central Processing Unit)101、主記憶装置102、ネットワークI/F103、グラフィックI/F104、入出力I/F105、補助記憶装置I/F106が、バスにより結合された形態になっている。
The source code
CPU101は、ソースコード等価性検証装置100の各部を制御し、主記憶装置102にソースコード等価性検証プログラム200をロードして実行する。
The
主記憶装置102は、通常、RAMなどの揮発メモリで構成され、CPU101が実行するプログラム、参照するデータが記憶される。
The
ネットワークI/F103は、外部ネットワーク150と接続するためのインタフェースである。
The network I /
グラフィックI/F104は、LCD(Liquid Crystal Display)などの表示装置120を接続するためのインタフェースである。
The graphic I /
入出力I/F105は、入出力装置を接続するためのインタフェースである。図1の例では、キーボード131とポインティングデバイスのマウス132が接続されている。
The input / output I /
補助記憶装置I/F106は、HDD(Hard Disk Drive)141やDVDドライブ(Digital Versatile Disk)142などの補助記憶装置を接続するためのインタフェースである。
The auxiliary storage device I /
HDD141は、大容量の記憶容量を有しており、本実施形態を実行するためのソースコード等価性検証プログラム200が格納されている。
The
DVDドライブ142は、DVDやCDなどの光学ディスクにデータを書き込んだり、光学ディスクからデータを読み込んだりする装置であり、ソースコード等価性検証プログラム200は、例えば、CD−ROMにより提供されたものをインストールすることができる。
The
本実施形態のソースコード等価性検証装置1000は、上記のようなパーソナルコンピュータに、ソースコード等価性検証プログラム200をインストールして、各機能を実行するものである。
The source code
次に、図2を用いて本発明の一実施形態に係るソースコード等価性検証装置のソフトウェア構成について説明する。
図2は、本発明の一実施形態に係るソースコード等価性検証装置のソフトウェア構成図である。
Next, the software configuration of the source code equivalence verification apparatus according to an embodiment of the present invention will be described with reference to FIG.
FIG. 2 is a software configuration diagram of the source code equivalence verification apparatus according to the embodiment of the present invention.
ソースコード等価性検証装置のソフトウェア構成は、図2に示したように、プログラム等価性検証プログラム200よりなり、プログラム等価性検証プログラム200は、サブルーチンであるソースコード解析モジュール201、構造グラフ生成・更新モジュール202、構造グラフ解析モジュール203、実行木生成モジュール204、記号実行実行モジュール205、入出力モジュール206、データベースモジュール207からなる。
As shown in FIG. 2, the software configuration of the source code equivalence verification apparatus includes a program
なお、プログラム等価性検証プログラム200は、OS(Operating System)上で動作するアプリケシーンソフトウェアであり、ソースコード等価性検証装置のソフトウェア構成として、OSやライブラリプログラムも含むが図では、省略している。
Note that the program
プログラム等価性検証プログラム200は、サブルーチンであるソースコード解析モジュール201、構造グラフ生成・更新モジュール202、構造グラフ解析モジュール203、実行木生成モジュール204、記号実行実行モジュール205、入出力モジュール206、データベースモジュール207からなる。
The program
ソースコード解析モジュール201は、ソースコードの字句解析・構文解析をおこない、構造グラフ生成のために必要な情報を取り出すモジュールである。 The source code analysis module 201 is a module that performs lexical analysis / syntactic analysis of the source code and extracts information necessary for generating the structure graph.
構造グラフ生成・更新モジュール202は、ソースコード解析モジュール201の解析結果に基づいて、構造グラフを生成したり、更新したりするモジュールである。 The structure graph generation / update module 202 is a module that generates or updates a structure graph based on the analysis result of the source code analysis module 201.
構造グラフ解析モジュール203は、構造グラフのグラフ構造を解析するモジュールである。
The structure
実行木生成モジュール204は、構造グラフ解析モジュール203の解析結果に基づき、実行木を生成するモジュールである。
The execution
記号実行実行モジュール205は、実行木生成モジュール204が生成した実行木に対する記号実行をおこなうモジュールである。
The symbol
入出力モジュール206は、外部から必要なデータの入出力をおこなうモジュールである。
The input /
データベースモジュール207は、各種データベースにアクセスするためのモジュールである。
The
次に、図3ないし図9を用いて本発明の一実施形態に係るソースコード等価性検証装置の機能と、その処理について説明する。
図3は、本発明の一実施形態に係るソースコード等価性検証装置全体の機能と、データフローを示した図である。
図4は、本発明の一実施形態に係るソースコード等価性検証装置の処理を示すフローチャートである。
図5は、入力部1100の機能の詳細とデータフローを示した図である。
図6は、正規化部1200の機能の詳細とデータフローを示した図である。
図7は、構造比較検証処理部1300の機能の詳細とデータフローを示した図である。
図8は、記号実行実施判定部1700の機能の詳細とデータフローを示した図である。
図9は、記号実行検証処理部1400の機能の詳細とデータフローを示した図である。
Next, functions and processing of the source code equivalence verification apparatus according to an embodiment of the present invention will be described with reference to FIGS.
FIG. 3 is a diagram showing the functions and data flow of the entire source code equivalence verification apparatus according to an embodiment of the present invention.
FIG. 4 is a flowchart showing processing of the source code equivalence checking apparatus according to the embodiment of the present invention.
FIG. 5 is a diagram illustrating details of functions of the
FIG. 6 is a diagram showing details of functions of the
FIG. 7 is a diagram showing details of the function and data flow of the structure comparison
FIG. 8 is a diagram showing details of functions and data flow of the symbol execution
FIG. 9 is a diagram showing details of functions and data flow of the symbol execution
本実施形態のソースコード等価性検証装置1000は、図3に示されるように、リファクタリング前ソースコード0001とリファクタリング後ソースコード0002の二つのソースコードと、リファクタリング前ソースコード0001に対して適用されたリファクタリングパターンに関する入力情報であるリファクタリングパターン入力情報0003の入力によって、リファクタリング前ソースコード0001とリファクタリング後ソースコード0002のソースコードの等価性を検証するものである。本実施形態のソースコード等価性検証装置1000の処理は、図1に示されたPCなどのハードウェアが、図2に示されたソースコード等価性検証プログラム200を実行することによりおこなわれる。
As shown in FIG. 3, the source code
先ず、入力部1100において、入力されたリファクタリング前ソースコード0001の入力を受け付ける(図4のS101)。リファクタリング後ソースコード入力ステップS102では、入力部1100において、リファクタリング後ソースコード0002を受け付ける(S102)。また、入力部1100において、リファクタリングパターン入力情報0003の入力を受け付ける(S103)。
First, the
以下、図5を用いて上記の入力部1100の機能の詳細とその処理について説明する。
Hereinafter, the details of the function of the
リファクタリング前ソースコード0001は、図5に示されるように、入力部1100におけるソースコード入力部1101によって受け取られ、ソースコードの字句解析と構文解析をおこない、リファクタリング前ソースコード情報1001に変換される。リファクタリング後ソースコード0002も、入力部1100におけるソースコード入力部1101によって受け取られ、ソースコードの字句解析と構文解析をおこない、リファクタリング後ソースコード情報1002に変換され、記憶部1600に格納される。また、リファクタリングパターン入力情報0003は、入力部1100におけるリファクタリングパターン入力部1102によって受け付けられ、リファクタリングパターン種別を表すリファクタリングパターン情報1003に変換され、記憶部1600に格納される。
As shown in FIG. 5, the
次に、リファクタリング前ソースコード情報1001と、リファクタリング後ソースコード情報1002を比較し、ソースコードの構造上の変更箇所を特定する(S1041)。
Next, the
そして、正規化部1200は、記憶部1600に格納された情報を用いて、リファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報1002の正規化をおこなう(S1042)。
Then, the
ここで、正規化とは、リファクタリングがおこなわれたソースコードのソースコード情報を、そのソースコードと等価なソースコードに対応するソースコード情報に変換することを意味する。この正規化は、この後に続く構造比較ステップS1043と記号実行ステップS1045に適した形にするためにおこなわれる。 Here, normalization means that the source code information of the refactored source code is converted into source code information corresponding to the source code equivalent to the source code. This normalization is performed in a form suitable for the subsequent structure comparison step S1043 and symbol execution step S1045.
以下、図6を用いて上記の正規化部1200の機能の詳細とその処理について説明する。
リファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報1002は、正規化部1200の変更箇所特定部1201に入力される。一方、正規化DB1601に格納されているリファクタリングパターン情報1003に対応した変更箇所特定情報1007bを取得される。そして、変更箇所特定部1201はソースコード情報を比較し、リファクタリングパターン情報1003に対応した変更箇所特定情報1007bを参照し、ソースコードの構造上の変更箇所を特定し、変更箇所情報1004を生成する(S1041)。
Hereinafter, details of the function of the
The pre-refactoring
次に、リファクタリングパターン入力情報1003に対応する正規化の方法を示した正規化情報1007aを記憶部1600の正規化DB1601から取得する(S1042)。正規化DB1601には、リファクタリングパターンごとに対応した正規化情報1007aを格納してある。正規化部1200のソースコード正規化部において、リファクタリング前ソースコード情報1001に対して、取得した正規化情報1007aに基づき正規化をおこない、リファクタリング前正規化ソースコード情報1005を生成する。また、正規化部1200のソースコード正規化部において、リファクタリング後ソースコード情報1002に対して、正規化情報1007aに基づき、正規化をおこない、リファクタリング後正規化ソースコード情報1006を生成する。
Next,
次に、構造比較検証処理部1300は、リファクタリング前正規化ソースコード情報1005とリファクタリング後正規化ソースコード情報1006の構造を比較し、同じ構造であるか否かを検証する(ステップS1042)。
Next, the structure comparison
以下、図7を用いて構造比較検証処理部1300の機能の詳細とその処理について説明する。
Hereinafter, details of the function of the structure comparison
構造比較検証処理部1300は、リファクタリング前正規化ソースコード情報1005とリファクタリング後正規化ソースコード情報1006を受け取り、二つの正規化後のソースコード情報の構造が一致しているか否かの比較をおこない、一致した場合は、構造比較結果1008として、一致しているという情報を生成し、不一致の場合は、構造比較結果1008として、不一致であるいう情報を生成する(S1043)。
The structure comparison /
次に、記号実行実施判定部1700では、記号実行をおこなうべきか否かを判定する(S1047)。ここで、上記の構造比較ステップS1043の結果で、構造が一致していると判定されたときには、等価非等価出力ステップS105に行き、構造が不一致であると判定されたときには、ソースコード抽象化ステップS1044に行く。
Next, the symbol execution
以下、図8を用いて記号実行実施判定部1700の機能の詳細とその処理について説明する。
Details of the function of the symbol execution
記号実行実施判定部1700は、構造比較結果1008を受け取り、構造比較結果1008で、構造が「一致」であれば、等価非等価出力ステップS105へ移行し、出力部1500に、ソースコードが等価であるとして検証結果0004を出力させる。
The symbol execution
ソースコードが等価であるいう結果が出力されたときには、ユーザは、おこなわれたリファクタリングが正当であると判断することができる。 When the result that the source code is equivalent is output, the user can determine that the refactoring performed is valid.
記号実行実施判定部1700は、構造比較結果1008を受け取り、構造比較結果1008で、構造が「不一致」であれば、記号実行開始指示1009を生成する。
The symbol execution
次に、ソースコード情報の抽象化をおこなう(S1044)。 Next, the source code information is abstracted (S1044).
ここで、ソースコード情報の抽象化とは、各々のソースコード情報に対して、記号実行したときに、同じ入力を与えて、同じ結果がでるようにした状態を保ったまま、ソースコード情報を縮約することを意味する。 Here, the abstraction of source code information means that source code information is kept in a state where the same input is given to each source code information and the same result is obtained when symbol execution is performed. Means contraction.
次に、抽象化したリファクタリング前のソースコード情報と、抽象化したリファクタリング後のソースコード情報に対して、記号実行をおこなう(S1045)。 Next, symbol execution is performed on the abstracted source code information before refactoring and the abstracted source code information after refactoring (S1045).
そして、記号実行の結果を比較し、同じ入力に対して、同じ出力(記号実行サマリ)が得られるときには、元のソースコードが等価であると、判断し、出力(記号実行サマリ)が異なるときには、元のソースコードが非等価であると、判断して(S1046)、等価非等価の結果出力をおこなう。 When the results of symbol execution are compared and the same output (symbol execution summary) is obtained for the same input, it is determined that the original source code is equivalent, and the output (symbol execution summary) is different. Then, it is determined that the original source code is not equivalent (S1046), and an equivalent non-equivalent result is output.
ここで、ソースコードが等価であるいう結果が出力されたときには、ユーザは、おこなわれたリファクタリングが正当であると判断することができ、ソースコードが非等価であるいう結果が出力されたときには、ユーザは、おこなわれたリファクタリングが不当であると判断することができる。そして、ユーザは、おこなわれたリファクタリングが不当であると判断したときには、おこなったリファクタリングを見直して、正当なものに修正する作業を開始することができる。 Here, when the result that the source code is equivalent is output, the user can determine that the refactoring performed is valid, and when the result that the source code is non-equivalent is output, The user can determine that the refactoring performed is inappropriate. When the user determines that the refactoring that has been performed is inappropriate, the user can review the refactoring that has been performed and start work to correct it.
記号実行検証処理部1400は、記号実行開始指示1008を受けて、ソースコード抽象化ステップS1044を開始する。ソースコード抽象化ステップ1044では、記憶部1600の抽象化DB1602に格納されている抽象化方法情報を用いて、リファクタリング前正規化ソースコード情報と変更箇所情報1004を受け取り、抽象化をおこない、リファクタリング前抽象化ソースコード情報を生成する。また、ソースコード抽象化ステップ1044では、記憶部1600の抽象化DB1602に格納されている抽象化手法を用いて、リファクタリング後正規化ソースコード情報と変更箇所情報1004を受け取り、抽象化をおこない、リファクタリング後抽象化ソースコード情報を生成する。ここで、抽象化DBに格納されている抽象化方法情報は、正規化後のソースコード情報に対して、変更箇所情報1004に関わらない箇所とループや再帰呼び出しの箇所を置き換えて、この後の記号実行ステップS1045の時に、変更箇所情報1004に関わらない箇所とループや再帰呼び出しの箇所を記号実行しないように変換する処理の方法に関する情報である。
The symbol execution
記号実行ステップS1045では、記号実行部1402において、リファクタリング前抽象化ソースコード情報1403とリファクタリング後抽象化ソースコード情報1404に対して、記号実行をおこない、それぞれリファクタリング前記号実行結果1405とリファクタリング後記号実行結果を得る。記号実行結果比較ステップS1046では、記号実行結果比較部1407において、リファクタリング前記号実行結果1405とリファクタリング後記号実行結果が同じものであるか否かを比較し判定する。記号実行結果比較部1407において、リファクタリング前記号実行結果1405とリファクタリング後記号実行結果が同じものであった場合、等価非等価出力ステップS105へ移行し、等価として出力部1500に検証結果0004を出力させる。記号実行結果比較部1407において、リファクタリング前記号実行結果1405とリファクタリング後記号実行結果が異なるものであった場合、等価非等価出力ステップS105へ移行し、非等価として出力部1500に検証結果0004を出力させる。
In the symbol execution step S1045, the
本実施形態のソースコード等価性検証装置によれば、計算量が爆発しやすい記号実行をおこなう前に、それぞれのリファクタリング前後のそれぞれのソースコード情報に対して、正規化後に、構造比較をおこない、その元になるソースコードが等価であると判定された場合には、記号実行をおこなわない。 According to the source code equivalence verification apparatus of the present embodiment, before performing symbol execution that tends to explode, the structure comparison is performed after normalization for each source code information before and after each refactoring, When it is determined that the source code as the source is equivalent, symbol execution is not performed.
また、構造比較で元になるソースコードが非等価と判定された場合には、ソースコード情報の抽象化をおこなって、ソースコード情報を縮減してから、記号実行をおこなうので、記号実行の計算量を削減することができる。 Also, if the source code is determined to be non-equivalent in the structure comparison, the source code information is abstracted and the source code information is reduced before performing symbol execution. The amount can be reduced.
〔ソースコード等価性検証装置の処理の具体例(構造一致と判定されるときの例)〕
以下、上記の図4を参照しながら、図10ないし図12を用いて本発明の一実施形態に係るソースコード等価性検証装置の処理の具体例について説明する。
この例は、図4の記号実行実施判定の処理で、ソースコード情報である構造グラフの構造が一致すると判定される例である。
図10は、リファクタリング前後のソースコードの例を示す図である(その一)。
図11は、リファクタリング前後のソースコードに対応するソースコード情報の例を示す図である(その一)。
[Specific example of processing of source code equivalence verification device (example when it is determined that the structure matches)]
Hereinafter, a specific example of processing of the source code equivalence checking apparatus according to the embodiment of the present invention will be described with reference to FIG. 4 and FIGS. 10 to 12.
This example is an example in which it is determined in the symbol execution execution determination process of FIG. 4 that the structure of the structure graph as the source code information matches.
FIG. 10 is a diagram illustrating an example of source code before and after refactoring (part 1).
FIG. 11 is a diagram illustrating an example of source code information corresponding to source codes before and after refactoring (part 1).
図12は、ソースコード情報に対しておこなわれる正規化の例を示す図である。 FIG. 12 is a diagram illustrating an example of normalization performed on source code information.
この例では、ソースコードに対するリファクタリングとして、リファクタリングパターンExtractMethodに基づいたリファクタリングがおこなわれる場合について説明する。リファクタリングパターンExtractMethodは、複数個所で同じ処理をしているソースコードにおいて、その同じ処理を関数として抜き出し、複数個所で同じ処理をしていた箇所を抜き出した関数への呼び出しに置き換えて、複数箇所に存在したソースコードを共通化するリファクタリングのパターンである。このリファクタリングパターンExtractMethodは、一つの関数においてソースコードの記述量が多い場合に、関数の可読性を向上させるために、その関数内のソースコードの一部を別の関数として抜き出すリファクタリングとしても用いられる。 In this example, a case where refactoring based on the refactoring pattern ExtractMethod is performed as refactoring for the source code will be described. In the refactoring pattern ExtractMethod, the same processing is extracted as a function in the source code that performs the same processing in a plurality of places, and the place where the same processing is performed in a plurality of places is replaced with a call to the extracted function. This is a refactoring pattern to share existing source code. This refactoring pattern ExtractMethod is also used as a refactoring that extracts a part of the source code in the function as another function in order to improve the readability of the function when the description amount of the source code is large in one function.
以下、図10によりリファクタリングパターンExtractMethodによって、ソースコードのリファクタリングをおこなう例を説明する。 Hereinafter, an example in which source code is refactored using a refactoring pattern ExtractMethod will be described with reference to FIG.
ソースコードC001は、リファクタリングパターンExtractMethodの適用前のソースコードであり、グローバル変数global_varに対してmain関数において10を代入するプログラムである。このソースコードC001に対して、リファクタリングパターンExtractMethodを適用したソースコードがC002となる。ソースコードC002は、ソースコードC001におけるglobal_var=10;というグローバル変数への代入文を関数fooとして抜き出し、global_var=10;の記述部分であった箇所を関数fooの呼び出しに変換している。 The source code C001 is a source code before application of the refactoring pattern ExtractMethod, and is a program for substituting 10 in the main function for the global variable global_var. A source code obtained by applying a refactoring pattern ExtractMethod to the source code C001 is C002. In the source code C002, the assignment statement to the global variable “global_var = 10;” in the source code C001 is extracted as the function foo, and the portion that was the description part of the global_var = 10; is converted into a call to the function foo.
先ず、図10に示したリファクタリングの例における、図4のリファクタリング前ソースコード入力S101とリファクタリング後ソースコード入力S102とリファクタリングパターンS103のステップについて説明する。 First, steps of the source code input S101 before refactoring, the source code input S102 after refactoring, and the refactoring pattern S103 in FIG. 4 in the example of refactoring shown in FIG. 10 will be described.
入力部1100では、ソースコード入力部1101によって、リファクタリング前ソースコード0001とリファクタリング後ソースコード0002を受け付けて、対応するリファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報を生成する。ここで、リファクタリング前ソースコード0001はソースコードC001、リファクタリング後ソースコード0002はソースコードC002に対応する。
In the
ソースコード等価性検証装置1000は、入力されたリファクタリング前ソースコード0001とリファクタリング後ソースコード0002をソースコード入力部1101によって字句解析と構文解析し、図11の例で示されるような内部で扱う構造グラフに変換される。リファクタリングパターンExtractMethodの例では、ソースコードC001は、構造グラフM001、ソースコードC002は、グラフM002に変換される。ここで、リファクタリング前ソースコード情報1001は構造グラフM001、リファクタリング後ソースコード情報1002は構造グラフM002に対応する。
The source code
入力部1100では、リファクタリングパターン入力部1102において、リファクタリングパターン入力情報0003を受け付けて、リファクタリングパターン情報1003を生成する。この例では、例えば、リファクタリングパターン入力情報0003が、リファクタリングパターンExtractMethodを表す文字列“ExtractMethod”や、画面のメニューでの選択番号のときに、リファクタリングパターン情報1003として、内部で、リファクタリングパターンExtractMethodを指し示すコードを生成する。
In the
次に、図4の変更箇所特定S1041のステップについて説明する。
正規化部1200の変更箇所特定部1201において、リファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報1002とリファクタリングパターン情報1003から、正規化DB1601の中にある対応する変更箇所特定情報1007bを参照し、ソースコード上のどこを変更したのかを特定し、変更箇所情報1004を出力する。このリファクタリングパターンExtractMethodの例では、リファクタリングパターンExtractMethodは、リファクタリング後ソースコード情報1002において関数が増加するという特徴から、リファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報1002の関数の宣言を比較し、リファクタリング後ソースコード情報1002のみに現れる関数を変更箇所として特定する。図11上では、リファクタリング前ソースコード情報1001の構造グラフM001とリファクタリング後ソースコード情報1002の構造グラフM002の中で、関数を示すentryを比較し、ノードM003が指し示すentryのfoo関数が増えていることから、ノードM003およびfoo関数を呼び出すノードM004が、変更箇所情報1004に該当する。
Next, the step of change location identification S1041 in FIG. 4 will be described.
In the changed
次に、図4のソースコード正規化S1042のステップについて説明する。
正規化部1200のソースコード正規化部1202において、変更箇所情報1004とリファクタリング前ソースコード情報1001から、正規化DB1601の中にある対応する正規化情報1007aを用いて正規化をおこない、リファクタリング前正規化ソースコード情報1005を生成する。リファクタリング後ソースコード情報1002も同様に正規化をおこない、リファクタリング後正規化ソースコード情報1006を生成する。このリファクタリングパターンExtractMethodにおけるソースコード正規化部1202の例を示すと、図12のようになる。先ず、正規化DB1601からリファクタリングパターン情報1003であるリファクタリングパターンExtractMethodに該当する正規化情報1007aを取得する。リファクタリングパターン情報1003のExtractMethodに対応する正規化情報1007aによれば、正規化方法は、Extractしたリファクタリング後ソースコード情報0002における変更箇所1004の関数を、インライン展開にして基に戻したときのソースコードを表す構造にすることである。
Next, the steps of source code normalization S1042 in FIG. 4 will be described.
In the source
図12における変更箇所1004は、リファクタリング後ソースコード情報1002の構造グラフM002におけるノードM003とノードM004であり、これらのノードは、リファクタリングより作られたExtractされた関数fooであるので、その関数fooを正規化して元に戻すと、構造グラフM006のようになる。これがリファクタリング後正規化ソースコード情報1006となる。リファクタリング前正規化ソースコード情報1005は、リファクタリングパターンExtractMethodに関して正規化処理が無いため、図12上のリファクタリング前ソースコード情報0001の構造グラフM001は正規化では何も変更されずに、そのまま、構造グラフM005となる。
The changed
次に、図4の構造比較S1043のステップについて説明する。
構造比較検証処理部1300では、リファクタリング前正規化ソースコード情報1005とリファクタリング後正規化ソースコード情報1006を受け取り、ソースコード情報の構造の比較をおこない、その結果を構造比較結果1008として生成する。リファクタリングパターンExtractMethodによるリファクタリングをおこなったこの図10による例において、構造比較検証処理部1300は、リファクタリング前正規化ソースコード情報1005のグラフM005とリファクタリング後正規化ソースコード情報1006のグラフM006の二つのグラフが同じ構造でありそれぞれのノードが同じであるため、構造比較結果1008として、ソースコードC001とソースコードC002を等価であると判定する。
Next, the step of the structure comparison S1043 in FIG. 4 will be described.
The structure comparison
次に、図4の記号実行実施判定S1047のステップについて説明する。
記号実行実施判定部1700は、リファクタリングパターンExtractMethodによるリファクタリングをおこなったこの図10による例において、構造比較結果1008として、リファクタリング前後のソースが等価として判定されるため、等価非等価出力ステップS105に移行し、出力部1500は、構造比較検証処理部1300が等価と判定した結果を受けて、検証結果0004として等価であることを出力する。
Next, the step of the symbol execution execution determination S1047 in FIG. 4 will be described.
In the example according to FIG. 10 in which the refactoring pattern ExtractMethod has been refactored, the symbol
記号実行実施判定部1700は、リファクタリングパターンExtractMethodによるリファクタリングをおこなったこの図10による例では、正規化部1200による変換と構造比較検証処理部1300の判定処理によって、リファクタリング前後のソースコードが、各々等価と判定できるため、記号実行検証処理部1400により、記号実行の計算を必要とせず、計算量を不必要に増加させずに、迅速な等価判定が可能となる。
In the example shown in FIG. 10 in which the symbol execution
〔ソースコード等価性検証装置の処理の具体例(構造不一致と判定されるときの例)〕
以下、上記の図4を参照しながら、図13ないし図16を用いて本発明の一実施形態に係るソースコード等価性検証装置の処理の具体例について説明する。
この例は、図4の記号実行実施判定の処理で、ソースコード情報である構造グラフの構造が不一致であると判定される例である。
図13は、リファクタリング前後のソースコードの例を示す図である(その二)。
図14は、リファクタリング前後のソースコードに対応するソースコード情報の例を示す図である(その二)。
図15は、抽象化されたソースコード情報の例を示す図である。
図16は、リファクタリング前ソースコードとリファクタリング後ソースコードに対して記号実行したときの実行木を示した例である。
[Specific example of processing of source code equivalence verification device (example when judged as structure mismatch)]
Hereinafter, a specific example of processing of the source code equivalence checking apparatus according to the embodiment of the present invention will be described with reference to FIG. 4 and FIG. 13 to FIG.
This example is an example in which it is determined in the symbol execution execution determination process of FIG. 4 that the structure of the structure graph as the source code information does not match.
FIG. 13 is a diagram illustrating an example of source code before and after refactoring (part 2).
FIG. 14 is a diagram illustrating an example of source code information corresponding to source codes before and after refactoring (part 2).
FIG. 15 is a diagram illustrating an example of abstracted source code information.
FIG. 16 is an example showing an execution tree when symbol execution is performed on the source code before refactoring and the source code after refactoring.
この例では、ソースコードに対するリファクタリングとして、ソースコードにおける条件式を変更せずに変数への代入を整理するリファクタリングがおこなわれる場合について説明する。 In this example, a case will be described in which refactoring for organizing assignments to variables without changing a conditional expression in the source code is performed as refactoring for the source code.
図13では、リファクタリング前のソースコードC003とリファクタリング後のソースコードC004が示されており、ソースコードC003とソースコードC004の間で、ソースコードにおける条件式を変更せずに変数への代入を整理するリファクタリングが適用されている。具体的には、リファクタリング前のソースコードC003では、ソースコード部分C005が示す所において、変数aに対して値を代入し、ソースコード部分C006が示す所において、変数a(左辺)の値を用いて演算し変数a(右辺)に代入している。リファクタリング後のソースコードC004では、ソースコード部分C007が示す所において、変数bに対して値を代入し、ソースコード部分C008が示す所において、変数bの値を用いて演算し変数aに代入している。リファクタリング前と後で、ソースコード部分C005が示す所とソースコード部分C007が示す所に存在する条件式、ソースコード部分C006が示す所とソースコード部分C008が示す所に存在する条件式が一致しているが用いている変数を変更し、ソースコードC004の方が、ソースコード行数が少なく可読性が高いものになっている。図13の例で示すリファクタリングは、非特許文献4に記載されているリファクタリングパターン72種に該当せず、本実施形態のソースコード等価性検証装置1000においてもパターンとしてデータベースに登録されていないものとする。
FIG. 13 shows the source code C003 before refactoring and the source code C004 after refactoring, and the assignment to variables is arranged between the source code C003 and the source code C004 without changing the conditional expression in the source code. Refactoring has been applied. Specifically, in the source code C003 before refactoring, a value is substituted for the variable a at the location indicated by the source code portion C005, and the value of the variable a (left side) is used at the location indicated by the source code portion C006. Is calculated and assigned to the variable a (right side). In the source code C004 after refactoring, a value is assigned to the variable b at the location indicated by the source code portion C007, and the value is calculated using the value of the variable b at the location indicated by the source code portion C008 and assigned to the variable a. ing. Before and after refactoring, the conditional expressions present at the location indicated by the source code portion C005 and the location indicated by the source code portion C007 match the conditional expressions present at the location indicated by the source code portion C006 and the location indicated by the source code portion C008. However, the variables used are changed, and the source code C004 has a smaller number of source code lines and higher readability. The refactoring shown in the example of FIG. 13 does not correspond to the 72 types of refactoring patterns described in
先ず、図13に示したリファクタリングの例における、図4のリファクタリング前ソースコード入力S101とリファクタリング後ソースコード入力S102について説明する。このリファクタリングの例では、リファクタリング前ソースコード0001がソースコードC003、リファクタリング後ソースコード0002がソースコードC004に対応する。入力部1100では、ソースコード入力部1101によって、リファクタリング前ソースコード0001とリファクタリング後ソースコード0002を受け付けて、対応するリファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報を生成する。図13のリファクタリングの例において、ソースコード入力部1101がリファクタリング前ソースコード0001としてソースコードC003を受けつけ、字句解析と構文解析をおこない、リファクタリング前ソースコード情報1001として図14の構造グラフM008に変換する。また、ソースコード入力部1101は、リファクタリング後ソースコード0002としてソースコードC004を受けつけ、字句解析と構文解析をおこない、リファクタリング後ソースコード情報1002として図14の構造グラフM009に変換する。ここで、リファクタリング前ソースコード情報1001は構造グラフM008、リファクタリング後ソースコード情報1002は構造グラフM009に対応する。
First, the pre-refactoring source code input S101 and the post-refactoring source code input S102 of FIG. 4 in the refactoring example shown in FIG. 13 will be described. In this refactoring example,
次に、リファクタリングパターンに関する情報を入力するS103のステップについて説明する。 Next, the step of S103 for inputting information related to the refactoring pattern will be described.
入力部1100では、リファクタリングパターン入力部1102において、リファクタリングパターン入力情報0003を受け付けて、リファクタリングパターン情報1003を生成する。このリファクタリングの例では、リファクタリングパターンは、登録されていないものと仮定しているため、「該当無し」を示す文字列やメニューの選択番号がリファクタリングパターン入力部1102に入力され、リファクタリングパターン入力部は、リファクタリングパターン情報1003として、「該当無し」を示すコードを生成する。
In the
次に、図4の変更箇所特定S1041のステップについて説明する。
正規化部1200の変更箇所特定部1201において、リファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報1002から、ソースコード上のどこを変更したのかを特定し、変更箇所情報1004を出力する。このリファクタリングの例では、リファクタリング前ソースコード情報1001である構造グラフM008とリファクタリング後ソースコード情報0002である構造グラフM009を比較し、両方に関数fooと関数varが存在しているため関数レベルの増減が無く、foo関数の内部に差異がみられるため、変更箇所特定部1201は、foo関数の内部を変更箇所情報1004として出力する。なお、この例では、リファクタリングパターンとして「該当無し」なので、正規化DB1601の変更箇所特定情報1007bは、参照せず、構造グラフの構造を解析することだけで、変更箇所を特定する。
Next, the step of change location identification S1041 in FIG. 4 will be described.
In the change
次に、図4のソースコード正規化S1042のステップについて説明する。 Next, the steps of source code normalization S1042 in FIG. 4 will be described.
正規化部1200のソースコード正規化部1202において、変更箇所情報1004とリファクタリング前ソースコード情報1001から、正規化DB1601の中にある対応する正規化情報1007aの正規化手法を用いて正規化をおこない、リファクタリング前正規化ソースコード情報1005を生成する。リファクタリング後ソースコード情報1002も同様に正規化をおこない、とリファクタリング後正規化ソースコード情報1006を生成する。このリファクタリングの例では、正規化DB1601からリファクタリングパターン情報1003である「該当無し」に対応する正規化情報を取得する。ここで、リファクタリングパターン情報1003である「該当無し」に対応する正規化情報は、変換無しとなるため、ソースコード正規化部1202は、リファクタリング前ソースコード情報1001とリファクタリング後ソースコード情報1002に関して、何も変更せずにリファクタリング前正規化ソースコード情報1005とリファクタリング後正規化ソースコード情報1006を出力する。正規化部1202で変換されていないので、リファクタリング前正規化ソースコード情報1005は、図14における構造グラフM008であり、リファクタリング後正規化ソースコード情報は、図14における構造グラフM009である。
In the source
次に、図4の構造比較S1043のステップについて説明する。
構造比較検証処理部1300では、リファクタリング前正規化ソースコード情報1005とリファクタリング後正規化ソースコード情報1006を受け取り、ソースコード情報の構造の比較をおこない、構造比較結果1008を生成する。このリファクタリングの例では、リファクタリング前正規化ソースコード情報1005のグラフM008とリファクタリング後正規化ソースコード情報1006の構造グラフM009を比較し、明らかにグラフ構造が異なるため、構造比較結果1008として、リファクタリング前後の構造が不一致であると判定する。
Next, the step of the structure comparison S1043 in FIG. 4 will be described.
The structure comparison
次に、図4の記号実行実施判定ステップS1047について説明する。
記号実行実施判定部1700は、このリファクタリングの例において、構造比較結果1008として、ソースコードが非等価と判定されため、記号実行開始指示1009のコマンドを生成する。
Next, the symbol execution execution determination step S1047 of FIG. 4 will be described.
In this refactoring example, the symbol execution
次に、図4のソースコード抽象化ステップS1044について説明する。
記号実行検証処理部1400は、記号実行開始指示1009を受け取ると、抽象化部1401において、変更箇所情報1004と抽象化DB1602の抽象化方法を記録した抽象化情報1010を用いて、リファクタリング前正規化ソースコード情報1005とリファクタリング後正規化ソースコード情報1006の抽象化をおこなう。抽象化DB1601の抽象化情報1603には、変更箇所情報1004に対応して適切な抽象化手法が記録されている。このリファクタリングの例では、変更箇所情報1004は関数fooの内部と判明しているため、抽象化DB1601から、関数fooを除いたソースコードの中で、リファクタリング前後で差異が生じていない関数を変数に変換して抽象化する方法を記載した抽象化情報1603を取得する。抽象化部1401において、リファクタリング前後で差異が生じていない関数を変数に変換して抽象化する方法を、リファクタリング前正規化ソースコード情報1005のグラフM008とリファクタリング後正規化ソースコード情報1006のグラフM009に適用した結果を示すと、図15のようになる。図14のリファクタリング前正規化ソースコード情報1005の構造グラフM008において、ノードM010の関数varはリファクタリングによって差異が生じていないため、関数varを呼び出す箇所のノードM011と合わせて変数vとして抽象化をおこない、図15の構造グラフM014のように変換する。ただし、この抽象化は、ノードM010と他のノードとのDataDependency(データの依存性)がないことが必要である。図14におけるリファクタリング後正規化ソースコード情報1006のグラフM009に関しても、同様に抽象化をおこない制御フローグラフM015に変換される。抽象化部1401は、前記制御フローグラフM014をリファクタリング前抽象化ソースコード情報1403、前記制御フローグラフM015をリファクタリング後抽象化ソースコード情報1404として出力する。ここで、この抽象化は、構造グラフM008、M009の各々において、ノードがカットされて、各々が記号実行されたときには、計算量が減ることに留意する。
Next, the source code abstraction step S1044 of FIG. 4 will be described.
When the symbol execution
次に、図4の記号実行S1045のステップについて説明する。
記号実行検証処理部1400では、抽象化部1401において抽象化をおこなった後、リファクタリング前抽象化ソースコード情報1403とリファクタリング後抽象化ソースコード情報1404のそれぞれに対して、記号実行部1402において、記号実行を実行し、その結果としてリファクタリング前記号実行結果1405とリファクタリング後記号実行結果1406を生成する。このリファクタリングの例において、記号実行部1402にて、前記リファクタリング前抽象化情報1403とリファクタリング後抽象化情報1404を記号実行した結果は、図16に示されるようになる。このリファクタリングの例では、リファクタリング前抽象化情報1403は、図15の構造グラフM014に該当し、構造グラフM014に対して記号実行をおこなうと、図16における実行木E100ができる。また、図16の実行木E100における記号実行サマリであるE101,E102,E103,E104が、リファクタリング前抽象化情報1403に対するリファクタリング前記号実行結果1405となる。リファクタリング後抽象化情報1404は、図4のリファクタリングの例では、図15の構造グラフM015に該当し、構造グラフM015に対して記号実行をおこなうと、図16における実行木E200ができる。また、図16の実行木E200における記号実行サマリであるE201,E202,E203,E204が、リファクタリング後抽象化情報1404に対するリファクタリング後記号実行結果1406となる。
Next, the step of symbol execution S1045 of FIG. 4 will be described.
In the symbol execution
次に、図4の記号実行結果比較S1046のステップについて説明する。
記号実行検証処理部1400の記号実行結果比較部1407では、リファクタリング前記号実行結果1405とリファクタリング後記号実行結果1406の比較をおこない、リファクタリング前後のソースコードが等価か非等価かの判定をおこなう。図13のリファクタリングの例では、リファクタリング前記号実行結果1405は、E101,E102,E103,E104であり、リファクタリング後記号実行結果1405は、E201,E202,E203,E204である。これらの二つの記号実行結果を比較すると、E101とE201のペアと、E102とE202のペアと、E103とE203のペアと、E104とE204のペアがそれぞれパス制約と変数状態が一致しているため、記号実行結果比較部1407は、ソースコードが等価と判定し、等価非等価出力部に送る。このとき、リファクタリング前の記号実行木E100とリファクタリング後の記号実行木E200の間には構造上の差異が生じているが、記号実行の最終的な記号実行サマリが一致しているため。ソースコードが等価と判定する。
Next, the step of the symbol execution result comparison S1046 of FIG. 4 will be described.
The symbol execution
次に、図4の等価非等価出力S105のステップについて説明する。
出力部1500は、記号実行比較部1407が、ソースコードが等価と判定した結果を受けて、検証結果0004として、ソースコードが等価であることを出力する。そして、これにより、ユーザは、リファクタリングが妥当なものであることを判断できる。
Next, the steps of the equivalent non-equivalent output S105 in FIG. 4 will be described.
The
本例では、S1047の判定で、ソースコード情報である構造グラフ上の構造の差異を生じるため、ソースコードが等価であることを検証するために、記号実行する必要があるが、ソースコード情報の抽象化をおこない、ソースコード情報の縮減をおこなうために、記号実行における計算量を削減することができる。 In this example, the determination in S1047 causes a structural difference on the structure graph that is the source code information. Therefore, it is necessary to execute symbols to verify that the source code is equivalent. Since the abstraction is performed and the source code information is reduced, the amount of calculation in symbol execution can be reduced.
0001…リファクタリング前ソースコード
0002…リファクタリング後ソースコード
0003…リファクタリングパターン
0004…検証結果
1000…ソースコード等価性検証装置
1100…入力部
1200…正規化部
1300…構造比較検証処理部
1400…記号実行検証処理部
1500…出力部
1600…記憶部
1700…記号実行実施判定部
1001…リファクタリング前ソースコード情報
1002…リファクタリング後ソースコード情報
1003…リファクタリングパターン情報
1004…変更箇所情報
1005…リファクタリング前正規化ソースコード情報
1006…リファクタリング後正規化ソースコード情報
1007a…正規化情報
1007b…変更箇所特定情報
1008…構造比較結果
1009…記号実行開始指示
1010…抽象化情報
1101…ソースコード入力部
1102…リファクタリングパターン入力部
1201…変更箇所特定部
1202…ソースコード正規化部
1401…抽象化部
1402…記号実行部
1403…リファクタリング前抽象化ソースコード情報
1404…リファクタリング後抽象化ソースコード情報
1405…リファクタリング前記号実行結果
1406…リファクタリング後記号実行結果
1407…記号実行結果比較部
1601…正規化データベース
1602…抽象化データベース
S101…リファクタリング前ソースコード入力ステップ
S102…リファクタリング後ソースコード入力ステップ
S103…リファクタリングパターン入力情報入力ステップ
S1041…変更箇所特定ステップ
S1042…ソースコード正規化ステップ
S1043…構造比較ステップ
S1044…ソースコード抽象化ステップ
S1045…記号実行ステップ
S1046…記号実行結果比較ステップ
S1047…記号実行実施判定ステップ
S105…等価非等価出力ステップ
C001…リファクタリング適用前のソースコード
C002…リファクタリング適用後のソースコード
C003…リファクタリング適用前のソースコード
C004…リファクタリング適用後のソースコード
C005…C003における関数foo内のソースコードの前半部
C006…C003における関数foo内のソースコードの後半部
C007…C004における関数foo内のソースコードの前半部
C008…C004における関数foo内のソースコードの後半部
E001…記号実行を説明するためのソースコード
E002…ソースコードの構造グラフ
E003…構造グラフにおける関数fooのエントリーを示すノード
E004…構造グラフにおけるE003の遷移先のノード
E005…構造グラフにおけるE004の遷移先のノード
E006…構造グラフにおけるE005の分岐先のノード
E007…構造グラフにおけるE005の分岐先のノード
E008…構造グラフにおけるE006と7の遷移先のノード
E009a…構造グラフにおけるE008の分岐先のノード
E009b…構造グラフにおけるE008の分岐先のノード
E010…E003に対応する実行木ノード
E010a…E010のパス制約
E010b…E010の変数状態
E011…E004に対応する実行木ノード
E011a…E011のパス制約
E011b…E011の変数状態
E012…E006に対応する実行木ノード
E012a…E012のパス制約
E012b…E012の変数状態
E013…E007に対応する実行木ノード
E013a…E013のパス制約
E013b…E013の変数状態
E014…E006を経由した場合のE009に対応する実行木ノード
E015…E006を経由した場合のE009aに対応する実行木ノード
E016…E007を経由した場合のE009に対応する実行木ノード
E017…E007を経由した場合のE009aに対応する実行木ノード
E020…記号実行の実行木
E100…リファクタリング適用前のソースコード情報の記号実行の実行木
E101…E100における記号実行サマリに含まれるノード
E102…E100における記号実行サマリに含まれるノード
E103…E100における記号実行サマリに含まれるノード
E104…E100における記号実行サマリに含まれるノード
E200…リファクタリング適用後のソースコード情報の記号実行の実行木
E201…E200における記号実行サマリに含まれるノード
E202…E200における記号実行サマリに含まれるノード
E203…E200における記号実行サマリに含まれるノード
E204…E200における記号実行サマリに含まれるノード
M001…リファクタリング適用前のソースコードの構造グラフ
M002…リファクタリング適用後のソースコードの構造グラフ
M003…リファクタリングによって追加された関数を示すノード
M004…リファクタリングによって追加された関数を呼び出すノード
M005…リファクタリング適用前のソースコード情報の正規化済みの構造グラフ
M006…リファクタリング適用後のソースコード情報の正規化済みの構造グラフ
M007…正規化によって関数が展開された結果のリンク
M008…リファクタリング適用前のソースコードの構造グラフ
M009…リファクタリング適用後のソースコードの構造グラフ
M010…M008における関数varを示すノード
M011…M008における関数varを呼び出すノード
M012…M009における関数varを示すノード
M013…M009における関数varを呼び出すノード
M014…リファクタリング適用前のソースコード情報の抽象化済みの構造グラフ
M015…リファクタリング適用後のソースコード情報の抽象化済みの構造グラフ
M016…M014における抽象化された箇所を示すノード
0001 ... Source code before refactoring 0002 ... Source code after refactoring 0003 ...
Claims (4)
変更前のソースコードと、変更後のソースコードを入力するソースコード入力手段と、
前記ソースコードの変更の変更種別パターン情報を入力する変更種別パターン入力手段と、
前記変更前のソースコードと、前記変更後のソースコードの各々に対して、変更前ソースコード情報と、変更後ソースコード情報を生成するソースコード情報生成手段と、
ソースコード変更種別パターンに対して、定義される正規化情報を参照し、前記変更前ソースコード情報と、前記変更後ソースコード情報を正規化し、各々変更前ソースコード正規化情報と、変更後ソースコード正規化情報を生成する正規化手段と、
前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の構造を比較する構造比較手段と、
前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報を記号実行する記号実行手段と、
前記記号実行手段により記号実行の結果を比較して、前記変更前ソースコードと前記変更後ソースコードの等価性を判定する等価性判定手段とを有することを特徴とするソースコード等価性検証装置。 A source code equivalence verification device that has a CPU and a storage device and verifies equivalence before and after the change of the source code by causing the CPU to execute a program stored in the storage device,
Source code input means for inputting the source code before the change and the source code after the change,
Change type pattern input means for inputting the change type pattern information of the change of the source code;
Source code information generating means for generating source code information before change and source code information after change for each of the source code before change and the source code after change,
Reference is made to defined normalization information for the source code change type pattern, the source code information before change and the source code information after change are normalized, source code normalization information before change and source after change, respectively. Normalization means for generating code normalization information;
Structure comparison means for comparing the source code normalization information before change and the structure of the source code normalization information after change,
Symbol execution means for performing symbol execution of the source code normalization information before change and the source code normalization information after change,
A source code equivalence verification apparatus comprising: equivalence determination means for comparing the results of symbol execution by the symbol execution means to determine equivalence of the pre-change source code and the post-change source code.
前記構造比較手段により、前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の構造が比較され、構造が不一致であると判定されたときに、前記抽象化手段が、前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の各々の抽象化をおこなって、前記変更前ソースコード抽象化情報と、前記変更後ソースコード抽象化情報を生成し、
前記記号実行手段は、前記変更前ソースコード抽象化情報と、前記変更後ソースコード抽象化情報に対して、記号実行をすることを特徴とする請求項1記載のソースコード等価性検証装置。 Furthermore, it has an abstraction means for abstracting and reducing the source code information,
When the structure comparison means compares the structure of the source code normalization information before the change with the structure of the source code normalization information after the change and determines that the structures do not match, the abstraction means Performing abstraction of each of the previous source code normalization information and the changed source code normalized information, and generating the pre-change source code abstraction information and the changed source code abstraction information,
2. The source code equivalence verification apparatus according to claim 1, wherein the symbol execution means performs symbol execution on the pre-change source code abstraction information and the post-change source code abstraction information.
変更前のソースコードと、変更後のソースコードとを入力するソースコード入力ステップと、
前記ソースコードの変更の変更種別パターン情報を入力する変更種別パターン入力ステップと、
前記変更前のソースコードと、前記変更後のソースコードの各々に対して、変更前ソースコード情報と、変更後ソースコード情報を生成するソースコード情報生成ステップと、
ソースコード変更パターンに対して、定義される正規化情報を参照し、前記変更前ソースコード情報と、前記変更後ソースコード情報を正規化し、各々変更前ソースコード正規化情報と、変更後ソースコード正規化情報を生成する正規化ステップと、
前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の構造を比較する構造比較ステップと、
前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報を記号実行する記号実行ステップと、
前記記号実行手段により記号実行の結果を比較して、前記変更前ソースコードと前記変更後ソースコードの等価性を判定する等価性判定ステップと、
前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の各々の抽象化をおこなって、前記変更前ソースコード抽象化情報と、前記変更後ソースコード抽象化情報を生成する抽象化ステップとを有し、
前記構造比較ステップにより、前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の構造が比較され、構造が一致すると判定されたときに、前記記号実行ステップにおいて、前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報に対して記号実行をおこなわないようにし、
前記構造比較ステップにより、前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の構造が比較され、構造が不一致であると判定されたときに、前記抽象化ステップを実行し、前記変更前ソースコード正規化情報と、前記変更後ソースコード正規化情報の各々に対して、前記変更前ソースコード抽象化情報と、前記変更後ソースコード抽象化情報を生成し、
前記記号実行ステップにおいて、前記変更前ソースコード抽象化情報と、前記変更後ソースコード抽象化情報に対して、記号実行をすることを特徴とするソースコード等価性検証方法。 Source code equivalence verification by a source code equivalence verification device that has a CPU and a storage device, and verifies equivalence before and after the change of the source code by causing the CPU to execute a program stored in the storage device A method,
A source code input step for inputting the source code before the change and the source code after the change,
A change type pattern input step of inputting change type pattern information of the source code change;
A source code information generating step for generating source code information before change and source code information after change for each of the source code before change and the source code after change;
Normalization information defined with respect to the source code change pattern is referred to, the source code information before change and the source code information after change are normalized, and source code normalization information before change and source code after change, respectively. A normalization step for generating normalization information;
A structure comparison step for comparing the structure of the source code normalization information before the change and the structure of the source code normalization information after the change;
A symbol execution step for performing symbol execution of the pre-change source code normalization information and the post-change source code normalization information;
An equivalence determination step of comparing the result of symbol execution by the symbol execution means to determine equivalence of the source code before change and the source code after change;
Abstraction for generating the pre-change source code abstraction information and the post-change source code abstraction information by abstracting each of the pre-change source code normalization information and the post-change source code normalization information And having steps
When the structure comparison step compares the structure of the pre-change source code normalization information with the structure of the post-change source code normalization information and determines that the structures match, the symbol execution step determines the source before change Do not perform symbol execution on the code normalization information and the source code normalization information after the change,
The structure comparison step compares the structure of the pre-change source code normalization information and the structure of the post-change source code normalization information, and when the structure is determined to be inconsistent, executes the abstraction step, For each of the source code normalization information before change and the source code normalization information after change, the source code abstraction information before change and the source code abstraction information after change are generated,
A source code equivalence verification method, wherein in the symbol execution step, symbol execution is performed on the pre-change source code abstraction information and the post-change source code abstraction information.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2012282485A JP5903038B2 (en) | 2012-12-26 | 2012-12-26 | Source code equivalence verification apparatus and source code equivalence verification method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2012282485A JP5903038B2 (en) | 2012-12-26 | 2012-12-26 | Source code equivalence verification apparatus and source code equivalence verification method |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2014126985A true JP2014126985A (en) | 2014-07-07 |
JP5903038B2 JP5903038B2 (en) | 2016-04-13 |
Family
ID=51406429
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2012282485A Expired - Fee Related JP5903038B2 (en) | 2012-12-26 | 2012-12-26 | Source code equivalence verification apparatus and source code equivalence verification method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP5903038B2 (en) |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2016038741A1 (en) * | 2014-09-12 | 2016-03-17 | 株式会社日立製作所 | Source code equivalence verifying device, and source code equivalence verifying method |
WO2016174743A1 (en) * | 2015-04-28 | 2016-11-03 | 株式会社日立製作所 | Source code equivalence verification device and source code equivalence verification method |
JP2019003385A (en) * | 2017-06-14 | 2019-01-10 | 富士通株式会社 | Analysis device, analysis program and analysis method |
JP2019061587A (en) * | 2017-09-27 | 2019-04-18 | 富士通株式会社 | Analysis method, analyzer and analysis program |
JP2020038521A (en) * | 2018-09-05 | 2020-03-12 | 株式会社日立製作所 | Source code creation assisting device and source code creation assisting method |
JP2020087087A (en) * | 2018-11-28 | 2020-06-04 | 富士通株式会社 | Correction candidate specification program |
JP2022502774A (en) * | 2018-09-28 | 2022-01-11 | ジーメンス インダストリー ソフトウェア エヌ・フェーSiemens Industry Software NV | Methods and equipment for verifying software systems |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH096606A (en) * | 1995-06-19 | 1997-01-10 | Nec Corp | Re-engineering verification system |
JP2012022681A (en) * | 2010-07-14 | 2012-02-02 | Fujitsu Ltd | System and method for comparison of software framework |
-
2012
- 2012-12-26 JP JP2012282485A patent/JP5903038B2/en not_active Expired - Fee Related
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH096606A (en) * | 1995-06-19 | 1997-01-10 | Nec Corp | Re-engineering verification system |
JP2012022681A (en) * | 2010-07-14 | 2012-02-02 | Fujitsu Ltd | System and method for comparison of software framework |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2016038741A1 (en) * | 2014-09-12 | 2016-03-17 | 株式会社日立製作所 | Source code equivalence verifying device, and source code equivalence verifying method |
JPWO2016038741A1 (en) * | 2014-09-12 | 2017-04-27 | 株式会社日立製作所 | Source code equivalence verification apparatus and source code equivalence verification method |
WO2016174743A1 (en) * | 2015-04-28 | 2016-11-03 | 株式会社日立製作所 | Source code equivalence verification device and source code equivalence verification method |
JPWO2016174743A1 (en) * | 2015-04-28 | 2018-01-25 | 株式会社日立製作所 | Source code equivalence verification apparatus and source code equivalence verification method |
JP2019003385A (en) * | 2017-06-14 | 2019-01-10 | 富士通株式会社 | Analysis device, analysis program and analysis method |
US10628139B2 (en) | 2017-06-14 | 2020-04-21 | Fujitsu Limited | Analysis apparatus, analysis method and recording medium on which analysis program is recorded |
JP2019061587A (en) * | 2017-09-27 | 2019-04-18 | 富士通株式会社 | Analysis method, analyzer and analysis program |
JP2020038521A (en) * | 2018-09-05 | 2020-03-12 | 株式会社日立製作所 | Source code creation assisting device and source code creation assisting method |
JP2022502774A (en) * | 2018-09-28 | 2022-01-11 | ジーメンス インダストリー ソフトウェア エヌ・フェーSiemens Industry Software NV | Methods and equipment for verifying software systems |
JP7230186B2 (en) | 2018-09-28 | 2023-02-28 | シーメンス インダストリー ソフトウェア インコーポレイテッド | Method and apparatus for validating software systems |
JP2020087087A (en) * | 2018-11-28 | 2020-06-04 | 富士通株式会社 | Correction candidate specification program |
JP7116313B2 (en) | 2018-11-28 | 2022-08-10 | 富士通株式会社 | Correction candidate identification program |
Also Published As
Publication number | Publication date |
---|---|
JP5903038B2 (en) | 2016-04-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP6001791B2 (en) | Source code equivalence verification apparatus and source code equivalence verification method | |
JP5903038B2 (en) | Source code equivalence verification apparatus and source code equivalence verification method | |
Gosain et al. | Static analysis: A survey of techniques and tools | |
WO2012032890A1 (en) | Source code conversion method and source code conversion program | |
US20170315903A1 (en) | Systems and methods for analyzing violations of coding rules | |
US20130159964A1 (en) | System and method for systematic error injection in generated code | |
US10725897B2 (en) | Systems and methods for automatically parallelizing sequential code | |
US10514898B2 (en) | Method and system to develop, deploy, test, and manage platform-independent software | |
CN110989997A (en) | Formal verification method based on theorem verification | |
Sanches et al. | J-swfit: A java software fault injection tool | |
Ratiu et al. | Automated testing of DSL implementations: experiences from building mbeddr | |
Yang et al. | Specification-based test repair using a lightweight formal method | |
Baudry et al. | A software-repair robot based on continual learning | |
Schuts et al. | Large‐scale semi‐automated migration of legacy C/C++ test code | |
Teixeira et al. | EasyTest: An approach for automatic test cases generation from UML Activity Diagrams | |
JP2020129371A (en) | Automated restoration of software program | |
Kabadi et al. | The Future Can’t Help Fix The Past: Assessing Program Repair In The Wild | |
US11442845B2 (en) | Systems and methods for automatic test generation | |
Lai et al. | Defining and verifying behaviour of domain specific language with fUML | |
Ahmed et al. | An Adaptation Model for Android Application Testing with Refactoring | |
Tahat et al. | Scalable Translation Validation of Unverified Legacy OS Code | |
Cornu et al. | Casper: Debugging null dereferences with ghosts and causality traces | |
US11740895B2 (en) | Generation of software program repair explanations | |
Adesina et al. | Optimizing hierarchical, concurrent state machines in umple for model checking | |
Westerberg | Proof-producing resolution of indirect jumps in the binary intermediate representation BIR |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
RD02 | Notification of acceptance of power of attorney |
Free format text: JAPANESE INTERMEDIATE CODE: A7422 Effective date: 20140908 |
|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20150304 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20151116 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20151215 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20160104 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20160301 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20160311 |
|
R150 | Certificate of patent or registration of utility model |
Ref document number: 5903038 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R150 |
|
LAPS | Cancellation because of no payment of annual fees |