// Add a node to set of nodes referenced in this scope void UTL_Scope::add_to_referenced(AST_Decl *e, idl_bool recursive) { UTL_Scope *s; AST_Decl **tmp; AST_Interface *itf; long oreferenced_allocated; long i; if (e == NULL) return ; // Special cases for forward declared interfaces and valuetypes in // the scope in which they're defined. Cannot add before full // definition is seen if ((e->node_type() == AST_Decl::NT_interface) || (e->node_type() == AST_Decl::NT_value)) { itf = AST_Interface::narrow_from_decl(e); if (itf != NULL && itf->defined_in() == this && !itf->is_defined()) return ; } // Only insert if it is not there already if (referenced(e)) return ; // Make sure there's space for one more if (pd_referenced_allocated == pd_referenced_used) { oreferenced_allocated = pd_referenced_allocated; pd_referenced_allocated += INCREMENT; tmp = new AST_Decl * [pd_referenced_allocated]; for (i = 0; i < oreferenced_allocated; i++) tmp[i] = pd_referenced[i]; delete [] pd_referenced; pd_referenced = tmp; } // Insert new reference pd_referenced[pd_referenced_used++] = e; // Now, if recursive is specified and "this" is not a common ancestor // of the referencing scope and the scope of definition of "e" then // add "e" to the set of referenced nodes in the parent of "this" if (recursive && !(e->has_ancestor(ScopeAsDecl(this)))) { s = e->defined_in(); if (s != NULL) s->add_to_referenced(e, recursive); } }
// We don't actually want the forward declaration, // but want to return the full definition member, // whether defined yet or not. AST_Decl * AST_InterfaceFwd::adjust_found ( bool ignore_fwd, bool full_def_only) { if (ignore_fwd) { AST_Interface *i = this->full_definition (); return (full_def_only && !i->is_defined () ? 0 : i); } return this; }
bool AST_InterfaceFwd::full_def_seen (void) { UTL_Scope *s = this->defined_in (); AST_Interface *i = 0; // If a full definition is seen in a previous module opening // or anywhere in the current scope (before or after our // declaration, reture TRUE. if (AST_Decl::NT_module == s->scope_node_type ()) { AST_Module *m = AST_Module::narrow_from_scope (s); AST_Decl *d = m->look_in_prev_mods_local (this->local_name (), false); if (0 != d) { i = AST_Interface::narrow_from_decl (d); if (0 != i && i->is_defined ()) { return true; } } } for (UTL_ScopeActiveIterator iter (s, UTL_Scope::IK_decls); !iter.is_done (); iter.next ()) { i = AST_Interface::narrow_from_decl (iter.item ()); if (0 != i && this->local_name ()->compare (i->local_name ())) { if (i->is_defined ()) { return true; } } } return false; }
void be_visitor_root_ch::gen_static_corba_overrides (void) { size_t size = idl_global->mixed_parentage_interfaces ().size (); if (size == 0) { return; } size_t index = 0; AST_Interface *i = 0; *o_ << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl; *o_ << be_global->core_versioning_begin (); *o_ << be_nl << "// Overrides of CORBA::release and CORBA::is_nil for" << be_nl << "// interfaces that inherit from both CORBA::Object" << be_nl << "// and CORBA::AbstractBase." << be_nl_2 << "namespace CORBA" << be_nl << "{" << be_idt; for (index = 0; index < size; ++index) { idl_global->mixed_parentage_interfaces ().dequeue_head (i); *o_ << be_nl << "TAO_NAMESPACE_STORAGE_CLASS void release (" << i->name () << "_ptr);" << be_nl << "TAO_NAMESPACE_STORAGE_CLASS ::CORBA::Boolean is_nil (" << i->name () << "_ptr);"; } *o_ << be_uidt_nl << "}"; *o_ << be_global->core_versioning_end (); }
/* * Look through inherited interfaces */ AST_Decl * UTL_Scope::look_in_inherited(UTL_ScopedName *e, idl_bool treat_as_ref) { AST_Decl *d = NULL; AST_Interface *i = AST_Interface::narrow_from_scope(this); AST_Interface **is; long nis; /* * This scope is not an interface.. */ if (i == NULL) return NULL; /* * Can't look in an interface which was not yet defined */ if (!i->is_defined()) { idl_global->err()->fwd_decl_lookup(i, e); return NULL; } /* * OK, loop through inherited interfaces. Stop when you find it */ for (nis = i->n_inherits(), is = i->inherits(); nis > 0; nis--, is++) { d = (*is)->lookup_by_name(e, treat_as_ref, I_TRUE); if (d != NULL) return d; } /* * Not found */ return NULL; }
void FE_ComponentHeader::compile_supports (UTL_NameList *supports) { if (supports == 0) { return; } AST_Decl *d = 0; UTL_ScopedName *item = 0; AST_Interface *iface = 0; AST_Type *t = 0; long j = 0; long k = 0; // Compute expanded flattened non-repeating list of interfaces // which this one inherits from. for (UTL_NamelistActiveIterator l (supports); !l.is_done (); l.next ()) { item = l.item (); // Check that scope stack is valid. if (idl_global->scopes ().top () == 0) { idl_global->err ()->lookup_error (item); // This is probably the result of bad IDL. // We will crash if we continue from here. throw Bailout (); } // Look it up. UTL_Scope *s = idl_global->scopes ().top (); d = s->lookup_by_name (item, true); if (d == 0) { AST_Decl *sad = ScopeAsDecl (s); if (sad->node_type () == AST_Decl::NT_module) { AST_Module *m = AST_Module::narrow_from_decl (sad); d = m->look_in_prev_mods_local (item->last_component ()); } } // Not found? if (d == 0) { idl_global->err ()->lookup_error (item); // This is probably the result of bad IDL. // We will crash if we continue from here. throw Bailout (); } // Remove typedefs, if any. if (d->node_type () == AST_Decl::NT_typedef) { d = AST_Typedef::narrow_from_decl (d)->primitive_base_type (); } AST_Decl::NodeType nt = d->node_type (); t = AST_Type::narrow_from_decl (d); if (nt == AST_Decl::NT_interface) { iface = AST_Interface::narrow_from_decl (d); // Undefined interface? if (!iface->is_defined ()) { idl_global->err ()->inheritance_fwd_error ( this->interface_name_, iface); continue; } // Local interface? (illegal for components to support). if (iface->is_local ()) { idl_global->err ()->unconstrained_interface_expected ( this->name (), iface->name ()); continue; } } else if (nt == AST_Decl::NT_param_holder) { AST_Param_Holder *ph = AST_Param_Holder::narrow_from_decl (d); nt = ph->info ()->type_; if (nt != AST_Decl::NT_type && nt != AST_Decl::NT_interface) { idl_global->err ()->mismatched_template_param ( ph->info ()->name_.c_str ()); continue; } } else { idl_global->err ()->interface_expected (d); continue; } // OK, see if we have to add this to the list of interfaces // inherited from. this->compile_one_inheritance (t); } // OK, install in interface header. // First the flat list (all ancestors). if (this->iused_flat_ > 0) { ACE_NEW (this->inherits_flat_, AST_Interface *[this->iused_flat_]); for (j = 0; j < this->iused_flat_; ++j) { this->inherits_flat_[j] = this->iseen_flat_[j]; } this->n_inherits_flat_ = this->iused_flat_; }
/* * Add this AST_Value node (a value type declaration) to this scope */ AST_BoxedValue *AST_Module::fe_add_boxed_valuetype(AST_BoxedValue *v) { AST_Decl *predef; AST_Interface *fwd; /* * Already defined? */ if ((predef = lookup_for_add (v)) != NULL) { /* * Treat fwd declared interfaces specially */ if (predef->node_type() == AST_Decl::NT_value) { fwd = AST_Value::narrow_from_decl(predef); if (fwd == NULL) return NULL; if (!fwd->is_defined()) { /* Forward declared and not defined yet */ if (fwd->defined_in() != this) { idl_global->err() ->error3(UTL_Error::EIDL_SCOPE_CONFLICT, fwd, v, this); return NULL; } } /* * OK, not illegal redef of forward declaration. Now check whether * it has been referenced already */ else if (referenced(predef)) { idl_global->err()->error3(UTL_Error::EIDL_DEF_USE, v, this, predef); return NULL; } } else if (!can_be_redefined(predef)) { idl_global->err()->error3(UTL_Error::EIDL_REDEF, v, this, predef); return NULL; } else if (referenced(predef)) { idl_global->err()->error3(UTL_Error::EIDL_DEF_USE, v, this, predef); return NULL; } else if (v->has_ancestor(predef)) { idl_global->err()->redefinition_in_scope(v, predef); return NULL; } } /* * Add it to scope */ add_to_scope(v); /* * Add it to set of locally referenced symbols */ add_to_referenced(v, I_FALSE); return v; }
/* * Compute the list of top-level values this one inherits from */ void FE_ValueInheritanceSpec::compile_inheritance(UTL_NameList *nl) { UTL_NamelistActiveIterator *l = new UTL_NamelistActiveIterator(nl); AST_Decl *d; AST_Interface *i; long k; long count = 0; bool present; while (!(l->is_done())) { count++; l->next(); } delete l; // count is an upper bound on inherited values pd_supports = new AST_Interface * [count]; l = new UTL_NamelistActiveIterator(nl); /* * Compute expanded flattened non-repeating list of values * which this one inherits from */ while (!(l->is_done())) { /* * Check that scope stack is valid */ if (idl_global->scopes()->top() == NULL) { idl_global->err()->lookup_error(l->item()); return ; } /* * Look it up */ d = idl_global->scopes()->top()->lookup_by_name(l->item(), I_TRUE); /* * Not found? */ if (d == NULL) { idl_global->err()->lookup_error(l->item()); return ; } /* * Not an interface? */ while (d->node_type() == AST_Decl::NT_typedef) d = AST_Typedef::narrow_from_decl(d)->base_type(); if (d->node_type() != AST_Decl::NT_interface) { idl_global->err()->value_inheritance_error(d); return ; } /* * OK, cast to an value */ i = AST_Interface::narrow_from_decl(d); if (i == NULL) idl_global->err()->value_inheritance_error(d); /* * Forward declared value? */ if (!i->is_defined()) { idl_global->err()->value_inheritance_fwd_error(i); return ; } /* * OK, see if we have to add this to the list of values * inherited from */ present = FALSE; for (k = 0; k < pd_n_supports; k++) { present = (pd_supports[k] == i); if (present) { break; } } if (!present) { pd_supports[pd_n_supports++] = i; } /* * Next element in header list */ l->next(); } delete l; }
/* * Compute the list of top-level interfaces this one inherits from */ void FE_InterfaceHeader::compile_inheritance(UTL_NameList *nl) { UTL_NamelistActiveIterator *l = new UTL_NamelistActiveIterator(nl); AST_Decl *d; AST_Interface *i; long k; iused = 0; /* * Compute expanded flattened non-repeating list of interfaces * which this one inherits from */ while (!(l->is_done())) { /* * Check that scope stack is valid */ if (idl_global->scopes()->top() == NULL) { idl_global->err()->lookup_error(l->item()); return ; } /* * Look it up */ d = idl_global->scopes()->top()->lookup_by_name(l->item(), I_TRUE); /* * Not found? */ if (d == NULL) { idl_global->err()->lookup_error(l->item()); return ; } /* * Not an interface? */ while (d->node_type() == AST_Decl::NT_typedef) d = AST_Typedef::narrow_from_decl(d)->base_type(); if (d->node_type() != AST_Decl::NT_interface) { idl_global->err()->inheritance_error(pd_interface_name, d); return ; } /* * OK, cast to an interface */ i = AST_Interface::narrow_from_decl(d); if (i == NULL) { idl_global->err()->inheritance_error(pd_interface_name, d); return; } /* * Forward declared interface? */ if (!i->is_defined()) { idl_global->err()->inheritance_fwd_error(pd_interface_name, i); return ; } /* * OK, see if we have to add this to the list of interfaces * inherited from */ compile_one_inheritance(i); /* * Next element in header list */ l->next(); } delete l; /* * OK, install in interface header */ pd_inherits = new AST_Interface * [iused]; for (k = 0; k < iused; k++) pd_inherits[k] = iseen[k]; pd_n_inherits = iused; }
bool idl_mapping_java::gen_interf(UTL_ScopedName *name, bool local, const std::vector<AST_Interface *> &inherits, const std::vector<AST_Interface *> &inherits_flat, const std::vector<AST_Attribute *> &attrs, const std::vector<AST_Operation *> &ops, const char *repoid) { JavaName jn(name); JavaName jn_ops(jn, "Operations"); JavaName jn_stub(jn, local ? "TAOPeer" : "Stub", true); string extends = jn.clazz_ + "Operations, " + (inherits.size() ? "" : "org.omg.CORBA.Object"); string extends_ops; for (size_t i = 0; i < inherits.size(); ++i) { extends += type(inherits[i]); extends_ops += type(inherits[i]) + "Operations"; if (i != inherits.size() - 1) { extends += ", "; extends_ops += ", "; } } string extends_stub = string("i2jrt.TAO") + (local ? "Local" : "") + "Object"; string allRepoIds = '"' + string(repoid) + '"', body_ops, body_stub = " protected " + jn_stub.clazz_ + "(long ptr) {\n" " super(ptr);\n" " }\n\n"; for (size_t i = 0; i < attrs.size(); ++i) { AST_Attribute *attr = attrs[i]; string signature = attr_signature_r(attr); body_ops += " " + signature + ";\n"; body_stub += " public native " + signature + ";\n\n"; if (!attr->readonly()) { string signature = attr_signature_w(attr); body_ops += " " + signature + ";\n"; body_stub += " public native " + signature + ";\n\n"; } } for (size_t i = 0; i < ops.size(); ++i) { string signature = op_signature(ops[i]); body_ops += " " + signature + ";\n"; body_stub += " public native " + signature + ";\n\n"; } for (size_t i = 0; i < inherits_flat.size(); ++i) { AST_Interface *base = inherits_flat[i]; allRepoIds += ", \"" + string(base->repoID()) + '"'; UTL_ScopeActiveIterator it(base, UTL_Scope::IK_decls); for (; !it.is_done(); it.next()) { AST_Decl *item = it.item(); if (item->node_type() == AST_Decl::NT_attr) { AST_Attribute *attr = AST_Attribute::narrow_from_decl(item); string signature = attr_signature_r(attr); body_stub += " public native " + signature + ";\n\n"; if (!attr->readonly()) { string signature = attr_signature_w(attr); body_stub += " public native " + signature + ";\n\n"; } } else if (item->node_type() == AST_Decl::NT_op) { AST_Operation *op = AST_Operation::narrow_from_decl(item); body_stub += " public native " + op_signature(op) + ";\n\n"; } } } bool ok(true); if (local) { JavaName jn_lb(jn, "LocalBase", true); string lb = " private String[] _type_ids = {" + allRepoIds + "};\n\n" " public String[] _ids() { return (String[])_type_ids.clone(); }\n"; ok = java_class_gen(jn_lb, JABSTRACT_CLASS, lb.c_str(), "org.omg.CORBA.LocalObject", jn.clazz_.c_str()); } return ok && java_class_gen(jn, JINTERFACE, "", extends.c_str()) && java_class_gen(jn_ops, JINTERFACE, body_ops.c_str(), extends_ops.c_str()) && java_class_gen(jn_stub, JCLASS, body_stub.c_str(), extends_stub.c_str(), jn.clazz_.c_str()) && gen_helper(jn, repoid, true) && gen_holder(jn); //FUTURE: server side }
int be_visitor_valuetype_fwd_any_op_ch::visit_valuetype_fwd ( be_valuetype_fwd *node ) { AST_Interface *fd = node->full_definition (); // Only a forward declared interface that is not defined in the same file // needs to have this generated here. The Any operators are needed by // portable interceptor code if the interface is a parameter of an operation. if (fd->is_defined () != 0) { return 0; } if (node->cli_hdr_any_op_gen () || node->imported ()) { return 0; } TAO_OutStream *os = this->ctx_->stream (); const char *macro = this->ctx_->export_macro (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl_2; be_module *module = 0; if (node->is_nested () && node->defined_in ()->scope_node_type () == AST_Decl::NT_module) { module = be_module::narrow_from_scope (node->defined_in ()); if (!module) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_valuebox_any_op_ch::" "visit_valuebox - " "Error parsing nested name\n"), -1); } // Some compilers handle "any" operators in a namespace // corresponding to their module, others do not. *os << "\n\n#if defined (ACE_ANY_OPS_USE_NAMESPACE)\n"; *os << be_global->core_versioning_begin () << be_nl; be_util::gen_nested_namespace_begin (os, module); // emit nested variation of any operators *os << macro << " void" << " operator<<= ( ::CORBA::Any &, " << node->local_name () << " *); // copying" << be_nl; *os << macro << " void" << " operator<<= ( ::CORBA::Any &, " << node->local_name () << " **); // non-copying" << be_nl; *os << macro << " ::CORBA::Boolean" << " operator>>= (const ::CORBA::Any &, " << node->local_name () << " *&);"; be_util::gen_nested_namespace_end (os, module); *os << be_nl << be_global->core_versioning_end () << be_nl; // emit #else *os << "#else\n\n"; } *os << be_global->core_versioning_begin () << be_nl; *os << macro << " void" << " operator<<= ( ::CORBA::Any &, " << node->name () << " *); // copying" << be_nl; *os << macro << " void" << " operator<<= ( ::CORBA::Any &, " << node->name () << " **); // non-copying" << be_nl; *os << macro << " ::CORBA::Boolean" << " operator>>= (const ::CORBA::Any &, " << node->name () << " *&);"; *os << be_global->core_versioning_end () << be_nl; if (module != 0) { *os << "\n\n#endif"; } node->cli_hdr_any_op_gen (1); return 0; }
void be_component::scan (UTL_Scope *s) { if (s == 0) { return; } AST_Extended_Port *ep = 0; AST_Mirror_Port *mp = 0; AST_Uses *u = 0; AST_Provides *p = 0; AST_Attribute *a = 0; AST_Decl::NodeType my_nt; AST_Decl::NodeType scope_nt; for (UTL_ScopeActiveIterator i (s, UTL_Scope::IK_both); !i.is_done (); i.next ()) { AST_Decl *d = i.item (); switch (d->node_type ()) { case AST_Decl::NT_provides: ++this->n_provides_; p = AST_Provides::narrow_from_decl (d); if (!p->provides_type ()->is_local ()) { ++this->n_remote_provides_; } continue; case AST_Decl::NT_uses: ++this->n_uses_; u = AST_Uses::narrow_from_decl (d); if (u->is_multiple ()) { this->has_uses_multiple_ = true; } if (!u->uses_type ()->is_local ()) { ++this->n_remote_uses_; } continue; case AST_Decl::NT_publishes: ++this->n_publishes_; continue; case AST_Decl::NT_consumes: ++this->n_consumes_; continue; case AST_Decl::NT_emits: ++this->n_emits_; continue; case AST_Decl::NT_ext_port: ep = AST_Extended_Port::narrow_from_decl (d); this->scan (ep->port_type ()); continue; case AST_Decl::NT_mirror_port: mp = AST_Mirror_Port::narrow_from_decl (d); this->mirror_scan (mp->port_type ()); continue; case AST_Decl::NT_attr: a = AST_Attribute::narrow_from_decl (d);; if (!a->readonly ()) { my_nt = this->node_type (); scope_nt = ScopeAsDecl (a->defined_in ())->node_type (); /// Attributes coming from a porttype appear /// only on connectors. if (my_nt == AST_Decl::NT_component && scope_nt == AST_Decl::NT_porttype) { continue; } this->has_rw_attributes_ = true; } continue; default: continue; } } AST_Component *c = AST_Component::narrow_from_scope (s); AST_Interface *iface = 0; if (c != 0) { for (long i = 0; i < c->n_supports (); ++i) { // See if the supported interfaces (if any) have attributes. // If CORBA::Object is supported, DeclAsScope will evaluate // to 0 and the call to scan() will return immediately. this->scan (DeclAsScope (c->supports ()[i])); } // Check the base component. If there is none, the arg to scan() // will be 0 and the call will return immediately. this->scan (c->base_component ()); } else if ((iface = AST_Interface::narrow_from_scope (s)) != 0) { for (long i = 0; i < iface->n_inherits (); ++i) { // Will pick up a chain of inheritance, // no need to use inherits_flat(). this->scan (DeclAsScope (iface->inherits ()[i])); } } }