Background technology
Conventional language (as COBOL, FORTRAN etc.) is from the existing till now nearly 50 years history that is born.Existing a large amount of commercializations and scientific program adopt these conventional language to write.The program of moving in bank, security and insurance at present has and manyly is born in that period.According to incompletely statistics, about 1,000 hundred million line codes are write with conventional language COBOL.Because modern languages has substituted conventional language with its superiority, seldom there is the software practitioner to go study and use conventional language, therefore just become legacy code with these language institute written program.Caused series of problems thus, first problem is the maintenance of legacy code, the programmer who only has at present only a few to understand conventional language removes to safeguard a large amount of legacy codes, be undoubtedly a huge burden, and will there be more programming language replaced along with the continuation of newspeak produces, also just be transformed into new legacy code by the program of these language compilation.As time goes on, the kind of legacy code and quantity can constantly increase, and safeguard that the burden of legacy code will be increasing, cause at last and can't bear.A good method safeguarding legacy code is that legacy code is translated into modern languages.Second problem, the existence of legacy code has influenced the interoperability of software.The new software that the employing modern languages is write and the old software of same industry are owing to adopt different programming languages, add the programmer of new software and mostly conventional language is unfamiliar with, thereby cause the link between the new and old software and become a new technology barrier alternately.The 3rd problem is the cross-platform migration that is unfavorable for code.It no longer is the machine of a platform independent that the appearance of computer network makes computing machine, but the ingredient of whole information network.Various computing machines dissimilar, different platform have been formed complicated system, how to make this system give full play to its effect, are the problems that present gridding technique is studied.Can one cover software cross-platform work determine whether it has stronger vitality.For code is moved smoothly, so produced the programming language of the platform independence as Java .Net.Adopt this category code written program, can on each platform, move substantially unfetteredly.Therefore, seeking a kind of legacy code to be changed into the technology of modern languages, is the code migration, makes old code shine a trial highly significant of new vigor.
At present, many research institutions and company have all carried out the research of this respect, as Saint-Petersburg State University, SoftwareMining, Corporola, LegacyJ Corporation, Micro-Processor Service or the like.Because Common business Oriented Language is born early, the quantity of its legacy code is big, and bigger with the grammatical and semantic difference of modern languages, therefore selects it as a typical conventional language.Java then is a kind of typical modern languages, and it also provides support to cross-platform except the characteristics that possess other modern languages, and has abandoned the statement that influences program construction.Compare the disparity of Java and conventional language with other modern languagess.Therefore, code transforms more options COBOL and the typical research object of Java conduct.
Modern languages is not advocated use GOTO statement for pursuing program construction, even some new language (as Java) no longer provide this statement.But those are born in a large amount of GOTO of use statements in the early stage legacy code of computing machine development, even in the code of Common business Oriented Language, have also used the PERFORM statement in a large number except that the GOTO statement.Therefore when these legacy codes are translated into modern languages, these control stream statements must be eliminated by equivalence transformation.
The method that present document and some research institutions release can be divided into two classes:
(1) analyzes by control stream, GOTO is changed into circulation, realize these circulations with the while statement of modern languages again legacy code.Though this method can realize eliminating GOTO and PERFORM statement effectively, has changed the structure of program, the code after the conversion is readable poor.In addition, for GOTO and the transfer of PERFORM structure from complexity dissolve corresponding circulation, need carry out copying codes in case of necessity, thereby cause the expansion of code, the average ratio that causes of these class methods is one or two order of magnitude after tested.Language as Java has restriction to the code total amount in the function, and too the code of Peng Zhanging may cause function excessive and can't carry out.
(2) adopt the function recurrence to simulate GOTO and PERFORM statement.An evident characteristic of this method is to utilize the Recursive Implementation circulation, and for the more structure of cycle index, thereby may cause dark recurrence to make storehouse can't bear to cause overflows, and causes the unexpected termination of program implementation.In addition, these class methods have also been destroyed the structure of program, and the programmed readability after the conversion is poor.
Because the GOTO statement has influenced the structuring of program, there is the people how to eliminate the GOTO statement for many years in research always, and many methods have been proposed, but the composite structure that PERFORM and GOTO statement form in the very suitable Common business Oriented Language of these methods, programmed readability after the conversion is relatively poor, the expansivity height of code.
Summary of the invention
The technical problem to be solved in the present invention provides the control rheology of a kind of legacy code in the modern languages conversion process and changes method, eliminate " goto " and " perform " statement in the conventional language, when guaranteeing programmed readability, controlled the expansivity of code preferably.
For solving the problems of the technologies described above, the invention provides the control rheology of a kind of legacy code in the modern languages conversion process and change method, may further comprise the steps:
A) process with cobol program converts a java class to;
B) set up an entrance function in above-mentioned java class, this function parameters tabulation is corresponding to the parameter list of former COBOL process;
C) set up the content of entrance function, comprise a compound statement in the entrance function, be used for that another is carried out function and call, and catch the exception that described execution function is dished out when end of run, described execution function is used to realize the procedure body of COBOL process;
D) the section name among the COBOL is numbered;
E) the procedure body structure is carried out following processing: whole procedure is placed a circulation carrying out function, a switch statement is set in loop body, with label variable as switch redirect condition, wherein every case clause of switch statement corresponding to a segment labeling in the cobol program, the code of its back is corresponding to the content of a section successively;
F) check statement in each COBOL section,, execution in step g then if run into the GOTO statement), if run into the PERRORM statement, execution in step h then); If at the end of cobol program section, execution in step i then);
G) the GOTO statement is handled: give the label variable of switch statement with the numbering of the object statement of the redirect of wanting in the GOTO statement, finish the execution of current switch statement then;
H) the PERFORM statement is handled: the execution function described in the recursive call step c), this function with the pairing segment number in former PERFORM statement entry and exit as first parameter, with the parameter list of former COBOL process as second parameter;
I) judge the numbering whether stomion equals this cobol program section at each section tail, if then withdraw from entrance function.
In such scheme, be used as the inlet of whole C OBOL process with a specific entrance function, simulate the process of COBOL with function in the modern languages, described specific entrance function comprises three parameters, it is respectively the parameter of entrance, exit point and former Common business Oriented Language self, whole process is translated into a structure that is combined by loop statement and switch statement, and the corresponding case statement of each COBOL section determines whether withdrawing from function with condition judgment.
In such scheme, realize the semanteme of PERFORM with the recursive call of Java subfunction self, represent the scope of PERFORM statement by two parameters.
In such scheme, carry out described in the described step c) to comprise with entrance function in the function parameters tabulation and have function list of the same name, also increased by two parameter entrances and exit point in front.
In such scheme, the inlet when described entrance parameter is carried out as the PERFORM statement, described exit point parameter is carried out the outlet of object as the PERFORM statement.
In such scheme, in the step d),, be numbered statement to the last downwards, numbering of increase before EOP (end of program) from 0 successively from first section of cobol program.
In such scheme, eliminate GOTO and PERFORM compound control structure simultaneously with the switch and the loop statement of higher level lanquage.
As from the foregoing, method is changed in a kind of control rheology provided by the invention, has kept programmed readability, and has controlled the code expansion preferably.
Embodiment
Describe technical scheme of the present invention in detail below in conjunction with accompanying drawing and following examples.
When needs are translated into modern languages Java with legacy code (cobol program), need will be in the Common business Oriented Language exist and PERFORM and GOTO statement that Java language can't be represented are eliminated, so that code translation successfully.
The present invention comes PERFORM and GOTO statement among the emulation COBOL with existing control stream statement Switch and while statement among the Java.
The effect of GOTO statement is identical with GOTO statement in the C language among the COBOL, exactly control changed over to another position in the process.
The PERFORM statement be statement with two kinds of functions, on the one hand it is equivalent to a loop statement, carries out the circulation object under certain cycling condition.It has calling function on the other hand, calls certain joint or several joint and carries out, and its basic syntax structure as shown in Figure 1.Analyze this and seem to be complicated structure, we are not difficult to find, no matter are PERFORM_until, PERFORM_varying or PERFORM_times, and its difference mainly is the control to cycling condition.We can realize this point with the while statement in the Java language like a cork.
The PERFORM statement is in Java conversion, and its maximum problem is not the round-robin conversion, but PERFORM is to being performed the method for calling of object, and this mode and GOTO statement combine formed compound control structure.In order can clearly to say something, we erase circulation, analyze its method of calling merely.
Referring to Fig. 2, in the section L1 PERFORM statement is arranged, this statement has a Through clause, and its semanteme is when condition condition-1 sets up, and from carrying out section L1 to L3 (comprising the section that L3 is indicated), carries out before the L4, returns this PERFORM statement.Two GOTO statements are arranged, respectively the section of jumping to L0 and section L1 in section L2.First redirect statement is redirect forward, has in fact constituted a cycle control stream.Second then is redirect backward, if the PERFORM L1 thru L3 statement of front when carrying out the L2 section, condition condition-3 satisfies, then control turns to L4.If no longer go back to but control, then order is carried out the exit-program EOP (end of program), no longer turns back to the PERFORM statement of front.If to having between the exit-program before the redirect statement turns back to L3 or L3 with control, when the ending of the program section of execution L3, control can also be returned the PERFORM statement of front again at L4.
As can be seen, the PERFORM statement is similar in the modern languages function calls the execution of each section very much, but different is, transform is not independent like that for section, but loose structure, it allows the redirect between section of GOTO statement, certainly will the section of making not have the closure of function in the other Languages like this.When the performed object of PERFORM jumped out in the GOTO statement, control stream will continue to carry out downwards, up to EOP (end of program) or satisfy the condition of returning of PERFORM.Therefore, can not be simply each section be configured to a process, simulates PERFORM and GOTO statement among the COBOL by function call.
Above-mentioned example is fairly simple, also more complicated situation may occur in fact.Such as the PERFORM statement that may also comprise other in performed several sections of PERFORM statement, these PERFORM statements will be to allow not to be subjected to any several sections of restrictedly carrying out other any range in theory.On essence, the generation of the problems referred to above stems from the destructuring in Common business Oriented Language stage casing.
This problem becomes COBOL stubborn problem very in the java applet conversion process, and whether the control structure conversion has rationally determined the success or failure of language conversion.
The invention provides following embodiment:
Referring to Fig. 6,
Step 100 converts a process of cobol program to a java class of the same name.Suppose the process CobolProcedure by name among the Cobol, then the java class of neotectonics is as follows:
class?CobolProcedure{
……
}
Step 110 is provided with an entrance function in above-mentioned java class, the tabulation of this function parameters is corresponding to the parameter list of former COBOL process, and an entrance function promptly is set in above-mentioned java class, and (we are with its called after _ entry).
Step 120, the content of inlet porting function comprises a compound statement in this function, be used for another execution function of same class is called, and catch and carry out the exception that function is dished out when end of run, carry out the procedure body that function is used to realize the COBOL process; Referring to Fig. 4, have the function list of the same name except comprising in the tabulation of this function parameters with _ entry function, also increased by two parameter entrance (entrance) and exit (exit point) in front.Inlet when entrance carries out as the PERFORM statement.Exit carries out the outlet of object as the PERFORM statement.We can think that whole procedure originally is equivalent to enter from first section, withdraws from from last section.Therefore, in _ entry, reality of carrying out function sub join be 0 and last+1).
Step 130 is numbered the section name of cobol program, and first section from cobol program is numbered statement to the last downwards from 0 successively.For the ease of the conforming maintenance of program, require before EOP (end of program), to increase a numbering.
Step 140, COBOL procedure body structure is carried out following processing: whole procedure is placed a circulation, and wherein every case statement is successively corresponding to a segment labeling in the cobol program, and the code of its back is corresponding to the content of a section;
In step 140, whole procedure is placed a circulation, its citation form is as shown in Figure 5.Wherein every case statement is successively corresponding to a segment labeling in the cobol program, and the code of its back is corresponding to the content of a section.Statement throw new Exception () is used to finish a process corresponding to the exit-program among the COBOL.In addition, for the consistance of program, increased a Case statement before end statement, its sequence number is last+1.
Step 150 is handled the GOTO statement.When running into the GOTO statement, it can be translated into following form:
{ the pairing numbering of label variable=jump target; The continue end point; ; Or { the pairing numbering of label variable=jump target; The break end point; , i.e. { label=dest; Continue end; Or { label=dest; Break end; The dest of } // here is the pairing numbering of jump target.
Step 160 is handled the PERFORM statement.When running into the PERFORM statement, it is translated into following form: carry out function (inlet, the numbering that outlet is corresponding, parameter list), promptly sub (en, ex, paraList); // wherein en is inlet, ex is the numbering of the corresponding section of outlet.
Step 170 increases statement a: if (exit point==this segment number) return at each section tail.
In step 170, after allowing sub execute pairing section of ex, return the PERFORM statement, also need increase statement a: if (exit==segNumber) return at each section tail; // wherein segNumber is the numbering of this section.
In addition, the PERFORM statement also may have cycling condition, and the realization of cycling condition is very simple, only need finish getting final product with while and for statement.For example label is a statement among the L4 among the figure two: perform L3 until var EQUAL 0 and perform L1 thru L3 varying I from 1 by 2 until 10, we become form corresponding among the figure three with them.
For example shown in Figure 2, we can simulate with java applet shown in Figure 3.
The present invention realizes what the conversion of PERFORM statement came down to realize by recursive call.Will increase a push operation like this, the activation record of sub is pressed in the storehouse.On space expense, PERFORM of every execution needs pop down once, in fact is pressed into an activation record in stack.In order to reduce activation record, we will be positioned over except the parameter entrance and the exit among the Vector, use the pointer that points to this object as parameter, thereby the number of parameters of sub is constrained to three.The size of activation record then becomes a less constant.
In addition, when cobol program is carried out the PERFORM statement, need equally to keep the return address, carry out push operation.Therefore, method described in the present invention is actually a less constant with the space expense ratio of COBOL.The GOTO statement is realized by the switch statement, does not therefore increase space expense.
As everyone knows, the conversion between the language will certainly cause the expansion of code, adopts this method to realize the conversion of GOTO and PERFORM.Its statement expansion relation is as shown in the table:
| Grammatical phenomenon | Required statement quantity |
| Switch and while framework | Article | 3 ,/file |
| Segment structure |
| | 2/section |
| ?GOTO | Article | 2 ,/GOTO |
| ?PERFORM | Article 1 ,/PERFORM |
Table 1 statement expands and concerns
The present invention can be by following formula computing statement expansivity:
3+ (the 2count section+2countGOTO+countPERFORM)/(countGOTO+countPERFORM).
By tested file analysis is found, because the statement expansivity that GOTO and PERFORM conversion cause is generally about 2.5 times.
And in the document that the inventor grasped, for the processing of analogue, its expansivity is generally more than 20 times.
In sum, method is changed in a kind of control rheology of legacy code of the present invention in the modern languages conversion process, utilizes switch and while statement in the higher level lanquage to eliminate GOTO and PERFORM compound control structure simultaneously.This method is the structure of reprogramming not, has kept programmed readability, and has controlled the code expansion preferably.This method is used in " C2J translation system " that we are developing at present, and has passed through the test of 4,000,000 row real-life programs.