Hi,

This patch replaces uses of casting to Type nodes with the newly
introduced isTypeXxxx functions.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

        * d-builtins.cc (d_eval_constant_expression): Use isTypeXxxx helpers
        instead of explicit casts.
        (d_build_builtins_module): Likewise.
        * d-codegen.cc (get_array_length): Likewise.
        (identity_compare_p): Likewise.
        (lower_struct_comparison): Likewise.
        (build_array_from_val): Likewise.
        (array_bounds_check): Likewise.
        (get_function_type): Likewise.
        (d_build_call): Likewise.
        * d-compiler.cc (Compiler::paintAsType): Likewise.
        * d-convert.cc (convert_expr): Likewise.
        (convert_for_assignment): Likewise.
        * d-lang.cc (d_classify_record): Likewise.
        (d_build_eh_runtime_type): Likewise.
        * decl.cc (DeclVisitor::visit): Likewise.
        * expr.cc (ExprVisitor::needs_postblit): Likewise.
        (ExprVisitor::needs_dtor): Likewise.
        (ExprVisitor::visit): Likewise.
        * imports.cc (ImportVisitor::visit): Likewise.
        * typeinfo.cc (get_typeinfo_kind): Likewise.
        (TypeInfoVisitor::visit): Likewise.
        (TypeDeclInfoVisitor::visit): Likewise.
        * types.cc (merge_aggregate_types): Likewise.
        (TypeVisitor::visit): Likewise.
---
 gcc/d/d-builtins.cc | 15 +++++-----
 gcc/d/d-codegen.cc  | 24 ++++++---------
 gcc/d/d-compiler.cc |  4 +--
 gcc/d/d-convert.cc  |  4 +--
 gcc/d/d-lang.cc     | 13 ++++-----
 gcc/d/decl.cc       | 16 ++++------
 gcc/d/expr.cc       | 71 ++++++++++++++++++---------------------------
 gcc/d/imports.cc    |  6 ++--
 gcc/d/typeinfo.cc   | 43 ++++++++++-----------------
 gcc/d/types.cc      |  6 ++--
 10 files changed, 82 insertions(+), 120 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 91e3173e670..f1bdcb9fafd 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -388,7 +388,7 @@ d_eval_constant_expression (tree cst)
            }
 
          Expression *e = ArrayLiteralExp::create (Loc (), elements);
-         e->type = ((TypeVector *) type)->basetype;
+         e->type = type->isTypeVector ()->basetype;
 
          return VectorExp::create (Loc (), e, type);
        }
@@ -517,8 +517,8 @@ d_build_builtins_module (Module *m)
   for (size_t i = 0; vec_safe_iterate (gcc_builtins_functions, i, &decl); ++i)
     {
       const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
-      TypeFunction *tf
-       = (TypeFunction *) build_frontend_type (TREE_TYPE (decl));
+      Type *t = build_frontend_type (TREE_TYPE (decl));
+      TypeFunction *tf = t ? t->isTypeFunction () : NULL;
 
       /* Cannot create built-in function type for DECL.  */
       if (!tf)
@@ -601,14 +601,13 @@ d_build_builtins_module (Module *m)
 
   /* Expose target-specific va_list type.  */
   Type *tvalist = target.va_listType (Loc (), NULL);
-  StructDeclaration *sd = (tvalist->ty == Tstruct)
-    ? ((TypeStruct *) tvalist)->sym : NULL;
-  if (sd == NULL || !sd->isAnonymous ())
+  TypeStruct *ts = tvalist->isTypeStruct ();
+  if (ts == NULL || !ts->sym->isAnonymous ())
     members->push (build_alias_declaration ("__builtin_va_list", tvalist));
   else
     {
-      sd->ident = Identifier::idPool ("__builtin_va_list");
-      members->push (sd);
+      ts->sym->ident = Identifier::idPool ("__builtin_va_list");
+      members->push (ts->sym);
     }
 
   /* Expose target-specific integer types to the builtins module.  */
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 83e757d5a38..1bf74e1f223 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -319,7 +319,7 @@ get_array_length (tree exp, Type *type)
   switch (tb->ty)
     {
     case Tsarray:
-      return size_int (((TypeSArray *) tb)->dim->toUInteger ());
+      return size_int (tb->isTypeSArray ()->dim->toUInteger ());
 
     case Tarray:
       return d_array_length (exp);
@@ -812,9 +812,8 @@ identity_compare_p (StructDeclaration *sd)
       Type *tb = vd->type->toBasetype ();
 
       /* Check inner data structures.  */
-      if (tb->ty == Tstruct)
+      if (TypeStruct *ts = tb->isTypeStruct ())
        {
-         TypeStruct *ts = (TypeStruct *) tb;
          if (!identity_compare_p (ts->sym))
            return false;
        }
@@ -897,11 +896,10 @@ lower_struct_comparison (tree_code code, 
StructDeclaration *sd,
       tree t2ref = component_ref (t2, sfield);
       tree tcmp;
 
-      if (type->ty == Tstruct)
+      if (TypeStruct *ts = type->isTypeStruct ())
        {
          /* Compare inner data structures.  */
-         StructDeclaration *decl = ((TypeStruct *) type)->sym;
-         tcmp = lower_struct_comparison (code, decl, t1ref, t2ref);
+         tcmp = lower_struct_comparison (code, ts->sym, t1ref, t2ref);
        }
       else if (type->ty != Tvector && type->isintegral ())
        {
@@ -1680,15 +1678,13 @@ build_array_set (tree ptr, tree length, tree value)
 tree
 build_array_from_val (Type *type, tree val)
 {
-  gcc_assert (type->ty == Tsarray);
-
   tree etype = build_ctype (type->nextOf ());
 
   /* Initializing a multidimensional array.  */
   if (TREE_CODE (etype) == ARRAY_TYPE && TREE_TYPE (val) != etype)
     val = build_array_from_val (type->nextOf (), val);
 
-  size_t dims = ((TypeSArray *) type)->dim->toInteger ();
+  size_t dims = type->isTypeSArray ()->dim->toInteger ();
   vec<constructor_elt, va_gc> *elms = NULL;
   vec_safe_reserve (elms, dims);
 
@@ -1762,8 +1758,7 @@ array_bounds_check (void)
       fd = d_function_chain->function;
       if (fd && fd->type->ty == Tfunction)
        {
-         TypeFunction *tf = (TypeFunction *) fd->type;
-         if (tf->trust == TRUSTsafe)
+         if (fd->type->isTypeFunction ()->trust == TRUSTsafe)
            return true;
        }
       return false;
@@ -1783,9 +1778,9 @@ get_function_type (Type *t)
   if (t->ty == Tpointer)
     t = t->nextOf ()->toBasetype ();
   if (t->ty == Tfunction)
-    tf = (TypeFunction *) t;
+    tf = t->isTypeFunction ();
   else if (t->ty == Tdelegate)
-    tf = (TypeFunction *) ((TypeDelegate *) t)->next;
+    tf = t->isTypeDelegate ()->next->isTypeFunction ();
   return tf;
 }
 
@@ -1916,8 +1911,7 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
          if (TREE_ADDRESSABLE (TREE_TYPE (targ)))
            {
              Type *t = arg->type->toBasetype ();
-             gcc_assert (t->ty == Tstruct);
-             StructDeclaration *sd = ((TypeStruct *) t)->sym;
+             StructDeclaration *sd = t->isTypeStruct ()->sym;
 
              /* Nested structs also have ADDRESSABLE set, but if the type has
                 neither a copy constructor nor a destructor available, then we
diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index a8adb983d06..75ca15737d9 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -111,7 +111,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type 
*type)
        }
 
       /* Build vector type.  */
-      int nunits = ((TypeSArray *) expr->type)->dim->toUInteger ();
+      int nunits = expr->type->isTypeSArray ()->dim->toUInteger ();
       Type *telem = expr->type->nextOf ();
       tree vectype = build_vector_type (build_ctype (telem), nunits);
 
@@ -127,7 +127,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type 
*type)
     {
       /* Interpret value as a vector of the same size,
         then return the array literal.  */
-      int nunits = ((TypeSArray *) type)->dim->toUInteger ();
+      int nunits = type->isTypeSArray ()->dim->toUInteger ();
       Type *elem = type->nextOf ();
       tree vectype = build_vector_type (build_ctype (elem), nunits);
 
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index f93405ed956..80101f17b1d 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -467,7 +467,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
        }
       else if (tbtype->ty == Tarray)
        {
-         dinteger_t dim = ((TypeSArray *) ebtype)->dim->toInteger ();
+         dinteger_t dim = ebtype->isTypeSArray ()->dim->toInteger ();
          dinteger_t esize = ebtype->nextOf ()->size ();
          dinteger_t tsize = tbtype->nextOf ()->size ();
 
@@ -616,7 +616,7 @@ convert_for_assignment (tree expr, Type *etype, Type 
*totype)
 
       if (same_type_p (telem, ebtype))
        {
-         TypeSArray *sa_type = (TypeSArray *) tbtype;
+         TypeSArray *sa_type = tbtype->isTypeSArray ();
          uinteger_t count = sa_type->dim->toUInteger ();
 
          tree ctor = build_constructor (build_ctype (totype), NULL);
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index badd67f5a8f..5266a6550dc 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1672,11 +1672,10 @@ static classify_record
 d_classify_record (tree type)
 {
   Type *t = TYPE_LANG_FRONTEND (type);
+  TypeClass *tc = t ? t->isTypeClass () : NULL;
 
-  if (t && t->ty == Tclass)
+  if (tc != NULL)
     {
-      TypeClass *tc = (TypeClass *) t;
-
       /* extern(C++) interfaces get emitted as classes.  */
       if (tc->sym->isInterfaceDeclaration ()
          && !tc->sym->isCPPinterface ())
@@ -1814,12 +1813,10 @@ static tree
 d_build_eh_runtime_type (tree type)
 {
   Type *t = TYPE_LANG_FRONTEND (type);
+  gcc_assert (t != NULL);
+  t = t->toBasetype ();
 
-  if (t != NULL)
-    t = t->toBasetype ();
-
-  gcc_assert (t != NULL && t->ty == Tclass);
-  ClassDeclaration *cd = ((TypeClass *) t)->sym;
+  ClassDeclaration *cd = t->isTypeClass ()->sym;
   tree decl;
 
   if (cd->isCPPclass ())
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 84aa42c139b..05868631eed 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -313,9 +313,9 @@ public:
     TemplateInstance *ti = NULL;
 
     if (tb->ty == Tstruct)
-      ti = ((TypeStruct *) tb)->sym->isInstantiated ();
+      ti = tb->isTypeStruct ()->sym->isInstantiated ();
     else if (tb->ty == Tclass)
-      ti = ((TypeClass *) tb)->sym->isInstantiated ();
+      ti = tb->isTypeClass ()->sym->isInstantiated ();
 
     /* Return type is instantiated from this template declaration, walk over
        all members of the instance.  */
@@ -620,7 +620,7 @@ public:
     if (have_typeinfo_p (Type::dtypeinfo))
       create_typeinfo (d->type, NULL);
 
-    TypeEnum *tc = (TypeEnum *) d->type;
+    TypeEnum *tc = d->type->isTypeEnum ();
     if (tc->sym->members && !d->type->isZeroInit ())
       {
        /* Generate static initializer.  */
@@ -717,11 +717,8 @@ public:
          }
        else
          {
-           if (d->type->ty == Tstruct)
-             {
-               StructDeclaration *sd = ((TypeStruct *) d->type)->sym;
-               DECL_INITIAL (decl) = layout_struct_initializer (sd);
-             }
+           if (TypeStruct *ts = d->type->isTypeStruct ())
+             DECL_INITIAL (decl) = layout_struct_initializer (ts->sym);
            else
              {
                Expression *e = d->type->defaultInitLiteral (d->loc);
@@ -813,9 +810,8 @@ public:
       return;
 
     /* Check if any errors occurred when running semantic.  */
-    if (d->type->ty == Tfunction)
+    if (TypeFunction *tf = d->type->isTypeFunction ())
       {
-       TypeFunction *tf = (TypeFunction *) d->type;
        if (tf->next == NULL || tf->next->ty == Terror)
          return;
       }
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 1940480f9c4..9c80db15552 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -62,10 +62,9 @@ class ExprVisitor : public Visitor
   {
     t = t->baseElemOf ();
 
-    if (t->ty == Tstruct)
+    if (TypeStruct *ts = t->isTypeStruct ())
       {
-       StructDeclaration *sd = ((TypeStruct *) t)->sym;
-       if (sd->postblit)
+       if (ts->sym->postblit)
          return true;
       }
 
@@ -78,10 +77,9 @@ class ExprVisitor : public Visitor
   {
     t = t->baseElemOf ();
 
-    if (t->ty == Tstruct)
+    if (TypeStruct *ts = t->isTypeStruct ())
       {
-       StructDeclaration *sd = ((TypeStruct *) t)->sym;
-       if (sd->dtor)
+       if (ts->sym->dtor)
          return true;
       }
 
@@ -298,17 +296,16 @@ public:
              this->result_ = build_boolop (TRUTH_ORIF_EXPR, req, ieq);
          }
       }
-    else if (tb1->ty == Tstruct)
+    else if (TypeStruct *ts = tb1->isTypeStruct ())
       {
        /* For struct objects, identity is defined as bits in operands being
           identical also.  Alignment holes in structs are ignored.  */
-       StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
        tree t1 = build_expr (e->e1);
        tree t2 = build_expr (e->e2);
 
        gcc_assert (same_type_p (tb1, tb2));
 
-       this->result_ = build_struct_comparison (code, sd, t1, t2);
+       this->result_ = build_struct_comparison (code, ts->sym, t1, t2);
       }
     else
       {
@@ -345,7 +342,7 @@ public:
            Or when generating a NE expression:
                e1.length != e2.length || memcmp(e1.ptr, e2.ptr, size) != 0;  */
        if ((t1elem->isintegral () || t1elem->ty == Tvoid
-            || (t1elem->ty == Tstruct && !((TypeStruct *)t1elem)->sym->xeq))
+            || (t1elem->ty == Tstruct && !t1elem->isTypeStruct ()->sym->xeq))
            && t1elem->ty == t2elem->ty)
          {
            tree t1 = d_array_convert (e->e1);
@@ -367,7 +364,7 @@ public:
            /* Compare arrays using memcmp if possible, otherwise for structs,
               each field is compared inline.  */
            if (t1elem->ty != Tstruct
-               || identity_compare_p (((TypeStruct *) t1elem)->sym))
+               || identity_compare_p (t1elem->isTypeStruct ()->sym))
              {
                tree size = size_mult_expr (t1len, size_int (t1elem->size ()));
                tree tmemcmp = builtin_decl_explicit (BUILT_IN_MEMCMP);
@@ -377,7 +374,7 @@ public:
              }
            else
              {
-               StructDeclaration *sd = ((TypeStruct *) t1elem)->sym;
+               StructDeclaration *sd = t1elem->isTypeStruct ()->sym;
 
                result = build_array_struct_comparison (code, sd, t1len,
                                                        t1ptr, t2ptr);
@@ -432,24 +429,22 @@ public:
            this->result_ = result;
          }
       }
-    else if (tb1->ty == Tstruct)
+    else if (TypeStruct *ts = tb1->isTypeStruct ())
       {
        /* Equality for struct objects means the logical product of all
           equality results of the corresponding object fields.  */
-       StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
        tree t1 = build_expr (e->e1);
        tree t2 = build_expr (e->e2);
 
        gcc_assert (same_type_p (tb1, tb2));
 
-       this->result_ = build_struct_comparison (code, sd, t1, t2);
+       this->result_ = build_struct_comparison (code, ts->sym, t1, t2);
       }
     else if (tb1->ty == Taarray && tb2->ty == Taarray)
       {
        /* Use _aaEqual() for associative arrays.  */
-       TypeAArray *taa1 = (TypeAArray *) tb1;
        tree result = build_libcall (LIBCALL_AAEQUAL, e->type, 3,
-                                    build_typeinfo (e->loc, taa1),
+                                    build_typeinfo (e->loc, tb1),
                                     build_expr (e->e1),
                                     build_expr (e->e2));
 
@@ -477,9 +472,7 @@ public:
   void visit (InExp *e)
   {
     Type *tb2 = e->e2->type->toBasetype ();
-    gcc_assert (tb2->ty == Taarray);
-
-    Type *tkey = ((TypeAArray *) tb2)->index->toBasetype ();
+    Type *tkey = tb2->isTypeAArray ()->index->toBasetype ();
     tree key = convert_expr (build_expr (e->e1), e->e1->type, tkey);
 
     /* Build a call to _aaInX().  */
@@ -1031,7 +1024,7 @@ public:
        tree t1 = build_expr (e->e1);
        tree t2 = convert_for_assignment (build_expr (e->e2),
                                          e->e2->type, e->e1->type);
-       StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
+       StructDeclaration *sd = tb1->isTypeStruct ()->sym;
 
        /* Look for struct = 0.  */
        if (e->e2->op == TOKint64)
@@ -1193,7 +1186,7 @@ public:
     if (tb1->ty == Taarray)
       {
        /* Get the key for the associative array.  */
-       Type *tkey = ((TypeAArray *) tb1)->index->toBasetype ();
+       Type *tkey = tb1->isTypeAArray ()->index->toBasetype ();
        tree key = convert_expr (build_expr (e->e2), e->e2->type, tkey);
        libcall_fn libcall;
        tree tinfo, ptr;
@@ -1476,10 +1469,9 @@ public:
        Type *telem = tb1->nextOf ()->baseElemOf ();
        tree ti = null_pointer_node;
 
-       if (telem->ty == Tstruct)
+       if (TypeStruct *ts = telem->isTypeStruct ())
          {
            /* Might need to run destructor on array contents.  */
-           TypeStruct *ts = (TypeStruct *) telem;
            if (ts->sym->dtor)
              ti = build_typeinfo (e->loc, tb1->nextOf ());
          }
@@ -1493,11 +1485,10 @@ public:
        /* For pointers to a struct instance, if the struct has overloaded
           operator delete, then that operator is called.  */
        t1 = build_address (t1);
-       Type *tnext = ((TypePointer *)tb1)->next->toBasetype ();
+       Type *tnext = tb1->isTypePointer ()->next->toBasetype ();
 
-       if (tnext->ty == Tstruct)
+       if (TypeStruct *ts = tnext->isTypeStruct ())
          {
-           TypeStruct *ts = (TypeStruct *)tnext;
            if (ts->sym->dtor)
              {
                tree ti = build_typeinfo (e->loc, tnext);
@@ -1527,7 +1518,7 @@ public:
     if (e->e1->type->toBasetype ()->ty == Taarray)
       {
        Type *tb = e->e1->type->toBasetype ();
-       Type *tkey = ((TypeAArray *) tb)->index->toBasetype ();
+       Type *tkey = tb->isTypeAArray ()->index->toBasetype ();
        tree index = convert_expr (build_expr (e->e2), e->e2->type, tkey);
 
        this->result_ = build_libcall (LIBCALL_AADELX, Type::tbool, 3,
@@ -1623,7 +1614,7 @@ public:
        allocated in memory because its address is taken.  */
     if (tnext && tnext->ty == Tstruct)
       {
-       StructDeclaration *sd = ((TypeStruct *) tnext)->sym;
+       StructDeclaration *sd = tnext->isTypeStruct ()->sym;
 
        for (size_t i = 0; i < sd->fields.length; i++)
          {
@@ -1998,7 +1989,7 @@ public:
              }
            else if (tb1->ty == Tpointer && tb1->nextOf ()->ty == Tstruct)
              {
-               StructDeclaration *sd = ((TypeStruct *) tb1->nextOf ())->sym;
+               StructDeclaration *sd = tb1->nextOf ()->isTypeStruct ()->sym;
                if (sd->inv != NULL)
                  {
                    Expressions args;
@@ -2089,7 +2080,7 @@ public:
        ci = indirect_ref (ptr_type_node, ci);
 
        /* Add extra indirection for interfaces.  */
-       if (((TypeClass *) type)->sym->isInterfaceDeclaration ())
+       if (type->isTypeClass ()->sym->isInterfaceDeclaration ())
          ci = indirect_ref (ptr_type_node, ci);
 
        this->result_ = build_nop (build_ctype (e->type), ci);
@@ -2288,9 +2279,8 @@ public:
       {
        /* Allocating a new class.  */
        tb = e->newtype->toBasetype ();
-       gcc_assert (tb->ty == Tclass);
 
-       ClassDeclaration *cd = ((TypeClass *) tb)->sym;
+       ClassDeclaration *cd = tb->isTypeClass ()->sym;
        tree type = build_ctype (tb);
        tree setup_exp = NULL_TREE;
        tree new_call;
@@ -2368,10 +2358,9 @@ public:
       {
        /* Allocating memory for a new struct.  */
        Type *htype = e->newtype->toBasetype ();
-       gcc_assert (htype->ty == Tstruct);
        gcc_assert (!e->onstack);
 
-       TypeStruct *stype = (TypeStruct *) htype;
+       TypeStruct *stype = htype->isTypeStruct ();
        StructDeclaration *sd = stype->sym;
        tree new_call;
 
@@ -2443,8 +2432,7 @@ public:
       {
        /* Allocating memory for a new D array.  */
        tb = e->newtype->toBasetype ();
-       gcc_assert (tb->ty == Tarray);
-       TypeDArray *tarray = (TypeDArray *) tb;
+       TypeDArray *tarray = tb->isTypeDArray ();
 
        gcc_assert (!e->allocator);
        gcc_assert (e->arguments && e->arguments->length >= 1);
@@ -2511,7 +2499,7 @@ public:
     else if (tb->ty == Tpointer)
       {
        /* Allocating memory for a new pointer.  */
-       TypePointer *tpointer = (TypePointer *) tb;
+       TypePointer *tpointer = tb->isTypePointer ();
 
        if (tpointer->next->size () == 0)
          {
@@ -2666,7 +2654,7 @@ public:
 
     /* Implicitly convert void[n] to ubyte[n].  */
     if (tb->ty == Tsarray && tb->nextOf ()->toBasetype ()->ty == Tvoid)
-      tb = Type::tuns8->sarrayOf (((TypeSArray *) tb)->dim->toUInteger ());
+      tb = Type::tuns8->sarrayOf (tb->isTypeSArray ()->dim->toUInteger ());
 
     gcc_assert (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tpointer);
 
@@ -2781,10 +2769,9 @@ public:
   {
     /* Want the mutable type for typeinfo reference.  */
     Type *tb = e->type->toBasetype ()->mutableOf ();
-    gcc_assert (tb->ty == Taarray);
 
     /* Handle empty assoc array literals.  */
-    TypeAArray *ta = (TypeAArray *) tb;
+    TypeAArray *ta = tb->isTypeAArray ();
     if (e->keys->length == 0)
       {
        this->result_ = build_constructor (build_ctype (ta), NULL);
@@ -3018,7 +3005,7 @@ public:
        interface offset to symbol.  */
     if (this->constp_)
       {
-       TypeClass *tc = (TypeClass *) e->type;
+       TypeClass *tc = e->type->toBasetype ()->isTypeClass ();
        InterfaceDeclaration *to = tc->sym->isInterfaceDeclaration ();
 
        if (to != NULL)
diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 2e3eb7408b7..e6e696ab325 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -131,11 +131,11 @@ public:
        if (type != NULL)
          {
            if (type->ty == Tenum)
-             dsym = ((TypeEnum *) type)->sym;
+             dsym = type->isTypeEnum ()->sym;
            else if (type->ty == Tstruct)
-             dsym = ((TypeStruct *) type)->sym;
+             dsym = type->isTypeStruct ()->sym;
            else if (type->ty == Tclass)
-             dsym = ((TypeClass *) type)->sym;
+             dsym = type->isTypeClass ()->sym;
          }
       }
 
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index 8249fa7c2e8..73443eaed50 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -140,7 +140,7 @@ get_typeinfo_kind (Type *type)
       return TK_TYPELIST_TYPE;
 
     case Tclass:
-      if (((TypeClass *) type)->sym->isInterfaceDeclaration ())
+      if (type->isTypeClass ()->sym->isInterfaceDeclaration ())
        return TK_INTERFACE_TYPE;
       else
        return TK_CLASSINFO_TYPE;
@@ -619,8 +619,7 @@ public:
 
   void visit (TypeInfoEnumDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tenum);
-    TypeEnum *ti = (TypeEnum *) d->tinfo;
+    TypeEnum *ti = d->tinfo->isTypeEnum ();
     EnumDeclaration *ed = ti->sym;
 
     /* The vtable for TypeInfo_Enum.  */
@@ -652,8 +651,7 @@ public:
 
   void visit (TypeInfoPointerDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tpointer);
-    TypePointer *ti = (TypePointer *) d->tinfo;
+    TypePointer *ti = d->tinfo->isTypePointer ();
 
     /* The vtable for TypeInfo_Pointer.  */
     this->layout_base (Type::typeinfopointer);
@@ -669,8 +667,7 @@ public:
 
   void visit (TypeInfoArrayDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tarray);
-    TypeDArray *ti = (TypeDArray *) d->tinfo;
+    TypeDArray *ti = d->tinfo->isTypeDArray ();
 
     /* The vtable for TypeInfo_Array.  */
     this->layout_base (Type::typeinfoarray);
@@ -687,8 +684,7 @@ public:
 
   void visit (TypeInfoStaticArrayDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tsarray);
-    TypeSArray *ti = (TypeSArray *) d->tinfo;
+    TypeSArray *ti = d->tinfo->isTypeSArray ();
 
     /* The vtable for TypeInfo_StaticArray.  */
     this->layout_base (Type::typeinfostaticarray);
@@ -708,8 +704,7 @@ public:
 
   void visit (TypeInfoAssociativeArrayDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Taarray);
-    TypeAArray *ti = (TypeAArray *) d->tinfo;
+    TypeAArray *ti = d->tinfo->isTypeAArray ();
 
     /* The vtable for TypeInfo_AssociativeArray.  */
     this->layout_base (Type::typeinfoassociativearray);
@@ -728,8 +723,7 @@ public:
 
   void visit (TypeInfoVectorDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tvector);
-    TypeVector *ti = (TypeVector *) d->tinfo;
+    TypeVector *ti = d->tinfo->isTypeVector ();
 
     /* The vtable for TypeInfo_Vector.  */
     this->layout_base (Type::typeinfovector);
@@ -746,8 +740,8 @@ public:
 
   void visit (TypeInfoFunctionDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tfunction && d->tinfo->deco != NULL);
-    TypeFunction *ti = (TypeFunction *) d->tinfo;
+    TypeFunction *ti = d->tinfo->isTypeFunction ();
+    gcc_assert (ti->deco != NULL);
 
     /* The vtable for TypeInfo_Function.  */
     this->layout_base (Type::typeinfofunction);
@@ -767,8 +761,8 @@ public:
 
   void visit (TypeInfoDelegateDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tdelegate && d->tinfo->deco != NULL);
-    TypeDelegate *ti = (TypeDelegate *) d->tinfo;
+    TypeDelegate *ti = d->tinfo->isTypeDelegate ();
+    gcc_assert (ti->deco != NULL);
 
     /* The vtable for TypeInfo_Delegate.  */
     this->layout_base (Type::typeinfodelegate);
@@ -801,8 +795,7 @@ public:
 
   void visit (TypeInfoClassDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tclass);
-    TypeClass *ti = (TypeClass *) d->tinfo;
+    TypeClass *ti = d->tinfo->isTypeClass ();
     ClassDeclaration *cd = ti->sym;
 
     /* The vtable for ClassInfo.  */
@@ -994,8 +987,7 @@ public:
 
   void visit (TypeInfoInterfaceDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tclass);
-    TypeClass *ti = (TypeClass *) d->tinfo;
+    TypeClass *ti = d->tinfo->isTypeClass ();
 
     if (!ti->sym->vclassinfo)
       ti->sym->vclassinfo = TypeInfoClassDeclaration::create (ti);
@@ -1028,8 +1020,7 @@ public:
 
   void visit (TypeInfoStructDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tstruct);
-    TypeStruct *ti = (TypeStruct *) d->tinfo;
+    TypeStruct *ti = d->tinfo->isTypeStruct ();
     StructDeclaration *sd = ti->sym;
 
     /* The vtable for TypeInfo_Struct.  */
@@ -1128,8 +1119,7 @@ public:
 
   void visit (TypeInfoTupleDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Ttuple);
-    TypeTuple *ti = (TypeTuple *) d->tinfo;
+    TypeTuple *ti = d->tinfo->isTypeTuple ();
 
     /* The vtable for TypeInfo_Tuple.  */
     this->layout_base (Type::typeinfotypelist);
@@ -1323,8 +1313,7 @@ public:
 
   void visit (TypeInfoClassDeclaration *tid)
   {
-    gcc_assert (tid->tinfo->ty == Tclass);
-    TypeClass *tc = (TypeClass *) tid->tinfo;
+    TypeClass *tc = tid->tinfo->isTypeClass ();
     tid->csym = get_classinfo_decl (tc->sym);
   }
 };
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index f3a1c473f7a..cb9a6dec7e5 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -498,9 +498,9 @@ merge_aggregate_types (Type *type, tree deco)
   AggregateDeclaration *sym;
 
   if (type->ty == Tstruct)
-    sym = ((TypeStruct *) type)->sym;
+    sym = type->isTypeStruct ()->sym;
   else if (type->ty == Tclass)
-    sym = ((TypeClass *) type)->sym;
+    sym = type->isTypeClass ()->sym;
   else
     gcc_unreachable ();
 
@@ -671,7 +671,7 @@ public:
 
   void visit (TypeVector *t)
   {
-    int nunits = ((TypeSArray *) t->basetype)->dim->toUInteger ();
+    int nunits = t->basetype->isTypeSArray ()->dim->toUInteger ();
     tree inner = build_ctype (t->elementType ());
 
     /* Same rationale as void static arrays.  */
-- 
2.25.1

Reply via email to