US 6,408,431 B1Grant
Method and apparatus for multi-language software code generation
Issue Date:2002-06-18
•10 Claims
•4 Drawing Sheets
Abstract
A method of generating code for a software program in multiple languages by converting input specification files into output code files. The input specification files contain a list of distinctive features of the software program to be generated and are written in a prescribed input language. The input specification files are converted into a set of nodes representing the logical relationship between the distinctive features listed in the input specification files. Output code files are then generated from the set of nodes using external guideline files that contain guidelines for generating code. Output code files are generated in at least two code languages.
Metadata
Assignee
- Sony Europa B.V.
Inventors
- Andre Heughebaert
- Luc De Ceulaer
Application Information
Application Number:US 09/101,675
Filing Date:1999-02-26
Priority Date:1996-11-27
Art Unit:7
Classifications
IPC:
G06F 944
Field of Search:
717 1717 2717 9717 5717100717106717151717136717124717147717114717117700 86709101
Patent Drawings (4 sheets)
Description
[0002] The present invention relates to a method and system for generating program code, for example source code and text code describing the source code.
[0003] In the design and implementation phase of software programming it is possible to use code generators to facilitate generation of program code. For instance the XWindows graphic system, which is known in the UNIX environment, provides code generators that produce the necessary code for a user interface according to a set of specifications.
[0004] In general a code generator extracts information from an input file or specification file and produces an output file, e.g. a source file, that is understandable by a compiler. The compiler then is able to generate from this source file an executable of executable file of machine code. The code generator produces a very large part of the source code to be written. The remaining part, which mostly is the program's logic, has to be written by hand.
[0005] Code generation by a way of a code, generator has many advantages. When for example there exists repetitive patterns in the code to be written which must be replicated many times, a code generator can greatly reduce the effort the programmer has to make by reducing the number of lines to be manually written. Another advantage of code generation is that the naming in the software program becomes consistent throughout the entire program. Also consistency between the source code and the corresponding documentation code or documentation text can be greatly improved. Because of the fact that a great part of the program lines to be written is written automatically, design and implementation changes can be implemented within very short time. Also the number of bugs in the produced software code can be reduced.
[0006] Prior art code :generators, hereafter named dedicated code generators, are dedicated to one single language. The input to the code generator is in this case a fully prescribed specification file which is a listing of distinctive features which are used to define the specific aspects of the program code to be generated, for example instances, message names, types, attributes, links etc. The code generator generates an output file, for example a source file. The coding rules for conversion of the input file are build into the code generator itself (i.e. hard coded). A code generator dedicated to two languages must have two sets of coding rules hardcoded. This means that the dedicated code generators are not flexible in that both the input language and the output language are fixed and the coding rules have to be hardcoded into the code generator.
[0007] The present invention however provides a code generator wherein the language of the specification of the program to be build and the resulting code language are flexibly chosen by specifying external sets of coding rules or guidelines. In this case the specification file can be of an arbitrary format. According to a separate language descriptor the specification file is converted into a input file to the code generator. According to external guidelines the input file is converted into one or more code files, for example a C++source code file, a HTML documentation file describing the source code or a Unix makefile.
[0008] The present invention therefore relates to a method for generating code for a software program comprising:
[0009] specifying one or more input files describing the functionality of the software program according to a prescribed input language;
[0010] supplying first and second guidelines to code generator means wherein first and second guidelines describe the first and second rules respectively for conversion of said one or more input files;
[0011] supplying the input files to code generator means, wherein the code generator means convert the input files according to the first guidelines into one or more first code files and according to the second guidelines into one or more second code files.
[0012] The invention also comprises a method comprising:
[0013] supplying first and second language descriptors to interpretation means;
[0014] supplying a specification file describing the functionality of the software program to the interpretation means; wherein the interpretation means convert the specification file according to the first language descriptor into a first input file and according to the second language into a second input file.
[0015] The present invention also comprises the method for generating code for a software program comprising:
[0016] supplying one or more specification files describing the functionality of the software program to interpreter means;
[0017] supplying first and second specification language descriptors to interpreter means;
[0018] converting by the interpretation means of the specification files according to the first language descriptor into a first input to code generator means and according to the second language descriptor into a second input to code generator means;
[0019] supplying first and second guidelines to code generator means wherein first and second guidelines define the first and second rules respectively for conversion of the first and second input respectively;
[0020] converting the first input according to the first guidelines into one or more first code files and according to the second guidelines into one or more second code files
[0021] converting the second input according to the first guidelines into one or more third code files and according to the second guidelines into one or more fourth code files.
[0022] The present invention also relates to a drawing simulation tool of message passing in an object-oriented operating system. This drawing tool allows to describe Message Sequence Charts (or MSC) representing concurrent objects exchanging asynchronous messages.
[0023] The present invention also comprises the system which implements the methods mentioned above.
[0024] The present invention will now be described by way of preferred embodiments with reference to the accompanying drawings, throughout which the like-parts are referred to by like-references, and in which:
[0025] FIG. 1 shows schematically a prior art dedicated code generator;
[0026] FIG. 2 shows schematically a code generator with external coding rules or guidelines;
[0027] FIG. 3 shows schematically a code generator with interpretation means or parser means;
[0028] FIG. 4 shows a code generator according to FIG. 3 with two different sets of coding guidelines;
[0029] FIG. 5 shows schematically a code generator according to FIG. 3 with two sets of specification language descriptions; and
[0030] FIG. 6 shows a preferred embodiment of a system for implementing the present invention.
[0031] FIG. 7 shows a message sequence chart of a specification file.
[0032] FIG. 1 shows a prior art dedicated code generator 2. The input file 1 to the code generator 2 is a text file describing the functionality and features of the software program to be generated. The input file can for example be written in IDL (Interface Definition Language) which is a standard language defined by the OMG (Object Management Group). IDL is a technology-independent syntax describing software components in an object oriented and implementation independent way. Coding rules are build in the code generator. The output file 3 is in this case a C++source file which is compiled by a C++compiler to machine code which in turn can be executed by the central processing unit of a computer system. As the coding rules that control the conversion from input to output file are hardcoded into the code generator, the code generator can only be used for this combination of input format and the output format, viz. in this case IDL and C++respectively. For other combinations of output and input file format a separate code generator has to be provided.
[0033] In FIG. 2 a generic code generator 5 according to a preferred embodiment is shown. The guidelines 6 that define the code rules, i.e. all operations that will be performed on the input file 4 to create the necessary output code, are external in the sense that they are not part of the program code of the code generator itself. The guidelines can be comprised in one or more separate files on the hard disk of the computer system. Changing the external guidelines changes the output code files 7 accordingly. Compared to a dedicated code generator the generic code generator with external guidelines provides flexible means for generating from files with a fixed, prescribed input format or definition the desired program code or documentation code.
[0034] In FIG. 3 a code generator with external guidelines or coding rules 6 is shown, however also comprising an interpreter or parser 8 that enables the conversion of a specification file 9, containing a listing of distinctive features of the code to be generated, with aid of a specification language, into a set of nodes in memory 10 that is understandable to the generic code generator 5 and forms all logical relationships between the features in the specification file 9. The specification language is described in an external specification language descriptor file 11. Code generator 5 converts the set of nodes in memory 10 from the interpreter 8 into one or more suitable output code files 7, wherein. the format of this output depends on the guidelines 6. The output file 7 is in this case a C++source file. The implementation of the generic code generator is independent on the specification language that is described in the external language description file 11. Compared to a dedicated code generator, which comprises the use of a fixed input and output language with hardcoded rules, the generic code generator according to the present invention provides variable input and output languages (viz. specification language descriptions and coding guidelines) with programmable rules. Both specification language description and coding guidelines can be custom-designed.
[0035] FIG. 4 shows another preferred embodiment with a specification file 9, a language description file 11, an interpreter 8 and a code generator 5. Instead of one set of external guidelines 6, an additional set of guidelines, for example in external guideline files 13, is provided. The generic code generator generates in this case two sets of codes 7 and 12, for example C++source code and Pascal source code or C++source code and documentation text code describing the C++source code. Changes in the specification of the software program will be translated into changes in the source code file and documentation file accordingly. The generic code generator ensures therefore coherence between the output files, i.e. the documentation code file is consistent with the source code.
[0036] FIG. 5 shows still another preferred embodiment with two sets of coding guideline files 6 and 13, a specification language description file 11, an interpreter 8 and a code generator 5. Besides one external set of specification files 9 an additional set of specification files 14 is provided. By specifying the external guideline files 6 and 13 and the external specification language description files 9 and 14 four different output code files 7, 12, 16, 17 are produced for every combination of sets of guidelines and specification language descriptions.
[0037] FIG. 6 schematically shows a preferred embodiment of a system in accordance with the present invention, comprising a personal computer or workstation with a central processing unit 20, which is connected through connector 27 to a read only memory 21, a random access memory 22, a network 23, a screen 24, a keyboard 25 and a hard disk 26. The code generator and interpreter software is fetched from the hard disk 26 or network 23, and is (partly) loaded into memory 22. The specification files of the program to be generated by the system are input by an operator with the keyboard 25 or else are present on the hard disk 26 or the network 23. Using the specification language descriptors and guidelines and the interpreter and code generator software, central processing unit 20 processes the specification files to generate a series of output code files. The output code files are stored on the hard disk 26 or are sent over network 23 to an external destination. Hereafter, the generated code can be compiled and linked with manually written code.
[0038] An example of an implementation of the embodiment of FIG. 2 is given below. The input file in this case comprises modules, interfaces, attributes, operators and parameters:
| module Entertainment{ |
[0039] This example describes the object interface for the classes Movie and Audio, located in a module entertainment. Objects of this class can receive three incoming messages:
[0040] the Play operation has one input parameter of type long, named startFrame;
[0041] the Stop operation without parameter;
[0042] the Where operation without parameter, returns the current frame.
[0043] An Example of a guideline file is the scriptfile given below:
| $FOR [modules, mod] |
[0044] The resulting output of the code generator according to the above mentioned input file and guideline file is as follows:
[0045] The module Entertainment contains:
[0046] Interface Movie with the following operations:
[0047] Play, Stop, Where
[0048] and
[0049] Interface, Audio with the following operations:
[0050] The guideline file contains literals and statements, wherein literals are simply copied to the output file and statements are interpreted. Since the literals are copied to the output file, the code generator is independent of the generated code. The statements that in these examples are interpreted are as follows:
[0051] $VAR [operation.name]
[0052] write the name attribute of the operation component to the generated file and
[0053] $FOR [module.interfaces,i]
[0054] #include “$VAR [i.name].h”
[0055] $ENDFOR[ ]
[0056] iterate through all the interfaces of a module and print out an “include” line with the interface names. The iteration variable is automatically created and removed after the for loop.
[0057] A further embodiment of the present invention relates to providing an emulator for development of object-oriented software e.g. an object-oriented operating system. The behaviour of the software to be developed is simulated by the emulator on a known operating system like UNIX etc. The code generator according to the present invention translates the developed object-oriented software code into program code that runs on UNIX. In the case of development of object-oriented operation systems the drawing tool is able to simulate the synchronous and a-synchronous message passing between the program objects and to local entry mode intantiation of the active program objects. With the MSC drawing tool, the developed object-oriented software can be easily documented.
[0058] As an example of a specification file a MSC-text file is shown hereafter.
| MSC [15] [15] FS “Opening a file” | |
| ROLE CLIENT p_client | |
| ROLE FS fs | |
| IN p_client | |
| SEND p_entry fs OpenFile “fileId, cid” | |
| AT fs p_entry | |
| /* Check file existance and access |
[0059] MSC stands for Message Sequence Chart which is a drawing that shows how program objects interact with each other, i.e. which messages they pass to each other and in which order. The MSC-text file renders the MSC-drawing of FIG. 7. After the software programmer has tested the MSC and given his approval, the code generator translates the MSC-text, which is used as specification file, into the desired program code files.
[0060] As an example of a language description file a grammar rules definition file is shown hereafter.
| MDL | grammar | $mscprogram $toSkip |
| toSkip | manyOf | $chartoSkip #null #null #null |
| chartoSkip | oneOf | ‘ ’ ‘\t’ ‘\n’ |
| mscprogram | sequence | ‘MSC’ xScale=?$int yScale=?$int project=#id |
[0061] As an example of a coding guidelines file a WALK coding file is shown hereafter.
| $*[******************************************************************** | * |
[0062] As an example of a program code file the following TCL file is shown hereafter.
| proc Init {} { |
Claims
What is claimed is:
1. A method of generating code for a software program, comprising the steps of:
converting input specification files into a set of nodes using an interpreter and specification language description files; said input specification files containing a list of distinctive features of the software program to be generated and being written in a prescribed input language; said specification language description files describing at least one specification language; said set of nodes forming the logical relationship between the distinctive features listed in the input specification files as interpreted by the at least one specification language described in the specification language description files;
storing said set of nodes in a memory; and
generating output code files from said set of nodes stored in said memory using external guideline files containing guidelines for generating code from the nodes in at least two code languages; said output code files being generated in said at least two code languages.
2. The method according to claim 1, wherein said output code files for each code language comprise a source code file and a documentation code file.
3. The method according to claim 1, wherein said specification language description files describe two specification languages; said set of nodes forming the logical relationship between the distinctive features listed in the input specification files as interpreted by both specification languages; and output code files being generated in each code language for both specification languages.
4. The method according to claim 1, wherein said prescribed input language for said input specification files is interface definition language.
5. The method according to claim 1, wherein said specification language description files are message sequence chart files.
6. A code generating apparatus for generating code for a software program, comprising:
an interpreter for converting input specification files into a set of nodes using specification language description files; said input specification files containing a list of distinctive features of the software program to be generated and being written in a prescribed input language; said specification language description files describing at least one specification language; said set of nodes forming the logical relationship between the distinctive features listed in the input specification files as interpreted by the at least one specification language described in the specification language description files;
a memory for storing said set of nodes output from said interpreter; and
a generic code generator for generating output code files from said set of nodes stored in said memory means using external guideline files containing guidelines for generating code from the nodes in at least two code languages; said output code files being generated in said at least two code languages.
7. The code generating apparatus according to claim 6, wherein said output code files for each code language comprise a source code file and a documentation code file.
8. The code generating apparatus according to claim 6, wherein said specification language description files describe two specification languages; said set of nodes forming the logical relationship between the distinctive features listed in the input specification files as interpreted by both specification languages; and output code files being generated in each code language for both specification languages.
9. The code generating apparatus according to claim 6, wherein said prescribed input language for said input specification files is interface definition language.
10. The code generating apparatus according to claim 6, wherein said specification language description files are message sequence chart files.
Patent Citations (9)
| Patent | Date | Inventor | Cited By |
|---|---|---|---|
| US4796179(A) | 1989-01-01 | Lehman et al. | Examiner |
| US5428782(A) | 1995-06-01 | White | Examiner |
| US5493675(A) | 1996-02-01 | Faiman, Jr. et al. | Examiner |
| US5499371(A) | 1996-03-01 | Henninger et al. | Examiner |
| US5522079(A) | 1996-05-01 | Acker et al. | Examiner |
| US5675805(A) | 1997-10-01 | Boldo et al. | Applicant |
| US5699310(A) | 1997-12-01 | Garloff et al. | Examiner |
| US5860072(A) | 1999-01-01 | Schofield | Examiner |
| EP735467(A2) | 1996-10-01 | Applicant |
Non-Patent Literature (4)
- Aimar et al., “A Configurable Code Generator for 00 Methodologies,” Cern Technical Report No.: CERN-ECP-94-15, Oct. 10, 1994, Geneva, Switzerland.Applicant
- Auerbach et al., “The Concert Signature Representation: IDL as Intermediate Language,” ACM Sigplan Notices, vol. 29, No. 8, Aug. 1, 1994.Applicant
- Huang et al., “A Rule-Based Tool for Reverse Engineering from Source Code to Graphical Models,” Proceedings of 4th International Conference on Software Engineering and Knowledge Engineering, Capri, Italy, Jun. 15-20, 1992.Applicant
- Lea et al.. “PSL: Protocols and Pragmatics for Open Systems,” May 1995, Sun Technical Report No. 95-36.Applicant