JP2022119668A - Code change method and code change program - Google Patents
Code change method and code change program Download PDFInfo
- Publication number
- JP2022119668A JP2022119668A JP2021016952A JP2021016952A JP2022119668A JP 2022119668 A JP2022119668 A JP 2022119668A JP 2021016952 A JP2021016952 A JP 2021016952A JP 2021016952 A JP2021016952 A JP 2021016952A JP 2022119668 A JP2022119668 A JP 2022119668A
- Authority
- JP
- Japan
- Prior art keywords
- node
- change
- code
- ast
- modified
- 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.)
- Pending
Links
Images
Landscapes
- Stored Programmes (AREA)
Abstract
【課題】変更対象プログラムコードのASTノードと変更後サブグラフのASTノードとの間の接続関係をパターンに基づいて決定できるコード変更方法及びプログラムを提供する。【解決手段】変更前と変更後のプログラムのプログラム依存グラフから抽出されたコード変更パターンに基づいてコード変更する方法であって、変更対象プログラムコードの抽象構文木(変更対象AST)と、変更後プログラムコードの抽象構文木(変更後AST)の夫々において、変更前サブグラフ又は変更後サブグラフのノードを有し、変更対象ASTと変更後AST間の対応付けがあるマップノードをルートノード又はリーフノードに有する変更対象誘導サブツリーと変更後誘導サブツリーを特定し、変更対象誘導サブツリーを削除した変更対象ASTに、変更後誘導サブツリーを追加し、変更後誘導サブツリー内の境界ノードを削除された変更対象AST内のノードと接続する。【選択図】図30A code modification method and program capable of determining a connection relationship between an AST node of a modification target program code and an AST node of a post-modification subgraph based on a pattern. A method for modifying code based on a code modification pattern extracted from a program dependency graph of a program before and after modification, comprising an abstract syntax tree (modified AST) of program code to be modified, and In each abstract syntax tree (post-change AST) of the program code, a map node having a node of a pre-change subgraph or a post-change subgraph and having a correspondence between the change target AST and the post-change AST is set as the root node or leaf node. Identify the modified derived subtree and the modified derived subtree, add the modified derived subtree to the modified AST from which the modified derived subtree is deleted, and add the boundary node in the modified derived subtree to the deleted modified AST node. [Selection drawing] Fig. 30
Description
本発明は、コード変更方法及びコード変更プログラムに関する。 The present invention relates to a code modification method and a code modification program.
コード変更方法及びコード変更プログラムは、プログラム開発を支援する開発支援プログラムに含まれる1つの機能である。プログラム開発では、ソースコードの複数の箇所に類似する変更が加えられることがある。例えば、ソースコード内のAPI(Application Programming Interface)のバージョンアップや変更が生じた場合、APIの利用箇所を一括で変更する、または、ソースコード内のバグを修正する場合に、同種のバグの箇所を一括で変更する、などである。 A code change method and a code change program are one function included in a development support program that supports program development. During program development, similar changes may be made to multiple locations in the source code. For example, if there is an API (Application Programming Interface) version upgrade or change in the source code, you can change the location of the API usage all at once, or fix a bug in the source code. , and so on.
このような、ソースコード内の異なる箇所に類似する変更を加えることを、システマティックエディット(Systematic edit:システマティックな編集または変更もしくは変換。)と呼ぶ。システマティックエディットは、ソースコードの開発履歴において、異なる版で同じ箇所や異なる箇所に発生することもあれば、同じ版の異なる箇所に発生することもある。 Making similar changes to different locations in the source code is called systematic edit. Systematic edits can occur at the same or different locations in different versions of the source code development history, or at different locations in the same version.
システマティックエディットで変更すべき箇所が多数ある場合、変更漏れの発生や、コード書き換えの作業コストが増大する。このような問題を解消するために、過去の開発履歴のソースコードから、システマティックエディットパターン(以下、コード変更パターン、エディットパターン、編集パターン、または単にパターンと称する。)を収集または抽出し、パターンを利用して、コード変更箇所の検出とコード変更や、類似するコード変更作業などを自動化する。このようなコード変更によりプログラム開発の支援が可能になる。 If there are many places to be changed in systematic editing, omission of changes will occur and the work cost of code rewriting will increase. In order to solve such problems, systematic editing patterns (hereinafter referred to as code change patterns, editing patterns, editing patterns, or simply patterns) are collected or extracted from the source code of the past development history, and the patterns are Use it to automate code change detection and code changes, as well as similar code change tasks. Such code changes can assist in program development.
システマティックエディットに基づく変更支援や自動修正の処理の流れは、例えば(1)ソースコードの開発履歴群からコード変更パターンをマイニングし、(2)変更対象プログラム内のコード変更パターンの適用箇所を検出し、(3)検出した適用箇所をコード変更パターンに基づいてコード変更する等である。 The process flow of change support and automatic correction based on systematic editing is, for example, (1) mining code change patterns from a group of source code development histories, and (2) detecting the application points of the code change patterns in the program to be changed. and (3) changing the code of the detected application location based on the code change pattern.
前述のコード変更パターンは、例えば、PDG(Program Dependence Graph:プログラム依存グラフ)の変化で表現される。そして、PDGの変化を表現するグラフであるチェンジグラフ(change graph)の集合から、頻出するサブグラフがコード変更パターンとしてマイニングされる。PDGの変化を表現するチェンジグラフを利用することで、プログラムの意味的な繋がりを考慮したコード変更パターンを表現でき、例えば、AST(Abstract Syntax Tree:抽象構文木)編集スクリプトを利用するより柔軟にコード変更パターンを表現できる。 The aforementioned code change pattern is represented by, for example, changes in PDG (Program Dependence Graph). Then, from a set of change graphs, which are graphs representing changes in the PDG, frequent subgraphs are mined as code change patterns. By using a change graph that expresses changes in PDG, it is possible to express code change patterns that consider the semantic connection of the program, for example, it is more flexible than using an AST (Abstract Syntax Tree) editing script. Can express code change patterns.
PDGのチェンジグラフは、例えば、(1)コード変更前後のソースプログラムをASTに変換し、(2)AST差分計算アルゴリズムによりASTのノード間の対応関係を計算し、(3)関数またはメソッドの変更前後のコードをfgPDG(fine-grained PDG:細粒度PDG)に変換し、変更前と後のfgPDGを左右に並べて表現し、(4)ASTノード間の対応関係に基づいて、変更前後のfgPDGのノード間に対応関係の情報を付与することで、生成される。 For example, the change graph of PDG is: (1) convert the source program before and after the code change into AST; Convert the code before and after to fgPDG (fine-grained PDG), express the fgPDG before and after the change side by side, and (4) based on the correspondence between AST nodes, the fgPDG before and after the change. It is generated by giving correspondence information between nodes.
開発履歴から生成された複数のチェンジグラフにおいて頻出するサブグラフがコード変更パターンとしてマイニングされる。コード変更パターンは変更前サブグラフと変更後サブグラフと両グラフのノード間の対応付け(マップ)とを有する。そして、変更対象プログラムコードのfgPDGから、コード変更パターンの変更前サブグラフと一致するサブグラフがパターン適用箇所として検出される。そして、変更対象プログラムコードのパターン適用箇所が、コード変更パターンの変更後サブグラフに変更される。このコード変更パターンを使用したコード変更が、パターンに基づくコード変更処理である。 Frequent subgraphs in multiple changegraphs generated from the development history are mined as code change patterns. A code change pattern has a pre-change subgraph, a post-change subgraph, and a correspondence (map) between nodes in both graphs. Then, from the fgPDG of the change target program code, a subgraph that matches the pre-change subgraph of the code change pattern is detected as a pattern application location. Then, the pattern application portion of the change target program code is changed to the post-change subgraph of the code change pattern. Code modification using this code modification pattern is pattern-based code modification processing.
以下の特許文献には、プログラムの編集を支援する方法について記載される。また、非特許文献にはPDGの変更としてコード変更パターンを表現することが記載されている。 The following patent documents describe methods for supporting program editing. In addition, non-patent literature describes expressing code change patterns as PDG changes.
上記のパターンに基づくコード変更処理は、fgPDGのノードレベルで行うことは困難である。fgPDGのノードはASTのノードと異なりソースコードと1対1に対応していないからである。そのため、fgPDGのノードレベルでパターンに基づくコード変更処理を行うと、変更対象プログラムコードのfgPDGノードと、コード変更パターンの変更後サブグラフのノードとを接続することが困難である。 Code changes based on the above patterns are difficult to do at the node level of fgPDG. This is because, unlike AST nodes, fgPDG nodes do not have a one-to-one correspondence with source code. Therefore, if the code change processing based on the pattern is performed at the node level of fgPDG, it is difficult to connect the fgPDG node of the program code to be changed and the node of the post-change subgraph of the code change pattern.
そこで、パターンに基づくコード変更処理は、ASTのノードレベルで行われる。しかしながら、ASTのノードレベルでのパターンに基づくコード変更処理でも、変更対象プログラムコードのASTノードと、コード変更パターンの変更後サブグラフのASTノードとの間の接続関係が決定できないことがある。 Therefore, the pattern-based code modification process is done at the node level of the AST. However, even in the code change processing based on the pattern at the node level of the AST, there are cases where the connection relationship between the AST node of the program code to be changed and the AST node of the post-change subgraph of the code change pattern cannot be determined.
そこで、本実施の形態の第1の側面の目的は、パターンに基づくコード変更処理で、変更対象プログラムコードのASTノードとコード変更パターンの変更後サブグラフのASTノードとの間の接続関係を決定できるコード変更方法及びコード変更プログラムを提供することにある。 Therefore, the purpose of the first aspect of the present embodiment is a pattern-based code change process that can determine the connection relationship between the AST node of the program code to be changed and the AST node of the post-change subgraph of the code change pattern. An object of the present invention is to provide a code change method and a code change program.
本実施の形態の第1の側面は、変更前プログラムコードと変更後プログラムコードの変更前プログラム依存グラフと変更後プログラム依存グラフから抽出された、変更前サブグラフと変更後サブグラフとを有するコード変更パターンに基づいて、変更対象プログラムコードをコード変更する方法であって、
前記変更前サブグラフと一致した前記変更対象プログラムコードの抽象構文木(以下ASTと称する。)である変更対象ASTと、前記変更後サブグラフを有する前記変更後プログラムコードのASTである変更後ASTそれぞれにおいて、
前記変更前サブグラフまたは前記変更後サブグラフのノードを有し、前記変更対象ASTと変更後AST間の対応付けがあるマップノードをルートノードまたはリーフノードに有する変更対象誘導サブツリーと変更後誘導サブツリーを特定し、
前記変更対象ASTから、前記変更対象誘導サブツリーを削除し、
前記削除された変更対象ASTに、前記変更後誘導サブツリーを追加し、
前記変更後誘導サブツリー内の境界ノードを前記削除された変更対象AST内のノードと接続する処理を有する、コード変更方法である。
A first aspect of the present embodiment is a code change pattern having pre-change sub-graphs and post-change sub-graphs extracted from pre-change program dependency graphs and post-change program dependency graphs of pre-change program code and post-change program code. A method of code-modifying program code to be modified based on
In each of the AST to be changed which is an abstract syntax tree (hereinafter referred to as AST) of the program code to be changed that matches the subgraph before change and the AST after change which is the AST of the program code after change having the subgraph after change ,
Identifying a modified derived subtree and a modified derived subtree having a node of the pre-modification subgraph or the post-modification subgraph and having, as a root node or a leaf node, a map node having a correspondence between the modification target AST and the post-modification AST. death,
deleting the modified derived subtree from the modified AST;
adding the modified derived subtree to the deleted modified AST;
A code modification method comprising a process of connecting boundary nodes in the modified derived subtree with nodes in the deleted modified AST.
第1の側面によれば、パターンに基づくコード変更処理で、変更対象プログラムコードのASTノードとコード変更パターンの変更後サブグラフのASTノードとの間の接続関係を決定できるコード変更方法及びコード変更プログラムを提供することができる。 According to the first aspect, in pattern-based code change processing, a code change method and a code change program capable of determining a connection relation between an AST node of a program code to be changed and an AST node of a post-change subgraph of a code change pattern can be provided.
以下、実施の形態についてJava言語(Javaはオラクルおよびその関連会社の登録商標)を例にして説明するが、実施の形態はJava言語に限定されるものではなく、C言語や他の言語にも適用できる。以下では、まず背景としてSystematic editとコード変更パターンをマイニングする技術について説明した後に、実施の形態におけるコード変更パターンのマイニングについて説明する。 Hereinafter, the embodiments will be described using the Java language (Java is a registered trademark of Oracle and its affiliates) as an example, but the embodiments are not limited to the Java language, and can be applied to C language and other languages. Applicable. In the following, as a background, the technique of mining systematic edit and code change patterns will be described first, and then mining of code change patterns in the embodiment will be described.
[Systematic editに基づくコード変更支援・自動修正]
図1は、システマティックエディットの一例を示す図である。図中、横軸が開発履歴の各バージョン番号v1~v3を示し、それぞれのバージョン番号v1~v3に対応するソースプログラムSP1~SP4が示される。
[Code change support/automatic correction based on systematic edit]
FIG. 1 is a diagram showing an example of systematic editing. In the figure, the horizontal axis indicates the version numbers v1 to v3 of the development history, and the source programs SP1 to SP4 corresponding to the respective version numbers v1 to v3 are indicated.
前述したとおり、プログラム開発では、ソースコードの複数の箇所に類似する変更が加えられることがある。例えば、ソースコード内のAPIのバージョンアップや変更が生じた場合、APIの利用箇所を一括で変更する、または、ソースコード内のバグを修正する場合に、同種のバグの箇所を一括で変更する、などである。このような、ソースコード内の異なる箇所に類似する変更を加えることを、システマティックエディットと呼ぶ。システマティックエディットは、ソースコードの開発履歴において、異なる版で同じ箇所または異なる箇所に発生することもあれば、同じ版の異なる箇所に発生することもある。 As mentioned above, during program development, similar changes may be made to multiple locations in the source code. For example, if the version of API in the source code is upgraded or changed, change the location where the API is used all at once, or when fixing a bug in the source code, change the location of the same type of bug all at once. , etc. Adding similar changes to different locations in the source code is called systematic editing. A systematic edit may occur at the same or different place in different versions, or at different places in the same version, in the development history of the source code.
図1において、各ソースプログラムSP1~SP4には、行頭が「-」の削除される文と、行頭が「+」の挿入される文(共に下線で示す文)とが含まれる。この例では、APIメソッドFile.read()からAPIメソッドIO.read()に変更される。このコード変更は、異なるバージョンのソースプログラムSP1~SP3内の異なる箇所で行われる。 In FIG. 1, each of the source programs SP1 to SP4 includes sentences beginning with "-" to be deleted and sentences beginning with "+" to be inserted (both underlined). In this example, API method File.read() is changed to API method IO.read(). This code change is made at different locations in the different versions of the source programs SP1-SP3.
図1の例において、コード変更パターンに基づくコード変更プログラムを実行するプロセッサが、バージョンv4のソースプログラムSP4の開発過程で、過去に開発されたソースプログラムSP1、SP2を含む開発履歴群から、APIメソッドFile.read()からAPIメソッドIO.read()に変更するというシステマティックエディットパターン(コード変更パターン)をマイニングする。そして、プロセッサが、新たに開発されるソースプログラムSP4を、マイニングされたコード変更パターンに基づいて、同様のコード変更を実行する。 In the example of FIG. 1, a processor that executes a code change program based on a code change pattern selects API method Mine the systematic edit pattern (code change pattern) of changing from File.read() to API method IO.read(). Then, the processor performs similar code changes on the newly developed source program SP4 based on the mined code change patterns.
図2は、システマティックエディットによるコード変更支援及び自動修正のフローチャートの一例を示す図である。システマティックエディット(システマティックなコード編集)は、複数の開発済みソースコードを含む開発履歴群10から、所定の頻度以上に発生したコード変更パターン11をマイニングする処理S1を有する。コード変更パターン11の例は、図1の例のAPIメソッドFile.read()からAPIメソッドIO.read()に変更するコード変更パターンである。ここでメソッドとは、JAVA(登録商標)の関数である。コード変更単位として、メソッドなどの関数を利用する。
FIG. 2 is a diagram showing an example of a flowchart of code change support and automatic correction by systematic editing. Systematic editing (systematic code editing) has a process S1 of mining
さらに、システマティックなコード変更は、変更対象プログラム12内のコード変更コード変更パターン11に合致するコード変更パターン適用箇所14を検出する処理S2と、変更対象プログラム12のコード変更パターン適用箇所14のコードをコード変更パターンに基づいてコード変更する処理S3とを有する。本実施の形態は、コード変更パターンに基づくコード変更する処理S3の改善に関する。
Furthermore, the systematic code change includes a process S2 of detecting a code change
コード変更パターンは、ソースプログラムの行またはトークン単位の変化、AST編集スクリプト、プログラム依存グラフ(PDG)の変化、などで表現される。ここで、トークンは、それ以上分解することができないプログラムの最小単位であり、プログラミングの命令文は複数のトークンによって構成される。また、AST編集スクリプトは、ソースコードの差分をAST間の差分として表現したものである。本実施の形態では、コード変更パターンとしてPDGの変化で表現するものを対象とする。PDGの変化は、プログラムの意味的なつながりを考慮した変更パターンを表現できるというメリットがあり、他の2つの表現よりもコード変更履歴内で頻出するコード変更パターンをより柔軟に表現することができる。 Code change patterns are represented by line- or token-level changes in the source program, AST editing scripts, program dependency graph (PDG) changes, and so on. Here, a token is the minimum unit of a program that cannot be further decomposed, and programming statements are composed of a plurality of tokens. Also, the AST editing script expresses the difference between source codes as the difference between ASTs. In the present embodiment, code change patterns expressed by changes in PDG are targeted. Changes in PDG have the advantage of being able to express change patterns that consider the semantic connection of programs, and can express code change patterns that occur frequently in the code change history more flexibly than the other two representations. .
図3は、PDGの変化を示すチェンジグラフからコード変更パターンをマイニングする処理のフローチャートを示す図である。チェンジグラフは、コード変更前のプログラムとコード変更後のプログラムのメソッドの差分から計算されるグラフである。コード変更パターンのマイニング処理は、開発履歴中のバージョン毎に(S10)、そして、変更されたメソッド毎に(S11)、変更されたメソッドmの変更差分からチェンジグラフCGmを計算する処理(S12)を繰り返す。そして、マイニング処理は、計算されたチェンジグラフ群から所定の頻度以上の頻出サブグラフをマイニングする(S13)。この頻出サブグラフがコード変更パターンに相当する。 FIG. 3 is a diagram showing a flowchart of processing for mining code change patterns from a change graph showing changes in PDG. A change graph is a graph calculated from differences in methods of a program before code change and a program after code change. The code change pattern mining process is for each version in the development history (S10), for each changed method (S11), and for calculating the change graph CGm from the change difference of the changed method m (S12). repeat. Then, in the mining process, frequent subgraphs with a predetermined frequency or more are mined from the calculated changegraph group (S13). This frequent subgraph corresponds to the code change pattern.
[PDGの変化としてコード変更パターンをマイニングする詳細処理]
図4は、PDGの変化としてコード変更パターンをマイニングする詳細処理のフローチャートを示す図である。図4のフローチャートは、図2のコード変更パターンのマイニング処理S1のフローチャートであり、図4中の処理S20~S23は、図3のメソッドmの変更差分からチェンジグラフCGmを計算する処理に対応する。以下、具体例を示しながら図4のフローチャートを説明する。
[Detailed processing for mining code change patterns as PDG changes]
FIG. 4 is a flowchart of detailed processing for mining code change patterns as changes in PDG. The flowchart of FIG. 4 is a flowchart of the code change pattern mining process S1 of FIG. 2, and the processes S20 to S23 in FIG. 4 correspond to the process of calculating the change graph CGm from the change difference of the method m in FIG. . Hereinafter, the flowchart of FIG. 4 will be described while showing a specific example.
図4、S20:コード変更パターンのマイニング処理では、開発履歴群10内の複数のソースコードをそれぞれASTに変換し、AST群50に蓄積する。
FIG. 4 , S20: In code change pattern mining processing, a plurality of source codes in the
図5は、ソースプログラム例に対するAST例を示す図である。ソースプログラムSP10の例は、メインメソッドm()のブロック{ }内にメソッド文send(readLines(“a.csv”))が含まれる。図5には、このソースプログラムSP10のASTの例が示される。ASTは、ソースコードをプログラミング言語で規定される構文構造に基づいて解析し、木構造に表現したものである。一般に、ASTは、ソースコード内のスペース等、プログラミング言語上意味を持たない要素が除去された状態になる。ASTの各ノードは、ソースコードの意味を持つ要素と1対1の関係を有する。 FIG. 5 is a diagram showing an example AST for an example source program. An example of the source program SP10 includes a method statement send(readLines(“a.csv”)) within the block { } of the main method m(). FIG. 5 shows an example of the AST of this source program SP10. The AST is obtained by analyzing the source code based on the syntax structure defined by the programming language and expressing it in a tree structure. In general, the AST is in a state in which elements that have no meaning in terms of programming language, such as spaces in the source code, are removed. Each node in the AST has a one-to-one relationship with a semantic element in the source code.
図5のASTの例には、各ノードの先頭に構文要素の種別の略称が示される。それぞれの略称の種別は以下の通りである。
MD: method declaration(メソッド宣言)
BLK: block(JAVAのブロック)
ES: expression statement(式の文)
MI: method invocation(メソッド呼び出し)
A: Assignment(代入)
SN: simple name(名前)
L: literal(固定値)
In the AST example of FIG. 5, the abbreviation of the syntax element type is shown at the beginning of each node. The types of abbreviations are as follows.
MD: method declaration
BLK: block (Java block)
ES: expression statement
MI: method invocation
A: Assignment
SN: simple name
L: literal (fixed value)
図5のASTには、ノードとして、上からメソッド宣言MD:m()、ブロックBLK:{…}、式の文ES:send(…)、メソッド呼び出しMI:send(…)、名前SN:send、メソッド呼び出しMI:readLines(…)、名前SN:readLines、固定値L:“a.csv”が含まれる。ノード間の矢印方向のノードは子ノード、矢印反対方向のノードは親ノードである。 In the AST of FIG. 5, as nodes, method declaration MD: m(), block BLK: {...}, expression statement ES: send(...), method call MI: send(...), name SN: send , method call MI: readLines(...), name SN: readLines, fixed value L: "a.csv". Nodes in the direction of arrows between nodes are child nodes, and nodes in the direction opposite to the arrows are parent nodes.
図4、S21:コード変更パターンのマイニング処理では、AST差分計算アルゴリズムにより、コード変更前後のAST間の対応関係51が計算される。
FIG. 4, S21: In the code change pattern mining process, an AST difference calculation algorithm calculates the
図6は、コード変更前のASTと変更後のASTと両AST間の対応関係の具体例を示す図である。コード変更前(before)のASTbは、図5と同じである。コード変更後(after)のASTaは、ASTbのソースコードが、コード差分CD1に示したように行先頭「-」の文を行先頭「+」の文に変更した変更後のソースコードのASTである。 FIG. 6 is a diagram showing a specific example of the correspondence relationship between the AST before code change, the AST after code change, and both ASTs. ASTb before the code change (before) is the same as in FIG. After the code change (after) ASTa is the AST of the source code after the source code of ASTb is changed from the sentence at the beginning of the line to the sentence at the beginning of the line, as shown in the code difference CD1. be.
AST差分計算アルゴリズムは、ノード種別の類似性、木構造の類似性等、複数の類似性基準を総合して、対応するノードの組を特定する。例えば、AST差分計算アルゴリズムは、ノード種別の類似度と木構造の類似度が共に0.7以上のノードの組に、ノード間の対応関係(map辺)を付与する。図6のノードSN:readLinesとノードSN:readCSVは、例えば、ASTのルートノード(根ノード)MD:m()からの距離が共に5、ラベル(readLine、readCSV)の文字列が類似、子ノードの数が共に0と同じ、等の類似性があるため、両ノード間に対応関係を示すmap辺が付与される。それ以外の2つのmap辺も、同等の類似性があるため付与される。AST差分計算アルゴリズムは、例えば、Diff/TSなどが知られている。 The AST difference calculation algorithm synthesizes multiple similarity criteria, such as node type similarity, tree structure similarity, etc., to identify corresponding sets of nodes. For example, the AST difference calculation algorithm assigns a correspondence relationship (map edge) between nodes to a set of nodes in which both the node type similarity and the tree structure similarity are 0.7 or higher. Node SN: readLines and node SN: readCSV in FIG. are the same as 0, a map edge indicating the correspondence between the two nodes is given. The other two map edges are also given because they are equally similar. Diff/TS, for example, is known as an AST difference calculation algorithm.
上記のとおり、AST差分計算アルゴリズムは、対応関係の基準(類似性が一定以上)を満たしたノード間にのみ対応関係を示すmap辺を付与する。 As described above, the AST difference calculation algorithm assigns map edges that indicate correspondence only between nodes that satisfy the correspondence criteria (similarity above a certain level).
図4、S22:コード変更パターンのマイニング処理では、変更前後のコードを細粒度PDG(fgPDG: fine-grained Program Dependence Graph)に変換し、fgPDG群52に蓄積する。
FIG. 4 , S22: In the mining process for code change patterns, the code before and after the change is converted into a fine-grained PDG (fgPDG: fine-grained Program Dependence Graph) and stored in the
図7は、ソースプログラムのコードから変換したfgPDGの例を示す図である。ソースプログラムSP11は、メインメソッドm()内に代入文n = graph.getName()を有する。PDGは、プログラムコード内の文(statement)や式(expression)等の要素と、要素間の依存関係をグラフ表現したものである。通常のPDGの場合、要素のノードには文や条件式が、ノード間の依存関係にはデータ依存や制御依存が、それぞれ用いられる。それに対して、細粒度PDG(fgPDG)では、ノードには文や条件式よりも単位が細かい式や演算子が用いられ、依存関係にはreceive(recv:受信)、parameter(para:パラメータ)、define(def:定義)、contorol(cont:制御)などの、データ依存や制御依存を細分化したものが用いられる。 FIG. 7 is a diagram showing an example of fgPDG converted from the code of the source program. Source program SP11 has an assignment statement n = graph.getName() in main method m(). The PDG is a graphical representation of elements such as statements and expressions in the program code and the dependencies between the elements. In the case of normal PDG, statements and conditional expressions are used for element nodes, and data dependencies and control dependencies are used for dependencies between nodes. On the other hand, in fine-grained PDG (fgPDG), expressions and operators with finer units than sentences and conditional expressions are used for nodes, and receive (recv: receive), parameter (para: parameter), Subdivided data dependence and control dependence such as define (def: definition) and control (cont: control) are used.
通常のPDGとは異なり、細粒度PDGは、データ依存や制御依存を文や条件式より細分化したコード間で表現でき、文や条件式の一部のみが変更されるようなコード変更パターンも容易に抽出できる。 Unlike normal PDG, fine-grained PDG can express data dependence and control dependence between codes that are more subdivided than statements and conditional expressions, and code change patterns where only a part of a statement or conditional expression is changed. Can be easily extracted.
図7に示したソースプログラムのコードSP11から変換されたfgPDGは、代入文n = graph.getName()を細分化したノードgraph, getName, =, n等と、ノード間のデータ依存recv、para、defを有する。 fgPDG converted from code SP11 of the source program shown in FIG. have a def.
図4、S23:コード変更パターンのマイニング処理では、変更前後のコードからそれぞれ変換した変更前後のfgPDGに、ASTノード間のmap辺を追加してチェンジグラフを生成し、チェンジグラフ群53に蓄積する。
FIG. 4, S23: In the code change pattern mining process, map edges between AST nodes are added to the fgPDG before and after the change respectively converted from the code before and after the change to generate a change graph, and the change graph is accumulated in the
図8は、チェンジグラフの例を示す図である。変更前のプログラムコードSP11とそれから変換された変更前のfgPDGbは、図7の例と同じである。一方、変更後のプログラムコードSP12は、変更前のプログラムコードSP11の代入文n = graph.getName()が、n = resolve(graph)に変更されたものである。変更前の代入文n = graph.getName()は、インスタンスgraphに対してメソッドgetName()が名前を返して、変数nに代入する命令である。一方、変更後の代入文n = resolve(graph)では、メソッドgetNameが式graphを引数(パラメータ)とする。その結果、変更後のコードに対するfgPDGaは、引数graphとメソッドgetNameとの間のデータ依存関係がパラメータparaになることが、変更前のコードに対するfgPDGbと異なる。 FIG. 8 is a diagram showing an example of a change graph. The pre-change program code SP11 and the pre-change fgPDGb converted therefrom are the same as in the example of FIG. On the other hand, in the program code SP12 after change, the assignment statement n = graph.getName() of the program code SP11 before change is changed to n = resolve(graph). The assignment statement n = graph.getName() before the change is an instruction that the method getName() returns the name for the instance graph and assigns it to the variable n. On the other hand, in the assignment statement n = resolve(graph) after the change, the method getName takes the expression graph as an argument (parameter). As a result, fgPDGa for the code after the change differs from fgPDGb for the code before the change in that the data dependency between the argument graph and the method getName becomes the parameter para.
チェンジグラフCG1は、変更前のコードに対するfgPDGbと変更後のコードに対するfgPDGaに、両fgPDGのノード間の対応関係を示すmap辺が追加されたグラフ表示である。このmap辺は、図示しない変更前コードのASTbと変更後コードのASTaについて算出したノード間の対応関係mapのうち、チェンジグラフCG1内のノード間に対応するmap辺を追加されたものである。 The change graph CG1 is a graph representation in which a map edge indicating the correspondence relationship between the nodes of fgPDGb for the code before change and fgPDGa for the code after change is added to fgPDGb for the code before change. This map edge is obtained by adding the map edge corresponding to the nodes in the change graph CG1 from the node correspondence map calculated for the pre-change code ASTb and the post-change code ASTa (not shown).
図8に示したチェンジグラフは、開発履歴群内の複数の変更前後のプログラムコードについてそれぞれ生成される。 The change graph shown in FIG. 8 is generated for each of a plurality of program codes before and after changes in the development history group.
図4、S24:コード変更パターンのマイニング処理では、チェンジグラフのPDGノード間の対応関係(map辺)に基づいて、map辺を持つPDGノードを有するサブグラフのうち、複数のチェンジグラフ内に所定の頻度以上で含まれるサブグラフを、コード変更パターンとして抽出する。この結果、単数または複数のコード変更パターン11が生成される。
Fig. 4, S24: In the code change pattern mining process, based on the correspondence (map edge) between PDG nodes in the change graph, out of the subgraphs having PDG nodes with map edges, predetermined Subgraphs that are included more than frequently are extracted as code change patterns. As a result, one or more
図9は、複数のチェンジグラフから所定の頻度以上のサブグラフをコード変更パターンとして抽出する例を示す図である。図9には、図1のバージョンv1とv2のソースプログラムSP1、SP2と、それらのソースコードの変更前後のコードに対するチェンジグラフCG11、CG12が示される。バージョンv1でのチェンジグラフCG11は、コード変更前の代入文s=File.read(“a.txt”)と、コード変更後の代入文s=IO.read(“b.txt”)に対するfgPDGbとfgPDGaと、ノード”=”間のmap辺とを有する。同様に、バージョンv2でのチェンジグラフCG12は、コード変更前の代入文u=File.read(path)と、コード変更後の代入文u=IO.read(path)に対するfgPDGbとfgPDGaと、ノード”=”間のmap辺とを有する。 FIG. 9 is a diagram showing an example of extracting subgraphs having a predetermined frequency or more from a plurality of changegraphs as code change patterns. FIG. 9 shows source programs SP1 and SP2 of versions v1 and v2 of FIG. 1, and change graphs CG11 and CG12 for the source code before and after the change. The change graph CG11 in version v1 is fgPDGb and It has fgPDGa and map edges between nodes “=”. Similarly, the change graph CG12 in version v2 is fgPDGb and fgPDGa for the assignment statement u=File.read(path) before the code change, the assignment statement u=IO.read(path) after the code change, and the node” =” with map edges between.
そして、上記2つのチェンジグラフCG11、CG12の共通する部分が頻出サブグラフ、つまりコード変更パターンPTNとして抽出される。 A common portion of the two change graphs CG11 and CG12 is extracted as a frequent subgraph, that is, a code change pattern PTN.
図2のS2、S3に示したとおり、マイニングされたコード変更パターンに基づいて、コード変更前のプログラムコード内のコード変更パターンの適用箇所の検出(S2)と、検出された適用箇所のコードをコード変更パターンに基づいてコード変更すること(S3)が行われる。 As shown in S2 and S3 in Fig. 2, based on the mined code change pattern, the application location of the code change pattern in the program code before the code change is detected (S2), and the code at the detected application location is detected. Code modification (S3) is performed based on the code modification pattern.
図10は、コード変更パターンの適用箇所の検出とコード変更の例を示す図である。図10には、図1のバージョンv4のソースプログラムSP4とコード変更パターンPTNとが示される。変更後(after)のソースプログラムSP4に示すとおり、ソースプログラムSP4内の代入文t=File.read(“b.txt”)は、バージョンv1,v2と同様の変更が必要である。 FIG. 10 is a diagram showing an example of detection of a code change pattern application location and code change. FIG. 10 shows the source program SP4 of version v4 of FIG. 1 and the code change pattern PTN. As shown in the after source program SP4, the assignment statement t=File.read(“b.txt”) in the source program SP4 needs to be changed in the same way as versions v1 and v2.
まず、コード変更前のソースプログラムSP4のコードから、コード変更パターンPTNの変更前(before)のPDGグラフと一致するコード辺t=File.read(“b.txt”)が、コード変更パターンPTNの適用箇所として検出される(S2)。次に、適用箇所のコードt=File.read(“b.txt”)が、コード変更パターンPTNの変更後(after)のPDGグラフに基づいて、コードt=IO.read(“b.txt”)に置換される。つまり、map辺が形成されているノード”=”に繋がっているノードが、”File.read”から”IO.read”に置換される。 First, from the code of the source program SP4 before the code change, the code edge t=File.read(“b.txt”) that matches the PDG graph before the change of the code change pattern PTN is It is detected as an application part (S2). Then the code t=File.read(“b.txt”) in the apply location is changed to the code t=IO.read(“b.txt” based on the PDG graph after the code change pattern PTN. ). In other words, the node connected to the node "=" where the map edge is formed is replaced from "File.read" to "IO.read".
上記のように、チェンジグラフ群からマイニングしたコード変更パターンPTNを利用して、コード未変更のプログラム内の変更漏れを検出し、自動的にコード変更を行うことができる。 As described above, by using the code change pattern PTN mined from the change graph group, it is possible to detect omission of changes in a program whose code has not been changed, and to automatically change the code.
[本実施の形態でのパターンに基づくコード変更]
図11は、本実施の形態におけるパターンに基づくコード変更を行う開発支援装置の構成例を示す図である。開発支援装置1は、サーバ、パーソナルコンピュータ、タブレット端末などである。開発支援装置1は、プロセッサ(CPU)30、メインメモリ32、ネットワークインターフェース34、バス36、及び大容量のストレージである補助記憶装置20を有する。ストレージ20には、開発支援プログラム21、開発履歴群(ソースコード群)10、コード変更パターン11、コード変更パターンによりシステマティックに変更される変更対象プログラム12、そして、変更済プログラム13がそれぞれ格納される。
[Code change based on pattern in this embodiment]
FIG. 11 is a diagram showing a configuration example of a development support device that changes code based on patterns according to the present embodiment. The
プログラム開発を支援する開発支援プログラム21は、コード変更パターンをマイニングするコード変更パターンマイニングプログラム21Aと、変更対象プログラムからコード変更パターンの変更前サブグラフと一致する箇所を検出するパターン適用箇所検出プログラム21Bと、コード変更パターンに基づいて変更対象プログラム26の一部のパターン適用箇所のコードを変更して変更済プログラム13を生成するコード変更プログラム21Cとを有する。
The
ネットワークインターフェース34は、例えばインターネットなどのネットワークNWを介して、クライアント端末装置40、42からアクセス可能である。プログラム開発の支援を受けたいユーザは、クライアント端末装置から開発支援装置1にアクセスし、コード変更パターンのマイニングと、パターン適用箇所の検出と、コード変更パターンに基づくコード変更の支援を受ける。
The
[パターン適用箇所の検出とコード変更処理]
図12は、本実施の形態におけるコード変更処理の概略フローチャートを示す図である。図2で説明したとおり、開発支援プログラムを実行するプロセッサ30は、fgPDGのチェンジグラフからマイニングしたコード変更パターン11に基づいて、変更対象プログラム12内のコード変更パターン11の変更前コードと一致するパターン適用箇所14を検出する。つまり、変更対象プログラム内のパターン適用箇所を検出する処理では、fgPDGのチェンジグラフからマイニングしたfgPDGのコード変更パターンに基づいて、変更対象プログラムのfgPDGのグラフ内において、fgPDGのコード変更パターンの変更前のfgPDGのサブグラフと一致する箇所を検出する。
[Detection of pattern application location and code change processing]
FIG. 12 is a diagram showing a schematic flowchart of code change processing according to the present embodiment. As described with reference to FIG. 2, the
次に、図12に示すとおり、プロセッサは、コード変更パターン11に基づくコード変更を実行する(S3)。このコード変更を、パターンに基づくコード変更と称する。パターンに基づくコード変更S3は、fgPDGのグラフではなく、ASTのグラフで行われる。前述したとおり、ASTはソースコードのプログラム要素と1対1に対応するノードのツリーであるので、パターン適用箇所をコード変更パターンの変更後のコードに変更する処理では、ASTのグラフで行うのが望ましい。 Next, as shown in FIG. 12, the processor executes code modification based on the code modification pattern 11 (S3). This code change is called pattern-based code change. Pattern-based code changes S3 are done in the AST graph, not in the fgPDG graph. As mentioned above, the AST is a tree of nodes that correspond one-to-one with the program elements of the source code, so in the process of changing the pattern application location to the code after changing the code change pattern, it is best to use the AST graph. desirable.
図12に示すとおり、プロセッサは、ソースコードの変更対象プログラム12を変換した変更対象プログラムのAST12_ASTと、コード変更パターン11と、パターン適用箇所14とから、変更済コードのAST13_ASTを生成する(S3)。変更済コードのAST13_ASTは、変更済のソースコードである変更済コード13に変更され、クライアント端末の画面に表示される。なお、ソースコードからASTへの変換及びASTからソースコードへの変換は、一般的なコンパイラが有する機能により行われる。
As shown in FIG. 12, the processor generates an AST 13_AST of the changed code from the AST 12_AST of the program to be changed obtained by converting the
図13は、fgPDGでのパターン適用箇所の検出とコード変更処理を説明する図である。図13中、ML、MRは、fgPDGのチェンジグラフのコード変更前と変更後のメソッドのfgPDGである。メソッドのfgPDGであるML、MR内のLとRは、コード変更パターンのコード変更前と変更後のfgPDGであり、メソッドのfgPDGの一部(サブグラフ)である。一方、MGは、変更対象プログラムのメソッドのfgPDGであり、MG内のGは、パターン適用箇所のfgPDGでありメソッドのfgPDGの一部(サブグラフ)である。また、MHは、コード変更後のメソッドのfgPDGである。ここで、LとRは、チェンジグラフの左側、右側を示す。また、GとHは、コード変更における変更前Gと変更後H(アルファベットのGの次のH)を示す。 FIG. 13 is a diagram for explaining detection of pattern application locations and code change processing in fgPDG. In FIG. 13, M L and M R are fgPDG of the method before and after the code change in the change graph of fgPDG. L and R in ML and MR, which are the fgPDG of the method, are the fgPDG before and after the code change of the code change pattern, and are a part (subgraph) of the fgPDG of the method. On the other hand, MG is the fgPDG of the method of the program to be changed, and G in MG is the fgPDG of the pattern application location and a part (subgraph) of the fgPDG of the method. Also, MH is the fgPDG of the method after the code change. Here, L and R indicate the left and right sides of the change graph. Also, G and H indicate G before change and H after change (H next to alphabet G) in code change.
図13中のパターン適用箇所の検出処理S2は、コード変更パターンのコード変更前サブグラフ(L)と、変更対象プログラムMG内のサブグラフ(G)のノード間が対応する、つまり、両サブグラフのfgPDGノードが一致したことを示す。一方、パターンに基づくコード変更処理S3は、変更対象プログラムMG内のサブグラフ(G)を削除し、代わりにコード変更パターンのコード変更後のサブグラフ(R)を追加してコード変更後のメソッドのfgPDG(MH)を生成することを示す。 In the pattern application portion detection processing S2 in FIG. 13, the nodes of the pre-code change subgraph (L) of the code change pattern and the subgraph ( G ) in the change target program MG correspond to each other. Indicates that the node was matched. On the other hand, the pattern-based code change processing S3 deletes the subgraph ( G ) in the program to be changed MG, and instead adds the subgraph (R) after code change of the code change pattern to the method after code change. Generating fgPDG(M H ).
図12で説明したとおり、コード変更処理S3はASTにより行われる。そこで、ASTにより行われるコード変更処理S3でのASTノード間の接続関係の決定の課題について具体例で説明する。 As described with reference to FIG. 12, the code change processing S3 is performed by AST. Therefore, the problem of determining the connection relationship between AST nodes in the code change processing S3 performed by the AST will be explained using a specific example.
図14は、fgPDGでのパターン適用箇所の検出処理S2の具体例を示す図である。この具体例のソースコードSCに示されるとおり、開発履歴群内の版v1とv2におけるコード変更例は次の通りである。
版v1におけるコード変更
- a = m1(p1,p2);
+ a = m2(p1,p4) + p3;
版v2におけるコード変更
- a = m1(r1,r2);
+ a = m2(r1,r4) + r3;
上記のコードの表記において、「-」は削除されたコード、「+」は追加されたコードを意味する。つまり、「-」のコードが「+」のコードに変更されたことを意味する。
FIG. 14 is a diagram showing a specific example of the pattern application location detection processing S2 in fgPDG. An example of code changes in versions v1 and v2 in the development history group is as follows, as shown in the source code SC for this example.
Code changes in version v1
- a = m1(p1,p2);
+ a = m2(p1,p4) + p3;
Code changes in version v2
- a = m1(r1,r2);
+ a = m2(r1,r4) + r3;
In the code notation above, "-" means deleted code and "+" means added code. This means that the "-" code has been changed to a "+" code.
上記のようなコード変更履歴から抽出されるコード変更パターンpatternは、従って、以下のようになる。
- a = m1( , );
+ a = m2( , ) + ;
上記のコード変更パターンに対応するfgPDGのサブグラフが、メソッドML、MR内のLとRに示される。Lが、a = m1のfgPDG、Rが、a = m2のfgPDGとなる。
The code change pattern pattern extracted from the code change history as described above is therefore as follows.
- a = m1( , );
+ a = m2( , ) + ;
Subgraphs of fgPDG corresponding to the above code change patterns are shown at L and R in methods M L , M R . L is fgPDG with a = m1, and R is fgPDG with a = m2.
一方、変更対象コードのメソッドMG内には、サブグラフL(a = m1のfgPDG)と一致するサブグラフG(a = m1のfgPDG)が含まれ、パターン適用箇所として検出される。 On the other hand, the method MG of the code to be changed includes a subgraph G (fgPDG of a=m1) that matches the subgraph L (fgPDG of a=m1), and is detected as a pattern application location.
図15は、ASTでのパターンに基づくコード変更処理S3の課題を具体例で示す図である。ASTでのパターンに基づくコード変更処理S3の処理内容は、以下の通りである。
(1)GのfgPDGノードに対応するA(G)のASTノードを、A(MG)から削除する。
(2)RのfgPDGノードに対応するA(R)のASTノードを、削除後のA(MG)に追加して、コード変更後のA(MH)を求める。
FIG. 15 is a diagram showing a specific example of the problem of the pattern-based code change processing S3 in the AST. The processing contents of the pattern-based code change processing S3 in the AST are as follows.
(1) Delete the AST node of A(G) corresponding to the fgPDG node of G from A(M G ).
(2) Add the AST node of A(R) corresponding to the fgPDG node of R to A(M G ) after deletion to obtain A(M H ) after code change.
図15のA(ML)、A(MR)はメソッドML、MRのASTであり、A(L)、A(R)はメソッド内のコード変更パターンの変更前ASTと変更後ASTである。A(MG)、A(MH)はそれぞれメソッドMG,MHのASTである。上記のコード変更処理S3の処理(2)の、変更後サブグラフRのfgPDGノードに対応するA(R)のASTノードを、削除後のA(MG)に追加してコード変更後のASTのA(MH)を求める場合、A(MH)とA(R)の境界部分で接続関係が決定できないノードがある。図中、?で示したノード間の接続関係の決定が困難なものがある。具体的には、A(R)には接続が必要な子ノード数が3個(ノード「+」に1個、ノードm2に2個)であるのに対して、A(MH)には親ノードを要求するノードがノードp1,p2の2個しかない。このようなことが生じる理由は、図14においてfgPDGのLとRとは同型であるが、図15においてASTのA(G)とA(R)とは必ずしも同じではないからである。 A(M L ) and A(M R ) in FIG. 15 are the ASTs of the methods M L and M R , and A(L) and A(R) are the AST before and after the code change pattern in the method. is. A(M G ) and A(M H ) are ASTs of methods M G and M H respectively. The AST node of A(R) corresponding to the fgPDG node of the post-change subgraph R in the process (2) of the above code change process S3 is added to A(M G ) after deletion, and the AST node after code change is When obtaining A(M H ), there are nodes whose connection relationship cannot be determined at the boundary between A(M H ) and A(R). In the figure, ? It is difficult to determine the connection relationship between nodes shown in . Specifically, A(R) has 3 child nodes that need to be connected (1 for node "+" and 2 for node m2), whereas A(M H ) has There are only two nodes p1 and p2 that require parent nodes. The reason why this happens is that in FIG. 14, L and R of fgPDG are of the same type, but in FIG. 15, A(G) and A(R) of AST are not necessarily the same.
[ASTノード間の接続関係を決定可能にするコード変更処理]
本実施の形態では、ASTによるコード変更処理において、サブツリーであるA(R)の境界部分のノードとA(MH)内のノードとの接続関係の決定を可能または容易にする。そのために、プロセッサは、コード変更処理において、A(R)とA(G)内のfgPDGノードに対応する各ASTノードから、境界部分でのノード間接続関係をより確実に決定できるような最小の誘導サブツリーを検出する。この最小の誘導サブツリーを、MIDS(Munimum Insertable/Deletable induced Subtree,挿入/削除可能な最小の誘導サブツリー)と称する。そして、プロセッサは、A(R)とA(G)に代えて、最小の誘導サブツリーMIDS(G)をA(MG)から削除し、MIDS(R)を追加してS(MH)を求める。
[Code change processing that enables determination of connection relationships between AST nodes]
In this embodiment, in the code change processing by AST, it is possible or easy to determine the connection relation between the nodes in the boundary part of A(R), which is a subtree, and the nodes in A(M H ). Therefore, in the code modification process, the processor, from each AST node corresponding to the fgPDG node in A(R) and A(G), determines the minimum node connection relation at the boundary more reliably. Detect derived subtrees. This minimal induced subtree is called MIDS (Munimum Insertable/Deletable induced Subtree). Then, instead of A(R) and A(G), the processor deletes the smallest derived subtree MIDS(G) from A(M G ) and adds MIDS(R) to obtain S(M H ). Ask.
図16は、本実施の形態におけるASTによるコード変更処理のフローチャートを示す図である。プロセッサは、パターンに基づくコード変更(S3)で、MIDSの生成(S60)を実行し、生成したMIDS(G)とMIDS(R)によりパターンに基づくコード変更を実行し(S3)、変更後のASTとしてA(MH)13_ASTを生成する。 FIG. 16 is a diagram showing a flowchart of code change processing by AST in this embodiment. The processor executes pattern-based code modification (S3), MIDS generation (S60), pattern-based code modification (S3) with the generated MIDS(G) and MIDS(R), and post-modification Generate A(M H )13_AST as AST.
MIDSの生成処理S60では、プロセッサは、(1)コード変更パターン11が抽出されたチェンジグラフCGの変更前PDG(CG_L_PDG)と変更前AST(CG_L_AST)と、(2)コード変更パターン11が抽出されチェンジグラフCGの変更後PDG(CG_R_PDG)と変更後AST(CG_R_AST)と、(3)パターン適用箇所14のPDG(14_PDG)とAST(14_AST)とから、コード変更パターンのfgPDGノードに対応するA(R)とA(G)内のASTノードに対しMIDSをそれぞれ生成する(S60)。MIDSの生成方法については後で詳述する。
In MIDS generation processing S60, the processor generates (1) pre-change PDG (CG_L_PDG) and pre-change AST (CG_L_AST) of change graph CG from which
図16において、処理S1の出力であるコード変更パターン11と、処理S2の出力であるパターン適用箇所14は、それぞれ複数存在する。更に、図9に示したとおり、コード変更パターン11が抽出された元のチェンジグラフCGも複数存在する。それに伴い、プロセッサは、パターンに基づくコード変更S3を、複数のコード変更パターン11と、複数のパターン適用箇所14と、複数のチェンジグラフCGについてそれぞれ実行する。
In FIG. 16, there are a plurality of
図17は、複数のコード変更パターンと複数のパターン適用箇所と複数のチェンジグラフについてそれぞれ実行されるパターンに基づくコード変更処理のフローチャートを示す図である。上記したとおり、プロセッサは、MIDSの生成S60を伴うパターンに基づくコード変更処理S3を、複数のコード変更パターン11毎に繰り返し(S40)、複数のパターン適用箇所14毎に繰り返し(S41)、そして、コード変更パターン11を抽出した複数のチェンジグラフCG毎に繰り返し実行する。
FIG. 17 is a flowchart of pattern-based code change processing executed for a plurality of code change patterns, a plurality of pattern application locations, and a plurality of change graphs. As described above, the processor repeats the pattern-based code modification process S3 with MIDS generation S60 for each of the plurality of code modification patterns 11 (S40), for each of the plurality of pattern application locations 14 (S41), and Repeated execution is performed for each of a plurality of change graphs CG from which the
MIDSの生成S60を伴うパターンに基づくコード変更処理S3では、プロセッサは、パターン適用箇所のPDG、ASTから誘導サブツリーMIDS(AST)を生成し(S51_1)、パターン適用箇所のAST(A(MG))から、Gの各fgPDGノードに対する誘導サブツリーMIDS(AST)を削除する(S51_2)。更に、プロセッサは、チェンジグラフの変更後のPDGとASTから誘導サブツリーMIDS(AST)を生成し(S52_1)、パターン適用箇所のAST(A(MG))に、Rの各fgPDGノードに対する誘導サブツリーMIDS(AST)を追加する(S52_2)。最後に、プロセッサは、追加したMIDS(AST)の境界ノードのAST(A(MG))のノードとの接続関係を決定し、両ノード間を接続し、変更後のAST(A(MH))を生成する(S53)。 In the pattern-based code modification process S3 with MIDS generation S60, the processor generates derived subtree MIDS (AST) from the pattern application location PDG, AST (S51_1), and the pattern application location AST (A(M G ) ), delete the derived subtree MIDS (AST) for each fgPDG node in G (S51_2). Furthermore, the processor generates an induced subtree MIDS (AST) from the PDG and AST after modification of the change graph (S52_1), and stores the induced subtree MIDS (AST) for each fgPDG node in R in the AST (A(M G )) of the pattern application location. Add MIDS (AST) (S52_2). Finally, the processor determines the connection relationship between the boundary node of the added MIDS (AST) and the node of AST (A(M G )), connects both nodes, and converts the AST (A(M H )) is generated (S53).
なお、図17のS52_1のChange graphとは、図8に示したfgPDGの変更前サブグラフと変更後サブグラフをmap辺で対応付けたものである。そして、図4で説明したとおり、fgPDGはASTから生成されるので、コード変更パターンの抽出元の複数のfgPDGのChange graphからそれぞれの変更前後のASTを取得することができる。 Note that the Change graph of S52_1 in FIG. 17 is obtained by associating the pre-change subgraph and the post-change subgraph of fgPDG shown in FIG. 8 with map edges. As described with reference to FIG. 4, since fgPDG is generated from AST, ASTs before and after each change can be obtained from Change graphs of multiple fgPDGs from which code change patterns are extracted.
[最小の誘導サブツリーMIDSの生成]
図18は、最小の誘導サブツリーMIDSの生成のフローチャートを示す図である。以下、最小の誘導サブツリーMIDSをサブツリーMIDSと略して称する。このASTノードNに対するMIDS(N)の生成のフローチャートは、サブツリーMIDSの定義S61と、MIDS(N)の生成処理S62を有する。
Generate Minimal Derived Subtree MIDS
FIG. 18 is a diagram showing a flow chart of generating a minimal induced subtree MIDS. Hereinafter, the minimum derived subtree MIDS will be abbreviated as subtree MIDS. The flow chart for generating MIDS(N) for this AST node N has subtree MIDS definition S61 and MIDS(N) generation processing S62.
ASTノードNのサブツリーMIDS(N)の定義S61は、ASTノードNを含み、条件C1-C3を全て満たす最小のASTサブツリーSTである。
条件C1は、ASTサブツリーST(MIDS)のルート(root)が、mappedノード、または、unmappedなstatementノードであること、である。
条件C2は、ASTサブツリーST(MIDS)のリーフ(reaf)が、mappedノード、または、子ノードを持たないunmappedノードであること、である。
条件C3は、A(R)のノードNのサブツリーMIDS(N)内に、mappedノードが1つ以上存在すること、である。条件C3は、ルートもリーフもunmappedノードの場合に必要な条件となる。
Definition S61 of subtree MIDS(N) of AST node N is the smallest AST subtree ST that contains AST node N and satisfies all conditions C1-C3.
Condition C1 is that the root of the AST subtree ST (MIDS) is a mapped node or an unmapped statement node.
Condition C2 is that the leaf (reaf) of the AST subtree ST (MIDS) is a mapped node or an unmapped node with no child nodes.
Condition C3 is that one or more mapped nodes exist in subtree MIDS(N) of node N of A(R). Condition C3 is a necessary condition when both root and leaf are unmapped nodes.
条件C1で、ASTサブツリーST(MIDS)のルートは、先祖側の境界のノードである。ルートがmappedノードであれば、ルートと対応付けられた(map辺でつながった)ノードがA(MG)内に存在するので、A(MG)内の対応付けられたノードの親ノードが、ASTサブツリーST(MIDS)のルートの接続先になる。また、ルートがunmappedであってもstatementの場合は、後述する制御フローを再構築することで、ルートの親ノードを検出できる場合がある。 In condition C1, the root of the AST subtree ST(MIDS) is the node of the ancestral boundary. If the root is a mapped node, the node associated with the root (connected by the map edge) exists in A(M G ), so the parent node of the mapped node in A(M G ) is , becomes the destination of the root of the AST subtree ST (MIDS). Also, even if the root is unmapped, if it is a statement, it may be possible to detect the root's parent node by reconstructing the control flow, which will be described later.
さらに、条件C2で、リーフがmappedノードであれば、リーフと対応付けられた(map辺でつながった)ノードがA(MG)内に存在するので、A(MG)内の対応付けられたノードの子ノードが、ASTサブツリーST(MIDS)のリーフの接続先になる。また、リーフが子ノードを持たないunmappedノードであれば、そのリーフに対する子ノードはA(MG)内にはないので、リーフの接続関係を決定する必要はない。 Furthermore, in condition C2, if the leaf is a mapped node, the node associated with the leaf (connected by the map edge) exists in A(M G ), so the mapped node in A(M G ) is The child nodes of the node that was created become the connection destinations of the leaves of the AST subtree ST (MIDS). Also, if a leaf is an unmapped node with no child nodes, there is no child node for that leaf in A(M G ), so there is no need to determine the connectivity of the leaf.
そして、条件C3が満たされれば、A(R)内のノードNのサブツリーMIDS(N)を、mappedノードの対応先のA(MG)内のmappedノードを手掛かりにして、サブツリーMIDS(N)の境界ノードの接続先を決定できる。 Then, if the condition C3 is satisfied, the subtree MIDS(N) of the node N in A(R) is used as a clue for the mapped node in A(MG) corresponding to the mapped node, and the subtree MIDS(N) You can decide where to connect border nodes.
mappedノードとは、対応付けを示すmap辺があるノードであり、unmappedなノードとは、map辺がないノードである。また、statementノードとは、JAVA(登録商標)の場合、BLK(Block)、ES(expression statement)、if、whileなどである。statementのより詳しい説明は、明細書の末尾にある。 A mapped node is a node with a map edge indicating correspondence, and an unmapped node is a node without a map edge. In the case of JAVA (registered trademark), statement nodes are BLK (Block), ES (expression statement), if, while, and the like. A more detailed description of the statement can be found at the end of the specification.
プロセッサは、fgPDGノードに対応するASTノードNを起点に、サブツリーMIDSの条件C1~C3が成立するまで、親ノード及び子ノードを繰り返したどり、辿ったノードを集めてサブツリーMIDS(N)を生成する(S62)。図18の下部にASTノードm2に対するサブツリーMIDS(m2)が示される。ノードm2の親ノードをたどるとmappedノード「=」に達し、ノードm2の子ノードをたどると子ノードを持たないunmappedノード「p1」「p4」に達する。また、ノード「=」の子ノードをたどるとmappedノード「a」に達し、ノード「+」の子ノードをたどると子ノードを持たないunmappedノード「p3」に達する。 Starting from the AST node N corresponding to the fgPDG node, the processor repeatedly traces parent nodes and child nodes until conditions C1 to C3 of the subtree MIDS are satisfied, collects the traced nodes, and generates a subtree MIDS(N). (S62). The subtree MIDS(m2) for AST node m2 is shown at the bottom of FIG. Tracing the parent node of the node m2 leads to the mapped node "=", and tracing the child nodes of the node m2 leads to the unmapped nodes "p1" and "p4" which have no child nodes. Further, following the child node of the node "=" leads to the mapped node "a", and following the child node of the node "+" leads to the unmapped node "p3" which has no child node.
また、図18の下部に示すASTの場合、mappedノード「=」と「a」は、条件C1~C3を満たすので、単独でサブツリーMIDSを構成する。ノード「+」のサブツリーMIDSは、ノード「m2」のサブツリーMIDSと同じである。 Also, in the case of the AST shown in the lower part of FIG. 18, the mapped nodes “=” and “a” satisfy the conditions C1 to C3, so they constitute the subtree MIDS by themselves. The subtree MIDS of node "+" is the same as the subtree MIDS of node "m2".
なお、図18に示したとおり、誘導サブツリー(MIDS)は、通常のサブツリーと異なり、誘導サブツリーMIDSのルートノードcが、ルートノードc以下の全ての子孫ノードd,eを有する必要はない。誘導サブツリーMIDSでは、ルートノードcは子孫ノードdだけを有しても良い。通常サブツリーは、ルートノードcが、ルートノードc以下の全ての子孫ノードd,eを有する。 As shown in FIG. 18, in the induced subtree (MIDS), unlike a normal subtree, the root node c of the induced subtree MIDS need not have all descendant nodes d and e below the root node c. In derived subtree MIDS, root node c may only have descendant node d. A normal subtree has a root node c with all descendant nodes d and e below the root node c.
[パターンに基づくコード変更でA(MH)を求める処理]
図19は、パターンに基づくコード変更でA(MH)を求める処理のフローチャートを示す図である。図19の処理S51、S52、S53は、図17の処理S51_1, S51_2、S52_1, S52_2、S53にそれぞれ対応する。
[Processing for obtaining A(M H ) by pattern-based code change]
FIG. 19 is a diagram showing a flow chart of processing for obtaining A(M H ) by pattern-based code modification. Processes S51, S52, and S53 in FIG. 19 correspond to processes S51_1, S51_2, S52_1, S52_2, and S53 in FIG. 17, respectively.
プロセッサは、Gの各fgPDGノードに対応する各ASTノードNGについてMIDS(NG)を求め、MIDS(NG)をA(MG)から削除する(S51)。但し、MIDS(NG)内のmappedノードは削除しないでA(MG)に残す。Gの全fgPDGノードに対して上記の削除処理が完了した後のA(MG)をAd(MG)と称する。この削除処理S51についての具体例に基づく説明を後述する。 The processor finds MIDS(N G ) for each AST node N G corresponding to each fgPDG node in G, and removes MIDS(N G ) from A(M G ) (S51). However, the mapped nodes in MIDS(N G ) are left in A(M G ) without being deleted. A(M G ) after the above deletion process is completed for all fgPDG nodes of G is called Ad(M G ). A description based on a specific example of this deletion processing S51 will be given later.
ここで、Gの各fgPDGノードに対応する各ASTノードNGについて求めた複数のMIDS(NG)には、包含関係を有する複数のMIDS(NG)が含まれ得る。その場合は最も範囲の広いMIDS(NG)をA(MG)から削除すればよい。図18に示したMIDS(m2)とMIDS(=)、MIDS(a)との関係の場合、最も広いMIDS(m2)を削除する。また、任意の2つのMIDSは、包含関係を持つか、互いに交わりを持たない独立した関係を持つかのいずれかの関係になる。交わりを持つが包含関係にないという関係は発生しない。交わりを持つとは両MIDSの一部が互いに重なることである。 Here, multiple MIDS(NG) obtained for each AST node NG corresponding to each fgPDG node of G may include multiple MIDS( NG ) having an inclusion relationship. In that case, MIDS(N G ) with the widest range should be deleted from A(M G ). In the case of the relationship between MIDS(m2), MIDS(=) and MIDS(a) shown in FIG. 18, the widest MIDS(m2) is deleted. Also, any two MIDSs have either a containment relationship or an independent relationship that does not intersect with each other. Relationships that intersect but do not contain do not occur. Intersecting means that parts of both MIDS overlap each other.
次に、プロセッサは、Rの各fgPDGノードに対応する各ASTノードNRについてMIDS(NR)を求め、MIDS(NR)をAd(MG)に追加する(S52)。このとき、Ad(MG)に削除されずに残されているmappedノードを、MIDS(NR)内の対応するmappedノードで置換する。この追加処理S52についての具体例に基づく説明も後述する。 Next, the processor finds MIDS(N R ) for each AST node N R corresponding to each fgPDG node in R and adds MIDS(N R ) to A d (M G ) (S52). At this time, the mapped nodes left undeleted in Ad(M G ) are replaced with the corresponding mapped nodes in MIDS(N R ). A description based on a specific example of this additional processing S52 will also be given later.
そして、プロセッサは、追加したMIDS(NR)について、その境界ノード(rootノード、leafノード)のAd(MG)のノードとの接続関係を決定し、ノード間を接続する(S53)。この接続関係の決定処理についての具体例に基づく説明も後述する。 Then, the processor determines the connection relationship between the boundary nodes (root node, leaf node) of the added MIDS(N R ) and the node of A d (M G ), and connects the nodes (S53). A description based on a specific example of this connection relationship determination process will also be given later.
[削除処理と追加処理の具体例]
図20は、削除処理S51の具体例に基づく説明の図である。図21は、追加処理S52の具体例に基づく説明の図である。いずれの説明も図15の具体例に基づく。
[Specific example of deletion processing and addition processing]
FIG. 20 is an explanatory diagram based on a specific example of the deletion processing S51. FIG. 21 is an explanatory diagram based on a specific example of the addition process S52. Both explanations are based on the specific example of FIG.
図20に示すとおり、プロセッサは、A(MG)からA(G)の各ASTノードNGに対するMIDS(NG)を削除して、Ad(MG)を生成する(S51)。図20に示した具体例に基いて説明すると、プロセッサは、A(G)内のノード「=」、「a」はmappedノードであるのでそれぞれMIDSの条件を満たすため、ノード「=」のみを有するMIDS(=)と、ノード「a」のみを有するMIDS(a)を生成し、A(MG)から削除する。但し、ノード「=」、「a」はmappedノードであるので、A(MG)から削除せずAd(MG)に残す(S51_a)。さらに、プロセッサは、A(G)内のノード「m1」のMIDS(m1)を図20中左下に示すとおり生成し、MIDS(m1)内のmappedノード「=」「a」以外のノード「m1」「p1」「p2」をA(MG)から削除する(S51_b)。その結果、図20中右下のAd(MG)が生成される。 As shown in FIG. 20, the processor deletes MIDS(N G ) for each AST node N G from A(M G ) to A(G) to generate A d (M G ) (S51). Based on the specific example shown in FIG. 20, since the nodes '=' and 'a' in A(G) are mapped nodes, the processor satisfies the MIDS conditions, so that only the node '=' is processed. Create MIDS(=) with and MIDS(a) with only node 'a' and delete from A(M G ). However, since the nodes “=” and “a” are mapped nodes, they are left in Ad(MG) without being deleted from A(MG) ( S51_a ). Further, the processor generates MIDS(m1) of node 'm1' in A(G) as shown in the lower left of FIG. ', 'p1' and 'p2' are deleted from A(M G ) (S51_b). As a result, A d (M G ) at the lower right in FIG. 20 is generated.
図21に示すとおり、プロセッサは、Ad(MG)にA(R)の各ASTノードNRに対するMIDS(NR)を追加して、A(MH)を生成する(S52)。図21に示した具体例に基いて説明すると、プロセッサは、A(R)内のノード「=」、「a」はmappedノードであるのでそれぞれMIDSの条件を満たすため、ノード「=」のみを有するMIDS(=)と、ノード「a」のみを有するMIDS(a)を生成し、Ad(MG)に追加する。但し、ノード「=」、「a」はmappedノードであるので、Ad(MG)内の対応するノード「=」「a」と交換する(S52_a)。更に、プロセッサは、ノード「+」のMIDS(+)とノード「m2」のMIDS(m2)を生成し、両MIDSは同じであるからMIDS(+)またはMIDS(m2)を、Ad(MG)に追加してA(MH)を生成する(S52_b)。但し、追加処理でmappedノード(「+」「a」)同士を交換する。 As shown in FIG. 21, the processor adds MIDS(N R ) for each AST node N R of A(R) to A d (M G ) to generate A(M H ) (S52). To explain based on the specific example shown in FIG. 21, since the nodes '=' and 'a' in A(R) are mapped nodes, the processor satisfies the conditions of MIDS, respectively, so that only the node '=' is processed. Create MIDS(=) with and MIDS(a) with only node 'a' and add to A d (M G ). However, since the nodes '=' and 'a' are mapped nodes, they are replaced with the corresponding nodes '=' and 'a' in A d (M G ) (S52_a). Further, the processor generates MIDS(+) of node "+" and MIDS(m2) of node "m2", and since both MIDS are the same, MIDS(+) or MIDS(m2), A d (M G ) to generate A(M H ) (S52_b). However, the mapped nodes (“+” and “a”) are exchanged in the additional processing.
図20,21の具体例では、プロセッサは、MIDS(+)とMIDS(m2)のルートノード「=」がmappedノードであるので、対応するmappedノードと置換することで、ルートノード「=」をAd(MG)内の親ノード「...」と接続する。一方、MIDS(NR)内のリーフノード「p1」「p3」「p4」が子ノードを持たないので、リーフノードの接続は発生しない。よって、上記の具体例では、境界ノードの接続関係の決定処理S53は必要ない。そこで、以下、別の具体例に基づき境界ノードの接続関係の決定処理S53について詳述する。 In the specific examples of FIGS. 20 and 21, since the root node "=" of MIDS(+) and MIDS(m2) is a mapped node, the processor replaces the root node "=" with the corresponding mapped node. Connect with the parent node "..." in Ad (MG). On the other hand, since the leaf nodes 'p1', 'p3' and 'p4' in MIDS(N R ) do not have child nodes, no leaf node connections occur. Therefore, in the above specific example, the boundary node connection relationship determination processing S53 is not necessary. Therefore, the connection relationship determination processing S53 of the boundary nodes will be described in detail below based on another specific example.
[境界ノードの接続関係の決定処理の具体例]
Ad(MG)に追加したA(R)のMIDS(NR)の境界ノードの接続関係の決定処理について、次の4種類の境界ノード別に説明する。
(a)rootノードがmappedノードの場合
この場合は、mappedノードに対応するAd(MG)内のノードの接続関係を元に決定する。
(b)rootノードがunmappedなstatementノードの場合
この場合は、後述する制御フロー再構築により接続関係を決定する。
(c)leafノードがmappedノードの場合
この場合は、mappedノードに対応するAd(MG)内のノードの接続関係を元に決定する。
(d)leafノードが子ノードを持たない場合(但し、接続関係が不要であり説明はない)
[Concrete example of determination processing of connection relationship of boundary nodes]
The process of determining the connection relation of the boundary nodes of MIDS(N R ) of A(R) added to A d (M G ) will be described for each of the following four types of boundary nodes.
(a) When the root node is a mapped node In this case, determination is made based on the connection relation of the nodes in A d (M G ) corresponding to the mapped node.
(b) When the root node is an unmapped statement node In this case, the connection relationship is determined by the later-described control flow reconstruction.
(c) When the leaf node is a mapped node In this case, determination is made based on the connection relation of the nodes in A d (M G ) corresponding to the mapped node.
(d) When the leaf node has no child nodes (however, there is no need for a connection relationship, so there is no explanation)
[(a)rootノードがmappedノードの場合]
図22は、(a)rootノードがmappedノードの場合の境界ノードの接続関係の決定処理を示す図である。図23、図24は、(a)rootノードがmappedノードの場合の境界ノードの接続関係の決定処理の2つの具体例をそれぞれ示す図である。
[(a) When the root node is a mapped node]
FIG. 22 is a diagram showing the process of determining the connection relation of boundary nodes when (a) the root node is a mapped node. FIG. 23 and FIG. 24 are diagrams respectively showing two specific examples of (a) the process of determining the connection relationship of boundary nodes when the root node is a mapped node.
図22において、(a)追加したMIDS(NR)のrootノードNrがmappedノードの場合、プロセッサは、
(a-1)Ad(MG)におけるMIDSのrootノードNrに対応するノードの親ノードを、A(MH)でもrootノードNrの親ノードとするよう接続する。
(a-2)Ad(MG)においてMIDSのrootノードNrに対応するノードに子ノードNcが存在する場合、A(MH)において、rootノードNrの子にNcを追加できるなら、NcをNrの子ノードとして追加するよう接続する。追加できないなら、Nc以下のノードをrootノードNrの子ノードで上書きするか、コード変更不可として処理を終了する(S53_1)。
In FIG. 22, (a) when the root node N r of the added MIDS(N R ) is a mapped node, the processor:
(a-1) Connect the parent node of the node corresponding to the MIDS root node N r in A d (M G ) to be the parent node of the root node N r in A(M H ) as well.
(a-2) If the node corresponding to the root node N r of MIDS has a child node N c in A d (M G ), add N c to the child of the root node N r in A(M H ). If possible, connect to add N c as a child node of N r . If it cannot be added, the nodes below Nc are overwritten with the child nodes of the root node Nr, or the code cannot be changed, and the process ends ( S53_1 ).
図23の具体例S53_1(1)では、コード変更パターンpatternは、変更前がif( ){ }であり、変更後がif( ){m1(); m2(p1,p2);}である。この場合、プロセッサは、図示しないMIDS(NG)(「if」のみを含む)が削除され但しmappedノード「if」が残されたAd(MG)に、図示されるMIDS(NR)を追加して、A(MH)を生成する。 In the specific example S53_1(1) of FIG. 23, the code change pattern pattern is if( ){ } before change and if( ){m1(); m2(p1,p2);} after change. In this case, the processor replaces the MIDS(N R ) shown in A d (M G ) with the MIDS(N G ) (containing only 'if') (not shown) removed but the mapped node 'if' left. to generate A(M H ).
この具体例では、プロセッサは、MIDS(N-R)のrootノード「if」について、以下の接続関係を決定する。
(a-1)MIDS(N-R)のrootノードNr「if」の親ノードは、rootノード「if」に対応するAd(M-G)内のノード「if」の親ノード「while」とする。
(a-2)MIDS(N-R)のrootノードNr「if」の子ノードは次の通りである。MIDS(N-R)のrootノードNr「if」に対応するAd(M-G)内のノード「if」に子ノードNc「cond」が存在し、MIDS(NR)のrootノード「if」の子ノードに文「BLK」があるが条件ノードが存在しないため、Ad(M-G)内の子ノード「cond」をrootノードNr「if」の子ノードとして追加する。
In this specific example, the processor determines the following connection relations for the root node “if” of MIDS(N −R ).
(a-1) The parent node of root node N r 'if' of MIDS (N- R ) is the parent node 'while ”.
(a-2) Child nodes of the root node N r "if" of MIDS(N- R ) are as follows. The node 'if' in A d (M -G ) corresponding to the root node N r 'if' of MIDS(N -R ) has a child node N c 'cond', and the root node of MIDS(N R ) Add the child node 'cond' in A d (M −G ) as a child node of the root node N r 'if' because the child node of 'if' has the sentence 'BLK' but no condition node.
図24の具体例S53_1(2)では、コード変更パターンpatternなどは図23と同じである。しかし、MIDS(N-R)のrootノードNr「if」に対応するAd(M-G)内のノード「if」に子ノード「cond」が存在し、一方、MIDS(NR)のrootノードNr「if」の子ノードに文「BLK」と条件ノード「cond2」が存在する。この場合は、プロセッサは、MIDS(N-R)のrootノードNr「if」について、以下の接続関係を決定する。
(a-1)図23と同じ
(a-2)図22の追加できない場合に該当し、Ad(MG)のNc以下のノード「cond」をMIDS(NR)内のrootノードNr「if」の子ノード「cond2」で上書きする。もしくは、コード変更不可のコメントを出力する。
In the specific example S53_1(2) in FIG. 24, the code change pattern pattern and the like are the same as in FIG. However, there is a child node 'cond' in node 'if' in A d (M -G ) corresponding to root node N r 'if' in MIDS( N -R ), while The child node of the root node N r "if" is the sentence "BLK" and the conditional node "cond2". In this case, the processor determines the following connection relation for the root node N r "if" of MIDS(N -R ).
(a-1) Same as FIG . 23 (a- 2 ) Corresponds to the case where addition is not possible in FIG. r Overwrite with child node "cond2" of "if". Alternatively, output a comment that cannot be changed.
[(b)rootノードがunmappedなstatementノードの場合]
図25は、(b)rootノードがunmappedなstatementノードの場合の境界ノードの接続関係の決定処理を示す図である。図26は、(b)rootノードがunmappedなstatementノードの場合の境界ノードの接続関係の決定処理の具体例を示す図である。
[(b) When the root node is an unmapped statement node]
FIG. 25 is a diagram showing the process of determining the connection relation of boundary nodes when the root node is an unmapped statement node (b). FIG. 26 is a diagram showing a specific example of the connection relationship determination processing of boundary nodes when the root node is an unmapped statement node (b).
図25において、(b)追加したMIDS(NR)のrootノードNrがunmappedなstatementノードの場合、プロセッサは、以下のように、制御フローを再構築する。
(b-1) MIDS(NR)においてrootノードNr の子孫の mapped ノードを Nm とする。
(b-2) Ad(MG) において、MIDS(NR)のmappedノードNm に対応するmappedノードNm_1から一番近い祖先の制御ノードをNacとする。ここで、
・制御ノードとは、ブロックノード、もしくは、if, while, do 等の条件分岐・繰り返しを表現するノード、を指す。
・MIDS(NG)を削除したことでAd(MG)を辿れない場合は、A(MG)を辿って上記条件を満たす制御ノードをNacと特定する。
(b-3) A(MH) において制御ノードNac の子ノードとして rootノードNr を追加するように接続する(S53_2)。
In FIG. 25, (b) when the root node N r of the added MIDS(N R ) is an unmapped statement node, the processor reconstructs the control flow as follows.
(b-1) In MIDS(N R ), let N m be a mapped node that is a descendant of the root node N r .
(b-2) In A d (M G ), let N ac be the closest ancestor control node from the mapped node N m — 1 corresponding to the mapped node N m of MIDS(N R ). here,
・Control nodes refer to block nodes or nodes that express conditional branching/repetition such as if, while, and do.
If A d (M G ) cannot be traced due to deletion of MIDS(N G ), A(M G ) is traced to identify the control node that satisfies the above conditions as N ac .
(b-3) A(M H ) is connected so as to add the root node N r as a child node of the control node N ac (S53_2).
但し、(b-1) で、Nmが複数存在する場合、Nr に一番近いノードをNmに選び、制御フロー再構築を行う。Ad(MG) における Nm から Nacまでの親子関係は、A(MH) では無視する (親子関係を作らない)(S53_2)。 However, in (b-1), if there are multiple N m , the node closest to N r is selected as N m and the control flow is reconstructed. The parent-child relationship from N m to N ac in A d (M G ) is ignored in A(M H ) (no parent-child relationship is created) (S53_2).
上記の制御フローを再構築する処理では、プロセッサは、MIDS(NR)においてrootノードNr の子孫の mapped ノードを Nmを検出し、Ad(MG) においてMIDS(NR)内のmappedノードNm に対応するAd(MG)内のmappedノードNm_1から一番近い祖先ノード且つ制御ノードNacを検出し、MIDS(NR)内のrootノードNr にAd(MG)内の制御ノードNac を親ノードとして接続する。 In the process of reconstructing the above control flow, the processor detects mapped nodes N m that are descendants of the root node N r in MIDS ( N R ), and The nearest ancestor node and control node N ac is detected from the mapped node N m_1 in A d ( M G ) corresponding to the mapped node N m , and A d ( M G ) in the control node N ac as a parent node.
図26の具体例S53_2, S53_3では、コード変更パターンの変更前がm1( );で、変更後がif(cond){m1();}である。そこで、プロセッサは、MIDS(NG)(m1のみ含む)を削除しmappedノードm1を残したAd(MG)に、MIDS(NR)を追加して、A(MH)を生成する。この場合、プロセッサは、次の制御フローを再構築する処理を行う。
(b-1) MIDS(NR)において、rootノードNr 「If」の子孫の mapped ノード「m1」を Nmとする。
(b-2) MIDS(NR)内のmapped ノードNm「m1」に対応するAd(MG)内のmappedノードNm_1 「m1」から一番近い祖先の制御ノード「while」をNacとする。
(b-3) A(MH) においてNac「while」の子ノードとして MIDS(NR)内のroot ノードNr「If」を追加するように接続する。但し、Ad(MG) 内のmappedノードNm 「m1」から 制御ノードNac 「while」までの親子関係は、A(MH) では無視する。
In specific examples S53_2 and S53_3 in FIG. 26, the code change pattern is m1( ); before change and if(cond){m1();} after change. Therefore, the processor adds MIDS(N R ) to A d (M G ), which deletes MIDS(N G ) (including only m1) and leaves the mapped node m1, to generate A(M H ). . In this case, the processor performs processing to reconstruct the next control flow.
(b-1) In MIDS(N R ), let N m be the mapped node “m1” descendant of the root node N r “If”.
(b-2) Mapped node N m_1 in A d ( M G ) corresponding to mapped node N m 'm1' in MIDS(N R ). Let it be Nac .
(b-3) Connect so as to add the root node N r 'If' in MIDS(N R ) as a child node of N ac 'while' in A(M H ). However, the parent-child relationship from the mapped node N m 'm1' in A d (M G ) to the control node N ac 'while' is ignored in A(M H ).
[(c)leafノードがmappedノードの場合]
図27は、(c)leafノードがmappedノードの場合の境界ノードの接続関係の決定処理を示す図である。図28、図29、図30は、(c)leafノードがmappedノードの場合の境界ノードの接続関係の決定処理の具体例を示す図である。前述したとおり、MIDSは、誘導サブツリーであるので、通常のサブツリーとは異なり、MIDSのleafノードに、Ad(MG)内のノードが子ノードとして接続する可能性がある。そのため、(c)のleafノードがmappedノードの場合の接続関係の決定処理を考慮する必要がある。
[(c) When the leaf node is a mapped node]
FIG. 27 is a diagram showing the process of determining the connection relation of boundary nodes when (c) the leaf node is a mapped node. 28, 29, and 30 are diagrams showing specific examples of the process of determining the connection relation of boundary nodes when (c) the leaf node is a mapped node. As described above, MIDS is an induction subtree, so unlike normal subtrees, a node in A d (M G ) may connect to a leaf node of MIDS as a child node. Therefore, it is necessary to consider the connection relationship determination process when the leaf node in (c) is a mapped node.
図27において、(c)追加したMIDS(NR)のleafノードNl が mapped ノードの場合、プロセッサは、以下の処理を実行する。
(c-1) MIDS(NR)のleafノードNl に対応するAd(MG) 内のmappedノードの子ノードを、 A(MH) においても leafノードNl の子ノードとするように、leafノードNl を接続する。
(c-2) 以下の条件を満たす場合、 A(MH) における leafノードNl を、A(MG) におけるleafノードNl のmappedノードNl_1の修飾名 (修飾子+単純名) ノード群で置換する。
・条件: A(MG) においてleafノードNl のmappedノードNl_1が修飾子 (qualifier、連続可) の子ノードである。
(c-3)(c-2)の条件以外の場合、A(MH) へ、Ad(MG) における “Nl_1” と “Nl_1 の親” の関係を明示的に反映する必要はない( MIDS(NR)のleafノードNl がAd(MG) の“Nl_1” と交換され、root ノード Nr はその接続関係決定処理にて親子関係が追加されるため、 ここでは何もする必要無し)。
In FIG. 27, when the leaf node Nl of (c) added MIDS (N R ) is a mapped node, the processor performs the following processing.
(c-1) Make the child node of the mapped node in A d (M G ) corresponding to leaf node N l in MIDS(N R ) the child node of leaf node N l in A(M H ) as well. , connect the leaf node Nl .
(c-2) If the following conditions are satisfied, the leaf node N l in A(M H ) is a qualified name (qualifier + simple name) of the mapped node N l _1 of the leaf node N l in A(M G ) Replace with a group of nodes.
- Condition: In A(M G ), the mapped node N l _1 of the leaf node N l is a child node of the qualifier (continuity possible).
(c-3) Except for condition (c-2), explicitly reflect the relationship between “N l _1” and “parent of N l _1” in A d (M G ) to A(M H ) (The leaf node N l of MIDS(N R ) is exchanged with “N l_1 ” of A d (M G ), and the parent-child relationship is added to the root node N r in the connection relationship determination process. (so you don't need to do anything here).
図28の具体例S53_4(c-1)では、コード変更パターンの変更前がif (cond) {m1( );}で、変更後がdo if(cond){m1();}である。そこで、プロセッサは、A(MG)からMIDS(NG)「If」を削除しそのmappedノード「If」を残したAd(MG)に、MIDS(NR)1を追加して、A(MH)を生成する。この場合、プロセッサは、図30のS53_4(c-1)に示した次の処理を行う。
MIDS(NR)1 の leafノードであるノード「If」について、
・MIDS(NR)1 のleafノード「If」に対応するAd(MG) のノード「If」の子ノード BLK, cond を、A(MH) においてもleafノード「If」の子ノードとするよう接続。
・Ad(MG) での親ノードWhile は、root ノードの接続関係決定方法の制御フロー再構築により、A(MH) では MIDS(NR)1 の rootノード「Do」の親ノードとなるよう接続する。
In the specific example S53_4(c-1) of FIG. 28, the code change pattern is if (cond) {m1( );} before change and do if(cond){m1();} after change. Therefore, the processor deletes MIDS(N G ) 'If' from A(M G ) and adds MIDS(N R )1 to A d (M G ) that leaves the mapped node 'If', Generate A(M H ). In this case, the processor performs the next processing shown in S53_4(c-1) of FIG.
For the node "If" which is a leaf node of MIDS(N R )1,
・The child node BLK, cond of the node "If" in A d (M G ) corresponding to the leaf node "If" in MIDS(N R )1 is also a child node of the leaf node "If" in A(M H ) and so on.
・The parent node While in A d (M G ) is the parent node of the root node “Do” in MIDS(N R )1 in A(M H ) by reconstructing the control flow of the connection relationship determination method of the root node. connect as much as possible.
図29の具体例S53_4(c-2)では、コード変更パターンの変更前がif (cond) {m2(p2);}で、変更後がif(cond){m3(p2);}である。そこで、プロセッサは、A(MG)からMIDS(NG)「ES~p1」を削除しmappedノード「p1」を残したAd(MG)に、MIDS(NR)2を追加して、A(MH)を生成する。この場合、プロセッサは、図30のS53_4(c-2)に示した次の処理を行う。
MIDS(NR)2の leafノードNl「p2」について、
A(MG) でのMIDS(NR)2の leafノードNl「p2」に対応するノードNl _1「p1」の親ノードは qualifier である。そのため、A(MH) では、MIDS(NR)2の leafノードNl「p2」を、A(MG) のノードNl _1「p1」の修飾名ノード群 (qualifier + qualifier + p1) で置換するよう接続する。
In the specific example S53_4(c-2) of FIG. 29, the code change pattern is if (cond) {m2(p2);} before change and if(cond){m3(p2);} after change. Therefore, the processor deletes MIDS(N G ) 'ES~p1' from A(M G ) and adds MIDS(N R )2 to A d (M G ) which leaves the mapped node 'p1'. , A(M H ). In this case, the processor performs the next processing shown in S53_4(c-2) of FIG.
For leaf node N l 'p2' of MIDS(N R )2,
The parent node of node N l — 1 'p1' corresponding to leaf node N l 'p2' of MIDS(N R )2 in A(M G ) is qualifier. Therefore, in A(M H ), let leaf node N l ``p2'' of MIDS(N R )2 be the qualified name node group (qualifier + qualifier + p1) of node N l _1 ``p1'' of A(M G ) Connect to replace with .
JAVA(登録商標)では、qualifier + qualifier + p1と、qualifier + qualifier + p2とは異なるメソッド呼び出しを意味するので、A(MG)でのqualifier + qualifier + p1を維持する。 In JAVA, qualifier + qualifier + p1 means a different method call than qualifier + qualifier + p2, so we keep qualifier + qualifier + p1 in A(M G ).
なお、この例では、プロセッサは、MIDS(NR)2のルートノードNrについては、制御フロー再構築処理(b-3)により、A(MH)の制御ノード「BLK」を親ノードとして接続する。但し、Ad(MG)のleafノードNl_1「p1」からNACの「BLK」に辿れないので、A (MG)のleafノードNl_1「p1」からNACの「BLK」に辿り検出する。図25のS53_2の(b-2)に記載した通りである。 In this example, the processor connects the control node "BLK" of A(M H ) as a parent node to the root node Nr of MIDS(N R )2 by the control flow reconstruction processing (b-3). do. However, since leaf node N l_1 “p1” of A d (M G ) cannot be traced to “BLK” of N AC , leaf node N l_1 “p1” of A (M G ) to “BLK” of N AC to detect. It is as described in (b-2) of S53_2 in FIG.
以上説明したとおり、本実施の形態によれば、コード変更パターンによるコード変更で、fgPDGのコード変更パターンの変更前fgPDGサブグラフに対応する変更前AST(A(G))と、変更後fgPDGサブグラフに対応する変更後AST(A(R))とから、誘導サブツリーMIDS(NG)とMIDS(NR)を生成し、MIDS(NG)とMIDS(NR)を使用して変更前AST(A(MG))を変更後AST(A(MH))にコード変更する。MIDS(NG)とMIDS(NR)を使用することにより、コード変更でのノードの接続関係を検出可能になる。 As described above, according to the present embodiment, in code change by a code change pattern, the pre-change AST (A(G)) corresponding to the pre-change fgPDG subgraph of the code change pattern of fgPDG and the post-change fgPDG subgraph. Generate induced subtrees MIDS(N G ) and MIDS(N R ) from the corresponding modified AST (A(R)), and use MIDS(N G ) and MIDS(N R ) to generate the unmodified AST ( A(M G )) is changed to AST(A(M H )). By using MIDS(N G ) and MIDS(N R ), it becomes possible to detect the connection relation of nodes in code modification.
図31は、本実施の形態におけるシステマティックエディットを行う開発支援装置1のユーザ画面例を示す図である。既に、開発履歴群10からコード変更パターンのマイニングが完了し、コード変更パターン群がストレージに格納された状態である。このような状態で、ユーザがクライアント端末装置40から開発支援装置1にアクセスし、開発支援プログラムを実行するときのクライアント端末の画面である。
FIG. 31 is a diagram showing an example of a user screen of the
画面S70で、ユーザが、システマティックエディットを行うために、編集対象プログラムコードのファイルとして「Ana.java」を選択すると、変更対象プログラムコード内のあるメソッド「void anaFunc(Arg arg)」のコードが表示される。そして、ユーザが、編集対象プログラムコードとマッチするコード変更パターンの検索を要求するサーチボタン「search」をクリックする。 On the screen S70, when the user selects "Ana.java" as the file of the program code to be edited in order to perform systematic editing, the code of a method "void anaFunc(Arg arg)" in the program code to be changed is displayed. be done. The user then clicks on the search button "search" which requests a search for code change patterns that match the program code to be edited.
画面S71で、サーチボタンのクリックに応答して、プロセッサが、コード変更パターン群ないの各パターンについて検索し、マッチした3つのコード変更パターン「Pattern title 1」~「Pattern title 3」を検出し、表示する。そして、「Pattern title 1」にマッチした「Ana.java」を選択すると、プロセッサが、右側の画面に、コード変更前のコード(左側)とコード変更後のコード(右側)を表示して提案し、両コードの変更箇所をハイライト表示する。
In screen S71, in response to clicking the search button, the processor searches for each pattern in the code change pattern group and detects three matched code change patterns "
ユーザが、両コードの変更箇所のコード変更をチェックし、コード変更を承認する場合にアクセプトボタン「Accept」をクリックすると、プロセッサが提案したコード変更を自動で行う。 When the user checks the code changes in both code changes and clicks the accept button "Accept" to approve the code changes, the processor automatically makes the proposed code changes.
[JAVA(登録商標)のStatement, Expression等]
以下、JAVA(登録商標)のStatement、Expression、上記を除いたAST要素の例は、以下の通りである。制御ノードには下線を付した。
[JAVA (registered trademark) statements, expressions, etc.]
Examples of JAVA (registered trademark) statements, expressions, and AST elements excluding the above are as follows. Control nodes are underlined.
Statement
AssertStatement, Block, BreakStatement, ConstructorInvocation, ContinueStatement, DoStatement, EmptyStatement, EnhancedForStatement, ExpressionStatement, ForStatement, IfStatement, LabeledStatement, ReturnStatement, SuperConstructorInvocation, SwitchCase, SwitchStatement, SynchronizedStatement, ThrowStatement, TryStatement, TypeDeclarationStatement, VariableDeclarationStatement, WhileStatement
Expression
Annotation, ArrayAccess, ArrayCreation, ArrayInitializer, Assignment, BooleanLiteral, CastExpression, CharacterLiteral, ClassInstanceCreation, ConditionalExpression, FieldAccess, InfixExpression, InstanceofExpression, LambdaExpression, MethodInvocation, MethodReference, Name, NullLiteral, NumberLiteral, ParenthesizedExpression, PostfixExpression, PrefixExpression, StringLiteral, SuperFieldAccess, SuperMethodInvocation, ThisExpression, TypeLiteral, VariableDeclarationExpression
上記を除いたAST要素
AnonymousClassDeclaration, BodyDeclaration, CatchClause, Comment, CompilationUnit, Dimension, ImportDeclaration, MemberRef, MemberValuePair, MethodRef, MethodRefParameter, Modifier, ModuleDeclaration, ModuleDirective, ModuleModifier, PackageDeclaration, TagElement, TextElement, Type, TypeParameter, VariableDeclaration
statement
AssertStatement, Block , BreakStatement, ConstructorInvocation, ContinueStatement, DoStatement , EmptyStatement, EnhancedForStatement , ExpressionStatement, ForStatement , IfStatement , LabeledStatement, ReturnStatement, SuperConstructorInvocation, SwitchCase, SwitchStatement , SynchronizedStatement , ThrowStatement, TryStatement , TypeDeclarationStatement, VariableDeclarationStatement, WhileStatement
expression
Annotation, ArrayAccess, ArrayCreation, ArrayInitializer, Assignment, BooleanLiteral, CastExpression, CharacterLiteral, ClassInstanceCreation, ConditionalExpression, FieldAccess, InfixExpression, InstanceofExpression, LambdaExpression, MethodInvocation, MethodReference, Name, NullLiteral, NumberLiteral, ParenthesizedExpression, PostfixExpression, PrefixExpression, StringLiteral, SuperFieldAccess, SuperMethodInvocation, ThisExpression, TypeLiteral, VariableDeclarationExpression
AST elements excluding the above
AnonymousClassDeclaration, BodyDeclaration, CatchClause , Comment, CompilationUnit, Dimension, ImportDeclaration, MemberRef, MemberValuePair, MethodRef, MethodRefParameter, Modifier, ModuleDeclaration, ModuleDirective, ModuleModifier, PackageDeclaration, TagElement, TextElement, Type, TypeParameter, VariableDeclaration
1:開発支援装置
10:開発履歴群
11:コード変更パターン群
12:変更対象プログラム
13:変更済プログラム
21:開発支援プログラム
21A:コード変更パターンマイニングプログラム
21B:パターン適用箇所検出プログラム
21C:コード変更プログラム
S1:パターンマイニング処理
S2:パターン適用箇所検出処理
S3:パターンに基づくコード変更
A(ML):変更前プログラムコード
A(MR):変更後プログラムコード
L:変更前サブグラフ
R:変更後サブグラフ
A(MG):変更対象AST
A(MR):変更後AST
MIDS(NG):変更対象誘導サブツリー
MIDS(NR):変更後誘導サブツリー
1: Development support device 10: Development history group 11: Code change pattern group 12: Change target program 13: Changed program 21:
A(M L ): Program code before change
A(M R ): Changed program code
L: Subgraph before change
R: Subgraph after change
A(M G ): AST to be changed
A(M R ): AST after change
MIDS(N G ): Induction subtree to be modified
MIDS(N R ): modified derived subtree
Claims (7)
前記変更前サブグラフと一致した前記変更対象プログラムコードの抽象構文木(以下ASTと称する。)である変更対象ASTと、前記変更後サブグラフを有する前記変更後プログラムコードのASTである変更後ASTそれぞれにおいて、
前記変更前サブグラフまたは前記変更後サブグラフのノードを有し、前記変更対象ASTと変更後AST間の対応付けがあるマップノードをルートノードまたはリーフノードに有する変更対象誘導サブツリーと変更後誘導サブツリーを特定し、
前記変更対象ASTから、前記変更対象誘導サブツリーを削除し、
前記削除された変更対象ASTに、前記変更後誘導サブツリーを追加し、
前記変更後誘導サブツリー内の境界ノードを前記削除された変更対象AST内のノードと接続する処理を有する、コード変更方法。 Code change of program code to be changed based on a code change pattern having a pre-change subgraph and a post-change subgraph extracted from the pre-change program dependency graph and the post-change program dependency graph of the pre-change program code and the post-change program code a method for
In each of the AST to be changed which is an abstract syntax tree (hereinafter referred to as AST) of the program code to be changed that matches the subgraph before change and the AST after change which is the AST of the program code after change having the subgraph after change ,
Identifying a modified derived subtree and a modified derived subtree having a node of the pre-modification subgraph or the post-modification subgraph and having, as a root node or a leaf node, a map node having a correspondence between the modification target AST and the post-modification AST. death,
deleting the modified derived subtree from the modified AST;
adding the modified derived subtree to the deleted modified AST;
A code modification method, comprising connecting boundary nodes in the modified derived subtree with nodes in the deleted modified AST.
前記変更後誘導サブツリー内のマップ付きルートノードを、前記変更対象AST内のノードであって前記変更対象誘導サブツリー内のマップ付きルートノードの親ノードに接続する処理を有する、請求項1に記載のコード変更方法。 The connecting process includes:
2. The method according to claim 1, comprising a process of connecting a root node with a map in the derived subtree after modification to a parent node of a root node with a map in the derived subtree to be modified which is a node in the AST to be modified. How to change code.
前記変更後誘導サブツリー内のマップ付きルートノードを、前記変更対象AST内のノードであって前記変更対象誘導サブツリー内のマップ付きルートノードの子ノードに接続する処理を有する、請求項2に記載のコード変更方法。 The connecting process includes:
3. The method according to claim 2, comprising a process of connecting a root node with a map in the derived subtree after modification to a child node of a root node with a map in the derived subtree to be modified which is a node in the AST to be modified. How to change code.
前記変更後誘導サブツリー内のマップ付きリーフノードを、前記変更対象AST内のノードであって前記変更対象誘導サブツリー内のマップ付きリーフノードの子ノードに接続する処理を有する、請求項1または2に記載のコード変更方法。 The connecting process includes:
3. The method according to claim 1 or 2, comprising a process of connecting a leaf node with a map in the derived subtree after modification to a child node of a leaf node with a map in the derived subtree to be modified that is a node in the AST to be modified. How to change the code as described.
前記変更後誘導サブツリー内のマップ付きリーフノードを、前記変更対象AST内のノードであって前記変更後誘導サブツリー内のマップ付きリーフノードに対応付けられたノードの修飾子と単純名を有する修飾名ノード群で、置換する処理を有する、請求項1または2に記載のコード変更方法。 The connecting process includes:
Mapped leaf nodes in the modified derived subtree are qualified names having qualifiers and simple names of nodes in the modified AST associated with mapped leaf nodes in the modified derived subtree. 3. The code modification method according to claim 1, further comprising a process of replacing in a group of nodes.
前記対応付けがないアンマップのステートメントノードをルートノードに有する変更後誘導サブツリーを特定する処理を有し、
前記接続する処理は、
前記変更後誘導サブツリー内の前記アンマップのステートメントノードの子孫の第1マップノードを特定し、
前記変更対象AST内の前記第1マップノードに対応する第2マップノードの祖先の制御ノードを特定し、
前記アンマップのステートメントノードを、前記制御ノードに接続する処理を有する、請求項1に記載のコード変更方法。 The process of identifying the post-change derived subtree includes:
identifying a modified induced subtree having an unmapped statement node with no association as a root node;
The connecting process includes:
identifying a first map node that is a descendant of the unmapped statement node in the modified derived subtree;
identifying a control node that is an ancestor of a second map node corresponding to the first map node in the AST to be modified;
2. The method of modifying code according to claim 1, comprising the step of connecting said unmapped statement nodes to said control nodes.
前記変更前サブグラフと一致した前記変更対象プログラムコードの抽象構文木(以下ASTと称する。)である変更対象ASTと、前記変更後サブグラフを有する前記変更後プログラムコードのASTである変更後ASTそれぞれにおいて、
前記変更前サブグラフまたは前記変更後サブグラフのノードを有し、前記変更対象ASTと変更後AST間の対応付けがあるマップノードをルートノードまたはリーフノードに有する変更対象誘導サブツリーと変更後誘導サブツリーを特定し、
前記変更対象ASTから、前記変更対象誘導サブツリーを削除し、
前記削除された変更対象ASTに、前記変更後誘導サブツリーを追加し、
前記変更後誘導サブツリー内の境界ノードを前記削除された変更対象AST内のノードと接続する処理をコンピュータに実行させる、コード変更プログラム。 Code change of program code to be changed based on a code change pattern having a pre-change subgraph and a post-change subgraph extracted from the pre-change program dependency graph and the post-change program dependency graph of the pre-change program code and the post-change program code a process for
In each of the AST to be changed which is an abstract syntax tree (hereinafter referred to as AST) of the program code to be changed that matches the subgraph before change and the AST after change which is the AST of the program code after change having the subgraph after change ,
Identifying a modified derived subtree and a modified derived subtree having a node of the pre-modification subgraph or the post-modification subgraph and having, as a root node or a leaf node, a map node having a correspondence between the modification target AST and the post-modification AST. death,
deleting the modified derived subtree from the modified AST;
adding the modified derived subtree to the deleted modified AST;
A code modification program that causes a computer to execute a process of connecting a boundary node in the modified derived subtree with a node in the deleted modified AST.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2021016952A JP2022119668A (en) | 2021-02-04 | 2021-02-04 | Code change method and code change program |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2021016952A JP2022119668A (en) | 2021-02-04 | 2021-02-04 | Code change method and code change program |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| JP2022119668A true JP2022119668A (en) | 2022-08-17 |
Family
ID=82848357
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP2021016952A Pending JP2022119668A (en) | 2021-02-04 | 2021-02-04 | Code change method and code change program |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP2022119668A (en) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116301775A (en) * | 2023-03-23 | 2023-06-23 | 深圳鲲云信息科技有限公司 | Code generation method, device, equipment and medium based on reset tree prototype graph |
| CN120562571A (en) * | 2025-07-30 | 2025-08-29 | 杭州未名信科科技有限公司 | Context-visualized interactive completion method and device based on large model dialogue |
-
2021
- 2021-02-04 JP JP2021016952A patent/JP2022119668A/en active Pending
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116301775A (en) * | 2023-03-23 | 2023-06-23 | 深圳鲲云信息科技有限公司 | Code generation method, device, equipment and medium based on reset tree prototype graph |
| CN120562571A (en) * | 2025-07-30 | 2025-08-29 | 杭州未名信科科技有限公司 | Context-visualized interactive completion method and device based on large model dialogue |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| JP7090778B2 (en) | Impact analysis | |
| Giese et al. | From model transformation to incremental bidirectional model synchronization | |
| US11372630B2 (en) | Efficient immutable syntax representation with incremental change | |
| JP4195479B2 (en) | Incremental generation system | |
| US7114149B2 (en) | Navigation links in generated documentation | |
| JP4619698B2 (en) | Code segment creation method and system | |
| US9182980B2 (en) | Expansion and reduction of source code for code refactoring | |
| Mayer et al. | Cross-language code analysis and refactoring | |
| CN113360156B (en) | An IOS compilation method and related equipment | |
| EP2521967A2 (en) | Creating inferred symbols from code usage | |
| US7363613B2 (en) | Program maintenance support device, program maintenance supporting method, and program for the same | |
| US8327323B2 (en) | Automatic copying by ancestor in object-oriented languages | |
| Khatchadourian et al. | [Engineering Paper] A Tool for Optimizing Java 8 Stream Software via Automated Refactoring | |
| JP2022119668A (en) | Code change method and code change program | |
| JP7522353B2 (en) | Code change pattern mining program and code change pattern mining method | |
| JP6651974B2 (en) | Information processing apparatus, compiling method and compiler program | |
| Achimugu et al. | An improved approach for generating test cases during model-based testing using tree traversal algorithm | |
| CN115373656A (en) | Page generation method and device, computer readable medium and electronic equipment | |
| Gomanyuk | An approach to creating development environments for a wide class of programming languages | |
| Aparna et al. | Building a common notation for enabling comparison of design and execution | |
| Kulagin | Research on Refactoring Methods for Ensuring Async Code in. NET Applications | |
| Einarsson | Refactoring UML diagrams and models with model-to-model transformations | |
| Copenhafer | StarTool User’s Guide | |
| HK1174708B (en) | A system and method for creating a data structure |