CN107038058B - Code processing method and device - Google Patents

Code processing method and device Download PDF

Info

Publication number
CN107038058B
CN107038058B CN201710068399.0A CN201710068399A CN107038058B CN 107038058 B CN107038058 B CN 107038058B CN 201710068399 A CN201710068399 A CN 201710068399A CN 107038058 B CN107038058 B CN 107038058B
Authority
CN
China
Prior art keywords
code
function
branch
processed
branch condition
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710068399.0A
Other languages
Chinese (zh)
Other versions
CN107038058A (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.)
Advanced New Technologies Co Ltd
Advantageous New Technologies Co Ltd
Original Assignee
Advanced New Technologies 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 Advanced New Technologies Co Ltd filed Critical Advanced New Technologies Co Ltd
Priority to CN201710068399.0A priority Critical patent/CN107038058B/en
Publication of CN107038058A publication Critical patent/CN107038058A/en
Application granted granted Critical
Publication of CN107038058B publication Critical patent/CN107038058B/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/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • G06F8/4434Reducing the memory space required by the program code
    • G06F8/4435Detection or removal of dead or redundant code
    • 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
    • G06F8/4434Reducing the memory space required by the program code

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 embodiment of the application discloses a code processing method and device. The method comprises the following steps: obtaining a code to be processed; determining each function call aiming at a specified function in the code to be processed and each branch condition in the specified function; and according to the branch condition and the parameters used by the function calls, cutting the branch codes corresponding to the branch condition in the specified function. By utilizing the embodiment of the application, part of redundant codes in the packed file can be eliminated, so that the volume of the packed file can be reduced.

Description

Code processing method and device
Technical Field
The present application relates to the field of computer software technologies, and in particular, to a code processing method and apparatus.
Background
With the rapid development of computer technology and internet technology, a great deal of application programs emerge, and convenience is brought to the life of people.
Most of the application programs or some functional modules in the application programs need to be packaged and provided for users, and then the users can use the packaged files after downloading and installing the packaged files. The packaged file generally includes function-related code and non-code files, such as JavaScript code used by front-end control, a program global configuration file, a binary resource file, and the like.
However, as the application program is more and more powerful, the volume of the packed file is more and more large, which may bring adverse effects to the user to obtain the packed file, and may also reduce the execution efficiency of the codes in the packed file.
Disclosure of Invention
The embodiment of the application provides a code processing method and a device, which are used for solving the following technical problems in the prior art: along with the more and more powerful functions of the application programs, the volume of the packed file is also larger and larger, adverse effects can be brought to a user for obtaining the packed file, and the execution efficiency of codes in the packed file can be reduced.
In order to solve the above technical problem, the embodiment of the present application is implemented as follows:
the code processing method provided by the embodiment of the application comprises the following steps:
obtaining a code to be processed;
determining each function call aiming at a specified function in the code to be processed and each branch condition in the specified function;
and according to the branch condition and the parameters used by the function calls, cutting the branch codes corresponding to the branch condition in the specified function.
An embodiment of the present application provides a code processing apparatus, including:
the obtaining module is used for obtaining a code to be processed;
the determining module is used for determining each function call aiming at the specified function in the code to be processed and each branch condition in the specified function;
and the processing module is used for cutting the branch codes corresponding to the branch conditions in the specified functions according to the branch conditions and the parameters used by the function calls.
The embodiment of the application adopts at least one technical scheme which can achieve the following beneficial effects: the method can eliminate partial redundant codes in the packed file, thereby reducing the volume of the packed file, further reducing the adverse effect of the prior art on obtaining the packed file for users, and being beneficial to improving the execution efficiency of the codes in the packed file, therefore, the problems in the prior art can be partially or completely solved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only some embodiments described in the present application, and for those skilled in the art, other drawings can be obtained according to the drawings without any creative effort.
Fig. 1 is a schematic flowchart of a code processing method according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a code processing apparatus corresponding to fig. 1 according to an embodiment of the present disclosure.
Detailed Description
The embodiment of the application provides a code processing method and device.
In order to make those skilled in the art better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. 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 application.
Fig. 1 is a schematic flowchart of a code processing method provided in an embodiment of the present application, where the flowchart may be implemented by a program, and apparatuses that can carry the program include, but are not limited to, the following: personal computers, large and medium-sized computers, computer clusters, mobile phones, tablet computers, intelligent wearable equipment, vehicle machines and the like.
The process in fig. 1 may include the following steps:
s101: and obtaining a code to be processed.
In the embodiments of the present application, the code may be based on any one of programming languages. For example, JavaScript, JAVA, C + +, PHP, Python, and other programming languages. For convenience of description, the following embodiments are mainly described by taking JavaScript code as an example.
In the embodiment of the present application, the to-be-processed code is generally a code waiting to be packaged or modularized for a specified application scenario.
The code to be processed comprises one or more function bodies of the function and one or more function calls for the function. Under different application scenarios, the function body may not be changed, and the parameters used by the corresponding function calls may be different, for example, the parameter types are different, the parameter values are different, and the like.
S102: and determining each function call aiming at the specified function in the code to be processed and each branch condition in the specified function.
In the embodiment of the present application, the specified function may be any function whose function body is included in the code to be processed. In practical applications, for each function of which the function body is included in the code to be processed, each function of at least some of the functions may be respectively used as a designated function, and the flow in fig. 1 may be executed on each designated function.
In this embodiment of the present application, each function call specifically includes all function calls for a specified function in the code to be processed. The function calls may use different parameters, respectively.
For example, assume that the specified function is "clone (item)", some function call for the specified function may be "clone ()", another function call for the specified function may be "clone ('foo')", and so on. It can be seen that the parameter used by clone () is null (belonging to non-item), and the parameter used by clone ('foo') is the character string foo.
In the embodiment of the application, one or more branch conditions are contained in the specified function. The branch conditions specifically include all branch conditions in the specified function. Generally, branch conditions are contained in conditional statements such as "if", "else", and the like.
For example, assume that the function clone (item) is specified as follows:
Figure BDA0001221838920000041
it can be seen that the specified function of the above example contains two branch conditions in common. Branch 1 has a Branch condition of "! item ", the branching condition of the branch 2 is" typeof item ═ string ".
It should be noted that, in practical applications, the function body of the specified function may not be included in the code to be processed. However, in this case, the subsequent clipping process for the specified function may have an effect: the result of a function call to a specified function outside the code to be processed.
S103: and according to the branch condition and the parameters used by the function calls, cutting the branch codes corresponding to the branch condition in the specified function.
In the embodiment of the present application, as described above, the to-be-processed code is generally a code waiting to be packaged or modularized for a specified application scenario, and in the specified application scenario, when a function in the to-be-processed code is called, all branches in the function are not necessarily required to be used. Then, it can be considered that: in the specified application scenario, the branch codes which are not used are redundant, and can be cut out from the codes to be processed, and then the cut codes to be processed are packaged to reduce the size of the codes to be processed.
In the embodiment of the application, according to the branch condition and the parameters used by each function call, which branches are not needed to be used in the scene corresponding to the code to be processed can be determined, and then the code of the branch which is not used can be cut.
In addition, the present application does not limit the execution sequence of "determining each function call for the specified function in the code to be processed" and "determining each branch condition in the specified function" in step S102, and may execute simultaneously or execute one after another.
By the method of fig. 1, part of redundant codes (included in the to-be-processed codes) in the packed file can be eliminated, so that the volume of the packed file can be reduced, adverse effects on a user to obtain the packed file in the prior art can be reduced, and the execution efficiency of codes in the packed file can be improved, thereby solving the problems in the prior art partially or completely.
Based on the method of fig. 1, the examples of the present application also provide some specific embodiments of the method, and further embodiments, which are described below.
In the embodiment of the application, after the code to be processed is obtained, the subsequent steps can be realized by traversing the code to be processed, the code to be processed can also be converted into a data form which is easier to analyze, such as a syntax tree, and then the subsequent steps are realized according to the data obtained after the conversion. The syntax tree is used as an example below.
For step S102, the determining each function call for the specified function in the code to be processed specifically may include: generating a syntax tree of the code to be processed; and determining each function call aiming at the specified function in the code to be processed, parameters used by each function call and each branch condition in the specified function according to the syntax tree of the code to be processed.
The present application is not limited to how to generate the syntax tree, and can be implemented by using the existing technology. In the syntax tree, elements in codes such as functions and function calls can be represented as tree nodes, and the analysis and the operation are easy.
As mentioned above, the flow in fig. 1 may be executed for a plurality of functions in the code to be processed, so that all function calls and parameters used by the function calls in the code to be processed may be uniformly determined (and the data may be stored in a data structure such as a list for use).
Specifically, the determining, according to the syntax tree of the code to be processed, each function call for a specified function in the code to be processed and a parameter used by each function call may include: determining all function calls in the code to be processed according to the syntax tree of the code to be processed, and determining parameters used by all the function calls respectively; classifying all the determined function calls, wherein the function calls with the same function are classified into the same class; a type of function call for a specified function is determined among the classes, and parameters used by the type of function call are determined.
Further, the determining the branch conditions in the specified function may specifically include: determining a syntax tree of the specified function according to the syntax tree of the code to be processed; and determining each branch condition in the specified function according to the syntax tree of the specified function.
In this embodiment of the present application, for step S103, the performing, according to the branch condition and the parameter used by each function call, a clipping process on the branch code corresponding to the branch condition in the specified function specifically includes:
executing, for each of the branch conditions:
determining whether the parameters used by the function call can meet the branch conditions according to the parameters used by each function call in the function calls; if the parameters used by each function call cannot meet the branch condition, deleting the branch code corresponding to the branch condition.
For ease of understanding, the above example is used for illustration.
Assume that for the above specified function clone (item) in the pending code, there are two function calls for clone (item): clone (), clone ('foo'). It can be seen that clone () can conform to the branch condition "!of branch 1 of clone (item)! item ", a clone ('foo') may conform to the branching condition" typeof item ═ string '"of branch 2 of the clone (item), and therefore, neither branch's branch code is redundant and does not need to be clipped.
However, assuming that the clone (item) only calls clone () for the function of clone (item), the parameter used by clone () does not satisfy the branch condition "typeof item" of branch 2, and therefore, the branch code of branch 2 (i.e., the branch code corresponding to the branch condition of branch 2) is redundant and can be clipped. The function of the clipped clone (item) is as follows:
Figure BDA0001221838920000071
further, after the execution of each of the branch conditions, the following may be further performed: and if the executed specified function only contains one branch condition, deleting the code representing the branch condition. In this manner, code redundancy can be further eliminated.
The reason this can be done is: if the executed specified function only contains one branch condition, for any function call in the code to be processed aiming at the specified function, the parameter used by the function call must meet the branch condition, so that the code required to be executed when the branch condition is met is only required to be reserved, and the branch condition is not required to be reserved.
For ease of understanding, the above example is used for illustration.
The function body of the clipped clone (item) in the above example is further clipped, and the further clipping is as follows:
“function clone(item){
return item;
}”
since the function call of the to-be-processed code to the clone (item) only has the clone (), when the function call is executed, the "return item" can be directly executed without performing branch condition judgment.
Based on similar thinking, after each branch condition in the branch conditions is executed, the following steps can be executed: and for other branch conditions except the last branch condition in the executed specified function, if the branch codes corresponding to the other branch conditions all jump out of the specified function, deleting the code representing the last branch condition. In this manner, code redundancy may be further eliminated.
The reason this can be done is: for any function call in the to-be-processed code for the specified function, if the parameter used by the function call does not satisfy each branch condition before the last branch condition (if the parameter used by the function call satisfies the branch condition, the specified function is skipped, and subsequent codes in the specified function are not executed again), the last branch condition is necessarily satisfied.
The above description is provided for a code processing method provided in the embodiment of the present application, and based on the same inventive idea, the embodiment of the present application further provides a corresponding apparatus, as shown in fig. 2.
Fig. 2 is a schematic structural diagram of a code processing apparatus corresponding to fig. 1 according to an embodiment of the present application, where the apparatus may be located on an execution main body of the flow in fig. 1, and includes:
an obtaining module 201 for obtaining a code to be processed;
a determining module 202, configured to determine function calls for a specified function in the code to be processed, and branch conditions in the specified function;
and the processing module 203 performs clipping processing on the branch code corresponding to the branch condition in the specified function according to the branch condition and the parameter used by each function call.
Optionally, the determining module 202 determines each function call for the specified function in the code to be processed, and each branch condition in the specified function, specifically including:
the determining module 202 generates a syntax tree of the code to be processed, and determines each function call and parameters used by the function call for a specified function in the code to be processed, and each branch condition in the specified function according to the syntax tree of the code to be processed.
Optionally, the determining module 202 determines, according to the syntax tree of the code to be processed, each function call for the specified function in the code to be processed and parameters used by the function call, specifically including:
the determining module 202 determines all function calls in the code to be processed according to the syntax tree of the code to be processed, determines parameters used by the function calls respectively, classifies the determined function calls, classifies the function calls having the same function into the same class, determines a class of function calls for a specified function in each class, and determines parameters used by the class of function calls.
Optionally, the determining module 202 determines each branch condition in the specified function, which specifically includes:
the determining module 202 determines the syntax tree of the specified function according to the syntax tree of the code to be processed, and determines each branch condition in the specified function according to the syntax tree of the specified function.
Optionally, the processing module 203 performs, according to the branch condition and the parameter used by each function call, a clipping process on a branch code corresponding to the branch condition in the specified function, which specifically includes:
the processing module 203 performs, for each of the branch conditions:
determining whether the parameters used by the function call can meet the branch conditions according to the parameters used by each function call in the function calls;
if the parameters used by each function call cannot meet the branch condition, deleting the branch code corresponding to the branch condition.
Optionally, after the processing module 203 executes each branch condition in the branch conditions, if the executed specified function only includes one branch condition, the code indicating the branch condition is deleted.
Optionally, after the processing module 203 executes each of the branch conditions, for other branch conditions except for the last branch condition in the executed specified function, if all branch codes corresponding to the other branch conditions jump out of the specified function, the code representing the last branch condition is deleted.
Optionally, the code is JavaScript code.
The device and the method provided by the embodiment of the application are in one-to-one correspondence, so the device also has the beneficial technical effects similar to the corresponding method, and the beneficial technical effects of the method are explained in detail above, so the beneficial technical effects of the corresponding device are not described again.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Hardware Description Language), traffic, pl (core universal Programming Language), HDCal (jhdware Description Language), lang, Lola, HDL, laspam, hardward Description Language (vhr Description Language), vhal (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that 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.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (12)

1. A code processing method, comprising:
obtaining a code to be processed; the code to be processed comprises a code waiting for packaging or modularization aiming at a specified application scene;
determining each function call aiming at a specified function in the code to be processed and each branch condition in the specified function; the branch condition is contained in a conditional statement;
according to the branch condition and the parameters used by the function calls, performing cutting processing on the branch codes corresponding to the branch condition in the specified function, specifically comprising: executing, for each of the branch conditions: determining whether the parameters used by the function call can meet the branch conditions according to the parameters used by each function call in the function calls; if the parameters used by each function call cannot meet the branch condition, deleting the branch code corresponding to the branch condition;
after the executing of each of the branch conditions, the method further includes:
if the executed specified function only contains one branch condition, the code which needs to be executed when the branch condition is met is reserved, and the code which represents the branch condition is deleted.
2. The method according to claim 1, wherein determining each function call in the code to be processed for the specified function and each branch condition in the specified function specifically includes:
generating a syntax tree of the code to be processed;
and determining each function call aiming at the specified function in the code to be processed, parameters used by each function call and each branch condition in the specified function according to the syntax tree of the code to be processed.
3. The method according to claim 2, wherein the determining, according to the syntax tree of the code to be processed, each function call for the specified function and the parameters used by the function calls in the code to be processed specifically includes:
determining all function calls in the code to be processed according to the syntax tree of the code to be processed, and determining parameters used by all the function calls respectively;
classifying all the determined function calls, wherein the function calls with the same function are classified into the same class;
a type of function call for a specified function is determined among the classes, and parameters used by the type of function call are determined.
4. The method of claim 2, wherein the determining the branch conditions in the specified function specifically comprises:
determining a syntax tree of the specified function according to the syntax tree of the code to be processed;
and determining each branch condition in the specified function according to the syntax tree of the specified function.
5. The method of claim 1, wherein after the separately executing for each of the branch conditions, the method further comprises:
and for other branch conditions except the last branch condition in the executed specified function, if the branch codes corresponding to the other branch conditions all jump out of the specified function, deleting the code representing the last branch condition.
6. The method of any of claims 1-5, wherein the code is JavaScript code.
7. A code processing apparatus, comprising:
the obtaining module is used for obtaining a code to be processed; the code to be processed comprises a code waiting for packaging or modularization aiming at a specified application scene;
the determining module is used for determining each function call aiming at the specified function in the code to be processed and each branch condition in the specified function; the branch condition is contained in a conditional statement;
a processing module, configured to perform clipping processing on a branch code corresponding to the branch condition in the specified function according to the branch condition and parameters used by the function calls, where the clipping processing specifically includes: the processing module respectively executes for each of the branch conditions: determining whether the parameters used by the function call can meet the branch conditions according to the parameters used by each function call in the function calls; if the parameters used by each function call cannot meet the branch condition, deleting the branch code corresponding to the branch condition;
after the processing module executes each branch condition in the branch conditions, if the executed specified function only contains one branch condition, the processing module reserves a code to be executed when the branch condition is met, and deletes the code representing the branch condition.
8. The apparatus according to claim 7, wherein the determining module determines each function call for the specified function in the code to be processed and each branch condition in the specified function, specifically including:
the determining module generates a syntax tree of the code to be processed, and determines each function call aiming at the specified function in the code to be processed, parameters used by each function call and each branch condition in the specified function according to the syntax tree of the code to be processed.
9. The apparatus according to claim 8, wherein the determining module determines, according to the syntax tree of the to-be-processed code, each function call for a specified function in the to-be-processed code and a parameter used by each function call, specifically including:
the determining module determines all function calls in the code to be processed according to the syntax tree of the code to be processed, determines parameters used by all the function calls respectively, classifies all the determined function calls, classifies the function calls with the same function in the same class, determines one class of function calls for a specified function in each class, and determines the parameters used by the class of function calls.
10. The apparatus of claim 8, wherein the determining module determines each branch condition in the specified function, including:
the determining module determines the syntax tree of the specified function according to the syntax tree of the code to be processed, and determines each branch condition in the specified function according to the syntax tree of the specified function.
11. The apparatus of claim 7, wherein after each of the branch conditions is executed, the processing module deletes, for other branch conditions other than a last branch condition in the executed specified function, code indicating the last branch condition if all branch codes corresponding to the other branch conditions jump out of the specified function.
12. The apparatus of any of claims 7 to 11, wherein the code is JavaScript code.
CN201710068399.0A 2017-02-08 2017-02-08 Code processing method and device Active CN107038058B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710068399.0A CN107038058B (en) 2017-02-08 2017-02-08 Code processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710068399.0A CN107038058B (en) 2017-02-08 2017-02-08 Code processing method and device

Publications (2)

Publication Number Publication Date
CN107038058A CN107038058A (en) 2017-08-11
CN107038058B true CN107038058B (en) 2021-12-24

Family

ID=59533258

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710068399.0A Active CN107038058B (en) 2017-02-08 2017-02-08 Code processing method and device

Country Status (1)

Country Link
CN (1) CN107038058B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107665124B (en) * 2017-09-14 2021-04-20 阿里巴巴(中国)有限公司 Modular JavaScript file processing method, device and server
CN111095197B (en) * 2017-10-27 2021-10-15 华为技术有限公司 Code processing method and device
CN110941431A (en) * 2018-09-21 2020-03-31 北京奇虎科技有限公司 Method and device for optimizing obfuscated codes, computing equipment and storage medium
US10956136B2 (en) * 2018-10-16 2021-03-23 Ebay, Inc. User interface resource file optimization
CN111552638B (en) * 2020-04-23 2023-08-18 北京奇艺世纪科技有限公司 Code detection method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102360305A (en) * 2011-10-09 2012-02-22 中国航天科技集团公司第五研究院第五一三研究所 VxWorks operating system scaling and customizing method for aerospace computer
US8782625B2 (en) * 2010-06-17 2014-07-15 Microsoft Corporation Memory safety of floating-point computations
CN104572424A (en) * 2013-10-09 2015-04-29 阿里巴巴集团控股有限公司 Test method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104375875B (en) * 2013-08-15 2017-08-25 国际商业机器公司 Method and compiler for the compiling optimization of application program

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8782625B2 (en) * 2010-06-17 2014-07-15 Microsoft Corporation Memory safety of floating-point computations
CN102360305A (en) * 2011-10-09 2012-02-22 中国航天科技集团公司第五研究院第五一三研究所 VxWorks operating system scaling and customizing method for aerospace computer
CN104572424A (en) * 2013-10-09 2015-04-29 阿里巴巴集团控股有限公司 Test method and device

Also Published As

Publication number Publication date
CN107038058A (en) 2017-08-11

Similar Documents

Publication Publication Date Title
CN107038058B (en) Code processing method and device
CN107577694B (en) Data processing method and device based on block chain
CN107450972B (en) Scheduling method and device and electronic equipment
CN107402824B (en) Data processing method and device
CN107562467B (en) Page rendering method, device and equipment
CN109104327B (en) Service log generation method, device and equipment
CN107368292B (en) Resource compiling method and device
CN107092475B (en) Calling method and device of interactive control
CN106293669B (en) Webpage component generation method and device
CN112597013A (en) Online development and debugging method and device
CN114547024A (en) SQL statement risk detection method, device, equipment and medium
CN107391529B (en) Method and device for realizing Object Relation Mapping (ORM)
CN115981870A (en) Data processing method and device, storage medium and electronic equipment
CN114168114A (en) Operator registration method, device and equipment
US9454382B2 (en) Verification of UML state machines
CN107391099B (en) Resource preprocessing method and device
CN114115016A (en) Data processing method, device, equipment and medium
US20210042319A1 (en) Data processing method, apparatus, and device
CN111459573B (en) Method and device for starting intelligent contract execution environment
CN116842715A (en) Simulation data structuring processing system
CN108681554B (en) Matching method, device and equipment using regular expression
CN107239270B (en) Code processing method and device
CN115934161A (en) Code change influence analysis method, device and equipment
CN111753990A (en) Quantum computer environment simulation method, equipment and medium
CN111984247A (en) Service processing method and device and electronic equipment

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
TA01 Transfer of patent application right

Effective date of registration: 20200924

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant after: Innovative advanced technology Co.,Ltd.

Address before: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant before: Advanced innovation technology Co.,Ltd.

Effective date of registration: 20200924

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant after: Advanced innovation technology Co.,Ltd.

Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands

Applicant before: Alibaba Group Holding Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant