Discussion:
[omniORB] resolving const and enum symbol names in AST
Tim Black
2009-08-20 06:11:36 UTC
Permalink
I am using omniIDL for generating some non-CORBA application-specific code.
The problem I'm having is that when const or enum symbols are used in .idl,
the resulting AST passed to my back-end seems to always have pre-substituted
the values of these symbols. This will give the desired machine code when
compiled, but is not always optimal in terms of clarity of the generated
code. To illustrate, consider the following .idl:

// myObject.idl:
module myObject {
const int arySize = 4;
const int seqSize = arySize;
struct myStruct {
int a[arySize];
}
sequence<float, seqSize> mySeq;
}

In the back end, when parsing the AST nodes that are defined using one of
these const symbols (seqSize, myStruct.a, or mySeq), there appears to be no
reference to the name of the symbol. Only the value. So my back end has no
choice but to generate a corresponding C++ class something like:

// myObject.h:
namespace myObject {
const int arySize = 4;
const int seqSize = 4;
struct myStruct {
int a[4];
}
sequence<float, 4> mySeq;
}

This is OK, but it would be more clear if it could use the actual symbol in
the generated code, something like:

// myObject.h:
namespace myObject {
const int arySize = 4;
const int seqSize = arySize;
struct myStruct {
int a[arySize];
}
sequence<float, seqSize> mySeq;
}

I realize this is merely an aesthetic issue, but does anyone know a way to
achieve what I am trying to achieve here?

Thanks,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20090819/ea35afc6/attachment.htm
Duncan Grisby
2009-08-28 15:54:00 UTC
Permalink
Post by Tim Black
I am using omniIDL for generating some non-CORBA application-specific code.
The problem I'm having is that when const or enum symbols are used in .idl,
the resulting AST passed to my back-end seems to always have pre-substituted
the values of these symbols. This will give the desired machine code when
compiled, but is not always optimal in terms of clarity of the generated code.
[...]
Post by Tim Black
In the back end, when parsing the AST nodes that are defined using one of
these const symbols (seqSize, myStruct.a, or mySeq), there appears to be no
reference to the name of the symbol. Only the value. So my back end has no
You're right. Where constants are used in array sizes, etc., omniidl
just gives the back-end the value, not the symbolic expression that
leads to it. It's not as simple as just including the name, because
you're allowed to do arithmetic. This is valid IDL, for example:

const long one = 1;
const long two = 2;
const long three = 3;

typedef string StringArray[one + two * three];

To allow symbolic expressions in arrays etc., omniidl would have to pass
the whole expression through, not just a name. Clearly that could be
done, but there has never been a compelling reason to do it.

Feel free to tinker with the front-end code...

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...