void be_exception::Generate (be_ClientImplementation& source) { ostream & os = source.Stream(); be_Tab tab (source); UTL_String * repID = get_decl_pragmas().get_repositoryID(); const DDS_StdString corbaException = "DDS::Exception"; // convenience constructor if (nmembers()) { GenerateConvenienceConstructor(source); } // copy constructor GenerateCopyConstructor (source); // assignment operator GenerateAssignmentOperator (source); be_CodeGenerator::Generate (source); // name and id assert (repID); os << "const char * " << ScopedName () << "::m_name = \"" << LocalName () << "\";" << nl << nl; os << "const char * " << ScopedName () << "::m_id = \"" << repID->get_string () << "\";" << nl << nl; // downcast os << tab << ScopedName () << " * "; os << ScopedName () << "::"; os << "_downcast (DDS::Exception * e)" << nl; os << tab << "{" << nl; tab.indent (); os << tab << "if (e && (e->_rep_id () == m_id))" << nl; os << tab << "{" << nl; tab.indent (); os << tab << "return static_cast < " << LocalName () << "*> (e);" << nl; tab.outdent (); os << tab << "}" << nl; os << tab << "return 0;" << nl; tab.outdent (); os << tab << "}" << nl << nl; // const downcast os << tab << "const " << ScopedName() << " * "; os << ScopedName () << "::"; os << "_downcast (const DDS::Exception * e)" << nl; os << tab << "{" << nl; tab.indent (); os << tab << "if (e && (e->_rep_id () == m_id))" << nl; os << tab << "{" << nl; tab.indent (); os << tab << "return static_cast < " << LocalName () << "*> ((" << LocalName () << "*) e);" << nl; tab.outdent (); os << tab << "}" << nl; os << tab << "return 0;" << nl; tab.outdent (); os << tab << "}" << nl << nl; // _clone os << tab << corbaException << " * " << ScopedName (); os << "::_clone () const" << nl; os << tab << "{" << nl; tab.indent (); os << tab << "return (" << corbaException << "*) new "; os << ScopedName () << " (*this);" << nl; tab.outdent (); os << tab << "}" << nl << nl; // raise os << tab << "void " << ScopedName () << "::_raise (" << XBE_Ev::arg (XBE_ENV_ARG1) << ") const" << nl; os << tab << "{" << nl; tab.indent (); os << tab; XBE_Ev::throwex (os, "*this"); os << nl; tab.outdent (); os << tab << "}" << nl << nl; // factory os << tab << "DDS::Exception * " << ScopedName() << "::factory ()" << nl; os << tab << "{" << nl; tab.indent (); os << tab << "return new " << ScopedName () << ";" << nl; tab.outdent (); os << tab << "}" << nl << nl; // initilaizer os << "DDS::ExceptionInitializer " << ScopedName() << "::m_initializer ("; os << "\"" << repID->get_string () << "\""; os << ", " << ScopedName () << "::factory);" << nl; }
// Dump this AST_Operation node (an operation) to the ostream o. void AST_Operation::dump (ACE_OSTREAM_TYPE &o) { AST_Decl *d = 0; AST_Type *e = 0; UTL_String *s = 0; if (this->pd_flags == OP_oneway) { this->dump_i (o, "oneway "); } else if (this->pd_flags == OP_idempotent) { this->dump_i (o, "idempotent "); } this->pd_return_type->name ()->dump (o); this->dump_i (o, " "); this->local_name ()->dump (o); this->dump_i (o, "("); // Must advance the iterator explicity inside the loop. for (UTL_ScopeActiveIterator i (this, IK_decls); !i.is_done ();) { d = i.item (); d->dump (o); i.next (); if (!i.is_done()) { this->dump_i (o, ", "); } } this->dump_i (o, ")"); if (this->pd_exceptions != 0) { this->dump_i (o, " raises("); // Must advance the iterator explicity inside the loop. for (UTL_ExceptlistActiveIterator ei (this->pd_exceptions); !ei.is_done ();) { e = ei.item (); ei.next (); e->local_name ()->dump (o); if (!ei.is_done()) { this->dump_i (o, ", "); } } this->dump_i (o, ")"); } if (this->pd_context != 0) { this->dump_i (o, " context("); // Must advance the iterator explicity inside the loop. for (UTL_StrlistActiveIterator si (this->pd_context); !si.is_done();) { s = si.item (); si.next (); this->dump_i (o, s->get_string ()); if (!si.is_done()) { this->dump_i (o, ", "); } } this->dump_i (o, ")"); } }
int ifr_adding_visitor_operation::visit_operation (AST_Operation *node) { try { // If this operation is already in the repository (for example, if // we are processing the IDL file a second time inadvertently), we // just return 0. The IDL file must be legal, otherwise the IDL // compiler front end would have told us. CORBA::Contained_var prev_def = be_global->repository ()->lookup_id (node->repoID ()); if (!CORBA::is_nil (prev_def.in ())) { return 0; } // Build the parameter list. Our overridden version of visit_argument // will look up each parameter and add its repository entry to // our params_ member. CORBA::ULong length = static_cast<CORBA::ULong> (node->argument_count ()); this->params_.length (length); if (this->visit_scope (node) == -1) { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::") ACE_TEXT ("visit_operation -") ACE_TEXT (" visit_scope failed\n") ), -1 ); } this->index_ = 0; // Build the exception list. UTL_ExceptList *excepts = node->exceptions (); if (excepts != 0) { length = static_cast<CORBA::ULong> (excepts->length ()); } else { length = 0; } CORBA::ExceptionDefSeq exceptions (length); exceptions.length (length); AST_Type *ex = 0; CORBA::ULong i = 0; for (UTL_ExceptlistActiveIterator ex_iter (excepts); !ex_iter.is_done (); ex_iter.next (), ++i) { ex = ex_iter.item (); prev_def = be_global->repository ()->lookup_id (ex->repoID ()); exceptions[i] = CORBA::ExceptionDef::_narrow (prev_def.in ()); } // Build the context list. UTL_StrList *ctx_list = node->context (); if (ctx_list != 0) { length = static_cast<CORBA::ULong> (ctx_list->length ()); } else { length = 0; } CORBA::ContextIdSeq contexts (length); contexts.length (length); UTL_StrlistActiveIterator ctx_iter (ctx_list); UTL_String *str = 0; i = 0; while (!ctx_iter.is_done ()) { str = ctx_iter.item (); contexts[i++] = str->get_string (); ctx_iter.next (); } // Get the return type. AST_Type *return_type = node->return_type (); // Updates ir_current_. this->get_referenced_type (return_type); // Is the operation oneway? CORBA::OperationMode mode = node->flags () == AST_Operation::OP_oneway ? CORBA::OP_ONEWAY : CORBA::OP_NORMAL; // Create the repository entry. CORBA::Container_ptr current_scope = CORBA::Container::_nil (); if (be_global->ifr_scopes ().top (current_scope) == 0) { AST_Decl *op_scope = ScopeAsDecl (node->defined_in ()); AST_Decl::NodeType nt = op_scope->node_type (); if (nt == AST_Decl::NT_interface) { CORBA::InterfaceDef_var iface = CORBA::InterfaceDef::_narrow (current_scope); CORBA::OperationDef_var new_def = iface->create_operation (node->repoID (), node->local_name ()->get_string (), node->version (), this->ir_current_.in (), mode, this->params_, exceptions, contexts); } else { CORBA::ValueDef_var vtype = CORBA::ValueDef::_narrow (current_scope); CORBA::OperationDef_var new_def = vtype->create_operation (node->repoID (), node->local_name ()->get_string (), node->version (), this->ir_current_.in (), mode, this->params_, exceptions, contexts); } } else { ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::") ACE_TEXT ("visit_operation -") ACE_TEXT (" scope stack is empty\n") ), -1 ); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( ACE_TEXT ( "ifr_adding_visitor_operation::visit_operation")); return -1; } return 0; }