last modified: November 25 2002

The IDL compiler

Introduction

The Jonathan idl2java Compiler generates the java classes and interfaces necessary to run distributed objects on the David personality of the Jonathan ORB platform. In its present version, it handles a subset of the IDL Grammar as described in the CORBA 2.3 specification document of october 1999 (mainly the grammar minus all object by value related constructions.

The compiler automatically launches jpp a simple preprocessor which implements a subset of the ansi C preprocessor facilities.

Compiler utilization

The syntax of the compilation command is : idl2java (option_list | idl_File_List)*. The command idl2java stands here for java org.omg.objectweb.david.tools.idlcompiler.Idl2Java. It could be implemented through a simple shell script (unix, Linux) or .bat file (dos, windows).

Options and file names can appear several times and be intertwinned in the command line. Option values are then used from their declaration point until they are redefined. Following options are available in the present version :

For example :

IDL Grammar

The compiler handles the IDL Grammar as described in the CORBA 2.3 specification document of october 1999 with one main exception : it does not recognize any object by value related constructions.

Main characteristics of the compiler are :

std Language mapping

The IDL mapping onto the java language modules complies to the IDL/Java Language Mapping as described in the CORBA specification of June 1999. There are generated classes for each struct, union, exception, enumeration type, for each constant (excepted enum constants), for each interface declared in the IDL file. Classes are stored in separate files. Scopes define packages.

Specific features are :

rmi Language mapping

The IDL mapping onto the java language modules complies to the IDL/Java Language Mapping as described in the CORBA specification of June 1999. There are generated classes for each struct, union, exception, enumeration type, for each constant (excepted enum constants), for each interface declared in the IDL file. Classes are stored in separate files. Scopes define packages.

Specific features are :

Known bugs and limitations

/etc...

This compiler is made of two separate parts :

The javacc grammar

The grammar implemented in the compiler is described by the following rules. Note that this grammar is, for historical reasons not precisely the same as the one specified in the OMG standard. However they seem to be equivalent.

The corresponding front end has been generated with the help of the javacc compiler from metadata.

rule 1)    specification 	::   definition+ 
rule 2)    definition 	        ::   (type_dcl | const_dcl | except_dcl | interfacex | module) ";"
rule 3)    module		::   "module" identifier "{" definition* "}"
rule 4)    interfacex 	        ::   "pseudo" interfacex1 | "abstract" interfacex1 | "local" interfacex1 | interfacex1
rule 4')   interfacex1 	        ::   interface_dcl | forward_dcl
rule 5)    interface_dcl 	::   interface_header "{" interface_body "}"
rule 6)    forward_dcl 	        ::   "interface" identifier
rule 7)    interface_header	::   "interface" identifier [ inheritance_spec ]
rule 8)    interface_body 	::   export*
rule 9)    export 		::   (type_dcl | const_dcl | except_dcl | attr_dcl| op_dcl) ";"
rule 10)   inheritance_spec 	::   ":" scoped_name inheritance_spec1*
rule 10')  inheritance_spec1    ::   "," scoped_name
rule 11)   scoped_name	        ::   scoped_name1
rule 11')  scoped_name1 	::   "::" identifier scoped_name2* identifier scoped_name2*
rule 11")  scoped_name2 	::   "::" identifier
rule 12)   const_dcl 	        ::   "const" const_type identifier "=" const_exp
rule 13)   const_type 	        ::   floating_type | integer_type | char_type | boolean_type |
 				     string_type | fixed_type | scoped_name
rule 14)   const_exp 	        ::   or_expr
rule 15)   or_expr 		::   xor_expr or_expr1*
rule 15')  or_expr1 		;:   "|" xor_expr
rule 16)   xor_expr 		::   and_expr xor_expr1*
rule 16')  xor_expr1 	        ::   "^" and_expr
rule 17)   and_expr 		::   shift_expr and_expr1*
rule 17')  and_expr1		::   "&" shift_expr
rule 18)   shift_expr 	        ::    add_expr shift_expr1*
rule 18')  shift_expr1 	        ::   ">>" add_expr |  "<<" add_expr
rule 19)   add_expr 		::    mult_expr add_expr1*
rule 19')  add_expr1 	        ::   "+" mult_expr |  "-" mult_expr
rule 20)   mult_expr 	        ::   unary_expr mult_expr1*
rule 20')  mult_expr1 	        ::   "*" unary_expr | "/" unary_expr | "%" unary_expr
rule 21)   unary_expr	        ::   "-" primary_expr | "+" primary_expr | "~" primary_expr | primary_expr
rule 23)   primary_expr 	::   scoped_name | literal | "(" const_exp ")"
rule 24)   literal 		::   integer_literal | string_literal | character_literal
 				   | floating_literal | boolean_literal
rule 25)   boolean_literal 	::   "TRUE" | "FALSE"
rule 26)   positive_int_const   ::   const_exp *
rule 27)   type_dcl 		::   "typedef" type_spec type_declarators | "native" native_type | constr_type_spec
rule 28)   type_declarator 	::   type_spec type_declarators
rule 29)   type_spec 	        ::   simple_type_spec | constr_type_spec
rule 30)   simple_type_spec	::   base_type_spec | template_type_spec | scoped_name
rule 31)   base_type_spec 	::   floating_type | integer_type |  char_type |  boolean_type
                              | octet_type | object_type | any_type
rule 32)   template_type_spec   ::   sequence_type | fixed_type | string_type
rule 33)   constr_type_spec 	::   struct_type | union_type | enum_type
rule 34)   type_declarators 	::   t_declarator ( "," t_declarator )* 
rule 35)   t_declarator 	::   complex_declarator | simple_declarator
rule 36)   simple_declarator    ::   identifier
rule 37)   complex_declarator   ::   array_declarator
rule 63)   array_declarator     ::   identifier fixed_array_size+
rule 64)   fixed_array_size     ::   "[" positive_int_const "]"
rule 38)   floating_type 	::   "float" | "double" | "long" "double"
rule 39)   integer_type	        ::    "unsigned" int_type | int_type
rule 40)   int_type             ::   "long" "long" | "long" | "short" 
rule 46)   char_type       ::   "char" | "wchar"
rule 47)   boolean_type 	::   "boolean"
rule 48)   octet_type		::   "octet"
rule 48')  object_type	   ::   "Object"
rule 49)   any_type        ::   "any"
rule 49')  typeCode_type 	::   "TypeCode"
rule 49'') principal_type  ::   "Principal"
rule       native_type		::   simple_declarator
rule       s_declarator 	::   complex_declarator | simple_declarator
rule	      e_declarator 	::   complex_declarator | simple_declarator
rule	      u_declarator 	::   complex_declarator | simple_declarator
rule 50)   struct_type 	        ::   "struct" identifier "{" struct_member_dcl+ "}"
rule 51)   struct_member_dcl	::   type_spec struct_declarators
rule 52)   struct_declarators   ::   s_declarator ( "," s_declarator )*  ";"
rule 53)   union_type	        ::   "union" identifier "switch" "(" switch_type_spec ")" {" switch_body "}"
rule 54)   switch_type_spec     ::  integer_type | char_type | boolean_type | enum_type | scoped_name
rule 55)   switch_body 	        :: (casex)+
rule 56)   casex		::  case_label (case_label1)* union_member_dcl ";"
rule 57)   case_label		::  "case" const_exp ":" | "default" ":" 
rule 57')  case_label1 	        ::  "case" const_exp ":"
rule 58)   union_member_dcl 	::  type_spec union_declarators
rule 58')  union_declarators	::  u_declarator
rule 59)   enum_type    	::  "enum" identifier "{" enumerator ( "," enumerator )* "}"
rule 60)   enumerator	        ::  identifier
rule 61)   sequence_type 	::  "sequence" "<" simple_type_spec  sequence_type1
rule 61')  sequence_type1 	::  "," positive_int_const ">" | ">"
rule   )   fixed_type   	::  "fixed" "<" positive_int_const "," integer_literal ">"
rule 62)   string_type  	::  "string" | "string"  "<" positive_int_const ">"
 				  | "wstring" | "wstring" "<" positive_int_const ">"
rule 65)   attr_dcl 		::  "readonly" "attribute" param_type_spec attr_declarator ( "," attr_declarator )*
     			  | "attribute" param_type_spec attr_declarator(false) ( "," attr_declarator(false) )*
rule 65')  attr_declarator 	::  simple_declarator
rule 66)   except_dcl	        ::  "exception" identifier "{" exception_member_dcl* "}"
rule 66')  exception_member_dcl   ::  type_spec exception_declarators
rule 66")  exception_declarators  ::  e_declarator ( ","  e_declarator )*  ";"
rule 67 )  op_dcl		::  "oneway" "void" identifier  parameter_dcls[ context_expr ]
 				  |  op_type_spec identifier(true)  parameter_dcls [ raises_expr ] [ context_expr ]
rule 68)   op_type_spec 	::   param_type_spec | "void" 
rule 70)   parameter_dcls 	::  "(" [ param_dcl ( "," param_dcl )* ] ")"
rule 71)   param_dcl 	        ::  param_attribute param_type_spec simple_declarator
rule 72)   param_attribute 	::  "in" | "out" | "inout"
rule 73)   raises_expr	        ::  "raises" "(" raises_expr1 ( "," raises_expr1 )* ")"
rule 73')  raises_expr1	        ::  scoped_name
rule 74)   context_expr	        ::  "context" "(" context_expr1 ( "," context_expr1 )* ")"
rule 74')  context_expr1 	::  string_literal
rule 75)   param_type_spec 	::  base_type_spec | string_type | scoped_name

Tokens used are :

identifier 		::  ID 
integer_literal 	::  OCTALINT | DECIMALINT | HEXADECIMALINT
string_literal   	::  STRING
character_literal 	::  CHARACTER
floating_literal  	::  FLOATONE | FLOATTWO

ID 	        :: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_"])*
OCTALINT        :: ["0"] (["0"-"7"])* (["u","U","l","L"])?
DECIMALINT   	:: ["1"-"9"] (["0"-"9"])* (["u","U","l","L"])?
HEXADECIMALINT 	:: ("0x"|"0X") (["0"-"9","a"-"f","A"-"F"])+ (["u","U","l","L"])?
FLOATONE        :: ((["0"-"9"])+ "." (["0"-"9"])* | (["0"-"9"])* "." (["0"-"9"])+)
 	            (["e","E"] (["-","+"])? (["0"-"9"])+)? (["f","F","l","L"])?
FLOATTWO 	:: (["0"-"9"])+ ["e","E"] (["-","+"])? (["0"-"9"])+ (["f","F","l","L"])?
CHARACTER 	:: (["L"])? "'" (	
		     ( ~["'","\\","\n","\r"])
		     | ("\\" ( ["n","t","v","b","r","f","a","\\","?","'","\""]
       		     | "0" (["0"-"7"])* | ["1"-"9"] (["0"-"9"])*
       		     | ("x" | "X") (["0"-"9","a"-"f","A"-"F"])+
                     | ("u" | "U") (["0"-"9","a"-"f","A"-"F"])+
		           ) "'"
STRING 		:: (["L"])? "\""
		   ( ( ~["\"","\\","\n","\r"])
		     | ("\\" ( ["n","t","v","b","r","f","a","\\","?","'","\""]
 		     | "0" (["0"-"7"])*
 			     | ["1"-"9"] (["0"-"9"])*
 		             | ("x" | "X") (["0"-"9","a"-"f","A"-"F"])+
 			       | ("u" | "U") (["0"-"9","a"-"f","A"-"F"])+
    	 		       )
  			     )
		           )* "\""

Characters and sequences to be skipped are :

	 " " | "\t" "\r" | "\n" | "//" (~["\n"])* "\n"
     |  "/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/"
	| "#" ([" ","\t"])* (["0"-"9"])+ (([" ","\t"])*
   "\"" (~["\""])+ "\"" ([" ","\t"])* (["0"-"9"])* ([" ","\t"])* (["0"-"9"])*)? "\n"