}
Expression *e = ArrayLiteralExp::create (Loc (), elements);
- e->type = ((TypeVector *) type)->basetype;
+ e->type = type->isTypeVector ()->basetype;
return VectorExp::create (Loc (), e, type);
}
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)
/* 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. */
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);
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;
}
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 ())
{
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);
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;
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;
}
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
}
/* 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);
{
/* 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);
}
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 ();
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);
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 ())
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 ())
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. */
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. */
}
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);
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;
}
{
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;
}
{
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;
}
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
{
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);
/* 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);
}
else
{
- StructDeclaration *sd = ((TypeStruct *) t1elem)->sym;
+ StructDeclaration *sd = t1elem->isTypeStruct ()->sym;
result = build_array_struct_comparison (code, sd, t1len,
t1ptr, t2ptr);
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));
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(). */
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)
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;
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 ());
}
/* 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);
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,
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++)
{
}
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;
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);
{
/* 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;
{
/* 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;
{
/* 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);
else if (tb->ty == Tpointer)
{
/* Allocating memory for a new pointer. */
- TypePointer *tpointer = (TypePointer *) tb;
+ TypePointer *tpointer = tb->isTypePointer ();
if (tpointer->next->size () == 0)
{
/* 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);
{
/* 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);
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)
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;
}
}
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;
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. */
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);
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);
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);
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);
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);
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);
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);
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. */
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);
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. */
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);
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);
}
};
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 ();
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. */