diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-21 17:07:25 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-21 17:07:25 +0000 |
commit | 29c95e28918cd56b59d22d77a4b79fd050f4d5a3 (patch) | |
tree | c456ce3efab0a54b85291dfd7c927a4fc0089f27 | |
parent | d6aa24cd1fe8bfbc3c3532ba9a05536f00a31bfb (diff) | |
download | ATCD-29c95e28918cd56b59d22d77a4b79fd050f4d5a3.tar.gz |
Added gen_default_label_value() to be_visitor_union_branch.* and
added a call to this instead of gen_label_value() in code
generation of mutator method for a union branch if it is an
explicit default case.
-rw-r--r-- | TAO/TAO_IDL/be/be_union_branch.cpp | 63 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_visitor_union_branch/public_ci.cpp | 252 | ||||
-rw-r--r-- | TAO/TAO_IDL/be_include/be_union_branch.h | 11 |
3 files changed, 217 insertions, 109 deletions
diff --git a/TAO/TAO_IDL/be/be_union_branch.cpp b/TAO/TAO_IDL/be/be_union_branch.cpp index 2328d31b26d..0d185d6164e 100644 --- a/TAO/TAO_IDL/be/be_union_branch.cpp +++ b/TAO/TAO_IDL/be/be_union_branch.cpp @@ -100,6 +100,69 @@ be_union_branch::gen_label_value (TAO_OutStream *os, unsigned long index) } int +be_union_branch::gen_default_label_value (TAO_OutStream *os, + be_union *bu) +{ + be_union::DefaultValue dv; + + if (bu->default_value (dv) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch::" + "gen_default_label_value - " + "computing default value failed\n"), + -1); + } + + switch (bu->udisc_type ()) + { + case AST_Expression::EV_short: + *os << dv.u.short_val; + break; + case AST_Expression::EV_ushort: + *os << dv.u.ushort_val; + break; + case AST_Expression::EV_long: + *os << dv.u.long_val; + break; + case AST_Expression::EV_ulong: + *os << dv.u.ulong_val; + break; + case AST_Expression::EV_char: + os->print ("%d", dv.u.char_val); + break; + case AST_Expression::EV_bool: + *os << dv.u.bool_val; + break; + case AST_Expression::EV_any: + // The discriminant is an enum. Some compilers will + // not accept a numeric value assigned to this + // discriminant, so we must generate the string name. + { + AST_ConcreteType *act = bu->disc_type (); + be_enum *be = be_enum::narrow_from_decl (act); + + // The function value_to_name() takes care of adding + // any necessary scoping to the output. + *os << be->value_to_name (dv.u.enum_val); + break; + } + case AST_Expression::EV_longlong: + case AST_Expression::EV_ulonglong: + // unimplemented + default: + // error caught earlier. + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_union_branch::" + "gen_default_label_value - " + "bad or unimplemented discriminant type\n"), + -1); + } + + return 0; +} + +int be_union_branch::accept (be_visitor *visitor) { return visitor->visit_union_branch (this); diff --git a/TAO/TAO_IDL/be/be_visitor_union_branch/public_ci.cpp b/TAO/TAO_IDL/be/be_visitor_union_branch/public_ci.cpp index 2b07f832f3a..13629b7cf88 100644 --- a/TAO/TAO_IDL/be/be_visitor_union_branch/public_ci.cpp +++ b/TAO/TAO_IDL/be/be_visitor_union_branch/public_ci.cpp @@ -449,53 +449,59 @@ be_visitor_union_branch_public_ci::visit_predefined_type (be_predefined_type *no *os << " val) // set" << be_nl << "{" << be_idt_nl; // set the discriminant to the appropriate label + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; - - switch (node->pt ()) - { - case AST_PredefinedType::PT_pseudo: - if (!ACE_OS::strcmp (node->local_name ()->get_string (), "Object")) - { - *os << "this->u_." << ub->local_name () << "_ = new " - << "TAO_Object_Field_T<CORBA::Object," - << "CORBA::Object_var> (CORBA::Object::_duplicate (val));" - << be_uidt_nl; - } - else - { - *os << "this->u_." << ub->local_name () << "_ = " - << bt->name () << "::_duplicate (val);" << be_uidt_nl; - } - break; - - case AST_PredefinedType::PT_any: - *os << "this->u_." << ub->local_name () << "_ = new " - << bt->name () << " (val);" << be_uidt_nl; - break; - - case AST_PredefinedType::PT_void: - break; - - default: - *os << "// set the value" << be_nl - << "this->u_." << ub->local_name () - << "_ = val;" << be_uidt_nl; - } } else + // We have an explicit default case. { - // default label - // XXXASG - TODO + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); } - *os << "}" << be_nl; + + *os << ";" << be_nl; + + switch (node->pt ()) + { + case AST_PredefinedType::PT_pseudo: + if (!ACE_OS::strcmp (node->local_name ()->get_string (), "Object")) + { + *os << "this->u_." << ub->local_name () << "_ = new " + << "TAO_Object_Field_T<CORBA::Object," + << "CORBA::Object_var> (CORBA::Object::_duplicate (val));" + << be_uidt_nl; + } + else + { + *os << "this->u_." << ub->local_name () << "_ = " + << bt->name () << "::_duplicate (val);" << be_uidt_nl; + } + break; + + case AST_PredefinedType::PT_any: + *os << "this->u_." << ub->local_name () << "_ = new " + << bt->name () << " (val);" << be_uidt_nl; + break; + + case AST_PredefinedType::PT_void: + break; + + default: + *os << "// set the value" << be_nl + << "this->u_." << ub->local_name () + << "_ = val;" << be_uidt_nl; + } + + *os << "}\n\n"; switch (node->pt ()) { @@ -617,25 +623,31 @@ be_visitor_union_branch_public_ci::visit_sequence (be_sequence *node) << "{" << be_idt_nl; // set the discriminant to the appropriate label + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; - - *os << "this->u_." << ub->local_name () << "_ = new " - << bt->name () << " (val);" << be_uidt_nl; } else + // We have an explicit default case. { - // default label - // XXXASG - TODO + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); } - *os << "}" << be_nl; + + *os << ";" << be_nl; + + *os << "this->u_." << ub->local_name () << "_ = new " + << bt->name () << " (val);" << be_uidt_nl; + + *os << "}\n\n"; // readonly get method *os << "// readonly get method " << be_nl @@ -643,7 +655,7 @@ be_visitor_union_branch_public_ci::visit_sequence (be_sequence *node) << bu->name () << "::" << ub->local_name () << " (void) const" << be_nl << "{" << be_idt_nl << "return *this->u_." << ub->local_name () << "_;" << be_uidt_nl - << "}" << be_nl; + << "}\n\n"; // read/write get method *os << "// read/write get method " << be_nl @@ -684,25 +696,31 @@ be_visitor_union_branch_public_ci::visit_string (be_string *) << be_nl << "{" << be_idt_nl; // set the discriminant to the appropriate label + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; - - *os << "// set the value" << be_nl - << "this->u_." << ub->local_name () << "_ = val;" << be_uidt_nl; - } + } else + // We have an explicit default case. { - // default label - // XXXASG - TODO + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); } - *os << "}" << be_nl; + + *os << ";" << be_nl; + + *os << "// set the value" << be_nl + << "this->u_." << ub->local_name () << "_ = val;" << be_uidt_nl; + + *os << "}\n\n"; // (2) set method from const char * *os << "// accessor to set the member" << be_nl @@ -712,27 +730,31 @@ be_visitor_union_branch_public_ci::visit_string (be_string *) << "{\n"; os->incr_indent (); // set the discriminant to the appropriate label + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; - - *os << "// set the value" << be_nl - << "this->u_." << ub->local_name () << "_ = " - << "CORBA::string_dup (val);" << be_uidt_nl; } else + // We have an explicit default case. { - // default label - // XXXASG - TODO + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); } - *os << "}" << be_nl; + *os << ";" << be_nl; + + *os << "// set the value" << be_nl + << "this->u_." << ub->local_name () << "_ = " + << "CORBA::string_dup (val);" << be_uidt_nl; + *os << "}\n\n"; // (3) set from const String_var& *os << "// accessor to set the member" << be_nl @@ -741,28 +763,33 @@ be_visitor_union_branch_public_ci::visit_string (be_string *) << " (const CORBA::String_var &val)" << be_nl << "{" << be_idt_nl; // set the discriminant to the appropriate label + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; - - *os << "// set the value" << be_nl - << "CORBA::String_var " << ub->local_name () - << "_var = val;" << be_nl - << "this->u_." << ub->local_name () << "_ = " - << ub->local_name () << "_var._retn ();" << be_uidt_nl; } else + // We have an explicit default case. { - // default label - // XXXASG - TODO + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); } - *os << "}" << be_nl; + + *os << ";" << be_nl; + + *os << "// set the value" << be_nl + << "CORBA::String_var " << ub->local_name () + << "_var = val;" << be_nl + << "this->u_." << ub->local_name () << "_ = " + << ub->local_name () << "_var._retn ();" << be_uidt_nl; + *os << "}\n\n"; // get method *os << "ACE_INLINE const char *" << be_nl @@ -839,33 +866,39 @@ be_visitor_union_branch_public_ci::visit_structure (be_structure *node) << "{" << be_idt_nl; // set the discriminant to the appropriate label + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; + } + else + // We have an explicit default case. + { + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); + } - if (bt->size_type () == be_type::VARIABLE - || node->has_constructor ()) - { - *os << "this->u_." << ub->local_name () << "_ = new " - << bt->name () << " (val);" << be_uidt_nl; - } - else - { - *os << "this->u_." << ub->local_name () << "_ = val;" << be_uidt_nl; - } + *os << ";" << be_nl; + + if (bt->size_type () == be_type::VARIABLE + || node->has_constructor ()) + { + *os << "this->u_." << ub->local_name () << "_ = new " + << bt->name () << " (val);" << be_uidt_nl; } else { - // default label - // XXXASG - TODO + *os << "this->u_." << ub->local_name () << "_ = val;" << be_uidt_nl; } - *os << "}" << be_nl; + + *os << "}\n\n"; // readonly get method *os << "// readonly get method " << be_nl @@ -877,7 +910,7 @@ be_visitor_union_branch_public_ci::visit_structure (be_structure *node) *os << "return *this->u_." << ub->local_name () << "_;" << be_uidt_nl; else *os << "return this->u_." << ub->local_name () << "_;" << be_uidt_nl; - *os << "}" << be_nl; + *os << "}\n\n"; // read/write get method *os << "// read/write get method " << be_nl @@ -978,26 +1011,31 @@ be_visitor_union_branch_public_ci::visit_union (be_union *node) << bu->name () << "::" << ub->local_name () << " (const " << bt->name () << " &val)" << be_nl << "{" << be_idt_nl; + *os << "// set the discriminant val" << be_nl; + *os << "this->_reset ("; + if (ub->label ()->label_kind () == AST_UnionLabel::UL_label) { - *os << "// set the discriminant val" << be_nl; - *os << "this->_reset ("; ub->gen_label_value (os); *os << ", 0);" << be_nl << "this->disc_ = "; ub->gen_label_value (os); - *os << ";" << be_nl; - - *os << "this->u_." - << ub->local_name () << "_ = new " << bt->name () - << " (val);" << be_nl; } else + // We have an explicit default case. { - // default label - // XXXASG - TODO + ub->gen_default_label_value (os, bu); + *os << ", 0);" << be_nl + << "this->disc_ = "; + ub->gen_default_label_value (os, bu); } - *os << "}" << be_nl; + + *os << ";" << be_nl; + + *os << "this->u_." + << ub->local_name () << "_ = new " << bt->name () + << " (val);" << be_uidt_nl; + *os << "}\n\n"; // readonly get method *os << "// readonly get method " << be_nl @@ -1005,7 +1043,7 @@ be_visitor_union_branch_public_ci::visit_union (be_union *node) << bu->name () << "::" << ub->local_name () << " (void) const" << be_nl << "{" << be_idt_nl << "return *this->u_." << ub->local_name () << "_;" << be_uidt_nl - << "}" << be_nl; + << "}\n\n"; // read/write get method *os << "// read/write get method " << be_nl diff --git a/TAO/TAO_IDL/be_include/be_union_branch.h b/TAO/TAO_IDL/be_include/be_union_branch.h index 944049c7195..b334ea15c10 100644 --- a/TAO/TAO_IDL/be_include/be_union_branch.h +++ b/TAO/TAO_IDL/be_include/be_union_branch.h @@ -41,13 +41,20 @@ public: be_union_branch (void); // default constructor - be_union_branch (UTL_LabelList *ll, AST_Type *ft, UTL_ScopedName *n, + be_union_branch (UTL_LabelList *ll, + AST_Type *ft, + UTL_ScopedName *n, UTL_StrList *p); // constructor - int gen_label_value (TAO_OutStream *os, unsigned long index = 0); + int gen_label_value (TAO_OutStream *os, + unsigned long index = 0); // Generate the label value (as in a switch/case statement). + int gen_default_label_value (TAO_OutStream *os, + be_union *bu); + // Generate the default label value (as in a switch/case statement). + // Visiting virtual int accept (be_visitor *visitor); |