diff options
Diffstat (limited to 'CIAO/tools/IDL3_to_XMI/IDL3_to_XMI_visitor.cpp')
-rw-r--r-- | CIAO/tools/IDL3_to_XMI/IDL3_to_XMI_visitor.cpp | 977 |
1 files changed, 613 insertions, 364 deletions
diff --git a/CIAO/tools/IDL3_to_XMI/IDL3_to_XMI_visitor.cpp b/CIAO/tools/IDL3_to_XMI/IDL3_to_XMI_visitor.cpp index e0d6ff98a1e..b0bd198761b 100644 --- a/CIAO/tools/IDL3_to_XMI/IDL3_to_XMI_visitor.cpp +++ b/CIAO/tools/IDL3_to_XMI/IDL3_to_XMI_visitor.cpp @@ -48,6 +48,7 @@ #include <sstream> #include "xercesc/dom/DOM.hpp" +#include "xercesc/util/XMLChar.hpp" #include "XML/XML_Helper.h" @@ -56,6 +57,7 @@ using XERCES_CPP_NAMESPACE::DOMAttr; using XERCES_CPP_NAMESPACE::DOMElement; using XERCES_CPP_NAMESPACE::DOMText; using XERCES_CPP_NAMESPACE::DOMDocumentType; +using XERCES_CPP_NAMESPACE::XMLChar1_1; using CIAO::XML::XStr; @@ -105,6 +107,34 @@ namespace CIAO return ACE::strnew (LITERALS[CAPS_FALSE]); } + template <> + ACE_TCHAR * + idl3_to_xmi_visitor::number_to_string (char val) + { + // There is no way to convert any char to xml encoding nicely + // so we convert it to a decimal integer. This will preserve at + // least a correct char value instead of some non-printable xml. + std::stringstream str; + + str << static_cast<unsigned int>(static_cast<unsigned char> (val)); + + return ACE::strnew (ACE_TEXT_CHAR_TO_TCHAR (str.str ().c_str ())); + } + + template <> + ACE_TCHAR * + idl3_to_xmi_visitor::number_to_string (wchar_t val) + { + // There is no way to convert any char to xml encoding nicely + // so we convert it to a decimal integer. This will preserve at + // least a correct char value instead of some non-printable xml. + std::stringstream str; + + str << static_cast<unsigned long>(static_cast<wchar_t> (val)); + + return ACE::strnew (ACE_TEXT_CHAR_TO_TCHAR (str.str ().c_str ())); + } + idl3_to_xmi_visitor::idl3_to_xmi_visitor (bool skip_imported) : dom_ (0), root_ (0), @@ -112,6 +142,7 @@ namespace CIAO associations_ (0), base_id_ (idl3_to_xmi_visitor::gen_xmi_id ()), skip_imported_ (skip_imported), + visiting_enum_ (false), union_disc_ (0) { } @@ -168,15 +199,22 @@ namespace CIAO } int - idl3_to_xmi_visitor::visit_predefined_type (AST_PredefinedType *t) + idl3_to_xmi_visitor::visit_predefined_type (AST_PredefinedType *node) { XMI_TRACE ("predef type"); - ACE_DEBUG ((LM_DEBUG, "pdt: %s\n", t->repoID ())); - switch (t->pt ()) + char const *local_name = 0; + switch (node->pt ()) { case AST_PredefinedType::PT_pseudo: - this->create_and_store_xmi_id (t); + // Only a limited number of predefined pseudo types + // needs our attention. + local_name = node->original_local_name ()->get_string (); + if (ACE_OS::strcmp (local_name, "TypeCode") == 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + this->gen_common_elements (node, LITERALS[ST_TC]); + } default: break; } @@ -190,6 +228,16 @@ namespace CIAO try { + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) == 0) + { + // If the module is reopened then put it on the stack. + ES_Guard (ele, this); + this->visit_scope (node); + // And don't do anything more. + return 0; + } + ES_Guard package_guard (LITERALS[PACKAGE_TAG], this); this->gen_common_elements (node, LITERALS[ST_MODULE]); @@ -197,6 +245,13 @@ namespace CIAO { NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); ES_Guard owned_guard (LITERALS[OWNEDELEMENT_TAG], this); + + // Save ownedElement to add to it later if the module + // will be reopened. + DOMElement *ele = 0; + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + this->visit_scope (node); } } @@ -222,10 +277,19 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->gen_common_elements (node, LITERALS[ST_INTF]); + this->gen_common_elements (node, LITERALS[ST_INTF]); + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); { // Operations. @@ -238,10 +302,10 @@ namespace CIAO // Inheritance for (long i = 0; i < node->n_inherits (); ++i) { - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->inherits ()[i]->repoID ()))); + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->inherits ()[i]->repoID ()))); } - } catch (Error &err) { @@ -259,7 +323,17 @@ namespace CIAO try { - this->create_and_store_xmi_id (node); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_INTF]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } } catch (Error &err) { @@ -276,7 +350,9 @@ namespace CIAO XMI_TRACE ("valuebox"); if (this->skip_imported_ && node->imported ()) - return 0; + { + return 0; + } try { @@ -284,8 +360,9 @@ namespace CIAO this->gen_common_elements (node, LITERALS[ST_BOXVALUE]); // add a generalization for the value we box - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->boxed_type ()->repoID ()))); + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->boxed_type ()->repoID ()))); } catch (Error &err) { @@ -309,9 +386,21 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->visit_valuetype_impl (node, LITERALS[ST_VALUE]); + this->gen_common_elements (node, LITERALS[ST_VALUE]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); + + this->visit_valuetype_impl (node); } catch (Error &err) { @@ -323,27 +412,34 @@ namespace CIAO } void - idl3_to_xmi_visitor::visit_valuetype_impl (AST_ValueType *node, const ACE_TCHAR *stereo) + idl3_to_xmi_visitor::visit_valuetype_impl (AST_ValueType *node) { try { - this->gen_common_elements (node, stereo); - // isAbstract if (node->is_abstract ()) - this->set_attribute (LITERALS[ABSTRACT], LITERALS[_TRUE]); - else this->set_attribute (LITERALS[ABSTRACT], LITERALS[_FALSE]); + { + this->set_attribute (LITERALS[ABSTRACT], LITERALS[_TRUE]); + } + else + { + this->set_attribute (LITERALS[ABSTRACT], LITERALS[_FALSE]); + } NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); if (node->inherits_concrete () != 0) - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->inherits_concrete ()->repoID ()))); + { + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->inherits_concrete ()->repoID ()))); + } for (long i = 0; i < node->n_supports (); ++i) { - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->supports ()[i]->repoID ()))); + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->supports ()[i]->repoID ()))); } /* NOTE: CDMW XMI generator ignores supports specifications. @@ -354,7 +450,9 @@ namespace CIAO ES_Guard oe_guard (LITERALS[OWNEDELEMENT_TAG], this); + this->cached_type_ = node; this->visit_scope (node); + this->cached_type_ = 0; } catch (Error &err) { @@ -370,7 +468,17 @@ namespace CIAO try { - this->create_and_store_xmi_id (node); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_VALUE]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } } catch (Error &err) { @@ -394,51 +502,66 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->gen_common_elements (node, LITERALS[ST_COMP]); + this->gen_common_elements (node, LITERALS[ST_COMP]); + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); for (long i = 0; i < node->n_supports (); ++i) { - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->supports ()[i]->repoID ()))); + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->supports ()[i]->repoID ()))); } if (node->base_component () != 0) { - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->base_component ()->repoID ()))); + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->base_component ()->repoID ()))); } // Component ports - this->gen_component_ports (node->provides (), - ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - LITERALS[ST_PROVIDES], - ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); - - this->gen_component_ports (node->uses (), - ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - LITERALS[ST_USES], - ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); - - this->gen_component_ports (node->emits (), - ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - LITERALS[ST_EMITS], - ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); - - this->gen_component_ports (node->publishes (), - ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - LITERALS[ST_PUBLISH], - ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); - - this->gen_component_ports (node->consumes (), - ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - LITERALS[ST_CONSUMES], - ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); - + this->gen_component_ports ( + node->provides (), + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + LITERALS[ST_PROVIDES], + ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); + + this->gen_component_ports ( + node->uses (), + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + LITERALS[ST_USES], + ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); + + this->gen_component_ports ( + node->emits (), + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + LITERALS[ST_EMITS], + ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); + + this->gen_component_ports ( + node->publishes (), + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + LITERALS[ST_PUBLISH], + ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); + + this->gen_component_ports ( + node->consumes (), + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + LITERALS[ST_CONSUMES], + ACE_TEXT_CHAR_TO_TCHAR (node->file_name ().c_str ())); ES_Guard oe_guard (LITERALS[OWNEDELEMENT_TAG], this); @@ -463,7 +586,17 @@ namespace CIAO try { - this->create_and_store_xmi_id (node); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_COMP]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } } catch (Error &err) { @@ -487,9 +620,21 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->visit_valuetype_impl (node, LITERALS[ST_EVENT]); + this->gen_common_elements (node, LITERALS[ST_EVENT]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); + + this->visit_valuetype_impl (node); } catch (Error &err) { @@ -515,7 +660,6 @@ namespace CIAO { XMI_TRACE ("home"); - if (this->skip_imported_ && node->imported ()) { this->visit_scope (node); @@ -532,15 +676,16 @@ namespace CIAO for (long i = 0; i < node->n_supports (); ++i) { - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->supports ()[i]->repoID ()))); - + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->supports ()[i]->repoID ()))); } if (node->base_home () != 0) { - XStr xid (this->add_generalization (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->base_home ()->repoID ()))); + XStr xid (this->add_generalization ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->base_home ()->repoID ()))); } if (node->factories ().size () != 0) @@ -557,13 +702,14 @@ namespace CIAO if (node->finders () .size () != 0) throw Error ("home finders not supported", node); - this->add_managed_component (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), - ACE_TEXT_CHAR_TO_TCHAR (node->managed_component ()->repoID ())); + this->add_managed_component ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + ACE_TEXT_CHAR_TO_TCHAR (node->managed_component ()->repoID ())); ES_Guard noe_guard (LITERALS[OWNEDELEMENT_TAG], this); - this->cached_type_ = node; // attributes in scope. + this->cached_type_ = node; this->visit_scope (node); this->cached_type_ = 0; } @@ -580,8 +726,12 @@ namespace CIAO idl3_to_xmi_visitor::visit_factory (AST_Factory *node) { XMI_TRACE ("factory"); + if (this->skip_imported_ && node->imported ()) - return 0; + { + return 0; + } + throw Error ("Factories not supported", node); return 0; @@ -592,7 +742,6 @@ namespace CIAO { XMI_TRACE ("structure"); - if (this->skip_imported_ && node->imported ()) { this->visit_scope (node); @@ -601,9 +750,21 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->visit_struct_impl (node, LITERALS[ST_STRUCT]); + this->gen_common_elements (node, LITERALS[ST_STRUCT]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); + + this->visit_struct_impl (node); } catch (Error &err) { @@ -615,11 +776,10 @@ namespace CIAO } void - idl3_to_xmi_visitor::visit_struct_impl (AST_Structure *node, const ACE_TCHAR *stereotype) + idl3_to_xmi_visitor::visit_struct_impl (AST_Structure *node) { try { - this->gen_common_elements (node, stereotype); ES_Guard ns_oe_guard (LITERALS[OWNEDELEMENT_TAG], this); NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); this->visit_scope (node); @@ -638,7 +798,17 @@ namespace CIAO try { - this->create_and_store_xmi_id (node); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_STRUCT]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } } catch (Error &err) { @@ -662,9 +832,21 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[EXCEPTION_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[EXCEPTION_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_EX]); - this->visit_struct_impl (node, LITERALS[ST_EX]); + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); + + this->visit_struct_impl (node); } catch (Error &err) { @@ -704,7 +886,9 @@ namespace CIAO NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); ES_Guard oe_guard (LITERALS[OWNEDELEMENT_TAG], this); + this->visiting_enum_ = true; this->visit_scope (node); + this->visiting_enum_ = false; } catch (Error &err) { @@ -716,8 +900,11 @@ namespace CIAO } void - idl3_to_xmi_visitor::visit_operation_impl (AST_Operation *op, const ACE_TCHAR *stereotype) + idl3_to_xmi_visitor::visit_operation_impl (AST_Operation *op, + const ACE_TCHAR *stereotype) { + XMI_TRACE ("operation"); + if (this->skip_imported_ && op->imported ()) { this->visit_scope (op); @@ -730,8 +917,9 @@ namespace CIAO ES_Guard op_guard (LITERALS[OP_TAG], this); // name and visiblity - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (op->original_local_name ()->get_string ())); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (op->original_local_name ()->get_string ())); this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); @@ -768,8 +956,9 @@ namespace CIAO { ES_Guard tv_guard (LITERALS[TV_TAG], this); this->set_attribute (LITERALS[TAG], LITERALS[RAISES]); - this->set_attribute (LITERALS[VALUE], - ACE_TEXT_CHAR_TO_TCHAR (ei.item ()->full_name ())); + this->set_attribute ( + LITERALS[VALUE], + ACE_TEXT_CHAR_TO_TCHAR (ei.item ()->full_name ())); } } } @@ -837,13 +1026,31 @@ namespace CIAO { ES_Guard attr_guard (LITERALS[ATTR_TAG], this); + if (node->field_type ()->node_type () == AST_Decl::NT_sequence) + { + AST_Sequence* sequence = + AST_Sequence::narrow_from_decl (node->field_type ()); + sequence->ast_accept (this); + // There is no need to proceed any further. + return 0; + } + else if (node->field_type ()->node_type () == AST_Decl::NT_array) + { + AST_Array* array = + AST_Array::narrow_from_decl (node->field_type ()); + array->ast_accept (this); + // There is no need to proceed any further. + return 0; + } + // I don't think anything else can refer to the parameter by // xid, so I won't store it. XStr xid = this->gen_xmi_id (node); this->set_attribute (LITERALS[XMI_ID], xid); - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); switch (node->visibility ()) { @@ -866,8 +1073,6 @@ namespace CIAO xid = this->lookup_type_xid (node->field_type ()); this->set_attribute (LITERALS[TYPE], xid); - - } catch (Error &err) { @@ -892,8 +1097,9 @@ namespace CIAO { ES_Guard param_guard (LITERALS[PARAM_TAG], this); - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); // I don't think anything else can refer to the parameter by // xid, so I won't store it. @@ -947,7 +1153,7 @@ namespace CIAO if (this->cached_type_ == 0) { - ACE_DEBUG ((LM_DEBUG, "Zounds! %d\n", + ACE_ERROR ((LM_ERROR, "Zounds! %d\n", this->cached_type_)); throw Error ("Internal error - attribute expected " "to have a cached type, but didn't"); @@ -958,31 +1164,33 @@ namespace CIAO // *** NS_Guard global_ns (ACE_TEXT ("::"), this); ES_Guard assoc_group (this->associations_, this); - ES_Guard attr_guard (LITERALS[ASSOC_TAG], this); + ES_Guard assoc_g (LITERALS[ASSOC_TAG], this); - this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); - if (node->readonly ()) - this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], - LITERALS[ST_RO]); - this->set_containing_element (LITERALS[OWNER]); // I don't think anything else can refer to the attribute by // xid, so I won't store it. XStr xid = this->gen_xmi_id (node); this->set_attribute (LITERALS[XMI_ID], xid); + this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); + this->set_containing_element (LITERALS[NS]); + if (node->readonly ()) + this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], + LITERALS[ST_RO]); ES_Guard assoc_conn (LITERALS[ASSOC_CONN_TAG], this); { // Containing type ES_Guard assoc_end (LITERALS[ASSOC_END_TAG], this); this->set_attribute (LITERALS[MULT], ACE_TEXT ("1")); - this->find_and_set_xid_as_attr (LITERALS[TYPE], - ACE_TEXT_CHAR_TO_TCHAR (this->cached_type_->repoID ())); + this->find_and_set_xid_as_attr ( + LITERALS[TYPE], + ACE_TEXT_CHAR_TO_TCHAR (this->cached_type_->repoID ())); } { ES_Guard assoc_end (LITERALS[ASSOC_END_TAG], this); - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); this->set_attribute (LITERALS[MULT], ACE_TEXT ("1")); xid = this->lookup_type_xid (node->field_type ()); this->set_attribute (LITERALS[TYPE], xid); @@ -1009,16 +1217,26 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->gen_common_elements (node, LITERALS[ST_UNION]); + this->gen_common_elements (node, LITERALS[ST_UNION]); + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } + + ES_Guard class_guard (ele, this); NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); ES_Guard oe_guard (LITERALS[OWNEDELEMENT_TAG], this); // Set discriminator type this->union_disc_ = node->disc_type (); this->visit_scope (node); + this->union_disc_ = 0; } catch (Error &err) { @@ -1035,10 +1253,19 @@ namespace CIAO { XMI_TRACE ("union_fwd"); - try { - this->create_and_store_xmi_id (node); + DOMElement * ele = 0; + if (this->repo_id_map_.find (node->repoID (), ele) != 0) + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_UNION]); + + // Save in order not to generate same element later. + this->stack_.top (ele); + this->repo_id_map_.bind (node->repoID (), ele); + } } catch (Error &err) { @@ -1064,8 +1291,9 @@ namespace CIAO this->set_attribute (LITERALS[XMI_ID], xid); // name - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); // visiblity this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); @@ -1115,13 +1343,12 @@ namespace CIAO // @@TODO: Yuck, there has got to be a better way.... AST_Expression::AST_ExprValue *ev = exp->ev (); - const size_t bool_length = 6; if (exp->ec () != AST_Expression::EC_symbol || this->union_disc_->node_type () == AST_Decl::NT_typedef || this->union_disc_->node_type () == AST_Decl::NT_pre_defined) { - /* AST_Expression::ExprType type; + /*AST_Expression::ExprType type; if (this->union_disc_->node_type () == AST_Decl::NT_typedef) { @@ -1130,46 +1357,26 @@ namespace CIAO } else type = ev->et;*/ - // We have a non-enum discriminator - // Allocate memory - switch (ev->et) - { - case AST_Expression::EV_bool: - ACE_DEBUG ((LM_DEBUG, "bool disc\n")); - buffer.reset (new ACE_TCHAR [bool_length]); // length of 'false' + 1 - break; - case AST_Expression::EV_char: - ACE_DEBUG ((LM_DEBUG, "char disc\n")); - buffer.reset (new ACE_TCHAR[1]); - break; - default: - ACE_DEBUG ((LM_DEBUG, "numberic?disc\n")); - // don't need to allocate room for numerics, handled by - // number_to_string - break; - } - // Decode the type switch (ev->et) { case AST_Expression::EV_long: - buffer.reset (this->number_to_string(ev->u.lval)); + buffer.reset (this->number_to_string (ev->u.lval)); break; case AST_Expression::EV_ulong: - buffer.reset (this->number_to_string(ev->u.ulval)); + buffer.reset (this->number_to_string (ev->u.ulval)); break; case AST_Expression::EV_short: - buffer.reset (this->number_to_string(ev->u.sval)); + buffer.reset (this->number_to_string (ev->u.sval)); break; case AST_Expression::EV_ushort: - buffer.reset (this->number_to_string(ev->u.usval)); + buffer.reset (this->number_to_string (ev->u.usval)); break; - case AST_Expression::EV_bool: buffer.reset (this->number_to_string (ev->u.bval)); break; case AST_Expression::EV_char: - *buffer.get () = ev->u.cval; + buffer.reset (this->number_to_string (ev->u.cval)); break; default: throw Error ("Unknown union union label type"); @@ -1226,7 +1433,7 @@ namespace CIAO } int - idl3_to_xmi_visitor::visit_constant (AST_Constant *node) + idl3_to_xmi_visitor::visit_constant (AST_Constant *node) { XMI_TRACE ("constant"); @@ -1339,7 +1546,7 @@ namespace CIAO { ES_Guard tv (LITERALS[TV_TAG], this); this->set_attribute (LITERALS[TAG], LITERALS[INIT_VAL]); - this->set_attribute (LITERALS[VALUE], str_value. get ()); + this->set_attribute (LITERALS[VALUE], str_value.get ()); } } } @@ -1355,20 +1562,29 @@ namespace CIAO int idl3_to_xmi_visitor::visit_enum_val (AST_EnumVal *node) { + XMI_TRACE ("enum val"); if (this->skip_imported_ && node->imported ()) { return 0; } + if (!this->visiting_enum_) + { + // It makes sence only to process enumvals in enum "scope". + return 0; + } + try { - XMI_TRACE ("enum val"); ES_Guard att_guard (LITERALS[ATTR_TAG], this); - this->create_and_store_xmi_id (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ())); - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); + this->create_and_store_xmi_id ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), + node); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); // I think this is fixed. this->set_attribute (LITERALS[MULT], LITERALS[MULT_OTO]); @@ -1400,14 +1616,7 @@ namespace CIAO idl3_to_xmi_visitor::visit_array (AST_Array *node) { XMI_TRACE ("array val"); - throw Error ("Arrays not supported", node); - return 0; - } - int - idl3_to_xmi_visitor::visit_sequence (AST_Sequence *node) - { - XMI_TRACE ("sequence val"); if (this->skip_imported_ && node->imported ()) { return 0; @@ -1415,263 +1624,256 @@ namespace CIAO try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->gen_common_elements (node, - LITERALS[ST_SEQ]); + LITERALS[ST_ARR]); - // Generate the bounds and type on the sequence, which is an - // association in the association tree. - NS_Guard global_ns (ACE_TEXT ("::"), this); - ES_Guard assoc_group (this->associations_, this); - ES_Guard assoc_g (LITERALS[ASSOC_TAG], this); + this->gen_array_associations (node, node); + } + catch (Error &err) + { + err.node (node); + throw; + } - // I don't think anything else can refer to this association - // xid, so I won't store it. - XStr xid = this->gen_xmi_id (node); - this->set_attribute (LITERALS[XMI_ID], xid); - this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); - this->set_containing_element (LITERALS[NS]); + return 0; + } - ES_Guard assoc_conn (LITERALS[ASSOC_CONN_TAG], this); + void + idl3_to_xmi_visitor::gen_array_associations (AST_Decl *node, + AST_Array *array) + { + // <UML:Namespace.ownedElement> + NS_Guard global_ns (ACE_TEXT ("::"), this); + + // <UML:Association xmi.id="xmi.1210085542354" + // visibility="public" namespace="xmi.1210085542350"> + ES_Guard assoc_group (this->associations_, this); + ES_Guard assoc_g (LITERALS[ASSOC_TAG], this); + + XStr xid = this->gen_xmi_id (node); + this->set_attribute (LITERALS[XMI_ID], xid); + this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); + this->set_containing_element (LITERALS[NS]); + // <UML:Association.connection> + ES_Guard assoc_conn (LITERALS[ASSOC_CONN_TAG], this); - { // Bounds - ES_Guard assocend (LITERALS[ASSOC_END_TAG], this); + { + // <UML:AssociationEnd multiplicity="0..1" type="xmi.1210085542353"> + ES_Guard assocend (LITERALS[ASSOC_END_TAG], this); - this->set_attribute (LITERALS[MULT], LITERALS[MULT_ZTO]); + this->set_attribute (LITERALS[MULT], LITERALS[MULT_ZTO]); - xid = this->lookup_xid (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ())); - this->set_attribute (LITERALS[TYPE], xid); + xid = this->lookup_xid (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ())); + this->set_attribute (LITERALS[TYPE], xid); - ES_Guard assoc_qual (LITERALS[ASSOC_END_QUAL_TAG], this); + // <UML:AssociationEnd.qualifier> + ES_Guard assoc_qual (LITERALS[ASSOC_END_QUAL_TAG], this); + + for (unsigned long i = 0; + array != 0 && i < array->n_dims (); + ++i) + { + // <UML:Attribute xmi.id="xmi.1210085542355" + // name="index0" type='xmi.1210085542329'> + // N.B. that type is long. ES_Guard attr (LITERALS[ATTR_TAG], this); xid = this->gen_xmi_id (node); this->set_attribute (LITERALS[XMI_ID], xid); - this->set_attribute (LITERALS[NAME], LITERALS[INDEX]); - this->set_attribute (LITERALS[TYPE], LITERALS[ST_LONG]); + std::stringstream str; + str << LITERALS[INDEX]; + str << i; + + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (str.str ().c_str ())); + xid = this->lookup_xid (LITERALS[ST_LONG]); + this->set_attribute (LITERALS[TYPE], xid); + + // <UML:ModelElement.constraint> ES_Guard me_c (LITERALS[ME_CONS_TAG], this); + + // <UML:Constraint xmi.id="xmi.1210085542356"> ES_Guard cons (LITERALS[CONSTRAINT], this); + + xid = this->gen_xmi_id (node); + this->set_attribute (LITERALS[XMI_ID], xid); + + // <UML:ModelElement.taggedValue> ES_Guard me_tv (LITERALS[ME_TV_TAG], this); + + // <UML:TaggedValue tag="constraintUpperValue" value="4"/> ES_Guard tv (LITERALS[TV_TAG], this); this->set_attribute (LITERALS[TAG], LITERALS[CONST_UPPER]); - // @@TODO: need to extract bound from node. - if (node->unbounded ()) - this->set_attribute (LITERALS[CONST_UPPER], LITERALS[UNBOUNDED_SEQ]); - else - { // bounded sequence - // convert the array bound to a string - // need a buffer, with a little safety padding - ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer - (this->number_to_string (node->max_size ()->ev ()->u.ulval)); - - this->set_attribute (LITERALS[CONST_UPPER], buffer.get ()); - } - } + ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer ( + this->number_to_string (array->dims ()[i]->ev ()->u.ulval)); - // Sequence type - ES_Guard assoc_end (LITERALS[ASSOC_END_TAG], this); - this->set_attribute (LITERALS[MULT], LITERALS[MULT_OTO]); - - XStr seq_type = this->lookup_type_xid (node->base_type ()); - this->set_attribute (LITERALS[TYPE], - seq_type); - } - catch (Error &err) - { - err.node (node); - throw; - } + this->set_attribute (LITERALS[VALUE], buffer.get ()); + } + } - return 0; - } + // <UML:AssociationEnd multiplicity="1..1" + // type="xmi.1210085542346"/> - type is Char for this IDL + ES_Guard assoc_end (LITERALS[ASSOC_END_TAG], this); + this->set_attribute (LITERALS[MULT], LITERALS[MULT_OTO]); - int - idl3_to_xmi_visitor::visit_string (AST_String *) - { - XMI_TRACE ("string"); - return 0; + XStr arr_type = this->lookup_type_xid (array->base_type ()); + this->set_attribute (LITERALS[TYPE], arr_type); } int - idl3_to_xmi_visitor::visit_typedef (AST_Typedef *node) + idl3_to_xmi_visitor::visit_sequence (AST_Sequence *node) { - XMI_TRACE ("typedef"); + XMI_TRACE ("sequence val"); if (this->skip_imported_ && node->imported ()) + { return 0; + } try { - ES_Guard class_guard (LITERALS[CLASS_TAG], this); + this->gen_common_elements (node, + LITERALS[ST_SEQ]); - AST_Decl *base (node->base_type ()); - if (base->node_type () == AST_Decl::NT_sequence || - base->node_type () == AST_Decl::NT_array) - { - // Anonymous Sequences and arrays appear to be a special case - const ACE_TCHAR *stereo (0); - switch (base->node_type ()) - { - case AST_Decl::NT_sequence: - stereo = LITERALS[ST_SEQ]; - break; - case AST_Decl::NT_array: - stereo = LITERALS[ST_ARR]; - break; - default: - throw Error ("Unsupported anonymous type inside typedef.", - node); - } - this->gen_common_elements (node, stereo); + // Generate the bounds and type on the sequence, which is an + // association in the association tree. + this->gen_sequence_associations (node, node); + } + catch (Error &err) + { + err.node (node); + throw; + } - // Hopefully we have hit something like: - // typedef char AirportName[4]; - AST_Array* the_array = 0; - AST_Sequence* the_sequence = 0; - if (base->node_type () == AST_Decl::NT_array) - { - the_array = AST_Array::narrow_from_decl (base); - } - else - { - the_sequence = AST_Sequence::narrow_from_decl (base); - } + return 0; + } - // <UML:Namespace.ownedElement> - NS_Guard global_ns (ACE_TEXT ("::"), this); + void + idl3_to_xmi_visitor::gen_sequence_associations (AST_Decl *node, + AST_Sequence *sequence) + { + // <UML:Namespace.ownedElement> + NS_Guard global_ns (ACE_TEXT ("::"), this); - // <UML:Association xmi.id="xmi.1210085542354" visibility="public" namespace="xmi.1210085542350"> - ES_Guard assoc_group (this->associations_, this); - ES_Guard assoc_g (LITERALS[ASSOC_TAG], this); + // <UML:Association xmi.id="xmi.1210085542354" + // visibility="public" namespace="xmi.1210085542350"> + ES_Guard assoc_group (this->associations_, this); + ES_Guard assoc_g (LITERALS[ASSOC_TAG], this); - XStr xid = this->gen_xmi_id (node); - this->set_attribute (LITERALS[XMI_ID], xid); - this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); - this->set_containing_element (LITERALS[NS]); + XStr xid = this->gen_xmi_id (node); + this->set_attribute (LITERALS[XMI_ID], xid); + this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); + this->set_containing_element (LITERALS[NS]); - // <UML:Association.connection> - ES_Guard assoc_conn (LITERALS[ASSOC_CONN_TAG], this); + // <UML:Association.connection> + ES_Guard assoc_conn (LITERALS[ASSOC_CONN_TAG], this); - { - // <UML:AssociationEnd multiplicity="0..1" type="xmi.1210085542353"> - ES_Guard assocend (LITERALS[ASSOC_END_TAG], this); + { + // <UML:AssociationEnd multiplicity="0..1" type="xmi.1210085542353"> + ES_Guard assocend (LITERALS[ASSOC_END_TAG], this); - this->set_attribute (LITERALS[MULT], LITERALS[MULT_ZTO]); + this->set_attribute (LITERALS[MULT], LITERALS[MULT_ZTO]); - xid = - this->lookup_xid (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ())); - this->set_attribute (LITERALS[TYPE], xid); + xid = this->lookup_xid (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ())); + this->set_attribute (LITERALS[TYPE], xid); - // <UML:AssociationEnd.qualifier> - ES_Guard assoc_qual (LITERALS[ASSOC_END_QUAL_TAG], this); + // <UML:AssociationEnd.qualifier> + ES_Guard assoc_qual (LITERALS[ASSOC_END_QUAL_TAG], this); - for (unsigned long i = 0; - the_array != 0 && i < the_array->n_dims (); - ++i) - { - // <UML:Attribute xmi.id="xmi.1210085542355" name="index0" type='xmi.1210085542329'> - N.B. that type is long. - ES_Guard attr (LITERALS[ATTR_TAG], this); + ES_Guard attr (LITERALS[ATTR_TAG], this); - xid = this->gen_xmi_id (node); - this->set_attribute (LITERALS[XMI_ID], xid); + xid = this->gen_xmi_id (node); + this->set_attribute (LITERALS[XMI_ID], xid); + this->set_attribute (LITERALS[NAME], LITERALS[INDEX]); + xid = this->lookup_xid (LITERALS[ST_LONG]); + this->set_attribute (LITERALS[TYPE], xid); - std::stringstream str; - str << LITERALS[INDEX]; - str << i; + ES_Guard me_c (LITERALS[ME_CONS_TAG], this); + ES_Guard cons (LITERALS[CONSTRAINT], this); + ES_Guard me_tv (LITERALS[ME_TV_TAG], this); + ES_Guard tv (LITERALS[TV_TAG], this); - this->set_attribute ( - LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (str.str ().c_str ())); - xid = this->lookup_xid (LITERALS[ST_LONG]); - this->set_attribute (LITERALS[TYPE], xid); + this->set_attribute (LITERALS[TAG], LITERALS[CONST_UPPER]); - // <UML:ModelElement.constraint> - ES_Guard me_c (LITERALS[ME_CONS_TAG], this); + // @@TODO: need to extract bound from node. + if (sequence->unbounded ()) + { + this->set_attribute (LITERALS[VALUE], + LITERALS[UNBOUNDED_SEQ]); + } + else + { // bounded sequence + // convert the array bound to a string + // need a buffer, with a little safety padding + ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer ( + this->number_to_string (sequence->max_size ()->ev ()->u.ulval)); + + this->set_attribute (LITERALS[VALUE], buffer.get ()); + } + } - // <UML:Constraint xmi.id="xmi.1210085542356"> - ES_Guard cons (LITERALS[CONSTRAINT], this); + // <UML:AssociationEnd multiplicity="1..1" + // type="xmi.1210085542346"/> - type is Char for this IDL + ES_Guard assoc_end (LITERALS[ASSOC_END_TAG], this); + this->set_attribute (LITERALS[MULT], LITERALS[MULT_OTO]); - xid = this->gen_xmi_id (node); - this->set_attribute (LITERALS[XMI_ID], xid); + XStr seq_type = this->lookup_type_xid (sequence->base_type ()); + this->set_attribute (LITERALS[TYPE], seq_type); + } - // <UML:ModelElement.taggedValue> - ES_Guard me_tv (LITERALS[ME_TV_TAG], this); + int + idl3_to_xmi_visitor::visit_string (AST_String *) + { + XMI_TRACE ("string"); + return 0; + } - // <UML:TaggedValue tag="constraintUpperValue" value="4"/> - ES_Guard tv (LITERALS[TV_TAG], this); + int + idl3_to_xmi_visitor::visit_typedef (AST_Typedef *node) + { + XMI_TRACE ("typedef"); - this->set_attribute (LITERALS[TAG], LITERALS[CONST_UPPER]); + if (this->skip_imported_ && node->imported ()) + { + return 0; + } - ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer ( - this->number_to_string ( - the_array->dims ()[i]->ev ()->u.ulval)); + try + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); - this->set_attribute (LITERALS[VALUE], buffer.get ()); - } + // Anonymous Sequences and arrays appear to be a special case + AST_Decl *base (node->base_type ()); + if (base->node_type () == AST_Decl::NT_sequence) + { + this->gen_common_elements (node, LITERALS[ST_SEQ]); - if (the_sequence) - { - ES_Guard attr (LITERALS[ATTR_TAG], this); - - xid = this->gen_xmi_id (node); - this->set_attribute (LITERALS[XMI_ID], xid); - this->set_attribute (LITERALS[NAME], LITERALS[INDEX]); - xid = this->lookup_xid (LITERALS[ST_LONG]); - this->set_attribute (LITERALS[TYPE], xid); - - - ES_Guard me_c (LITERALS[ME_CONS_TAG], this); - ES_Guard cons (LITERALS[CONSTRAINT], this); - ES_Guard me_tv (LITERALS[ME_TV_TAG], this); - ES_Guard tv (LITERALS[TV_TAG], this); - - this->set_attribute (LITERALS[TAG], LITERALS[CONST_UPPER]); - - // @@TODO: need to extract bound from node. - if (the_sequence->unbounded ()) - { - this->set_attribute (LITERALS[CONST_UPPER], - LITERALS[UNBOUNDED_SEQ]); - } - else - { // bounded sequence - // convert the array bound to a string - // need a buffer, with a little safety padding - ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer ( - this->number_to_string ( - the_sequence->max_size ()->ev ()->u.ulval)); - - this->set_attribute (LITERALS[CONST_UPPER], - buffer.get ()); - } - } + AST_Sequence* sequence = + AST_Sequence::narrow_from_decl (base); + this->gen_sequence_associations (node, sequence); + } + else if (base->node_type () == AST_Decl::NT_array) + { + this->gen_common_elements (node, LITERALS[ST_ARR]); - // <UML:AssociationEnd multiplicity="1..1" type="xmi.1210085542346"/> - type is Char for this IDL - ES_Guard assoc_end (LITERALS[ASSOC_END_TAG], this); - this->set_attribute (LITERALS[MULT], LITERALS[MULT_OTO]); - - XStr seq_type = - this->lookup_type_xid ( - (the_array ? - the_array->base_type () : - the_sequence->base_type ())); - this->set_attribute (LITERALS[TYPE], - seq_type); - } + AST_Array* array = + AST_Array::narrow_from_decl (base); + this->gen_array_associations (node, array); } else { this->gen_common_elements (node, LITERALS[ST_TYPEDEF]); - // Generalization - XStr xid (this->add_generalization (node, - node->base_type ())); + // Generalization. Assignment required for memory management. + XStr xid = this->add_generalization (node, + node->base_type ()); + ACE_UNUSED_ARG (xid); } } catch (Error &err) @@ -1709,9 +1911,6 @@ namespace CIAO target_name += fn; - ACE_DEBUG ((LM_DEBUG, "Opening %C\n", - target_name.c_str ())); - CIAO::XML::NoOp_Resolver res_func; CIAO::XML::XML_Schema_Resolver<> resolver (res_func); CIAO::XML::XML_Error_Handler handler; @@ -1765,8 +1964,10 @@ namespace CIAO // Create generalizations and associations elements, but don't join // them to the tree yet - this->associations_ = this->dom_->createElement (XStr (LITERALS[OWNEDELEMENT_TAG])); - this->generalizations_ = this->dom_->createElement (XStr (LITERALS[OWNEDELEMENT_TAG])); + this->associations_ = + this->dom_->createElement (XStr (LITERALS[OWNEDELEMENT_TAG])); + this->generalizations_ = + this->dom_->createElement (XStr (LITERALS[OWNEDELEMENT_TAG])); if (this->visit_scope (node) != 0) { @@ -1804,9 +2005,27 @@ namespace CIAO } int - idl3_to_xmi_visitor::visit_native (AST_Native *) + idl3_to_xmi_visitor::visit_native (AST_Native *node) { XMI_TRACE ("native"); + + if (this->skip_imported_ && node->imported ()) + { + return 0; + } + + try + { + ES_Guard class_guard (LITERALS[CLASS_TAG], this); + + this->gen_common_elements (node, LITERALS[ST_NATIVE]); + } + catch (Error &err) + { + err.node (node); + throw; + } + return 0; } @@ -1857,7 +2076,8 @@ namespace CIAO DOMElement * idl3_to_xmi_visitor::generate_stereotypes (void) { - DOMElement *retval = this->dom_->createElement (XStr (LITERALS[OWNEDELEMENT_TAG])); + DOMElement *retval = + this->dom_->createElement (XStr (LITERALS[OWNEDELEMENT_TAG])); // put it on the stack to subsequent create_element calls refer to it. this->stack_.push (retval); @@ -1868,8 +2088,8 @@ namespace CIAO this->add_stereotype (ST_UNION, CLASS); this->add_stereotype (ST_USES, ASSOC); this->add_stereotype (ST_SEQ, CLASS); - this->add_stereotype (ST_ROE, _NULL); - this->add_stereotype (ST_RO, _NULL); + this->add_stereotype (ST_ROE, __NULL); + this->add_stereotype (ST_RO, __NULL); this->add_stereotype (ST_OBJ, DATATYPE); this->add_stereotype (ST_STR, DATATYPE); this->add_stereotype (ST_LD, DATATYPE); @@ -1916,6 +2136,7 @@ namespace CIAO this->add_stereotype (ST_INTF, CLASS); this->add_stereotype (ST_PRI_KEY, CLASS); this->add_stereotype (ST_ANY, DATATYPE); + this->add_stereotype (ST_NATIVE, CLASS); this->stack_.pop (retval); @@ -1949,7 +2170,23 @@ namespace CIAO current_id_ = rand (); } std::stringstream str; - str << name << ':' << line << '.' << current_id_++; + // Skip all characters that cannot be a first name char in xmi.id. + while (name && *name && !XMLChar1_1::isFirstNameChar(*name)) ++name; + // Since we use a file path as name then let's change all non-name + // chars for '_'. + while (name && *name) + { + if (XMLChar1_1::isNameChar (*name)) + { + str << *name; + } + else + { + str << '_'; + } + ++name; + } + str << ':' << line << '.' << current_id_++; XStr retval (ACE_TEXT_CHAR_TO_TCHAR (str.str ().c_str ())); return retval.release (); @@ -1996,7 +2233,8 @@ namespace CIAO { try { - this->create_and_store_xmi_id (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), node); + this->create_and_store_xmi_id ( + ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), node); } catch (Error &ex) { @@ -2006,7 +2244,8 @@ namespace CIAO } void - idl3_to_xmi_visitor::create_and_store_xmi_id (const ACE_TCHAR *name, AST_Decl *node) + idl3_to_xmi_visitor::create_and_store_xmi_id ( + const ACE_TCHAR *name, AST_Decl *node) { XStr xid = this->gen_xmi_id (node); @@ -2119,7 +2358,8 @@ namespace CIAO } XMLCh * - idl3_to_xmi_visitor::add_generalization (const ACE_TCHAR *sub, const ACE_TCHAR *super) + idl3_to_xmi_visitor::add_generalization (const ACE_TCHAR *sub, + const ACE_TCHAR *super) { return this->add_generalization (XStr (this->lookup_xid (sub)), XStr (this->lookup_xid (super))); @@ -2133,9 +2373,11 @@ namespace CIAO } XMLCh * - idl3_to_xmi_visitor::add_generalization (const XMLCh *sub, const XMLCh *super) + idl3_to_xmi_visitor::add_generalization (const XMLCh *sub, + const XMLCh *super) { - XStr xid; + // Generate XMI ID + XStr xid (this->gen_xmi_id ()); { // add generalization to the 'generalizations' set ES_Guard es_guard (this->generalizations_, this); @@ -2143,8 +2385,6 @@ namespace CIAO ES_Guard gen_guard (LITERALS[GEN_TAG], this); - // Generate XMI ID - xid = this->gen_xmi_id (); this->set_attribute (LITERALS[XMI_ID], xid); this->set_containing_element (LITERALS[NS]); @@ -2226,30 +2466,35 @@ namespace CIAO XStr xid (this->gen_xmi_id ()); this->set_attribute (LITERALS[XMI_ID], xid); this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); - this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], LITERALS[ST_MANAGES]); + this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], + LITERALS[ST_MANAGES]); this->set_containing_element (LITERALS[NS]); ES_Guard conn_guard (LITERALS[ASSOC_CONN_TAG], this); { // home end ES_Guard end_guard (LITERALS[ASSOC_END_TAG], this); - this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], LITERALS[ST_HOME]); + this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], + LITERALS[ST_HOME]); this->find_and_set_xid_as_attr (LITERALS[TYPE], home); } { // component end ES_Guard end_guard (LITERALS[ASSOC_END_TAG], this); - this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], LITERALS[ST_COMP]); + this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], + LITERALS[ST_COMP]); this->find_and_set_xid_as_attr (LITERALS[TYPE], component); } } void - idl3_to_xmi_visitor::gen_common_elements (AST_Decl *node, const ACE_TCHAR *stereotype) + idl3_to_xmi_visitor::gen_common_elements (AST_Decl *node, + const ACE_TCHAR *stereotype) { this->create_and_store_xmi_id (node); - this->set_attribute (LITERALS[NAME], - ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); + this->set_attribute ( + LITERALS[NAME], + ACE_TEXT_CHAR_TO_TCHAR (node->original_local_name ()->get_string ())); this->set_attribute (LITERALS[VISIBIL], LITERALS[PUBLIC]); this->set_containing_element (LITERALS[NS]); this->find_and_set_xid_as_attr (LITERALS[STEREO_ATTR], @@ -2258,6 +2503,7 @@ namespace CIAO NS_Guard ns_guard (ACE_TEXT_CHAR_TO_TCHAR (node->repoID ()), this); this->gen_tagged_value (node); } + void idl3_to_xmi_visitor::gen_component_ports (PORTS &ports, const ACE_TCHAR *component, @@ -2278,14 +2524,16 @@ namespace CIAO } } - idl3_to_xmi_visitor::ES_Guard::ES_Guard (const ACE_TCHAR *name, idl3_to_xmi_visitor *vis) + idl3_to_xmi_visitor::ES_Guard::ES_Guard (const ACE_TCHAR *name, + idl3_to_xmi_visitor *vis) : vis_ (*vis) { if (vis_.stack_.push (vis_.create_element (name))) throw Error ("element stack error"); } - idl3_to_xmi_visitor::ES_Guard::ES_Guard (DOMElement *ele, idl3_to_xmi_visitor *vis) + idl3_to_xmi_visitor::ES_Guard::ES_Guard (DOMElement *ele, + idl3_to_xmi_visitor *vis) : vis_ (*vis) { if (vis_.stack_.push (ele) != 0) @@ -2302,7 +2550,8 @@ namespace CIAO } } - idl3_to_xmi_visitor::NS_Guard::NS_Guard (const ACE_TCHAR *name, idl3_to_xmi_visitor *vis) + idl3_to_xmi_visitor::NS_Guard::NS_Guard (const ACE_TCHAR *name, + idl3_to_xmi_visitor *vis) : vis_ (*vis) { int res = vis_.namespace_.push (name); |