Mercurial > projects > ddmd
diff dmd/TypeArray.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 2e2a5c3f943a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/TypeArray.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,134 @@ +module dmd.TypeArray; + +import dmd.Type; +import dmd.TypeNext; +import dmd.Id; +import dmd.Loc; +import dmd.ArrayTypes; +import dmd.CallExp; +import dmd.FuncDeclaration; +import dmd.VarExp; +import dmd.Expression; +import dmd.MATCH; +import dmd.Scope; +import dmd.Identifier; +import dmd.TY; +import dmd.IntegerExp; +import dmd.Global; + +// Allow implicit conversion of T[] to T* +bool IMPLICIT_ARRAY_TO_PTR() +{ + return global.params.useDeprecated; +} + +class TypeArray : TypeNext +{ + this(TY ty, Type next) + { + super(ty, next); + } + + Expression dotExp(Scope sc, Expression e, Identifier ident) + { + Type n = this.next.toBasetype(); // uncover any typedef's + + version (LOGDOTEXP) { + printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); + } + if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar)) + { + Expression ec; + FuncDeclaration fd; + Expressions arguments; + string nm; + static string name[2] = [ "_adReverseChar", "_adReverseWchar" ]; + + nm = name[n.ty == Twchar]; + fd = FuncDeclaration.genCfunc(Type.tindex, nm); + ec = new VarExp(Loc(0), fd); + e = e.castTo(sc, n.arrayOf()); // convert to dynamic array + arguments = new Expressions(); + arguments.push(cast(void*)e); + e = new CallExp(e.loc, ec, arguments); + e.type = next.arrayOf(); + } + else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar)) + { + Expression ec; + FuncDeclaration fd; + Expressions arguments; + string nm; + static string name2[2] = [ "_adSortChar", "_adSortWchar" ]; + + nm = name2[n.ty == Twchar]; + fd = FuncDeclaration.genCfunc(Type.tindex, nm); + ec = new VarExp(Loc(0), fd); + e = e.castTo(sc, n.arrayOf()); // convert to dynamic array + arguments = new Expressions(); + arguments.push(cast(void*)e); + e = new CallExp(e.loc, ec, arguments); + e.type = next.arrayOf(); + } + else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup) + { + Expression ec; + FuncDeclaration fd; + Expressions arguments; + int size = cast(int)next.size(e.loc); + int dup; + + assert(size); + dup = (ident == Id.dup || ident == Id.idup); + fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse); + ec = new VarExp(Loc(0), fd); + e = e.castTo(sc, n.arrayOf()); // convert to dynamic array + arguments = new Expressions(); + if (dup) + arguments.push(cast(void*)getTypeInfo(sc)); + arguments.push(cast(void*)e); + if (!dup) + arguments.push(cast(void*)new IntegerExp(Loc(0), size, Type.tsize_t)); + e = new CallExp(e.loc, ec, arguments); + if (ident == Id.idup) + { + Type einv = next.invariantOf(); + if (next.implicitConvTo(einv) < MATCHconst) + error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars()); + e.type = einv.arrayOf(); + } + else + e.type = next.mutableOf().arrayOf(); + } + else if (ident == Id.sort) + { + Expression ec; + FuncDeclaration fd; + Expressions arguments; + + fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort"); + ec = new VarExp(Loc(0), fd); + e = e.castTo(sc, n.arrayOf()); // convert to dynamic array + arguments = new Expressions(); + arguments.push(cast(void*)e); + arguments.push(n.ty == Tsarray + ? cast(void*)n.getTypeInfo(sc) // don't convert to dynamic array + : cast(void*)n.getInternalTypeInfo(sc)); + e = new CallExp(e.loc, ec, arguments); + e.type = next.arrayOf(); + } + else + { + e = Type.dotExp(sc, e, ident); + } + return e; + } + +version (DumbClone) { +} else { + Type clone() + { + assert(false); + } +} +} \ No newline at end of file