// Specialized visit_scope method for stucts only. int ifr_adding_visitor_structure::visit_scope (UTL_Scope *node) { // If the struct has members that are scopes but not structs, // the regular visit_scope method should be called instead. if (node->scope_node_type () != AST_Decl::NT_struct) { return ifr_adding_visitor::visit_scope (node); } AST_Structure *s = AST_Structure::narrow_from_scope (node); CORBA::ULong nfields = static_cast<CORBA::ULong> (s->nfields ()); this->members_.length (nfields); AST_Field **f = 0; try { // Visit each field. for (CORBA::ULong i = 0; i < nfields; ++i) { if (s->field (f, i) != 0) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::") ACE_TEXT ("visit_scope -") ACE_TEXT (" field node access failed\n")), -1); } AST_Type *ft = (*f)->field_type (); bool defined_here = ft->is_child (this->scope_); // If the struct member is defined in the struct, we have to // do some visiting - otherwise we can just look up the entry. if (defined_here) { if (ft->node_type () == AST_Decl::NT_struct) { // Since the enclosing scope hasn't been created yet, // we make a special visitor to create this member // at global scope and move it into the struct later. ifr_adding_visitor_structure visitor (ft); if (ft->ast_accept (&visitor) == -1) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::") ACE_TEXT ("visit_scope -") ACE_TEXT (" failed to accept visitor\n")), -1); } this->ir_current_ = CORBA::IDLType::_duplicate (visitor.ir_current ()); } else { if (ft->ast_accept (this) == -1) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::") ACE_TEXT ("visit_scope -") ACE_TEXT (" failed to accept visitor\n")), -1); } } } else { // Updates ir_current_. this->get_referenced_type (ft); } this->members_[i].name = CORBA::string_dup ((*f)->local_name ()->get_string ()); // IfR method create_struct does not use this - it just needs // to be non-zero for marshaling. this->members_[i].type = CORBA::TypeCode::_duplicate (CORBA::_tc_void); this->members_[i].type_def = CORBA::IDLType::_duplicate (this->ir_current_.in ()); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( ACE_TEXT ( "ifr_adding_visitor_structure::visit_scope")); return -1; } return 0; }
// Specialized visit_scope method for unions only. int ifr_adding_visitor_union::visit_scope (UTL_Scope *node) { // If the union has members that are scopes but not unions, // the regular visit_scope method should be called instead. if (node->scope_node_type () != AST_Decl::NT_union) { return ifr_adding_visitor::visit_scope (node); } AST_Union *u = AST_Union::narrow_from_scope (node); CORBA::ULong nfields = static_cast<CORBA::ULong> (u->nfields ()); this->members_.length (nfields); AST_Field **f = 0; // Index into members_. CORBA::ULong index = 0; try { // Visit each field. for (CORBA::ULong i = 0; i < nfields; ++i) { if (u->field (f, i) != 0) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_union::") ACE_TEXT ("visit_scope -") ACE_TEXT (" field node access failed\n") ), -1 ); } AST_Type *ft = (*f)->field_type (); bool defined_here = ft->is_child (this->scope_); // If the union member is defined in the union, we have to // do some visiting - otherwise we can just look up the entry. if (defined_here) { if (ft->node_type () == AST_Decl::NT_union) { // Since the enclosing scope hasn't been created yet, // we make a special visitor to create this member // at global scope and move it into the union later. ifr_adding_visitor_union visitor (ft); if (ft->ast_accept (&visitor) == -1) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_union::") ACE_TEXT ("visit_scope -") ACE_TEXT (" failed to accept visitor\n")), -1); } this->ir_current_ = CORBA::IDLType::_duplicate (visitor.ir_current ()); } else { if (ft->ast_accept (this) == -1) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_union::") ACE_TEXT ("visit_scope -") ACE_TEXT (" failed to accept visitor\n")), -1); } } } else { // Updates ir_current_. this->get_referenced_type (ft); } // Get the case label(s). AST_UnionLabel *case_label = 0; AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (*f); unsigned long len = ub->label_list_length (); // If there are multiple case labels, we will have an element // in the UnionMemberSeq for each label, not just for each member, // so the list length and the loop terminator must both be // increased accordingly. if (len > 1) { this->members_.length (this->members_.length () + len - 1); } for (unsigned long j = 0; j < len; ++j) { case_label = ub->label (j); // Is this a regular label or default label? if (case_label->label_kind () == AST_UnionLabel::UL_label) { AST_Expression::AST_ExprValue *ev = case_label->label_val ()->ev (); // If the discriminator is an enum, we can't just insert // a ulong into the Any member of struct UnionMember. if (u->disc_type ()->node_type () == AST_Decl::NT_enum) { TAO_OutputCDR cdr; cdr.write_ulong (ev->u.ulval); TAO_InputCDR in_cdr (cdr); TAO::Unknown_IDL_Type *unk = 0; ACE_NEW_RETURN (unk, TAO::Unknown_IDL_Type ( this->disc_tc_.in (), in_cdr), -1); this->members_[index].label.replace (unk); } else { this->load_any (ev, this->members_[index].label); } } else // Default case label. { this->members_[index].label <<= CORBA::Any::from_octet (0); } this->members_[index].name = CORBA::string_dup ((*f)->local_name ()->get_string ()); // IfR method create_union does not use this - it just needs // to be non-zero for marshaling. this->members_[index].type = CORBA::TypeCode::_duplicate (CORBA::_tc_void); this->members_[index++].type_def = CORBA::IDLType::_duplicate (this->ir_current_.in ()); } } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( ACE_TEXT ( "ifr_adding_visitor_union::visit_scope")); return -1; } return 0; }