[eros-cvs] cvs commit: eros/src/base/cross/bin/capidl SymTab.hxx gram.y

shap@eros.cs.jhu.edu shap@eros.cs.jhu.edu
Wed, 31 Jan 2001 14:07:32 -0500


shap        01/01/31 14:07:31

  Modified:    src/base/cross/bin/capidl SymTab.hxx gram.y
  Log:
  Clean up in/out parameters a bit.
  
  Revise the various <xx_definition> nonterminals for proper
  restrictions at various scopes.

Revision  Changes    Path
1.5       +1 -0      eros/src/base/cross/bin/capidl/SymTab.hxx

Index: SymTab.hxx
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/SymTab.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SymTab.hxx	2001/01/25 03:30:20	1.4
+++ SymTab.hxx	2001/01/31 19:07:31	1.5
@@ -59,6 +59,7 @@
   sc_function,			/* function name */
   sc_oneway,			/* oneway function name */
   sc_formal,			/* formal parameter name */
+  sc_outformal,			/* OUT formal parameter name */
   sc_exception,			/* exception name */
 };
 



1.6       +108 -72   eros/src/base/cross/bin/capidl/gram.y

Index: gram.y
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/gram.y,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- gram.y	2001/01/26 23:47:42	1.5
+++ gram.y	2001/01/31 19:07:31	1.6
@@ -152,10 +152,15 @@
 
 /* operators */
 %token <NONE> OPSCOPE /* :: */
+%token <NONE> RESUME
 
 %type  <NONE> start
-%type  <NONE> definitions
-%type  <NONE> definition
+%type  <NONE> top_definitions
+%type  <NONE> top_definition
+%type  <NONE> mod_definitions
+%type  <NONE> mod_definition
+%type  <NONE> if_definitions
+%type  <NONE> if_definition
 %type  <tok>  name_def
 %type  <NONE> struct_dcl
 %type  <NONE> except_dcl
@@ -184,17 +189,13 @@
 %type  <NONE> case_labels
 %type  <NONE> enum_defs
 %type  <sym>  literal
-%type  <NONE> message
-%type  <NONE> messages
-%type  <NONE> message_dcl
+%type  <NONE> opr_dcl
 %type  <sym>  ret_type
+%type  <NONE> params
 %type  <NONE> param_list
-%type  <NONE> in_param
-%type  <NONE> param
-%type  <NONE> param_2_list
-%type  <NONE> param_2
+%type  <sym>  param
 %type  <NONE> param_2s
-%type  <NONE> params
+%type  <NONE> param_2_list
 %type  <NONE> opt_raises
 %type  <NONE> raises
 %type  <NONE> advice
@@ -203,34 +204,56 @@
 /* Grammar follows */
 %%
 
-start: { Symbol::PushScope(GlobalScope); } definitions
+start: { Symbol::PushScope(GlobalScope); } top_definitions
  ;
 
-definitions:
+top_definitions:
  /* empty */       { }
- |      definitions definition
+ |      top_definitions top_definition
  ;
 
 /**
  * Defined a name to have a specified meaning in a scope.  The name
  * may be defined as a type, a scope, or a constant value.
  */
-definition:
-        ';'   {}                                // empty definition
- |      MODULE name_def '{' definitions '}'     // a scope
- |      struct_dcl                              // a struct
- |      except_dcl                              // a struct to throw
- |      union_dcl                               // a discriminated union
- |      enum_dcl                                // a set of const unsigneds
+/* SHAP: Trailing semicolons added per CORBA IDL spec.
+ * Also, does repr_dcl make sense at global scope, or should it be
+ * part of the interface declaration? I suppose it's needed for struct
+ * level, which is yet another line of questions (I'm really full of
+ * questions).
+ *
+ * SHAP: empty top_definition removed per CORBA 2.4.1
+ */
+top_definition:
+        MODULE name_def '{' mod_definitions '}' ';' // a scope
+ |      interface_dcl ';'                       // a capability
+ |      struct_dcl ';'                          // a struct
+ |      except_dcl ';'                          // a struct to throw
+ |      union_dcl  ';'                          // a discriminated union
+ |      enum_dcl ';'                            // a set of const unsigneds
  |      TYPEDEF type name_def ';'               // names a type
  |      TYPEDEF name_def ';'                    // forward declaration
- |      const_dcl;                              // constant value
- |      interface_dcl                           // a capability
- |      repr_dcl                                // advises on representation
+ |      const_dcl ';'                           // constant value
+ |      repr_dcl ';'                            // advises on representation
  ;
 
-
+mod_definitions:
+ /* empty */       { }
+ |      mod_definitions mod_definition
+ ;
 
+mod_definition:
+        interface_dcl ';'                       // a capability
+ |      struct_dcl ';'                          // a struct
+ |      except_dcl ';'                          // a struct to throw
+ |      union_dcl  ';'                          // a discriminated union
+ |      enum_dcl ';'                            // a set of const unsigneds
+ |      TYPEDEF type name_def ';'               // names a type
+ |      TYPEDEF name_def ';'                    // forward declaration
+ |      const_dcl ';'                           // constant value
+ |      repr_dcl ';'                            // advises on representation
+ ;
+	
 /********************** Names ***************************/
 
 
@@ -505,7 +528,7 @@
  * are accessed by member name (ie, field name). <p>
  *
  * Like a Corba or CapIDL module, a CapIDL struct also defines a named
- * scope, such that definitions between the curly brackets define
+ * scope, such that top_definitions between the curly brackets define
  * names in that scope.
  */
 struct_dcl:
@@ -523,7 +546,7 @@
  ;
 
 member:
-        definition         /* defines a name inside this scope */
+        top_definition         /* defines a name inside this scope */
  |      type name_def ';'  /* defines an actual member (ie, field) */ {
 	  Symbol *sym = Symbol::create($2.is, sc_member);
 	  if (sym == 0) {
@@ -571,7 +594,7 @@
  * value switched on. 
  *
  * The union as a whole creates a named nested scope for further name
- * definitions (as does module, struct, and interface), but the
+ * top_definitions (as does module, struct, and interface), but the
  * individual case labels do not create further subscopes.
  */
 union_dcl:
@@ -606,17 +629,17 @@
 
 /**
  * Each case consists of one or more case labels, zero or more name
- * definitions (scoped to the union as a whole), and one element
- * declaration.  (Note: I would like to scope these definitions to the
- * case, but the case has no natural name.)
- */
-/** SHAP: I think that allowing definitions inside other definitions
- * is in general a bad idea, because the scoping rules need to be
- * honored in the output language and there are too many possible
- * scoping rule resolutions.
+ * top_definitions (scoped to the union as a whole), and one element
+ * declaration.  (Note: I would like to scope these top_definitions to
+ * the case, but the case has no natural name.)
+ */
+/** SHAP: I think that allowing top_definitions inside other
+ * top_definitions is in general a bad idea, because the scoping rules
+ * need to be honored in the output language and there are too many
+ * possible scoping rule resolutions.
  */
 case:
-        case_labels definitions element_dcl
+        case_labels top_definitions element_dcl
  ;
 
 case_labels:
@@ -787,6 +810,24 @@
 /******************* Interfaces / Capabilities **********************/
 
 
+/* SHAP: In CORBA, and interface is a scope. While it defines
+ * operations, it can also define structures, constants, and so
+ * forth. That is, all top-level declarables except for interfaces and
+ * modules can be declared within an interface scope. Interfaces and
+ * modules are distinguished in that the notion of "interface" in the
+ * CORBA IDL is "top level" (ignoring modules, which are optional),
+ * and so interfaces cannot contain interfaces.
+ *
+ * To implement this, I revised MarkM's original grammar to replace
+ * his <message> nonterminal with an <twoway_dcl> (which is what the
+ * CORBA 2.4.1 grammar called operation declarations) and
+ * re-introduced the original style of <interface> nonterminal with
+ * <if_definitions> and <if_definition> as intermediate nonterminals
+ * in place of <messages>. In some ways this is regrettable, as it
+ * renders the "what is a capability" question less clear -- an
+ * interface can now contain stuff in addition to the operations.
+ */
+
 /**
  * Defines a capability type.  The type of a capability is defined by
  * what you can send it.  By far the most common convention is to send
@@ -844,20 +885,24 @@
  */
 interface_dcl:
         INTERFACE name_def '(' type name_def ')'   // struct-level
- |      INTERFACE name_def '{' messages '}'        // message-levels
+ |      INTERFACE name_def '{' if_definitions '}'  // message-levels
  ;
 
-/**
- * Message declarations, interspersed with name definitions for this
- * scope 
- */
-messages:
- /*empty*/    {}
- |      messages message
+if_definitions:
+	if_definition
+ |      if_definitions if_definition
  ;
-message:
-        definition
- |      message_dcl
+
+if_definition:
+        struct_dcl ';'                          // a struct
+ |      except_dcl ';'                          // a struct to throw
+ |      union_dcl  ';'                          // a discriminated union
+ |      enum_dcl ';'                            // a set of const unsigneds
+ |      TYPEDEF type name_def ';'               // names a type
+ |      TYPEDEF name_def ';'                    // forward declaration
+ |      const_dcl ';'                           // constant value
+ |      opr_dcl ';'                             // an operation
+ |      repr_dcl ';'                            // advises on representation
  ;
 
 /**
@@ -865,9 +910,9 @@
  * created before any of the parameter symbols. This is necessary
  * because the function symbol forms a scope into which the parameters
  * must be installed. */
-message_dcl:
+opr_dcl:
         ONEWAY VOID name_def '(' {
-	  Symbol *sym = Symbol::create($2.is, sc_oneway);
+	  Symbol *sym = Symbol::create($3.is, sc_oneway);
 	  if (sym == 0) {
 	    Diag::printf("%s:%d: syntax error -- identifier reused\n",
 			 current_file.str(), current_line);
@@ -876,7 +921,7 @@
 	  /* Procedure name is a scope for its formals: */
 	  Symbol::PushScope(sym);
 	}
-        in_params ')' {
+        params ')' {
 	  Symbol::PopScope();
 	}
  |      ret_type name_def '(' {
@@ -901,18 +946,14 @@
  * capability type.
  */
 params:
- /*empty*/  {}
+        /*empty*/ {}
  |      param_list
  ;
 
 param_list:
-        in_param
- |      param_list ',' in_param
- ;
-
-in_param:
-	param
- |      IN param
+        param {}
+ |      param_list ',' param {
+	}
  ;
 
 /**
@@ -923,14 +964,7 @@
  * "messageName::parameterName" 
  */
 param:
-        type name_def {
-	  Symbol *sym = Symbol::create($2.is, sc_formal);
-	  if (sym == 0) {
-	    Diag::printf("%s:%d: syntax error -- identifier reused\n",
-			 current_file.str(), current_line);
-	  }
-	  sym->type = $1;
-	}
+        type name_def
  ;
 
 /**
@@ -943,18 +977,18 @@
 ret_type:
         type
  |      VOID {
-          $$ = KeywordScope->LookupChild(".void");
+	  $$ = KeywordScope->LookupChild(".void");
 	}
  ;
 
 param_2s:
- /*empty*/   {}
+        /*empty*/ {}
  |      param_2_list
  ;
 
 param_2_list:
-        param_2
- |      param_2_list ',' param_2
+        param_2 {}
+ |      param_2_list ',' param_2 {}
  ;
 
 /**
@@ -964,8 +998,10 @@
  * parameter. 
  */
 param_2:
-        in_param
- |      OUT param
+        param {}
+ |      OUT param {
+	  $2->cls = sc_outformal;
+	}
  ;
 
 /**