Discussion:
[omniORB] problem differentiating between Arrays and Sequences
Tim Black
2009-07-30 09:40:10 UTC
Permalink
The CORBA Core Spec has separate syntax for Arrays and Sequences. Sequences
are variable-length, and may optionally have a bound:

sequence<long> UnboundLongs;
sequence<long, 10> BoundLongs;

Arrays are fixed-length sequences, defined thusly:

long ExactlyTenLongs[10];

In omniIDL documentation, I can see that there is no mention of this
fixed-length Array type. However, I can see that there is a type kind for
arrays: idltype.tk_array. But when I visit an IDL array (e.g.
ExactlyTenLongs above) in my back end, the type comes out looking like a
bounded sequence, i.e. the type of the corresponding AST node is an instance
of class Sequence, it's self.__kind is tk_sequence, not tk_array, and bound
= 10. What gives? Does omniIDL not support the CORBA array construct?

Being able to differentiate between arrays and sequences is useful because
you can map IDL arrays to C-style arrays which use the stack, and map IDL
sequences to C++-style vectors, which will use the heap. I assume this is
the reason why CORBA spec differentiates between the two types.

Thoughts?

Thanks,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20090729/898e52ec/attachment.htm
Duncan Grisby
2009-07-30 21:19:43 UTC
Permalink
Post by Tim Black
sequence<long> UnboundLongs;
sequence<long, 10> BoundLongs;
long ExactlyTenLongs[10];
In omniIDL documentation, I can see that there is no mention of this
fixed-length Array type. However, I can see that there is a type kind for
arrays: idltype.tk_array. But when I visit an IDL array (e.g. ExactlyTenLongs
above) in my back end, the type comes out looking like a bounded sequence,
i.e. the type of the corresponding AST node is an instance of class Sequence,
it's self.__kind is tk_sequence, not tk_array, and bound = 10. What gives?
Does omniIDL not support the CORBA array construct?
What exactly does your IDL look like? I don't know why you're meeting a
sequence unless you have an array of a sequence type.

Arrays are handled differently from sequences, because the semantics of
declaring them in IDL are different. Places you can use an array are a
Declarator, and the Declarator class has a sizes() method that returns a
list of array sizes. It's done that way to support nasty but valid IDL
like this:

typedef long one, two[10], three[20][30];

It's documented (briefly) in the section about omniidl.idlast.Declarator.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Tim Black
2009-07-31 02:46:27 UTC
Permalink
OK, thanks. I see that array-ness is specified in Declarator.sizes().
Is this the only place array-ness is specified? Is idltype.tk_array
never used? I tend to use type.kind() to determine what kind of
declaration I'm dealing with, so for example, I can treat an int
struct member differently than an array struct member when I generate
code.

It seems like I could just modify visitDeclarator() to set my
visitor's self.__result_typekind = idltype.tk_array when it sees a
declarator with len(sizes) > 0. I need to do something different to
detect array-ness, because just visiting the type is not enough.
Visiting the type just tells me what it is an array of. (Bc it seems
the type objects know nothing about sizes.)

I apologize - I misinterpreted some of my back-end observations. My
visitor is not seeing a sequence type corresponding to an array
declaration in IDL. (I actually had a valid bounded sequence in my IDL
that I was visiting) When you visit an array in the AST, its type
corresponds to what the array elements are. So, as stated above, to
determine array-ness you have to look at decl.sizes().

Please let me know if you see any holes in my reasoning.

Thanks,
Tim
Post by Tim Black
sequence<long> UnboundLongs;
sequence<long, 10> BoundLongs;
long ExactlyTenLongs[10];
In omniIDL documentation, I can see that there is no mention of this
fixed-length Array type. However, I can see that there is a type kind for
arrays: idltype.tk_array. But when I visit an IDL array (e.g. ExactlyTenLongs
above) in my back end, the type comes out looking like a bounded sequence,
i.e. the type of the corresponding AST node is an instance of class Sequence,
it's self.__kind is tk_sequence, not tk_array, and bound = 10. What gives?
Does omniIDL not support the CORBA array construct?
What exactly does your IDL look like? ?I don't know why you're meeting a
sequence unless you have an array of a sequence type.
Arrays are handled differently from sequences, because the semantics of
declaring them in IDL are different. Places you can use an array are a
Declarator, and the Declarator class has a sizes() method that returns a
list of array sizes. It's done that way to support nasty but valid IDL
?typedef long one, two[10], three[20][30];
It's documented (briefly) in the section about omniidl.idlast.Declarator.
Cheers,
Duncan.
--
?-- Duncan Grisby ? ? ? ? --
? -- http://www.grisby.org --
Loading...