3

I have the following CORBA IDL 3.2, which attempts to declare a mutually recursive structure:

module SE
{
  interface SE
  {

typedef unsigned short MenuItemID; // a small integer representing a unique menu item

enum MenuSubaction { CollectCharacter, CollectStruct };

struct MenuItemAction;   // forward declaration

union MenuSubactionParameter switch (MenuSubaction)
{  case CollectStruct:  MenuItemAction sub_structure;    // <<<<<<<<< use of forward
};

struct MenuItemAction {   MenuSubaction menu_subaction;
              MenuSubactionParameter menu_subaction_parameter;
              };
  }; // interface
}; // module

I get a complaint from Sun JDK 1.7 idlj on the line marked with <<<<<

 ... SE.idl (line xx): Illegal reference to incomplete forward declaration of type MenuItemAction.

Note: this isn't a "forward interface" declaration.

What's an "incomplete forward declaration"? (If you successfully declared as a forward declaration, I wouldn't think the forward declaration as incomplete, just not yet defined. Maybe that's just an easy to misinterpret phrase).

More importantly, how do I manage to define my recursive structure?

I'm new to CORBA, so I don't really :-} know what I'm doing. I don't see why CORBA can't define such recursive structures; one transmits a particular instance that won't be recursive. In particular, this one forms a tree, which should be "easy" for CORBA to send.

EDIT: Brian had the right answer. I needed to replace the direct mention of the forward reference,

         MenuItemAction sub_structure

with

         sequence<MenuItemAction> sub_structure>  
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • I don't think you can have a module and an interface with the same name. You are also missing some closing braces in your IDL. Can you clean up the code? – Brian Neal Jun 25 '13 at 01:01
  • I tried to post an answer but my knowledge of this area is a bit stretched. In the meantime you can check this link out, it might be helpful. http://sandeshudupa.blogspot.com/2006/04/structure-declaration-in-idl-and-its-c.html – Brian Neal Jun 25 '13 at 02:09
  • http://www.cs.uic.edu/~troy/fall04/cs441/drake/CORBA.html says "IDL supports forward declaration of constructed types, e.g. struct Point; ". Your link also show this is valid, at least in a Sequence. I can't imagine, if they can support Sequence, they can't support a sequence of exactly *one* element, and thus directly the struct itself. – Ira Baxter Jun 25 '13 at 02:11
  • But only as an "operation parameter type or a sequence element type before its complete declaration appears". – Brian Neal Jun 25 '13 at 02:13
  • Ok, I undeleted my answer and tried again. – Brian Neal Jun 25 '13 at 02:19
  • idlj accepts a module and interface with the same name just fine; their HelloWorld example names both parts "HelloWorld". I fixed the braces but I don't think that affects anything; I get the error before they are processed. Yes, your link hints that only thing allowed is a Sequence which I don't do. I'll try to dig some more in the IDL docs. – Ira Baxter Jun 25 '13 at 02:20
  • omniORB complains about the interface name clashing with the module name. – Brian Neal Jun 25 '13 at 02:23
  • In versions of this file where I'm not using the forward declaration, I get clean compiles with idlj from JDK 1.7.22(?), with identical interface and module names. omniORB would be perfectly self-consistent/safe if it enforced its rule, I think, so maybe that's why it complains. – Ira Baxter Jun 25 '13 at 02:30
  • In my copy of the CORBA spec it says "The name of an interface, value type, struct, union, exception or a module may not be redefined within the immediate scope of the interface, value type, struct, union, exception, or the module." I have no experience with your ORB but I know omniORB is very conformant. – Brian Neal Jun 25 '13 at 02:41

2 Answers2

1

It seems to be a known bug "4754974 : idlj does not support forward declaration of struct and unions": http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4754974

after the comments above i tried out:

module SE
{
  interface SE
  {

    typedef unsigned short MenuItemID; // a small integer representing a unique menu item

    enum MenuSubaction { CollectCharacter, CollectStruct };

    struct MenuItemAction;   // forward declaration

    union MenuSubactionParameter switch (MenuSubaction)
    {
      case CollectStruct:  sequence<MenuItemAction> sub_structure;    // <<<<<<<<< use of forward
    };

    struct MenuItemAction {
      MenuSubaction menu_subaction;
      MenuSubactionParameter menu_subaction_parameter;
  };
}; // interface

which works.You'll end up with a sequence instead of a single record but for pratical purposes that might not be an issue.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • That bug report is mildly interesting, but it dates from 2002, so there's been plenty of time to fix it, and it is marked as "resolved" apparantly in 2004. Nice try. – Ira Baxter Jun 23 '13 at 14:42
  • struct forward references are not even conformant to CORBA IDL syntax see rule 50 in http://www.sce.carleton.ca/netmanage/corba/idlsyn.htm (50) ::= "struct" "{" "}" I know that IBM was on of the first vendors ignoring this fact. Sun seems to have tried the same. – Wolfgang Fahl Jun 24 '13 at 16:38
  • I'm not sure I understood what you just told me. Are you saying the forward reference declaration in my provided example is correct? idlj doesn't object to it; it objects later. Your example of struct syntax looks fine... for a full structure declaration; why one would need all that stuff for a forward declaration, where the point is to leave that stuff out? "I know IBM ... ignore this (what?) fact". – Ira Baxter Jun 25 '13 at 00:25
1

You can forward declare structs, but there are many restrictions.

Edit: I don't know what version of CORBA you are using, but in the 2.6.1 specification it says in section 3.10.2.3 (emphasis mine):

The IDL syntax allows the generation of recursive structures and unions via members that have a sequence type.

And later:

IDL supports recursive types via a forward declaration for structures and unions (as well as for valuetypes).

And later:

An incomplete type can only appear as the element type of a sequence definition. A sequence with incomplete element type is termed an incomplete sequence type.

An incomplete sequence type can appear only as the element type of another sequence, or as the member type of a structure or union definition.

Example:

struct Foo; // Forward declaration; Foo is incomplete
typedef sequence<Foo> FooSeq;  // incomplete sequence type
struct Foo {
   long value;
   FooSeq chain; // incomplete seq. type used as struct member; OK
};

Much more information can be found in the link, including this example, which may be closer to what you want to do:

union Bar; // Forward declaration
typedef sequence<Bar> BarSeq;

union Bar switch(long) { // Define incomplete union
   case 0:
      long l_mem;
   case 1:
   struct Foo {
      double d_mem;
      BarSeq nested; // OK, recurse on enclosing
                     // incomplete type
   } s_mem;
};
Community
  • 1
  • 1
Brian Neal
  • 31,821
  • 7
  • 55
  • 59
  • I'll try this just to see a forward struct work, but you're right, its not what I want. There's lots of dicussion about how interfaces can have forward declarations; structs (from my point of view, similar to C++), are just weak objects/interfaces. I guess the notion of nested struct-as-value has to be disallowed; that would make an infinitely big data structure, so what one needs is struct-as-reference (which is how it works in C) and that's not possible to say in IDL directly. Probably that's why interfaces are different than structs; they are treated effectively as references... – Ira Baxter Jun 25 '13 at 02:25
  • ... and maybe that's the justification for Sequence. – Ira Baxter Jun 25 '13 at 02:26
  • I'll have to wait until tomorrow to check this out, I not on my dev system. – Ira Baxter Jun 25 '13 at 02:32
  • I just updated my answer with references to the CORBA spec. Sorry, should have done that from the beginning. – Brian Neal Jun 25 '13 at 02:36
  • OK, there's chapter and verse. So I assume tomorrow's experiment will succeed :-} – Ira Baxter Jun 25 '13 at 02:38