[omniORB] omniidl2 and unions
J. Cameijo Cerdeira
jverissi@mail.telepac.pt
Thu, 25 Feb 1999 15:11:42 +0000
This is a multi-part message in MIME format.
--------------6F3E63743B4B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello,
I've started playing with omniORB and noticed the idl compiler rejects
the following idl file (which must be correct since it's borrowed from
the corba 2 spec) complaining about the redefinition of U::w :
module dummy {
typedef octet Bytes[64];
struct S { short s; };
interface A;
union U switch (long) {
case 1: long x;
case 2: Bytes y;
case 3: string z;
case 4:
case 5: S w;
default: A obj;
};
};
in fact omniidl2 interprets the above union as
union U switch (long) {
case 1: long x;
case 2: Bytes y;
case 3: string z;
case 4: S w;
case 5: S w;
default: A obj;
};
I think this is a bug in omniidl2 isn't it ?
Anyway i've hacked the src a little bit and came up with the following
quick'n'dirty patch which i think solves the problem (i've not done an
extensive testing, though).
J. Cameijo Cerdeira
--------------6F3E63743B4B
Content-Type: text/plain; charset=us-ascii; name="lixo"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="lixo"
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/ast/ast_generator.cc newsrc1/tool/omniidl2/ast/ast_generator.cc
*** src/tool/omniidl2/ast/ast_generator.cc Tue Dec 9 20:04:24 1997
--- newsrc1/tool/omniidl2/ast/ast_generator.cc Thu Feb 25 12:11:17 1999
***************
*** 230,238 ****
AST_Generator::create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p)
{
! return new AST_UnionBranch(lab, ft, n, p);
}
/*
--- 230,239 ----
AST_Generator::create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p,
! bool multilabel)
{
! return new AST_UnionBranch(lab, ft, n, p, multilabel);
}
/*
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/ast/ast_union.cc newsrc1/tool/omniidl2/ast/ast_union.cc
*** src/tool/omniidl2/ast/ast_union.cc Tue Apr 7 19:09:27 1998
--- newsrc1/tool/omniidl2/ast/ast_union.cc Thu Feb 25 14:28:34 1999
***************
*** 327,332 ****
--- 327,334 ----
{
AST_Decl *d;
+
+ //cerr<<"#$# fe_add_union_branch, multilabel = "<<t->multilabel()<<endl;
/*
* If this is a malformed branch, don't do anything with it
*/
***************
*** 339,344 ****
--- 341,348 ----
idl_global->err()->error2(UTL_Error::EIDL_MULTIPLE_BRANCH, this, t);
return NULL;
}
+
+ if ( !t->multilabel() ) {
/*
* If branch with same field name exists, complain
*/
***************
*** 356,361 ****
--- 360,367 ----
return NULL;
}
}
+ }
+
/*
* Add it to scope
*/
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/ast/ast_union_branch.cc newsrc1/tool/omniidl2/ast/ast_union_branch.cc
*** src/tool/omniidl2/ast/ast_union_branch.cc Tue Apr 7 19:09:47 1998
--- newsrc1/tool/omniidl2/ast/ast_union_branch.cc Thu Feb 25 11:56:04 1999
***************
*** 83,92 ****
}
AST_UnionBranch::AST_UnionBranch(AST_UnionLabel *fl, AST_Type *ft,
! UTL_ScopedName *n, UTL_StrList *p)
: AST_Field(AST_Decl::NT_union_branch, ft, n, p),
AST_Decl(AST_Decl::NT_union_branch, n, p),
! pd_label(fl)
{
}
--- 83,92 ----
}
AST_UnionBranch::AST_UnionBranch(AST_UnionLabel *fl, AST_Type *ft,
! UTL_ScopedName *n, UTL_StrList *p, bool multilabel)
: AST_Field(AST_Decl::NT_union_branch, ft, n, p),
AST_Decl(AST_Decl::NT_union_branch, n, p),
! pd_label(fl), multilabel_(multilabel)
{
}
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/fe/idl.yy newsrc1/tool/omniidl2/fe/idl.yy
*** src/tool/omniidl2/fe/idl.yy Mon Dec 14 11:04:23 1998
--- newsrc1/tool/omniidl2/fe/idl.yy Thu Feb 25 12:25:59 1999
***************
*** 1444,1458 ****
* Add them to the enclosing scope (the union scope)
*/
if (s != NULL && $1 != NULL && $3 != NULL) {
l = new UTL_LabellistActiveIterator($1);
! for (;!(l->is_done()); l->next()) {
d = l->item();
if (d == NULL)
continue;
b = idl_global->gen()->create_union_branch(d,
f->field_type(),
f->name(),
! f->pragmas());
(void) s->fe_add_union_branch(b);
}
delete l;
--- 1444,1461 ----
* Add them to the enclosing scope (the union scope)
*/
if (s != NULL && $1 != NULL && $3 != NULL) {
+ register int i;
l = new UTL_LabellistActiveIterator($1);
! for (i = 0;!(l->is_done()); l->next()) {
d = l->item();
if (d == NULL)
continue;
b = idl_global->gen()->create_union_branch(d,
f->field_type(),
f->name(),
! f->pragmas(),
! i > 0);
! i++;
(void) s->fe_add_union_branch(b);
}
delete l;
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/include/ast_generator.hh newsrc1/tool/omniidl2/include/ast_generator.hh
*** src/tool/omniidl2/include/ast_generator.hh Tue Dec 9 20:07:16 1997
--- newsrc1/tool/omniidl2/include/ast_generator.hh Thu Feb 25 12:20:34 1999
***************
*** 156,162 ****
virtual AST_UnionBranch *create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p);
// Create a node representing a label on a union branch
virtual AST_UnionLabel *create_union_label(AST_UnionLabel::UnionLabel ul,
--- 156,163 ----
virtual AST_UnionBranch *create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p,
! bool multilabel);
// Create a node representing a label on a union branch
virtual AST_UnionLabel *create_union_label(AST_UnionLabel::UnionLabel ul,
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/include/ast_union_branch.hh newsrc1/tool/omniidl2/include/ast_union_branch.hh
*** src/tool/omniidl2/include/ast_union_branch.hh Tue Apr 7 19:20:22 1998
--- newsrc1/tool/omniidl2/include/ast_union_branch.hh Thu Feb 25 11:55:20 1999
***************
*** 86,97 ****
AST_UnionBranch(AST_UnionLabel *label,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p);
virtual ~AST_UnionBranch() {}
// Data Accessors
AST_UnionLabel *label();
!
// Narrowing
DEF_NARROW_METHODS1(AST_UnionBranch, AST_Field);
DEF_NARROW_FROM_DECL(AST_UnionBranch);
--- 86,99 ----
AST_UnionBranch(AST_UnionLabel *label,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p,
! bool multilabel = false);
virtual ~AST_UnionBranch() {}
// Data Accessors
AST_UnionLabel *label();
! bool multilabel() { return multilabel_; }
!
// Narrowing
DEF_NARROW_METHODS1(AST_UnionBranch, AST_Field);
DEF_NARROW_FROM_DECL(AST_UnionBranch);
***************
*** 102,107 ****
--- 104,110 ----
private:
// Data
AST_UnionLabel *pd_label; // Label of this branch
+ bool multilabel_;
};
#endif // _AST_UNION_BRANCH_AST_UNION_BRAN_HH
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/omniORB2_be/o2be.h newsrc1/tool/omniidl2/omniORB2_be/o2be.h
*** src/tool/omniidl2/omniORB2_be/o2be.h Tue Feb 23 11:05:04 1999
--- newsrc1/tool/omniidl2/omniORB2_be/o2be.h Thu Feb 25 12:28:42 1999
***************
*** 460,466 ****
public:
o2be_union_branch(AST_UnionLabel *lab, AST_Type *ft, UTL_ScopedName *n,
! UTL_StrList *p);
DEF_NARROW_METHODS1(o2be_union_branch, AST_UnionBranch);
DEF_NARROW_FROM_DECL(o2be_union_branch);
--- 460,466 ----
public:
o2be_union_branch(AST_UnionLabel *lab, AST_Type *ft, UTL_ScopedName *n,
! UTL_StrList *p, bool multilabel);
DEF_NARROW_METHODS1(o2be_union_branch, AST_UnionBranch);
DEF_NARROW_FROM_DECL(o2be_union_branch);
***************
*** 1379,1385 ****
create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p);
virtual AST_Constant *
create_constant(AST_Expression::ExprType et,
--- 1379,1386 ----
create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p,
! bool multilabel);
virtual AST_Constant *
create_constant(AST_Expression::ExprType et,
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/omniORB2_be/o2be_generator.cc newsrc1/tool/omniidl2/omniORB2_be/o2be_generator.cc
*** src/tool/omniidl2/omniORB2_be/o2be_generator.cc Thu Aug 13 22:53:06 1998
--- newsrc1/tool/omniidl2/omniORB2_be/o2be_generator.cc Thu Feb 25 12:22:05 1999
***************
*** 144,152 ****
o2be_generator::create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p)
{
! return (AST_UnionBranch *) new o2be_union_branch(lab, ft, n, p);
}
AST_Constant *
--- 144,153 ----
o2be_generator::create_union_branch(AST_UnionLabel *lab,
AST_Type *ft,
UTL_ScopedName *n,
! UTL_StrList *p,
! bool multilabel)
{
! return (AST_UnionBranch *) new o2be_union_branch(lab, ft, n, p, multilabel);
}
AST_Constant *
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/omniORB2_be/o2be_union.cc newsrc1/tool/omniidl2/omniORB2_be/o2be_union.cc
*** src/tool/omniidl2/omniORB2_be/o2be_union.cc Mon Jan 18 13:47:35 1999
--- newsrc1/tool/omniidl2/omniORB2_be/o2be_union.cc Thu Feb 25 12:46:57 1999
***************
*** 562,569 ****
while (!i.is_done())
{
AST_Decl* d = i.item();
! if (d->node_type() == AST_Decl::NT_union_branch)
{
o2be_field *f = o2be_union_branch::narrow_from_decl(d);
o2be_operation::argMapping mapping;
o2be_operation::argType ntype;
--- 562,582 ----
while (!i.is_done())
{
AST_Decl* d = i.item();
! if (d->node_type() == AST_Decl::NT_union_branch &&
! !AST_UnionBranch::narrow_from_decl(d)->multilabel() )
{
+ /*
+ cerr <<"#$# AST_UnionBranch before narrowing"<<endl;
+ AST_UnionBranch *b = AST_UnionBranch::narrow_from_decl(d);
+ cerr <<"#$# AST_UnionBranch "<<b<<endl;
+ if ( b != NULL ) {
+ if ( b->multilabel() ) {
+ cerr <<"#$# AST_UnionBranch "<<b->multilabel()<<endl;
+ continue;
+ }
+ }
+ */
+
o2be_field *f = o2be_union_branch::narrow_from_decl(d);
o2be_operation::argMapping mapping;
o2be_operation::argType ntype;
***************
*** 1153,1159 ****
while (!i.is_done())
{
AST_Decl* d = i.item();
! if (d->node_type() == AST_Decl::NT_union_branch)
{
o2be_field *f = o2be_union_branch::narrow_from_decl(d);
o2be_operation::argMapping mapping;
--- 1166,1173 ----
while (!i.is_done())
{
AST_Decl* d = i.item();
! if (d->node_type() == AST_Decl::NT_union_branch &&
! !AST_UnionBranch::narrow_from_decl(d)->multilabel() )
{
o2be_field *f = o2be_union_branch::narrow_from_decl(d);
o2be_operation::argMapping mapping;
***************
*** 1222,1228 ****
while (!i.is_done())
{
AST_Decl* d = i.item();
! if (d->node_type() == AST_Decl::NT_union_branch)
{
o2be_field *f = o2be_union_branch::narrow_from_decl(d);
o2be_operation::argMapping mapping;
--- 1236,1243 ----
while (!i.is_done())
{
AST_Decl* d = i.item();
! if (d->node_type() == AST_Decl::NT_union_branch &&
! !AST_UnionBranch::narrow_from_decl(d)->multilabel() )
{
o2be_field *f = o2be_union_branch::narrow_from_decl(d);
o2be_operation::argMapping mapping;
diff -x y.tab.cc -x lex.yy.cc -x *.o -x *.a -rc src/tool/omniidl2/omniORB2_be/o2be_union_branch.cc newsrc1/tool/omniidl2/omniORB2_be/o2be_union_branch.cc
*** src/tool/omniidl2/omniORB2_be/o2be_union_branch.cc Thu Aug 13 22:47:57 1998
--- newsrc1/tool/omniidl2/omniORB2_be/o2be_union_branch.cc Thu Feb 25 12:24:10 1999
***************
*** 47,56 ****
#endif
o2be_union_branch::o2be_union_branch(AST_UnionLabel *lab, AST_Type *ft,
! UTL_ScopedName *n, UTL_StrList *p)
: AST_Decl(AST_Decl::NT_union_branch, n, p),
AST_Field(AST_Decl::NT_union_branch, ft, n, p),
! AST_UnionBranch(lab, ft, n, p),
o2be_field(ft,n,p),
o2be_name(AST_Decl::NT_union_branch, n, p)
{
--- 47,56 ----
#endif
o2be_union_branch::o2be_union_branch(AST_UnionLabel *lab, AST_Type *ft,
! UTL_ScopedName *n, UTL_StrList *p, bool multilabel)
: AST_Decl(AST_Decl::NT_union_branch, n, p),
AST_Field(AST_Decl::NT_union_branch, ft, n, p),
! AST_UnionBranch(lab, ft, n, p, multilabel),
o2be_field(ft,n,p),
o2be_name(AST_Decl::NT_union_branch, n, p)
{
Binary files src/tool/omniidl2/omniidl2 and newsrc1/tool/omniidl2/omniidl2 differ
--------------6F3E63743B4B--