Program and method for generating flowchart generation data from source code
The program simplifies complex program verification by generating flowcharts from source code, aiding in problem detection and reducing the verifier's workload.
Patent Information
- Application Number
- JP2024103370
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2026-01-15
- Estimated Expiration
- 2044-06-26
AI Technical Summary
White box testing becomes burdensome as program structures become complex, necessitating a less cumbersome verification method.
A program generates flowchart generation data by assigning line numbers, decomposing lines, identifying syntax types, determining display requirements, and specifying next execution lines to facilitate problem identification in source code.
Enables easy identification of program issues through visual flowcharts, reducing verifier burden and enhancing problem detection efficiency.
Smart Images

Figure 2026005121000001_ABST
Abstract
Description
[Technical Field]
[0001] The present invention relates to a technique for assisting in identifying problems contained in the source code of a program executed by a computer. [Background technology]
[0002] The source code of a program executed by a computer (hereinafter simply referred to as a "program") is not necessarily written to cause the computer to correctly perform the processing intended by the user, i.e., the processing in accordance with the specifications.
[0003] One method for checking whether a program is written correctly is called white box testing, which is a test that determines whether a program passes or fails by verifying whether the program's structure, logic, control flow, etc. are written as intended.
[0004] For example, Patent Document 1 is a patent document that discloses technology related to white box testing. The testing method disclosed in Patent Document 1 extracts the test target portion and its dependent portions from the main code and generates differential code based on these, allowing users to perform white box testing using only the differential code. The testing method disclosed in Patent Document 1 also stores the test results and hash values of copies of the test target portion and ensures identity with the main code based on the hash values, allowing users to confirm that testing was performed with the contents of the main code and the verification coverage of the test of the main code. [Prior art documents] [Patent documents]
[0005] [Patent Document 1] Patent Publication No. 2021-103354 Summary of the Invention [Problem to be solved by the invention]
[0006] In white box testing, the burden on the verifier increases as the program structure becomes more complex. Therefore, there is a need to reduce the burden on the verifier in white box testing, or to develop a verification method that is less burdensome than white box testing.
[0007] In view of the above, the present invention provides a technique for assisting a program verifier in identifying problems contained in source code. [Means for solving the problem]
[0008] The present invention provides a program for causing a computer to execute the following processes: assigning a first line number indicating an execution order to each of a plurality of lines constituting the source code of a program; for each of the plurality of lines constituting the source code that indicate a plurality of processes, breaking down the line into lines corresponding to each of the plurality of processes indicated by the line; for each of the plurality of lines constituting the source code, identifying a syntax type that is a type of syntax of the line; for each of the plurality of lines constituting the source code, identifying a line that should be displayed in a flowchart based on the syntax type; for each of the plurality of lines constituting the source code that should be displayed in a flowchart, identifying the first line number of a line that will be executed after the line as a second line number; and for each of the plurality of lines constituting the source code that should be displayed in a flowchart, generating data indicating the first line number of the line, the second line number of the line, and the description content of the source code of the line as data for generating a flowchart.
[0009] The present invention also provides the above-mentioned program, which causes the computer to execute a process for identifying, for each of the multiple lines constituting the source code that should be displayed in a flowchart, a display description content, which is the description content to be displayed in a flowchart, based on the description content of the source code for that line, and in the process of generating the flowchart generation data, generates, for each of the multiple lines constituting the source code that should be displayed in a flowchart, the flowchart generation data that indicates the display description content of that line instead of the description content of the source code for that line. [Effects of the Invention]
[0010] According to the present invention, a program verifier can identify problems contained in the source code by inputting flowchart generation data, which a computer generates from the source code, into a computer running a general-purpose visualization program and viewing the displayed flowchart. [Brief explanation of the drawings]
[0011] [Figure 1] FIG. 1 is a diagram showing the configuration of a computer that executes a program according to an embodiment. [Figure 2] FIG. 10 is a diagram showing the relationship between a program according to an embodiment and a general-purpose graph generation program. [Figure 3A] FIG. 2 is a diagram illustrating a source code (first half) processed according to a program according to an embodiment. [Figure 3B] FIG. 10 is a diagram illustrating a source code (second half) processed according to a program according to an embodiment. [Figure 4A] FIG. 10 is a diagram showing the state (second half) in which line numbers are assigned to source code in accordance with a program according to an embodiment. [Figure 4B] FIG. 1 is a diagram showing a state (first half) in which line numbers are assigned to source code in accordance with a program according to an embodiment. [Figure 5A]FIG. 10 is a diagram showing a state (first half) in which some lines included in source code are decomposed into multiple lines in accordance with a program according to an embodiment. [Figure 5B] FIG. 10 is a diagram showing the state (second half) in which some lines included in source code are decomposed into multiple lines in accordance with a program according to an embodiment. [Figure 6A] FIG. 10 is a diagram showing the state (first half) in which syntax types are assigned to source code in accordance with a program according to an embodiment. [Figure 6B] FIG. 10 is a diagram showing the state (second half) in which syntax types are assigned to source code in accordance with a program according to an embodiment. [Figure 7A] FIG. 10 is a diagram showing a state (first half) in which flags indicating whether a line should be displayed in a flowchart are added to source code according to a program according to an embodiment. [Figure 7B] FIG. 10 is a diagram showing a state (second half) in which flags indicating whether a line should be displayed in a flowchart are added to source code according to a program according to an embodiment. [Figure 8A] FIG. 10 is a diagram showing the state (first half) in which a next execution line number is assigned to source code according to a program according to an embodiment. [Figure 8B] FIG. 10 is a diagram showing the state (second half) in which the next execution line number is assigned to source code according to a program according to an embodiment. [Figure 9A] FIG. 10 is a diagram showing the state (first half) in which display description content is added to source code in accordance with a program according to an embodiment. [Figure 9B] FIG. 10 is a diagram showing the state (second half) in which display description content is added to source code in accordance with a program according to an embodiment. [Figure 10] FIG. 10 is a diagram showing a flowchart generated by a graph generation program using flowchart generation data generated in accordance with a program according to an embodiment. [Figure 11] FIG. 10 is a diagram illustrating another source code to which display description content and the like are added in accordance with a program according to an embodiment. [Figure 12]FIG. 12 is a diagram showing a flowchart generated by a graph generation program using the flowchart generation data included in the data of FIG. 11. [Figure 13A] A diagram showing an example of source code (first half) modified by a verifier. [Figure 13B] A diagram showing an example of source code (second half) modified by the verifier. [Figure 14] FIG. 13C is a diagram showing a flowchart generated by a graph generation program using the flowchart generation data included in the data of FIGS. 13A and 13B. [Figure 15] FIG. 10 is a diagram showing a flowchart generated by a graph generation program using flowchart generation data generated according to a program according to one modified example. DETAILED DESCRIPTION OF THE INVENTION
[0012] [Embodiment] The following describes the processing performed by a computer in accordance with a program P according to one embodiment of the present invention.
[0013] 1 shows the configuration of a computer 1 that executes a program P. The computer 1 is a data processing device that includes a processor 11 that processes data in accordance with the program, and a memory 12 that persistently stores various data including the program. The memory 12 of the computer 1 stores a program P and a program Q.
[0014] Figure 2 shows the relationship between Program P and Program Q. Program P is a program for causing Computer 1 to execute a process for generating flowchart generation data from source code. Program Q is a program for causing Computer 1 to execute a process for generating a flowchart using the flowchart generation data generated by Computer 1 in accordance with Program P. The flowchart generated by Computer 1 in accordance with Program Q is output to a display for display or output to a printer for printing, so that it can be used by a user (verifier).
[0015] Since the program Q is a general-purpose graph generation program, a detailed description of the processing executed by the computer 1 in accordance with the program Q will be omitted in this application.
[0016] Hereinafter, for convenience, when a computer performs a process according to a program, it will be described as "the program performs the process." For example, when computer 1 performs process A according to program P, it will be described as "program P performs process A."
[0017] 3A and 3B show source code S1, which is a portion of source code S as a sample for explaining the processing executed by program P. FIG. 3A shows the first half of source code S1, and FIG. 3B shows the second half of source code S1. Hereinafter, FIGS. 3A and 3B will be collectively referred to as FIG. 3. The same applies to FIGS. 4A and 4B, 5A and 5B, 6A and 6B, 7A and 7B, 8A and 8B, 9A and 9B, and 13A and 13B, which will be described later. Note that while source code S, a portion of which is shown in FIG. 3, etc., is written in COBOL, the source code used to process program P may be written in any language.
[0018] The source code S is, for example, input to the computer 1 and stored in the memory 12 .
[0019] First, the program P assigns line numbers (first line numbers) indicating the execution order to each of the multiple lines that make up the source code S. Figures 4A and 4B show the state in which the program P assigns line numbers to the source code S1.
[0020] Next, program P decomposes each line of source code S1 that indicates multiple processes into lines corresponding to the processes it indicates. Figures 5A and 5B show how program P identifies line 33 in source code S1, "PERFORM MAIN-RTN UNTIL EMPNO = 999.", as a line indicating multiple processes, and decomposes the line into three lines: "PERFORM MAIN-RTN UNTIL EMPNO = 999.", "PERFORM MAIN-RTN," and "END-PERFORM." Hereinafter, Figures 3A and 3B are collectively referred to as Figure 3. To distinguish the decomposed lines from one another, program P adds subnumbers in parentheses to the line numbers of these lines, such as 33(1).
[0021] To execute the above line decomposition process, program P has, for example, the following data (hereinafter referred to as "line decomposition rule data"): Note that "(A)" and "(B)" can be any character string.
[0022] (Before disassembly) "PERFORM (A) UNTIL (B)" (After decomposition) "PERFORM (A) UNTIL (B)", "PERFORM (A)", "END-PERFORM"
[0023] Line decomposition rule data is prepared for each language used to write source code, and program P performs the above-mentioned line decomposition process in accordance with the line decomposition rule data corresponding to the language of the source code to be processed.
[0024] Next, the program P identifies a syntax type for each of the multiple lines (after decomposition) that make up the source code S. Figures 6A and 6B show the state in which the syntax type identified by the program P has been assigned to the source code S1.
[0025] In order to execute the above-mentioned syntax type specific processing, the program P has, for example, the following data (hereinafter referred to as "syntax type rule data"): Note that any character string can be entered in "(A)".
[0026] (Source Code) "(A) SECTION." (Syntax type) "Section start"
[0027] Note that syntax type rule data is prepared for each language used to write source code, and program P performs the above-mentioned syntax type specification process in accordance with the syntax type rule data corresponding to the language of the source code to be processed.
[0028] Next, the program P identifies, based on the syntax type, lines that should be displayed in the flowchart from among the multiple lines that make up the source code S. Figures 7A and 7B show a state in which a flag (Yes or No) is assigned to the source code S1, as identified by the program P, indicating whether the line should be displayed in the flowchart.
[0029] The program P has, for example, the following data (hereinafter referred to as "display line rule data") in order to execute the above-mentioned specific processing of the lines to be displayed.
[0030] (Syntax type) "Annotation statement" (Display line) "No"
[0031] In addition, display line rule data is prepared for each language used to write source code, and program P performs the above-mentioned process of specifying the lines to be displayed in accordance with the display line rule data corresponding to the language of the source code being processed.
[0032] Next, for each line to be displayed in the flowchart among the multiple lines constituting the source code S, the program P identifies the line number (first line number) of the line to be executed next as the next execution line number (second line number). Figures 8A and 8B show the state in which the next execution line number identified by the program P has been assigned to the source code S1.
[0033] Normally, the next execution line number of a line to be displayed in a flowchart is the closest line number (first line number) to that line that is greater than the line number of the line (first line number) of the other lines to be displayed in the flowchart. For example, the next execution line number of line number 29 "MAIN SECTION." is line number 31, the closest line number (31, 32, 33(1), 33(2), 33(3), 34, 35, 37) to that line that is greater than 29.
[0034] However, for lines with syntax types such as conditional statements, the next execution line number is determined according to rules that correspond to the syntax. Also, when processing branches based on a condition, the next execution line number for that line is determined according to each of multiple cases.
[0035] For example, for line number 33(3) "END-PERFORM", "end condition false: 33(1), end condition true: 34" is specified and assigned as the next execution line number.
[0036] To execute the specific process for the next execution line number, program P has the following data (hereinafter referred to as "next execution line number rule data"), for example. Note that "(A)" and "(B)" can be any character string.
[0037] (Source code) "END-PERFORM" (Next execution line number) "Termination condition false: Line number of the previous PERFORM (A) UNTIL (B) ; Termination condition true: Line number of the next displayed line"
[0038] In addition, next execution line number rule data is prepared for each language used to write source code, and program P performs the above-mentioned process of specifying the next execution line number in accordance with the next execution line number rule data corresponding to the language of the source code being processed.
[0039] Next, for each of the lines that should be displayed in the flowchart among the multiple lines that make up the source code S, the program P specifies a display description, which is the description to be displayed in the flowchart, based on the description of the source code of that line. Figures 9A and 9B show the state in which the display description specified by the program P has been added to the source code S1.
[0040] In order to execute the above-mentioned specific processing of the description content for display, the program P has, for example, the following data (hereinafter referred to as "display description content rule data"): Note that "(A)" can be any character string.
[0041] (Source code) "DISPLAY "(A)". (Display description) "Display (A)"
[0042] Note that default display description content rule data is prepared for each language used to write source code, and the program P performs the above-mentioned specific processing of the display description content in accordance with the display description content rule data corresponding to the language of the source code to be processed. Also, data that has been modified by the user from the default data may be used as the display description content rule data.
[0043] Next, for each of the lines that make up the source code S that should be displayed in the flowchart, the program P generates data for generating a flowchart, which data indicates the line number of that line (first line number), the next execution line number of that line (second line number), and the display description content of that line.
[0044] Program P passes the generated flowchart generation data to program Q. The method of passing the flowchart generation data from program P to program Q may be any of the following: program P directly passes the flowchart generation data to program Q; program P stores the flowchart generation data in memory 12, and program Q reads out the flowchart generation data;
[0045] Furthermore, program P and program Q may be executed by different computers. In this case, the flowchart generation data may be transmitted, for example, from the computer executing program P to the program executing program Q via a network, or the flowchart generation data may be recorded on a recording medium such as a memory card by the computer executing program P, and then read from the recording medium by the computer executing program Q.
[0046] 10 shows a flowchart generated by program Q using flowchart generation data generated by program P for source code S1. Program Q outputs the generated flowchart to a display for display, or to a printer for printing.
[0047] By looking at the flowchart generated by program Q, such as the one shown in Figure 10, a program verifier can easily discover problems contained in the program, such as differences between the processing performed according to the program and the specifications, or processing flows that pose a risk of causing results unintended by the program user.
[0048] Fig. 11 is a diagram showing the state after the above-mentioned processing (from assigning line numbers to identifying the display description content) by program P is completed for source code S2, which is a part of source code S2 that is different from source code S1. Fig. 12 is a diagram showing a flowchart generated by program Q using the flowchart generation data included in the data of Fig. 11.
[0049] For example, suppose that the verifier notices a problem in the flowchart in Figure 12, where "Line 76: Display deletion completed" is executed immediately after the process "Line 75: Delete employee file." This is because, for important processes such as deleting a file, a process should be executed to prompt the user for confirmation before deleting the file in order to prevent the user from accidentally deleting the file, but according to the flowchart in Figure 12, there is no line related to this process in source code S2.
[0050] 13A and 13B show source code S2 after the verifier, who noticed the above problem, made corrections. Note that the line numbers of source code S2 (before correction) in FIG. 11 and source code S2 (after correction) in FIG. 13 are different due to corrections made to the part of source code S before source code S2. The line with line number 75 in FIG. 11 has been corrected by the verifier to line numbers 78-80(2) in FIG. 13.
[0051] Fig. 14 shows a flowchart generated by program Q using the flowchart generation data included in the data in Fig. 13. The boxed parts of the flowchart in Fig. 14 are the parts that have changed from the flowchart in Fig. 12 due to modifications made to the source code by the verifier.
[0052] According to the above-mentioned program P, a program verifier can easily find problems contained in the program by looking at a flowchart automatically generated from the source program.
[0053] [Variations] The above-described embodiment is one embodiment of the present invention, and various modifications can be made within the scope of the technical concept of the present invention. Examples of such modifications are shown below. Note that two or more of the following modifications may be combined as appropriate.
[0054] (1) In the above-described embodiment, the program P identifies a display description, which is a description to be displayed in a flowchart, based on the description of the source code to be processed. Then, the program P generates, as flowchart generation data, data indicating the line number (first line number) of each line to be displayed in a flowchart among multiple lines of the source code to be processed, the line number (second line number) of that line, and the display description of that line.
[0055] The program P may generate flowchart generation data including data indicating a description of source code instead of the display description. That is, the program P may generate, as flowchart generation data, data indicating the line number (first line number) of each line to be displayed in a flowchart among multiple lines of source code to be processed, the line number (second line number) of the line to be next executed, and the description of the source code of the line. In this case, the program P does not need to perform the process of identifying the display description described above.
[0056] FIG. 15 shows a flowchart generated by program Q using the flowchart generation data generated by program P using the information in FIG. 8 for source code S1 in this modified example.
[0057] The flowcharts generated in the above-described embodiments describe the processing performed by the computer at each step in a way that is closer to natural language than source code. This has the advantage that even people who are not familiar with the language used to write the source code can easily identify problems in the program.
[0058] On the other hand, the flowchart generated in this modification shows the source code as it is, so that a person familiar with the language used to write the source code can easily identify problems in the program by looking at the flowchart generated in this modification, just as they can by looking at the flowchart generated in the embodiment.
[0059] (2) In the above-described embodiment, it is assumed that the natural language used by the verifier is Japanese. Therefore, Japanese is used for the display description content specified by the program P in accordance with the display description content rule data. The display description content rule data used by the program P may be changed depending on the natural language used by the verifier. For example, the verifier may input the natural language he or she uses into the computer 1 running the program P, and the program P may specify the display description content using the display description content rule data corresponding to that natural language.
[0060] (3) In addition to the program exemplified by the program P described above, the present invention provides a method including the steps of each process performed by a data processing device in accordance with the program of the present invention exemplified by program P.
[0061] The present invention also provides a data processing device having a memory that persistently stores a program according to the present invention, exemplified by program P, and a processor that performs processing in accordance with the program, and a recording medium on which the program according to the present invention, exemplified by program P, is recorded. [Explanation of symbols]
[0062] 1...computer, 11...processor, 12...memory.
Claims
1. On the computer, a process of assigning a first line number indicating an execution order to each of a plurality of lines constituting a source code of a program; a process of decomposing each line indicating a plurality of processes among the plurality of lines constituting the source code into lines corresponding to each of the plurality of processes indicated by the line; a process of identifying a syntax type of each of a plurality of lines constituting the source code; a process of identifying lines to be displayed in a flowchart from among a plurality of lines constituting the source code based on a syntax type; a process of identifying, for each of a plurality of lines constituting the source code that should be displayed in a flowchart, the first line number of a line to be executed next to the line as a second line number; generating, as flowchart generation data, data indicating the first line number of each line, the second line number of each line, and the description of the source code on each line, for each line to be displayed in a flowchart among a plurality of lines constituting the source code; A program to execute.
2. The computer, A process for identifying, for each of the lines to be displayed in the flowchart among the plurality of lines constituting the source code, a display description content that is a description content to be displayed in the flowchart based on the description content of the source code of the line. Execute In the process of generating the flowchart generation data, for each of the lines to be displayed in a flowchart among the plurality of lines constituting the source code, the flowchart generation data is generated which indicates the display description content of the line instead of the description content of the source code of the line. The program according to claim 1 for
3. a data processing device, assigning a first line number indicating an execution order to each of a plurality of lines constituting a source code of a program; a step of decomposing each line indicating a plurality of processes among the plurality of lines constituting the source code into lines corresponding to each of the plurality of processes indicated by the line; Identifying a syntax type of each of a plurality of lines constituting the source code; Identifying lines to be displayed in a flowchart from among a plurality of lines constituting the source code based on a syntax type; specifying, for each of the lines to be displayed in a flowchart among the plurality of lines constituting the source code, the first line number of the line to be executed next to the line as a second line number; generating, as flowchart generation data, data indicating the first line number of each line, the second line number of each line, and the description of the source code on each line, for each line to be displayed in a flowchart among a plurality of lines constituting the source code; A method for providing
4. the data processing device comprises a step of specifying, for each of the lines to be displayed in a flowchart among the plurality of lines constituting the source code, a description content for display, which is a description content to be displayed in a flowchart, based on the description content of the source code of the line; In the step of generating the flowchart generation data, the data processing device generates the flowchart generation data indicating the display description content of each line of the source code, instead of the description content of the source code of that line, for each line to be displayed in the flowchart among the plurality of lines constituting the source code. The method of claim 3.
Citation Information
Patent Citations
Visualized drifting algorithm of Gif warehouse file annotation system
CN108228231A
Microcomputer development assisting device
JP1992229336A
Program generator
JP1994324851A
Method and device for preparing flow chart and recording medium recording program for preparing flow chart
JP1999085484A
Device, method, and program for drawing flow chart
JP2011048477A