A fast build system based on automatic code generation
Through static analysis of historical code and comprehensive analysis of user input information, code that meets the needs is generated, which solves the problem of increased construction time in the existing technology and improves the efficiency and accuracy of code generation.
Patent Information
- Application Number
- CN202410832291.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-26
AI Technical Summary
Existing automated code generation tools and frameworks require too much existing technology overlay when building code, resulting in increased build time and reduced build efficiency.
Code metadata information is obtained through static analysis of historical code, and comprehensive analysis is performed based on user input information and code environment information to generate code that meets the needs, including a static analysis module, a template generation module and a code generation module. The static analysis module is used to obtain Code metadata, the template generation module generates code templates, and the code generation module automatically generates code based on user needs and code characteristics.
It improves the efficiency of code generation, can more accurately determine user needs and code characteristics, generates code that meets the needs, adapts to the development environment and needs, and improves construction efficiency.
Smart Images

Figure CN118377472B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code development, and in particular to a rapid construction system based on automatic code generation. Background Art
[0002] With the continuous development of software development, rapid construction and efficient development of code have become urgent needs.
[0003] There are already some automated code generation tools and frameworks, such as template engines and code generators, which generate code through predefined templates or rules. In addition, in order to adapt to different development environments and requirements, too many existing technologies need to be superimposed to achieve this goal in the process, which invisibly greatly increases the build time, which undoubtedly reduces the build efficiency.
[0004] Therefore, the present invention introduces a rapid construction system based on automatic code generation. Summary of the invention
[0005] The present invention provides a rapid construction system based on automatic code generation, which is used to obtain code metadata information by statically analyzing historical codes, and to perform comprehensive analysis in combination with user input information and code environment information, so as to more accurately determine user needs and code features, thereby generating codes that meet the needs, and facilitating improving the efficiency of code generation on the basis of adapting to the development environment and needs.
[0006] The present invention provides a rapid construction system based on automatic code generation, comprising:
[0007] Static analysis module: performs static analysis on historical codes in the code base to obtain code metadata information;
[0008] Template generation module: generates several code templates based on code metadata information;
[0009] Information analysis module: analyzes user input information and input environment, and determines user needs and code environment information;
[0010] Code generation module: determines the code features to be generated based on user needs, and performs template matching from several code templates based on the code features to automatically generate the required code based on the matching templates and code environment information.
[0011] The present invention provides a rapid construction system based on automatic code generation, a static analysis module, comprising:
[0012] Preprocessing unit: extracts historical codes from the code base and performs code preprocessing to obtain several code syntax structures;
[0013] Static analysis unit: performing a first static analysis on each code syntax structure to obtain code structure metadata, and at the same time, performing a second static analysis on each code syntax structure to obtain code measurement metadata;
[0014] A code metadata acquisition unit is configured to obtain code metadata information based on the code structure metadata and the code metric metadata.
[0015] The present invention provides a rapid construction system based on automatic code generation, a preprocessing unit, comprising:
[0016] A code division subunit: dividing the historical code into a plurality of code segments of a preset size;
[0017] Analyzer selection subunit: based on the programming language type of the code base, selects the corresponding lexical analyzer from the preset type-analyzer database;
[0018] Initial splitting subunit: performs initial splitting on all code snippets based on the corresponding lexical analyzer, obtains the code sequence of each code snippet, and splits the code sequence into several sequence regions again;
[0019] Structure acquisition subunit: obtains the code syntax structure of each code fragment based on the syntax rule of each sequence region, wherein each code fragment corresponds to a code syntax structure.
[0020] The present invention provides a rapid construction system based on automatic code generation, a static analysis unit, comprising:
[0021] The first static analysis subunit: based on the node type of each structure node in the code syntax structure, obtains the access method of each structure node from the type-access database, and then performs traceability access on the corresponding structure node based on the access method to extract the node attribute information of the corresponding structure node;
[0022] Code structure subunit: Analyze the node attribute information of all structure nodes in each code syntax structure to construct code structure metadata;
[0023] The second static analysis subunit: performs control flow analysis on each code syntax structure and determines several code quality indicators;
[0024] Code measurement subunit: Based on several code quality indicators corresponding to each code syntax structure, determine the corresponding code measurement metadata.
[0025] The present invention provides a rapid construction system based on automatic code generation, wherein the second static analysis subunit comprises:
[0026] Control flow graph generation block: performs structural analysis on each code syntax structure to generate the corresponding control flow graph;
[0027] Data flow analysis block: performs data flow analysis on the control flow graph, and combines the data flow analysis results according to preset rules to obtain several code analysis arrays;
[0028] Indicator acquisition block: Analyze several code analysis arrays to determine several code quality indicators.
[0029] The present invention provides a rapid construction system based on automatic code generation, an indicator acquisition block, including:
[0030] Frame selection sub-block: input the array elements in each code analysis array and the corresponding control flow graph into the frame selection model to obtain the frame selection flow graph of the corresponding code analysis array;
[0031] Calculation sub-block: calculates the complexity of the corresponding code analysis array based on the box selection flow graph;
[0032] ; Among them, N01 corresponds to the number of control edges in the box selection flow graph of the code analysis array, N02 corresponds to the number of nodes in the box selection flow graph of the code analysis array, N03 corresponds to the number of splits of the complete flow line in the box selection flow graph of the code analysis array, and F corresponds to the complexity of the code analysis array; represents the total number of nodes involved in the j1th complete process line, Indicates the number of control edges corresponding to the maximum connection of a single node in the j1th complete process line;
[0033] Array building sub-block: builds the analysis factor array of the matched code analysis array based on the corresponding box selection flow graph;
[0034] ;in, Represents the analysis factor combination of the code analysis array matched by the corresponding box-selected flow graph; Indicates the number of simple structures in the corresponding box selection flow graph, Indicates the number of loop structures in the corresponding box selection flow graph, Indicates the number of complex structures in the corresponding box selection flow graph, Represents the weight of the complete flow line in the corresponding box selection flow graph, Represents the simple structural weight in the corresponding box selection flow graph, Represents the weight of the loop structure in the corresponding box selection flow graph, Represents the weight of the complex structure in the corresponding box selection flow graph;
[0035] Function analysis sub-block: performs function analysis on the box-selected flow graph of the corresponding code analysis array, and calculates the function call depth and nesting level of the corresponding code analysis array;
[0036] ;in, Indicates the function call depth of the corresponding code analysis array, Indicates the function call depth of the j2th function involved in the corresponding code analysis array, Indicates the number of function calls of the j2th function involved in the corresponding code analysis array, Indicates the function call relationship weight of the j2th function involved in the corresponding code analysis array, Indicates the function complexity weight of the j2th function involved in the corresponding code analysis array, Indicates the total number of functions involved in the corresponding code analysis array. Indicates the function operation depth of the j2th function involved in the corresponding code analysis array; Indicates the actual execution end time of the function analysis of the j2th function involved in the corresponding code analysis array; Indicates the actual execution start time of the function analysis of the j2th function involved in the corresponding code analysis array; Indicates the estimated execution time of the j2th function involved in the corresponding code analysis array;
[0037] ;in, Indicates the number of nesting levels determined by the function analysis results, Indicates the number of loop nesting levels of the j-th loop statement based on the function analysis result, Indicates the number of loops of the jth loop statement based on the function analysis result, represents the weight of the number of nested layers of the jth loop statement based on the function analysis result, represents the cyclomatic complexity weight of the jth loop statement based on the function analysis result, Indicates the total number of loop statements based on function analysis results;
[0038] Indicator determination sub-block: Based on each analysis array factor, function call depth, and nesting level, determine the code quality indicator of the corresponding array to be analyzed.
[0039] The present invention provides a rapid construction system based on automatic code generation, an information analysis module, comprising:
[0040] Text preprocessing unit: performs text preprocessing on the input information input by the user to obtain text segmentation combinations;
[0041] Keyword extraction unit: performs word segmentation similarity analysis on text word combinations based on a preset word vector model, obtains similarity analysis results between all word segments, and uses several word segments with similarities higher than a threshold as keywords for user needs;
[0042] Demand classification unit: Classify the keywords of user needs based on a predefined classification system to determine multiple classified needs;
[0043] Information determination unit: Analyzes the user's input environment and classification requirements to obtain code environment information.
[0044] The present invention provides a rapid construction system based on automatic code generation, and the predefined classification system includes: function classification, data type classification, algorithm classification, framework classification and design pattern classification.
[0045] The present invention provides a rapid construction system based on automatic code generation, which is used to obtain code metadata information by statically analyzing historical codes, and to perform comprehensive analysis in combination with user input information and code environment information, so as to more accurately determine user needs and code features, thereby generating codes that meet the needs, and facilitating improving the efficiency of code generation on the basis of adapting to the development environment and needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 It is a structural schematic diagram of a rapid construction system based on automatic code generation provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings 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.
[0049] Example 1
[0050] like Figure 1 As shown, the present invention provides a rapid construction system based on automatic code generation, comprising:
[0051] Static analysis module: performs static analysis on historical codes in the code base to obtain code metadata information;
[0052] Template generation module: generates several code templates based on code metadata information;
[0053] Information analysis module: analyzes user input information and input environment, and determines user needs and code environment information;
[0054] Code generation module: determines the code features to be generated based on user needs, and performs template matching from several code templates based on the code features to automatically generate the required code based on the matching templates and code environment information.
[0055] In this embodiment, static analysis refers to the process of analyzing the code to obtain information about the code structure, variable usage, function calls, etc., for example: extracting information such as the structure, dependency, function call relationship, etc. of historical code in the code library;
[0056] In this embodiment, code metadata information refers to data describing code features, structures, and relationships, including parameter lists, return value types, call relationship graphs, etc. of each function, such as file names, function call relationships, and variable definitions;
[0057] In this embodiment, the code template is a general code framework, which includes placeholders filled in according to specific requirements and is used to generate code for specific functions. For example, a code template for a database query includes steps such as connecting to a database, building a query statement, and executing a query, wherein specific database information and query conditions can be filled in according to actual requirements;
[0058] In this embodiment, the input information is information provided by the user to the system, such as: the function of the code to be generated, the framework and language to be used, etc.;
[0059] In this embodiment, the input environment is the operating environment information provided by the user to the system, such as the operating system, database type, etc.
[0060] In this embodiment, code environment information refers to environmental factors considered in the code generation process, including the status of the current editor, the selected file, existing code, etc., such as the language, framework, library version, etc. used, including the status of the current editor, the selected file, existing code, etc.
[0061] In this embodiment, code features refer to specific elements in user requirements that are used to describe the characteristics of generated code, such as functional points, performance requirements, exception handling, etc. For example: the user requirement is to generate a login system that supports user identity authentication, and the code features in the user requirements include user input verification, database storage of user information, etc.
[0062] The working principle and beneficial effects of the above technical solution are: the present invention provides a rapid construction system based on automatic code generation, which is used to obtain code metadata information by static analysis of historical codes, and conducts comprehensive analysis in combination with user input information and code environment information, so as to more accurately determine user needs and code features, thereby generating codes that meet the needs, and facilitating the improvement of code generation efficiency on the basis of adapting to the development environment and needs.
[0063] Example 2
[0064] The present invention provides a rapid construction system based on automatic code generation, a static analysis module, comprising:
[0065] Preprocessing unit: extracts historical codes from the code base and performs code preprocessing to obtain several code syntax structures;
[0066] Static analysis unit: performing a first static analysis on each code syntax structure to obtain code structure metadata, and at the same time, performing a second static analysis on each code syntax structure to obtain code measurement metadata;
[0067] A code metadata acquisition unit is configured to obtain code metadata information based on the code structure metadata and the code metric metadata.
[0068] In this embodiment, code preprocessing refers to preprocessing the code before static analysis, including removing comments, formatting code, generating a syntax structure tree, etc.;
[0069] In this embodiment, the code syntax structure refers to the syntax elements in the code and their organizational structure, such as functions, classes, statements, etc. For example, in the code syntax structure, a function definition, loop statement, conditional statement, etc. are all different syntax structures.
[0070] In this embodiment, the first static analysis is a preliminary analysis of the code syntax structure, mainly used to obtain basic code structure information, such as: extracting basic information such as function call relationships and file structures;
[0071] In this embodiment, the second static analysis is to further analyze the code based on the first static analysis to obtain code metric metadata, such as the number of lines, complexity, and other information;
[0072] In this embodiment, the code structure metadata includes: calling relationships between functions, file structure, etc.;
[0073] In this embodiment, the code metric metadata includes the number of lines of code, cyclomatic complexity, code duplication information, dependency information, etc.
[0074] The working principle and beneficial effects of the above technical solution are: through code preprocessing, the first static analysis and the second static analysis, the code structure metadata and code measurement metadata are obtained, the structure and measurement information of the code are fully understood, and a sufficient basis is provided for the subsequent automatic code generation. The required code is generated based on the code metadata information, thereby improving the quality and generation efficiency of the generated code.
[0075] Example 3
[0076] The present invention provides a rapid construction system based on automatic code generation, a preprocessing unit, comprising:
[0077] A code division subunit: dividing the historical code into a plurality of code segments of a preset size;
[0078] Analyzer selection subunit: based on the programming language type of the code base, selects the corresponding lexical analyzer from the preset type-analyzer database;
[0079] Initial splitting subunit: performs initial splitting on all code snippets based on the corresponding lexical analyzer, obtains the code sequence of each code snippet, and splits the code sequence into several sequence regions again;
[0080] Structure acquisition subunit: obtains the code syntax structure of each code fragment based on the syntax rule of each sequence region, wherein each code fragment corresponds to a code syntax structure.
[0081] In this embodiment, the preset type-analyzer database is a database in which lexical analyzers corresponding to different programming language types are stored. According to the programming language type of the code base, the corresponding lexical analyzer is selected for subsequent code processing. For example, if the code base uses Python language, the preset type-analyzer database contains the lexical analyzer of Python language;
[0082] In this embodiment, the lexical analyzer is a tool for splitting the code text into lexical units. It recognizes keywords, identifiers, operators, etc., and provides a basis for subsequent syntax analysis. For example, for C language, the lexical analyzer decomposes the code text into lexical units such as keywords (if, else, etc.), identifiers (variable names), operators (+, -, etc.).
[0083] In this embodiment, the initial splitting refers to performing preliminary splitting of the historical code according to the selected lexical analyzer, dividing the code text into a series of code fragments;
[0084] In this embodiment, the code sequence is a string of code sequences formed after each code segment is initially split, which is a rough code representation form;
[0085] In this embodiment, the sequence region is to split each code sequence into smaller units again to obtain several sequence regions. For example, a code snippet contains a function definition. The code sequence formed after the initial split includes the function name, parameter list, function body, etc. The sequence region is the different statements in the function body.
[0086] In this embodiment, the grammatical rules are rules that describe the grammatical structure of the code, and the specific grammatical structure of each code fragment is obtained based on the code sequence and sequence area. For example, for the C language, the grammatical rules include the grammar of function definition, the grammar of conditional statements, etc. The structure of each code fragment can be determined based on these rules.
[0087] The working principle and beneficial effects of the above technical solution are: through code division, analyzer selection, initial splitting, and structure acquisition, the historical code is converted into structured data that is easier to process, providing accurate grammatical structure information for subsequent automatic code generation, and through careful processing of the historical code, the grammatical structure of the code is understood more accurately, thereby improving the quality and accuracy of code generation. This provides a more convenient and accurate basis for subsequent automatic code generation.
[0088] Example 4
[0089] The present invention provides a rapid construction system based on automatic code generation, a static analysis unit, comprising:
[0090] The first static analysis subunit: based on the node type of each structure node in the code syntax structure, obtains the access method of each structure node from the type-access database, and then performs traceability access on the corresponding structure node based on the access method to extract the node attribute information of the corresponding structure node;
[0091] Code structure subunit: Analyze the node attribute information of all structure nodes in each code syntax structure to construct code structure metadata;
[0092] The second static analysis subunit: performs control flow analysis on each code syntax structure and determines several code quality indicators;
[0093] Code measurement subunit: Based on several code quality indicators corresponding to each code syntax structure, determine the corresponding code measurement metadata.
[0094] In this embodiment, the node type refers to the classification of each structural node in the code syntax structure. A function node, a loop node, a conditional statement node, etc. have different node types. For example, in the syntax structure of a piece of code, the node types include function definition nodes, loop statement nodes, conditional statement nodes, etc.;
[0095] In this embodiment, the type-access database is a database that stores the access method corresponding to each node type. During the static analysis process, the corresponding access method is obtained from the database according to the node type for subsequent traceability access. For example, if a node type is a function definition node, the type-access database contains access methods for obtaining attributes such as function name, parameter list, and return type.
[0096] In this embodiment, the access method is a method for obtaining node attribute information. The corresponding method is obtained from the type-access database according to the node type. For example, the following access methods are available for function node C: a method for obtaining the function name: get_function_name(), a method for obtaining the function parameter list: get_parameters(), a method for obtaining the function return type: get_return_type();
[0097] In this embodiment, source access refers to traversing and accessing the structure nodes in the code syntax structure according to the access method, and gradually obtaining the node attribute information. For example, for the function node in the above code snippet, source access is performed through the access method, and get_function_name() is used to obtain the name of the function, that is, "calculate_area", and get_parameters() is used to obtain the parameter list of the function, that is, "radius", and get_return_type() is used to obtain the return type of the function, such as a floating point type;
[0098] In this embodiment, node attribute information refers to specific information or data contained in each structural node in the code syntax structure, which is used to describe the characteristics, content or other relevant information of the node, and varies according to the type and context of the node. It is used to better understand and operate the code during static analysis and automatic code generation, such as: the name or identifier of the function, the input parameters accepted by the function and their types, the return value type of the function, and the code block or statement sequence inside the function.
[0099] In this embodiment, control flow analysis is to analyze the syntax structure of the code, determine the control flow in the code, and obtain a control flow graph, that is, the path of code execution, which is a graphical representation of code execution, where nodes represent basic blocks (a set of statements executed sequentially) and edges represent the direction of control flow;
[0100] In this embodiment, the code quality index is a standard for evaluating code quality, and information about code maintainability, readability, performance, testability and other key aspects includes code quality indicators such as number of lines, cyclomatic complexity, code duplication, etc.
[0101] The working principle and beneficial effects of the above technical solution are: through node type and type-access database, the attribute information of each structure node is extracted, and the code structure metadata is constructed by analyzing the attribute information of all structure nodes. By performing control flow analysis, code quality indicators are obtained, and then code measurement metadata is generated based on these indicators. Through detailed analysis of the code syntax structure, richer code metadata information can be obtained, including structural information and measurement information, to better support the accuracy and quality of subsequent automatic code generation, thereby improving the speed of code construction.
[0102] Example 5
[0103] The present invention provides a rapid construction system based on automatic code generation, wherein the second static analysis subunit comprises:
[0104] Control flow graph generation block: performs structural analysis on each code syntax structure to generate the corresponding control flow graph;
[0105] Data flow analysis block: performs data flow analysis on the control flow graph, and combines the data flow analysis results according to preset rules to obtain several code analysis arrays;
[0106] Indicator acquisition block: Analyze several code analysis arrays to determine several code quality indicators.
[0107] In this embodiment, structural analysis is the process of analyzing and interpreting the grammatical structure of the code to obtain the organization and hierarchy of the code. For example, for a piece of code: if (x>0) { y = x;} else { y = -x;}, structural analysis will identify the conditional statement and two branches;
[0108] In this embodiment, the control flow graph is a graphical representation of the control flow of the code, showing the control flow such as conditional statements, loops and function calls in the code. For example, for the above code snippet, the control flow graph includes two branches, which respectively represent the execution paths when the condition is true and when the condition is false.
[0109] In this embodiment, data flow analysis is a process of analyzing the transfer and change of variable values between different statements in the code, and obtaining the flow of data in the program. For example, in a piece of code, if variable a is assigned a value of 10 in a certain statement and is used by another variable b in a subsequent statement, data flow analysis will track and analyze the data flow between the two variables;
[0110] In this embodiment, the preset rules are rules predefined when performing data flow analysis, for example: putting the call depths of all functions into one array, putting the nesting levels of all loops into another array, etc.;
[0111] In this embodiment, the code analysis array is a data structure generated based on the results of data flow analysis, and contains analysis information of different parts of the code, for example; a set of code analysis arrays includes information such as the complexity of each function, the nesting depth of the loop, etc.
[0112] The working principle and beneficial effects of the above technical solution are: parsing the code syntax structure into a control flow graph through structural analysis, better obtaining the execution process and structure of the code, mapping elements such as conditional statements, loops and branches into nodes and edges in the graph through structural analysis of each code syntax structure, forming a control flow graph of the code, analyzing the control flow graph to understand the flow of variable values between different statements, and generating several code analysis arrays through the results of data flow analysis, providing detailed information on code quality indicators, and improving the quality of subsequent generated code. The efficiency and accuracy of code analysis and generation are improved.
[0113] Example 6
[0114] The present invention provides a rapid construction system based on automatic code generation, an indicator acquisition block, including:
[0115] Frame selection sub-block: input the array elements in each code analysis array and the corresponding control flow graph into the frame selection model to obtain the frame selection flow graph of the corresponding code analysis array;
[0116] Calculation sub-block: calculates the complexity of the corresponding code analysis array based on the box selection flow graph;
[0117] ; Among them, N01 corresponds to the number of control edges in the box selection flow graph of the code analysis array, N02 corresponds to the number of nodes in the box selection flow graph of the code analysis array, N03 corresponds to the number of splits of the complete flow line in the box selection flow graph of the code analysis array, and F corresponds to the complexity of the code analysis array; represents the total number of nodes involved in the j1th complete process line, Indicates the number of control edges corresponding to the maximum connection of a single node in the j1th complete process line;
[0118] Array building sub-block: builds the analysis factor array of the matched code analysis array based on the corresponding box selection flow graph;
[0119] ;in, Represents the analysis factor combination of the code analysis array matched by the corresponding box-selected flow graph; Indicates the number of simple structures in the corresponding box selection flow graph, Indicates the number of loop structures in the corresponding box selection flow graph, Indicates the number of complex structures in the corresponding box selection flow graph, Represents the weight of the complete flow line in the corresponding box selection flow graph, Represents the simple structural weight in the corresponding box selection flow graph, Represents the weight of the loop structure in the corresponding box selection flow graph, Represents the weight of the complex structure in the corresponding box selection flow graph;
[0120] Function analysis sub-block: performs function analysis on the box-selected flow graph of the corresponding code analysis array, and calculates the function call depth and nesting level of the corresponding code analysis array;
[0121] ;in, Indicates the function call depth of the corresponding code analysis array, Indicates the function call depth of the j2th function involved in the corresponding code analysis array, Indicates the number of function calls of the j2th function involved in the corresponding code analysis array, Indicates the function call relationship weight of the j2th function involved in the corresponding code analysis array, Indicates the function complexity weight of the j2th function involved in the corresponding code analysis array, Indicates the total number of functions involved in the corresponding code analysis array. Indicates the function operation depth of the j2th function involved in the corresponding code analysis array; Indicates the actual execution end time of the function analysis of the j2th function involved in the corresponding code analysis array; Indicates the actual execution start time of the function analysis of the j2th function involved in the corresponding code analysis array; Indicates the estimated execution time of the j2th function involved in the corresponding code analysis array;
[0122] ;
[0123] in, Indicates the number of nesting levels determined by the function analysis results, Indicates the number of loop nesting levels of the j-th loop statement based on the function analysis result, Indicates the number of loops of the jth loop statement based on the function analysis result, represents the weight of the number of nested layers of the jth loop statement based on the function analysis result, represents the cyclomatic complexity weight of the jth loop statement based on the function analysis result, Indicates the total number of loop statements based on function analysis results;
[0124] Indicator determination sub-block: Based on each analysis array factor, function call depth, and nesting level, determine the code quality indicator of the corresponding array to be analyzed.
[0125] In this embodiment, the graph box selection model is a model for processing array elements and corresponding control flow graphs in each code analysis array, generating a box selection flow graph, and providing a basis for subsequent complexity calculation and construction of analysis factor arrays. For example, the box selection model receives a code analysis array containing conditional statements and loops, and generates a box selection flow graph to represent the control flow relationship between these structures.
[0126] In this embodiment, the box selection flow graph is generated by a box selection model, which reflects the combination of array elements in the code analysis array and the control flow graph. It is a graphical representation of the box selection of the code structure. For example: for code segment A, the box selection flow graph shows the relationship between conditional statements, loops, and function calls.
[0127] In this embodiment, the analysis factor array is an array constructed based on the box selection flow graph, which includes various analysis factors of the corresponding code analysis array, such as the number of simple structures, the number of loop structures, etc. For example: the elements of the analysis factor array [C] include the number of simple structures, the number of loop structures, the number of complex structures, etc., reflecting various aspects of the code structure.
[0128] In this embodiment, the function call depth represents the hierarchical depth of the function call in a code analysis array, that is, the number of levels of function nesting;
[0129] In this embodiment, the nesting level indicates the nesting depth of a certain structure (such as a loop) in the code, that is, the nesting level. For example, there are two nested loops in code segment A, the first loop is nested in the main loop, and the nesting level is 2.
[0130] In this embodiment, the code quality indicators of the corresponding array to be analyzed are determined by obtaining indicators such as function call depth, cyclomatic complexity, code complexity, etc. based on each analysis array factor, function call depth, and number of nesting levels, and the above indicators are mapped to corresponding quality measurement indicators. For example, the code length is mapped to a readability indicator, the function call depth is mapped to a maintainability indicator, the number of nesting levels is mapped to a reusability indicator, etc.
[0131] The working principle and beneficial effects of the above technical solution are: by receiving the array elements and the corresponding control flow graph in each code analysis array, and generating a box selection flow graph through a specific algorithm, so as to facilitate subsequent complexity calculation and analysis factor array construction, it helps to identify important relationships in the code structure, and by constructing the analysis factor array, it provides a basis for subsequent complexity calculation.
[0132] By comprehensively considering multiple factors such as the code structure, complexity, and function call relationships, it provides a more comprehensive and in-depth code quality analysis, and improves the maintainability of the generated code while achieving rapid code construction.
[0133] Example 7
[0134] The present invention provides a rapid construction system based on automatic code generation, an information analysis module, comprising:
[0135] Text preprocessing unit: performs text preprocessing on the input information input by the user to obtain text segmentation combinations;
[0136] Keyword extraction unit: performs word segmentation similarity analysis on text word combinations based on a preset word vector model, obtains similarity analysis results between all word segments, and uses several word segments with similarities higher than a threshold as keywords for user needs;
[0137] Demand classification unit: Classify the keywords of user needs based on a predefined classification system to determine multiple classified needs;
[0138] Information determination unit: Analyzes the user's input environment and classification requirements to obtain code environment information.
[0139] In this embodiment, text preprocessing refers to cleaning and standardizing the text information input by the user;
[0140] In this embodiment, text segmentation combination refers to segmenting and combining the text according to certain rules to form a collection of words or phrases for subsequent text analysis and processing. For example, for an input text "rapidly build a system based on automatic generation of code", the text segmentation combination includes: based on, code, automatically generated, quickly, build, system, etc.
[0141] In this embodiment, the preset word vector model refers to a pre-trained word vector representation model, which is used to map words in a text into a vector space for semantic analysis and similarity calculation, such as Word2Vec, GloVe, etc.;
[0142] In this embodiment, the keywords of user needs are words with important meanings extracted from the text input by the user. For example, for the text input by the user: building an online shopping platform, the extracted keywords include: online, shopping, platform, etc.
[0143] In this embodiment, the predefined classification system refers to a set of classification standards or classification systems predefined in the system, which are used to classify and categorize user requirements.
[0144] The working principle and beneficial effects of the above technical solution are: by cleaning and standardizing the text information input by the user, ensuring that the subsequent processing and analysis can be more accurate and efficient, by segmenting and combining the text information according to the unit of words, providing basic data for the subsequent semantic analysis and keyword extraction, using the pre-trained word vector representation, and performing similarity analysis and keyword extraction, by extracting the keywords of user needs, the user's intentions and needs can be understood more accurately. It can understand the user's needs and environment more intelligently, so as to build the corresponding code more quickly and accurately.
[0145] Example 8
[0146] The present invention provides a rapid construction system based on automatic code generation, and the predefined classification system includes: function classification, data type classification, algorithm classification, framework classification and design pattern classification.
[0147] In this embodiment, the functional requirements are to classify the functional requirements mentioned by the user and determine the functional direction of the code features. For example, if the user mentions functional requirements such as database operation, file processing, image processing, etc., the requirements for generating corresponding functional codes can be determined after classification;
[0148] In this embodiment, the data type requirement is to classify the data type requirements mentioned by the user and determine the data type direction of the code feature. For example, the user mentions data types such as integers, strings, arrays, etc. After classification, the requirement to generate codes related to the corresponding data types can be determined;
[0149] In this embodiment, algorithm requirement classification is to classify the algorithm requirements mentioned by the user and determine the algorithm direction of the code feature. For example, the user may mention sorting algorithm, search algorithm, machine learning algorithm, etc. After classification, the requirements for generating corresponding algorithm codes can be determined;
[0150] In this embodiment, the framework requirement is to classify the platform or framework requirements mentioned by the user and determine the platform or framework direction of the code features. For example, the user mentioned that it is necessary to develop on the Android platform and use the TensorFlow framework for deep learning. After classification, the requirement to generate the corresponding platform or framework-related code can be determined;
[0151] In this embodiment, the design pattern requirements are to classify the design pattern requirements mentioned by the user and determine the design pattern direction of the code features. For example, the user mentioned the need to use the singleton pattern, observer pattern, etc. After classification, the requirements for generating corresponding design pattern related codes can be determined.
[0152] The working principle and beneficial effects of the above technical solution are: by classifying the requirements proposed by users and determining the direction of code features, according to the determined requirements classification, it is possible to quickly generate code that meets specific requirements, accelerate the system development and iteration process, and improve development efficiency and code quality.
[0153] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A rapid construction system based on automatic code generation, characterized in that: include: Static analysis module: performs static analysis on historical codes in the code base to obtain code metadata information; Template generation module: generates several code templates based on code metadata information; Information analysis module: analyzes user input information and input environment, and determines user needs and code environment information; Code generation module: determines the code features to be generated based on user needs, and performs template matching from a number of code templates based on the code features to automatically generate the required code based on the matching template and code environment information; Among them, the static analysis module includes: Preprocessing unit: extracts historical codes from the code base and performs code preprocessing to obtain several code syntax structures; Static analysis unit: performing a first static analysis on each code syntax structure to obtain code structure metadata, and at the same time, performing a second static analysis on each code syntax structure to obtain code measurement metadata; A code metadata acquisition unit: based on the code structure metadata and the code metric metadata, obtains code metadata information; The static analysis unit includes: The first static analysis subunit: based on the node type of each structure node in the code syntax structure, obtains the access method of each structure node from the type-access database, and then performs traceability access on the corresponding structure node based on the access method to extract the node attribute information of the corresponding structure node; Code structure subunit: Analyze the node attribute information of all structure nodes in each code syntax structure to construct code structure metadata; The second static analysis subunit: performs control flow analysis on each code syntax structure and determines several code quality indicators; Code measurement subunit: Based on several code quality indicators corresponding to each code syntax structure, determine the corresponding code measurement metadata.
2. A rapid construction system based on automatic code generation according to claim 1, characterized in that: Pre-processing unit, including: A code division subunit: dividing the historical code into a plurality of code segments of a preset size; Analyzer selection subunit: based on the programming language type of the code base, selects the corresponding lexical analyzer from the preset type-analyzer database; Initial splitting subunit: performs initial splitting on all code snippets based on the corresponding lexical analyzer, obtains the code sequence of each code snippet, and splits the code sequence into several sequence regions again; Structure acquisition subunit: obtains the code syntax structure of each code fragment based on the syntax rule of each sequence region, wherein each code fragment corresponds to a code syntax structure.
3. A rapid construction system based on automatic code generation according to claim 1, characterized in that: The second static analysis subunit includes: Control flow graph generation block: performs structural analysis on each code syntax structure to generate the corresponding control flow graph; Data flow analysis block: performs data flow analysis on the control flow graph, and combines the data flow analysis results according to preset rules to obtain several code analysis arrays; Indicator acquisition block: Analyze several code analysis arrays to determine several code quality indicators.
4. A rapid construction system based on automatic code generation according to claim 3, characterized in that: Indicator acquisition block, including: Frame selection sub-block: input the array elements in each code analysis array and the corresponding control flow graph into the frame selection model to obtain the frame selection flow graph of the corresponding code analysis array; Calculation sub-block: calculates the complexity of the corresponding code analysis array based on the box selection flow graph; ; Among them, N01 corresponds to the number of control edges in the box selection flow graph of the code analysis array, N02 corresponds to the number of nodes in the box selection flow graph of the code analysis array, N03 corresponds to the number of splits of the complete flow line in the box selection flow graph of the code analysis array, and F corresponds to the complexity of the code analysis array; represents the total number of nodes involved in the j1th complete process line, Indicates the number of control edges corresponding to the maximum connection of a single node in the j1th complete process line; Array building sub-block: builds the analysis factor array of the matched code analysis array based on the corresponding box selection flow graph; ;in, Represents the analysis factor combination of the code analysis array matched by the corresponding box-selected flow graph; Indicates the number of simple structures in the corresponding box selection flow graph, Indicates the number of loop structures in the corresponding box selection flow graph, Indicates the number of complex structures in the corresponding box selection flow graph, Represents the weight of the complete flow line in the corresponding box selection flow graph, Represents the simple structural weight in the corresponding box selection flow graph, Represents the weight of the loop structure in the corresponding box selection flow graph, Represents the weight of the complex structure in the corresponding box selection flow graph; Function analysis sub-block: performs function analysis on the box-selected flow graph of the corresponding code analysis array, and calculates the function call depth and nesting level of the corresponding code analysis array; ;in, Indicates the function call depth of the corresponding code analysis array, Indicates the function call depth of the j2th function involved in the corresponding code analysis array, Indicates the number of function calls of the j2th function involved in the corresponding code analysis array, Indicates the function call relationship weight of the j2th function involved in the corresponding code analysis array, Indicates the function complexity weight of the j2th function involved in the corresponding code analysis array, Indicates the total number of functions involved in the corresponding code analysis array. Indicates the function operation depth of the j2th function involved in the corresponding code analysis array; Indicates the actual execution end time of the function analysis of the j2th function involved in the corresponding code analysis array; Indicates the actual execution start time of the function analysis of the j2th function involved in the corresponding code analysis array; Indicates the estimated execution time of the j2th function involved in the corresponding code analysis array; ;in, Indicates the number of nesting levels determined by the function analysis results, Indicates the number of loop nesting levels of the j-th loop statement based on the function analysis result, Indicates the number of loops of the jth loop statement based on the function analysis result, represents the weight of the number of nested layers of the jth loop statement based on the function analysis result, represents the cyclomatic complexity weight of the jth loop statement based on the function analysis result, Indicates the total number of loop statements based on function analysis results; Indicator determination sub-block: Based on each analysis array factor, function call depth, and nesting level, determine the code quality indicator of the corresponding array to be analyzed.
5. A rapid construction system based on automatic code generation according to claim 1, characterized in that: Information analysis module, including: Text preprocessing unit: performs text preprocessing on the input information input by the user to obtain text segmentation combinations; Keyword extraction unit: performs word segmentation similarity analysis on text word combinations based on a preset word vector model, obtains similarity analysis results between all word segments, and uses several word segments with similarities higher than a threshold as keywords for user needs; Demand classification unit: Classify the keywords of user needs based on a predefined classification system to determine multiple classified needs; Information determination unit: Analyzes the user's input environment and classification requirements to obtain code environment information.
6. A rapid construction system based on automatic code generation according to claim 5, characterized in that: The predefined classification system includes: function classification, data type classification, algorithm classification, framework classification and design pattern classification.
