CN113010182A - Method and device for generating upgrade file and electronic equipment - Google Patents

Method and device for generating upgrade file and electronic equipment Download PDF

Info

Publication number
CN113010182A
CN113010182A CN202110321883.6A CN202110321883A CN113010182A CN 113010182 A CN113010182 A CN 113010182A CN 202110321883 A CN202110321883 A CN 202110321883A CN 113010182 A CN113010182 A CN 113010182A
Authority
CN
China
Prior art keywords
syntax tree
normalized
generating
parameter
upgrade 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.)
Granted
Application number
CN202110321883.6A
Other languages
Chinese (zh)
Other versions
CN113010182B (en
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 Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and 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 Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202110321883.6A priority Critical patent/CN113010182B/en
Priority to CN202210204861.6A priority patent/CN114816467B/en
Publication of CN113010182A publication Critical patent/CN113010182A/en
Application granted granted Critical
Publication of CN113010182B publication Critical patent/CN113010182B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring

Landscapes

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

Abstract

The disclosure discloses a method and a device for generating an upgrade file and electronic equipment, and relates to the technical field of artificial intelligence, in particular to the technical field of deep learning. The specific implementation scheme is as follows: obtaining a syntax tree corresponding to a source code; carrying out normalization processing on codes in the syntax tree to obtain a normalized syntax tree; converting the normalized syntax tree to obtain a converted normalized syntax tree; generating a converted source code according to the converted normalized syntax tree; and generating an upgrade file according to the converted source code. Therefore, the method can carry out code reconstruction based on the normalized syntax tree, further generates the upgrade file, is beneficial to improving the generation efficiency of the upgrade file, further can improve the development efficiency, and has good applicability and expansibility.

Description

Method and device for generating upgrade file and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for generating an upgrade file, an electronic device, a storage medium, and a computer program product.
Background
At present, with the progress of technology and the change of demand, the architecture and the use mode of software are continuously evolved, and developers need to develop the upgrade files in time, so that users can install the updated software in time according to the upgrade files. The generation method of the upgrade file in the related art has low generation efficiency, influences software development efficiency and has poor user experience.
Disclosure of Invention
Provided are a method and an apparatus for generating an upgrade file, an electronic device, a storage medium, and a computer program product.
According to a first aspect, there is provided a method for generating an upgrade file, including: obtaining a syntax tree corresponding to a source code; carrying out normalization processing on codes in the syntax tree to obtain a normalized syntax tree; converting the normalized syntax tree to obtain a converted normalized syntax tree; generating a converted source code according to the converted normalized syntax tree; and generating an upgrade file according to the converted source code.
According to a second aspect, there is provided an upgrade file generation apparatus, including: the obtaining module is used for obtaining a syntax tree corresponding to the source code; the normalization module is used for carrying out normalization processing on codes in the syntax tree to obtain a normalized syntax tree; the conversion module is used for converting the normalized syntax tree to obtain a converted normalized syntax tree; a generating module for generating a converted source code according to the converted normalized syntax tree; and the generating module is also used for generating an upgrading file according to the converted source code.
According to a third aspect, there is provided an electronic device comprising: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of generating an upgrade file according to the first aspect of the present disclosure.
According to a fourth aspect, there is provided a non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to execute the method of generating an upgrade file according to the first aspect of the present disclosure.
According to a fifth aspect, there is provided a computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the method of generating an upgrade file of the first aspect of the present disclosure.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
fig. 1 is a flowchart illustrating a method of generating an upgrade file according to a first embodiment of the present disclosure;
fig. 2 is a flowchart illustrating a method of generating an upgrade file according to a second embodiment of the present disclosure;
fig. 3 is a block diagram of an upgrade file generation apparatus according to a first embodiment of the present disclosure;
fig. 4 is a block diagram of an electronic device for implementing the method of generating an upgrade file according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
AI (Artificial Intelligence) is a technical science that studies and develops theories, methods, techniques and application systems for simulating, extending and expanding human Intelligence. At present, the AI technology has the advantages of high automation degree, high accuracy and low cost, and is widely applied.
DL (Deep Learning) is a new research direction in the field of ML (Machine Learning), and is an intrinsic rule and an expression level for Learning sample data, so that a Machine can have an analysis Learning capability like a human, can recognize data such as characters, images and sounds, and is widely applied to speech and image recognition.
Fig. 1 is a flowchart illustrating a method for generating an upgrade file according to a first embodiment of the present disclosure.
As shown in fig. 1, a method for generating an upgrade file according to a first embodiment of the present disclosure includes:
s101, obtaining a syntax tree corresponding to the source code.
It should be noted that the execution subject of the method for generating an upgrade file according to the embodiment of the present disclosure may be a hardware device having a data information processing capability and/or software necessary for driving the hardware device to operate. Alternatively, the execution body may include a workstation, a server, a computer, a user terminal and other intelligent devices. The user terminal includes, but is not limited to, a mobile phone, a computer, an intelligent voice interaction device, an intelligent household appliance, a vehicle-mounted terminal, and the like.
In the embodiment of the disclosure, a syntax tree corresponding to a source code may be obtained. It is to be understood that source code refers to code that requires code reconstruction, and that different source code may correspond to different syntax trees.
Optionally, the obtaining of the syntax tree corresponding to the source code may include inputting the source code into a preset syntax analyzer to obtain the syntax tree corresponding to the source code. Wherein, the grammar analyzer can be set according to actual conditions.
It should be noted that, in the embodiments of the present disclosure, the types of the source code and the syntax tree are not limited too much. For example, Syntax trees include, but are not limited to, AST (Abstract Syntax Tree), CST (Concrete Syntax Tree), and the like.
And S102, carrying out normalization processing on codes in the syntax tree to obtain a normalized syntax tree.
In the embodiment of the disclosure, codes in the syntax tree are normalized to obtain the normalized syntax tree, so that code reconstruction can be performed based on the normalized syntax tree, and the efficiency of code reconstruction is improved.
For example, one or more module names may exist in the code, each module may include multiple sub-modules, that is, each module name may correspond to multiple sub-module names, and then the sub-module names in the code may be modified into corresponding module names, so as to implement normalization processing on the module names in the code. For example, if the a module includes an a.fluid as fluid submodule, the name of the a.fluid as fluid submodule in the code may be modified to the a module name. It should be noted that a may be any module name, and is not limited herein.
It should be noted that, the normalization processing on the codes in the syntax tree may also include other embodiments, which are not limited herein.
S103, converting the normalized syntax tree to obtain the converted normalized syntax tree.
It can be understood that the normalized syntax tree can be converted according to actual situations such as software upgrading requirements, and the converted normalized syntax tree is obtained.
For example, if the software upgrade requirement includes performing parameter conversion on parameters in the normalized syntax tree, the parameters in the normalized syntax number may be subjected to parameter conversion to obtain the normalized syntax tree after the parameter conversion. The parameters may be set according to actual conditions, and the parameter conversion may include parameter addition, deletion, renaming, reordering, reassignment, and the like, which is not limited herein.
It should be noted that, the conversion of the normalized syntax tree may also include other embodiments, which are not limited herein.
And S104, generating the converted source code according to the converted normalized syntax tree.
In embodiments of the present disclosure, the transformed source code may be generated from the transformed normalized syntax tree. It is to be understood that the converted source code refers to code that has undergone code reconstruction.
Optionally, generating the converted source code according to the converted normalized syntax tree may include inputting the converted normalized syntax tree into a preset syntax analyzer, and performing code write-back on the converted normalized syntax tree through the syntax analyzer to generate the converted source code. Wherein, the grammar analyzer can be set according to actual conditions.
And S105, generating an upgrade file according to the converted source code.
In an embodiment of the present disclosure, an upgrade file may be generated according to the converted source code, where the upgrade file may be used for software update.
Optionally, generating an upgrade file according to the converted source code may include storing the converted source code into a preset upgrade file.
In summary, according to the method for generating an upgrade file of the embodiment of the present disclosure, a syntax tree corresponding to a source code may be obtained, codes in the syntax tree are normalized to obtain a normalized syntax tree, the normalized syntax tree is converted to obtain a converted normalized syntax tree, a converted source code is generated according to the converted normalized syntax tree, and an upgrade file is generated according to the converted source code. Therefore, the method can carry out code reconstruction based on the normalized syntax tree, further generates the upgrade file, is beneficial to improving the generation efficiency of the upgrade file, further can improve the development efficiency, and has good applicability and expansibility.
On the basis of any of the above embodiments, the obtaining of the syntax tree corresponding to the source code in step S101 includes obtaining the source code, and generating a corresponding specific syntax tree by using a lib2to3 library in Python according to the source code.
In the embodiment of the disclosure, the specific syntax tree corresponding to the source code can be generated based on the lib2to3 library in the Python, the specific syntax tree can be compatible with Python2 and Python2 codes at the same time, the code compatibility is good, the position information of the comment in the source code can be kept, and the user can conveniently check the comment of the source code.
It can be understood that a code reconstruction may include a large number of modification nodes, and the modification nodes need to be accurately located and modified in the code reconstruction process. In the related art, a large number of matching codes of modified nodes need to be written according to software upgrading requirements for positioning the modified nodes, the codes are complex, errors are easy to occur, manpower is consumed, and later maintenance is difficult.
Optionally, after the corresponding specific syntax tree is generated, a mode compiler of the lib2to3 library in Python may be adopted according to the software upgrading requirement, so as to obtain the position information of the modified node of the specific syntax tree. Therefore, the method can obtain the position information of the modification node of the specific syntax tree according to the mode compiler, so that the modification node is automatically positioned according to the position information of the modification node, and the method has the advantages of high accuracy, low labor cost, high automation degree and the like.
Optionally, a mapping relationship between the software upgrading requirement and the location information of the modified node may be established in the mode compiler in advance, and after the software upgrading requirement is obtained, the location information of the corresponding modified node may be obtained by querying the mapping relationship or the mapping table. It should be noted that the mapping relationship or the mapping table may be set according to actual situations, and is not limited herein.
On the basis of any of the above embodiments, the normalization processing on the codes in the syntax tree in step S102 includes at least one possible implementation manner of:
mode 1, modify the module name in the code in the syntax tree to a preset module name.
In the embodiment of the disclosure, the module name in the code in the syntax tree can be modified into the preset module name, so that the normalization processing of the module name in the code is realized.
Optionally, modifying the module name in the code in the syntax tree to a preset module name may include modifying the sub-module name in the code to a preset module name. For example, if the a module includes an a.fluid as fluid submodule, the name of the a.fluid as fluid submodule in the code may be modified to be the name of the a module, and in one embodiment of the present disclosure, the import a.fluid as fluid may be modified to be import a.
And 2, completing module paths in codes in the syntax tree.
In the embodiment of the disclosure, the module path in the code in the syntax tree can be completed, so that the normalization processing of the module path in the code is realized.
Optionally, completing module paths in the codes in the syntax tree may include completing sub-module paths in the codes. For example, if the a module includes an a.fluid submodule, the fluid.api submodule path in the code may be modified to a.fluid.api.
Mode 3 modifies an alias of an API (Application Programming Interface) in a code in the syntax tree to a preset primary alias.
It is to be understood that an API may correspond to a main alias and one or more aliases. In the embodiment of the disclosure, the alias of the API in the code in the syntax tree can be modified into the preset main alias, so that the normalization processing of the API alias in the code is realized.
For example, if an API corresponds to the main alias of a.fluid.api, the alias of a.fluid.api _ alias1, and the alias of a.fluid.api _ alias2, the alias of a.fluid.api _ alias1 and the alias of a.fluid.api _ alias2 in the code may be modified to the main alias of a.fluid.api.
Optionally, a conversion rule table may be pre-established, where the conversion rule table includes the alias of the API and the preset primary alias, and the alias of the API in the code in the syntax tree may be modified into the preset primary alias according to the conversion rule table. The conversion rule table may be set according to actual conditions, and is not limited herein.
For example, the conversion rule table may be set with reference to table 1.
TABLE 1 conversion rule Table
Figure BDA0002993186530000061
As shown in table 1, line L2 in the conversion rule table defines a preset main alias, line L3 defines an alias list of the API, the alias list of the API including one or more aliases of the API, the preset main alias can be obtained according to line L2, and the alias list of the API can be obtained according to line L3, so that the alias of the API in the code in the syntax tree can be modified to the preset main alias. For example, if the preset main alias obtained from line L2 in table 1 is a.fluid.api, and the alias obtained from line L3 is a.fluid.nn.api _ alias1, then a.fluid.nn.api _ alias1 in the code in the syntax tree may be modified to be a.fluid.api.
Mode 4, converting the position parameters in the codes in the syntax tree into keyword parameters.
In the embodiment of the disclosure, the position parameter in the code in the syntax tree can be converted into the keyword parameter, so that the normalization processing of the position parameter in the code is realized.
Optionally, a conversion rule table may be established in advance, where the conversion rule table includes a position parameter to be converted, and then the position parameter in the code in the syntax tree may be converted into a keyword parameter according to the conversion rule table.
Continuing with table 1 as an example, the L5 line in the conversion rule table defines a parameter list, and the parameter list includes one or more location parameters to be converted, so that the parameter list can be obtained according to the L5 line, and the location parameters in the codes in the syntax tree can be converted into the key parameters. For example, if the location parameters to be converted in the parameter list obtained from line L5 in table 1 are L, h, and d, the parameters L, h, and d may be converted into key parameters.
Therefore, the method can modify the module name in the code in the syntax tree into the preset module name and/or complement the module path in the code in the syntax tree, and/or modify the alias of the API in the code in the syntax tree into the preset main alias, and/or convert the position parameter in the code in the syntax tree into the keyword parameter, thereby realizing the normalization processing of the module name and/or the module path and/or the alias and/or the position parameter of the API in the code.
On the basis of any of the above embodiments, the step S103 of converting the normalized syntax tree includes at least one of the following possible implementations:
mode 1, rule transformation is performed on the normalized syntax tree.
In the embodiment of the present disclosure, the normalized syntax tree may be subjected to rule conversion, that is, the normalized syntax tree is converted according to a preset rule.
Optionally, the rule transformation is performed on the normalized syntax tree, and may include at least one of: carrying out parameter conversion on parameters in the normalized syntax tree; and performing name translation on the primary alias of the API in the normalized syntax tree.
Optionally, the parameter transformation is performed on the parameters in the normalized syntax tree, and may include parameter addition, deletion, renaming, reordering, reassignment, and the like, which are not limited herein.
Optionally, a conversion rule table may be pre-established, where the conversion rule table includes a preset rule for parameter conversion, and the preset rule for parameter conversion may be obtained according to the conversion rule table, and the parameter in the normalized syntax tree is subjected to parameter conversion according to the preset rule for parameter conversion.
Continuing with table 1 as an example, if the line L6 in the conversion rule table defines a preset rule for parameter conversion, the preset rule for parameter conversion can be obtained according to the line L6, and the parameter in the normalized syntax tree is subjected to parameter conversion according to the preset rule for parameter conversion. For example, if the predetermined other parameter transformation rule obtained from line L6 in table 1 includes ("h", "high"), ("d", ""), ("," e "," default _ value "), the parameter h in the normalized syntax tree may be renamed to high according to (" h "," high "), the parameter d in the normalized syntax tree may be deleted according to (" d "," "), the parameter e may be added to the normalized syntax tree according to (", "e", "default _ value"), and the default value of the parameter e is set to default _ value.
Optionally, name converting the primary alias of the API in the normalized syntax tree may include converting the primary alias of the API in the normalized syntax tree to a reset primary alias.
Optionally, a conversion rule table may be pre-established, where the conversion rule table includes the primary alias of the API and the reset primary alias, and the primary alias of the API in the normalized syntax tree may be converted into the reset primary alias according to the conversion rule table.
Continuing with Table 1 as an example, if row L2 in the conversion rules table defines a preset primary alias (i.e., the primary alias of the API), row L4 defines a reset primary alias, then the primary alias of the API may be obtained according to row L2 and the reset primary alias may be obtained according to row L4, thereby converting the primary alias of the API in the normalized syntax tree to the reset primary alias. For example, if the main alias obtained from line L2 in table 1 is a.fluid.api, and the reset main alias obtained from line L4 is a.new _ API, the a.fluid.api in the normalized syntax tree may be converted into a.new _ API.
Mode 2, syntax transformation is performed on the normalized syntax tree.
In the embodiment of the present disclosure, syntax conversion may be performed on the normalized syntax tree, that is, syntax conversion may be performed on the normalized syntax tree according to a preset rule.
Optionally, the syntax transformation of the normalized syntax tree may include at least one of: carrying out sentence pattern correction and/or indentation correction on the basic blocks in the normalized syntax tree; and performing statement adding correction and/or statement deleting correction on the non-basic blocks in the normalized syntax tree.
Optionally, performing sentence pattern modification on the basic block in the normalized syntax tree may include modifying a with sentence of the basic block in the normalized syntax tree into a non-with sentence. For example, the basic blocks in the normalized syntax tree include with a. fluid.dygraph.guard (): and can correct to a.disable _ static ().
Optionally, performing indentation modification on the basic block in the normalized syntax tree may include increasing and/or decreasing the indentation of the sentence of the basic block in the normalized syntax tree by a set distance. The set distance can be set according to actual conditions, and is not limited too much here.
And 3, carrying out custom conversion on the normalized syntax tree.
It can be appreciated that some transformations are difficult to implement unified transformations, and in the embodiments of the present disclosure, the normalized syntax tree may be custom transformed, that is, the normalized syntax tree is transformed according to a custom rule.
Optionally, the custom conversion of the normalized syntax tree may include deleting a first parameter in the normalized syntax tree, adding a second parameter and a third parameter in the normalized syntax tree, and determining a target parameter in the second parameter and the third parameter according to a value of the first parameter. Therefore, the influence of the value of the first parameter on the determination of the target parameter of the second parameter and the third parameter can be considered, and the flexibility is high.
For example, determining the target parameter of the second parameter and the third parameter according to the value of the first parameter may include determining the second parameter as the target parameter if the value of the first parameter is greater than 0, and determining the third parameter as the target parameter if the value of the first parameter is less than or equal to 0.
It should be noted that, the target parameter of the second parameter and the third parameter is determined according to the value of the first parameter, and other embodiments may also be included, which are not limited herein.
Therefore, the method can carry out rule conversion on the normalized syntax tree, and/or carry out syntax conversion on the normalized syntax tree, and/or carry out custom conversion on the normalized syntax tree, thereby realizing the conversion on the normalized syntax tree.
On the basis of any of the above embodiments, the conversion rule table may further include API warning information and/or parameter warning information, where the API warning information is used to remind a user that the preset API is used, and the parameter warning information is used to remind the user that the preset parameter is used.
Continuing with the example of Table 1, line L7 in the conversion rules table defines API warning information and line L8 defines parameter warning information.
Fig. 2 is a flowchart illustrating a method for generating an upgrade file according to a second embodiment of the present disclosure.
As shown in fig. 2, a method for generating an upgrade file according to a second embodiment of the present disclosure includes:
s201, obtaining a syntax tree corresponding to the source code.
S202, modifying the module name in the code in the grammar tree into a preset module name.
S203, complementing module paths in codes in the syntax tree.
S204, the alias of the API in the code in the syntax tree is modified into a preset main alias.
And S205, converting the position parameters in the codes in the syntax tree into keyword parameters.
And S206, obtaining the normalized syntax tree.
In the embodiment of the disclosure, the normalizing process of the codes in the syntax tree may include modifying module names in the codes in the syntax tree into preset module names, completing module paths, modifying alias of API into preset main alias, and converting location parameters into keyword parameters, thereby obtaining the normalized syntax tree.
And S207, carrying out rule conversion on the normalized syntax tree.
And S208, carrying out grammar conversion on the normalized grammar tree.
S209, the normalized syntax tree is subjected to custom conversion.
And S210, obtaining the converted normalized syntax tree.
In the embodiment of the disclosure, the converting the normalized syntax tree may include sequentially performing rule conversion, syntax conversion, and custom conversion on the normalized syntax tree, so as to obtain the converted normalized syntax tree.
And S211, generating the converted source code according to the converted normalized syntax tree.
And S212, generating an upgrading file according to the converted source code.
The relevant contents of steps S201-S212 can be referred to the above embodiments, and are not described herein.
In summary, according to the method for generating an upgrade file according to the embodiment of the present disclosure, the normalization processing on the codes in the syntax tree may include sequentially modifying the module name in the codes in the syntax tree to a preset module name, completing the module path, modifying the alias of the API to a preset main alias, and converting the position parameter into a keyword parameter, thereby obtaining a normalized syntax tree. In addition, the conversion of the normalized syntax tree can include the steps of carrying out rule conversion, syntax conversion and custom conversion on the normalized syntax tree in sequence so as to obtain the converted normalized syntax tree, and therefore, code reconstruction can be carried out according to a preset normalization sequence and a conversion sequence so as to generate an upgrade file, the generation efficiency of the upgrade file is improved, and development time is saved.
Fig. 3 is a block diagram of an upgrade file generation apparatus according to a first embodiment of the present disclosure.
As shown in fig. 3, an upgrade file generation apparatus 300 according to an embodiment of the present disclosure includes: an acquisition module 301, a normalization module 302, a conversion module 303 and a generation module 304.
An obtaining module 301, configured to obtain a syntax tree corresponding to a source code;
a normalization module 302, configured to perform normalization processing on the codes in the syntax tree to obtain a normalized syntax tree;
a conversion module 303, configured to convert the normalized syntax tree to obtain a converted normalized syntax tree; and
a generating module 304, configured to generate a converted source code according to the converted normalized syntax tree.
The generating module 304 is further configured to generate an upgrade file according to the converted source code.
In an embodiment of the present disclosure, the obtaining module 301 is specifically configured to: acquiring the source code; and generating a corresponding specific syntax tree by adopting a lib2to3 library in Python according to the source code.
In an embodiment of the disclosure, the normalization module 302 is specifically configured to at least one of: modifying the module name in the codes in the grammar tree into a preset module name; completing module paths in codes in the syntax tree; modifying the alias of the application programming interface in the code in the syntax tree into a preset main alias; and converting the position parameter in the code in the syntax tree into a keyword parameter.
In an embodiment of the present disclosure, the conversion module 303 is specifically configured to at least one of: carrying out rule conversion on the normalized syntax tree; carrying out grammar conversion on the normalized grammar tree; and carrying out custom conversion on the normalized syntax tree.
In an embodiment of the present disclosure, the conversion module 303 is specifically configured to at least one of: performing parameter conversion on parameters in the normalized syntax tree; and performing name conversion on a primary alias of the application programming interface in the normalized syntax tree.
In an embodiment of the present disclosure, the conversion module 303 is specifically configured to at least one of: carrying out sentence pattern correction and/or indentation correction on the basic blocks in the normalized syntax tree; and performing statement adding correction and/or statement deleting correction on the non-basic blocks in the normalized syntax tree.
In an embodiment of the present disclosure, the conversion module 303 is specifically configured to: deleting a first parameter in the normalized syntax tree; adding a second parameter and a third parameter in the normalized syntax tree; and determining a target parameter of the second parameter and the third parameter according to the value of the first parameter.
In summary, the apparatus for generating an upgrade file according to the embodiment of the present disclosure may obtain a syntax tree corresponding to a source code, perform normalization processing on codes in the syntax tree to obtain a normalized syntax tree, convert the normalized syntax tree to obtain a converted normalized syntax tree, generate a converted source code according to the converted normalized syntax tree, and generate an upgrade file according to the converted source code. Therefore, code reconstruction can be carried out based on the normalized syntax tree, an upgrade file is generated, generation efficiency of the upgrade file is improved, development efficiency can be improved, and the method is good in applicability and expansibility.
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.
FIG. 4 shows a schematic block diagram of an example electronic device 400 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 4, the electronic device 400 includes a computing unit 401 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM)402 or a computer program loaded from a storage unit 408 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 can also be stored. The computing unit 401, ROM 402, and RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
A number of components in the electronic device 400 are connected to the I/O interface 405, including: an input unit 406 such as a keyboard, a mouse, or the like; an output unit 407 such as various types of displays, speakers, and the like; a storage unit 408 such as a magnetic disk, optical disk, or the like; and a communication unit 409 such as a network card, modem, wireless communication transceiver, etc. The communication unit 409 allows the electronic device 400 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
Computing unit 401 may be a variety of general and/or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The computing unit 401 executes the respective methods and processes described above, such as the generation method of the upgrade file described in fig. 1 to 2. For example, in some embodiments, the generation method of the upgrade file may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 408. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 400 via the ROM 402 and/or the communication unit 409. When the computer program is loaded into RAM 403 and executed by computing unit 401, one or more steps of the method of generating an upgrade file described above may be performed. Alternatively, in other embodiments, the computing unit 401 may be configured to perform the generation method of the upgrade file by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The Server can be a cloud Server, also called a cloud computing Server or a cloud host, and is a host product in a cloud computing service system, so as to solve the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service ("Virtual Private Server", or simply "VPS"). The server may also be a server of a distributed system, or a server incorporating a blockchain.
According to an embodiment of the present disclosure, the present disclosure further provides a computer program product including a computer program, where the computer program is executed by a processor to implement the method for generating an upgrade file according to the above-mentioned embodiment of the present disclosure.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel, sequentially, or in different orders, as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved, and the present disclosure is not limited herein.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.

Claims (17)

1. A method for generating an upgrade file comprises the following steps:
obtaining a syntax tree corresponding to a source code;
carrying out normalization processing on codes in the syntax tree to obtain a normalized syntax tree;
converting the normalized syntax tree to obtain a converted normalized syntax tree;
generating a converted source code according to the converted normalized syntax tree; and
and generating an upgrade file according to the converted source code.
2. The method for generating the upgrade file according to claim 1, wherein the obtaining a syntax tree corresponding to the source code includes:
acquiring the source code; and
and generating a corresponding specific syntax tree by adopting a lib2to3 library in Python according to the source code.
3. The method for generating an upgrade file according to claim 1, wherein the normalizing the codes in the syntax tree includes at least one of:
modifying the module name in the codes in the grammar tree into a preset module name;
completing module paths in codes in the syntax tree;
modifying the alias of the application programming interface in the code in the syntax tree into a preset main alias; and
converting a position parameter in a code in the syntax tree into a keyword parameter.
4. The method for generating an upgrade file according to claim 1, wherein the converting the normalized syntax tree includes at least one of:
carrying out rule conversion on the normalized syntax tree;
carrying out grammar conversion on the normalized grammar tree; and
and carrying out custom conversion on the normalized syntax tree.
5. The method for generating an upgrade file according to claim 4, wherein the performing a rule transformation on the normalized syntax tree includes at least one of:
performing parameter conversion on parameters in the normalized syntax tree; and
name converting the primary alias of the application programming interface in the normalized syntax tree.
6. The method for generating an upgrade file according to claim 4, wherein the syntax transformation of the normalized syntax tree includes at least one of:
carrying out sentence pattern correction and/or indentation correction on the basic blocks in the normalized syntax tree; and
and performing statement adding correction and/or statement deleting correction on the non-basic blocks in the normalized syntax tree.
7. The method for generating an upgrade file according to claim 4, wherein the custom converting the normalized syntax tree includes:
deleting a first parameter in the normalized syntax tree;
adding a second parameter and a third parameter in the normalized syntax tree; and
and determining a target parameter of the second parameter and the third parameter according to the value of the first parameter.
8. An upgrade file generation apparatus comprising:
the obtaining module is used for obtaining a syntax tree corresponding to the source code;
the normalization module is used for carrying out normalization processing on codes in the syntax tree to obtain a normalized syntax tree;
the conversion module is used for converting the normalized syntax tree to obtain a converted normalized syntax tree;
a generating module for generating a converted source code according to the converted normalized syntax tree; and
the generating module is further configured to generate an upgrade file according to the converted source code.
9. The apparatus for generating an upgrade file according to claim 8, wherein the obtaining module is specifically configured to:
acquiring the source code; and
and generating a corresponding specific syntax tree by adopting a lib2to3 library in Python according to the source code.
10. The apparatus for generating an upgrade file according to claim 8, wherein the normalization module is specifically configured to at least one of:
modifying the module name in the codes in the grammar tree into a preset module name;
completing module paths in codes in the syntax tree;
modifying the alias of the application programming interface in the code in the syntax tree into a preset main alias; and
converting a position parameter in a code in the syntax tree into a keyword parameter.
11. The apparatus for generating an upgrade file according to claim 8, wherein the conversion module is specifically configured to at least one of:
carrying out rule conversion on the normalized syntax tree;
carrying out grammar conversion on the normalized grammar tree; and
and carrying out custom conversion on the normalized syntax tree.
12. The apparatus for generating an upgrade file according to claim 11, wherein the conversion module is specifically configured to at least one of:
performing parameter conversion on parameters in the normalized syntax tree; and
name converting the primary alias of the application programming interface in the normalized syntax tree.
13. The apparatus for generating an upgrade file according to claim 11, wherein the conversion module is specifically configured to at least one of:
carrying out sentence pattern correction and/or indentation correction on the basic blocks in the normalized syntax tree; and
and performing statement adding correction and/or statement deleting correction on the non-basic blocks in the normalized syntax tree.
14. The apparatus for generating an upgrade file according to claim 11, wherein the conversion module is specifically configured to:
deleting a first parameter in the normalized syntax tree;
adding a second parameter and a third parameter in the normalized syntax tree; and
and determining a target parameter of the second parameter and the third parameter according to the value of the first parameter.
15. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of generating an upgrade file according to any one of claims 1 to 7.
16. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of generating an upgrade file according to any one of claims 1 to 7.
17. A computer program product comprising a computer program which, when executed by a processor, implements a method of generating an upgrade file according to any one of claims 1 to 7.
CN202110321883.6A 2021-03-25 2021-03-25 Method and device for generating upgrade file and electronic equipment Active CN113010182B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202110321883.6A CN113010182B (en) 2021-03-25 2021-03-25 Method and device for generating upgrade file and electronic equipment
CN202210204861.6A CN114816467B (en) 2021-03-25 2021-03-25 Upgrade file generation method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110321883.6A CN113010182B (en) 2021-03-25 2021-03-25 Method and device for generating upgrade file and electronic equipment

Related Child Applications (1)

Application Number Title Priority Date Filing Date
CN202210204861.6A Division CN114816467B (en) 2021-03-25 2021-03-25 Upgrade file generation method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN113010182A true CN113010182A (en) 2021-06-22
CN113010182B CN113010182B (en) 2022-05-03

Family

ID=76407327

Family Applications (2)

Application Number Title Priority Date Filing Date
CN202110321883.6A Active CN113010182B (en) 2021-03-25 2021-03-25 Method and device for generating upgrade file and electronic equipment
CN202210204861.6A Active CN114816467B (en) 2021-03-25 2021-03-25 Upgrade file generation method and device and electronic equipment

Family Applications After (1)

Application Number Title Priority Date Filing Date
CN202210204861.6A Active CN114816467B (en) 2021-03-25 2021-03-25 Upgrade file generation method and device and electronic equipment

Country Status (1)

Country Link
CN (2) CN113010182B (en)

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102222004A (en) * 2011-07-01 2011-10-19 福建富士通信息软件有限公司 Method for transforming switch special language into C language
US9477461B1 (en) * 2014-03-12 2016-10-25 Cloud Linux Zug GmbH Systems and methods for generating and applying operating system live updates
CN106650437A (en) * 2016-12-29 2017-05-10 广州华多网络科技有限公司 Webshell detection method and device
CN109582352A (en) * 2018-10-19 2019-04-05 北京硅心科技有限公司 A kind of code completion method and system based on double AST sequences
CN110543297A (en) * 2018-05-28 2019-12-06 北京京东尚科信息技术有限公司 method and apparatus for generating source code
CN110612526A (en) * 2017-05-29 2019-12-24 富士通株式会社 System C model generation method and system C model generation program
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN111580825A (en) * 2020-04-28 2020-08-25 中国科学院软件研究所 Compiling method and system for mechanical arm program development programming language
CN111625224A (en) * 2020-05-28 2020-09-04 北京百度网讯科技有限公司 Code generation method, device, equipment and storage medium
CN111767076A (en) * 2020-06-23 2020-10-13 中国工商银行股份有限公司 Code reconstruction method and device
CN112328257A (en) * 2020-11-24 2021-02-05 中国工商银行股份有限公司 Code conversion method and device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101580258B1 (en) * 2008-06-10 2015-12-28 오아시스 툴링 인코포레이티드 Methods and devices for independent evaluation of cell integrity, changes and origin in chip design for production workflow
US9959324B2 (en) * 2015-03-26 2018-05-01 International Business Machines Corporation Bootstrapping the data lake and glossaries with ‘dataset joins’ metadata from existing application patterns
CN111638908A (en) * 2020-05-29 2020-09-08 深圳壹账通智能科技有限公司 Interface document generation method and device, electronic equipment and medium
CN111752571A (en) * 2020-06-29 2020-10-09 广州华多网络科技有限公司 Program upgrading method, device, equipment and storage medium

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102222004A (en) * 2011-07-01 2011-10-19 福建富士通信息软件有限公司 Method for transforming switch special language into C language
US9477461B1 (en) * 2014-03-12 2016-10-25 Cloud Linux Zug GmbH Systems and methods for generating and applying operating system live updates
CN106650437A (en) * 2016-12-29 2017-05-10 广州华多网络科技有限公司 Webshell detection method and device
CN110612526A (en) * 2017-05-29 2019-12-24 富士通株式会社 System C model generation method and system C model generation program
CN110543297A (en) * 2018-05-28 2019-12-06 北京京东尚科信息技术有限公司 method and apparatus for generating source code
CN109582352A (en) * 2018-10-19 2019-04-05 北京硅心科技有限公司 A kind of code completion method and system based on double AST sequences
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN111580825A (en) * 2020-04-28 2020-08-25 中国科学院软件研究所 Compiling method and system for mechanical arm program development programming language
CN111625224A (en) * 2020-05-28 2020-09-04 北京百度网讯科技有限公司 Code generation method, device, equipment and storage medium
CN111767076A (en) * 2020-06-23 2020-10-13 中国工商银行股份有限公司 Code reconstruction method and device
CN112328257A (en) * 2020-11-24 2021-02-05 中国工商银行股份有限公司 Code conversion method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
匡小萌: "transform code to graph with clang", 《HTTPS://BLOG.CSDN.NET/KHY123KHY/ARTICLE/DETAILS/107353426》 *

Also Published As

Publication number Publication date
CN114816467B (en) 2023-04-28
CN114816467A (en) 2022-07-29
CN113010182B (en) 2022-05-03

Similar Documents

Publication Publication Date Title
CN113342345A (en) Operator fusion method and device of deep learning framework
CN112597754A (en) Text error correction method and device, electronic equipment and readable storage medium
CN111104479A (en) Data labeling method and device
CN112966824A (en) Deployment method and device of inference library and electronic equipment
CN114691148A (en) Model reasoning acceleration method and device, electronic equipment and storage medium
CN110175128B (en) Similar code case acquisition method, device, equipment and storage medium
US20230141932A1 (en) Method and apparatus for question answering based on table, and electronic device
CN113010182B (en) Method and device for generating upgrade file and electronic equipment
CN113408304B (en) Text translation method and device, electronic equipment and storage medium
CN113127357B (en) Unit test method, apparatus, device, storage medium, and program product
CN114218166A (en) Data processing method and device, electronic equipment and readable storage medium
CN113377924A (en) Data processing method, device, equipment and storage medium
CN113220367A (en) Applet running method and device, electronic equipment and storage medium
CN112835007B (en) Point cloud data conversion method and device, electronic equipment and storage medium
CN114661751B (en) Data production method, device, system, equipment and medium based on SQL (structured query language) knowledge base
CN112817990B (en) Data processing method, device, electronic equipment and readable storage medium
CN113642295B (en) Page typesetting method, device and computer program product
CN114880242B (en) Test case extraction method, device, equipment and medium
CN116257611B (en) Question-answering model training method, question-answering processing device and storage medium
CN116302218B (en) Function information adding method, device, equipment and storage medium
US20220374603A1 (en) Method of determining location information, electronic device, and storage medium
CN117931195A (en) Data dictionary processing method and device, electronic equipment and storage medium
CN115033238A (en) Code display method and device, electronic equipment and storage medium
CN117251164A (en) Model code conversion method, device, equipment and storage medium
CN117270862A (en) Software pluggable method, device, equipment and medium based on dynamic compiling

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