예제 #1
0
// 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);
   }
}
예제 #2
0
/*
 * 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;
}