CN109344230B - Code library file generation, code search, coupling, optimization and migration method - Google Patents
Code library file generation, code search, coupling, optimization and migration method Download PDFInfo
- Publication number
- CN109344230B CN109344230B CN201811285105.0A CN201811285105A CN109344230B CN 109344230 B CN109344230 B CN 109344230B CN 201811285105 A CN201811285105 A CN 201811285105A CN 109344230 B CN109344230 B CN 109344230B
- Authority
- CN
- China
- Prior art keywords
- file
- abstract
- code
- library
- library file
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Stored Programmes (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a code library file generation, code searching, coupling, optimizing and transplanting method, firstly, generating library files of each element code segment, storing characteristic information of each element code segment by the library files, extracting the characteristic information in the library files, storing the characteristic information in the library files together with library file addresses into abstract files, enabling a user to obtain code segments of the library files by retrieving the abstract files, recommending codes, adding the code segments selected by the user to source codes written by the user according to the setting of the user, realizing the coupling of the codes, and further realizing the automatic optimization of the codes and the application of auxiliary program transplanting on the basis. The abstract file pointing to the library file only stores the simplified characteristic information of the element code segment, so that only the input/output parameter types, output results and the like of the code segment are analyzed, full-text semantic analysis of the code segment is not needed, the content of the element code segment is summarized, and the calculation amount of the characteristics is reduced.
Description
Technical Field
The invention relates to the field of computers, in particular to a method for generating, searching, connecting, optimizing and transplanting a code library file.
Background
Programming is the process of letting a computer write program code in a programming language to solve a problem and finally get the result. A method of assisting a developer in programming in a specific manner to reduce development time of the developer is called an assisted programming method.
Most of the current auxiliary programming methods are special keyword highlighting, sentence association input and error prompt. The related art only assists the user to generate a single statement, and a developer still needs to convert a certain process into a code statement to realize the process, and the process must be written statement by statement, so that the workload is complex, and the existing code is often repeatedly written.
In the code searching part in the auxiliary programming method, most of the codes are searched based on natural language description, and the codes are manually recorded to cause long time consumption so that only old code segments can be searched, the searching based on the natural language description also causes barriers to the code recording and the searching of developers, the operation mode and logic of the code segments are difficult to be precisely and briefly summarized in the prior searching technology by natural language, and meanwhile, the searched results still need to be manually copied to manually modify codes added to users by sentences.
How to assist developers in reducing the workload of the developers and efficiently assist users in adding code segments is a problem to be solved in the technical field.
Disclosure of Invention
A first object of the present invention is to overcome the drawbacks and deficiencies of the prior art by providing a method for generating a code library file that can summarize the contents of code segments while reducing the amount of computation to generate code features.
The second object of the present invention is to provide a code searching method implemented based on the code library file generating method, which has the advantages of fast and accurate code searching.
The third object of the present invention is to provide a code automatic linking method based on the code library file generating method, which enables a user to add a code segment selected by the user to a source code input by the user after simple operation.
The fourth object of the present invention is to provide a code optimization method implemented based on the code library file generation method, which can replace a code segment selected by a user with a code segment with a faster execution speed, thereby improving the code quality and the running performance.
The fifth object of the present invention is to provide a code auxiliary method implemented based on the code library file generation method, which can reduce analysis of a user on a code segment with a complex structure, and the user can implement code migration only by simple operation, thereby effectively saving programming time of the user.
The first object of the invention is achieved by the following technical scheme: a code library file generation method comprises the following steps:
step S1, firstly, acquiring programming language and environment information of a source code;
s2, loading a slicing rule file of a corresponding language according to programming language and environment information of the source code, and dividing the source code into independent code segments with complete functions according to the slicing rule file; searching whether the called external code exists in the obtained independent code segments, if so, adding the external code into the element code segments, and finally generating element code segments without the called external code;
step S3, firstly, respectively generating a library file aiming at each element code segment, and storing each element code segment and source code address, language and environment information corresponding to each element code segment into the library file corresponding to each element code segment;
Meanwhile, for each element code segment, searching an entry of the element code segment, and generating a corresponding call statement from the entry in the element code segment to a statement of a function call part; adding the generated call statement into a library file;
meanwhile, aiming at each element code segment, amplifying the element code segment to generate a test code, generating a test data list comprising each group of test data, inputting each group of test data in the test data list into the test code, obtaining each corresponding group of test results after the test code is operated, and adding each group of test results into a library file corresponding to each element code segment;
meanwhile, for each element code segment, acquiring an input/output statement according to grammar, marking the statement as an inlet/outlet, extracting an input/output parameter type and a function name from the input/output statement, and storing the extracted input/output parameter type and function name of each element code segment into a library file corresponding to each element code segment; obtaining the label in the element code segment, and storing the label in the element code segment into a library file;
step S4, extracting language and environment information, input/output parameter types, function names, test results and labels stored in the library files obtained in the step S3 respectively;
For each library file, a digest file directed thereto is generated, the above-mentioned extracted contents of each library file are stored as digest contents in the digest file directed thereto, and the address of each library file is added to the digest file directed thereto.
Preferably, the method further comprises the following steps:
step S5, for each abstract file, periodically accessing the stored library file address, determining whether the library file can be accessed and whether the data which is extracted from the accessed library file and used as abstract content is updated;
if the library file is not accessed, the new address of the library file is queried, if the new address of the library file cannot be queried, the abstract file is deleted, and if the new address of the library file is queried, the address in the abstract file is replaced by the new address of the library file;
if the library file extracts the data used as the abstract content and has update, the data stored in the library file and used as the abstract content are re-extracted, and the abstract content in the abstract file pointed by the library file is replaced by the re-extracted data.
Preferably: the method also comprises the following steps: and (3) carrying out duplicate checking and merging processing on the library files acquired in the step (S3), wherein the method specifically comprises the following steps:
Step S31, firstly screening abstract files with the same input type, output type and test result;
step S32, aiming at the abstract files screened in the step S31, adding amplification test data into the abstract files, calling test codes in library files pointed by the amplification test data, sequentially inputting the amplification test data into the test codes for testing, sequentially obtaining amplification test results of each group respectively, stopping testing when the number of the obtained amplification test results reaches a certain value, and adding the amplification test results of each group into the abstract files;
step S33, aiming at each abstract file which is obtained in the step S32 and points to each library file, matching each group of amplification test results in each abstract file, and screening out the same abstract file corresponding to each group of amplification test results;
step S34, aiming at the abstract files screened in the step S33, obtaining each pointed library file, matching element code segments in each library file according to semantic meanings, and regarding the library files with the semantic similarity larger than a certain value after matching as repeated library files;
step S35, for a terminal for storing library files: aiming at the repeated library files acquired in the step S34, the library files with the least calling time and attribute of disallowing deletion are reserved; then adding the labels of other library files into the reserved library files under the condition that the terminal allows label addition, adding the addresses of the reserved library files into the other library files, and deleting the contents except the reserved library file addresses in the other repeated library files so that the other repeated library files only contain the reserved library file addresses;
Wherein, the preservation time of other repeated library files only containing the address of the reserved library file and the abstract file pointing to the repeated library file is permanent preservation or temporary preservation; when the temporary storage is performed, the temporary storage time is the longest time interval for the library files to be accessed periodically, and after the time interval is exceeded, other repeated library files are deleted; in the time interval, when other repeated library files are accessed through the abstract files pointing to other repeated library files, only the addresses of reserved library files can be searched, and at the moment, the library file addresses in the abstract files pointing to other repeated library files are replaced by the addresses of reserved library files, so that the abstract files pointing to other library files are updated;
when the reserved library file is accessed through the abstract file pointing to the reserved library file, if the tags in the library file are increased, adding the increased tags into the abstract file pointing to the reserved library file;
in the process of accessing the library file, if the library file cannot be accessed through the library file address in the abstract file, a search request is sent to the terminal, the terminal searches other abstract files with abstract information identical to the abstract file, and after the conforming abstract file is searched, the library file address in the abstract file is replaced by the library file address in the conforming abstract file.
Preferably, the specific process of acquiring the programming language and the environment information of each source code in step S1 is as follows:
step S11, aiming at the source code, firstly searching the annotation of the source code, determining whether a character string for recording language and environment information exists in the annotation, and if so, directly reading the language and environment information from the annotation; if not, the step S12 is carried out;
step S12, reading from the beginning of the source code, and reading the character strings;
step S13, searching each language/environment judgment file in the environment judgment library for the currently acquired character string, and judging whether the language/environment judgment file comprises the character string or not; if yes, go to step S14; if not, the step S15 is carried out;
step S14, reading language and environment information from a language/environment judgment file in which the currently read character string is located, and feeding back the language and environment information; and then judging whether the first condition and the second condition are satisfied in all the language and environment information fed back currently, wherein the first condition is as follows: the feedback times of certain language information in all the currently fed back languages and environment information exceed y times, and the feedback times of certain environment information in all the currently fed back languages and environment information exceed q times under a second condition;
If the first condition and the second condition are met, judging the language of the source code as the language information, and judging the environment of the source code as the environment information;
if only the first condition is satisfied and the second condition is not satisfied, determining the language of the source code as the language information, ending the acquisition of the source code language information, and then proceeding to step S15;
if only the second condition is satisfied and the first condition is satisfied, determining the environment of the source code as such environment information, ending the acquisition of the environment information of the source code, and then proceeding to step S15;
if the first condition and the second condition are not satisfied; step S15 is entered;
step S15, judging whether the current read character string is the last character string of the source code, if so, entering step S17; if not, the step S16 is carried out;
step S16, reading the next character string in the source code as the currently read character string, and then entering step S13;
step S17, acquiring all language and environment information fed back in the step S14; when the language information of the source code is not judged yet, the language information with the largest feedback times is used as the language information of the source code; when the environment information of the source code is not judged yet, the environment information with the largest feedback times is taken as the environment information of the source code.
Further, the step S3 is a method for generating the test code by amplifying each element code segment by using a template adding method, a removing method or a complementary method, wherein:
the step of obtaining the test code by using the template addition method is as follows:
step 1, screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments;
step 2: retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking;
step 3: splitting the marked sentence into character strings, matching the split character strings with the entrance/exit keywords of the screened templates, selecting the template with the largest matching item, and completing the matching of the templates;
adding element code segments to the selected templates to obtain test codes, and storing the test codes into corresponding library files;
the step of obtaining the test code by adopting the removal method is as follows:
firstly, generating a copy of a source code, and defining a unit code segment corresponding to a test code to be generated as a target code segment; marking the target code segment statement as a reserved statement in a copy of the source code, deleting other element code segments, and deleting the statement calling the other element code segments;
Retrieving the target code section call statement to obtain an input variable therein, retrieving the statement related to the input variable and the statement defining the input variable before the main function is called in the target code section call statement through the name of the input variable, marking the statement as a reserved statement, and deleting the rest of the statements containing the name of the input variable; simultaneously deleting other irrelevant sentences;
deleting sentences which are not marked as reserved in the copy of the source code by adopting an edge deleting and debug method, taking the code which is least and complete in the finally obtained sentences as a test code, and storing the test code into a corresponding library file;
the test code is obtained by the supplement method as follows:
s3a, screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments;
step S3b, operation 1: screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments; operation 2: retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking; operation 3: splitting the marked sentence into character strings, matching the split character strings with the entrance/exit keywords of the screened templates, selecting the template with the largest matching item, and completing the matching of the templates;
Step S3c, adding the element code segment to the template selected in the step S3b to obtain a test code;
s3d, testing the input test data by adopting the test code obtained in the step S3c, and if the test cannot pass; the following steps are performed:
s3d1, generating a copy of the source code, and defining a unit code segment corresponding to the test code to be generated as a target code segment; marking the target code segment statement as a reserved statement in a copy of the source code, deleting other element code segments, and deleting the statement calling the other element code segments;
s3d2, retrieving the target code section call statement to obtain an input variable therein, retrieving the statement which is reserved in the target code section call statement and is related to the input variable and the statement which defines the input variable before the main function is called, marking the statement as reserved statement, and deleting the rest of the statements containing the input variable name; simultaneously deleting other irrelevant sentences;
step S3d3, carrying out relevance analysis on the statements which are not reserved in the copy of the source code, and summarizing the related statements together to be used as a partial code;
step S3d4, selecting one of the obtained partial codes as the current partial code for each of the obtained partial codes;
Step S3d5, adding the current partial code to the template screened in the step S3b, and then adding the element code segment to the obtained template to obtain a test code; inputting test data for one time aiming at the test codes, if the test is passed, taking the test codes as final test codes, and if the test is not passed, entering a step S3d6;
step S3d6, selecting the next partial code as the current partial code, and then executing step S3d5 until the obtained test code input test data can pass through after one test, and storing the test code passing the test into a corresponding library file;
in the step S3, when generating a call statement for each element code, it is first determined whether there is a data association statement in the function call statement; if yes, adding the data association statement before a function call statement in the element code segment, then searching an entry of the element code segment, and generating a corresponding call statement from the entry in the optimized code segment to the function call part; if not, directly searching the entry of the element code segment, and generating a corresponding call statement from the entry in the element code segment to the statement of the function call part
The second object of the invention is achieved by the following technical scheme: a code searching method comprises the following steps:
step X1, firstly, acquiring a library file generated by the code library file generation method and a summary file pointing to the library file;
step X2, after receiving the code segment search request of the user:
step X21, acquiring the input type of a code segment required by a user, and then screening out abstract files with the input type identical to the input type of the code segment;
step X22, obtaining the output type of the code segment required by the user, and filtering out the abstract file with the output type identical to the output type of the code segment from the abstract files screened in the step X21 again;
step X23, generating a test data list formed by arranging a plurality of groups of test data according to a certain order according to the input type input by a user, selecting corresponding test data by the user through the test data list, and inputting a corresponding output value by the user according to the selected test data; aiming at each group of output values which are input by the user for each group of test data selected by the user, matching each group of output values with each group of output results in the summary files screened in the step X22, and screening summary files with each group of output results being the same as each group of output values which are input by the user for each group of test data selected by the user;
Step X24, acquiring a first label which is selected by a user and needs to be reserved, comparing the label in the first label with the first label aiming at the abstract file screened in the step X23, screening the abstract file with the same label as the first label again, acquiring a second label which is selected by the user and needs to be deleted, screening the abstract file with the same label as the second label from the abstract files screened again, and deleting the abstract file;
and step X25, recommending the abstract file finally reserved in the step X24 to a user, and enabling the user to acquire the corresponding library file for testing and selecting.
The third object of the invention is achieved by the following technical scheme: a code automatic coupling method comprises the following steps:
step Y1, firstly, acquiring the code library file generation method to generate library files selected by a user and abstract files pointing to the library files;
y2, acquiring a user function name in a self-definition mode, and aiming at a library file selected by a user, reading the function name of a summary file pointing to the library file and defining the function name as the library file function name; extracting corresponding function definition content in the element code of the library file and modifying as follows: replacing the function name of the library file in the function definition content with the function name of the user, and then adding the modified function definition content into source codes input by the user;
Acquiring a user function name of a user definition; for a library file selected by a user, reading the function name of a summary file pointing to the library file, and defining the function name as a library file function name; and simultaneously creating a header file and naming the header file by a user function name, extracting corresponding function definition contents in element codes of the library file, and modifying the function definition contents as follows: replacing the function name of the library file in the function definition content with the function name of the user, adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by the user;
and Y3, aiming at the library file selected by the user, acquiring a call statement in the library file after the user selects the input variable, adding the call statement to a user-specified function call position in source codes input by the user, and modifying the variable in the call statement into a variable name input by the user.
The fourth object of the invention is achieved by the following technical scheme: a code optimization method comprises the following steps:
step Z1, firstly, acquiring a library file generated by the code library file generation method and a summary file pointing to the library file, and defining the library file as a first library file and a first summary file;
For a source code segment selected by a user, firstly generating a second library file, simultaneously acquiring an inlet and an outlet of the source code segment, extracting an input/output parameter type and a function name from the inlet and the outlet, and then adding the source code segment and the extracted input/output parameter type and function name thereof to the second library file;
meanwhile, aiming at a source code segment selected by a user, amplifying the source code segment to generate a test code, storing the test code segment into a second library file, generating a test data list at the same time, inputting each group of test data in the test data list into the test code, obtaining corresponding groups of output results after the test code is operated, and adding the groups of output results into the second library file;
meanwhile, adding amplification test data in a second library file;
step Z2, generating a second abstract file pointing to the second library file generated in the step Z1, extracting the input/output parameter types, function names, output results of each group and amplification test data stored in the second library file, storing the extracted results as abstract contents in the second abstract file, and simultaneously storing the address of the second library file in the second abstract file;
Step Z3, matching the second abstract file pointing to the second library file obtained in the step Z2 with each first abstract file pointing to each first library file obtained in the step Z1, wherein the specific matching process is as follows:
step Z31, obtaining input types in the second abstract files, and then screening out first abstract files with the same input types as the input types in the second abstract files from the first abstract files;
step Z32, obtaining the output type in the second abstract file, and filtering out the first abstract files with the same output type as the output type in the second abstract file from the first abstract files screened in the step Z31 again;
step Z33, obtaining each group of output results in the second abstract files, and re-screening each group of first abstract files screened in the step Z32 to obtain first abstract files with the same corresponding output results as each group of output results in the second abstract files;
step Z34, adding amplification test data into the first abstract files screened in the step Z33, and simultaneously acquiring first library files pointed by the first abstract files; for each obtained first library file, inputting each group of amplification test data in a first abstract file pointing to the first library file in a test code, obtaining corresponding temporary output results of each group after the test code is operated, and adding the temporary output results of each group into the first library file and the first abstract file pointing to the first library file according to the sequence of the amplification test data of each group;
Meanwhile, for the second library file, calling the test codes therein, then respectively inputting each group of amplification test data in the second abstract file into the test codes, obtaining corresponding temporary output results of each group after the test codes are operated, and adding the temporary output results of each group into the second library file and the first abstract file;
step Z35, obtaining each group of temporary output results in the first abstract files, and screening out the first abstract files, of which each group of temporary output results corresponds to the same as each group of temporary output results in the second abstract files, from each first abstract file obtained in the step Z34;
step Z36, searching each first library file according to the library file address stored in the first abstract file screened in the step Z35, and obtaining the running time of the test codes in each first library file; and displaying the operation time of the test codes in each first abstract file screened in the step Z35 and each first library file pointed by the first abstract file to a user for selection by the user, and finally taking the element code segment in the first library file pointed by the library file address stored in the first abstract file selected by the user as an optimized code segment and replacing the source code segment selected by the user by the optimized code segment.
Preferably, in the step Z36, the specific process of replacing the code segment selected by the user with the optimized code segment is as follows:
step Z361, searching a first abstract file pointing to a first library file where the optimized code segment is located and a second abstract file pointing to the optimized code segment, and reading function names in the first abstract file and the second abstract file, wherein the function names are respectively defined as library file function names and user function names correspondingly; extracting corresponding function definition content in the element code of the first library file and modifying as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into source codes input by users;
or searching a first abstract file pointing to a first library file where the optimized code segment is located and a second abstract file pointing to the optimized code segment, and reading function names in the first abstract file and the second abstract file, wherein the function names are respectively defined as library file function names and user function names correspondingly; newly creating a header file and naming the header file by a user function name, extracting corresponding function definition contents in element codes of the first library file, and modifying the function definition contents as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by a user;
Step Z362, for the first library file in which the optimized code segment is located, obtaining a call statement in the first library file after the user selects the input variable, adding the call statement to the source code input by the user, designating the function call position by the user, and modifying the variable therein to be the variable name input by the user.
The fifth object of the present invention is achieved by the following technical scheme: a code auxiliary transplanting method comprises the following steps:
step B1, firstly, acquiring a library file and a summary file pointing to the library file generated by the code library file generation method, and defining the library file and the summary file as a first library file and a first summary file;
when a source code transplanting request of a user is received, firstly dividing the source code into independent code segments with complete functions according to a slicing rule file; for each obtained code segment to be transplanted, firstly, respectively generating a third library file, searching an input/output statement of each code segment, extracting an input/output parameter type and a function name from the input/output statement, and then storing the extracted input/output parameter type and function name into the third library file corresponding to each code segment;
Meanwhile, amplifying the obtained code segments to be transplanted to generate test codes, generating a plurality of groups of test data, sequencing the groups of test data to generate a test data list, inputting each group of test data in the test data list into the test code segments, obtaining corresponding groups of output results after the test codes are operated, and adding the groups of output results into a third library file according to the sequencing of the corresponding groups of test data;
for the obtained third library file of each code segment, generating a third abstract file pointing to the third library file, extracting the input/output parameter type, function name and each group of output results stored in the third library file, storing the extracted results as abstract contents in the third abstract file, and simultaneously storing the address of the third library file in the third abstract file;
step B2, for each third abstract file pointing to each third library file obtained in step B1, matching the third abstract file with each first abstract file pointing to each first library file obtained in step B1, wherein the specific matching process is as follows:
step B21, obtaining the input type and the output type in the third abstract file, simultaneously obtaining the language and the environment information of the code to be transplanted by the user as the appointed language and the environment information, and then screening out first abstract files which have the same input type and the output type as the third abstract file and the same language and the environment information as the appointed language and the environment information from the first abstract files;
Step B22, obtaining each group of output results in the third abstract file, and re-screening each group of output results from the first abstract files screened in the step B21 to obtain first abstract files with the same corresponding to each group of output results in the third abstract file; searching each first library file according to the library file address stored in the first abstract file to obtain the running time of the test code in each first library file; then, displaying the operation time of the test codes in the screened first abstract files and the first library files pointed by the first abstract files to a user so that the user can select corresponding first abstract files for the code segments to be transplanted;
step B23, aiming at a third abstract file of the code segment which is finally needed to be transplanted and corresponds to the selected first abstract file and the code segment which is needed to be transplanted, reading function names in the first abstract file and the third abstract file, and respectively correspondingly defining the function names as library file function names and user function names; extracting corresponding function definition content in the element code of the first library file pointed by the first abstract file, and modifying as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into source codes input by users;
Or for a third abstract file of the code segment which is finally needed to be transplanted and corresponds to the selected first abstract file and the code segment which is needed to be transplanted, reading function names in the first abstract file and the third abstract file, and respectively and correspondingly defining the function names as library file function names and user function names; newly creating a header file and naming the header file by a user function name; extracting corresponding function definition content in the element code of the first library file pointed by the first abstract file, and modifying the function definition content as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by a user;
and B24, aiming at a first library file pointed by the first abstract file which is finally selected by the user and corresponds to each source code segment to be transplanted, acquiring a call statement in the first library file after the user selects an input variable, adding the call statement to a user-specified function call position in source codes input by the user, and modifying the variable in the call statement to be the variable name input by the user.
Compared with the prior art, the invention has the following advantages and effects:
(1) In the code library file method, for a source code, the code library file method is divided into a plurality of independent code segments with complete functions, wherein each independent code segment with complete functions is called a unit code segment, a library file is generated for each unit code segment, and source code addresses, language and environment information, input/output parameter types, function names, labels and test results corresponding to the unit code segments, calling sentences and test code unit code segments are stored in the library file; for each library file, generating a summary file pointing to the library file, adding the summary part (comprising source code language and environment information, input/output parameter types, function names, labels, various groups of test results, library file addresses and amplified data) in the library file into the summary file, wherein the summary file pointing to the library file obtained by carrying out automatic processing on element code segments after source code division only stores the simplified characteristic information of the element code segments, so that analysis is carried out on the input/output parameter types, the test results and the like of the code segments, full-text semantic analysis (namely, ignoring the statement of the code segments on a specific function implementation mode) is not needed, and the calculation amount of the characteristics is reduced while the content of the element code segments is summarized. In addition, the library file obtained by the method can be saved to a server, the abstract file can be saved to a user terminal, when the abstract file of the small file is searched for each code segment in the source code, the corresponding library file can be found, the abstract is convenient to move and save, and the cost of computer resources for searching and saving is reduced.
(2) In the code library file method, the duplicate checking and merging processing are carried out on each generated library file, specifically, firstly, the stored abstract files with the same input type, output type and test result are screened out; and further calling test codes in the pointed library files aiming at the screened abstract files, inputting each group of amplified data in the abstract files into the test codes for testing to obtain each group of amplified test results again, screening abstract files with the same amplified test results from the screened abstract files again, finally obtaining each pointed library file, matching element code segments in each library file according to the semantic meanings, and regarding the library files with the semantic similarity larger than a certain value after matching as repeated library files. For the obtained repeated library files, only the library files with the least calling time and the attribute of not allowing deletion are reserved, and for other repeated library files, under the condition that the terminal allows label addition, labels in the repeated library files are respectively added into reserved library files, wherein only the addresses of the reserved library files are stored. The above method aims at the duplicate checking and merging processing of library files, and can effectively save the storage space of library files.
(3) In the code searching method, firstly, library files generated by the code library file method and abstract files pointing to the library files are obtained, the generated abstract files are sequentially screened according to input/output parameter types input by a user, output values input by the user for selected test data and labels input by the user aiming at code segments of corresponding functions required to be searched by the user, so that abstract files meeting the conditions can be screened, and for each screened abstract file, the user can perform final selection again according to the conditions of the running time of test codes, the complexity of element codes, the occupied memory space of codes and the like stored in each library file pointed by each abstract file. Therefore, under the invention, users do not need to pay attention to the internal codes of the code segments when searching, only need to pay attention to the input/output parameter types and test results of the codes, and the most suitable code segments can be rapidly screened out from a large number of codes by a standard input mode, so that the invention has the advantages of reducing the computer resources consumed by code searching, along with high code searching speed and accuracy.
(4) In the code automatic coupling method, firstly, library files generated by the code library file method and abstract files pointing to the library files are obtained, aiming at library files selected by a user, the abstract files pointing to the library files are obtained, function names in the abstract files are read, corresponding function definition contents in the library files are modified into user function names which are customized, and then the user function names are directly copied into source codes input by the user; or newly creating a header file, adding function definition contents which are correspondingly modified into user function names in a user-defined manner into the newly created header file named by the read function names, and then adding sentences for calling the header file into source codes input by a user; for a library file selected by a user, acquiring a call statement in the library file after the user selects an input variable, adding the call statement to a user-specified function call position in source code input by the user, and modifying the variable in the call statement to be the name of the variable input by the user. From the above, the method of the present invention can realize automatic code addition by simply selecting the input variable by the user according to the specified mode after the user selects the code segment, and can automatically generate the matched variable name to join the context in the addition process, so the method of the present invention can reduce the workload of the user and the time for modifying the added code.
(5) In the code automatic optimization method, first, a first library file generated by the code library file method and a first abstract file pointing to the first library file are acquired, and for a source code segment input by a user, the code library file method is referred to generate a library file and a second abstract file pointing to a second library file. Then matching the second abstract file and the first abstract file according to the input type, the output type and the test result, screening to obtain a first abstract file with the input type, the output type and the test result being the same as the second abstract file, calling test codes in a first library file, inputting each group of amplified data in the first abstract file into the test codes for testing, obtaining each group of temporary test results and storing the temporary test results into the first abstract file, and simultaneously inputting the amplified data into the test codes of the second library file, obtaining each group of temporary test results and storing the temporary test results into the second abstract file; aiming at the obtained first abstract file and second abstract file, comparing each group of temporary test results of the first abstract file and the second abstract file, and screening out the first abstract file with each group of temporary test results being the same as the second abstract file again and recommending the first abstract file to a user; the user can finally select a first summary file according to the information (such as code, running time, etc.) in the first library file, and replace the source code of the first summary file as the optimized code segment for the selected source code segment. From the above, the method of the present invention can replace the source code segment input by the user with the code segment with faster execution speed by decelerating the source code segment input by the user, which is convenient for the user to improve the code quality and the running performance.
(6) The code assisted transplanting method comprises the steps of firstly obtaining a first library file generated by the code library file method and a first abstract file pointing to the first library file, slicing a source code and generating a third library file of each code segment after slicing and a third abstract file pointing to the third library file when receiving a source code transplanting request of a user, matching each third abstract file pointing to each third library file with each first abstract file pointing to each first library file, firstly matching input type, output type, language and environment information of the first library file and the second abstract file, and screening the first abstract file of which the input type and the output type are the same as the third abstract file and the language and environment information are the specified language and environment information from each first abstract file; comparing the stored test results with the test results in the third abstract files aiming at the selected first abstract files, screening the first abstract files with the test results identical with the third abstract files again, displaying the first abstract files and information (such as codes, running time and the like) pointing to the first library files to a user for selection by the user, and transplanting corresponding element code segments in the first library files into source codes input by the user aiming at the first abstract files finally selected by the user through the code automatic connection method. As can be seen from the above, the method can be matched with two code segments with the same functions under different languages and environments through the characteristic information in the abstract file, and takes the code segments as units in the transplanting process.
(7) In summary, the user can directly obtain the code segment for realizing a certain function by using the method to search, so that the workload of the user for carrying out logic analysis and writing specific sentences for realizing the function is reduced, the user can also take more time to pay attention to the architecture of the whole program, and the excellent algorithm is more easily popularized to the user through the recommendation of the code segment and the automatic optimization of the code, so that the method has positive significance for the software industry.
Drawings
FIG. 1 is a flow chart of a method for generating a code library file according to the present invention.
Detailed Description
The present invention will be described in further detail with reference to examples and drawings, but embodiments of the present invention are not limited thereto.
Example 1
The embodiment discloses a code library file generation method, as shown in fig. 1, comprising the following steps:
step S1, firstly, acquiring programming language and environment information of a source code;
s2, loading a slicing rule file of a corresponding language according to programming language and environment information of the source code, and dividing the source code into independent code segments with complete functions according to slicing programs in the slicing rule file; searching whether the called external code exists in the obtained independent code segments, if so, adding the external code into the element code segments, and finally generating element code segments without the called external code;
Step S3, firstly, respectively generating a library file for each element code segment, and then storing each element code segment and source code addresses, languages and environment information corresponding to each element code segment into the library file corresponding to each element code segment;
meanwhile, for each element code segment, searching an entry of the element code segment, and generating a corresponding call statement from the entry in the element code segment to a statement of a function call part; adding the generated call statement into a library file; in this embodiment, for each element code, when generating a call statement, it is first determined whether there is a data-related statement in the function call statement; if yes, adding the data association statement before a function call statement in the element code segment, then searching an entry of the element code segment, and generating a corresponding call statement from the entry in the optimized code segment to the function call part; if not, searching an entry of the element code segment, and generating a corresponding call statement from the entry in the element code segment to a statement of the function call part; retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking; in this embodiment, the entry refers to a sentence in which a parameter is input in the code segment, the exit refers to a sentence in which a parameter is output in the code segment, and the entry mark refers to an annotation in which an entry/exit identifier is added to a line in which the sentence is located.
Meanwhile, aiming at each element code segment, amplifying the element code segments to generate test codes, generating a test data list, arranging all test data in the list according to a certain order, inputting all groups of test data in the test data list in the test codes, obtaining corresponding groups of test results after the test codes are operated, and adding the test codes and the groups of test results into library files corresponding to the element code segments according to the ordering of the corresponding groups of test data;
meanwhile, for each element code segment, acquiring an input/output statement according to grammar, marking the statement as an inlet/outlet, extracting an input/output parameter type and a function name from the input/output statement, and storing the extracted input/output parameter type and function name of each element code segment into a library file corresponding to each element code segment; and obtaining the tags in the element code segments and storing the tags in the element code segments in the library file.
Step S4, extracting language and environment information, input/output parameter types, function names, test results and labels stored in the library files obtained in the step S3 respectively;
for each library file, a digest file directed thereto is generated, the above-mentioned extracted contents of each library file and the amplified data are stored as digest contents in the digest file directed thereto, and the address of each library file is added to the digest file directed thereto. In this embodiment, the execution time of the test code in the library file pointed by the summary file under the standard environment, the complexity of the element code, and the size information of the memory space occupation of the library file may also be added to the summary file.
Step S5, for each abstract file, periodically accessing the stored library file address, determining whether the library file can be accessed and whether the data which is extracted from the accessed library file and used as abstract content is updated;
if the library file is not accessed, the new address of the library file is queried, if the new address of the library file cannot be queried, the abstract file is deleted, and if the new address of the library file is queried, the address in the abstract file is replaced by the new address of the library file;
if the library file extracts the data used as the abstract content and has update, the data stored in the library file and used as the abstract content are re-extracted, and the abstract content in the abstract file pointed by the library file is replaced by the re-extracted data.
In this embodiment, the library file acquired in step S3 stores the following contents:
:/(function name); (input parameter type:); (output parameter type); * /
Result 1; result 2; result 3; ... * /
/(programming language); (environmental information); (execution time in the context of the code standard under test); (complexity); (memory space occupied)/(
/(tag) ×
Element code segment
Call statement
Test code
Address/(x pointing to source code
In this embodiment, the content stored in the summary file acquired in step S4 is as follows:
:/(function name); (input parameter type:); (output parameter type); * /
Result 1; result 2; result 3; ... * /
/(programming language); (environmental information); (execution time in the context of the code standard under test); (complexity); (memory space occupied)/(
The labels herein refer to what programming problem or function comments can be solved by the function segments of the library file, for example, some function segments are ordered and some are string matched, then the labels herein are "ordered", "string matched
Library file address: ftp Address/local File Address
Wherein in the summary file the above library file address is copied to the end of the summary. In this embodiment, the labels stored in the library file and the summary file are obtained after being submitted by the developer/user, and the system can generate the labels by retrieving code sentences, comments and parameters. In this embodiment, the summary file holds information strictly in format, with punctuation separating the different items, thereby retrieving the different items. The content in the abstract file is separated by specific symbols specified by the system, for example, the output type and the test result are separated by @, when the user is programmed, after the user taps in the Searchin, the user taps in the text, then the user starts to match the character string in the area of the input type in the abstract file, and if the character in the area of the input type in the abstract file has only one user's int, the user indicates that the matching is successful, and the first screening is successful.
In the above step S1 of the present embodiment, the specific process of obtaining the programming language and the environment information of each source code is as follows:
step S11, aiming at the source code, firstly searching the annotation of the source code, determining whether a character string for recording language and environment information exists in the annotation, and if so, directly reading the language and environment information from the annotation; if not, the step S12 is carried out;
step S12, reading from the beginning of the source code, and reading the character strings;
step S13, searching each language/environment judgment file in the environment judgment library for the currently acquired character string, and judging whether the language/environment judgment file comprises the character string or not; if yes, go to step S14; if not, the step S15 is carried out;
step S14, reading language and environment information from a language/environment judgment file in which the currently read character string is located, and feeding back the language and environment information; and then judging whether the first condition and the second condition are satisfied in all the language and environment information fed back currently, wherein the first condition is as follows: the feedback times of certain language information in all the currently fed back languages and environment information exceed y times, and the feedback times of certain environment information in all the currently fed back languages and environment information exceed q times under a second condition;
If the first condition and the second condition are met, judging the language of the source code as the language information, and judging the environment of the source code as the environment information;
if only the first condition is satisfied and the second condition is not satisfied, determining the language of the source code as the language information, ending the acquisition of the source code language information, and then proceeding to step S15;
if only the second condition is satisfied and the first condition is satisfied, determining the environment of the source code as such environment information, ending the acquisition of the environment information of the source code, and then proceeding to step S15;
if the first condition and the second condition are not satisfied; step S15 is entered;
step S15, judging whether the current read character string is the last character string of the source code, if so, entering step S17; if not, the step S16 is carried out;
step S16, reading the next character string in the source code as the currently read character string, and then entering step S13;
step S17, acquiring all language and environment information fed back in the step S14; when the language information of the source code is not judged yet, the language information with the largest feedback times is used as the language information of the source code; when the environment information of the source code is not judged yet, the environment information with the largest feedback times is taken as the environment information of the source code.
Codes written in different programming languages, such as C language, c++, java, etc., implement the same algorithm, but the codes must be different, and in this embodiment, the above steps are to identify and distinguish between language and environment by unique features in the codes (such as standard library files, header files, input/output sentences, etc. included in the codes). For example, for the following source code (denoted as code 1), the first line retrieves the c++ language unique statement "# include < iostream >", then "programming language: c++ "is output to the system, and" programming language: c++ "frequency count +1 (the frequency count is recorded as 1 when the unique character string of the language/environment is detected for the first time), and at the moment, the frequency count of the language/environment does not exceed y/q times, so that the search is continued. Retrieving the annotation "c++ language" on line 24, then "programming language: c++ "is output to the system, and the keyword count is +1, and the frequency count of the language/environment is not more than y/q times at this time, so the search is continued. Line 24 retrieves the annotation "generic platform" → "programming environment: the general platform outputs this information to the system, and "programming environment: the generic platform "counts +1. If the source code is completely read and no language information or environment information still does not reach the occurrence frequency y and q times, the language information with the highest occurrence frequency (namely, programming language: C++) and the environment information (namely, programming environment: universal platform) are respectively selected as judging results. The system adds it ("// programming language: C++; programming environment: general purpose platform") to the source code header.
Code 1:
in step S3 described above in the present embodiment, in order to identify the manner of distinguishing the input and output, 4 types are specially named to save the input type and output type part information of the library file: 1. user input type: a variable manually typed by a user, such as the type name int of the variable a input by a cin > a sentence, is retrieved and modified: the variable type name is added to the library file after being prefixed (such as 'c_' i.e. "c_type name": c_int "). 2. Type of printout: the type of the variable output after the output sentence is used, for example, the type of the variable appearing after the sentence of cout < < is used, and the variable type name is retrieved and modified: the variable type name is prefixed (such as 'p_' i.e. "p_type name": p_int ") and then added to the library file. 3. Type of incoming: non-user input types, including: the types of the variables serving as function shape parameters, macro definition, pointers, arrays and the like, and the type names corresponding to the variables are retrieved and added to the library file; 4. outgoing type: a non-printout type comprising: when the function has a return value, the type of the return value, macro definition variable, pointer variable and other corresponding types are added to the library file by the type name corresponding to the variable. In this embodiment, the recognition of function names and input/output types in the element code segments needs to be performed by a computer, i.e. the basis of recognition is that a piece of function code must have function type names, such as void, void and ("before" must be function names, so that the character between the function names is extracted to be the function names which we want, the reason of recognizing input and output types is the same, such as that common input types, such as int, char, float, etc., are stored together in the form of individual character strings, and then are matched with the function code segments to find the input types of the function code segments, for example, in the following code (marked as code 2), after the recognition in this embodiment, (function name) insert_sort, (transmission/input type) int [ ], and (transmission/output type) int [ ].
Code 2:
the method can only face simple calling, and can not solve the problem that macro definition variables and custom types are used as parameters. Therefore, this embodiment proposes another more sophisticated method: variable retrieval method: 1. according to the operation part and the input/output rule in the grammar (the variable is found by the operator because the variable is next to the operator in the operation sentence, and the variable is next to the key words < < and > > in the input/output sentence), the variable name in the code segment is obtained by searching; 2. searching a sentence containing the variable by searching the variable name (searching source codes), searching whether the sentence is a macro definition sentence or an input/output sentence, if not, searching the next sentence, if yes, marking the sentence as an entry/exit and searching the sentence defined by the variable, (1) directly outputting if the variable is a basic type, (2) adding the variable defined by the macro to a code segment and marking the variable as a macro definition, searching the sentence to obtain the type of the variable and outputting the variable to a system; (3) If the character constant is the character constant, adding the character constant into the code segment; (4) If the variable is the custom type, adding the definition statement of the custom type into the code segment and marking the definition statement as the custom type, retrieving the definition statement of the custom type to obtain the variable type of the variable name and outputting the variable type to the system.
In this embodiment, step S3 is performed for each element code segment by using a template addition method, a subtraction method or a complementary method, where:
in this embodiment, the step of obtaining the test code by using the template addition method is as follows:
step 1, screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments; definition of templates: the written code frame can form an executable complete program by only adding element code segments into codes of templates; the template consists of two parts: retrieving content and code; the search content is used for system search when screening.
Step 2: retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking; in this embodiment, the entry refers to a sentence in which a parameter is input in the code segment, the exit refers to a sentence in which a parameter is output in the code segment, and the entry mark refers to an annotation in which an entry/exit identifier is added to a line in which the sentence is located.
Step 3: splitting the marked sentence into character strings, matching the split character strings with the entrance/exit keywords of the screened templates, selecting the template with the largest matching item, and completing the matching of the templates;
Adding element code segments to the selected templates to obtain test codes, and storing the test codes into corresponding library files;
for example, the element code segments are as follows:
matching the template according to the information and adding the element code segment to obtain a test code as follows:
in this embodiment, the step of obtaining the test code by adopting the removal method is as follows:
firstly, generating a copy of a source code, and defining a unit code segment corresponding to a test code to be generated as a target code segment; marking the target code segment statement as a reserved statement in a copy of the source code, deleting other element code segments, and deleting the statement calling the other element code segments;
retrieving the target code section call statement to obtain an input variable therein, retrieving the statement related to the input variable and the statement defining the input variable before the main function is called in the target code section call statement through the name of the input variable, marking the statement as a reserved statement, and deleting the rest of the statements containing the name of the input variable; simultaneously deleting other irrelevant sentences;
deleting sentences which are not marked as reserved in the copy of the source code by adopting an edge deleting and debug method, taking the code which is least and complete in the finally obtained sentences as a test code, and storing the test code into a corresponding library file;
For example, the copy of the source code (labeled code 3) is processed using the above-described removal method of the present embodiment, where the necessary structure statement refers to a necessary statement that makes the code executable, and is defined by the developer. The delete-while-debug method is specifically as follows: 1. firstly performing debug and test once (searching the code segment inlet and outlet, assigning a value to the code segment at the inlet, inserting a test statement at the outlet to obtain a result, and omitting the test); 2. carrying out relevance analysis (inter-statement calling and nesting) on the non-reserved statements, wherein the inter-related statements are a part; 3. and deleting the parts one by one, performing debug and test once every part is deleted, if the part passes (debug has no problem, and the test result is the same as that of the first test), continuing to delete the next part, if the part cannot pass, recovering the part and marking the part as reserved, and continuing to delete the next part until the rest of sentences are marked as reserved. The code 3 is as follows:
in this embodiment, the test code is obtained by the following steps by the augmentation method:
s3a, screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments;
step S3b, operation 1: screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments; operation 2: retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking; operation 3: splitting the marked sentence into character strings, matching the split character strings with the entrance/exit keywords of the screened templates, selecting the template with the largest matching item, and completing the matching of the templates;
Step S3c, adding the element code segment to the template selected in the step S3b to obtain a test code;
s3d, testing the input test data by adopting the test code obtained in the step S3c, and if the test cannot pass; the following steps are performed:
s3d1, generating a copy of the source code, and defining a unit code segment corresponding to the test code to be generated as a target code segment; marking the target code segment statement as a reserved statement in a copy of the source code, deleting other element code segments, and deleting the statement calling the other element code segments;
s3d2, retrieving the target code section call statement to obtain an input variable therein, retrieving the statement which is reserved in the target code section call statement and is related to the input variable and the statement which defines the input variable before the main function is called, marking the statement as reserved statement, and deleting the rest of the statements containing the input variable name; simultaneously deleting other irrelevant sentences;
step S3d3, carrying out relevance analysis on the statements which are not reserved in the copy of the source code, and summarizing the related statements together to be used as a partial code;
step S3d4, selecting one of the obtained partial codes as the current partial code for each of the obtained partial codes;
Step S3d5, adding the current partial code to the template screened in the step S3b, and then adding the element code segment to the obtained template to obtain a test code; inputting test data for one time aiming at the test codes, if the test is passed, taking the test codes as final test codes, and if the test is not passed, entering a step S3d6;
step S3d6, selecting the next partial code as the current partial code, and then executing step S3d5 until the obtained test code input test data can pass through after one test, and storing the test code passing the test into the corresponding library file.
The code library file generating method of the present embodiment further includes searching for and merging the library files obtained in step S3, where the repeated library files refer to: several library files are identical in input type, output type and algorithm in code, etc. but the variable names used for defining variable may be different, and the labels of this code may be different, so that these several library files are called repeated library files
The method comprises the following specific steps:
step S31, firstly screening abstract files with the same input type, output type and test result;
Step S32, aiming at the abstract files and the pointed library files thereof screened in the step S31, adding the amplification test data into the abstract files, then calling the test codes in the pointed library files, sequentially inputting the amplification test data of each group into the test codes for testing, sequentially obtaining each amplification test result respectively, stopping testing when the number of the obtained amplification test results reaches a certain value, and adding the amplification test results of each group into the abstract files;
step S33, aiming at each abstract file which is obtained in the step S32 and points to each library file, matching each group of amplification test results in each abstract file, and screening out the same abstract file corresponding to each group of amplification test results;
step S34, aiming at the abstract files screened in the step S33, obtaining each pointed library file, matching element code segments in each library file according to semantic meanings, and regarding the library files with the semantic similarity larger than a certain value after matching as repeated library files;
step S35, for a terminal for storing library files: aiming at the repeated library files acquired in the step S34, the library files with the least calling time and attribute of disallowing deletion are reserved; then adding the labels of other library files into the reserved library files under the condition that the terminal allows label addition, adding the addresses of the reserved library files into the other library files, and deleting the contents except the reserved library file addresses in the other repeated library files so that the other repeated library files only contain the reserved library file addresses;
Wherein, the preservation time of other repeated library files only containing the address of the reserved library file and the abstract file pointing to the repeated library file is permanent preservation or temporary preservation; when the temporary storage is performed, the temporary storage time is the longest time interval for the library files to be accessed periodically, and after the time interval is exceeded, other repeated library files are deleted; in the time interval, when other repeated library files are accessed through the abstract files pointing to other repeated library files, only the addresses of reserved library files can be searched, and at the moment, the library file addresses in the abstract files pointing to other repeated library files are replaced by the addresses of reserved library files, so that the abstract files pointing to other library files are updated;
when the reserved library file is accessed through the abstract file pointing to the reserved library file, if the tags in the library file are increased, adding the increased tags into the abstract file pointing to the reserved library file;
in the process of accessing the library file, if the library file cannot be accessed through the library file address in the abstract file, a search request is sent to the terminal, the terminal searches other abstract files with abstract information identical to the abstract file, and after the conforming abstract file is searched, the library file address in the abstract file is replaced by the library file address in the conforming abstract file;
For example, in this embodiment, the library file is placed in a storage area or server in a certain computer (terminal), if there are 5 library files in the storage area or server in the computer at this time, the numbers are 1,2,3,4,5, and there are 5 summary files, the numbers are 1-,2-,3-,4-,5-, and each summary file is associated with a corresponding library file, for example, the 1-th summary file points to the 1-th library file, and after steps 31 to 34, it is found that the 1-th library file and the 2-th library file are repeated, so that they are subjected to the merging process of step 35; before merging, we need to determine which of the two library files 1,2 is better and keep the better library file, then the question arises how to determine which library file is better? The concept of "library file calling time" is used, and the "library file calling time" means the time from the address in the terminal access abstract (the address is the address of a library file in a server or a storage area of the terminal) to the time when the library file is downloaded to the terminal, of course, the shorter the time is, the better the library file is, if the test finds that the library file number 1 is better, the library file number 1 needs to be reserved, the tag in the library file number 2 is copied into the library file number 1, meanwhile, the content in the library file number 2 is completely deleted, and the address of the library file number 1 is added to the library file number 2, that is, when the user accesses the library file number 2 through the abstract file number 2, only one address link in the library file number 2 is found, and the library file number 1 is found through the link, and the abstract file number 2 updates the abstract information and the address according to the library file number 1: the library file No. 2 is deleted together with the digest file No. 2 when the maximum time interval for which the library file is accessed periodically is exceeded; when the library file 2 is accessed by pointing to the No. 2 summary file, the address of the reserved No. 1 library file can be searched in the No. 2 library file only when the library file is accessed periodically within the longest time interval, and the library file address in the No. 2 summary file is replaced by the address of the No. 1 library file, thereby realizing the update of the No. 2 summary file. When a user accesses the No. 1 library file through the No. 1 abstract file, the added labels are copied to the No. 1 abstract file when the user finds that the labels of the library file are increased, so that the abstract file is updated, and the repeated No. 2 library file and the repeated No. 2 abstract file are deleted together, thereby realizing the functions of searching and merging the library files.
Example 2
The embodiment discloses a code searching method, which comprises the following steps:
step X1, firstly, acquiring a library file generated by the code library file generation method in the embodiment 1 and a summary file pointing to the library file;
step X2, after receiving the code segment search request of the user:
step X21, acquiring the input type of a code segment required by a user, and then screening out abstract files with the input type identical to the input type of the code segment;
in this embodiment, the search shortcut key input by the user is set, which may be an arrow ↙ toward the lower left, when the user inputs: the search: int, int: ↙, the system will match each summary according to the input type inputted by the user, as shown in step X21, if 1000 summary files match this situation, the search result will be shown to us as follows:
result 1000Counts (total 1000 search results);
if the code segment intended by the user has no input, then we specify that the user should tap in the search key, the enter key, indicating no input type, the system will filter according to this condition, filter out the function code segment without input, and display how many such summary files are in total to the user. In this embodiment, if the user wants to enter or print out in the ideal code segment, for example, input/output modes such as scanf, cin, printf, cout are used, the input mode of the search entry needs to be prefixed by "c_" to the input type name, i.e., enter: "search: c_type name" search, the output mode of the search printout requires adding a prefix "p_" to the output type name, i.e., input: "typing: searchout p_type name.
Step X22, obtaining the output type of the code segment required by the user, and filtering out the abstract file with the output type identical to the output type of the code segment from the abstract files screened in the step X21 again;
in the present embodiment, the output type of the user input may be set as: searchout, int: ↙, wherein Searchout is an identifier indicating the output type, and assuming that the output type is an int type variable, the identifier Searchout needs to be marked, i.e. the int is marked later, and at this time, two rounds of matching are performed again on the 1000 search results generated after the operation of step X21 is completed, the matching is performed according to the output type result, and after the matching is completed, assuming that the original 1000 search results are changed into 500 search results, the matching is displayed on the interface:
Result:500Counts
such statements are used to prompt the user to filter the results.
Step X23, generating a test data list formed by arranging a plurality of groups of test data according to a certain order according to the input type input by a user, selecting corresponding test data by the user through the test data list, and inputting a corresponding output value by the user according to the selected test data; aiming at each group of output values which are input by the user for each group of test data selected by the user, matching each group of output values with each group of test results in the summary files screened in the step X22, and screening summary files with each group of test results being the same as each group of output values which are input by the user for each group of test data selected by the user;
In this step, the user may manually input the corresponding output value according to the function of the code segment according to the selected multiple sets of input values recommended by the system, for example, a code segment requiring two maximum shaping numbers is selected, the system recommends the set of input values [1,2] when the user needs to manually input the corresponding input output value of [2] after typing down the output type, the following set of recommended values are the same theory, the system will perform matching according to the output value and the test result in the abstract file when the system determines the input system recommendation value of the specific type, so that the running result is also determined according to the input and the test result is recorded in the abstract file when the abstract file is generated, namely, for matching the data result of the step, the user is reminded of displaying the following characters when the remaining 20 pieces of the searched result are also assumed to be 20 pieces of the remaining after screening in the step X22, wherein the system can specify that the tab number is smaller than 30 pieces of tab is displayed when the searched result is smaller than 30 pieces of tab:
[2][3][4][4]
A section of reminding character is displayed:
Result:20Counts
tags:0- [ maximum=3 ],1- [ rank=1 ],2- [ arm plateau=4 ],
3- [ x86 platform=3 ],4- [ full platform=4 ];
wherein the label number 0 means that the last 3 code segments are used for maximum value and meet the conditions of three rounds of screening from step X21 to step X23, the label number 1 means that the last 1 code segments are used for sorting and meet the conditions of three rounds of screening from step X21 to step X23, and the label number 2 means that the remaining 4 code segments can run on the arm platform and also meet the conditions of three rounds of screening from step X21 to step X23.
Step X24, acquiring a first label which is selected by a user and needs to be reserved, comparing the label in the first label with the first label aiming at the abstract file screened in the step X23, screening the abstract file with the same label as the first label again, acquiring a second label which is selected by the user and needs to be deleted, screening the abstract file with the same label as the second label from the abstract files screened again, and deleting the abstract file;
in this embodiment, "hold" is used when setting a key for retaining a certain tag: by "it is meant that after entering this key, the code segment of a tag of a certain number will remain in the recommendation, and" remove "is used when deleting the key of a certain tag: by "is meant that the tag is deleted in the recommended reality, for example:
hold 0,4; or remove 1,2,3;
the element code segments meeting the common requirements of the No. 0 tag and the No. 4 tag are left in the recommendation display, the rest of the element code segments are deleted, for example, the element code segments meeting the No. 0 tag can be maximally found, 3 element code segments are total, the element code segments meeting the No. 4 tag can also run on the whole platform on the premise of being maximally found, so that if the element code segments are screened out, if only 3 recommendations are left at last, the following statement is provided for prompting a user:
Result:3Counts
XXX (representing the library file code corresponding to 3 digests).
And step X25, recommending the abstract file finally reserved in the step X24 to a user, and enabling the user to acquire the corresponding library file for testing and selecting. In this embodiment, when a user obtains each summary file recommended by the system, a test code in a library file pointed by the summary file is called, meanwhile, the user selects test data and inputs an output value of corresponding test data, test output is input into the test code to run, a test result is obtained, if the obtained test result is the same as the output value input by the user for the selected test data, the summary file is reserved, otherwise, the summary file is deleted.
In this embodiment, after step X25, the user may perform deeper screening according to parameters such as the running time of the test code in the library file pointed by the summary file and the memory space occupied by the library file; for example, a user manually enters a specific value of 3 sets of [ int, int ] to run and display the running result and elapsed time in the test code in the library file to which the corresponding recommended summary file points, e.g., manually enters a test of [7,4] [12,2] [999,0] (where test is a key representing a manual test library file or is called an identifier), where this input runs in the remaining recommended a-element code segment, b-element code segment, c-element code segment and displays the running result and elapsed time, e.g., as shown:
testout:a:[7][12][999]:0.01s
b:[7][12][999]:0.03s
c:[7][12][999]:0.02s
at this time, the user may select the a-element code segment with the shortest running time.
If the user wants to see some parameters (complexity, running speed, occupied memory space, etc.) of the code segment meeting the requirements, the user needs to manually knock in the keywords: the showfilename, up represents the ascending order of the parameters, f represents the descending order of the sizes of the parameters;
such as manual tap-in:
show-a. Up or show (order of increasing complexity-default order)
The operating parameters (ordered) of the three library files are displayed as follows:
sort: a- [ complexity ], b- [ operating speed ], c- [ memory footprint ];
a.h:10;0.02s;0.1KB;
b.h:20;0.03s;0.2KB;
c.h:30;0.01s;0.3KB;
after the above operations, if it is desired to retain the desired code segment or remove the relatively undesired code segment, the following operations may be performed, for example:
hold:[7][12][999]↙;
or hold: a.test (retaining the same library file as a.h test results) ↙;
or remove: test (removing the same library file as b.h test results) ↙;
remaining display after deletion:
a.h:10;0.02s;0.1KB;
c.h:30;0.01s;0.3KB;
with the above operation, the number of eligible element codes, i.e., corresponding library files, is reduced, wherein after the above operation, if two eligible code segments a.h and b.h, respectively, remain, then if a programmer wants to view a particular code segment of a library file, he can type in a keyword + library file name, e.g., click in view: a.h, c.h ↙
The element code segments of the corresponding library file are then displayed for reference by the user to facilitate selection of a final code segment by the user. In addition, after the user determines a library file and wants to use the element code segment in the library file, the user only needs to manually click in the determination+library file name, for example: determining: a.h ↙.
Example 3
The embodiment discloses a code automatic coupling method, which comprises the following steps:
step Y1, firstly, acquiring a library file selected by a user and a summary file pointing to the library file generated by the code library file generation method in the embodiment 1;
y2, acquiring a user function name in a self-definition mode, and aiming at a library file selected by a user, reading the function name of a summary file pointing to the library file and defining the function name as the library file function name; extracting corresponding function definition content in the element code of the library file and modifying as follows: replacing the function name of the library file in the function definition content with the function name of the user, and then adding the modified function definition content into source codes input by the user;
acquiring a user function name of a user definition; for a library file selected by a user, reading the function name of a summary file pointing to the library file, and defining the function name as a library file function name; and simultaneously creating a header file and naming the header file by a user function name, extracting corresponding function definition contents in element codes of the library file, and modifying the function definition contents as follows: replacing the function name of the library file in the function definition content with the function name of the user, adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by the user;
And Y3, aiming at the library file selected by the user, acquiring a call statement in the library file after the user selects the input variable, adding the call statement to a user-specified function call position in source codes input by the user, and modifying the variable name into the variable name input by the user.
In this embodiment, the following code 4 is a unit code section in a library file selected by a user, and when function definition contents corresponding to function names in the unit code section of the library file are directly added to a source code of the user, the obtained source code of the user is the following code 5. In the code automatic coupling method of the embodiment, a user is reminded of modifying an incoming variable, namely int a [ ], int n; a// incoming type variable name; at this point the user inputs the following: a < - > b < - > and N < - > N ↙, respectively modifying a < > and N variables in the call statement into variables b < > and N selected by the user, and modifying "n=sizeof (a)/sizeof (int); "modified to" n=sizeof (b)/sizeof (int); "the" insert_start (a, N) "is modified to" insert_start (b, N) "; "
Code 4:
function calling part:
N=sizeof(a)/sizeof(int);
insert_sort(a,N);
code 5:
/>
example 4
The embodiment discloses a code optimization method, which comprises the following steps:
Step Z1, firstly, obtaining a code library file generation method in the embodiment 1 to generate a library file and a summary file pointing to the library file, and defining the library file as a first library file and a first summary file;
for a source code segment selected by a user, firstly generating a second library file, simultaneously acquiring an inlet and an outlet of the source code segment, extracting an input/output parameter type and a function name from the inlet and the outlet, and then adding the source code segment and the extracted input/output parameter type and function name thereof to the second library file;
meanwhile, aiming at a source code segment selected by a user, amplifying the source code segment to generate a test code, storing the test code segment into a second library file, generating a test data list at the same time, inputting each group of test data in the test data list into the test code, obtaining corresponding groups of output results after the test code is operated, and adding the groups of output results into the second library file;
meanwhile, adding amplification test data in a second library file;
step Z2, generating a second abstract file pointing to the second library file generated in the step Z1, extracting the input/output parameter types, function names, output results of each group and amplification test data stored in the second library file, storing the extracted results as abstract contents in the second abstract file, and simultaneously storing the address of the second library file in the second abstract file;
Step Z3, matching the second abstract file pointing to the second library file obtained in the step Z2 with each first abstract file pointing to each first library file obtained in the step Z1, wherein the specific matching process is as follows:
step Z31, obtaining input types in the second abstract files, and then screening out first abstract files with the same input types as the input types in the second abstract files from the first abstract files;
step Z32, obtaining the output type in the second abstract file, and filtering out the first abstract files with the same output type as the output type in the second abstract file from the first abstract files screened in the step Z31 again;
step Z33, obtaining each group of output results in the second abstract files, and re-screening each group of first abstract files screened in the step Z32 to obtain first abstract files with the same corresponding output results as each group of output results in the second abstract files;
step Z34, adding amplification test data into the first abstract files screened in the step Z33, and simultaneously acquiring first library files pointed by the first abstract files and adding the amplification test data into the first library files; for each obtained first library file, inputting each group of amplification test data in a first abstract file pointing to the first library file in a test code, obtaining corresponding temporary output results of each group after the test code is operated, and adding the temporary output results of each group into the first library file and the first abstract file pointing to the first library file according to the sequence of the amplification test data of each group;
Meanwhile, for the second library file, calling the test codes therein, then respectively inputting each group of amplification test data in the second abstract file into the test codes, obtaining corresponding temporary output results of each group after the test codes are operated, and adding the temporary test results of each group into the second library file and the first abstract file according to the sequence of the amplification data of each group;
step Z35, obtaining each group of temporary test results in the first abstract files, and screening out the first abstract files, of which each group of temporary test results corresponds to the same as each group of temporary test results in the second abstract files, from each first abstract file obtained in step Z34;
step Z36, searching each first library file according to the library file address stored in the first abstract file screened in the step Z35, and obtaining the running time of the test codes in each first library file; and displaying the operation time of the test codes in each first abstract file screened in the step Z35 and each first library file pointed by the first abstract file to a user for selection by the user, and finally taking the element code segment in the first library file pointed by the library file address stored in the first abstract file selected by the user as an optimized code segment and replacing the source code segment selected by the user by the optimized code segment.
In this embodiment, the specific process of replacing the code segment selected by the user with the optimized code segment is as follows:
step Z361, searching a first abstract file pointing to a first library file where the optimized code segment is located and a second abstract file pointing to the optimized code segment, and reading function names in the first abstract file and the second abstract file, wherein the function names are respectively defined as library file function names and user function names correspondingly; extracting corresponding function definition content in the element code of the first library file and modifying as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into source codes input by users;
or searching a first abstract file pointing to a first library file where the optimized code segment is located and a second abstract file pointing to the optimized code segment, and reading function names in the first abstract file and the second abstract file, wherein the function names are respectively defined as library file function names and user function names correspondingly; newly creating a header file and naming the header file by a user function name, extracting corresponding function definition contents in element codes of the first library file, and modifying the function definition contents as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by a user;
Step Z362, for the first library file in which the optimized code segment is located, obtaining a call statement in the first library file after the user selects the input variable, adding the call statement to the source code input by the user, designating the function call position by the user, and modifying the variable therein to be the variable name input by the user.
In step S36 of this embodiment, the user may perform deeper screening according to the running time of the test code in the first library file pointed to by the first summary file and the parameters such as the memory space occupied by the library file, and perform operations of displaying the code parameters, checking the code and determining the code; the specific deeper screening methods and code parameter display, code viewing and code determination operations are the same as in example 2.
Example 5
The embodiment discloses a code auxiliary transplanting method, which comprises the following steps:
step B1, firstly, obtaining a library file and a summary file pointing to the library file generated by the code library file generating method in the embodiment 1, and defining the library file and the summary file as a first library file and a first summary file;
when a source code transplanting request of a user is received, firstly dividing the source code into independent code segments with complete functions according to a slicing rule file; for each obtained code segment to be transplanted, firstly, respectively generating a third library file, searching an input/output statement of each code segment, extracting an input/output parameter type and a function name from the input/output statement, and then storing the extracted input/output parameter type and function name into the third library file corresponding to each code segment;
Meanwhile, amplifying the obtained code segments to be transplanted to generate test codes, generating a plurality of groups of test data, sequencing the groups of test data to generate a test data list, inputting each group of test data in the test data list into the test code segments, obtaining corresponding groups of test results after the test codes are operated, and adding the groups of test results into a third library file according to the sequencing of the corresponding groups of test data;
for the obtained third library file of each code segment, generating a third abstract file pointing to the third library file, extracting the input/output parameter type, function name and each group of test results stored in the third library file, storing the extracted results as abstract contents in the third abstract file, and simultaneously storing the address of the third library file in the third abstract file;
step B2, for each third abstract file pointing to each third library file obtained in step B1, matching the third abstract file with each first abstract file pointing to each first library file obtained in step B1, wherein the specific matching process is as follows:
step B21, obtaining the input type and the output type in the third abstract file, simultaneously obtaining the language and the environment information of the code to be transplanted by the user as the appointed language and the environment information, and then screening out first abstract files which have the same input type and the output type as the third abstract file and the same language and the environment information as the appointed language and the environment information from the first abstract files;
Step B22, obtaining each group of output results in the third abstract file, and re-screening each group of output results from the first abstract files screened in the step B21 to obtain first abstract files with the same corresponding to each group of output results in the third abstract file; searching each first library file according to the library file address stored in the first abstract file to obtain the running time of the test code in each first library file; then, displaying the operation time of the test codes in the screened first abstract files and the first library files pointed by the first abstract files to a user so that the user can select corresponding first abstract files for the code segments to be transplanted;
step B23, aiming at a third abstract file of the code segment which is finally needed to be transplanted and corresponds to the selected first abstract file and the code segment which is needed to be transplanted, reading function names in the first abstract file and the third abstract file, and respectively correspondingly defining the function names as library file function names and user function names; extracting corresponding function definition content in the element code of the first library file pointed by the first abstract file, and modifying as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into source codes input by users;
Or for a third abstract file of the code segment which is finally needed to be transplanted and corresponds to the selected first abstract file and the code segment which is needed to be transplanted, reading function names in the first abstract file and the third abstract file, and respectively and correspondingly defining the function names as library file function names and user function names; newly creating a header file and naming the header file by a user function name; extracting corresponding function definition content in the element code of the first library file pointed by the first abstract file, and modifying the function definition content as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by a user;
and B24, aiming at a first library file pointed by the first abstract file which is finally selected by the user and corresponds to each source code segment to be transplanted, acquiring a call statement in the first library file after the user selects an input variable, adding the call statement to a user-specified function call position in source codes input by the user, and modifying the variable in the call statement to be the variable name input by the user.
In this embodiment, the source code division in step B1 may be a manual division by a user or an automatic division by a system, where:
Manual partitioning refers to: manually selecting some sentences to be divided into a code section by a user; such as:
(division operation) divide:3 (line sentence) -9 (line sentence),. The.a.. To insert_start (code segment name 1);
the automatic system division refers to: the identification is performed according to a definition statement of a structure realizing a specific function, such as: function structure in c++, class structure in Java.
For example, the old source code of the user (labeled code 6) is as follows:
code 6:
the c language of the code 7 is transplanted by the method of the embodiment to obtain a new source code (marked as code 7) in the java language environment as follows:
/>
it should be noted that, the test data related to each embodiment are all specified by the system, and the plurality of sets of test data are arranged in a determined order to form a test data table, and the test data table is also specified by the system. Each basic type of data has corresponding test data. The test results stored in the abstract file are correspondingly stored according to the sequence of the test data list. Therefore, the system can find out the corresponding test result according to the sequence of the test data selected by the user. Illustrating: the test data table of the input type int→int is listed as: 0,1,2,3,4,5 and feedback to the user selection, at which time the user selects: 0 (order 1 in table), 1 (order 2 in table), the user inputs the corresponding result: and 0,2, the system searches the summary file with the first output (sequence 1) result of 0 and the second output (sequence 2) result of 2 in the test results according to the sequence, so that the summary file of the test results and the output value input by the user for the selected test data can be found.
The above examples are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above examples, and any other changes, modifications, substitutions, combinations, and simplifications that do not depart from the spirit and principle of the present invention should be made in the equivalent manner, and the embodiments are included in the protection scope of the present invention.
Claims (10)
1. The code library file generating method is characterized by comprising the following steps:
step S1, firstly, acquiring programming language and environment information of a source code;
s2, loading a slicing rule file of a corresponding language according to programming language and environment information of the source code, and dividing the source code into independent code segments with complete functions according to the slicing rule file; searching whether the called external code exists in the obtained independent code segments, if so, adding the external code into the element code segments, and finally generating element code segments without the called external code;
step S3, firstly, respectively generating a library file aiming at each element code segment, and storing each element code segment and source code address, language and environment information corresponding to each element code segment into the library file corresponding to each element code segment;
Meanwhile, for each element code segment, searching an entry of the element code segment, and generating a corresponding call statement from the entry in the element code segment to a statement of a function call part, wherein the call statement specifically comprises the following steps: firstly, judging whether a function call statement has a data relevance statement or not; if yes, adding the data association statement before a function call statement in the element code segment, then searching an entry of the element code segment, and generating a corresponding call statement from the entry in the optimized code segment to the function call part; if not, searching an entry of the element code segment, and generating a corresponding call statement from the entry in the element code segment to a statement of the function call part; retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking; adding the generated call statement into a library file;
meanwhile, aiming at each element code segment, amplifying the element code segment to generate a test code, generating a test data list comprising each group of test data, inputting each group of test data in the test data list into the test code, obtaining each corresponding group of test results after the test code is operated, and adding each group of test results into a library file corresponding to each element code segment;
Meanwhile, for each element code segment, acquiring an input/output statement according to grammar, marking the statement as an inlet/outlet, extracting an input/output parameter type and a function name from the input/output statement, and storing the extracted input/output parameter type and function name of each element code segment into a library file corresponding to each element code segment; obtaining the label in the element code segment, and storing the label in the element code segment into a library file;
step S4, extracting language and environment information, input/output parameter types, function names, test results and labels stored in the library files obtained in the step S3 respectively;
for each library file, a digest file directed thereto is generated, the above-mentioned extracted contents of each library file are stored as digest contents in the digest file directed thereto, and the address of each library file is added to the digest file directed thereto.
2. The code library file generation method according to claim 1, further comprising the steps of:
step S5, for each abstract file, periodically accessing the stored library file address, determining whether the library file can be accessed and whether the data which is extracted from the accessed library file and used as abstract content is updated;
If the library file is not accessed, the new address of the library file is queried, if the new address of the library file cannot be queried, the abstract file is deleted, and if the new address of the library file is queried, the address in the abstract file is replaced by the new address of the library file;
if the library file extracts the data used as the abstract content and has update, the data stored in the library file and used as the abstract content are re-extracted, and the abstract content in the abstract file pointed by the library file is replaced by the re-extracted data.
3. The code library file generation method according to claim 1, wherein: the method also comprises the following steps: and (3) carrying out duplicate checking and merging processing on the library files acquired in the step (S3), wherein the method specifically comprises the following steps:
step S31, firstly screening abstract files with the same input type, output type and test result;
step S32, aiming at the abstract files screened in the step S31, adding amplification test data into the abstract files, calling test codes in library files pointed by the amplification test data, sequentially inputting the amplification test data into the test codes for testing, sequentially obtaining amplification test results of each group respectively, stopping testing when the number of the obtained amplification test results reaches a certain value, and adding the amplification test results of each group into the abstract files;
Step S33, aiming at each abstract file which is obtained in the step S32 and points to each library file, matching each group of amplification test results in each abstract file, and screening out the same abstract file corresponding to each group of amplification test results;
step S34, aiming at the abstract files screened in the step S33, obtaining each pointed library file, matching element code segments in each library file according to semantic meanings, and regarding the library files with the semantic similarity larger than a certain value after matching as repeated library files;
step S35, for a terminal for storing library files: aiming at the repeated library files acquired in the step S34, the library files with the least calling time and attribute of disallowing deletion are reserved; then adding the labels of other library files into the reserved library files under the condition that the terminal allows label addition, adding the addresses of the reserved library files into the other library files, and deleting the contents except the reserved library file addresses in the other repeated library files so that the other repeated library files only contain the reserved library file addresses;
wherein, the preservation time of other repeated library files only containing the address of the reserved library file and the abstract file pointing to the repeated library file is permanent preservation or temporary preservation; when the temporary storage is performed, the temporary storage time is the longest time interval for the library files to be accessed periodically, and after the time interval is exceeded, other repeated library files are deleted; in the time interval, when other repeated library files are accessed through the abstract files pointing to other repeated library files, only the addresses of reserved library files can be searched, and at the moment, the library file addresses in the abstract files pointing to other repeated library files are replaced by the addresses of reserved library files, so that the abstract files pointing to other library files are updated;
When the reserved library file is accessed through the abstract file pointing to the reserved library file, if the tags in the library file are increased, adding the increased tags into the abstract file pointing to the reserved library file;
in the process of accessing the library file, if the library file cannot be accessed through the library file address in the abstract file, a search request is sent to the terminal, the terminal searches other abstract files with abstract information identical to the abstract file, and after the conforming abstract file is searched, the library file address in the abstract file is replaced by the library file address in the conforming abstract file.
4. The code library file generating method according to claim 1, wherein the specific process of obtaining the programming language and the environment information of each source code in step S1 is as follows:
step S11, aiming at the source code, firstly searching the annotation of the source code, determining whether a character string for recording language and environment information exists in the annotation, and if so, directly reading the language and environment information from the annotation; if not, the step S12 is carried out;
step S12, reading from the beginning of the source code, and reading the character strings;
step S13, searching each language/environment judgment file in the environment judgment library for the currently acquired character string, and judging whether the language/environment judgment file comprises the character string or not; if yes, go to step S14; if not, the step S15 is carried out;
Step S14, reading language and environment information from a language/environment judgment file in which the currently read character string is located, and feeding back the language and environment information; and then judging whether the first condition and the second condition are satisfied in all the language and environment information fed back currently, wherein the first condition is as follows: the feedback times of certain language information in all the currently fed back languages and environment information exceed y times, and the feedback times of certain environment information in all the currently fed back languages and environment information exceed q times under a second condition;
if the first condition and the second condition are met, judging the language of the source code as the language information, and judging the environment of the source code as the environment information;
if only the first condition is satisfied and the second condition is not satisfied, determining the language of the source code as the language information, ending the acquisition of the source code language information, and then proceeding to step S15;
if only the second condition is satisfied and the first condition is satisfied, determining the environment of the source code as such environment information, ending the acquisition of the environment information of the source code, and then proceeding to step S15;
if the first condition and the second condition are not satisfied; step S15 is entered;
Step S15, judging whether the current read character string is the last character string of the source code, if so, entering step S17; if not, the step S16 is carried out;
step S16, reading the next character string in the source code as the currently read character string, and then entering step S13;
step S17, acquiring all language and environment information fed back in the step S14; when the language information of the source code is not judged yet, the language information with the largest feedback times is used as the language information of the source code; when the environment information of the source code is not judged yet, the environment information with the largest feedback times is taken as the environment information of the source code.
5. The method of generating a code library file according to claim 1, wherein the method of generating a test code by amplifying each element code segment in step S3 adopts a template addition method, a subtraction method or a complementary method, wherein:
the step of obtaining the test code by using the template addition method is as follows:
step 1, screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments;
step 2: retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking;
Step 3: splitting the marked sentence into character strings, matching the split character strings with the entrance/exit keywords of the screened templates, selecting the template with the largest matching item, and completing the matching of the templates;
adding element code segments to the selected templates to obtain test codes, and storing the test codes into corresponding library files;
the step of obtaining the test code by adopting the removal method is as follows:
firstly, generating a copy of a source code, and defining a unit code segment corresponding to a test code to be generated as a target code segment; marking the target code segment statement as a reserved statement in a copy of the source code, deleting other element code segments, and deleting the statement calling the other element code segments;
retrieving the target code section call statement to obtain an input variable therein, retrieving the statement related to the input variable and the statement defining the input variable before the main function is called in the target code section call statement through the name of the input variable, marking the statement as a reserved statement, and deleting the rest of the statements containing the name of the input variable; simultaneously deleting other irrelevant sentences;
deleting sentences which are not marked as reserved in the copy of the source code by adopting an edge deleting and debug method, taking the code which is least and complete in the finally obtained sentences as a test code, and storing the test code into a corresponding library file;
The test code is obtained by the supplement method as follows:
s3a, screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments;
step S3b, operation 1: screening templates according to the parameter types of the element code segments and the language and environment information of the element code segments; operation 2: retrieving the element code segment, identifying the entry/exit of the element code segment through keyword and semantic analysis and marking; operation 3: splitting the marked sentence into character strings, matching the split character strings with the entrance/exit keywords of the screened templates, selecting the template with the largest matching item, and completing the matching of the templates;
step S3c, adding the element code segment to the template selected in the step S3b to obtain a test code;
s3d, testing the input test data by adopting the test code obtained in the step S3c, and if the test cannot pass; the following steps are performed:
s3d1, generating a copy of the source code, and defining a unit code segment corresponding to the test code to be generated as a target code segment; marking the target code segment statement as a reserved statement in a copy of the source code, deleting other element code segments, and deleting the statement calling the other element code segments;
S3d2, retrieving the target code section call statement to obtain an input variable therein, retrieving the statement which is reserved in the target code section call statement and is related to the input variable and the statement which defines the input variable before the main function is called, marking the statement as reserved statement, and deleting the rest of the statements containing the input variable name; simultaneously deleting other irrelevant sentences;
step S3d3, carrying out relevance analysis on the statements which are not reserved in the copy of the source code, and summarizing the related statements together to be used as a partial code;
step S3d4, selecting one of the obtained partial codes as the current partial code for each of the obtained partial codes;
step S3d5, adding the current partial code to the template screened in the step S3b, and then adding the element code segment to the obtained template to obtain a test code; inputting test data for one time aiming at the test codes, if the test is passed, taking the test codes as final test codes, and if the test is not passed, entering a step S3d6;
step S3d6, selecting the next partial code as the current partial code, and then executing step S3d5 until the obtained test code input test data can pass through after one test, and storing the test code passing the test into a corresponding library file;
In the step S3, when generating a call statement for each element code, it is first determined whether there is a data association statement in the function call statement; if yes, adding the data association statement before a function call statement in the element code segment, then searching an entry of the element code segment, and generating a corresponding call statement from the entry in the optimized code segment to the function call part; if not, directly searching the entry of the element code segment, and generating a corresponding call statement from the entry of the element code segment to the statement of the function call part.
6. A code search method characterized by the steps of:
step X1, firstly, obtaining a code library file generating method according to any one of claims 1 to 5 to generate a library file and a summary file pointing to the library file;
step X2, after receiving the code segment search request of the user:
step X21, acquiring the input type of a code segment required by a user, and then screening out abstract files with the input type identical to the input type of the code segment;
step X22, obtaining the output type of the code segment required by the user, and filtering out the abstract file with the output type identical to the output type of the code segment from the abstract files screened in the step X21 again;
Step X23, generating a test data list according to the input type input by the user, selecting corresponding test data by the user through the test data list, and inputting a corresponding output value by the user according to the selected test data; aiming at each group of output values which are input by the user for each group of test data selected by the user, matching each group of output values with each group of output results in the summary files screened in the step X22, and screening summary files with each group of output results being the same as each group of output values which are input by the user for each group of test data selected by the user;
step X24, acquiring a first label which is selected by a user and needs to be reserved, comparing the label in the first label with the first label aiming at the abstract file screened in the step X23, screening the abstract file with the same label as the first label again, acquiring a second label which is selected by the user and needs to be deleted, screening the abstract file with the same label as the second label from the abstract files screened again, and deleting the abstract file;
and step X25, recommending the abstract file finally reserved in the step X24 to a user, and enabling the user to acquire the corresponding library file for testing and selecting.
7. An automatic code coupling method is characterized by comprising the following steps:
Step Y1, firstly, obtaining a code library file generating method according to any one of claims 1 to 5 to generate a library file selected by a user and a summary file pointing to the library file;
y2, acquiring a user function name in a self-definition mode, and aiming at a library file selected by a user, reading the function name of a summary file pointing to the library file and defining the function name as the library file function name; extracting corresponding function definition content in the element code of the library file and modifying as follows: replacing the function name of the library file in the function definition content with the function name of the user, and then adding the modified function definition content into source codes input by the user;
acquiring a user function name of a user definition; for a library file selected by a user, reading the function name of a summary file pointing to the library file, and defining the function name as a library file function name; and simultaneously creating a header file and naming the header file by a user function name, extracting corresponding function definition contents in element codes of the library file, and modifying the function definition contents as follows: replacing the function name of the library file in the function definition content with the function name of the user, adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by the user;
And Y3, aiming at the library file selected by the user, acquiring a call statement in the library file after the user selects the input variable, adding the call statement to a user-specified function call position in source codes input by the user, and modifying the variable in the call statement into a variable name input by the user.
8. A code optimization method, characterized by the steps of:
step Z1, firstly, obtaining a code library file generation method according to any one of claims 1 to 5 to generate a library file and a summary file pointing to the library file, wherein the library file and the summary file are defined as a first library file and a first summary file;
for a source code segment selected by a user, firstly generating a second library file, simultaneously acquiring an inlet and an outlet of the source code segment, extracting an input/output parameter type and a function name from the inlet and the outlet, and then adding the source code segment and the extracted input/output parameter type and function name thereof to the second library file;
meanwhile, aiming at a source code segment selected by a user, amplifying the source code segment to generate a test code, storing the test code segment into a second library file, generating a test data list at the same time, inputting each group of test data in the test data list into the test code, obtaining corresponding groups of output results after the test code is operated, and adding the groups of output results into the second library file;
Meanwhile, adding amplification test data in a second library file;
step Z2, generating a second abstract file pointing to the second library file generated in the step Z1, extracting the input/output parameter types, function names, output results of each group and amplification test data stored in the second library file, storing the extracted results as abstract contents in the second abstract file, and simultaneously storing the address of the second library file in the second abstract file;
step Z3, matching the second abstract file pointing to the second library file obtained in the step Z2 with each first abstract file pointing to each first library file obtained in the step Z1, wherein the specific matching process is as follows:
step Z31, obtaining input types in the second abstract files, and then screening out first abstract files with the same input types as the input types in the second abstract files from the first abstract files;
step Z32, obtaining the output type in the second abstract file, and filtering out the first abstract files with the same output type as the output type in the second abstract file from the first abstract files screened in the step Z31 again;
step Z33, obtaining each group of output results in the second abstract files, and re-screening each group of first abstract files screened in the step Z32 to obtain first abstract files with the same corresponding output results as each group of output results in the second abstract files;
Step Z34, adding amplification test data into the first abstract files screened in the step Z33, and simultaneously acquiring first library files pointed by the first abstract files; for each obtained first library file, inputting each group of amplification test data in a first abstract file pointing to the first library file in a test code, obtaining corresponding temporary output results of each group after the test code is operated, and adding the temporary output results of each group into the first library file and the first abstract file pointing to the first library file according to the sequence of the amplification test data of each group;
meanwhile, for the second library file, calling the test codes therein, then respectively inputting each group of amplification test data in the second abstract file into the test codes, obtaining corresponding temporary output results of each group after the test codes are operated, and adding the temporary output results of each group into the second library file and the first abstract file;
step Z35, obtaining each group of temporary output results in the first abstract files, and screening out the first abstract files, of which each group of temporary output results corresponds to the same as each group of temporary output results in the second abstract files, from each first abstract file obtained in the step Z34;
Step Z36, searching each first library file according to the library file address stored in the first abstract file screened in the step Z35, and obtaining the running time of the test codes in each first library file; and displaying the operation time of the test codes in each first abstract file screened in the step Z35 and each first library file pointed by the first abstract file to a user for selection by the user, and finally taking the element code segment in the first library file pointed by the library file address stored in the first abstract file selected by the user as an optimized code segment and replacing the source code segment selected by the user by the optimized code segment.
9. The code optimization method according to claim 8, wherein in the step Z36, the specific process of replacing the code segment selected by the user with the optimized code segment is as follows:
step Z361, searching a first abstract file pointing to a first library file where the optimized code segment is located and a second abstract file pointing to the optimized code segment, and reading function names in the first abstract file and the second abstract file, wherein the function names are respectively defined as library file function names and user function names correspondingly; extracting corresponding function definition content in the element code of the first library file and modifying as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into source codes input by users;
Or searching a first abstract file pointing to a first library file where the optimized code segment is located and a second abstract file pointing to the optimized code segment, and reading function names in the first abstract file and the second abstract file, wherein the function names are respectively defined as library file function names and user function names correspondingly; newly creating a header file and naming the header file by a user function name, extracting corresponding function definition contents in element codes of the first library file, and modifying the function definition contents as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by a user;
step Z362, for the first library file in which the optimized code segment is located, obtaining a call statement in the first library file after the user selects the input variable, adding the call statement to the source code input by the user, designating the function call position by the user, and modifying the variable therein to be the variable name input by the user.
10. A code auxiliary transplanting method is characterized by comprising the following steps:
step B1, firstly, obtaining a code library file generating method according to any one of claims 1 to 5 to generate a library file and a summary file pointing to the library file, wherein the library file and the summary file are defined as a first library file and a first summary file;
When a source code transplanting request of a user is received, firstly dividing the source code into independent code segments with complete functions according to a slicing rule file; for each obtained code segment to be transplanted, firstly, respectively generating a third library file, searching an input/output statement of each code segment, extracting an input/output parameter type and a function name from the input/output statement, and then storing the extracted input/output parameter type and function name into the third library file corresponding to each code segment;
meanwhile, amplifying the obtained code segments to be transplanted to generate test codes, generating a plurality of groups of test data, sequencing the groups of test data to generate a test data list, inputting each group of test data in the test data list into the test code segments, obtaining corresponding groups of output results after the test codes are operated, and adding the groups of output results into a third library file according to the sequencing of the corresponding groups of test data;
for the obtained third library file of each code segment, generating a third abstract file pointing to the third library file, extracting the input/output parameter type, function name and each group of output results stored in the third library file, storing the extracted results as abstract contents in the third abstract file, and simultaneously storing the address of the third library file in the third abstract file;
Step B2, for each third abstract file pointing to each third library file obtained in step B1, matching the third abstract file with each first abstract file pointing to each first library file obtained in step B1, wherein the specific matching process is as follows:
step B21, obtaining the input type and the output type in the third abstract file, simultaneously obtaining the language and the environment information of the code to be transplanted by the user as the appointed language and the environment information, and then screening out first abstract files which have the same input type and the output type as the third abstract file and the same language and the environment information as the appointed language and the environment information from the first abstract files;
step B22, obtaining each group of output results in the third abstract file, and re-screening each group of output results from the first abstract files screened in the step B21 to obtain first abstract files with the same corresponding to each group of output results in the third abstract file; searching each first library file according to the library file address stored in the first abstract file to obtain the running time of the test code in each first library file; then, displaying the operation time of the test codes in the screened first abstract files and the first library files pointed by the first abstract files to a user so that the user can select corresponding first abstract files for the code segments to be transplanted;
Step B23, aiming at a third abstract file of the code segment which is finally needed to be transplanted and corresponds to the selected first abstract file and the code segment which is needed to be transplanted, reading function names in the first abstract file and the third abstract file, and respectively correspondingly defining the function names as library file function names and user function names; extracting corresponding function definition content in the element code of the first library file pointed by the first abstract file, and modifying as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into source codes input by users;
or for a third abstract file of the code segment which is finally needed to be transplanted and corresponds to the selected first abstract file and the code segment which is needed to be transplanted, reading function names in the first abstract file and the third abstract file, and respectively and correspondingly defining the function names as library file function names and user function names; newly creating a header file and naming the header file by a user function name; extracting corresponding function definition content in the element code of the first library file pointed by the first abstract file, and modifying the function definition content as follows: replacing the library file function name in the function definition content with the user function name; then adding the modified function definition content into a newly-built header file, and finally adding a statement for calling the header file into a source code input by a user;
And B24, aiming at a first library file pointed by the first abstract file which is finally selected by the user and corresponds to each source code segment to be transplanted, acquiring a call statement in the first library file after the user selects an input variable, adding the call statement to a user-specified function call position in source codes input by the user, and modifying the variable in the call statement to be the variable name input by the user.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811285105.0A CN109344230B (en) | 2018-10-31 | 2018-10-31 | Code library file generation, code search, coupling, optimization and migration method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811285105.0A CN109344230B (en) | 2018-10-31 | 2018-10-31 | Code library file generation, code search, coupling, optimization and migration method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109344230A CN109344230A (en) | 2019-02-15 |
CN109344230B true CN109344230B (en) | 2023-08-11 |
Family
ID=65313175
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811285105.0A Active CN109344230B (en) | 2018-10-31 | 2018-10-31 | Code library file generation, code search, coupling, optimization and migration method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109344230B (en) |
Families Citing this family (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110083351B (en) * | 2019-04-22 | 2023-06-27 | 北京百度网讯科技有限公司 | Method and device for generating code |
CN110196952B (en) * | 2019-05-30 | 2021-11-12 | 百度时代网络技术(北京)有限公司 | Program code search processing method, device, equipment and storage medium |
CN110221824B (en) * | 2019-06-03 | 2024-03-22 | 北京秒针人工智能科技有限公司 | Method and device for generating component |
CN111309853B (en) * | 2019-09-03 | 2024-03-22 | 东南大学 | Code searching method based on structured information |
CN111177313A (en) * | 2019-12-10 | 2020-05-19 | 同济大学 | Searching method for instantly inputting programming code and instantly searching reference multiplexing program |
CN111338616A (en) * | 2020-03-24 | 2020-06-26 | 北京自如信息科技有限公司 | Protocol analysis code generation method and device and electronic equipment |
CN112394936B (en) * | 2020-11-26 | 2024-06-25 | 中信银行股份有限公司 | Database operation instruction conversion method, device, equipment and storage medium |
US12039365B2 (en) * | 2021-03-30 | 2024-07-16 | International Business Machines Corporation | Program context migration |
CN113822014B (en) * | 2021-11-19 | 2022-03-29 | 北京明略昭辉科技有限公司 | Code material storage method and device, electronic equipment and storage medium |
CN114968351B (en) * | 2022-08-01 | 2022-10-21 | 北京大学 | Hierarchical multi-feature code homologous analysis method and system |
CN116185379B (en) * | 2022-11-17 | 2023-09-22 | 北京东方通科技股份有限公司 | Method for optimizing code hosting platform |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7496906B2 (en) * | 2004-03-31 | 2009-02-24 | International Business Machines Corporation | Evaluation of a code segment |
CN101826014B (en) * | 2010-04-20 | 2013-05-08 | 北京邮电大学 | Dividing method of source code in software engineering |
CN106919434B (en) * | 2017-03-22 | 2021-02-12 | 恒生电子股份有限公司 | Code generation method and device |
-
2018
- 2018-10-31 CN CN201811285105.0A patent/CN109344230B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN109344230A (en) | 2019-02-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109344230B (en) | Code library file generation, code search, coupling, optimization and migration method | |
CN110399457B (en) | Intelligent question answering method and system | |
CN109697162B (en) | Software defect automatic detection method based on open source code library | |
US9519636B2 (en) | Deduction of analytic context based on text and semantic layer | |
US20120303661A1 (en) | Systems and methods for information extraction using contextual pattern discovery | |
US7853595B2 (en) | Method and apparatus for creating a tool for generating an index for a document | |
CN113190687B (en) | Knowledge graph determining method and device, computer equipment and storage medium | |
JPWO2004034282A1 (en) | Content reuse management device and content reuse support device | |
CN113297251A (en) | Multi-source data retrieval method, device, equipment and storage medium | |
CN100498773C (en) | Method for indexing and retrieving documents, computer program and data carrier | |
CN113419721B (en) | Web-based expression editing method, device, equipment and storage medium | |
CN116304347A (en) | Git command recommendation method based on crowd-sourced knowledge | |
CN116400910A (en) | Code performance optimization method based on API substitution | |
CN110362694A (en) | Data in literature search method, equipment and readable storage medium storing program for executing based on artificial intelligence | |
CN115577694A (en) | Intelligent recommendation method for standard writing | |
CN114676155A (en) | Code prompt information determining method, data set determining method and electronic equipment | |
JP2018156552A (en) | Computer system and method for searching text data | |
JPH06195371A (en) | Unregistered word acquiring system | |
JP4477587B2 (en) | Method for generating operation buttons for computer processing of text data | |
JP2009181524A (en) | Document search system and document search method | |
CN112988137B (en) | System and method for managing class file import code | |
WO2024108986A1 (en) | Communication network service processing method and device | |
JP2009301511A (en) | Index information preparing device, index information preparing method and program | |
CN118297080A (en) | Content display method, device, computer equipment and storage medium | |
JP6476638B2 (en) | Specific term candidate extraction device, specific term candidate extraction method, and specific term candidate extraction program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |