Example #1
0
// Look up a branch by label.
AST_UnionBranch *
AST_Union::lookup_label (AST_UnionBranch *b)
{
  AST_UnionLabel *label = b->label ();
  AST_Expression *lv = label->label_val ();

  if (label->label_val () == 0)
    {
      return b;
    }

  AST_Decl *d = 0;
  AST_UnionBranch *fb = 0;

  lv->set_ev (lv->coerce (this->pd_udisc_type));

  if (lv->ev () == 0)
    {
      idl_global->err ()->eval_error (lv);
      return b;
    }

  for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls);
       !i.is_done();
       i.next ())
    {
      d = i.item ();

      if (d->node_type () == AST_Decl::NT_union_branch)
        {
          fb = AST_UnionBranch::narrow_from_decl (d);

          if (fb == 0)
            {
              continue;
            }

          if (fb->label() != 0
              && fb->label ()->label_kind () == AST_UnionLabel::UL_label
              && fb->label ()->label_val ()->compare (lv))
            {
              idl_global->err ()->error2  (UTL_Error::EIDL_MULTIPLE_BRANCH,
                                           this,
                                           b);
              return b;
            }
        }
    }

  return 0;
}
Example #2
0
void
AST_UnionBranch::coerce_labels (AST_Union *u)
{
  for (unsigned long i = 0; i < this->label_list_length (); ++i)
    {
      AST_UnionLabel *ul = this->label (i);

      if (ul->label_kind () == AST_UnionLabel::UL_default)
        {
          continue;
        }

      AST_Expression *lv = ul->label_val ();
      lv->set_ev (lv->coerce (u->udisc_type ()));
    }
}