Software system reconstruction method and device, equipment and medium

Generate abstract syntax trees and shadow directory mechanisms through the compiler, and automatically refactor the software system, solving the time-consuming and error-prone problems in traditional methods, and achieving efficient and accurate software system reconstruction, suitable for large-scale and complex refactoring task.

CN119271206APending Publication Date: 2025-01-07JINAN INSPUR DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411328250.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-23
Publication Date
2025-01-07

AI Technical Summary

Technical Problem

Traditional software system reconstruction methods require developers to check and modify the code line by line, which is time-consuming and labor-intensive, and error-prone. In the reconstruction process, it may cause interruptions due to compilation errors, which will affect efficiency, especially for large-scale code migration or complex architecture adjustments. Manual reconstruction is almost impossible to complete, seriously affecting the improvement of software quality.

Method used

The compiler obtains the source code directory of the software system, generates an abstract syntax tree, extracts matching information, obtains the initial shadow directory, automatically refactors based on the matching information and shadow directory, generates the target shadow directory, and replaces it with the source code directory to realize the software system automated reconstruction.

Benefits of technology

Improve the efficiency and accuracy of reconstruction, reduce human errors, ensure the stability of the reconstruction process, be able to cope with complex reconstruction tasks, and improve software quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119271206A_ABST
    Figure CN119271206A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a software system reconstruction method and device, equipment and a medium, and is applied to a compiler, the method comprises the following steps: in a software system reconstruction process, in response to a reconstruction instruction for a software system, obtaining a source code directory of the software system; compiling the source code directory to generate a corresponding abstract syntax tree, and extracting matching information related to a reconstruction target from the abstract syntax tree; obtaining an initial shadow catalogue of the source code catalogue, reconstructing the source code catalogue according to the initial shadow catalogue and the extracted matching information, and generating a target shadow catalogue; and finally, replacing the source code catalog with the target shadow catalog, completing reconstruction of the software system, obtaining a reconstructed target software system, automatically reconstructing the software system through a compiler, generating matching information accurately matched with a reconstruction target by utilizing an abstract syntax tree, and automatically and efficiently reconstructing the software system in combination with a shadow catalog mechanism. And the accuracy and safety of the reconstruction process are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer software technology, and in particular to a software system reconstruction method, a software system reconstruction device, an electronic device and a computer-readable storage medium. Background Art

[0002] With the continuous changes in business needs and the continuous advancement of technology, software systems are also constantly evolving and becoming more complex. In order to meet these challenges, software system refactoring has become a key means to improve software quality and maintain system flexibility and maintainability.

[0003] However, traditional software system refactoring methods require developers to check and modify the code line by line, which is not only time-consuming and labor-intensive, but also prone to errors. In addition, during the refactoring process, if modifications are made directly in the working directory, the refactoring may be interrupted due to compilation errors, affecting the efficiency of the refactoring. In addition, for some specific refactoring tasks, such as large-scale code migration or complex architecture adjustments, manual refactoring is almost impossible to complete, which seriously affects the implementation effect of software system refactoring and hinders the continuous improvement of software quality. Summary of the invention

[0004] In view of the above problems, an embodiment of the present invention provides a software system reconstruction method, device, electronic device and storage medium to overcome the above problems or at least partially solve the above problems.

[0005] The embodiment of the present invention discloses a software system reconstruction method, which is applied to a compiler. The method includes:

[0006] In response to a refactoring instruction for a software system, obtaining a source code directory of the software system;

[0007] Compile the source code directory to obtain an abstract syntax tree corresponding to the source code directory, and determine matching information corresponding to the abstract syntax tree;

[0008] Obtaining an initial shadow directory for the source code directory, and reconstructing the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory;

[0009] The target shadow directory replaces the source code directory to reconstruct the software system and obtain a reconstructed target software system.

[0010] Optionally, the source code directory includes source code of the software system, and the determining matching information corresponding to the abstract syntax tree includes:

[0011] Analyze the abstract syntax tree to obtain syntax structure information of the source code;

[0012] A reconstruction target for the source code is obtained, and the matching information is generated in combination with the grammatical structure information of the source code.

[0013] Optionally, the reconstructing the source directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory includes:

[0014] Identify the source code directory according to the matching information, and obtain the reconstructed code in the source code directory;

[0015] Obtaining a refactoring operation for the refactored code;

[0016] The reconstruction operation is redirected to the initial shadow directory to obtain the target shadow directory.

[0017] Optionally, the compiler includes at least a source code manager, and the reconstructing the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory includes:

[0018] Modifying the source code manager to obtain a shadow directory source code manager, wherein the shadow directory source code manager is used to identify the initial shadow directory and redirect the reconstruction operation to the initial shadow directory;

[0019] Obtaining preset refactoring information, where the refactoring information is used to determine a refactoring operation for the refactoring code;

[0020] Integrate the matching information, the shadow directory source code manager, and the reconstruction information to obtain a target compiler plug-in;

[0021] Obtaining compilation parameters for the source code directory, and adding the target compiler plug-in to the compilation parameters to obtain target compilation parameters;

[0022] The reconstructed code in the source code directory is identified according to the target compilation parameter, and a reconstructing operation for the reconstructed code is obtained, and the reconstructing operation is redirected to the initial shadow directory to obtain the target shadow directory.

[0023] Optionally, after determining the matching information corresponding to the abstract syntax tree, the method further includes:

[0024] The correctness of the matching information is verified.

[0025] Optionally, before replacing the source code directory with the target shadow directory to reconstruct the software system, the method further includes:

[0026] The target shadow directory is analyzed to determine whether to replace the source code directory with the target shadow directory to reconstruct the software system.

[0027] Optionally, analyzing the target shadow directory to determine whether to replace the source code directory with the target shadow directory to reconstruct the software system includes:

[0028] Compile the target shadow directory to obtain a compilation result;

[0029] Evaluate the target shadow directory to obtain an evaluation result;

[0030] If the compilation result is successful, and the evaluation result meets the preset evaluation index, the target shadow directory replaces the source code directory to reconstruct the software system to obtain the reconstructed target software system.

[0031] The embodiment of the present invention further discloses a software system reconstruction device, which is applied to a compiler, and the device comprises:

[0032] A source code directory acquisition module, used to obtain a source code directory of the software system in response to a reconstruction instruction for the software system;

[0033] A matching information acquisition module, used to compile the source code directory, obtain an abstract syntax tree corresponding to the source code directory, and determine matching information corresponding to the abstract syntax tree;

[0034] A target shadow directory generation module is used to obtain an initial shadow directory for the source code directory, and reconstruct the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory;

[0035] The software system reconstruction module is used to replace the source code directory with the target shadow directory to reconstruct the software system and obtain the reconstructed target software system.

[0036] The embodiment of the present invention further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0037] The memory is used to store computer programs;

[0038] The processor is used to implement the method described in the embodiment of the present invention when executing the program stored in the memory.

[0039] The embodiment of the present invention further discloses a computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the method described in the embodiment of the present invention.

[0040] The embodiments of the present invention include the following advantages:

[0041] In an embodiment of the present invention, during the reconstruction of a software system, in response to a reconstruction instruction for the software system, a source code directory of the software system is obtained; the source code directory is compiled to generate a corresponding abstract syntax tree, and matching information related to the reconstruction target is extracted therefrom; then an initial shadow directory of the source code directory is obtained, and the source code directory is reconstructed according to the initial shadow directory and the extracted matching information to generate a target shadow directory; finally, the source code directory is replaced by the target shadow directory to complete the reconstruction of the software system and obtain the reconstructed target software system, the software system is automatically reconstructed by the compiler, the abstract syntax tree is used to generate matching information that accurately matches the reconstruction target, and combined with the shadow directory mechanism, the software system is automatically and efficiently reconstructed, ensuring the accuracy and security of the reconstruction process. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0043] Figure 1 is a flowchart of the steps of a software system reconstruction method provided by an embodiment of the present invention;

[0044] Figure 2 is a structural block diagram of a software system reconstruction device provided by an embodiment of the present invention;

[0045] Figure 3 is a block diagram of an electronic device provided in an embodiment of the present invention;

[0046] Figure 4 is a schematic diagram of a computer-readable storage medium provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0048] As an example, with respect to software system refactoring, the prior art is to manually refactor the software system, and developers need to check and manually modify the code line by line. The refactoring efficiency is low and errors are easily introduced, affecting the code quality. In addition, the prior art is to directly modify the working directory of the software system, which may cause compilation errors and interrupt the refactoring process. In addition, the manual refactoring method is not applicable to large-scale code migration or complex architecture adjustments, which seriously affects the implementation effect of software system refactoring and hinders the continuous improvement of software quality.

[0049] In this regard, the advantages of the present invention over the prior art are that the present invention realizes automatic reconstruction of the software system through a compiler, uses an abstract syntax tree to generate matching information that accurately matches the reconstruction target, and combines a shadow directory mechanism to avoid interruptions caused by compilation errors during the reconstruction process, thereby ensuring the stability of the reconstruction process, improving the efficiency and accuracy of reconstruction, reducing human errors, and being able to cope with complex reconstruction tasks, thereby improving software quality.

[0050] Reference Figure 1 , shows a flowchart of the steps of a software system reconstruction method provided in an embodiment of the present invention, which is applied to a compiler and may specifically include the following steps:

[0051] Step 101: In response to a refactoring instruction for a software system, a source code directory of the software system is obtained;

[0052] In an embodiment of the present invention, after receiving a reconstruction instruction for a software system to be reconstructed, the source code directory of the software system is first obtained. The source code directory contains all source code files and related configuration files of the software system. By obtaining the source code directory, it can be ensured that the reconstruction is a complete code base for the entire software system. Furthermore, through the source code directory, it can be clarified which source code in the software system needs to be reconstructed, that is, by obtaining the source code directory of the software system, the reconstruction starting point of the software system is clarified.

[0053] As an example, an embodiment of the present invention is applied to a compiler, wherein the compiler is a clang compiler, and the software system to be reconstructed is compiled by the clang compiler to obtain a source code directory of the software system. Specifically, the clang compiler compiles the software system and generates a compile_commands.json database, which includes the source code directory of the software system and the compilation commands and parameters of each source code file.

[0054] Step 102: compile the source code directory to obtain an abstract syntax tree corresponding to the source code directory, and determine matching information corresponding to the abstract syntax tree;

[0055] In an embodiment of the present invention, the obtained source code directory is compiled to generate a corresponding abstract syntax tree, and key information of the source code is obtained from the abstract syntax tree to determine matching information, and then the reconstructed target in the source code directory, that is, the code to be reconstructed, can be identified through the matching information.

[0056] In a preferred embodiment of the present invention, the source code directory includes the source code of the software system, and step 102, determining the matching information corresponding to the abstract syntax tree, includes:

[0057] Analyze the abstract syntax tree to obtain syntax structure information of the source code;

[0058] A reconstruction target for the source code is obtained, and the matching information is generated in combination with the grammatical structure information of the source code.

[0059] In the embodiment of the present invention, the source code directory includes all the source codes of the software system, and the abstract syntax tree represents the syntax structure of the source code through a tree structure, and then analyzes the syntax structure of the source code to extract the key information required for reconstruction, and generates matching information, and the code that needs to be reconstructed in the source code directory can be identified through the matching information. In the embodiment of the present invention, the structure and semantics of the code are accurately identified through the abstract syntax tree, so as to accurately determine the reconstruction target and improve the accuracy of reconstruction.

[0060] As an example, the clang compiler compiles the source directory and executes clang++-Xclang-ast-dump-fsyntax-only <filename>Instruction, output the corresponding abstract syntax tree, analyze the abstract syntax tree, obtain the source code structure and node relationship, and then determine the code points to be reconstructed based on the node relationship of the abstract syntax tree to generate matching information, so as to accurately identify the code nodes that need to be reconstructed in the source code through matching information.

[0061] In a preferred embodiment of the present invention, after determining the matching information corresponding to the abstract syntax tree in step 102, the method further includes:

[0062] The correctness of the matching information is verified.

[0063] In the embodiment of the present invention, after the matching information is obtained, the correctness of the matching information is also verified to ensure that the extracted matching information can accurately reflect the reconstruction target, thereby ensuring the correct execution of subsequent reconstruction operations. Specifically, the correctness of the matching information can be verified by an automated testing tool or the matching information can be code reviewed to find potential problems, which is not limited by the present invention.

[0064] As an example, the clang compiler is paired with the clang-query tool. The matching information is input into the clang-query tool for execution and output. The output result includes all matching items. All matching items are used to verify whether the code that needs to be refactored can be correctly matched.

[0065] Step 103: obtaining an initial shadow directory for the source code directory, and reconstructing the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory;

[0066] In an embodiment of the present invention, an initial shadow directory for a source code directory is obtained. The shadow directory is essentially a copy of the source code directory and contains all the files in the source code directory. Specifically, the shadow directory can be obtained by copying the source code directory, and the source code directory is further reconstructed through the shadow directory and matching information to obtain a reconstructed shadow directory. Specifically, the code to be reconstructed in the source code directory is identified through matching information, and then the reconstruction operation is performed in the initial shadow directory to obtain a reconstructed target shadow directory. The target shadow directory contains the reconstructed code. The embodiment of the present invention avoids directly modifying the source code directory by using the shadow directory as a temporary workspace for the reconstruction operation, thereby ensuring the security and stability of the reconstruction process.

[0067] In a preferred embodiment of the present invention, in step 103, the source code directory is reconstructed according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory, including:

[0068] Identify the source code directory according to the matching information, and obtain the reconstructed code in the source code directory;

[0069] Obtaining a refactoring operation for the refactored code;

[0070] The reconstruction operation is redirected to the initial shadow directory to obtain the target shadow directory.

[0071] In an embodiment of the present invention, a source code directory is identified based on matching information, and the code that needs to be reconstructed in the source code directory, i.e., the code to be reconstructed, is obtained, and then a reconstructing operation for the code to be reconstructed is determined. The reconstructing operation is used to modify the code. The specific reconstructing operation may be to modify function calls, variable definitions, type declarations, etc. The reconstructing operation for the source code directory is further redirected and applied to the initial shadow directory to generate a target shadow directory. The target shadow directory is the reconstructed directory corresponding to the source code directory, so as to realize the use of the shadow directory as a temporary workspace for the reconstructing operation, avoid directly modifying the source code directory, and ensure the security and stability of the reconstruction process.

[0072] In a preferred embodiment of the present invention, the compiler at least includes a source code manager, and in step 103, the source code directory is reconstructed according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory, including:

[0073] Modifying the source code manager to obtain a shadow directory source code manager, wherein the shadow directory source code manager is used to identify the initial shadow directory and redirect the reconstruction operation to the initial shadow directory;

[0074] Obtaining preset refactoring information, where the refactoring information is used to determine a refactoring operation for the refactoring code;

[0075] Integrate the matching information, the shadow directory source code manager, and the reconstruction information to obtain a target compiler plug-in;

[0076] Obtaining compilation parameters for the source code directory, and adding the target compiler plug-in to the compilation parameters to obtain target compilation parameters;

[0077] The reconstructed code in the source code directory is identified according to the target compilation parameter, and a reconstructing operation for the reconstructed code is obtained, and the reconstructing operation is redirected to the initial shadow directory to obtain the target shadow directory.

[0078] In an embodiment of the present invention, the compiler also includes a source code manager, and by rewriting the function of the source code manager, it can identify the initial shadow directory and redirect the reconstruction operation to the initial shadow directory to obtain a shadow directory source code manager for managing the code version and status during the reconstruction process, and obtain reconstruction information for determining the reconstruction operation for the reconstructed code, and further integrate the matching information, the shadow directory source code manager and the reconstruction information to generate a target compiler plug-in, and add the target compiler plug-in to the compilation parameters of the source code directory, and the compilation parameters refer to various parameters required when compiling the code in the source code directory, such as the compilation instructions of the code, and then the target compiler plug-in can identify the reconstructed code in the source code directory based on the compilation parameters according to the matching information, and then determine the corresponding reconstruction operation according to the reconstruction information, and apply the reconstruction operation to the initial shadow directory to generate the target shadow directory. In the embodiment of the present invention, the code points that need to be reconstructed in the source code directory are accurately identified through matching information to avoid omissions or misoperations, and through the shadow directory mechanism, the reconstruction operation can be performed without affecting the source code directory, ensuring the security and stability of the reconstruction process, and the reconstruction can be automatically performed based on the target compiler plug-in, which is suitable for large-scale code migration or complex architecture adjustments, and realizes automated, efficient and secure software system reconstruction.

[0079] In a preferred embodiment of the present invention, before redirecting the refactoring operation to the initial shadow directory to refactor the initial shadow directory, a static analysis tool can be used to detect potential problems in the code before refactoring, generate a problem report, and modify and improve the preset refactoring rules according to the problem report, and then perform the refactoring operation according to the improved refactoring rules to automatically repair; and after redirecting the refactoring operation to the initial shadow directory to refactor the initial shadow directory and obtaining the target shadow directory, the refactored code can be detected again through static analysis to ensure that no new problems are introduced.

[0080] As an example, the clang compiler also includes the Clang-Tidy tool. Before refactoring, the Clang-Tidy tool is used to detect potential problems in the code and generate a problem report. Based on the problem report, the refactoring rules are modified and improved. During the refactoring process, Clang-Tidy automatically performs the refactoring operation according to the refactoring rules, generates the refactored code, and detects the refactored code again to ensure that no new problems are introduced.

[0081] Step 104: Replace the source code directory with the target shadow directory to reconstruct the software system and obtain a reconstructed target software system;

[0082] In an embodiment of the present invention, after obtaining the reconstructed target shadow directory, the reconstructed target shadow directory replaces the source code directory to complete the reconstruction of the software system, and finally obtain the reconstructed target software system, ensuring that the reconstructed code is correctly applied to the software system to complete the reconstruction process of the entire software system.

[0083] In a preferred embodiment of the present invention, before step 104, replacing the source code directory with the target shadow directory to reconstruct the software system and obtaining the reconstructed target software system, the process further includes:

[0084] The target shadow directory is analyzed to determine whether to replace the source code directory with the target shadow directory to reconstruct the software system.

[0085] In an embodiment of the present invention, before replacing the reconstructed shadow directory with the source code directory to realize the reconstruction of the software system, the shadow directory will also be analyzed, and it is determined whether to replace the source code directory with the target shadow directory based on the analysis results. If the analysis results show that the reconstructed code has passed all necessary verification and analysis and no new problems have been introduced, the replacement can be performed. If the analysis results show that there are problems with the reconstructed code, further debugging and repair are required until the problem is solved before replacement is performed to ensure that the reconstructed software system does not introduce potential problems.

[0086] In a preferred embodiment of the present invention, analyzing the target shadow directory to determine whether to replace the source code directory with the target shadow directory to reconstruct the software system includes:

[0087] Compile the target shadow directory to obtain a compilation result;

[0088] Evaluate the target shadow directory to obtain an evaluation result;

[0089] If the compilation result is successful, and the evaluation result meets the preset evaluation index, the target shadow directory replaces the source code directory to reconstruct the software system to obtain the reconstructed target software system.

[0090] In an embodiment of the present invention, after obtaining the reconstructed target shadow directory, all files in the target shadow directory will be compiled and evaluated. When the compilation result is successful, it proves that all files can be successfully compiled and no new compilation errors are introduced. The target shadow directory is further evaluated in detail to ensure that the reconstructed code has passed all necessary verification and analysis. If the evaluation result also meets the preset evaluation index, the target shadow directory replaces the source code directory to reconstruct the software system and obtain the reconstructed target software system. The specific preset evaluation index may include test pass rate, code review pass rate, performance index, safety index, etc. The embodiment of the present invention verifies and judges the reconstructed shadow directory to improve the accuracy and efficiency of the software system reconstruction, and also ensures the security and stability of the reconstruction process.

[0091] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0092] Reference Figure 2 , shows a structural block diagram of a software system reconstruction device provided in an embodiment of the present invention, which may specifically include the following modules:

[0093] A source code directory acquisition module 201, for acquiring a source code directory of the software system in response to a refactoring instruction for the software system;

[0094] A matching information acquisition module 202 is used to compile the source code directory, obtain an abstract syntax tree corresponding to the source code directory, and determine matching information corresponding to the abstract syntax tree;

[0095] A target shadow directory generating module 203 is used to obtain an initial shadow directory for the source directory, and reconstruct the source directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory;

[0096] The software system reconstruction module 204 is used to replace the source code directory with the target shadow directory to reconstruct the software system and obtain a reconstructed target software system.

[0097] In a preferred embodiment of the present invention, the source code directory includes the source code of the software system, and the matching information acquisition module 202 includes:

[0098] An abstract syntax tree analysis submodule is used to analyze the abstract syntax tree to obtain syntax structure information of the source code;

[0099] The matching information generating submodule is used to obtain the reconstruction target for the source code and generate the matching information in combination with the grammatical structure information of the source code.

[0100] In a preferred embodiment of the present invention, the target shadow directory generation module 203 includes:

[0101] A reconstructed code identification submodule, used to identify the source code directory according to the matching information, and obtain the reconstructed code in the source code directory;

[0102] A refactoring operation determination submodule, used to obtain a refactoring operation for the refactored code;

[0103] The redirection submodule is used to redirect the reconstruction operation to the initial shadow directory to obtain the target shadow directory.

[0104] In a preferred embodiment of the present invention, the target shadow directory generation module 203 specifically includes:

[0105] A source code manager modification submodule, used to modify the source code manager to obtain a shadow directory source code manager, wherein the shadow directory source code manager is used to identify the initial shadow directory and redirect the reconstruction operation to the initial shadow directory;

[0106] A refactoring operation determination submodule, used for obtaining preset refactoring information, wherein the refactoring information is used for determining a refactoring operation for the refactored code;

[0107] A custom plug-in submodule, used to integrate the matching information, the shadow directory source code manager and the reconstruction information to obtain a target compiler plug-in;

[0108] A compilation parameter submodule, used to obtain compilation parameters for the source code directory, and add the target compiler plug-in to the compilation parameters to obtain target compilation parameters;

[0109] The redirection submodule is used to identify the reconstructed code in the source code directory according to the target compilation parameters, obtain the reconstructed operation for the reconstructed code, and redirect the reconstructed operation to the initial shadow directory to obtain the target shadow directory.

[0110] In a preferred embodiment of the present invention, the device further comprises:

[0111] The matching information verification module is used to verify the correctness of the matching information.

[0112] In a preferred embodiment of the present invention, the device further comprises:

[0113] The reconstruction judgment module is used to analyze the target shadow directory and determine whether to replace the source code directory with the target shadow directory to reconstruct the software system.

[0114] In a preferred embodiment of the present invention, the reconstruction judgment module specifically includes:

[0115] A compiling submodule, used to compile the target shadow directory and obtain a compilation result;

[0116] An evaluation submodule, used to evaluate the target shadow directory and obtain an evaluation result;

[0117] The judgment submodule is used to replace the source code directory with the target shadow directory to reconstruct the software system if the compilation result is successful and the evaluation result meets the preset evaluation index, so as to obtain the reconstructed target software system.

[0118] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0119] In addition, an embodiment of the present invention further provides an electronic device, such as Figure 3 As shown, it includes a processor 301, a communication interface 302, a memory 303 and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304.

[0120] Memory 303, used for storing computer programs;

[0121] The processor 301 is used to implement the method described in the above embodiment when executing the program stored in the memory 303.

[0122] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0123] The communication interface is used for communication between the above terminal and other devices.

[0124] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0125] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0126] like Figure 4 As shown, in another embodiment provided by the present invention, a computer-readable storage medium 401 is further provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the method described in the above embodiment.

[0127] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0128] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0129] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0130] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.< / filename>

Claims

1. A software system reconstruction method, characterized in that: Applied to a compiler, the method comprises: In response to a refactoring instruction for a software system, obtaining a source code directory of the software system; Compile the source code directory to obtain an abstract syntax tree corresponding to the source code directory, and determine matching information corresponding to the abstract syntax tree; Obtaining an initial shadow directory for the source code directory, and reconstructing the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory; The target shadow directory replaces the source code directory to reconstruct the software system and obtain a reconstructed target software system.

2. The method according to claim 1, characterized in that: The source code directory includes source code of the software system, and the determining matching information corresponding to the abstract syntax tree includes: Analyze the abstract syntax tree to obtain syntax structure information of the source code; A reconstruction target for the source code is obtained, and the matching information is generated in combination with the grammatical structure information of the source code.

3. The method according to claim 1, characterized in that: The reconstructing the source directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory includes: Identify the source code directory according to the matching information, and obtain the reconstructed code in the source code directory; Obtaining a refactoring operation for the refactored code; The reconstruction operation is redirected to the initial shadow directory to obtain the target shadow directory.

4. The method according to claim 3, characterized in that The compiler at least includes a source code manager, and the reconstructing the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory includes: Modifying the source code manager to obtain a shadow directory source code manager, wherein the shadow directory source code manager is used to identify the initial shadow directory and redirect the reconstruction operation to the initial shadow directory; Obtaining preset refactoring information, where the refactoring information is used to determine a refactoring operation for the refactoring code; Integrate the matching information, the shadow directory source code manager, and the reconstruction information to obtain a target compiler plug-in; Obtaining compilation parameters for the source code directory, and adding the target compiler plug-in to the compilation parameters to obtain target compilation parameters; The reconstructed code in the source code directory is identified according to the target compilation parameter, and a reconstructing operation for the reconstructed code is obtained, and the reconstructing operation is redirected to the initial shadow directory to obtain the target shadow directory.

5. The method according to claim 1, characterized in that After determining the matching information corresponding to the abstract syntax tree, the method further includes: The correctness of the matching information is verified.

6. The method according to claim 1, characterized in that Before replacing the source code directory with the target shadow directory to reconstruct the software system, the method further includes: The target shadow directory is analyzed to determine whether to replace the source code directory with the target shadow directory to reconstruct the software system.

7. The method according to claim 6, characterized in that The analyzing the target shadow directory to determine whether to replace the source code directory with the target shadow directory to reconstruct the software system includes: Compile the target shadow directory to obtain a compilation result; Evaluate the target shadow directory to obtain an evaluation result; If the compilation result is successful, and the evaluation result meets the preset evaluation index, the target shadow directory replaces the source code directory to reconstruct the software system to obtain the reconstructed target software system.

8. A software system reconstruction device, characterized in that: Applied to a compiler, the device comprises: A source code directory acquisition module, used to obtain a source code directory of the software system in response to a reconstruction instruction for the software system; A matching information acquisition module, used to compile the source code directory, obtain an abstract syntax tree corresponding to the source code directory, and determine matching information corresponding to the abstract syntax tree; A target shadow directory generation module is used to obtain an initial shadow directory for the source code directory, and reconstruct the source code directory according to the initial shadow directory and the matching information to obtain a corresponding target shadow directory; The software system reconstruction module is used to replace the source code directory with the target shadow directory to reconstruct the software system and obtain the reconstructed target software system.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the method according to any one of claims 1 to 7 when executing the program stored in the memory.

10. A computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 7.