Embodiment
The embodiment of the present application provides a kind of code process method and device.
In order that those skilled in the art more fully understand the technical scheme in the application, below in conjunction with this
Apply for the accompanying drawing in embodiment, the technical scheme in the embodiment of the present application be clearly and completely described,
Obviously, described embodiment is only some embodiments of the present application, rather than whole embodiments.Base
Embodiment in the application, those of ordinary skill in the art are obtained under the premise of creative work is not made
The every other embodiment obtained, should all belong to the scope of the application protection.
Code process method in the embodiment of the present application solves existing skill by handling object code
Be likely to occur in art causes the problem of object code volume additionally increases due to importing redundant file, ties below
Close accompanying drawing and this method is described in detail.
The targeted object code of code process method in the embodiment of the present application can be the system code of software,
Can also be scripted code that support software is used etc., the programming voice that object code is based on is alternatively
C++, Java, JavaScript etc., this is technology well known to those of ordinary skill in the art, herein not
Repeat.
Fig. 1 is the process of code process method in the application first embodiment, and the executive agent of this method can be with
It is that program staff is used to write the computer equipment of object code or the clothes for storing object code
Business device etc.;The code process method may include steps of.
S20, file import statement is determined in object code, the file import statement is treated for importing
Import file.
Increasingly mature with code development technology, numerous programming languages, which have, introduces other existing codes texts
The file of part imports syntax rule, and file import statement, which is used to refer to, meets file importing language in each programming language
The code line of method rule.By file import statement can realize by least one realize preset function wait lead
Enter file to be directed into object code so that object code there can be the function of these files to be imported, carry
Height improves programming efficiency.
File to be imported is in the file for the state for being identified " allowing to be imported into ", file import statement
The mark of file to be imported is carried, then can be according to text wherein to be imported when file import statement is performed
The mark of part determines the position of file to be imported, and then the file to be imported is directed into object code.
From file dimension, file to be imported can have identified as the single of " allowing to be imported into " state
For realize certain preset function code file or by it is multiple it is being identified, realize it is not of the same race
The business module of the code file composition of preset function.
From file type dimension, file to be imported can have identified as treating for " allowing to be imported into " state
Obj ect file or function file to be imported are imported, obj ect file to be imported shows that file to be imported is object class
Type, and function file to be imported then shows that file to be imported is type function.
In the embodiment of the present application, file import statement removes the mark for carrying file to be imported, also carries both
Set the goal the mark of file, and set objective file is used to describing object code truly importing demand, set objective
File is as the code file for realizing preset function being located in file to be imported specified by programming personnel.
Set objective file is normally in file to be imported, such as file to be imported is by multiple code files
During the business module of composition, set objective file can be at least one code file in business module, and treat
File is imported when being single code file, set objective file be the file to be imported in itself.
In the embodiment of the present application, the syntax rule that can be applicable according to object code is set to file import statement
Determine regular expression, and then object code is scanned based on set regular expression, so that it is determined that
Go out to be located at the All Files import statement in object code.The specific building process of regular expression, can be with pin
Code composition to file import statement under different programming languages is preset, and this is ordinary skill people
Technology known to member, will not be described here.
In actual applications, can be according to treating when building the regular expression for determining file import statement
The position of file is imported to determine multiple regular expressions, and scans target using each regular expression successively
Code, so that the file import statement of the file to be imported for diverse location is obtained, to be subsequently directed to this
A little file import statements do adaptive processes.
In the generation that the embodiment of the present application is provided, is described in detail so that object code is based on JavaScript language environment as an example
Code processing method, corresponding object code can be the scripted code based on JavaScript language environment, example
Some the Webpage script such as loaded by browser;Corresponding, file import statement can be based on
Import sentences under JavaScript language environment, the import sentences are located in object code, for inciting somebody to action
The business that the code file that some existing suffix are JS by JS code file or by these suffix is constituted
Module is directed into object code.
Continuation of the previous cases, for ease of understanding file import statement and file to be imported, to the part piece of object code
Duan Jinhang illustrates, specific as follows:
export funbtion a(…){
…
};
export funbtion b(…){
…
};
export a from'./lia/a.js';
export b from'./lia/b.js';
// mark X modules, including function a and function b;
export funbtion c(…){
…
};
export c from'./lia/c.js';
// mark Y modules, including function c;
import X from'X';
// the X object imported under X modules;
a(…){
…
};
// call function a under X modules;
import{a,b}from'X';
// function a and b imported under X modules;
b(…){
…
};
// call function b under X modules;
import{c}from'Y';
// function the c imported under Y modules;
c(…){
…
};
// function the c imported under Y modules;
d(…){
…
};
// call user function d newly-built in object code.
, can be by building import**from** canonical table for the fragment of the foregoing object code enumerated
Up to formula, then all file import statements can be determined in object code.In the embodiment of the present application,
The two regular expressions of import**from*X* and import**from*Y* can be set, so that really
The position of file to be imported is made in module X and Y.
Based on regular expression import**from*X*, it may be determined that go out import X from'X' and
Import { a, b } from'X' both of these documents import statements, its file to be imported is module X;Difference
It is, import X from'X' set objective file is then object X, import { a, b } from'X'
Set objective file then be function a and b.
Based on regular expression import**from*Y*, it may be determined that go out import c from'Y', it is treated
Importing file is module Y;Set objective file is then object c.
S40, in the object code determine that the file corresponding with the file import statement calls language
Sentence, the file call statement is used to call the file to be called in the file to be imported.
The continuity that file call statement is acted on as file import statement, is treated for being imported in file import statement
File to be called is called after importing file.
File to be called can be understood as in file to be imported:File to be called be file to be imported in itself or
The code file of certain preset function is realized in the file to be imported, can be with by performing sentence to be called
Be so that object code can really realize function of file to be imported itself or in the file to be imported certain
A little functions.
With reference to shown in Fig. 2, in the embodiment of the present application, S40 specifically includes following steps.
S42, determine file call statement in the object code, the file call statement is used to adjust
Use file to be called.
In actual applications, it again may be by setting regular expression to file call statement, then based on just
Then expression formula is scanned to object code, so that it is determined that the All Files gone out in object code calls language
Sentence.The building process of specific regular expression, refers to the foregoing expression formula to file import statement, herein
Do not repeat.
Still continuation of the previous cases, for the fragment of the foregoing object code enumerated, file call statement can be by building
Vertical * (* *) { * * } regular expression, then can determine All Files call statement in object code.
S44, mark identical set objective file is judged whether and during file to be called, if so, holding
Row step S46, if it is not, performing step S48.
In the embodiment of the present application, code process method also includes the following step being located between step S20 and S40
Suddenly:The mark of set objective file in the file import statement determined is preserved to default storage region.
Default storage region can be a data data storage storehouse or list, can be carried on hard disk, caching
Deng in computer memory space, this is technology well known to those of ordinary skill in the art, be will not be described here.
In actual applications, set objective file includes:Set objective obj ect file or set objective function text
Part, the file to be called includes:Obj ect file to be called or function file to be called.
Corresponding, the mark by set objective file in the file import statement determined is preserved to pre-
If storage region, specifically include at least one of following:
The mark of set objective obj ect file in the file import statement determined is preserved to default storage
First position in region;
The mark of set objective function file in the file import statement determined is preserved to default storage
The second place in region.
In actual applications, the type identification of set objective file can be set up and judge keyword, it is determined that
Go out after file import statement, the type of set objective file is judged by judging keyword.It can such as lead to
Bracket mark " { } " is crossed to set up function keyword, when there is bracket mark " { } " in set keyword,
Judge the set objective file as set objective function file.
Because first position and the second place are two relatively independent storage locations, for storing class respectively
The different set objective file of type, in order to subsequent match efficiency.
The step S44 of correspondence is adjusted to:Determine exist in the default storage region and set objective text
Part identifies identical file to be called.
Specifically, determining exist and the obj ect file to be called in the first position of the default storage region
Identify identical set objective obj ect file;Determine exist and institute in the second place of the default storage region
State function file mark identical set objective function file to be called.
Storage file is distinguished according to the type of set objective file, is easy to the follow-up class according to file to be called
Type identifies identical set objective file to determine whether to exist, and improves judgement efficiency.
S46, determine the file to be called where file call statement and file where the set objective file
Import statement is corresponding.
S48, determine the file to be called where file call statement and file where the set objective file
Import statement is not corresponded to.
In the embodiment of the present application, scanned by corresponding regular expression after object code, can obtain corresponding
File import statement and file call statement, and then determine wherein set objective file and file to be called
Mark.It is determined that wherein after the mark of set objective file and file to be called, it is determined whether there is mark phase
Same mark identical set objective file and file to be called, if so, determining text where the file to be called
Part call statement is corresponding with file import statement where the set objective file;Conversely, determining that this waits to adjust
It is not corresponding with file call statement where file and file import statement where the set objective file.
Still continuation of the previous cases, based on regular expression import**from*X*, to determine import X from
' exemplified by X' and import { a, b } from'X' both of these documents import statements, it may be determined that set objective file
Be designated a and b, file to be called is designated a, b, c and d.By the mark of file to be called with
Set objective file is matched, and obtains identifying a and b file importing of the file to be called with foregoing determination
Sentence is corresponding.
Still continuation of the previous cases, based on regular expression import**from*Y*, to determine import c from
' exemplified by Y', it may be determined that set objective file is designated c, file to be called be designated a, b, c and
d.The mark of file to be called is matched with set objective file, obtains identifying c file to be called
File import statement with foregoing determination is corresponding.
S60, the mark using the file to be called in the corresponding file call statement, replace described
The mark of file to be imported in file import statement.
What it is due to file to be called replacement is file to be imported in corresponding file import statement, can be caused
When file import statement after being replaced is performed, the follow-up code file being really called can be imported and (treated
Call file) so that the file that file import statement is imported is the code that programming personnel really needs to call
File, it is to avoid the code file that importing to be called causes the object code volume additionally to increase.Still prolong
Continuous upper example, for the scripted code of Webpage, the code process method provided by the embodiment of the present application
Afterwards, can avoid the script of the Webpage that volume additionally increases downloaded by browser and implementation procedure in consume
When it is longer the problem of.
In actual applications, the quantity of file to be called imports language with corresponding file in file call statement
The quantity of file to be imported should be identical in sentence, and each file to be called is replaced into corresponding file one by one imports
File to be imported in sentence.In replacement process, directly the mark of file to be imported can be replaced with
The mark of file to be called, will not be described here.
In the embodiment of the present application, file to be called in file call statement can be also implemented by the following steps
It is specific as follows to replace file to be imported in corresponding file import statement:
File import statement where deleting the file to be imported is simultaneously newly-increased such as in the first trip of the object code
Lower sentence:Mark/lib/ texts to be called of the mark from' target service modules of import files to be called
The mark of part '.The mark of target service module is business mould where the file to be imported of this document import statement
The mark of block, it can determine that the regular expression set during file import statement is obtained by abovementioned steps,
Object code fragment below in conjunction with aforementioned list is described in detail, and can specifically be joined shown in table 1.
Table 1
Such as the example of sequence number 1 in table 1, file to be called is function b, file import statement import a from
' a' is processed into:Import b from'a/lib/b', wherein as the object a of set objective file by according to treating
The mark of file is called to be adjusted to object b, as the module a of file to be imported by according to target service module
A/lib/b is adjusted to the mark of file to be called.
Such as the example of sequence number 2 in table 1, file to be called is function c, file import statement import { b, c }
From'a' is processed into:Import c from'a/lib/c', wherein being used as the function b and c of set objective file
Object c is adjusted to by the mark according to file to be called, as the module a of file to be imported by according to target
The mark of business module and file to be called is adjusted to a/lib/c.
To sum up, the code process method that the embodiment of the present application is provided, by be called in file call statement
File replaces file to be imported in corresponding file import statement so that the file import statement after being replaced
When being performed, the follow-up code file being really called can be imported so that the text that file import statement is imported
Part is the code file that programming personnel really needs to call, it is to avoid import the code file that need not be called
Object code volume is caused additionally to increase.
Fig. 3 is the process of code process method in the application second embodiment, compared with first embodiment, area
It is not, also comprises the following steps between step S20 and S40.
S30, judge the file to be imported whether include at least two code files, if so, directly execution
Step S40, if it is not, then performing step S70.
Because file to be imported is existing module or code file, whether it includes at least two codes text
Part can be obtained by inquiry, will not be described here.Continuation of the previous cases, if file to be imported is module X,
It includes two code files (function a and b), if file to be imported is module Y, it only includes one
Code file (function c).
S70, send without process signal.
When file to be imported only has a code file, redundant case can't occur for importing process, therefore
Handled without to object code.It can be sent to without process signal and initiate code process request
On terminal device so that promoter can be clearly without handling code.
Certainly, in the other embodiment of the application, step S30 may be located on before step S20, only
File identical file import statement to be imported is determined when need to perform step S20 again, for example, only determines to treat
Import file be module X file import statement, you can by the direct judge module X of step 30 whether
Including at least two code files, if so, then perform step S20 and subsequent step to carry out code process,
If it is not, directly performing step S70, it will not be described here.
To sum up, the code processing apparatus that the embodiment of the present application is provided, by be called in file call statement
File replaces file to be imported in corresponding file import statement so that the file import statement after being replaced
When being performed, the follow-up code file being really called can be imported so that the text that file import statement is imported
Part is the code file that programming personnel really needs to call, it is to avoid due to importing the code that need not be called
File causes object code volume additionally to increase, it is ensured that it is normally used.
Fig. 4 is the module map of code processing apparatus in the embodiment of the present application, and the code processing apparatus is before being based on
State in each embodiment that code process method is come what is run, its technical principle and details refer to preceding method,
It will not be described here.
In the embodiment of the present application, code processing apparatus includes:
Import statement determining module 20, for determining file import statement, the file in object code
Import statement is used to import file to be imported;
Call statement determining module 40, for being determined in the object code and the file import statement
Corresponding file call statement, the file call statement is used to call treating in the file to be imported to adjust
Use file;
File replacement module 60, for using the file to be called in the corresponding file call statement
Mark, replaces the mark of the file to be imported in the file import statement.
In the embodiment of the present application, described device also includes judge module and signal generating module;
The judge module is used for:Judge whether the file to be imported includes at least two code files;
When the file to be imported includes at least two code files, the call statement determining module 40
For determining the file call statement corresponding with the file import statement in the object code;
When the file to be imported does not include at least two code files, the signal generating module is used to send out
Go out without process signal.
In the embodiment of the present application, the file import statement is carried:Truly imported for describing object code
The mark of the set objective file of demand;
The call statement determining module 40, specifically for:
File call statement is determined in the object code, the file call statement is used to call to wait to adjust
Use file;
When there is mark identical set objective file and file to be called, file place to be called is determined
File call statement is corresponding with file import statement where the set objective file, and the file calls language
The file to be called that sentence is called is in the file to be imported.
In the embodiment of the present application, described device also includes memory module, and the memory module is used for:By really
The mark of set objective file is preserved to default storage region in the file import statement made;
The call statement determining module 40, specifically for:
Determine exist and the set objective file identification identical text to be called in the default storage region
Part.
In the embodiment of the present application, the set objective file includes:Set objective obj ect file or set objective
Function file, the file to be called includes:Obj ect file to be called or function file to be called;
The memory module specifically for:
The mark of set objective obj ect file in the file import statement determined is preserved to default storage
First position in region;
The mark of set objective function file in the file import statement determined is preserved to default storage
The second place in region;
The call statement determining module 40, specifically for:
Determine exist in the first position of the default storage region and the obj ect file mark phase to be called
Same set objective obj ect file;
Determine exist in the second place of the default storage region and the function file mark phase to be called
Same set objective function file.
In the embodiment of the present application, the object code is the browser scripted code based on JavaScript.
To sum up, the code processing apparatus that the embodiment of the present application is provided, by be called in file call statement
File replaces file to be imported in corresponding file import statement so that the file import statement after being replaced
When being performed, the follow-up code file being really called can be imported so that the text that file import statement is imported
Part is the code file that programming personnel really needs to call, it is to avoid due to importing the code that need not be called
File causes object code volume additionally to increase, it is ensured that it is normally used.
In the 1990s, can clearly to distinguish be changing on hardware for the improvement of a technology
The improvement entered on (for example, improvement to circuit structures such as diode, transistor, switches) or software is (right
In the improvement of method flow).However, with the development of technology, the improvement of many method flows now is
Through directly improving for hardware circuit can be considered as.Designer is nearly all by by improved method flow
It is programmed into hardware circuit to obtain corresponding hardware circuit.Therefore, it cannot be said that method flow
Improvement cannot be realized with hardware entities module.For example, PLD (Programmable
Logic Device, PLD) (for example field programmable gate array (Field Programmable Gate Array,
FPGA)) it is exactly such a integrated circuit, its logic function is determined by user to device programming.By setting
Meter personnel are voluntarily programmed a digital display circuit " integrated " on a piece of PLD, without asking chip
Manufacturer designs and made special IC chip 2.Moreover, nowadays, substitution manually makes
" logic compiler (logic compiler) " software is also used in IC chip, this programming instead mostly
Realize, software compiler used is similar when it writes with program development, and the original generation before compiling
Code also write by handy specific programming language, and this is referred to as hardware description language (Hardware
Description Language, HDL), and HDL is also not only a kind of, but have many kinds, such as
ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware
Description Language)、Confluence、CUPL(Cornell University Programming
Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、
MyHDL, PALASM, RHDL (Ruby Hardware Description Language) etc., at present
Most generally use VHDL (Very-High-Speed Integrated Circuit Hardware
Description Language) and Verilog2.Those skilled in the art also will be apparent to the skilled artisan that only need to by
Method flow slightly programming in logic and is programmed into integrated circuit with above-mentioned several hardware description languages, it is possible to
It is readily available the hardware circuit for realizing the logical method flow.
Controller can be implemented in any suitable manner, for example, controller can take such as microprocessor
Or processor and storage can by (micro-) computing device computer readable program code (such as software
Or firmware) computer-readable medium, gate, switch, application specific integrated circuit (Application Specific
Integrated Circuit, ASIC), the form of programmable logic controller (PLC) and embedded microcontroller, controller
Example include but is not limited to following microcontroller:ARC 625D、Atmel AT91SAM、Microchip
PIC18F26K20 and Silicone Labs C8051F320, Memory Controller is also implemented as depositing
A part for the control logic of reservoir.It is also known in the art that except with pure computer-readable program
Code means are realized beyond controller, can cause control by the way that method and step is carried out into programming in logic completely
Device is with the shape of gate, switch, application specific integrated circuit, programmable logic controller (PLC) and embedded microcontroller etc.
Formula realizes identical function.Therefore this controller is considered a kind of hardware component, and to being wrapped in it
The device for realizing various functions included can also be considered as the structure in hardware component.Or even, can be with
It not only can will be the software module of implementation method for realizing that the device of various functions is considered as but also can be hardware
Structure in part.
System, device, module or unit that above-described embodiment is illustrated, specifically can be by computer chip or reality
Body is realized, or is realized by the product with certain function.
For convenience of description, it is divided into various units during description apparatus above with function to describe respectively.Certainly,
The function of each unit can be realized in same or multiple softwares and/or hardware when implementing the application.
It should be understood by those skilled in the art that, embodiments of the invention can be provided as method, system or meter
Calculation machine program product.Therefore, the present invention can be using complete hardware embodiment, complete software embodiment or knot
The form of embodiment in terms of conjunction software and hardware.Wherein wrapped one or more moreover, the present invention can be used
Containing computer usable program code computer-usable storage medium (include but is not limited to magnetic disk storage,
CD-ROM, optical memory etc.) on the form of computer program product implemented.
The present invention is with reference to the production of method according to embodiments of the present invention, equipment (system) and computer program
The flow chart and/or block diagram of product is described.It should be understood that can by computer program instructions implementation process figure and
/ or each flow and/or square frame in block diagram and the flow in flow chart and/or block diagram and/
Or the combination of square frame.These computer program instructions can be provided to all-purpose computer, special-purpose computer, insertion
Formula processor or the processor of other programmable data processing devices are to produce a machine so that pass through and calculate
The instruction of the computing device of machine or other programmable data processing devices is produced for realizing in flow chart one
The device for the function of being specified in individual flow or multiple flows and/or one square frame of block diagram or multiple square frames.
These computer program instructions, which may be alternatively stored in, can guide computer or the processing of other programmable datas to set
In the standby computer-readable memory worked in a specific way so that be stored in the computer-readable memory
Instruction produce include the manufacture of command device, the command device realization in one flow or multiple of flow chart
The function of being specified in one square frame of flow and/or block diagram or multiple square frames.
These computer program instructions can be also loaded into computer or other programmable data processing devices, made
Obtain and perform series of operation steps on computer or other programmable devices to produce computer implemented place
Reason, so that the instruction performed on computer or other programmable devices is provided for realizing in flow chart one
The step of function of being specified in flow or multiple flows and/or one square frame of block diagram or multiple square frames.
In a typical configuration, computing device includes one or more processors (CPU), input/defeated
Outgoing interface, network interface and internal memory.
Internal memory potentially includes the volatile memory in computer-readable medium, random access memory
And/or the form, such as read-only storage (ROM) or flash memory (flash RAM) such as Nonvolatile memory (RAM).
Internal memory is the example of computer-readable medium.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by appointing
What method or technique realizes that information is stored.Information can be computer-readable instruction, data structure, program
Module or other data.The example of the storage medium of computer includes, but are not limited to phase transition internal memory
(PRAM), static RAM (SRAM), dynamic random access memory (DRAM), its
Random access memory (RAM), read-only storage (ROM), the electrically erasable of his type are read-only
Memory (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read-only storage
(CD-ROM), digital versatile disc (DVD) or other optical storages, magnetic cassette tape, tape magnetic
Disk storage or other magnetic storage apparatus or any other non-transmission medium, can be calculated available for storage
The information that equipment is accessed.Defined according to herein, computer-readable medium does not include temporary computer-readable matchmaker
The data-signal and carrier wave of body (transitory media), such as modulation.
It should also be noted that, term " comprising ", "comprising" or its any other variant be intended to it is non-
It is exclusive to include, so that process, method, commodity or equipment including a series of key elements are not only wrapped
Include those key elements, but also other key elements including being not expressly set out, or also include for this process,
Method, commodity or the intrinsic key element of equipment.In the absence of more restrictions, by sentence " including
One ... " key element that limits, it is not excluded that in the process including the key element, method, commodity or set
Also there is other identical element in standby.
It will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer journey
Sequence product.Therefore, the application can using complete hardware embodiment, complete software embodiment or combine software and
The form of the embodiment of hardware aspect.Moreover, the application can be used wherein includes calculating one or more
Machine usable program code computer-usable storage medium (include but is not limited to magnetic disk storage, CD-ROM,
Optical memory etc.) on the form of computer program product implemented.
The application can be described in the general context of computer executable instructions, example
Such as program module.Usually, program module includes performing particular task or realizes particular abstract data type
Routine, program, object, component, data structure etc..This can also be put into practice in a distributed computing environment
Application, in these DCEs, by the remote processing devices connected by communication network come
Execution task.In a distributed computing environment, program module can be located at local including storage device
In remote computer storage medium.
Each embodiment in this specification is described by the way of progressive, identical phase between each embodiment
As part mutually referring to, what each embodiment was stressed be it is different from other embodiment it
Place.For system embodiment, because it is substantially similar to embodiment of the method, so description
Fairly simple, the relevent part can refer to the partial explaination of embodiments of method.
Embodiments herein is the foregoing is only, the application is not limited to.For this area skill
For art personnel, the application can have various modifications and variations.All institutes within spirit herein and principle
Any modification, equivalent substitution and improvements of work etc., should be included within the scope of claims hereof.