CN104536797B - A kind of java applet precompile method and pre compiler - Google Patents

A kind of java applet precompile method and pre compiler Download PDF

Info

Publication number
CN104536797B
CN104536797B CN201510018651.8A CN201510018651A CN104536797B CN 104536797 B CN104536797 B CN 104536797B CN 201510018651 A CN201510018651 A CN 201510018651A CN 104536797 B CN104536797 B CN 104536797B
Authority
CN
China
Prior art keywords
keyword
precompile
code
conditional statement
source files
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
CN201510018651.8A
Other languages
Chinese (zh)
Other versions
CN104536797A (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.)
Datang Microelectronics Technology Co Ltd
Original Assignee
Datang Microelectronics 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 Datang Microelectronics Technology Co Ltd filed Critical Datang Microelectronics Technology Co Ltd
Priority to CN201510018651.8A priority Critical patent/CN104536797B/en
Publication of CN104536797A publication Critical patent/CN104536797A/en
Application granted granted Critical
Publication of CN104536797B publication Critical patent/CN104536797B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

The embodiment of the present invention provides a kind of java applet precompile method and pre compiler, and the above method includes:Obtain the corresponding platform information of target platform;Java source files are scanned, the precompile keyword in the Java source files is recognized;According to the precompile keyword, platform information corresponding to the target platform judges, and the precompile code segment in the Java source files is identified, according to the judged result of the platform information, the precompile code segment in the Java source files is handled;According to the result of the processing, the precompile process to the Java source files is performed.During precompile, pre compiler is directed to different platforms, precompile file of the generation corresponding to each platform, so as to complete to realize in the application of different platform by same set of source code, so as to save memory space, in addition, when changing code, only need to modify to Java source files so that code administration is more succinct and efficient.

Description

A kind of java applet precompile method and pre compiler
Technical field
The present invention relates to field java applet language technology, more particularly to a kind of java applet precompile method and precompile Device.
Background technology
Java is a kind of object oriented program language, is May nineteen ninety-five by Sun Microsystems companies Release.Java is very popular because of its remarkable versatility, high efficiency and cross-platform characteristic from after emerging, and is widely used in Personal PC, data center, game console, science supercomputer, mobile phone, internet and embedded system.
Java cross-platform characteristic, is to be directed to application and development, Java Virtual Machine is shielded flat when explaining that execution is applied Difference between platform, but Java Virtual Machine is not cross-platform in itself, and a virtual machine generally comprises two parts:It is supplied to user Exploitation SDK (usual Java realize), support the Native codes of SDK operations (usual C is realized).
Java card is that a typical Java Virtual Machine is realized, Java Virtual Machine has many different Version Specs, real The virtual machine of existing different editions specification is usually using different code bags, rather than uses identical code bag, compiles different versions This virtual machine is controlled by compilation script, by giving compilation script the incoming parameter specified, so as to compile out difference Virtual machine.
In this embedded system development of Java card, Java and the multilingual mixed developings of C, in face of different hardware, Or, it is necessary to write different Java source files for different hardware or platform during different software platform, and different Each self-corresponding code bag is stored under catalogue, code bag includes multiple Java source files, and can not be with a set of source code come same There is substantial amounts of duplicated code in platforms different Shi Shiying, the code bag of different directories, take more memory space, when need , it is necessary to be modified to the code bag under each catalogue, workload is larger when being modified to source code, applied when needs Platform is more and more, or the version of virtual machine, when being continually changing, the maintenance work of code becomes extremely difficult.
The content of the invention
The present invention provides a kind of java applet precompile method and pre compiler, for solving in the prior art due to difference A large amount of memory spaces and code maintenance task are tired the need for existing in code bag under catalogue caused by substantial amounts of duplicated code Difficult the problem of.
In order to solve the above-mentioned technical problem, the invention provides a kind of java applet precompile method, the java applet Precompile method includes:
According to target platform, the corresponding platform information of the target platform is obtained;
Java source files are scanned, the precompile keyword in the Java source files are recognized, and obtain precompile The corresponding semanteme of keyword;
According to the corresponding semanteme of the precompile keyword, platform information corresponding to the target platform judges, And the precompile code segment in the Java source files is identified, and according to the judged result of the platform information, it is right Precompile code segment in the Java source files is handled;
According to the result handled the precompile code segment in the Java source files, perform to the Java source documents The precompile process of part.
In order to solve the above-mentioned technical problem, present invention also offers a kind of pre compiler, the pre compiler includes
Acquisition module, for according to target platform, obtaining the corresponding platform information of the target platform;.
Scan module, for being scanned to Java source files, recognizes the precompile keyword in the Java source files, And obtain the corresponding semanteme of precompile keyword;
Processing module, for according to the corresponding semanteme of the precompile keyword, platform corresponding to the target platform Information is judged, and the precompile code segment in the Java source files is identified, and according to the platform information Judged result, the precompile code segment in the Java source files is handled;
Output module, for according to the result handled the precompile code segment in the Java source files, performing To the precompile process of the Java source files.
Beneficial effects of the present invention include:
By java applet precompile method provided in an embodiment of the present invention, it can realize by same set of source code come same Platforms different Shi Shiying, can be in the form of precompile code segment for the code for needing individually to perform for each platform It is programmed in Java source files, during precompile ground, pre compiler is directed to different platforms, and generation corresponds to each platform Precompile file so that by same set of source code complete different platform application realize, due to realizing identical API , will not be because of storing different codes under different directories during class, it is only necessary to a Java source file is stored under a catalogue Wrap and take excessive memory space, so that substantial amounts of memory space is saved, furthermore, it is necessary to when changing code, it is not necessary to respectively Change the Java source files under different directories, it is only necessary to a Java source file is modified, workload is smaller, hence in so that Code administration is more succinct and efficient.
Brief description of the drawings
Fig. 1 is a kind of schematic flow sheet of java applet precompile method provided in an embodiment of the present invention;
Fig. 2 is the structural representation of pre compiler provided in an embodiment of the present invention;
Fig. 3 is the schematic diagram that pre compiler performs precompile process.
Embodiment
To make those skilled in the art more fully understand technical scheme, below in conjunction with the accompanying drawings to of the invention real The java applet precompile method and pre compiler for applying example offer are described in detail.
Referring to Fig. 1, being a kind of schematic flow sheet of java applet precompile method provided in an embodiment of the present invention, such as scheme Shown in 1, the java applet precompile method includes:
Step S101, according to target platform, obtains the corresponding platform information of the target platform.
Step S102, is scanned to Java source files, recognizes the precompile keyword in the Java source files, and obtain Take the corresponding semanteme of precompile keyword.
Step S103, according to the corresponding semanteme of the precompile keyword, platform information corresponding to target platform is carried out Judge, and the precompile code segment in Java source files is identified, and according to the judged result of the platform information, it is right Precompile code segment in Java source files is handled.
Step S104, according to the result handled the precompile code segment in the Java source files, is performed to institute State the precompile process of Java source files.Wherein, precompile code segment in the source file to Java carry out processing include with Under it is any or its any combination:Optionally shielding or reservation process are carried out to the precompile code segment;Comment line is turned It is changed to code line;Abandon generating corresponding precompile file.In the former two cases, it will generate corresponding with the Java source files Precompile file, in the latter case, will abandon generating corresponding precompile file.
In the embodiment of the present invention, the precompile of Java source files is realized by pre compiler realization.
Preferably, to be stored in each platform beforehand through the mode of macrodefinition corresponding for the corresponding platform information of different platform In header file.Pre compiler is directed to different platforms, for same Java source files, will generate different precompile files. When pre compiler performs precompile process for some target platform, the corresponding header file of the target platform is called first, so that Macrodefinition information all in header file are read, and according to the semanteme of precompile keyword definition, are performed to macrodefinition information Judge, and according to the judgement to the macrodefinition information, realize the judgement to the platform information of target platform, and further basis Judgement to platform information, which kind of processing determined to carry out precompile code segment.In addition it is also possible to which platform information is stored in In the file of extended formatting, for example, can be stored in xml document, xml document is that one kind is used to describe data with being widely used File, the corresponding platform information of each platform can be stored in xml document in the way of data.
Above-mentioned platform information includes but is not limited to virtual machine version information, and whether operation system information, function information need Realize the information of certain function.Different platform in the embodiment of the present invention refers to for identical application, it is necessary to write difference Java source files hardware or software systems, the platform in the embodiment of the present invention includes but is not limited to operating system not Together, the difference of virtual machine version, and systemic-function realize desired difference.
Volume can be performed by existing compiler according to the precompile file that above-mentioned java applet precompile method is generated Process is translated, and generates corresponding compiled code.
In the embodiment of the present invention, by precompile function, it can realize by same set of source code come while adapting to difference Platform, for the code for needing individually to perform for each platform, Java can be programmed in the form of precompile code segment In source file, during precompile ground, pre compiler is directed to different platforms, prelist translation of the generation corresponding to each platform Part, so as to complete to realize in the application of different platform by same set of source code, due to when realizing identical API classes, only needing A Java source file is stored under a catalogue, will not be taken because different code bags are stored under different directories Many memory spaces, so that substantial amounts of memory space is saved, furthermore, it is necessary to when changing code, it is not necessary to different mesh are respectively modified Java source files under record, it is only necessary to modified to a Java source file, workload is smaller so that code administration is simpler It is clean and efficient.
In the embodiment of the present invention, predetermined precompile rule are followed between Java source files and the precompile file of corresponding generation Then, i.e., precompile need to follow these precompiles rule when performing precompile process, and the precompile rule includes following any Plant or its any combination:Bag title in the precompile file is consistent with the bag title in the Java source files;Institute The class name stated in precompile file is consistent with the class name in the Java source files;Generation in the precompile file Code line number is consistent with the code line number in the Java source files;The precompile keyword is compiled in the way of annotating word Write in the Java source files.
In the embodiment of the present invention, the precompile keyword includes designator part and Grammar section, the pre compiler According to the designator part, the content of Grammar section can be obtained;Wherein, the designator part is used as the Grammar section Prefix;Or, the designator part includes two parts, respectively as the prefix and suffix of the Grammar section.
, it is necessary to which so that Java IDEs will not report an error to precompile keyword, while again in the embodiment of the present invention Need pre compiler to detect and recognize precompile keyword, therefore, precompile keyword is set to include designator portion Divide and Grammar section.Wherein, designator part includes annotation symbol, and therefore, Java IDEs will not be closed to precompile Key word reports an error, in addition, designator part includes predetermined mark character, it is special book character string to make a reservation for mark character, because This, pre compiler can be by the detection to the predetermined mark character, to realize the detection to precompile keyword and identification.
It is preferred that, can set designator part as " // [# ", that is to say, that all Grammar sections with " // [# " start, Wherein " // " is annotation symbol, and " [# " is predetermined mark character, using two slash (//) up front, is to ensure not destroy Java original grammer, Java IDEs (such as Ecllipse) can ignore the annotation of two slash, it is ensured that Integrated Development Environment will not point out syntax error.In addition, starting within bracket, before Grammar section plus additional character No. #, enter one Step avoids the annotation conflict with user so that detect more accurate, while above-mentioned setting also complies with the pact of C language pre compiler It is fixed.
In addition, designator part can include two parts, respectively as the prefix and suffix of Grammar section so that precompile Device easily can be detected and be recognized to the Grammar section of precompile keyword, it is, for example, possible to use " // [before # " is used as Sew part, and use "] " as suffix portion, Grammar section is expanded to get up by using bracket, with facilitating pre compiler Processing.
In the embodiment of the present invention, the designator part all same of each precompile keyword passes through the difference of Grammar section To distinguish each precompile keyword, the corresponding semanteme of precompile keyword refers to the corresponding semanteme of Grammar section therein.
During precompile file is generated, due to being selected according to precompile keyword precompile code segment Shield to selecting property or reservation process, therefore, corresponding precompile keyword needs not continue to retain in precompile file, prelists The correspondence for translating keyword is about to carry out masking operation after the completion of precompile code segment is handled.
Except using // most starting as designator part, can also use/* most starts as designator part, Also correspond to the grammar request of Java IDEs and the agreement of C language.Two specific examples are named, for example, in advance It is " // [#ifdef] " to compile keyword, wherein, " ifdef " is Grammar section, and " // [# " and "] " is designator part, and Respectively as the prefix and suffix of Grammar section;For another example precompile keyword for/* [#ifdef] */, wherein, " ifdef " is Grammar section "/* [# " and "] */" it is designator part, and respectively as the prefix and suffix of Grammar section.
In the embodiment of the present invention, the Grammar section includes first and starts keyword, terminates keyword;The precompile generation Code section includes first code section;Conditional statement is encoded with behind the described first beginning keyword.Described first starts key The semanteme of word includes:Corresponding judgement is carried out to conditional statement thereafter, and according to judged result to first code section thereafter Handled;The semanteme for terminating keyword includes:Used cooperatively with the corresponding first beginning keyword, for identifying correspondence First start keyword effective range end.
The precompile code segment in the Java source files be identified including:According to first start keyword and Terminate the position of keyword, the sentence between the conditional statement and the end keyword is identified as first code section.
The judged result according to the platform information, at the precompile code segment in the Java source files Reason includes:When reading the first beginning keyword, the conditional statement after the first beginning keyword is judged, such as really bar The judged result of part sentence is true, then reservation process is performed to first code section, if the judged result of conditional statement is Vacation, then perform shielding processing to first code section.
Include the deterministic process to macrodefinition in the embodiment of the present invention, in conditional statement, so as to judge by above-mentioned Journey, realizes the differentiation to platform information, and according to different platform informations, realizes the different disposal to precompile code segment, from And according to different platforms, the different precompile file of correspondence generation, then by existing compiler, generates and corresponds to difference The compiling file of platform.
In the embodiment of the present invention, the first beginning keyword judges that keyword, second judge keyword, Yi Ji including first Three judge keyword, and above-mentioned three kinds judge that keyword performs different judgment mechanisms respectively, distinguish with reference to specific example Illustrate.In the embodiment of the present invention, first judge keyword be ifdef keywords, second judge keyword be ifndef close Key word, the 3rd judge keyword for if keywords, and end keyword is endif keywords.Described first judges the language of keyword Justice includes:Whether it is that the macrodefinition existed judges to conditional statement thereafter.Described second judges the semantic bag of keyword Include:Whether it is that non-existent macrodefinition judges to conditional statement thereafter.Described 3rd judges that the semanteme of keyword includes: Value to conditional statement thereafter carries out the judgement of zero-sum non-zero.
In the embodiment of the present invention, the first beginning keyword includes first and judges keyword, and the conditional statement is the One macro name symbol string, the conditional statement to after the first beginning keyword, which carries out judgement, to be included:The pre compiler judges Whether the first macro name symbol string is pre-defined grand name, if first macro name symbol string is pre-defined grand name, The judged result of decision condition sentence is true;If the first macro name symbol string is not pre-defined grand name, bar is judged The judged result of part sentence is false.
Judge that keyword is illustrated to above-mentioned first with reference to a specific example.For example, in Java source files Including following paragraph:
//[#ifdef Test]
JavaCode1
//[#endif]
Wherein, ifdef is first judge keyword, and first judges keyword for the first macro name followed by judging Whether symbol string is pre-defined grand, and endif is terminates keyword, Test conditional statements, and JavaCode1 is that conditional statement is corresponding First code section, when pre compiler detects the first judgement keyword, pre compiler judge first judge keyword after Whether corresponding first macro name symbol string is pre-defined grand name, if Test is defined grand, decision condition language The judged result of sentence is true, then retaining JavaCode1, i.e. JavaCode1 will be performed, if Test is not define Grand, then the judged result of decision condition sentence is false, then pre compiler is by JavaCode1 delete processing, in order to keep line number not Become, character all in JavaCode1 can be replaced with into space character, i.e. JavaCode1 will not be performed.
In the embodiment of the present invention, the first beginning keyword also judges keyword including second, second judge keyword be with First judges the semantic opposite grammer of keyword, and the conditional statement is that the first macro name accords with string.
The conditional statement to after the first beginning keyword, which carries out judgement, to be included:Pre compiler judges the first macro name Whether symbol string is pre-defined grand name, if first macro name symbol string is not pre-defined grand name, decision condition The judged result of sentence is true;If first macro name symbol string is pre-defined grand name, decision condition sentence is sentenced Disconnected result is false.
Judge that keyword is illustrated to above-mentioned second with reference to a specific example.For example, in Java source files Including following paragraph:
//[#ifndef Test]
JavaCode1
//[#endif]
Wherein, ifndef is second judge keyword, and second judges keyword for the first grand name followed by judging Whether character string is pre-defined grand, and endif is terminates keyword, Test conditional statements, and JavaCode1 is conditional statement pair Answer first code section, when pre compiler detects the second judgement keyword, pre compiler judge second judge keyword it Whether corresponding first macro name symbol string is pre-defined grand name afterwards, if Test is undefined grand, decision condition The judged result of sentence is true, then retains JavaCode1, then JavaCode1 will be performed, if Test is defined mistake It is grand, then the judged result of decision condition sentence is false, then pre compiler is by JavaCode1 delete processing, in order to keep line number It is constant, character all in JavaCode1 can be replaced with space character, then JavaCode1 will not be performed.
In the embodiment of the present invention, the first beginning keyword also judges keyword including the 3rd,
The conditional statement is the second character string;The conditional statement progress judgement bag started to first after keyword Include:Second character string is judged, if the value of second character string is nonzero value, decision condition sentence is sentenced Disconnected result is true, if the value of second character string is null value, and the judged result of decision condition sentence is false;And/or,
The conditional statement compares sentence for second, and second compares sentence becomes including the first variable, comparison operators and second Amount;The conditional statement to after the first beginning keyword, which carries out judgement, to be included:Compare sentence to described second to judge, If the relation between first variable and the second variable meets the description of the comparison operators, the judgement of decision condition sentence As a result it is true, if the relation between first variable and the second variable does not meet the description of the comparison operators, judges bar The judged result of part sentence is false.
Judge that keyword is illustrated to the above-mentioned 3rd with reference to a specific example.For example, in Java source files Including following paragraph:
//[#if RMI_SUPPORT]
JavaCode1
//[#endif]
Wherein, if judges keyword for the 3rd, and RMI_SUPPORT is corresponding second character string, and the 3rd judges keyword Value for the second character string followed by judgement is true (non-zero value) or false (0 value), and endif is end keyword, JavaCode1 is the corresponding first code section of conditional statement, when pre compiler, which detects the 3rd, judges keyword, pre compiler Judge the 3rd value for judging corresponding second character string after keyword, if RMI_SUPPORT value is non-zero value, judge The judged result of conditional statement is true, then retaining JavaCode1, i.e. JavaCode1 will be performed, if RMI_SUPPORT Value be 0, then the judged result of decision condition sentence is false, then pre compiler is by JavaCode1 delete processing, in order to keep capable Number constant, character all in JavaCode1 can be replaced with into space character, i.e. JavaCode1 will not be performed.
It is that the second situation for comparing sentence is illustrated to conditional statement with reference to a specific example.For example, Java source files include following paragraph:
//[#if JCRE_Version>2.2]
JavaCode1
//[#endif]
Wherein, if judges keyword for the 3rd, JCRE_Version>2.2 compare sentence for corresponding second, wherein, JCRE_Version be the first variable,>Be the second variable for comparison operators, 2.2, the 3rd judge keyword be used for judge followed by The second value for comparing sentence be true (non-zero value) or false (0 value), that is, judge the pass between first variable and the second variable Whether system meets the description of comparison operators, and endif is terminates keyword, and JavaCode1 is the corresponding first code section of conditional statement, When pre compiler, which detects the 3rd, judges keyword, pre compiler judges that the 3rd judges after keyword that corresponding second compares The value of sentence, if JCRE_Version value is more than 2.2, it is true, i.e. decision condition language to judge the second value for comparing sentence The judged result of sentence is true, then retaining JavaCode1, i.e. JavaCode1 will be performed, if JCRE_Version value is small In 2.2, then it is false to judge the second value for comparing sentence, i.e. the judged result of decision condition sentence is false, then pre compiler will JavaCode1 delete processing, in order to keep line number constant, can replace with space character by character all in JavaCode1, That is JavaCode1 will not be performed.
Wherein, pre compiler in header file according to judging JCRE_Version definition, if for example, header file Include sentence:
#define JCRE_Version 2.1.1
Then pre compiler is for // [#if JCRE_Version>2.2] judged result of the conditional statement in is False (vacation);
If header file includes sentence:
#define JCRE_Version 2.2.1
Then pre compiler is for // [#if JCRE_Version>2.2] judged result of the conditional statement in is True (true).
On the basis of the precompile keyword that above-described embodiment is provided, the Grammar section also includes second and starts key Word, the precompile code segment also include second code section.In the embodiment of the present invention, the second beginning keyword is else crucial Word.
The second beginning keyword is programmed between the first code section and the end keyword;
The semanteme of the second beginning keyword includes:Used cooperatively with the corresponding first beginning keyword, for basis First starts the judged result of the conditional statement of keyword thereafter, second code section is carried out opposite with first code section Processing;
The precompile code segment in the Java source files, which is identified, also to be included:Described second is started crucial Code segment between word and the end keyword is identified as second code section;
The judged result according to the platform information, at the precompile code segment in the Java source files Reason also includes:After the conditional statement after to the first beginning keyword judges, if the judgement of the conditional statement As a result it is true, then shielding processing is performed to second code section, if the judged result of conditional statement is false, to described the Two code segments perform reservation process.
The above-mentioned second beginning keyword is illustrated with reference to a specific example.For example, in Java source files Including following paragraph:
Wherein, ifdef judges keyword for first, i.e., first starts one kind of keyword, and else is that the second beginning is crucial Word, endif is terminates keyword, and Test is conditional statement, and JavaCode1 is the corresponding first code section of conditional statement, JavaCode2 is the second code section being programmed between the second beginning keyword and the end keyword, works as precompile When device detects the beginning keyword else of the first judgement keyword ifdef and second, pre compiler is starting keyword to first Corresponding conditional statement is judged whether be defined grand name, if the judged result of conditional statement if judging Test It is true, then reservation process is performed to first code section JavaCode1 and second code section JavaCode2 is held Row shielding processing, if the judged result of conditional statement is false, is performed at reservation to second code section JavaCode1 Reason, and shielding processing is performed to first code section JavaCode1.
In the embodiment of the present invention, the Grammar section also includes excluding keyword, excludes keyword and is closed for excludeFile Key word.
The exclusion keyword is programmed between the conditional statement and the end keyword.The exclusion keyword Semanteme includes:Shielding processing is carried out to Java source files.
The judged result according to the platform information, at the precompile code segment in the Java source files Reason also includes:After the conditional statement after to the first beginning keyword judges, if according to the judgement of conditional statement As a result, it is determined that in the case that behavior needs the row of reservation where excluding keyword, then according to the presence of the exclusion keyword, putting The corresponding precompile file of generation is abandoned, if the judged result of conditional statement is false, retains whole generations in Java source files Code row.If that is, according to the judged result of conditional statement, determining that excludeFile keywords are expert at and being not required to The row of reservation, i.e. it is the row for needing to shield to determine that excludeFile keywords are expert at, then is not carried out excludeFile passes Key word corresponding precompile processing, but excludeFile keywords are expert at shielding.
Above-mentioned exclusion keyword is illustrated with reference to a specific example.For example, Java source files include Following paragraph:
//[#if JCRE_Version<2.2.2]
//[#excludeFile]
//[#endif]
Wherein, if judges keyword for the 3rd, JCRE_Version<2.2.2 sentence is compared for corresponding second, ExcludeFile is excludes keyword, and endif is terminates keyword, and // [#excludeFile] is conditional statement corresponding the One code segment, when pre compiler, which detects the 3rd, judges keyword, pre compiler judges that the 3rd judges correspondence after keyword The second value for comparing sentence, if JCRE_Version<2.2.2 set up, then the judged result of decision condition sentence be it is true, then Retain first code section // [#excludeFile], due to // [#excludeFile] be precompile keyword, therefore prelisting Sentence is performed during translating, i.e., according to the corresponding semanteme of keyword is excluded, abandons that the generation of above-mentioned Java source files is corresponding Precompile file, and abandon compilation process thereafter, if it is decided that the judged result of conditional statement is false, then to first code Section // [#excludeFile] performs shielding processing.
In the embodiment of the present invention, the first precompile code segment for starting keyword and terminating between keyword can be common Code line, precompile keyword, if common code line, then pre compiler sentencing according to conditional statement can also be included Disconnected structure, performs and retains or shielding processing, if precompile keyword, judge structure in conditional statement for fictitious time, in advance Compiling keyword is expert at and is equally performed shielding processing, when the judgement structure of conditional statement is true, and pre compiler is by basis The corresponding handling process of semantic execution of precompile keyword.In addition, precompile keyword provided in an embodiment of the present invention can be with Nesting is used.For the keyword in nesting, only when outer layer condition judgment is true, internal layer can just work, if outer layer It is judged as vacation, the code segment of internal layer will not work, and can directly carry out shielding processing.When recognizing the first beginning keyword, System can all start keyword to first and terminate keyword progress pairing detection, it is ensured that the shield ranges of precompile code segment are not Can be because internal keys cause entanglement.
In the embodiment of the present invention, the Grammar section also includes code and indicates keyword, and code indicates that keyword is code Keyword.The code indicates that keyword is programmed between the conditional statement and the end keyword.The code is indicated The semanteme of keyword includes:Comment line is converted into normal codes row.The judged result according to the platform information, to institute Stating the precompile code segment in Java source files and being handled also includes:Conditional statement after to the first beginning keyword enters After row judges, if according to the judged result of conditional statement, determining that code indicates that keyword place behavior needs the row retained In the case of, then keyword is indicated according to code, code is indicated that keyword and corresponding designator part are removed.Namely Say, if according to the judged result of conditional statement, determining that code indicates that keyword is expert at and is not required to the row of reservation, i.e. really It is the row for needing to shield to determine code to indicate that keyword is expert at, then is not carried out code and indicates at the corresponding precompile of keyword Reason, but code instruction keyword is expert at shielding.
The use of keyword, which is illustrated, to be indicated to above-mentioned code with reference to a specific example.For example, Java sources File includes following paragraph:
Under Java IDE Eclipse environment, the mistakes of return 0 can be pointed out, the return repeated, to understand Certainly this problem, can be solved with employing mode one, i.e., using a variable, be variable difference assignment, finally only write one Return sentences, it would however also be possible to employ mode two is solved, mode two, relative to mode one, is a more simple solution, Indicate that 1 and 0 return is realized in the use of keyword by code, following paragraph please be check:
Wherein, code is that code indicates keyword, will when the judged result of pre compiler then decision condition sentence is true Reserved of codes row " return 1 ", and shield code line " // [#code] return 0 ", if it is decided that the judgement of conditional statement As a result it is false, then pre compiler is by reserved of codes row " // [#code] return 0 ", because code line includes precompile key Word, therefore, the corresponding semantic execution of keyword is indicated according to code, and pre compiler is by code line " // [#code] return 0 " Replace with corresponding code line " return 0 ".
By above-mentioned processing, Java IDEs will not report an error, while can obtain correct result again;Because to pre- For compiler, it is believed that this two sections of codes are consistent, because precompile will be ignored and remove // [#code] keyword, Generate identical precompile file.
In following example, it is necessary to which use // [#code] could solve the syntax error of IDE discovery:
In above-mentioned code, ignore macrodefinition keyword, it may appear that two identical definition, thus IDE discovery Syntax error can be reported, if this section of code is changed into as follows:
By above-mentioned modification, IDE will not find that syntax error can be reported, therefore pass through above-mentioned code keywords Use, in a certain sense cause re-define and can be received by existing IDE so that code energy Enough according to different platforms, different compiled codes are generated.
In the embodiment of the present invention, the Grammar section includes first and starts keyword, terminates keyword, N number of selection key Word, N are the integer more than or equal to 2.In the embodiment of the present invention, selection keyword is elseif keywords.
N number of selection keyword is programmed between the beginning keyword and the end keyword;The precompile Code segment includes first code section and N number of subcode section;
Starting behind keyword and N number of selection keyword, corresponding conditional statement, the N+1 bars are encoded with respectively Part sentence meets as genuine condition non-overlapping copies respectively;
The semanteme of the first beginning keyword includes:Thereafter corresponding conditional statement is judged, and according to judgement As a result corresponding first code section is handled;
The semanteme for terminating keyword includes:Used cooperatively with the corresponding first beginning keyword, for identifying correspondence The first end for starting keyword and N number of selection keyword effective range;
The precompile code segment in the Java source files be identified including:
According to the first position for starting keyword and next selection keyword, the corresponding condition of keyword is started by first Sentence between sentence and next selection keyword is identified as first code section;For last of N number of selection keyword, The corresponding conditional statement of the selection keyword and the sentence terminated between keyword are identified as the selection keyword correspondence Subcode section;For others selection keyword, the corresponding conditional statement of keyword and next selection will be currently selected to close Sentence between key word is identified as currently selecting the corresponding subcode section of keyword;
The judged result according to the platform information, at the precompile code segment in the Java source files Reason also includes:
When reading the first beginning keyword, conditional statement corresponding to the first beginning keyword judges, if The judged result of conditional statement is true, then performs reservation process to the first code section after the conditional statement, and to other Subcode section performs shielding processing;
If the judged result of conditional statement is false, the first code section after the conditional statement is performed at shielding Reason, and continue to judge the corresponding conditional statement of next selection keyword,
It is described that the corresponding conditional statement progress judgement of next selection keyword is specifically included:If the selection is crucial The judged result of the corresponding conditional statement of word is true, then performs reservation process to the subcode section after the conditional statement, and Shielding processing is performed to other subcodes section between next selection keyword and end keyword;If the selection is crucial The judged result of the corresponding conditional statement of word is false, then performs shielding processing to the conditional statement corresponding subcode section, and Continue to judge the corresponding conditional statement of next selection keyword, until having judged all selection keywords, and examine End keyword is measured, then is terminated.
Above-mentioned selection keyword is illustrated with reference to a specific example.For example, Java source files include Following paragraph:
Wherein, ifdef judges keyword for first, i.e., first starts one kind of keyword, and elseif is selection keyword, Endif is terminates keyword, and Test, Test2 and Test3 are conditional statement, and JavaCode1 is conditional statement corresponding first Code segment, JavaCode2 and JavaCode3 are the corresponding subcode section of selection keyword, during precompile, pre compiler Conditional statement Test, Test2 and Test3 are judged, and according to judged result to JavaCode1, JavaCode2 and JavaCode3 carries out reservation or the shielding processing of selectivity.
Precompile keyword provided in an embodiment of the present invention can nesting use.For example, the first beginning keyword is corresponding In first code section, or second starts in keyword corresponding second code section, nested first can be started using another Keyword, if nesting occurs in keyword, outermost first beginning keyword and outermost end keyword make for cooperation Keyword, the first of internal layer start keyword and internal layer terminate keyword be with the use of keyword.For nesting The keyword used in internal layer, only according to the judged result of the conditional statement of the keyword of outer layer, when the keyword institute of internal layer The row for needing to retain in behavior, the keyword of internal layer is expert at and can just carry out corresponding precompile processing.When the pass according to outer layer The judged result of the conditional statement of key word, when behavior needs the row shielded where the keyword of internal layer, the bar of the keyword of internal layer Part sentence be will not work, i.e. the keyword of internal layer is expert at and its corresponding code segment is all shielded.With reference to one Specific example is illustrated
Here is the nested example of a condition
Wherein, ifdef judges keyword for first, i.e., first starts one kind of keyword, and else is that the second beginning is crucial Word, endif for terminate keyword, the ifdef keywords of outer layer, else keywords, endif keywords be with the use of key Word, the ifdef keywords of internal layer, else keywords, endif keywords be with the use of keyword.Test1 and Test2 are equal For conditional statement, if ifdef Test1 are false, JavaCode1 and JavaCode2 can be shielded, and JavaCode3 can be protected Stay.If ifdef Test1 are true, it is necessary to see ifdef Test2 result, protected if ifdef Test2 are true JavaCode1 Stay, JavaCode2 shieldings, if ifdef Test2 are false JavaCode1 shieldings, JavaCode2 retains.
It should be noted that each precompile keyword defined above and corresponding semanteme are exemplary illustration, in advance Compiler as needed, can increase the definition of corresponding precompile keyword, and precompile defined above can be selected crucial One or more in word, to perform the precompile of Java source files.
It should be noted that in the embodiment of the present invention, each is stored in the way of platform information is beforehand through macrodefinition It is illustrated exemplified by mode in the corresponding header file of platform, accordingly, the judgement of conditional statement includes believing macrodefinition The judgement of breath, in addition, when the corresponding information of target platform is stored in the alternative document of xml document etc, it is flat in order to realize The judgement of station information, the judgement of conditional statement will use other corresponding modes, i.e., carried from the alternative document of xml document etc Make even station information data, and judged accordingly.
In the prior art, for two platform (operating system) S1 and S2, in order to realize an API class j1.Java, need Different Java source files are write for S1 and S2, and are saved in different positions respectively, different code bags are formed, for example For S1 platforms, code bag is saved under APIS1/src/j, Java, Java catalogues, for S2 platforms, code bag preserved To APIS2/src/j, Java, under Java catalogues, the source code under needing to select different directories in compiling, compiler is compiled respectively Translate the correspondence of class under different class files j1.class, different catalogues different platform S1 and S2, different class File can be run in the different virtual machines corresponding to each platform.For the j1.Java files under different directories, due to It is to realize that duplicated code is more, it is necessary to take more memory space, most in identical API classes, two j1.Java files Importantly, if necessary to be modified to API classes, it is necessary to file j1.Java files under different directories are respectively modified, work Amount is larger, difficult in maintenance.
By java applet precompile method provided in an embodiment of the present invention, when realizing an API class j1.Java, no Need to write different Java source files for platform S1 and S2, it is only necessary to write a source code j1.Java, and be saved in same In one catalogue, such as API/src/j, Java, the pre compiler that the present embodiment is provided carries out precompile to source code j1.Java, For two platforms S1 and S2, each self-corresponding precompile file is respectively obtained, precompile file is similarly the entitled Java of suffix Java source files, i.e., after precompile, respectively obtain the corresponding j1.Java files of S1 and S2, compiling system is according to corresponding Java source files j1.Java, which is compiled, obtains the corresponding j1.class operations in corresponding virtual machine respectively.For difference Platform (operating system), when realizing identical API classes, it is only necessary under a catalogue store a Java source file, no Memory space can be saved, furthermore, it is necessary to when being modified to API classes, it is not necessary to repair respectively because being stored under different directories Change the file j1.Java files under different directories, it is only necessary to a Java source file is modified, workload is smaller so that Code administration is more succinct and efficient.
Compilation Method is provided in the embodiment of the present invention to be particularly suitable for use in the implementation process of API classes, by precompile process, The process differentiated in Java source files by the grammer of condition judgment to platform information is realized, so that by differentiating result Retain or shield corresponding code segment, it is achieved thereby that for different platforms, different precompile files are generated, in API In the implementation process of class, there are more strict requirements to the type function in Java source files, by precompile process, in reality While now differentiation to platform information, it is not necessary to increase the type function in Java source files, while so that size of code most It is small, because under some platform, if precompile code segment is the code that need not be performed, then due to precompile Journey, will not generate the code segment in corresponding precompile file and compiling file so that the occupancy of system resource reaches minimum.
Based on the same or analogous design of above method embodiment, the embodiment of the present invention also provides a kind of pre compiler, The pre compiler carries out precompile to Java source files, and generates precompile file corresponding with the Java source files, institute It is the file that can be compiled by existing compiler to state precompile file;Wherein, the pre compiler is according to above-mentioned A kind of java applet precompile method carries out precompile to Java source files.
Referring to Fig. 2, being the structural representation of pre compiler provided in an embodiment of the present invention, as shown in Fig. 2 described prelist Translating device includes:
Acquisition module 10, for according to target platform, obtaining the corresponding platform information of the target platform;.
Scan module 20, for being scanned to Java source files, recognizes that the precompile in the Java source files is crucial Word, and obtain the corresponding semanteme of precompile keyword;
Processing module 30, it is corresponding to the target platform flat for according to the corresponding semanteme of the precompile keyword Station information is judged, and the precompile code segment in the Java source files is identified, and is believed according to the platform The judged result of breath, is handled the precompile code segment in the Java source files;
Output module 40, for according to the result handled the precompile code segment in the Java source files, holding Precompile process of the row to the Java source files.
Based on the same or analogous design of above method embodiment, basic procedure of the embodiment of the present invention to pre compiler It is described.During precompile, pre compiler is progressively scanned to the code in Java source files, and according to current defeated It is true or false to do well, and optionally current line correspondence is output in output file, or shielding current line, that is, Corresponding blank line is set up in output file, after the scanning of all rows in Java source files is completed, output file is exactly The corresponding precompile file of Java source files, wherein, Java source files are the file for including Java source files, and precompile file is Include the file of precompile file.Referring to Fig. 3, the schematic diagram of precompile process is performed for pre compiler, as shown in figure 3, in advance Compiler, which performs precompile process, to be included:
Step S201, scanning PCH, and extract macrodefinition information all in the PCH.Should In step, all macrodefinition information will be stored in the Hash table of inside in PCH, facilitate pre compiler to perform Read at any time during precompile.
Step S202, reading one treat the Java source files of precompile.
Step S203, a line read in file, whether be a precompile keyword, if it is, jumping if searching for the row Step S205 is gone to, if it is not, then continuing executing with step S204.
Step S204, according to current output state will correspondence row content export, wherein, if current output state is Very, then correspondence row is exported, if current output state is false, shielding correspondence row.
Wherein, the initial value of output state is true, and output state will will be according to precompile keyword pair with pre compiler The processing answered, carries out the switching between true and false.
Step S205, the Grammar section according to precompile keyword, are transferred to the corresponding processing module of compiling keyword.
In step S205, pre compiler is sentenced according to corresponding processing module function calculating precompile condition, pre compiler The Grammar section of disconnected precompile keyword, carries out the switching between true and false, so as to the precompile code to output state Duan Jinhang is optionally shielded or reservation process.
Specifically, in step S205, if pre compiler judges that the Grammar section of precompile keyword starts for first Keyword, then carry out first and start in the corresponding processing module of keyword, the module, and pre compiler will safeguard a condition calculating As a result storehouse, after calculating the corresponding conditional statement of the first beginning keyword, is stored in storehouse, such as by result of calculation Fruit result of calculation is non-zero value, then is set to current output state very, if result of calculation is 0 value, by current output state It is set to false as.In view of nested realization, it is necessary to check the data of last stacking before result is put into storehouse, that is, on The judged result of layer keyword, if upper strata is false, subsequently enters all vacations of stack state, and independent of lower floor's result of calculation, such as Fruit upper strata is true, and follow-up stacking is defined by lower floor's result.
If pre compiler judges the Grammar section of precompile keyword for else keywords, into else keywords correspondence Processing module, the module ejects the state in current stack first, if true, and this is converted to vacation;If vacation, then upper strata is seen State, if upper strata is false, continue as vacation, if true, invert current state, i.e., be really changed into vacation, vacation is changed into true;Finally The state newly calculated is put into storehouse.
If pre compiler judges the Grammar section of precompile keyword for endif keywords, into endif keywords In corresponding processing module, the module, pre compiler takes out result of calculation from the storehouse of condition calculation results, if take out Result of calculation is last result of calculation in storehouse, no matter then result of calculation is 0 value or non-zero value, all will currently export shape State is set to very, if the result of calculation taken out continues to read next calculating knot to be not last result in storehouse The value (the namely result of calculation of stack) of fruit, if the result of calculation is non-zero value, current output state is set to Very, if the result of calculation is 0 value, current output state is set to false as.According to above-mentioned setting, the first beginning can be supported The nesting of keyword is used.
If pre compiler judges the Grammar section of precompile keyword for code keywords, into code keywords pair In the processing module answered, the module, if current output state is set to very, remove mask information, if currently exporting shape State is set to false as, then shields correspondence row.
If pre compiler judges that the Grammar section of precompile keyword, for excludeFile keywords, enters In the corresponding processing module of excludeFile keywords, the module, pre compiler is according to current output state, if current defeated It is true to do well, then deletes the corresponding output file of current Java source files, and continue with the pre- of next Java source files Flow is compiled, if current output state is set to false as, current line is shielded, and continue step S206.
In the case of the excludeFile keywords defined in pre compiler, if according to excludeFile keywords Implementing result delete corresponding output file, that is, abandon the Java source files, that is, do not compile and run and be current Java source files, here it is " terminating in advance " in Fig. 3 after step S205, that is, content in dotted line frame is to define It is likely to occur in the case of excludeFile keywords.There is no the feelings for defining excludeFile keywords in pre compiler Under condition, usual step S205 will continue S206 after terminating.
Step S206, with the presence or absence of next line;If it is, step S203 is jumped to, if it is not, then continuing executing with step S207;
Step S207, with the presence or absence of next Java source files;If it is, step S202 is jumped to, if it is not, then knot Beam precompile process.
Based on the same or analogous design of above method embodiment, the embodiment of the present invention also provides a kind of pre compiler, The pre compiler carries out precompile according to the precompile process shown in Fig. 3 to Java source files, and generates corresponding precompile File.The precompile file of pre compiler generation can perform compilation process by existing compiler, and generate corresponding volume Translate code.
It is understood that the principle that embodiment of above is intended to be merely illustrative of the present and the exemplary implementation that uses Mode, but the invention is not limited in this.For those skilled in the art, the essence of the present invention is not being departed from In the case of refreshing and essence, various changes and modifications can be made therein, and these variations and modifications are also considered as protection scope of the present invention.

Claims (12)

1. a kind of java applet precompile method, it is characterised in that the java applet precompile method includes:
According to target platform, the corresponding platform information of the target platform is obtained;
Java source files are scanned, the precompile keyword in the Java source files is recognized, and it is crucial to obtain precompile The corresponding semanteme of word;The precompile keyword includes designator part and Grammar section, and the designator part includes annotation Symbol and predetermined mark character;The designator part is the prefix of the Grammar section;Or, the designator part includes two Point, the prefix and suffix of respectively described Grammar section;
Precompile keyword in the identification Java source files, and obtain the corresponding semanteme of precompile keyword and include: According to the designator part of precompile keyword, precompile keyword is identified, and by Grammar section, obtains precompile The corresponding semanteme of keyword;According to the corresponding semanteme of the precompile keyword, platform information corresponding to the target platform Judged, and the precompile code segment in the Java source files is identified, and sentencing according to the platform information Disconnected result, is handled the precompile code segment in the Java source files;Precompile generation in the source file to Java Code section, which carries out processing, includes following any or its any combination:
Optionally shielding or reservation process are carried out to the precompile code segment;
Comment line is converted into code line;
Abandon generating corresponding precompile file;
According to the result handled the precompile code segment in the Java source files, perform to the Java source files Precompile process.
2. the method as described in claim 1, it is characterised in that
It is described according to target platform, obtaining the corresponding platform information of the target platform includes:The corresponding head of invocation target platform File, reads all macrodefinition information from the header file;Wherein, the corresponding platform information of different platform is beforehand through grand The mode for defining information is stored in the corresponding header file of each platform;
It is described according to the corresponding semanteme of the precompile keyword, platform information corresponding to target platform carries out judging specific Including:
According to the semanteme of precompile keyword, the judgement to macrodefinition information is performed, and sentence according to the macrodefinition information It is disconnected, realize the judgement to the platform information of target platform.
3. the method as described in claim 1, it is characterised in that the precompile file of the Java source files and corresponding generation it Between follow predetermined precompile rule, the precompile rule includes following any or its any combination:
Bag title in the precompile file is consistent with the bag title in the Java source files;
Class name in the precompile file is consistent with the class name in the Java source files;The precompile file In code line number be consistent with the code line number in the Java source files;
The precompile keyword is programmed in the way of annotating word in the Java source files.
4. the method as described in claim 1, it is characterised in that the Grammar section includes first and starts keyword, terminates to close Key word;The precompile code segment includes first code section;Conditional statement is encoded with behind the described first beginning keyword,
The semanteme of the first beginning keyword includes:Corresponding judgement is carried out to conditional statement thereafter, and is tied according to judgement Fruit is handled first code section thereafter;
The semanteme for terminating keyword includes:Used cooperatively with the corresponding first beginning keyword, for identifying corresponding the The end of keyword effective range at the beginning;
The precompile code segment in the Java source files be identified including:Start keyword and end according to first The position of keyword, first code section is identified as by the sentence between the conditional statement and the end keyword;
The judged result according to the platform information, processing bag is carried out to the precompile code segment in the Java source files Include:When reading the first beginning keyword, the conditional statement after the first beginning keyword is judged, if condition language The judged result of sentence is true, then performs reservation process to first code section, if the judged result of conditional statement is false, Shielding processing is performed to first code section.
5. method as claimed in claim 4, it is characterised in that
The first beginning keyword judges keyword including first, and the conditional statement is that the first macro name accords with string,
Described first judges that the semanteme of keyword includes:Whether it is that the macrodefinition existed judges to conditional statement thereafter;
The conditional statement to after the first beginning keyword, which carries out judgement, to be included:
Judge whether the first macro name symbol string is pre-defined grand name, if first macro name symbol string is pre-defined Grand name, then the judged result of decision condition sentence is true;If the first macro name symbol string is not pre-defined grand name, The judged result of decision condition sentence is false.
6. method as claimed in claim 4, it is characterised in that
The first beginning keyword judges keyword including second, and the conditional statement is that the first macro name accords with string,
Described second judges that the semanteme of keyword includes:Whether it is that non-existent macrodefinition is sentenced to conditional statement thereafter It is disconnected;
The conditional statement to after the first beginning keyword, which carries out judgement, to be included:Judge whether the first macro name symbol string is pre- The grand name first defined, if first macro name symbol string is not pre-defined grand name, the judgement knot of decision condition sentence Fruit is true;If the first macro name symbol string is pre-defined grand name, the judged result of decision condition sentence is false.
7. method as claimed in claim 4, it is characterised in that the first beginning keyword judges keyword including the 3rd,
Described 3rd judges that the semanteme of keyword includes:Value to conditional statement thereafter carries out the judgement of zero-sum non-zero;
The conditional statement to after the first beginning keyword, which carries out judgement, to be included:
When the conditional statement is the second character string;Second character string is judged, if second character string It is worth for nonzero value, then the judged result of decision condition sentence is true;If the value of second character string is null value, bar is judged The judged result of part sentence is false;And/or,
The conditional statement is second when comparing sentence, wherein described second compare sentence including the first variable, comparison operators and Second variable, compares sentence to described second and judges, if the relation between first variable and the second variable meets The description of the comparison operators, then the judged result of decision condition sentence is true;If between first variable and the second variable Relation do not meet the description of the comparison operators, then the judged result of decision condition sentence is false.
8. the method as described in claim 5~7 is any, it is characterised in that the Grammar section also includes second and starts key Word, the precompile code segment also include second code section;
The second beginning keyword is programmed between the first code section and the end keyword;
The semanteme of the second beginning keyword includes:Used cooperatively with the corresponding first beginning keyword, for according to first Start the judged result of the conditional statement of keyword thereafter, the place opposite with first code section is carried out to second code section Reason;
The precompile code segment in the Java source files, which is identified, also to be included:By described second start keyword and Code segment between the end keyword is identified as second code section;
The judged result according to the platform information, carries out handling also to the precompile code segment in the Java source files Including:After the conditional statement after to the first beginning keyword judges, if the judged result of the conditional statement It is true, then shielding processing is performed to second code section, if the judged result of conditional statement is false, to the second generation Code section performs reservation process.
9. method as claimed in claim 4, it is characterised in that the Grammar section also includes excluding keyword,
The exclusion keyword is programmed between the conditional statement and the end keyword;
The semanteme for excluding keyword includes:Shielding processing is carried out to Java source files;
The judged result according to the platform information, carries out handling also to the precompile code segment in the Java source files Including:After the conditional statement after to the first beginning keyword judges, if according to the judged result of conditional statement, It is determined that in the case that behavior needs the row of reservation where excluding keyword, then according to the presence of the exclusion keyword, abandoning life Into corresponding precompile file, if the judged result of conditional statement is false, retain whole code lines in Java source files.
10. method as claimed in claim 4, it is characterised in that the Grammar section also includes code and indicates keyword,
The code indicates that keyword is programmed between the conditional statement and the end keyword;
The code indicates that the semanteme of keyword includes:Comment line is converted into normal codes row;
The judged result according to the platform information, carries out handling also to the precompile code segment in the Java source files Including:After the conditional statement after to the first beginning keyword judges, if according to the judged result of conditional statement, In the case of determining that code indicates that keyword place behavior needs the row of reservation, then keyword is indicated according to code, code is referred to Show that keyword and corresponding designator part are removed.
11. the method as described in claim 1, it is characterised in that the Grammar section includes first and starts keyword, terminates to close Key word and N number of selection keyword, N are the integer more than or equal to 2;
N number of selection keyword is programmed between the beginning keyword and the end keyword;The precompile code Section includes first code section and N number of subcode section;
Starting behind keyword and N number of selection keyword, corresponding conditional statement, the N+1 conditions language are encoded with respectively It is genuine condition non-overlapping copies that sentence is met respectively;
The semanteme of the first beginning keyword includes:Thereafter corresponding conditional statement is judged, and according to judged result Corresponding first code section is handled;
The semanteme for terminating keyword includes:Used cooperatively with the corresponding first beginning keyword, for identifying corresponding the The end of keyword and N number of selection keyword effective range at the beginning;
The precompile code segment in the Java source files be identified including:
According to the first position for starting keyword and next selection keyword, the corresponding conditional statement of keyword is started by first Sentence between next selection keyword is identified as first code section;For last of N number of selection keyword, by institute The sentence stated the corresponding conditional statement of selection keyword and terminated between keyword is identified as the corresponding son of the selection keyword Code segment;For others selection keyword, the corresponding conditional statement of keyword and next selection keyword will be currently selected Between sentence be identified as currently selecting the corresponding subcode section of keyword;
The judged result according to the platform information, carries out handling also to the precompile code segment in the Java source files Including:
When reading the first beginning keyword, conditional statement corresponding to the first beginning keyword judges, if condition The judged result of sentence is true, then performs reservation process to the first code section after the conditional statement, and to other filial generations Code section performs shielding processing;
If the judged result of conditional statement is false, shielding processing is performed to the first code section after the conditional statement, And continue to judge the corresponding conditional statement of next selection keyword,
It is described that the corresponding conditional statement progress judgement of next selection keyword is specifically included:If the selection keyword pair The judged result for the conditional statement answered is true, then performs reservation process to the subcode section after the conditional statement, and under One selection keyword and other subcodes section terminated between keyword perform shielding processing;If the selection keyword pair The judged result for the conditional statement answered is false, then performs shielding processing to the conditional statement corresponding subcode section, and continue Conditional statement corresponding to next selection keyword judges, until having judged all selection keywords, and detects Terminate keyword, then terminate.
12. a kind of pre compiler, it is characterised in that the pre compiler includes
Acquisition module, for according to target platform, obtaining the corresponding platform information of the target platform;
Scan module, for being scanned to Java source files, recognizes the precompile keyword in the Java source files, and obtain Take the corresponding semanteme of precompile keyword;The precompile keyword includes designator part and Grammar section, the designator Part includes annotation symbol and predetermined mark character;The designator part is the prefix of the Grammar section;Or, the designator Part includes two parts, the prefix and suffix of respectively described Grammar section;
Precompile keyword in the identification Java source files, and obtain the corresponding semanteme of precompile keyword and include: According to the designator part of precompile keyword, precompile keyword is identified, and by Grammar section, obtains precompile The corresponding semanteme of keyword;Processing module, for according to the corresponding semanteme of the precompile keyword, to the target platform pair The platform information answered is judged, and the precompile code segment in the Java source files is identified, and according to described The judged result of platform information, is handled the precompile code segment in the Java source files;It is described to Java source files In precompile code segment carry out processing include it is following any or its be combined:
Optionally shielding or reservation process are carried out to the precompile code segment;
Comment line is converted into code line;
Abandon generating corresponding precompile file;
Output module, for according to the result handled the precompile code segment in the Java source files, performing to institute State the precompile process of Java source files.
CN201510018651.8A 2015-01-14 2015-01-14 A kind of java applet precompile method and pre compiler Active CN104536797B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510018651.8A CN104536797B (en) 2015-01-14 2015-01-14 A kind of java applet precompile method and pre compiler

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510018651.8A CN104536797B (en) 2015-01-14 2015-01-14 A kind of java applet precompile method and pre compiler

Publications (2)

Publication Number Publication Date
CN104536797A CN104536797A (en) 2015-04-22
CN104536797B true CN104536797B (en) 2017-10-27

Family

ID=52852329

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510018651.8A Active CN104536797B (en) 2015-01-14 2015-01-14 A kind of java applet precompile method and pre compiler

Country Status (1)

Country Link
CN (1) CN104536797B (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106547527B (en) * 2015-09-22 2020-01-21 阿里巴巴集团控股有限公司 JavaScript file construction method and device
CN105511935B (en) * 2015-12-09 2019-07-09 网易(杭州)网络有限公司 The acquisition methods and device of resource index value
CN106445625A (en) * 2016-09-23 2017-02-22 网易(杭州)网络有限公司 Preprocessing method and device of to-be-compiled codes
CN106843996A (en) * 2017-03-08 2017-06-13 百富计算机技术(深圳)有限公司 Conditional compilation preprocess method and device
CN109840133A (en) * 2017-11-29 2019-06-04 北京高德云图科技有限公司 The operation method and device of application function
CN108563442A (en) * 2018-02-28 2018-09-21 北京智行鸿远汽车有限公司 Code compiling method and device
CN109117182B (en) * 2018-08-29 2022-03-08 赛尔网络有限公司 Detection method, equipment, system and medium for supporting IPv6 degree based on source code
CN109977043B (en) * 2019-03-22 2021-06-22 北京三快在线科技有限公司 Interface preheating method and device, electronic equipment and storage medium
CN110377276B (en) * 2019-07-19 2023-05-23 潍柴动力股份有限公司 Source code file management method and device
CN111190585B (en) * 2019-12-12 2023-05-02 杭州安恒信息技术股份有限公司 Method for realizing JAVA mode matching characteristic based on byte code enhancement technology
CN111142935A (en) * 2019-12-31 2020-05-12 奇安信科技集团股份有限公司 Method, apparatus, computer system, and medium for cross-platform running of applications
CN111552479A (en) * 2020-05-06 2020-08-18 湖南国科微电子股份有限公司 Mirror image file compiling method and device and electronic equipment
CN112685049B (en) * 2021-01-22 2024-02-13 大连高德瑞信科技有限公司 JAVA byte code compiling method
CN115904393B (en) * 2023-01-05 2023-06-30 拉扎斯网络科技(上海)有限公司 Condition compiling realization method, device, medium and equipment
CN117172203A (en) * 2023-09-07 2023-12-05 芯华章科技股份有限公司 Method for processing script command, electronic device and storage medium
CN117406996B (en) * 2023-10-20 2024-04-16 北京市辰至半导体科技有限公司 Semantic analysis method and device for hardware description code

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1542616A (en) * 2003-04-10 2004-11-03 松下电器产业株式会社 Compiler, program prduct, compilation device, communication terminal device, and compilation method
CN1751291A (en) * 2003-02-18 2006-03-22 株式会社爱可信 Native compile method, native compile preprocessing method, computer program, and server
CN103713902A (en) * 2013-12-26 2014-04-09 Tcl集团股份有限公司 Method and system for BOA compiling based on Android system
CN103729235A (en) * 2013-12-24 2014-04-16 华为技术有限公司 Java virtual machine (JVM) and compiling method thereof

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8307350B2 (en) * 2009-01-14 2012-11-06 Microsoft Corporation Multi level virtual function tables
US8903702B2 (en) * 2011-08-31 2014-12-02 International Business Machines Corporation Generating specifications for expression language expressions and tag libraries

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1751291A (en) * 2003-02-18 2006-03-22 株式会社爱可信 Native compile method, native compile preprocessing method, computer program, and server
CN1542616A (en) * 2003-04-10 2004-11-03 松下电器产业株式会社 Compiler, program prduct, compilation device, communication terminal device, and compilation method
CN103729235A (en) * 2013-12-24 2014-04-16 华为技术有限公司 Java virtual machine (JVM) and compiling method thereof
CN103713902A (en) * 2013-12-26 2014-04-09 Tcl集团股份有限公司 Method and system for BOA compiling based on Android system

Also Published As

Publication number Publication date
CN104536797A (en) 2015-04-22

Similar Documents

Publication Publication Date Title
CN104536797B (en) A kind of java applet precompile method and pre compiler
CN112100054B (en) Data management and control oriented program static analysis method and system
CN104899147B (en) A kind of code Static Analysis Method towards safety inspection
CN110414261B (en) Data desensitization method, device, equipment and readable storage medium
US9823902B2 (en) Editing source code
JP4783289B2 (en) Program generation device, program test device, program execution device, and information processing system
CN103413075B (en) A kind of method and apparatus of protecting JAVA executable program by virtual machine
CN106843840B (en) Source code version evolution annotation multiplexing method based on similarity analysis
Miecznikowski et al. Decompiling Java using staged encapsulation
CN107092518A (en) A kind of Compilation Method for protecting mimicry system of defense software layer safe
CN107632832B (en) Dalvik byte code oriented control flow confusion method
CN1983295A (en) Method and device for recognizing virus
CN102375778A (en) Method and system for automatically testing digital signal processor (DSP)
EP3495978A1 (en) Method for detecting vulnerabilities in software
CN108664471A (en) Text region error correction method, device, equipment and computer readable storage medium
CN111459500A (en) Safety compiling method and device based on sea eagle wing brightness operating system
CN103559125A (en) Method for verifying compiler by graph isomorphism
CN108897678B (en) Static code detection method, static code detection system and storage device
JP5038760B2 (en) Source code conversion apparatus and source code conversion method
CN113805861B (en) Code generation method based on machine learning, code editing system and storage medium
CN111796832B (en) Hot patch file generation method, device, equipment and storage medium
CN114282227B (en) Safety analysis and detection method for intelligent contract of Fabric block chain system
CN114266020A (en) Software protection method, device, equipment and readable storage medium
CN112114809B (en) Program code safety protection method, device and storage medium
KR20090011974A (en) Method for extracting the target files of compilation

Legal Events

Date Code Title Description
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant