// 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); } }
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; }
// 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; }
/* * 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; }
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; }