Automatically generate the method for C++ program based on the definition of the component language
Technical field
The present invention relates to a kind of based on definition of the component language (Component Definition Language, the CDL language) generates the method for C++ program automatically, be meant a kind of Compilation Method of utilizing especially, to be automatically converted to method based on the program code of member statement, belong to computer software technical field based on the program code framework of C Plus Plus.
Background technology
Along with popularizing that development of internet technology and the Internet (Internet) use, network service (WebService) is becoming the important feature that Internet of new generation uses.The gordian technique that realizes the network service is the programming technique of component-oriented, middleware, and platform technologys such as a whole set of running environment, development environment.
Can mutual operation use the connection between the member and call and to finish by the agreement of standard in order to solve the construction part module (software object) that the different software developer provides.The componentization programming model is emphasized consensus standard, the protocol architecture that need provide each manufacturer of member to observe.Just as the standard of metric system screw, all standard compliant screws and nut can assemble mutually.The componentization programming model is based upon on the basis of Object-oriented Technique, is OO fully, and the mechanism of dynamic structural member module (in service can structural member) is provided.Member is dynamically packed into when operation, and member is interchangeable.Its representative is The Component Object Model (The Component Object Model is called for short a COM) technical manual.Componentization programming technique based on COM is the important means of large software through engineering approaches exploitation.MS all follows the COM technical manual based on the software of Windows2000 operating system and realizes.
In addition, because the Internet is universal, member can come from network; Operating system will solve automatic download, security problems.Therefore, need to generate automatically the running environment of member in the operating system, generate and act on behalf of member, that is: middleware according to the self-described information of member.Automatically the middleware that generates by operating system is intervened the running status of member or is controlled, or the service at different network protocol, input-output device (being running environment) is provided automatically.The self-described of member and the transparency of member running environment are emphasized in the middleware programming more, are the important technologies of programming cybertimes.
In order in resource limited embedded system, to realize towards the middleware programming technique, simultaneously can obtain higher running efficiency again, use obviously is inappropriate based on the mechanism of intermediate code-virtual machine, because influence efficient exactly for the translation of intermediate code and compilation process in the virtual machine mechanism.And adopt the C++ programming to realize component technology, and direct generating run is in the binary code of member operation platform, make more programmer can fully use oneself familiar programming language knowledge and development Experience, the technology of grasping component-oriented, middleware programming is the important means that addresses the above problem.But the component description system of COM technical manual is very loaded down with trivial details, is not easy to grasp into the programming technique personnel.
Summary of the invention
Fundamental purpose of the present invention is to provide a kind of method that generates the C++ program based on the definition of the component language automatically, can be with according to being automatically converted to program code framework by Compilation Method, for the programming technique personnel provide a kind of program development means and method based on member that is easy to grasp based on C Plus Plus based on the program code of definition of the component language compilation.
The object of the present invention is achieved like this:
A kind ofly generate the method for C++ program automatically, comprising based on the definition of the component language:
Step 1:, and be the definition of the component language file with this procedure stores according to definition of the component language compilation component program code;
Step 2: this definition of the component language file is compiled, this definition of the component language file is converted to program frame based on the C++ program language, be used for the program development personnel and under this program frame, add corresponding program code.
Following grammar rule followed in above-mentioned definition of the component language: the definition of the component language file writes down attribute information and the definition information that is described object at least, attribute information is used to modify member, class, classification or interface, and attribute information is recorded in before the definition information of corresponding theme.
Above-mentioned attribute information is recorded among the square bracket, and this attribute information comprises at least: attribute-bit and property content.
Attribute-bit comprises at least:
Global unique identification accords with, and is used for the global unique identification information of identification means, class, classification or interface;
Version number is used for the version of identification means or class;
On the last date, be used for last modification date of identification means or class;
Final time is used for the last modification time of identification means or class;
Internet address is used for identification means address on the internet;
Can carry out sign, be used for sign and can carry out member;
Device drives identifies, but is used to identify the class of support member device driver;
The inlet sign is used to be designated class or the classification that executive routine enters the mouth;
Banner, the component object that is used to identify such generation can be checked on webpage;
Read-Write Locks sign, the component object that is used to identify such generation can use Read-Write Locks mechanism;
Synchrolock sign, the component object that is used to identify such generation can use synchrolock mechanism;
Signal identification, the component object that is used to identify such generation can use signaling mechanism;
Non-far call sign, being used to identify interface can only use in the territory identical with CLIENT PROGRAM, can not be used for far call;
Parameter identification is used for the type of identification parameter;
False sorts type definition sign, being used to identify the type definition that is identified is the type definition of a vacation.
The above-mentioned member carried out can enter graphic model, and system's main window or Drawing Object that carries out mapping operation of providing a CLIENT PROGRAM can add control thereon.
The above-mentioned member carried out can enter the control desk pattern.
Above-mentioned parameter is the rreturn value that input parameter or output parameter or its value can be used as function.
Above-mentioned attribute information is one or more, and when the attribute information of being modified object be one when above, be provided with separator between this attribute information.
Described definition information is recorded among the brace, comprises key word and definition content at least.
Described key word comprises at least: be used for defining expression symbol, the define styles of expression symbol, the definition enumeration type of expression symbol, the definition structure body of expression symbol, the definition classification of expression symbol, the definition class of the expression symbol of member, the expression symbol that is used for defining interface, definition event interface the expression symbol, specify this member to use the expression symbol of other members, forbid or allows to show that the expression that compiler provides warning message accords with.
Described compiling is specially: at first, the file compiler adopts the recurrence descent algorithm with the definition of the component language file, compiles it as the file of representing with binit; Then, will be somebody's turn to do the class of the member of putting down in writing in the file of representing with binit and the definition information of interface again and be converted into C++ syntactic representation form, generate the C Plus Plus source program framework of member.
The above-mentioned program frame based on the C++ program language comprises at least: the program header file of the program's code file of C Plus Plus, C Plus Plus and the program resource file of C Plus Plus.
The present invention has solved the loaded down with trivial details problem that adopts the component description system of COM technical manual by a kind of definition of the component language, the programming technique personnel are easy to grasp and use programming technique based on member, make and to adopt the C++ programming to realize component technology, and direct generating run is in the binary code of member operation platform; Simultaneously, the present invention can generate C++ program code framework automatically according to the definition of the component language, for the programming technique personnel provide the more convenient program development means based on member.
Embodiment
The present invention is described in further detail below in conjunction with specific embodiment:
The present invention is at first according to definition of the component language compilation component program code, and is the definition of the component language file with this procedure stores; Then, this definition of the component language file is compiled, this definition of the component language file is converted to program frame based on the C++ program language, be used for the program development personnel and under this program frame, add corresponding program code.
In the present embodiment, described definition of the component language (Component Definition Language is called for short CDL) file is used for defining the information such as class, interface and interface method of member.Each member can be made up of one or more classes, and each class can provide one or more interfaces, can define one or more methods in each interface.
In the CDL file, the description of member, interface, class, classification etc. all is divided into two parts: attribute information and definition information.The CDL attribute information is arranged in square bracket " [] ", between a plurality of attributes with comma, " as separator; Definition information to member, interface, class, classification etc. is arranged in brace " { } ".Attribute information always appears at before the definition information of corresponding theme.
Above-mentioned attribute information comprises at least: attribute-bit and property content.
Attribute-bit in the present embodiment is referring to table 1:
Table 1
Property Name | Attribute specification |
uuid | The global unique identification symbol that is used for identification means, class, classification or interface |
version | The version number that is used for identification means or class |
lastdate | The last modification date that is used for identification means or class |
lasttime | The last modification time that is used for identification means or class |
urn | Be used to identify this member address on the internet |
graphics | Be used to identify this member for can carry out member, can enter graphic model, system will provide a CLIENT PROGRAM can add the main window of control |
graphics(lit e) | This attribute is used to identify this member for can carry out member, can enter graphic model, and system provides a Drawing Object that can carry out mapping operation |
console | This attribute is used to identify this member for can carry out member, can enter the control desk pattern |
driver | This attribute is used to identify such can the support member device driver |
main | This attribute is used to identify such or classification is the inlet of executive routine |
scriptable | This attribute is used to identify the component object of such generation can be checked on webpage |
rwlock | The component object that this attribute is used to identify such generation can use Read-Write Locks mechanism |
monitor | The component object that this attribute is used to identify such generation can use synchrolock mechanism |
signal | The component object that this attribute is used to identify such generation can use signaling mechanism |
local | This attribute is used to identify this interface can only be used in the territory identical with CLIENT PROGRAM, can not be used for far call |
in | It is input parameter that this attribute is used to identify this parameter |
out | It is output parameter that this attribute is used to identify this parameter |
retval | The value that this attribute is used to identify this parameter can be used as function return value |
dummytype | This attribute-bit the type definition is the type definition of a vacation |
Be provided with separator between this attribute information when the attribute information of being modified object is one when above, in the present embodiment, attribute information is separated with ", ".For example:
[uuid(994381D4-397D-410F-A106-56DED7359FC2),scriptable]
Definition information in the present embodiment is recorded among the brace, comprises key word and definition content at least.
Concrete key word is as shown in table 2:
Table 2
Key word | Key word is described |
component | The definition member |
interface | Defining interface |
events | The definition event interface |
class | The definition class |
category | The definition classification |
struct | The definition structure body, its using method is with basic identical in the C/C++ program |
enum | The definition enumeration type, its using method is with basic identical in the C/C++ program |
typedef | Define styles, its using method is with basic identical in the C/C++ program |
importlib | Specify other member (dynamic link libraries) or the static library used in this member |
pragma | The warning message of forbidding or allowing demonstration CDL compiler to provide |
Described compiling is specially:
At first, use CDL file compiler to adopt the recurrence descent algorithm that the definition of the component language file is compiled as " .cls " file, this " .cls " file is that the binitization of CDL file is represented file, is also referred to as category information (ClassInfo) file; " .cls " file is the compiling result (is the compiling destination file of C or C++ source program as " .obj " file) to the CDL file.
Then, will be somebody's turn to do the class of the member of putting down in writing in " .cls " file of representing with binit and the definition information of interface again and be converted into C++ syntactic representation form, generate the C Plus Plus source program framework of member.Should comprise in the program frame based on the C++ program language: the program header file (* .h) of the program's code file of C Plus Plus (* .cpp), C Plus Plus and the program resource file (* .src) of C Plus Plus.
The example of a concrete CDL file:
Suppose: defined three class: CHello1, CHello2 and CHello3 among the member HelloDemo.Wherein, class CHello2 provides interface IHello, and class CHello3 provides interface IHei, and class CHello1 provides interface IHello and IHei simultaneously.These information all are defined in " HelloDemo.cdl " by name file.
The HelloDemo.cdl file:
[uuid (1845B8D5-15A0-4EFB-AFB7-2A261A0EF408), and urn (http: ∥ www.koretide.com/ezcom/HelloDemo.dll)] component HelloDemo // member HelloDemo{ ∥ interface IHello [uuid (B5613847-0A96-4F16-A63F-0BC00358607E)] interface IHello{ HRESULT Hello ([in] inti); ∥ interface IHei [uuid (07280692-2E77-4562-A9D9-8813ECE351AF)] interface IHei{ HRESULT Hei ([in] int i, [out, retval] char*pChar); ∥ class CHello1 [uuid (994381D4-397D-410F-A106-56DED7359FC2), scriptable] class CHellol{ interface IHello; Interface IHei; ∥ class CHello2 [uuid (C71ACA6F-ECCA-4537-832D-89033590B02C)] class CHello2{<!--SIPO<DP n=" 7 "〉--〉<dp n=" d7 "/interface IHello; } // class CHello3 [uuid (8C4F6ED3-C3A2-482C-9211-3E315500978F)] class CHello3{ interface IHei;
Illustrate: above-mentioned double slashes " // " accords with as the statement note.
Wherein, the attribute representation of member HelloDemo is:
[??uuid(1845B8D5-15A0-4EFB-AFB7-2A261A0EF408),
urn(
http://www.koretide.com/ezcom/HelloDemo.dll)
]
Structure attribute plays modification to member, and above-mentioned " uuid " attribute and " urn " attribute are necessary." uuid " in the structure attribute is called component mark " ID ", and it is used for member of unique identification; " urn " specifies the position of the existing dynamic link libraries of member (d11) file on Internet.
The definition list of member HelloDemo is shown:
component?HelloDemo
{
......
}
The interface attributes docking port plays modification, and " uuid " attribute wherein is necessary." uuid " in the interface attributes is called interface identifier " ID " (IID), and it is used for interface of unique identification.The attribute representation of interface IHello is:
[uuid(B5613847-0A96-4F16-A63F-0BC00358607E)]
Interface definition mainly comprises the statement of interface method.The most important definition that surely belongs to interface in the CDL file.Because in member, can have only interface with the external world comes into contacts with.One does not have the interface of interface method nonsensical in reality.The definition list of interface IHello is shown:
interface?IHello{
HRESULT?Hello([in]int?i);
}
Method definition in the interface must be observed following regulation:
1. interface method must use " HRESULT " as rreturn value;
2. the interface method parameter must the explicit parameter that indicates interface method be input parameter (in) or output parameter (out) or uses (retval) as rreturn value,
Generic attribute plays modification to class, and " uuid " attribute wherein is necessary." uuid " in the generic attribute is called class sign (CLSID), is used for class of unique identification.The implication of attribute scriptable represents that this member can be used on the webpage.
The attribute representation of class CHello2 is:
[uuid(C71ACA6F-ECCA-4537-832D-89033590B02C)]
Mainly comprise the statement of interface in the class definition, represent the interface that this class object provides.Because for class object, interface is that it carries out mutual unique channel with extraneous, so an existence that does not have the class of interface is nonsensical.
The definition list of class CHello2 is shown:
class?CHello2{
interface?IHello;
}
It should be noted that at last: above embodiment only in order to the explanation the present invention and and unrestricted technical scheme described in the invention; Therefore, although this instructions has been described in detail the present invention with reference to each above-mentioned embodiment,, those of ordinary skill in the art should be appreciated that still and can make amendment or be equal to replacement the present invention; And all do not break away from the technical scheme and the improvement thereof of the spirit and scope of the present invention, and it all should be encompassed in the middle of the claim scope of the present invention.