Search

US-12619426-B2 - Impact analysis on source code change

US12619426B2US 12619426 B2US12619426 B2US 12619426B2US-12619426-B2

Abstract

The method of this disclosure may comprise generating a statement invocation relation for a source code by parsing intermediate representation of the source code produced by a compiler. The method of this disclosure may further comprise in response to a first statement in a first code snippet of the plurality of code snippet being changed, determining affected statements in the source code due to the change of the first statement based on the statement invocation relation.

Inventors

  • Wu Song Fang
  • Xiao Ling CHEN
  • Xinzhe Wang
  • Jing Wang
  • Ting Xie
  • JI DONG LI
  • Yi Huang

Assignees

  • INTERNATIONAL BUSINESS MACHINES CORPORATION

Dates

Publication Date
20260505
Application Date
20220801

Claims (20)

  1. 1 . A computer-implemented method comprising: generating, by one or more processing units, a statement invocation relation table for a source code by parsing intermediate representation of the source code produced by a compiler, wherein the source code includes a plurality of code snippets and each of the code snippets includes a plurality of statements, and wherein for a statement in one of the plurality of code snippets, the statement invocation relation table associates the statement with invocation information of the statement indicating statements and code snippets being invoked by the statement; and in response to a first statement in a first code snippet of the plurality of code snippets being changed, determining, by the one or more processing units, affected statements in the source code due to the change of the first statement based on the statement invocation relation table, wherein the affected statements include a second statement in the first code snippet invoking the first statement and a third statement in a second code snippet invoking the first code snippet.
  2. 2 . The computer-implemented method according to claim 1 , wherein the generating the statement invocation relation table comprises: determining, by the one or more processing units, one or more instructions in the intermediate representation related to the statement in one of the plurality of code snippets; and performing, by the one or more processing units, syntactic analysis on the determined one or more instructions to obtain the invocation information of the statement, wherein the statement invocation relation table comprises: a first column indicating a changed flag, wherein the changed flag is a binary value that indicates whether a respective statement has been changed, and a second column indicating an affected flag, wherein the affected flag is a binary value that indicates whether a respective statement is affected by the first statement being changed.
  3. 3 . The computer-implemented method according to claim 1 , wherein the method further comprises: in response to the source code being updated, determining, by the one or more processing units, one or more changed statements based on the updated source code, wherein the one or more changed statements include at least one selected from a group consisting of a newly added statement, a statement invoking a deleted statement, and a statement with a changed assignment.
  4. 4 . The computer-implemented method according to claim 1 , wherein the method further comprises: generating, by the one or more processing units, a statement representation for the source code, wherein the statement representation includes a tree structure including a plurality of nodes each corresponding to a statement of the source code, and wherein a child node for one node in the tree structure corresponds to a next statement in the source code which is to be executed after a statement corresponding to the one node.
  5. 5 . The computer-implemented method according to claim 4 , wherein the generating the statement representation for the source code comprises: highlighting the nodes corresponding to at least one of the changed and affected statements based on the statement invocation relation table.
  6. 6 . The computer-implemented method according to claim 5 , wherein the method further comprises: evaluating, by the one or more processing units, an impact on the source code due to the change of the first statement, based on an impacted path breadth and an impacted path depth of the tree structure, wherein the impacted path breadth is a count of impacted paths in the tree structure, each of the impacted paths including at least one highlighted node, and the impacted path depth is a maximum depth of impacted paths in the tree structure, a depth of an impacted path being a count of nodes in the impacted path from a first highlighted node to a last highlighted node.
  7. 7 . The computer-implemented method according to claim 1 , wherein the method further comprises: in response to the first statement being changed, determining, by the one or more processing units, affected test cases for testing the source code based on the statement invocation relation table, wherein a test case invoking a second code snippet which includes the changed first statement and one or more of the affected statements is determined as an affected test case.
  8. 8 . A system comprising: a processor set; one or more computer-readable storage media; and program instructions stored on the one or more computer-readable storage media to cause the processor set to perform operations comprising: generating a statement invocation relation table for a source code by parsing intermediate representation of the source code produced by a compiler, wherein the source code includes a plurality of code snippets and each of the code snippets includes a plurality of statements, and wherein for a statement in one of the plurality of code snippets, the statement invocation relation table associates the statement with invocation information of the statement indicating statements and code snippets being invoked by the statement; and in response to a first statement in a first code snippet of the plurality of code snippets being changed, determining affected statements in the source code due to the change of the first statement based on the statement invocation relation table, wherein the affected statements include a second statement in the first code snippet invoking the first statement and a third statement in a second code snippet invoking the first code snippet.
  9. 9 . The system according to claim 8 , wherein the generating the statement invocation relation table comprises: determining one or more instructions in the intermediate representation related to the statement in one of the plurality of code snippets; and performing syntactic analysis on the determined one or more instructions to obtain the invocation information of the statement, wherein the statement invocation relation table comprises: a first column indicating a changed flag, wherein the changed flag is a binary value that indicates whether a respective statement has been changed, and a second column indicating an affected flag, wherein the affected flag is a binary value that indicates whether a respective statement is affected by the first statement being changed.
  10. 10 . The system according to claim 8 , wherein operations further comprise: in response to the source code being updated, determining one or more changed statements based on the updated source code, wherein the one or more changed statements include at least one selected from the group consisting of a newly added statement, a statement invoking a deleted statement, and a statement with a changed assignment.
  11. 11 . The system according to claim 8 , wherein the operations further comprise generating a statement representation for the source code, wherein the statement representation includes a tree structure including a plurality of nodes each corresponding to a statement of the source code, and wherein a child node for one node in the tree structure corresponds to a next statement in the source code which is to be executed after a statement corresponding to the one node.
  12. 12 . The system according to claim 11 , wherein the generating the statement representation for the source code comprises: highlighting the nodes corresponding to at least one of the changed and affected statements based on the statement invocation relation table.
  13. 13 . The system according to claim 12 , wherein the operations further comprises: evaluating an impact on the source code due to the change of the first statement, based on an impacted path breadth and an impacted path depth of the tree structure, wherein the impacted path breadth is a count of impacted paths in the tree structure, each of the impacted paths including at least one highlighted node, and the impacted path depth is a maximum depth of impacted paths in the tree structure, a depth of an impacted path being a count of nodes in the impacted path from a first highlighted node to a last highlighted node.
  14. 14 . The system according to claim 8 , wherein the operations further comprises: in response to the first statement being changed, determining affected test cases for testing the source code based on the statement invocation relation table, wherein a test case invoking a second code snippet which includes the changed first statement and one or more of the affected statements is determined as an affected test case.
  15. 15 . A computer program product comprising: one or more computer-readable storage media; and program instructions stored on the one or more computer-readable storage media to perform operations comprising: generating a statement invocation relation table for a source code by parsing intermediate representation of the source code produced by a compiler, wherein the source code includes a plurality of code snippets and each of the code snippets includes a plurality of statements, and wherein for a statement in one of the plurality of code snippets, the statement invocation relation table associates the statement with invocation information of the statement indicating at least one of statements and code snippets being invoked by the statement; and in response to a first statement in a first code snippet of the plurality of code snippets being changed, determining affected statements in the source code due to the change of the first statement based on the statement invocation relation table, wherein the affected statements include a second statement in the first code snippet invoking the first statement and a third statement in a second code snippet invoking the first code snippet.
  16. 16 . The computer program product of claim 15 , wherein the generating the statement invocation relation table comprises: determining one or more instructions in the intermediate representation related to the statement in one of the plurality of code snippets; and performing syntactic analysis on the determined one or more instructions to obtain the invocation information of the statement, wherein the statement invocation relation table comprises: a first column indicating a changed flag, wherein the changed flag is a binary value that indicates whether a respective statement has been changed, and a second column indicating an affected flag, wherein the affected flag is a binary value that indicates whether a respective statement is affected by the first statement being changed.
  17. 17 . The computer program product of claim 15 , wherein the operations further comprise: in response to the source code being updated, determining one or more changed statements based on the updated source code, wherein the one or more changed statements include at least one selected from a group consisting of a newly added statement, a statement invoking a deleted statement, and a statement with a changed assignment.
  18. 18 . The computer program product of claim 15 , wherein the operations further comprise: generating a statement representation for the source code, wherein the statement representation includes a tree structure including a plurality of nodes each corresponding to a statement of the source code, and wherein a child node for one node in the tree structure corresponds to a next statement in the source code which is to be executed after a statement corresponding to the one node.
  19. 19 . The computer program product of claim 18 , wherein the generating the statement representation for the source code comprises: highlighting the nodes corresponding to at least one of the changed and affected statements based on the statement invocation relation table.
  20. 20 . The computer program product of claim 19 , wherein the operations further comprise: evaluating an impact on the source code due to the change of the first statement, based on an impacted path breadth and an impacted path depth of the tree structure, wherein the impacted path breadth is a count of impacted paths in the tree structure, each of the impacted paths including at least one highlighted node, and the impacted path depth is a maximum depth of impacted paths in the tree structure, a depth of an impacted path being a count of nodes in the impacted path from a first highlighted node to a last highlighted node.

Description

BACKGROUND The present disclosure relates to software development, and more specifically, relates to method/system/computer program product for impact analysis on source code change. In software development, a developer or tester may add new methods to a source code or change existing methods of the source code to meet different development requirements. The addition or change may have an impact on other portions of the source code. The developer or tester may need to know the impact on source code change to continue the source code development or complete the regression test. SUMMARY According to one embodiment of the present disclosure, there is provided a computer-implemented method for impact analysis on a source code change. The method may comprise generating, by one or more processing units, a statement invocation relation for a source code by parsing intermediate representation of the source code produced by a compiler, wherein the source code includes a plurality of code snippets and each of the code snippets includes a plurality of statements, and wherein for a statement in one of the plurality of code snippets, the statement invocation relation associates the statement with invocation information of the statement indicating at least one of statements and code snippets being invoked by the statement. The method may further comprise in response to a first statement in a first code snippet of the plurality of code snippet being changed, determining, by the one or more processing units, affected statements in the source code due to the change of the first statement based on the statement invocation relation, wherein the affected statements include at least one of a second statement in the first code snippet invoking the first statement and a third statement in a second code snippet invoking the first code snippet. According to another embodiment of the present disclosure, there is provided a system for impact analysis on a source code change which may comprise one or more processors and a memory coupled to at least one of the one or more processors. The system may further comprise a set of computer program instructions stored in the memory and executed by at least one of the one or more processors in order to perform actions of generating a statement invocation relation for a source code by parsing intermediate representation of the source code produced by a compiler, wherein the source code includes a plurality of code snippets and each of the code snippets includes a plurality of statements, and wherein for a statement in one of the plurality of code snippets, the statement invocation relation associates the statement with invocation information of the statement indicating at least one of statements and code snippets being invoked by the statement; and in response to a first statement in a first code snippet of the plurality of code snippet being changed, determining affected statements in the source code due to the change of the first statement based on the statement invocation relation, wherein the affected statements include at least one of a second statement in the first code snippet invoking the first statement and a third statement in a second code snippet invoking the first code snippet. According to a further embodiment of the present disclosure, there is provided a computer program product. The computer program product may comprise a computer readable storage medium having program instructions embodied therewith. The program instructions may be executable by a device to perform a method for impact analysis on a source code change, comprising: generating a statement invocation relation for a source code by parsing intermediate representation of the source code produced by a compiler, wherein the source code includes a plurality of code snippets and each of the code snippets includes a plurality of statements, and wherein for a statement in one of the plurality of code snippets, the statement invocation relation associates the statement with invocation information of the statement indicating at least one of statements and code snippets being invoked by the statement; and in response to a first statement in a first code snippet of the plurality of code snippet being changed, determining affected statements in the source code due to the change of the first statement based on the statement invocation relation, wherein the affected statements include at least one of a second statement in the first code snippet invoking the first statement and a third statement in a second code snippet invoking the first code snippet. BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS Through the more detailed description of some embodiments of the present disclosure in the accompanying drawings, the above and other objects, features and advantages of the present disclosure will become more apparent, wherein the same reference generally refers to the same components in the embodiments of the present disclosure