CN113946340A - Code processing method and device, electronic equipment and storage medium - Google Patents

Code processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113946340A
CN113946340A CN202111166913.7A CN202111166913A CN113946340A CN 113946340 A CN113946340 A CN 113946340A CN 202111166913 A CN202111166913 A CN 202111166913A CN 113946340 A CN113946340 A CN 113946340A
Authority
CN
China
Prior art keywords
code
type
character string
sample code
sample
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.)
Pending
Application number
CN202111166913.7A
Other languages
Chinese (zh)
Inventor
朱林涛
彭飞
邓竹立
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing 58 Information Technology Co Ltd
Original Assignee
Beijing 58 Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing 58 Information Technology Co Ltd filed Critical Beijing 58 Information Technology Co Ltd
Priority to CN202111166913.7A priority Critical patent/CN113946340A/en
Publication of CN113946340A publication Critical patent/CN113946340A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a code processing method and device, electronic equipment and a storage medium. According to the method and the device, when the code which does not accord with the code normative rule needs to be corrected, the first target code which does not accord with the code normative rule can be obtained; the first sample code can be compiled normally. Acquiring a second target code which corresponds to the first target code and accords with code normative rules according to the code normative correction model; the execution result of the first object code is the same as the execution result of the second object code. Like this, can not have artificial participation in correcting the code that is not conform to code normative rule to can reduce the cost of labor, secondly, correct accuracy and integrality etc. that can improve the correction to the code that is not conforming to code normative rule through code normative correction model.

Description

Code processing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a code processing method and apparatus, an electronic device, and a storage medium.
Background
Developers in software companies write computer program codes every day, but the code normalization in the companies is low due to different habits of writing codes by different persons, and therefore, the code normalization needs to be improved.
Disclosure of Invention
The application discloses a code processing method and device, electronic equipment and a storage medium.
In a first aspect, the present application shows a method of code processing, the method comprising:
acquiring a first sample code which accords with code normative rules; the first sample code is capable of being compiled normally;
generating a second sample code corresponding to the first sample code and not conforming to code normative rules; the second sample code is capable of being compiled normally; the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code;
and training the model according to the first sample code and the second sample code until parameters in the model are converged, thereby obtaining a code normative correction model.
In an optional implementation manner, the generating a second sample code corresponding to the first sample code and not complying with the code normative rule includes:
and adding a third type of character string between the first type of character string and the second type of character string to obtain the second sample code under the condition that the first sample code comprises the first type of character string and the second type of character string, and the first type of character string is adjacent to the second type of character string.
In an optional implementation manner, the generating a second sample code corresponding to the first sample code and not complying with the code normative rule includes:
the first sample code comprises a second type character string and a fourth type character string related to the second type character string, and the second type character string and the fourth type character string are respectively arranged on different rows under the condition that the second type character string and the fourth type character string are located on the same row, so that the second sample code is obtained.
In an optional implementation manner, the generating a second sample code corresponding to the first sample code and not complying with the code normative rule includes:
and under the condition that the first sample code comprises the character string of the third type, adding at least one character string of the third type on the front side and/or the rear side of the character string of the third type to obtain the second sample code.
In an optional implementation manner, the generating a second sample code corresponding to the first sample code and not complying with the code normative rule includes:
in a case where there is a case in the first sample code where the end of the previous line includes a character string of a fifth type and the beginning of the next line adjacent thereto includes at least one character string of a third type, deleting at least a part of the character strings of the third type in the at least one character string of the third type in the next line, resulting in the second sample code.
In a second aspect, the present application illustrates a method of code processing, the method comprising:
acquiring a first target code which does not accord with a code normative rule; the first sample code is capable of being compiled normally;
acquiring a second target code which corresponds to the first target code and accords with code normative rules according to a code normative correction model; the execution result of the first target code is the same as the execution result of the second target code;
the code normative correction model is obtained by training a model according to a first sample code and a second sample code until parameters in the model are converged; the first sample code comprises code meeting code normative rules, and the second sample code comprises generated sample code which corresponds to the first sample code and does not meet the code normative rules; the first sample code is capable of being compiled normally; the second sample code is capable of being compiled normally; the execution result of the first sample code is the same as the execution result of the second sample code.
In a third aspect, the present application shows a code processing apparatus comprising:
the first acquisition module is used for acquiring a first sample code which accords with code normative rules; the first sample code is capable of being compiled normally;
the generating module is used for generating a second sample code which corresponds to the first sample code and does not conform to the code normative rule; the second sample code is capable of being compiled normally; the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code;
and the training module is used for training the model according to the first sample code and the second sample code until parameters in the model are converged, so that a code normative correction model is obtained.
In an optional implementation manner, the generating module is specifically configured to:
and adding a third type of character string between the first type of character string and the second type of character string to obtain the second sample code under the condition that the first sample code comprises the first type of character string and the second type of character string, and the first type of character string is adjacent to the second type of character string.
In an optional implementation manner, the generating module is specifically configured to:
the first sample code comprises a second type character string and a fourth type character string related to the second type character string, and the second type character string and the fourth type character string are respectively arranged on different rows under the condition that the second type character string and the fourth type character string are located on the same row, so that the second sample code is obtained.
In an optional implementation manner, the generating module is specifically configured to:
and under the condition that the first sample code comprises the character string of the third type, adding at least one character string of the third type on the front side and/or the rear side of the character string of the third type to obtain the second sample code.
In an optional implementation manner, the generating module is specifically configured to:
in a case where there is a case in the first sample code where the end of the previous line includes a character string of a fifth type and the beginning of the next line adjacent thereto includes at least one character string of a third type, deleting at least a part of the character strings of the third type in the at least one character string of the third type in the next line, resulting in the second sample code.
In a fourth aspect, the present application illustrates a code processing apparatus comprising:
the second acquisition module is used for acquiring the first target code which does not conform to the code normative rule; the first sample code is capable of being compiled normally;
the third acquisition module is used for acquiring a second target code which corresponds to the first target code and accords with the code normative rule according to a code normative correction model; the execution result of the first target code is the same as the execution result of the second target code;
the code normative correction model is obtained by training a model according to a first sample code and a second sample code until parameters in the model are converged; the first sample code comprises code meeting code normative rules, and the second sample code comprises generated sample code which corresponds to the first sample code and does not meet the code normative rules; the first sample code is capable of being compiled normally; the second sample code is capable of being compiled normally; the execution result of the first sample code is the same as the execution result of the second sample code.
In a fifth aspect, the present application illustrates an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to perform the code processing method of the first aspect.
In a sixth aspect, the present application illustrates a non-transitory computer-readable storage medium having instructions which, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method of the first aspect.
In a seventh aspect, the present application shows a computer program product, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method according to the first aspect.
In an eighth aspect, the present application illustrates an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to perform the code processing method according to the second aspect.
In a ninth aspect, the present application shows a non-transitory computer-readable storage medium having instructions which, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method of the second aspect.
In a tenth aspect, the present application shows a computer program product, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method according to the second aspect.
The technical scheme provided by the application can comprise the following beneficial effects:
in the present application, a first sample code is obtained that complies with code normative rules. The first sample code can be compiled normally. And generating a second sample code which corresponds to the first sample code and does not conform to the code normative rule. The second sample code can be compiled normally. The execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the first sample code. And training the model according to the first sample code and the second sample code until parameters in the model are converged, thereby obtaining a code normative correction model.
Therefore, when the code which does not conform to the code normative rule needs to be corrected, the first target code which does not conform to the code normative rule can be obtained; the first object code can be compiled normally. Acquiring a second target code which corresponds to the first target code and accords with code normative rules according to the code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code.
Like this, can not have artificial participation to the process of revising to the code that is not conform to code normative rule to can reduce the cost of labor, secondly, revise accuracy and integrality etc. that can improve the revision to the code that is not conforming to code normative rule through code normative revision model.
Drawings
FIG. 1 is a flow chart illustrating the steps of a method of code processing shown in the present application.
FIG. 2 is a flow chart illustrating steps of a method of code processing shown in the present application.
Fig. 3 is a block diagram of a code processing apparatus according to the present application.
Fig. 4 is a block diagram of a code processing apparatus according to the present application.
Fig. 5 is a block diagram of an electronic device shown in the present application.
Fig. 6 is a block diagram of an electronic device shown in the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flowchart illustrating steps of a code processing method according to the present application is applied to an electronic device, and the method may specifically include the following steps:
in step S101, a first sample code that conforms to a code normative rule is acquired. The first sample code can be compiled normally.
In one embodiment of the application, the first sample code that conforms to the code normative rules may be manually gathered, for example, the first sample code that conforms to the code normative rules may be manually gathered in code that is manually developed in advance, and the gathered first sample code may be set on the electronic device.
In another embodiment of the present application, a code normative rule may be manually formulated on an electronic device in advance, and then the electronic device may automatically generate a first sample code that conforms to the code normative rule, where when the electronic device generates the first sample code, the electronic device has the code normative rule, and specifically, how to generate the first sample code that conforms to the code normative rule under the condition that the code normative rule is obtained may refer to a currently existing generation manner, and the specific generation manner is not limited by the present application.
In step S102, a second sample code that does not comply with the code normative rule corresponding to the first sample code is generated. The second sample code can be compiled normally. The execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code.
In the present application, the generated second sample code is not identical to the first sample code, but is different in terms of code normative rules, in which the entity contents are identical, so that both the second sample code and the first sample code can be compiled normally.
And because the entity content of the generated second sample code is the same as that of the first sample code, the execution result of the executable file obtained by compiling the second sample code is the same as that of the executable file obtained by compiling the first sample code.
In one case, a plurality of different second sample codes corresponding to the first sample code may be generated that do not comply with code normative rules. Therefore, the first sample code and the plurality of different second sample codes form a one-to-many relationship, so that the training data of the later training code normative correction model can be increased, and the generalization degree of the trained code normative correction model can be improved.
In an embodiment of the present application, it may be detected whether the first sample code includes a first type of character string and a second type of character string, and whether the first type of character string is adjacent to the second type of character string, and the first sample code includes the first type of character string and the second type of character string, and when the first type of character string is adjacent to the second type of character string, a third type of character string is added between the first type of character string and the second type of character string, so as to obtain a second sample code.
One of the ways that a string of the first type is adjacent to a string of the second type is to understand: the first type of string and the second type of string are located on the same row, and there is no other string between the first type of string and the second type of string, e.g., the last element in the first type of string is next to the first element in the second type of string.
In one example, a first type of string may include return values and the like, a second type of string may include function names and the like, and a third type of string may include spaces and the like.
For example, assume that the first sample code that complies with code normative rules is:
Figure BDA0003291682850000071
in the first sample code, the first type of character string includes a return value "(void)", the second type of character string includes a function name "initialize", a third type of character string "space" may be added between the first type of character string return value "(void)" and the second type of character string function name "initialize", and a second sample code corresponding to the first sample code and not meeting the code normative rule is obtained:
Figure BDA0003291682850000081
in another embodiment of the present application, it may be detected whether the first sample code includes a second type character string and a fourth type character string associated with the second type character string, and whether the second type character string and the fourth type character string are located in the same row, where the first sample code includes the second type character string and the fourth type character string associated with the second type character string, and in a case that the second type character string and the fourth type character string are located in the same row, the second sample code is obtained by respectively setting the second type character string and the fourth type character string in different rows.
There is an association in content between the second type of character string and the fourth type of character string, for example, the second type of character string may include a function name and the like, and the fourth type of character string may include a function body (implementation of a function) corresponding to the function name and the like.
In one example, assume that the first sample code that complies with code normative rules is the code exemplified for the preceding example.
In the first sample code, the second type of character string includes the function name "initial", and the fourth type of character string includes the function body corresponding to the function name "initial":
Figure BDA0003291682850000082
the first element "{" in the function body corresponding to the second type of character string function name "initial" and the fourth type of character string function name "initial" is located in the same row (in this application, it is regarded that the function body corresponding to the second type of character string function name "initial" and the fourth type of character string function name "initial" is located in the same row), and the first element "{" in the function body corresponding to the function name "initial" may be set in the next row, resulting in a second sample code corresponding to the first sample code and not meeting the code normative rules:
Figure BDA0003291682850000091
in another embodiment of the present application, it may be detected whether the first sample code includes a third type of character string, and in a case that the first sample code includes the third type of character string, at least one third type of character string is added to the front side and/or the rear side of the third type of character string to obtain the second sample code.
The third type of character string includes a space, a semicolon, a comma, and the like.
In one example, assume that the first sample code that complies with code normative rules is the code exemplified for the preceding example.
Wherein, in the first sample code, line 5 includes a third type of string "; ", may be in a third type of string"; "add a plurality of third type strings after"; "to obtain a second sample code corresponding to the first sample code and not meeting the code normative rules:
Figure BDA0003291682850000092
in another embodiment of the present application, it may be detected whether there is a case in the first sample code where the end of the previous line includes a character string of the fifth type and the beginning of the next adjacent line includes at least one character string of the third type, and in the first sample code where there is a case in which the end of the previous line includes a character string of the fifth type and the beginning of the next adjacent line includes at least one character string of the third type, at least a part of the character string of the third type in the at least one character string of the third type in the next line may be deleted to obtain the second sample code.
The third type of character string includes a space, a semicolon, a comma, and the like.
The fifth type of character string includes a character string for containing one structural body (e.g., a function body) or the like, for example, "{" or the like.
In one example, assume that the first sample code that complies with code normative rules is the code exemplified for the preceding example.
In the first sample code, the end of the 1 st line is a fifth type character string "{", and the beginning of the 2 nd line includes a plurality of (e.g., 4, etc.) third type character strings "spaces", that is, there is an indentation at the beginning of the 2 nd line code.
A number (e.g., 4, etc.) of third type character strings "spaces" at the beginning of line 2 may be deleted so that there is no indentation in the beginning of the code of line 2, resulting in a second sample code corresponding to the first sample code that does not comply with the code normative rules:
Figure BDA0003291682850000101
in step S103, the model is trained according to the first sample code and the second sample code until the parameters in the model converge, so as to obtain a code normative correction model.
In the training process, a second sample code can be input into the model, so that the model can correct the second sample code to obtain a corrected code, and then network parameters in the model can be adjusted based on the corrected code and the first sample code by means of a loss function until the network parameters in the model are converged, so that the training can be completed, and the code normative correction model can be obtained.
In the application, after the code normative correction model is obtained through training, whether the correction accuracy of the code normative correction model meets the requirement can be evaluated. And if the correction accuracy of the code normative correction model meets the requirement, the code normative correction model can be applied on line, and if the correction accuracy of the code normative correction model does not meet the requirement, the code normative correction model can be continuously optimized until the correction accuracy of the code normative correction model meets the requirement, and then the code normative correction model is applied on line.
For example, a first test code may be obtained that complies with code normative rules. The first test code can be compiled normally. And generating a second test code which corresponds to the first test code and does not conform to the code normative rule. The second test code can be compiled normally. The execution result of the executable file obtained by compiling the first test code is the same as the execution result of the executable file obtained by compiling the second test code.
The manner of acquiring the first test code may refer to the manner of acquiring the first sample code in step S101, and is not described in detail here.
The manner of acquiring the second test code may refer to the manner of acquiring the second sample code in step S102, which is not described in detail herein.
The second test code which does not conform to the code normative rule can be input into the code normative correction model, so that the code normative correction model corrects the second test code which does not conform to the code normative rule, and the corrected code is output.
The first test code is then compared with the processed code to see if there is any place in the processed code that is different from the first test code.
If the place different from the first test code does not exist, the code normative correction model can correct the second test code which does not conform to the code normative rule, and the code normative correction model can be used online.
Or if the place different from the first test code exists, the code normative correction model does not correct the second test code which does not conform to the code normative rule, so that the accuracy of the code normative correction model does not meet the requirement, the code normative correction model can be continuously optimized until the accuracy of the code normative correction model meets the requirement, and the code normative correction model can be used online.
In the present application, a first sample code is obtained that complies with code normative rules. The first sample code can be compiled normally. And generating a second sample code which corresponds to the first sample code and does not conform to the code normative rule. The second sample code can be compiled normally. The execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the first sample code. And training the model according to the first sample code and the second sample code until parameters in the model are converged, thereby obtaining a code normative correction model.
Therefore, when the code which does not conform to the code normative rule needs to be corrected, the first target code which does not conform to the code normative rule can be obtained; the first object code can be compiled normally. Acquiring a second target code which corresponds to the first target code and accords with code normative rules according to the code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code.
Like this, can not have artificial participation to the process of revising to the code that is not conform to code normative rule to can reduce the cost of labor, secondly, revise accuracy and integrality etc. that can improve the revision to the code that is not conforming to code normative rule through code normative revision model.
After the trained code normative correction model is deployed on a line for application, if the electronic device needs to detect whether the code conforms to the code normative rules, and if the code does not conform to the code normative rules, the code is corrected so that the corrected code conforms to the code normative rules, the electronic device can input the code into the code normative correction model so that the code normative correction model detects whether the code conforms to the code normative rules, and if the code does not conform to the code normative rules, the code is corrected and the corrected code is output, so that the electronic device can obtain the corrected code, namely the code conforming to the code normative rules.
The specific process can be seen in the embodiment shown in fig. 2.
Referring to fig. 2, a flowchart illustrating steps of a code processing method according to the present application is shown, and the method is applied to an electronic device, and specifically may include the following steps:
in step S201, a first target code that does not comply with the code normative rule is acquired; the first object code can be compiled normally.
The first target code which does not conform to the code normative rule can be code which is manually developed by a developer in the working process, and in order to unify the code developed by a group, the code which is developed by the developer in the group in the working process can be obtained and used as the first target code.
In step S202, a second target code corresponding to the first target code and conforming to the code normative rule is obtained according to the code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code.
The code normative correction model is obtained by training a model according to a first sample code and a second sample code until parameters in the model are converged; the first sample code comprises code meeting code normative rules, and the second sample code comprises generated sample code which corresponds to the first sample code and does not meet the code normative rules; the first sample code can be compiled normally; the second sample code can be compiled normally; the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code.
The specific training mode of the code normative correction model can be referred to the embodiment shown in fig. 1, and is not described in detail here.
In the application, the first target code may be output to a code normative correction model, so that the code normative correction model performs correction processing on the first target code to obtain a second target code meeting code normative rules.
Further, the first object code that does not comply with the code normative rules may be replaced with a second object code that complies with the code normative rules, after which the first object code that does not comply with the code normative rules is no longer used, but the second object code that complies with the code normative rules may be used.
Further, prompt information can be output to inform a developer of which places of the first target code which does not conform to the code normative rules are modified to obtain a second target code which conforms to the code normative rules.
According to the method and the device, when the code which does not accord with the code normative rule needs to be corrected, the first target code which does not accord with the code normative rule can be obtained; the first object code can be compiled normally. Acquiring a second target code which corresponds to the first target code and accords with code normative rules according to the code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code.
Like this, can not have artificial participation to the process of revising to the code that is not conform to code normative rule to can reduce the cost of labor, secondly, revise accuracy and integrality etc. that can improve the revision to the code that is not conforming to code normative rule through code normative revision model.
It is noted that, for simplicity of explanation, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will appreciate that the present application is not limited by the order of acts, as some steps may, in accordance with the present application, occur in other orders and concurrently. Further, those skilled in the art will also appreciate that the embodiments described in the specification are exemplary and that no action is necessarily required in this application.
Referring to fig. 3, a block diagram of a code processing apparatus of the present application is shown, and the code processing apparatus is applied to an electronic device, and the apparatus may specifically include the following modules:
a first obtaining module 11, configured to obtain a first sample code that meets a code normative rule; the first sample code is capable of being compiled normally;
a generating module 12, configured to generate a second sample code that corresponds to the first sample code and does not conform to the code normative rule; the second sample code is capable of being compiled normally; the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code;
and the training module 13 is configured to train the model according to the first sample code and the second sample code until parameters in the model converge, so as to obtain a code normative correction model.
In an optional implementation manner, the generating module is specifically configured to:
and adding a third type of character string between the first type of character string and the second type of character string to obtain the second sample code under the condition that the first sample code comprises the first type of character string and the second type of character string, and the first type of character string is adjacent to the second type of character string.
In an optional implementation manner, the generating module is specifically configured to:
the first sample code comprises a second type character string and a fourth type character string related to the second type character string, and the second type character string and the fourth type character string are respectively arranged on different rows under the condition that the second type character string and the fourth type character string are located on the same row, so that the second sample code is obtained.
In an optional implementation manner, the generating module is specifically configured to:
and under the condition that the first sample code comprises the character string of the third type, adding at least one character string of the third type on the front side and/or the rear side of the character string of the third type to obtain the second sample code.
In an optional implementation manner, the generating module is specifically configured to:
in a case where there is a case in the first sample code where the end of the previous line includes a character string of a fifth type and the beginning of the next line adjacent thereto includes at least one character string of a third type, deleting at least a part of the character strings of the third type in the at least one character string of the third type in the next line, resulting in the second sample code.
In the present application, a first sample code is obtained that complies with code normative rules. The first sample code can be compiled normally. And generating a second sample code which corresponds to the first sample code and does not conform to the code normative rule. The second sample code can be compiled normally. The execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the first sample code. And training the model according to the first sample code and the second sample code until parameters in the model are converged, thereby obtaining a code normative correction model.
Therefore, when the code which does not conform to the code normative rule needs to be corrected, the first target code which does not conform to the code normative rule can be obtained; the first object code can be compiled normally. Acquiring a second target code which corresponds to the first target code and accords with code normative rules according to the code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code.
Like this, can not have artificial participation to the process of revising to the code that is not conform to code normative rule to can reduce the cost of labor, secondly, revise accuracy and integrality etc. that can improve the revision to the code that is not conforming to code normative rule through code normative revision model.
Referring to fig. 4, a block diagram of a code processing apparatus of the present application is shown, and the code processing apparatus is applied to an electronic device, and the apparatus may specifically include the following modules:
a second obtaining module 21, configured to obtain a first target code that does not meet the code normative rule; the first sample code is capable of being compiled normally;
a third obtaining module 22, configured to obtain, according to a code normative correction model, a second target code that corresponds to the first target code and meets a code normative rule; the execution result of the first target code is the same as the execution result of the second target code;
the code normative correction model is obtained by training a model according to a first sample code and a second sample code until parameters in the model are converged; the first sample code comprises code meeting code normative rules, and the second sample code comprises generated sample code which corresponds to the first sample code and does not meet the code normative rules; the first sample code is capable of being compiled normally; the second sample code is capable of being compiled normally; the execution result of the first sample code is the same as the execution result of the second sample code.
According to the method and the device, when the code which does not accord with the code normative rule needs to be corrected, the first target code which does not accord with the code normative rule can be obtained; the first object code can be compiled normally. Acquiring a second target code which corresponds to the first target code and accords with code normative rules according to the code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code.
Like this, can not have artificial participation to the process of revising to the code that is not conform to code normative rule to can reduce the cost of labor, secondly, revise accuracy and integrality etc. that can improve the revision to the code that is not conforming to code normative rule through code normative revision model.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
Optionally, an embodiment of the present invention further provides an electronic device, including: the processor, the memory, and the computer program stored in the memory and capable of running on the processor, when being executed by the processor, implement each process of the code processing method embodiments, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program implements each process of the code processing method embodiment, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here. The computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
Fig. 5 is a block diagram of an electronic device 800 shown in the present application. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like.
Referring to fig. 5, electronic device 800 may include one or more of the following components: a processing component 802, a memory 804, a power component 806, a multimedia component 808, an audio component 810, an input/output (I/O) interface 812, a sensor component 814, and a communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operation at the device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, images, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front-facing camera and/or the rear-facing camera may receive external multimedia data when the device 800 is in an operating mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in the position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in the temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 may access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives broadcast signals or broadcast operation information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium comprising instructions, such as the memory 804 comprising instructions, executable by the processor 820 of the electronic device 800 to perform the above-described method is also provided. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
Fig. 6 is a block diagram of an electronic device 1900 shown in the present application. For example, the electronic device 1900 may be provided as a server.
Referring to fig. 6, electronic device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method.
The electronic device 1900 may also include a power component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input/output (I/O) interface 1958. The electronic device 1900 may operate based on an operating system stored in memory 1932, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a U disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (16)

1. A method of code processing, the method comprising:
acquiring a first sample code which accords with code normative rules; the first sample code is capable of being compiled normally;
generating a second sample code corresponding to the first sample code and not conforming to code normative rules; the second sample code is capable of being compiled normally; the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code;
and training the model according to the first sample code and the second sample code until parameters in the model are converged, thereby obtaining a code normative correction model.
2. The method of claim 1, wherein generating a second sample code corresponding to the first sample code that does not comply with code normative rules comprises:
and adding a third type of character string between the first type of character string and the second type of character string to obtain the second sample code under the condition that the first sample code comprises the first type of character string and the second type of character string, and the first type of character string is adjacent to the second type of character string.
3. The method of claim 1, wherein generating a second sample code corresponding to the first sample code that does not comply with code normative rules comprises:
the first sample code comprises a second type character string and a fourth type character string related to the second type character string, and the second type character string and the fourth type character string are respectively arranged on different rows under the condition that the second type character string and the fourth type character string are located on the same row, so that the second sample code is obtained.
4. The method of claim 1, wherein generating a second sample code corresponding to the first sample code that does not comply with code normative rules comprises:
and under the condition that the first sample code comprises the character string of the third type, adding at least one character string of the third type on the front side and/or the rear side of the character string of the third type to obtain the second sample code.
5. The method of claim 1, wherein generating a second sample code corresponding to the first sample code that does not comply with code normative rules comprises:
in a case where there is a case in the first sample code where the end of the previous line includes a character string of a fifth type and the beginning of the next line adjacent thereto includes at least one character string of a third type, deleting at least a part of the character strings of the third type in the at least one character string of the third type in the next line, resulting in the second sample code.
6. A method of code processing, the method comprising:
acquiring a first target code which does not accord with a code normative rule; the first object code is capable of being compiled normally;
acquiring a second target code which corresponds to the first target code and accords with code normative rules according to a code normative correction model; the execution result of the executable file obtained by compiling the first object code is the same as the execution result of the executable file obtained by compiling the second object code;
the code normative correction model is obtained by training a model according to a first sample code and a second sample code until parameters in the model are converged; the first sample code comprises code meeting code normative rules, and the second sample code comprises generated sample code which corresponds to the first sample code and does not meet the code normative rules; the first sample code is capable of being compiled normally; the second sample code is capable of being compiled normally; and the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code.
7. A code processing apparatus, characterized in that the apparatus comprises:
the first acquisition module is used for acquiring a first sample code which accords with code normative rules; the first sample code is capable of being compiled normally;
the generating module is used for generating a second sample code which corresponds to the first sample code and does not conform to the code normative rule; the second sample code is capable of being compiled normally; the execution result of the executable file obtained by compiling the first sample code is the same as the execution result of the executable file obtained by compiling the second sample code;
and the training module is used for training the model according to the first sample code and the second sample code until parameters in the model are converged, so that a code normative correction model is obtained.
8. The apparatus of claim 7, wherein the generating module is specifically configured to:
and adding a third type of character string between the first type of character string and the second type of character string to obtain the second sample code under the condition that the first sample code comprises the first type of character string and the second type of character string, and the first type of character string is adjacent to the second type of character string.
9. The apparatus of claim 7, wherein the generating module is specifically configured to:
the first sample code comprises a second type character string and a fourth type character string related to the second type character string, and the second type character string and the fourth type character string are respectively arranged on different rows under the condition that the second type character string and the fourth type character string are located on the same row, so that the second sample code is obtained.
10. The apparatus of claim 7, wherein the generating module is specifically configured to:
and under the condition that the first sample code comprises the character string of the third type, adding at least one character string of the third type on the front side and/or the rear side of the character string of the third type to obtain the second sample code.
11. The apparatus of claim 7, wherein the generating module is specifically configured to:
in a case where there is a case in the first sample code where the end of the previous line includes a character string of a fifth type and the beginning of the next line adjacent thereto includes at least one character string of a third type, deleting at least a part of the character strings of the third type in the at least one character string of the third type in the next line, resulting in the second sample code.
12. A code processing apparatus, characterized in that the apparatus comprises:
the second acquisition module is used for acquiring the first target code which does not conform to the code normative rule; the first sample code is capable of being compiled normally;
the third acquisition module is used for acquiring a second target code which corresponds to the first target code and accords with the code normative rule according to a code normative correction model; the execution result of the first target code is the same as the execution result of the second target code;
the code normative correction model is obtained by training a model according to a first sample code and a second sample code until parameters in the model are converged; the first sample code comprises code meeting code normative rules, and the second sample code comprises generated sample code which corresponds to the first sample code and does not meet the code normative rules; the first sample code is capable of being compiled normally; the second sample code is capable of being compiled normally; the execution result of the first sample code is the same as the execution result of the second sample code.
13. An electronic device, comprising: processor, memory and a computer program stored on the memory and executable on the processor, which computer program, when executed by the processor, implements the steps of the code processing method according to any of claims 1 to 5.
14. A computer-readable storage medium, characterized in that a computer program is stored thereon, which computer program, when being executed by a processor, realizes the steps of the code processing method according to any one of claims 1 to 5.
15. An electronic device, comprising: processor, memory and a computer program stored on the memory and executable on the processor, which computer program, when executed by the processor, carries out the steps of the code processing method according to claim 6.
16. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, carries out the steps of the code processing method of claim 6.
CN202111166913.7A 2021-09-30 2021-09-30 Code processing method and device, electronic equipment and storage medium Pending CN113946340A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111166913.7A CN113946340A (en) 2021-09-30 2021-09-30 Code processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111166913.7A CN113946340A (en) 2021-09-30 2021-09-30 Code processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113946340A true CN113946340A (en) 2022-01-18

Family

ID=79329925

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111166913.7A Pending CN113946340A (en) 2021-09-30 2021-09-30 Code processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113946340A (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109871317A (en) * 2019-01-11 2019-06-11 平安普惠企业管理有限公司 Code quality analysis method and device, storage medium and electronic equipment
US20190220253A1 (en) * 2018-01-15 2019-07-18 Cognizant Technology Solutions India Pvt. Ltd. System and method for improving software code quality using artificial intelligence techniques
CN110109823A (en) * 2019-04-02 2019-08-09 视联动力信息技术股份有限公司 A kind of application program repairing method and device
US10423709B1 (en) * 2018-08-16 2019-09-24 Audioeye, Inc. Systems, devices, and methods for automated and programmatic creation and deployment of remediations to non-compliant web pages or user interfaces
CN110297656A (en) * 2019-05-23 2019-10-01 重庆金融资产交易所有限责任公司 Method, apparatus and computer equipment based on allocation models evaluation code
CN110334483A (en) * 2019-06-20 2019-10-15 韶关市启之信息技术有限公司 A kind of code protection method and device
CN111061488A (en) * 2019-12-18 2020-04-24 深圳前海环融联易信息科技服务有限公司 Method and device for detecting quality of front-end code, computer equipment and storage medium
US20200301672A1 (en) * 2019-03-20 2020-09-24 International Business Machines Corporation Generating program analysis rules based on coding standard documents
CN111832028A (en) * 2020-07-27 2020-10-27 中国工商银行股份有限公司 Code auditing method and device, electronic equipment and medium
CN112416361A (en) * 2020-12-03 2021-02-26 平安普惠企业管理有限公司 Structured query language script examination method and related equipment

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190220253A1 (en) * 2018-01-15 2019-07-18 Cognizant Technology Solutions India Pvt. Ltd. System and method for improving software code quality using artificial intelligence techniques
US10423709B1 (en) * 2018-08-16 2019-09-24 Audioeye, Inc. Systems, devices, and methods for automated and programmatic creation and deployment of remediations to non-compliant web pages or user interfaces
CN109871317A (en) * 2019-01-11 2019-06-11 平安普惠企业管理有限公司 Code quality analysis method and device, storage medium and electronic equipment
US20200301672A1 (en) * 2019-03-20 2020-09-24 International Business Machines Corporation Generating program analysis rules based on coding standard documents
CN110109823A (en) * 2019-04-02 2019-08-09 视联动力信息技术股份有限公司 A kind of application program repairing method and device
CN110297656A (en) * 2019-05-23 2019-10-01 重庆金融资产交易所有限责任公司 Method, apparatus and computer equipment based on allocation models evaluation code
CN110334483A (en) * 2019-06-20 2019-10-15 韶关市启之信息技术有限公司 A kind of code protection method and device
CN111061488A (en) * 2019-12-18 2020-04-24 深圳前海环融联易信息科技服务有限公司 Method and device for detecting quality of front-end code, computer equipment and storage medium
CN111832028A (en) * 2020-07-27 2020-10-27 中国工商银行股份有限公司 Code auditing method and device, electronic equipment and medium
CN112416361A (en) * 2020-12-03 2021-02-26 平安普惠企业管理有限公司 Structured query language script examination method and related equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
刘树春 等: "《深度实践OCR 基于深度学习的文字识别》", 31 May 2020, 机械工业出版社 *

Similar Documents

Publication Publication Date Title
EP3176709A1 (en) Video categorization method and apparatus, computer program and recording medium
CN113238752B (en) Code generation method, device, electronic equipment and storage medium
CN104850643B (en) Picture comparison method and device
CN107885571B (en) Display page control method and device
CN107463372B (en) Data-driven page updating method and device
CN113590091A (en) Data processing method and device, electronic equipment and storage medium
CN107885464B (en) Data storage method, device and computer readable storage medium
CN110674416A (en) Game recommendation method and device
CN106126104B (en) Keyboard simulation method and device
CN113946340A (en) Code processing method and device, electronic equipment and storage medium
CN110457084B (en) Loading method and device
CN114416505A (en) Data processing method and device, electronic equipment and storage medium
CN114416247A (en) Data processing method and device, electronic equipment and storage medium
CN114201665A (en) Data processing method and device, electronic equipment and storage medium
CN104317480B (en) Character keys display methods, device and terminal
CN107766722B (en) Application software installation processing method and device and electronic equipment
CN111680248A (en) Method and device for generating batch number of message pushed
CN113934452B (en) Data processing method and device, electronic equipment and storage medium
CN113191792B (en) Task processing method, device, electronic equipment, storage medium and program product
CN114416218B (en) Data processing method and device, electronic equipment and storage medium
CN113946353B (en) Data processing method and device, electronic equipment and storage medium
CN113946346B (en) Data processing method and device, electronic equipment and storage medium
CN113467853B (en) Data processing method, apparatus, device, storage medium, and program product
CN114020504B (en) Data processing method and device, electronic equipment and storage medium
CN111241097B (en) Method for processing object, device for processing object and storage medium

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20220118