Source code correction program and source code correction device
The source code proofreading program efficiently converts and proofreads code to meet multiple coding conventions and languages, ensuring high-quality output by using intermediate steps and definition files, addressing inefficiencies and errors in software development.
Patent Information
- Application Number
- JP2024113957
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2026-01-29
AI Technical Summary
Existing software development processes face challenges in efficiently creating high-quality source code that adheres to various coding conventions and programming languages, leading to errors and inefficiencies due to differing interpretations and misunderstandings among programmers, and modifications that can affect functionality.
A source code proofreading program that converts source code into pre-proofreading intermediate code, then into proofread intermediate code conforming to target coding conventions, and finally into proofread source code in the target programming language, using definition files to ensure compliance with specific coding standards.
Enables efficient creation of high-quality source code that conforms to diverse coding conventions and programming languages, reducing errors and maintaining functionality while accommodating client-specific standards.
Smart Images

Figure 2026013547000001_ABST
Abstract
Description
[Technical Field]
[0001] The present invention relates to a program and an apparatus for correcting source code written in various programming languages into source code that conforms to predetermined coding conventions. [Background technology]
[0002] Various types of software, such as application software, business software, software for controlling various electronic devices, and game software, are created using a variety of programming languages. In the field of information processing, terms such as software, program, and source code exist and are sometimes used synonymously. However, while these terms are interrelated, they can also be used with different meanings.
[0003] In other words, the term software refers to a set of instructions and data that is executed by a computer system. Software is contrasted with hardware and refers to an application or system that actually works. The term program refers to a set of instructions written to perform a specific task. A program is a part of software that performs a specific function or process. The term source code refers to the instructions and statements that make up a program written in a human-readable format. For example, source code can be written using various programming languages such as C, Java, and Python.
[0004] In other words, in this specification, source code is written in a format that can be read by humans, and a program is a computer-executable version of this code, and a collection of programs is software. In recent years, the scale of software development has grown, and it is common for multiple programmers (engineers who write source code) to share the work of creating source code for multiple programs that function in relation to each other. Therefore, if each programmer writes source code using their own method, the source code written will be interpreted differently, and it may be difficult for people other than the creator to understand.
[0005] As a result, errors in the source code can be overlooked, causing the program generated from that source code to not work, or to not function as expected, leading to problems. Furthermore, understanding the source code during maintenance can take time, resulting in unnecessary effort. To avoid these inconveniences, coding standards are created that define rules to be followed when writing source code, and each programmer is expected to write source code in accordance with these standards. This improves the efficiency of source code creation and maintenance, and ultimately the quality of programs and software as a whole.
[0006] However, because coding standards have many detailed rules, oversights can occur, making it difficult to write (create) source code that fully complies with the coding standards. Patent Document 1, described below, therefore discloses an invention related to a program or the like that makes it possible to ensure the quality of program development. Specifically, the invention disclosed in Patent Document 1 refers to a storage unit that stores information related to coding standards, and determines whether source code, in which processing is described in a programming language, satisfies the coding standards. If it is determined that the source code satisfies the coding standards, object code corresponding to the source code is generated. This process is performed by a computer.
[0007] Furthermore, Patent Document 2, which will be described later, discloses an invention related to a coding convention check system. Specifically, the invention disclosed in Patent Document 2 reads coded source code (source program) in a source reading unit and registers the source code. The registered source code is then checked for syntax and grammar in a compilation unit, and compared against coding conventions to check for violations of the conventions. If a violation of the conventions is found, the number of lines involved and an error or warning message are output on the screen as the compilation result. Input data for unit testing is registered in a data registration unit, testing is performed in a unit testing unit, and the results of this unit testing and compilation are received, and source corrections, etc. are performed in a debugging unit. [Prior art documents] [Patent documents]
[0008] [Patent Document 1] Japanese Patent Application Publication No. 2019-020990 [Patent Document 2] Japanese Patent Application Publication No. 11-073328 Summary of the Invention [Problem to be solved by the invention]
[0009] As an example of a coding standard, as shown in Figure 11(A), one standard states that the opening brace (left brace) [{] within an "if" statement should not be written on the same line as the "if" statement, but on the next line. This means that there should not be a "{" at the end of an "if" statement, as shown in (1) of Figure 11(A). The correct rule is to not put a "{" at the end of an "if" statement, but to put a "{" on the line following the "if" statement, as shown in (a) and (b) of Figure 11(A). The standard in Figure 11(A) also specifies the position of a single brace "{", which can lead to mistakes being overlooked even by experts familiar with source code (checkers with knowledge of source code and coding standards).
[0010] Another example of a coding standard is that the immediate value of the comparison condition in an "if" statement should be written on the left side, as shown in Figure 11(B). Here, "immediate value" refers to a constant (numeric value) included in the instruction that is immediately available when the instruction is read. For example, in the if statement shown in Figure 11(B)(1), "NULL" is used to indicate nonexistence or nothingness, but whether or not "NULL" is considered an immediate value can vary among experts. That is, some people believe that "NULL" means nothingness and is not a numeric value, while others believe that "NULL" has the same meaning as the numeric value 0 (zero) in source code and is a numeric value. In this case, the former would not correct the statement in Figure 11(B)(1), while the latter would reposition "NULL" to the left, as shown in Figure 11(B)(a). Differences in the understanding of the experts performing the checks can prevent appropriate source code modifications.
[0011] Coding standards are revised with the aim of improving quality. However, there are parts of source code that do not comply with the standards, such as previously developed or reused parts. Therefore, when modifying these parts to comply with the revised coding standards, the process of finding and modifying these parts increases, making it difficult to create source code efficiently. Furthermore, even if there is no need to change the functionality of the part in question, making modifications to comply with the coding standards may result in modifications that affect the functionality of the part in question, which could lead to a decrease in the performance of the program generated from that source code.
[0012] For this reason, it is important to utilize inventions such as the programs disclosed in Patent Documents 1 and 2, which check whether created source code complies with coding standards. However, software development companies develop software in response to requests from various clients, and the coding standards and programming languages used vary from client to client. Even in software development companies, it is rare for all employees to be familiar with many programming languages, and each employee will have programming languages they are familiar with and programming languages they are unfamiliar with. For this reason, it is desirable to be able to develop efficient and reliable programs that can accommodate, for example, the different coding standards and programming languages used by each client.
[0013] In view of the above, an object of the present invention is to enable efficient creation of high-quality source code in accordance with various coding conventions and various programming languages. [Means for solving the problem]
[0014] In order to solve the above problem, the source code proofreading program of the invention described in claim 1 is: a first conversion step of converting source code written in a predetermined programming language into pre-proofreading intermediate code by referring to a first definition file that holds definition data for converting the source code into intermediate code separated into meaningful components; a second conversion step of referencing a second definition file that holds definition data for converting the unproofreaded intermediate code into proofread intermediate code that conforms to the coding conventions of a target programming language, and proofreading the unproofreaded intermediate code to convert it into the proofread intermediate code; a third conversion step of converting the proofread intermediate code into proofread source code in a target programming language by referring to a third definition file that holds definition data for converting the proofread intermediate code into proofread source code in a target programming language; The present invention is characterized by carrying out the following.
[0015] The source code proofreading program of the invention described in claim 1 has a first conversion step in which a first definition file is used to convert source code written in a predetermined programming language into intermediate code separated into meaningful components. A second conversion step in which a second definition file is used to convert this intermediate code into proofread intermediate code that conforms to the coding conventions of a target programming language. Furthermore, a third definition file is used to convert this proofread intermediate code into proofread source code in the target programming language.
[0016] In this way, the conversion is performed in the following order: (1) source code written in a predetermined programming language → (2) intermediate code → (3) proofread intermediate code → (4) proofread source code in the target programming language. As a result, (4) proofread source code in the target programming language is obtained from (1) source code written in a predetermined programming language. In this case, the programming languages used in (1) source code written in a predetermined programming language and (4) proofread source code in the target programming language may be the same or different. [Effects of the Invention]
[0017] According to the present invention, high-quality source code can be efficiently created in accordance with various coding conventions and various programming languages. [Brief explanation of the drawings]
[0018] [Figure 1] 1 is a block diagram illustrating an example of a configuration of an information processing apparatus according to an embodiment. [Figure 2] 10A and 10B are diagrams illustrating files used in a source code proofreading processing unit of the information processing device according to the embodiment; [Figure 3] 10A and 10B are diagrams for explaining details of processing performed by a source code proofreading processing unit of the information processing device according to the embodiment; [Figure 4] FIG. 10 is a diagram illustrating an example of data stored in a coding convention definition file. [Figure 5] 4 is a diagram for explaining an example of stored data in the pre-proofreading source file, each intermediate file, and the proofreading source file shown in FIG. 3. FIG. [Figure 6] 10 is a flowchart illustrating a source code proofreading process executed by the information processing apparatus according to the embodiment. [Figure 7] 7 is a flowchart for explaining the intermediate code conversion process executed in step S4 of the flowchart of FIG. 6. [Figure 8] 7 is a flowchart for explaining an intermediate code proofreading process executed in step S5 of the flowchart of FIG. 6. [Figure 9] 9 is a flowchart continuing from FIG. 8. [Figure 10] 7 is a flowchart for explaining a source code conversion process executed in step S6 of the flowchart of FIG. 6. [Figure 11] FIG. 10 is a diagram illustrating an example of a coding convention. DETAILED DESCRIPTION OF THE INVENTION
[0019] An embodiment of a program and device according to the present invention will be described below with reference to the drawings. In the embodiment described below, an example will be given in which the program and device according to the present invention are applied to PCs (Personal Computers), which are information processing devices used by employees at a company that develops software in response to requests from various companies. Companies that develop software in response to requests from various companies are also called software houses or system integrators.
[0020] [Configuration example of information processing device according to embodiment] FIG. 1 is a block diagram illustrating an example of the configuration of an information processing device 1 according to an embodiment of the present invention, to which an embodiment of a source code proofreading device according to the present invention is applied. The information processing device 1 according to this embodiment is configured as, for example, a notebook PC (Personal Computer). A connection terminal 101T constitutes a connection terminal to a LAN (Local Area Network). A LAN I / F (interface) 101 realizes a function of converting data transmitted via the LAN to its own device into data in a format that can be processed by the own device and importing the data. The LAN I / F 101 also realizes a function of converting data to be sent from its own device into data for transmission, sending the data to the LAN, and transmitting it to a destination.
[0021] As a result, data can be transmitted and received between other devices connected to the LAN through the connection terminal 101T and the LAN I / F 101, or the Internet can be accessed via the LAN to transmit and receive data between server devices on the Internet. Note that, although the LAN I / F 101 is configured to be connected to the LAN by a wired connection in Fig. 1, this is not limiting. It may also be configured to be connected to the LAN by a wireless LAN conforming to the Wi-Fi (registered trademark) standard.
[0022] Although not shown, the control unit 102 is a microprocessor including a central processing unit (CPU), read-only memory (ROM), random access memory (RAM), non-volatile memory, etc., and realizes the function of controlling each unit of the information processing device 1. The storage device 103 is a device unit including a recording medium, such as a hard disk drive (HDD) or solid state drive (SSD), and its driver, and performs operations such as recording, reading, modifying, and deleting various data from the recording medium. The storage device 103 not only stores and holds necessary data and programs, but also serves as a work area for temporarily storing intermediate data generated in various processes. In this embodiment, various intermediate files, such as comment files, original source files, pre-proofreading intermediate files, proofreading intermediate files, and post-proofreading source files, are stored in the storage device 103, as will be described in detail below.
[0023] The operation unit 104 is configured with a keyboard, a mouse, and other pointing devices, and realizes the function of receiving operation inputs from the user, converting them into electrical signals, and providing them to the control unit 102. This enables the control unit 102 to execute processing in accordance with instructions from the user. Note that the operation unit 104 may also be provided with other button switches, such as a power button and several function buttons.
[0024] The company-specific definition file group 105 is formed on a storage medium of a device unit consisting of a recording medium such as an HDD or SSD and its driver, and stores and holds various definition files created for each company that orders the program. As will be described in detail later, the company-specific definition file group 105 includes a comment saving rule file, an intermediate code conversion definition file, a coding convention definition file, and a source code conversion definition file for each company.
[0025] The external I / F 106 and the connection terminal 106T constitute a so-called digital interface, enabling connection to an external device and enabling data transmission and reception to and from the external device. The external device may be, for example, an external storage device or another information processing device. The short-range wireless communication unit 107 and the short-range wireless communication antenna 107A are components that enable short-range wireless communication, and in this embodiment, comply with the Bluetooth (registered trademark) standard. Data can be transmitted and received wirelessly to and from the external device via the short-range wireless communication unit 107 and the short-range wireless communication antenna 107A.
[0026] Video output processing unit 108 converts the video data from control unit 102 into a video signal in a format suitable for supply to display unit 109, and supplies this to display unit 109. Display unit 109 is configured using a thin display element such as an LCD (Liquid Crystal Display) or an OEL (Organic Electro-Luminescence) display. Display unit 109 displays a video corresponding to the video signal from video output processing unit 108 on its own display screen. Audio output processing unit 110 converts the digital audio data from control unit 102 into an analog audio signal, and supplies this to speaker 111. As a result, various audio information corresponding to the digital audio data is emitted from speaker 111.
[0027] The pre-proofreading source file 121 is formed on a storage medium of a device unit consisting of a recording medium and its driver, such as an HDD or SSD, and stores and holds source code created in a predetermined programming language for the ordering company. The source code stored and held in the pre-proofreading source file 121 is input using a keyboard, mouse, or the like that make up the operation unit 104. It is also possible to receive source code from an external information processing device connected to the LAN via the connection terminal 101T and the LAN I / F 101, store this source code in the pre-proofreading source file 121, and use it as the processing target.
[0028] It is also possible to obtain source code from an external device such as a USB memory connected via connection terminal 106T and external I / F 106, store this in pre-proofreading source file 121, and use it as a processing target. It is also possible to obtain source code created in an external device such as another information processing device via short-range wireless communication unit 107 and short-range wireless communication antenna 107A, record this in pre-proofreading source file 121, and use it as a processing target. In this way, source code created in information processing device 1 or source code created and stored in an external device can be recorded in pre-proofreading source file 121 and used as a processing target.
[0029] The source code proofreading processor 122 proofreads the source code in the pre-proofreading source file 121 using the definition files in the company-specific definition file group 105 to make it conform to the coding standards of the target company, and records it in the proofread source file 123. The term "proofreading" originally meant checking and correcting created text for typos, English spelling errors, variations in notation, text structure, grammatical usage, and inconsistencies in content. In this specification, the term "proofreading" means correcting source code created in a specified programming language so that it conforms to the coding standards of the ordering company.
[0030] Furthermore, the source code proofreading processor 122 of the information processing device 1 according to this embodiment can convert source code that is written in a predetermined programming language and recorded in the pre-proofreading source file 121 into source code written in a target programming language. In other words, the source code recorded in the pre-proofreading source file 121 and the source code recorded in the proofreading source file 123 can be written in the same programming language, or they can be written in different programming languages.
[0031] As described above, the proofread source file 123 stores and holds the proofread source code obtained as a result of the source code stored in the unproofread source file 121 being proofread by the source code proofreading processor 122. This makes it possible to obtain in the proofread source file source code that conforms to the coding conventions of the client company and is written in the target programming language.
[0032] <Processing Overview of Source Code Proofreading Processor 122> FIG. 2 is a diagram illustrating files used by the source code proofreading processor 122 of the information processing device 1 according to the embodiment. As shown in FIG. 2, the company-specific definition file group 105 is a definition file group for each company that orders source code. FIG. 2 illustrates a case in which a company A definition file group 105A, a company B definition file group 105B, a company C definition file group 105C, and so on are provided. As described above, the pre-proofreading source file 121 stores and holds source code created in a predetermined programming language for the ordering company. Intermediate files such as the comment file 1031 are formed in a predetermined storage area of the storage medium of the storage device 103 and are a file group that temporarily stores intermediate processing results generated during the processing of the source code proofreading processor 122.
[0033] Normally, there is only one proofread source file 123 corresponding to the unproofread source file 121. However, for simplicity of explanation, we will show a case where a proofread source file is prepared for each company that orders the source code (program). That is, we will show a case where the proofread source files are Company A proofread source file 123A, Company B proofread source file 123B, Company C proofread source file 123C, and so on.
[0034] The source code proofreading processor 122 performs proofreading on the pre-proofreading source code in the pre-proofreading source file 121, using the company-specific definition file group 105 as a reference file, and outputs proofread source data to the proofread source file 123. At this time, the source code proofreading processor 122 uses the intermediate file group in the storage device 103 as a temporary storage area for the intermediate processing results. Note that the company A definition file group 105A, company B definition file group 105B, company C definition file group 105C, ... of the company-specific definition file group 105 are switched depending on which company the source code stored in the pre-proofreading source file 121 is for.
[0035] Similarly, company A proofread source file 123A, company B proofread source file 123B, company C proofread source file 123C, ... of proofread source file 123 are switched depending on which company the source code stored in unproofread source file 121 is for. For this reason, an instruction as to which company the source code stored in unproofread source file 121 is for is input via operation unit 104. As a result, in source code proofreading processing unit 122, the company-specific definition file group referenced by company-specific definition file group 105 and the company-specific proofread source file to which the proofread source code of proofread source file 123 is output are switched in accordance with the input instruction.
[0036] <Details of the processing by the source code proofreading processor 122> As explained using Fig. 2, the information processing device 1 of this embodiment can create source code for each of a plurality of different companies that place orders, and proofread the source code so that it conforms to the coding conventions of each company. However, since different companies place orders, only the definition file groups referenced by the company-specific definition file group 105 are different, and proofread source code is generated by the same proofreading process. Therefore, the proofreading process performed by the source code proofreading processing unit 122 will be specifically explained using an example in which the orderer is Company A.
[0037] 3 is a diagram for explaining details of the processing performed by the source code proofreading processing unit 122 of the information processing device 1 according to the embodiment. In this example, the orderer is Company A, so the definition file group of the company-specific definition file group 105 uses Company A definition file group 105A, as shown in Fig. 3. Company A definition file group 105A consists of a comment saving rule file A1, an intermediate code conversion definition file A2, a coding convention definition file A3, and a source code conversion definition file A4.
[0038] The comment saving rule file A1 extracts comment portions contained in the pre-proofreading source code, saves them in an identifiable manner, and stores information for attaching identification labels to the extracted portions to identify what the comment portions are. In other words, the comment saving rule file A1 stores information for identifying comment portions in the pre-proofreading source code and information about identification labels to be attached to the pre-proofreading source code.
[0039] The intermediate code conversion definition file A2 holds definition data for converting pre-proofreading source code written in a specified programming language into intermediate code separated into meaningful components. This definition data includes information such as the character string to be distinguished, the position of that character string in the source code, and the character strings before and after that character string. For example, suppose the programming language is C and the source code "if(a==10){" is written. In this case, based on the information in the intermediate code conversion definition file A2, the "if" at the beginning of the line can be recognized as an "if" that constitutes a conditional decision statement. Furthermore, the "(" and "a" following "if" can be recognized as a left parenthesis and the variable a, respectively, and the "==" can be recognized as a symbol indicating equality rather than assignment. Furthermore, the "10", ")", and "{" following the symbol "==" can be recognized as the number 10, a right parenthesis, and an opening curly brace.
[0040] The coding convention definition file A3 holds definition data for converting pre-proofreading intermediate code into proofread intermediate code that conforms to the coding conventions of the target programming language. FIG. 4 is a diagram for explaining an example of data stored in the coding convention definition file shown in FIG. 3. The stored data (definition data) in the coding convention definition file A3 shown in FIG. 4 expresses the coding convention that the opening curly brace "{" within an "if" statement should be written on the next line, not on the same line as the "if" statement.
[0041] As shown in Figure 4, the definition data consists of a check action definition (defines section) and a check condition definition (rules section). The check action definition specifies that opening braces (brackets ({)) on the same line as an if statement should be written on the next line, and that opening braces (brackets ({)) on the same line as a for statement should be written on the next line. The check condition definition specifies that it should check whether opening braces (brackets ({)) are on the same line as an if statement, and whether opening braces (brackets ({)) are on the same line as a for statement. It also specifies that an opening brace on the same line as an if statement should actually be on the next line after the if statement, and that an opening brace on the same line as a for statement should actually be on the next line after the for statement.
[0042] The source code conversion definition file A4 holds definition data for converting the proofread intermediate code into proofread source code in the target programming language. The definition data associates each meaningful component of the intermediate code with the source code when expressed in the target programming language.
[0043] 3, unproofreading source file 121 is the input file, and proofreading source file 123 is the output file. Also in FIG. 3, comment file 1031, original source file 1032, pre-proofreading intermediate file 1033, proofreading intermediate file 1034, and proofreading source file 1035 are each a group of intermediate files formed in storage device 103. Note that in FIG. 3, the letter "F" in pre-proofreading source F, etc., represents a file. Also in FIG. 3, process 1, process 2, process 3, process 4, and process 5 represent processes performed by source code proofreading processing unit 122 of information processing device 1, respectively.
[0044] The processing performed by the source code proofreading processor 122 will be described with reference to Fig. 3 and Fig. 5. Fig. 5 is a diagram for explaining an example of stored data in the pre-proofreading source file 121, the intermediate files 1031 to 1034, and the proofreading source file 123 shown in Fig. 3. As described above, it is assumed that the pre-proofreading source file 121 stores source code created using, for example, the C programming language for Company A, the client. In this case, it is assumed that an instruction has been issued to proofread the data stored in the pre-proofreading source file 121 so that it conforms to the coding conventions of Company A.
[0045] For simplicity's sake, the following description will be given assuming that a portion of source code stored in pre-proofreading source file 121 contains a comment section and source code, as shown in Figure 5(A), and that this portion is to be proofread. In Figure 5(A), the comment section is " / *aiueokakikukeko* / ", and the source code section is "if(a==10){" and, on a different line, "}".
[0046] First, the source code proofreading processor 122 executes comment evacuation processing as process 1. As shown in FIG. 5(A), the pre-proofreading source code stored in the pre-proofreading source file 121 includes a comment portion and a source code portion. In process 1, the rule information in the comment evacuation rule file A1 is used to determine that the portion sandwiched between " / *" at the beginning and "* / " at the end is a comment portion, and label information is added to this portion according to the rule information in the comment evacuation rule file A1. The label information consists of text information called "Label" and numerical information that counts up from "1," "2," "3," ... in order of appearance from the beginning of the source code, such as Label1, Label2, Label3, ...
[0047] In process 1, comment sections are extracted from the source code of the pre-proofreading source file 121, and label information is added to the extracted comment sections and recorded in the comment file 1031. Furthermore, in process 1, comment sections present in the pre-proofreading source code are replaced with label information and recorded in the original source file 1032. As a result, information in which the label information and the comment sections are paired is stored in the comment file 1031, as shown in FIG. 5(B). That is, "Label1" can be identified as the comment section " / *¥nアイウエオ¥nかきくけこ¥n* / ". Furthermore, as shown in FIG. 5(C), the original source file 1032 stores the pre-proofreading source code in which the comment section " / *¥nアイウエオ¥nかきくけこ¥n* / " has been replaced with the label information "Label1". Therefore, for the pre-proofreading source code of the original source file 1032 in Figure 5(C), it is possible to determine where and what comment parts were present by using label information such as "$$Label1" and the data stored in the comment file 1031.
[0048] Next, the source code proofreading processor 122 executes intermediate code conversion processing as process 2. Process 2 is a process in which the pre-proofreading source code, in which the comment portions stored in the original source file 1032 have been replaced with level information, is converted into intermediate code in accordance with the definition data in the intermediate code conversion definition file A2, and this is written to the pre-proofreading intermediate file 1033. Specifically, in process 2, as described above, the pre-proofreading source code is converted into intermediate code separated into each meaningful component element, and this is written to the pre-proofreading intermediate file 1033.
[0049] Specifically, as shown in Figure 5(C), the original source file 1032 contains label information corresponding to the comment section and pre-proofreading source code containing an if statement. The definition data in the intermediate code conversion definition file A2 allows the label information "$$Label1" to be recognized as label information with a single meaning. Furthermore, as mentioned above, for the source code section "if(a==10){", the "if" at the beginning of the line can be recognized as an "if" that constitutes a conditional decision statement based on the information in the intermediate code conversion definition file A2.
[0050] Furthermore, the "(" and "a" following "if" can be recognized as the left parenthesis and the variable a, and the "==" can be recognized as a symbol meaning equality rather than assignment. Furthermore, the "10", ")", and "{" following the symbol "==" can be recognized as the number 10, the right parenthesis, and the opening curly brace, and the "}" can be recognized as the closing curly brace (right curly brace). As a result, the pre-proofreading source code of FIG. 5(C) is converted into intermediate code in which the label information, the "if" statement, "[a", "==", "10]{", and "}" can be distinguished, as shown in FIG. 5(D), and is written out to the pre-proofreading intermediate file 1033.
[0051] Next, the source code proofreading processor 122 executes intermediate code proofreading as process 3. Process 3 proofreads the pre-proofreading intermediate code stored in the pre-proofreading intermediate file 1033 so that it conforms to the coding convention based on the definition data in the coding convention definition file A3, and writes the proofreading intermediate file 1034. The coding convention definition file A3 contains definition data corresponding to various coding conventions, but here we will focus on the following two coding conventions. One is that, as explained using Figures 11(A) and 4, "the opening curly brace [{] within an 'if' processing should be written on the next line, not on the same line as the 'if'." The other is that "the immediate value of the comparison condition within an 'if' should be written on the left side."
[0052] By executing process 3, the pre-proofreading intermediate code shown in Fig. 5(D) is proofread into intermediate code as shown in Fig. 5(E) in which the immediate value 10 is positioned to the left of the symbol "==" and the opening curly brace [{] written on the same line as the if statement is positioned on the line following the if statement. The proofread intermediate code thus proofread is written to intermediate file (proofread) 1034.
[0053] Next, the source code proofreading processor 122 executes source code conversion processing as processing 4. Processing 4 is processing for converting the proofread intermediate code stored in the proofread intermediate file 1034 into source code in the target programming language. That is, as shown in FIG. 5(E), the proofread intermediate file 1034 stores proofread intermediate code that has been proofread so as to conform to coding conventions. In processing 4, each of the constituent parts that have been separated into the meaning of the proofread intermediate code in the proofread intermediate file 1034 is converted into one that corresponds to the target programming language, and these are combined to create source code in the target programming language.
[0054] For simplicity's sake, an example will be given here in which proofread intermediate code is converted into C language source code. As shown in FIG. 5(E), in the proofread intermediate code stored in the proofread intermediate file 1034, the label information "$$Label1" is recognized as label information having a single meaning. Furthermore, the "if" at the beginning of the line is recognized as an "if" that constitutes a conditional decision statement. The "[" and "a" following "if" are recognized as left parentheses and the variable a, respectively, and "==" is recognized as a symbol that means equality rather than assignment. Furthermore, the "10" and "]" following the symbol "==" are recognized as the number 10 and a right parenthesis, with "{" recognized as an opening curly brace and "}" as a closing curly brace.
[0055] When each of these parts is converted based on the definition data in the source code conversion definition file A4, source code conforming to the grammar of the C language is generated, as shown in FIG. 5(F), and this is written to the post-source file 1035. Here, the case where the proofread intermediate code is converted into C language source code has been described as an example, but the present invention is not limited to this. The proofread intermediate code can also be converted into source code in various programming languages, such as JavaScript, Ruby, Python, and PHP. In this case, definition data that associates each of the meaningful components of the intermediate code with the corresponding descriptions in the target programming language can be prepared in the source code conversion definition file A4.
[0056] Thereafter, the source code proofreading processor 122 performs comment restoration processing as process 5. Label information has been added to the comment portion of the source code written to the post source file 1035. Therefore, in process 5, the source code proofreading processor 122 extracts the corresponding comment portion from the data stored in the comment file 1031 and replaces it with the label information of the source code in the post source file 1035.
[0057] As a result, as shown in Figure 5(F), the source code having label information "$$Label1" has the corresponding comment portion from comment file 1031 restored to the label information portion, as shown in Figure 5(G). The source code with this comment portion restored is written to proofread source file 123. As a result, the source code written to proofread source file 123 conforms to the coding conventions of Company A and has been written in the programming language targeted by Company A.
[0058] Note that the explanation given here assumes that the pre-proofreading source code and the proofreading source code are created in the same programming language, C. However, if the pre-proofreading source code and the proofreading source code are created in different programming languages, then in process 5 too, the source code conversion definition file A4 will be referenced and the comments will be restored in a description format that matches the target programming language.
[0059] [Summary of processing performed by information processing device 1] Next, the processing performed by the information processing device 1 according to the embodiment will be summarized with reference to a flowchart. Fig. 6 is a flowchart for explaining the source code proofreading processing (main routine) executed by the information processing device 1 according to the embodiment. The processing shown in the flowchart in Fig. 6 is executed by the control unit 102, and is performed by the control unit 102 controlling the source code proofreading processing unit 122, and the main part of the processing corresponds to the processing performed by the source code proofreading processing unit 122 described with reference to Fig. 3.
[0060] 6 is executed, the control unit 102, in response to a request from the client, inputs source code created in a predetermined programming language into the pre-proofreading source file 121 (step S1). In step S1, the source code input into the pre-proofreading source file 121 includes not only that created by the information processing device 1 but also that created by an external device and provided via the external I / F 106, the short-range wireless communication unit 107, or the LAN I / F 101.
[0061] Thereafter, the control unit 102 performs a process of identifying a definition file group to be referenced in the proofreading process (step S2). Specifically, in this embodiment, the operation unit 104 receives an input operation of which company the ordering party is, and identifies the definition file group of the target company stored in the company-specific definition file group 105. Thereafter, under the control of the control unit 102, the source code proofreading processing unit 122 functions and executes a comment saving process (step S3).
[0062] The comment saving process in step S3 corresponds to process 1 described with reference to Fig. 3. That is, in step S3, the source code proofreading processor 122 first identifies comment portions present in the pre-proofreading source code using the information in the comment saving rule file A1, and sets label information (identification information) for the comment portions. Next, the source code proofreading processor 122 associates the label information with the comment portions and stores them in the comment file 1031, and writes the source code in which the comment portions of the pre-proofreading source code have been replaced with the label information into the original source file 1032. As a result, the comment information in which the label information and the comment portions are associated with each other is stored in the comment file 1031, and the pre-proofreading source code in which the comment portions have been replaced with the label information is stored in the original source file 1032.
[0063] Next, under the control of the control unit 102, the source code proofreading unit 122 executes intermediate code conversion processing (step S4). The intermediate code conversion processing in step S4 corresponds to processing 2 described with reference to Fig. 3. As described above, the processing in step S4 refers to the definition data in the intermediate code conversion definition file A2, converts the pre-proofreading source code of the original source file 1032 into intermediate code, and writes it into the pre-proofreading intermediate file 1033. Details of the processing in step S4 will be described later.
[0064] Next, under the control of the control unit 102, the source code proofreading unit 122 executes intermediate code proofreading processing (step S5). The intermediate code proofreading processing in step S5 corresponds to processing 3 described with reference to FIG. 3. As described above, the processing in step S5 is processing for proofreading the pre-proofreading intermediate code in the pre-proofreading intermediate file 1033 into intermediate code that conforms to the coding convention, in accordance with the definition data in the coding convention definition file A3. In step S4, the proofread intermediate code is written to the proofreading intermediate file 1034. The processing in step S5 will be described in detail later.
[0065] Next, under the control of the control unit 102, the source code proofreading unit 122 executes a source code conversion process (step S6). The intermediate code proofreading process in step S6 corresponds to process 4 described with reference to FIG. 3. As described above, the process in step S6 is a process for converting the proofread intermediate code in the proofread intermediate file 1034 into source code in the target programming language in accordance with the definition data in the source code conversion definition file A4. In step S6, the converted source code is written to the post-conversion source file 1035. The process in step S6 will be described in detail later.
[0066] Next, under the control of the control unit 102, the source code proofreading unit 122 executes comment restoration processing (step S7). The comment restoration processing in step S7 corresponds to processing 5 described with reference to FIG. 3. As described above, the processing in step S7 is processing for replacing the label information of the proofread source code recorded in the proofread source file 1035 with the comment portion associated with the label information in the comment file 1031. As a result, source code that has been proofread to conform to the target coding convention and written in the target programming language is obtained in the proofread source file 123.
[0067] In this embodiment, in order to perform source code configuration processing quickly and appropriately, consideration is given to preventing comment portions from being subject to proofreading processing by performing comment saving processing and comment restoration processing. However, if comment portions can be properly identified, they can be excluded from the proofreading processing, so the comment portions may be left as they are in the source code. For this reason, the following will explain in detail the intermediate code proofreading processing (step S4), intermediate code proofreading processing (step S5), and source code conversion processing (step S6), which are important processes in the source code proofreading processing shown in Figure 6.
[0068] <Intermediate code conversion process> Fig. 7 is a flowchart for explaining the intermediate code conversion process executed in step S4 of the flowchart in Fig. 6. First, the source code proofreading processor 122 determines whether all lines of the source code to be processed have been read and processed from the original source file 1032 (step S401). If it is determined in the determination process of step S401 that all lines have not been read and processed, one line of source code to be processed this time is acquired (step S402). The process of step S402 is a process of reading one line of source code to be processed next when reading one line of source code stored in the original source file 1032 in order from the beginning.
[0069] Next, the source code proofreading processor 122 refers to the intermediate code conversion definition file and performs a process of converting the source code acquired in step S402 into intermediate code (step S403). As described above, the process of step S403 converts source code written in a predetermined programming language into intermediate code by separating it into meaningful components, and records this in the pre-proofreading intermediate file 1033. As a result, as also shown in Figures 5(C) and (D), when the source code shown in Figure 7(a) is acquired in step S402, this is converted into the intermediate code shown in Figure 7(b) and recorded in the pre-proofreading intermediate file 1033.
[0070] After the process of step S403, the process from step S401 is repeated. If it is determined in the determination process of step S401 that all lines of the source code to be processed have been read and processed, the process of Fig. 7 is exited and the process returns to the main process of Fig. 6. This causes the intermediate code proofreading process of step S5 to be executed next.
[0071] <Intermediate code proofreading process> 8 and 9 are flowcharts for explaining the intermediate code proofreading process executed in step S5 of the flowchart in FIG. 6. First, the source code proofreading processor 122 determines whether all lines of the pre-proofreading intermediate code to be processed have been read and processed from the pre-proofreading intermediate file 1033 (step S501). If it is determined in the determination process of step S501 that all lines have not been read and processed, one line of the intermediate code to be processed this time is acquired (step S502). The process of step S502 is a process of reading one line of the intermediate code to be processed next when reading one line of the pre-proofreading intermediate code stored in the pre-proofreading intermediate file 1033 in order from the beginning. Therefore, in step S502, one line of pre-proofreading intermediate code is read from the pre-proofreading intermediate file 1033, as shown in FIG. 8(a).
[0072] Next, the source code proofreading processor 122 determines whether all definitions have been read from the coding convention definition file A3 (step S503). If it is determined in the determination process of step S503 that all definitions have not been read from the coding convention definition file A3, one definition data is acquired from the coding convention definition file A3 (step S504). The process of step S504 is a process of reading the next definition data to be used when reading definition data related to coding conventions stored in the coding convention definition file A3 one by one from the beginning. Specifically, in step S504, the check operation definition shown in FIG. 8(b) and the check condition definition shown in FIG. 8(c) are read.
[0073] Therefore, the check condition definition (FIG. 8(c)) acquired in step S504 instructs to check whether opening braces (brackets ({)) are present on the same line as the if statement. It can also be understood that opening braces on the same line as the if statement should actually be located on the line following the if statement. Furthermore, the check operation definition (FIG. 8(b)) instructs that opening braces (brackets ({)) on the same line as the if statement should be written on the next line.
[0074] For this reason, the source code proofreading processor 122 determines whether or not the instruction in the intermediate code acquired in step S502 is the same as the syntax of the check condition definition in the definition data acquired in step S504 (step S505). In this example, as shown in Fig. 8(d), the instruction in the intermediate code acquired in step S502 is "if," and the syntax of the check condition definition in the definition data acquired in step S504 is also "if." For this reason, in the determination process of step S505, it is determined that the instruction in the intermediate code acquired in step S502 is the same as the syntax of the check condition definition in the definition data acquired in step S504.
[0075] In this case, the source code proofreading processor 122 determines whether or not the intermediate code acquired in step S502 contains a component that is the same as the component of the check condition definition of the definition data acquired in step S504 (step S506). In this example, as shown in Fig. 8(e), the process determines whether or not "brackets," i.e., "{," which is a component of the check condition definition of the definition data acquired in step S504, exists in the intermediate code acquired in step S502.
[0076] In this example, in step S506, it is determined that the intermediate code acquired in step S502 contains "{", which is a component of the check condition definition in the definition data acquired in step S504. Therefore, the source code proofreading processor 122 identifies the operation content from the check operation definition in the definition data acquired in step S504 (step S507). That is, in this example, in step S507, as shown in FIG. 8(f), it is determined that the following operation will be performed: the opening curly brace "{" on the same line as the if statement is moved to the next line.
[0077] Therefore, the source code proofreading processor 122 proceeds to the processing of FIG. 9. The source code proofreading processor 122 determines whether or not a component of the check condition definition of the definition data acquired in step S504 exists on the same line as the intermediate code acquired in step S502 (step S508). In this example, as shown in FIG. 9(g), the component of the check condition definition, "{", is on the same line as the if statement, which is the source code acquired in step S502, and therefore it is determined in step S508 that they exist on the same line. In this case, the source code proofreading processor 122 forms proofread intermediate code according to the operation content identified in step S507 (step S509). That is, in this example, as shown in FIG. 9(h), a process is performed to delete the opening curly brace "{" on the same line as the if statement. After the process of step S509, the process proceeds to step S510.
[0078] Based on the operation content identified in step S507, the source code proofreading processor 122 determines whether it is necessary to add "{", which is a component of the check condition definition in the definition data, to the next line, as shown in FIG. 9(i) (step S510). In this example, the "{", which is a component of the check condition definition, needs to be written on the line following the if statement. For this reason, a component, in this example an opening curly brace "{", is added to the next line of the proofread intermediate code proofread in step S509 (step S511).
[0079] Furthermore, if it is determined in the determination process of step S508 that the component of the check condition definition of the definition data acquired in step S504 is not present on the same line as the intermediate code acquired in step S502, the process proceeds to step S512. Similarly, after the process of step S511, or if it is determined in the determination process of step S510 that it is not necessary to add a component of the check condition definition of the definition data to the next line, the process proceeds to step S512. In this case, the source code proofreading processor 122 writes the intermediate code proofread by the processes up to this point into a proofread intermediate file and stores it (step S512). Thereafter, the processes from step S503 are repeated.
[0080] If it is determined in the determination process of step S505 that the command in the intermediate code acquired in step S502 is not the same as the syntax of the check condition definition of the definition data acquired in step S504, the process repeats from step S503. Similarly, if it is determined in the determination process of step S506 that the intermediate code acquired in step S502 does not contain an instruction that is the same as the component of the check condition definition of the definition data acquired in step S504, the process repeats from step S503.
[0081] Furthermore, if it is determined in the determination process of step S503 that all definitions have been read and processed from coding convention definition file A3, then the proofreading process for the intermediate code read in step S502 is complete, and the process is repeated from step S501. If it is determined in the determination process of step S501 that all lines of the pre-proofreading intermediate code to be processed have been read and processed from pre-proofreading intermediate file 1033, then it can be determined that proofreading has been completed for all pre-proofreading intermediate code. In this case, the process leaves the processing of the flowcharts shown in Figures 8 and 9 and returns to the main routine shown in Figure 6, where source code conversion processing is executed. <Source code conversion process> 10 is a flowchart for explaining the source code conversion processing executed in step S6 of the flowchart in FIG. 6. First, the source code proofreading processor 122 determines whether all lines of the proofread intermediate code to be processed have been read and processed from the proofread intermediate file 1034 (step S601). If it is determined in the determination processing of step S601 that all lines have not been read and processed, the proofread intermediate code to be processed this time is acquired (step S602). The processing of step S602 is processing for reading the next intermediate code to be processed when the proofread intermediate codes stored in the intermediate file (proofread) 1034 are read in order from the beginning. Basically, it is sufficient to read and process one line at a time, but in the example shown in FIG. 10, two lines of proofread intermediate code are shown to clearly show the proofreading results.
[0082] Next, the source code proofreading processor 122 refers to the source code conversion definition file A4 and performs a process of converting the proofread intermediate code acquired in step S602 into source code in the target programming language (step S603). The process in step S603 converts each of the components separated into the meaningful components of the proofread intermediate code in the proofread intermediate file 1034 into one corresponding to the target programming language, and combines these to create source code in the target programming language. The created reconstructed source code is then recorded in the post-source file 1035.
[0083] As a result, as shown in Fig. 5(E), it is assumed that the constructed intermediate code shown in Fig. 10(a) is obtained in step S602. In this case, as shown in Fig. 5(F), in step S603, it is converted into the proofread source code of the target programming language shown in Fig. 10(b), and this is recorded in the post-proofread source file 1035. After the processing of step S603, the processing from step S601 is repeated. When it is determined in the determination processing of step S601 that all lines of the proofread intermediate code to be processed have been read and processed, the processing of Fig. 10 is exited and the processing returns to the main processing of Fig. 6. As a result, the comment recovery processing of step S7 is next executed.
[0084] [Realization of source code proofreading program] In the above-described embodiment, the source code proofreading process has been described as being performed by the control unit 102 executing the processes of the flowcharts shown in Figures 6 to 10 and the control unit 102 controlling the source code proofreading processing unit 122. However, this is not limited to this. That is, by creating a program that executes the processes of the flowcharts shown in Figures 6 to 10 in the control unit 102 and making it executable in the control unit 102, the function of the source code proofreading processing unit 122 can also be realized as a function of the control unit 102. Therefore, the program that executes the processes of the flowcharts shown in Figures 6 to 10 is an embodiment of the source code proofreading program according to the present invention.
[0085] [Applicability to previously created source code] In the above-described embodiment, it is basically possible to create source code in a target programming language that conforms to the target coding conventions by preparing newly created source code in the pre-proofreading source file 121. However, this is not limiting. Even when source code is created by reusing previously created source code and combining newly created source code, it is possible to proofread both the previously created portion and the newly created portion so that they conform to the latest coding conventions. Furthermore, even when the coding conventions themselves are revised, by preparing a coding convention definition file that conforms to the new coding conventions, it is possible to proofread previously created source code, newly created source code, or a mixture of these, in accordance with the latest coding conventions.
[0086] [Effects of the embodiment] According to the information processing device of the above-described embodiment, (1) the created source code is automatically checked against various rules described in a definition file, which reduces the time required to check the source code and prevents oversights (reduced code review work). (2) It is possible to prevent code generation errors caused by misunderstandings between the manufacturer and the code reviewer (production using uniform coding rules). (3) By performing rule checks and automatic corrections even on unchanged parts of previously developed and reused materials due to function changes, it is possible to prevent bugs in the reused source and reduce the amount of work required for manual corrections (application of coding rules to previously developed and reused materials).
[0087] In other words, source code written in various programming languages can be automatically proofread to match the set coding. Therefore, unlike when checking by human eyes, there is no risk of oversight or discrepancies in the check due to different people checking.
[0088] Moreover, rather than directly proofreading the created source code, the created source code is converted into intermediate code, and this intermediate code is then proofread to ensure that it conforms to the coding conventions. Therefore, the proofread intermediate code can be restored to source code in the original programming language, or it can be converted into source code in a programming language different from the original programming language.
[0089] Therefore, a programmer can create source code to perform the desired processing using the programming language they are good at, convert this into intermediate code, proofread it to conform to the coding conventions, and then convert it into source code in the desired programming language. It is not necessary to be familiar with all programming languages; if you are familiar with one programming language, you can create source code in various programming languages that conforms to the coding conventions.
[0090] [Modifications, etc.] In the above-described embodiment, the present invention has been described as being applied to an information processing device used by a company that develops software in response to requests from various companies. For this reason, the company-specific definition file group 105 is used. However, this is not limited to this. If coding conventions are created for each programming language, the company-specific definition file group 105 will be a programming language-specific definition file group. In other words, the definition file group 105 is not limited to being for each company, and it is sufficient if a definition file group for each coding convention is prepared in advance.
[0091] Furthermore, the coding convention definition file corresponding to coding convention definition file A3 in the case of Company A will be created according to the programming language of the source code to be obtained. In other words, if C language source code is to be obtained, the coding convention definition file will be one corresponding to C language, and if Java source code is to be obtained, the coding convention definition file will be one corresponding to Java.
[0092] Similarly, the source code conversion definition file corresponding to source code conversion definition file A4 in the case of Company A will be created according to the programming language of the source code to be obtained. That is, if you are trying to obtain C source code, the source code conversion definition file will be one that corresponds to C language, and if you are trying to obtain Java source code, the source code conversion definition file will be one that corresponds to Java.
[0093] In the above-described embodiment, the program and device according to the present invention are applied to personal computers (PCs), which are information processing devices used by employees at a company that develops software in response to requests from various companies. However, the present invention is not limited to this. For example, the present invention may be applied to a server device installed on a LAN or the Internet. That is, the created source code is transmitted to the server device, and the server device performs the processing described with reference to FIGS. 3 to 5 and 6 to 10. Then, the server device may provide the source code written in the target programming language after proofreading as a processing result.
[0094] 8 and 9 has been explained in a generalized manner. However, if there are complex coding conventions, it is possible to deal with such complex coding conventions by creating and executing a separate processing program for those coding conventions. [Explanation of symbols]
[0095] 1...information processing device, 101T...connection end, 101...LAN I / F, 102...control unit, 103...storage device, 104...operation unit, 105...company-specific definition file group, A1...comment saving rule file, A2...intermediate code conversion definition file, A3...coding convention definition file, A4...source code conversion definition file, 105A...company A definition file group, 105B...company B definition file group, 105C...company C definition file group, 106...external I / F, 106T...connection end, 107A...short-range wireless communication antenna, 10 7... short-range wireless communication unit, 108... video output processing unit, 109... display unit, 110... audio output processing unit, 111... speaker, 121... source file before proofreading, 122... source code proofreading processing unit, 123... proofread source file, 123A... source file after proofreading from company A, 123B... source file after proofreading from company B, 123C... source file after proofreading from company C, 1031... comment file, 1032... original source file, 1033... intermediate file before proofreading, 1034... intermediate file after proofreading, 1035... later source file
Claims
1. a first conversion step of converting source code written in a predetermined programming language into pre-proofreading intermediate code by referring to a first definition file that holds definition data for converting the source code into intermediate code separated into meaningful components; a second conversion step of referencing a second definition file that holds definition data for converting the unproofreaded intermediate code into proofread intermediate code that conforms to the coding conventions of a target programming language, and proofreading the unproofreaded intermediate code to convert it into the proofread intermediate code; a third conversion step of converting the proofread intermediate code into proofread source code in a target programming language by referring to a third definition file that holds definition data for converting the proofread intermediate code into proofread source code in a target programming language; A source code proofreading program that executes the above steps.
2. 2. The source code proofreading program according to claim 1, The first definition file, the second definition file, and the third definition file correspond to different programming languages. A source code proofreading program.
3. 3. The source code proofreading program according to claim 1, the first definition file, the second definition file, and the third definition file are provided for each trading partner, a supplier acceptance step for accepting a supplier selection input; In the first conversion step, the second conversion step, and the third conversion step, the first definition file, the second definition file, and the third definition file are used according to the business partner accepted through the business partner acceptance step. A source code proofreading program.
4. a first definition file that stores definition data for converting source code written in a predetermined programming language into intermediate code separated into meaningful components; a first conversion means for converting the source code written in a predetermined programming language into pre-proofreading intermediate code by referring to the first definition file; a second definition file that stores definition data for converting the unproofread intermediate code into proofread intermediate code that conforms to the coding conventions of a target programming language; a second conversion means for referencing the second definition file, proofreading the pre-proofreading intermediate code, and converting it into the proofreading intermediate code; a third definition file that stores definition data for converting the proofread intermediate code into proofread source code in a target programming language; a third conversion means for converting the proofread intermediate code into a proofread source code in a target programming language by referring to the third definition file; a source code proofreading device comprising:
Citation Information
Patent Citations
Coding rule check system
JP1999073328A
Program, information processing device and information processing method
JP2019020990A
Cited By
Software conversion generation system, program, and control method for the software conversion generation system.
JP7870997B1