Discussion:
[omniORB] problem differentiating between Arrays and Sequences
Duncan Grisby
2009-08-11 19:27:13 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.
idltype.tk_array is never used. It's there for consistency with TypeCode
kinds and in case a back-end wants to use it.
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.)
You can do that, but beware of IDL like this:

struct S {
long a, b[10], c[5][6];
};

There, you have a single type with three declarators, one of which is a
scalar, one a single-dimensional array, and the other a two-dimensional
array.

That kind of IDL is the reason array-ness is part of the declarator and
not the type.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Tim Black
2009-08-11 22:22:13 UTC
Permalink
Thanks. The sizes-detection test for array-ness is working for me just
fine. Very good point about the multiple declarators. Luckily I am in
an organization that can just make an internal rule that says "only
one declaration per line!"

T
Post by Duncan Grisby
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.
idltype.tk_array is never used. It's there for consistency with TypeCode
kinds and in case a back-end wants to use it.
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.)
struct S {
long a, b[10], c[5][6];
};
There, you have a single type with three declarators, one of which is a
scalar, one a single-dimensional array, and the other a two-dimensional
array.
That kind of IDL is the reason array-ness is part of the declarator and
not the type.
Cheers,
Duncan.
--
-- Duncan Grisby --
-- http://www.grisby.org --
Loading...