Mercurial > projects > ddmd
diff dmd/NullExp.d @ 72:2e2a5c3f943a
reduced warnings by adding override to the methods
think this also normalizes different line endings used all over the place
author | Trass3r |
---|---|
date | Sat, 28 Aug 2010 16:19:48 +0200 |
parents | 4290d870944a |
children | e28b18c23469 |
line wrap: on
line diff
--- a/dmd/NullExp.d Sat Aug 28 16:14:07 2010 +0200 +++ b/dmd/NullExp.d Sat Aug 28 16:19:48 2010 +0200 @@ -1,153 +1,153 @@ -module dmd.NullExp; - -import dmd.Expression; -import dmd.backend.elem; -import dmd.InterState; -import dmd.MATCH; -import dmd.Type; -import dmd.TY; -import dmd.TypeTypedef; -import dmd.OutBuffer; -import dmd.Loc; -import dmd.Scope; -import dmd.IRState; -import dmd.HdrGenState; -import dmd.TOK; -import dmd.backend.dt_t; -import dmd.backend.Util; - +module dmd.NullExp; + +import dmd.Expression; +import dmd.backend.elem; +import dmd.InterState; +import dmd.MATCH; +import dmd.Type; +import dmd.TY; +import dmd.TypeTypedef; +import dmd.OutBuffer; +import dmd.Loc; +import dmd.Scope; +import dmd.IRState; +import dmd.HdrGenState; +import dmd.TOK; +import dmd.backend.dt_t; +import dmd.backend.Util; + class NullExp : Expression { ubyte committed; this(Loc loc) - { + { super(loc, TOK.TOKnull, NullExp.sizeof); } - Expression semantic(Scope sc) + override Expression semantic(Scope sc) { -version (LOGSEMANTIC) { - printf("NullExp.semantic('%s')\n", toChars()); -} - // null is the same as (void*)0 - if (!type) - type = Type.tvoid.pointerTo(); - +version (LOGSEMANTIC) { + printf("NullExp.semantic('%s')\n", toChars()); +} + // null is the same as (void*)0 + if (!type) + type = Type.tvoid.pointerTo(); + return this; } - bool isBool(bool result) + override bool isBool(bool result) { assert(false); } - int isConst() + override int isConst() { return 0; } - void toCBuffer(OutBuffer buf, HdrGenState* hgs) + override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { buf.writestring("null"); } - void toMangleBuffer(OutBuffer buf) + override void toMangleBuffer(OutBuffer buf) { buf.writeByte('n'); } - MATCH implicitConvTo(Type t) + override MATCH implicitConvTo(Type t) { -static if (false) { - printf("NullExp.implicitConvTo(this=%s, type=%s, t=%s, committed = %d)\n", - toChars(), type.toChars(), t.toChars(), committed); -} - if (this.type.equals(t)) - return MATCH.MATCHexact; - - /* Allow implicit conversions from invariant to mutable|const, - * and mutable to invariant. It works because, after all, a null - * doesn't actually point to anything. - */ - if (t.invariantOf().equals(type.invariantOf())) - return MATCH.MATCHconst; - - // null implicitly converts to any pointer type or dynamic array - if (type.ty == TY.Tpointer && type.nextOf().ty == TY.Tvoid) - { - if (t.ty == TY.Ttypedef) - t = (cast(TypeTypedef)t).sym.basetype; - if (t.ty == TY.Tpointer || t.ty == TY.Tarray || - t.ty == TY.Taarray || t.ty == TY.Tclass || - t.ty == TY.Tdelegate) - { - return committed ? MATCH.MATCHconvert : MATCH.MATCHexact; - } - } - +static if (false) { + printf("NullExp.implicitConvTo(this=%s, type=%s, t=%s, committed = %d)\n", + toChars(), type.toChars(), t.toChars(), committed); +} + if (this.type.equals(t)) + return MATCH.MATCHexact; + + /* Allow implicit conversions from invariant to mutable|const, + * and mutable to invariant. It works because, after all, a null + * doesn't actually point to anything. + */ + if (t.invariantOf().equals(type.invariantOf())) + return MATCH.MATCHconst; + + // null implicitly converts to any pointer type or dynamic array + if (type.ty == TY.Tpointer && type.nextOf().ty == TY.Tvoid) + { + if (t.ty == TY.Ttypedef) + t = (cast(TypeTypedef)t).sym.basetype; + if (t.ty == TY.Tpointer || t.ty == TY.Tarray || + t.ty == TY.Taarray || t.ty == TY.Tclass || + t.ty == TY.Tdelegate) + { + return committed ? MATCH.MATCHconvert : MATCH.MATCHexact; + } + } + return Expression.implicitConvTo(t); } - Expression castTo(Scope sc, Type t) + override Expression castTo(Scope sc, Type t) { - NullExp e; - Type tb; - - //printf("NullExp::castTo(t = %p)\n", t); - if (type is t) - { - committed = 1; - return this; - } - - e = cast(NullExp)copy(); - e.committed = 1; - tb = t.toBasetype(); - e.type = type.toBasetype(); - - if (tb !is e.type) - { - // null implicitly converts to any pointer type or dynamic array - if (e.type.ty == TY.Tpointer && e.type.nextOf().ty == TY.Tvoid && - (tb.ty == TY.Tpointer || tb.ty == TY.Tarray || tb.ty == TY.Taarray || - tb.ty == TY.Tdelegate)) - { -static if (false) { - if (tb.ty == TY.Tdelegate) - { - TypeDelegate td = cast(TypeDelegate)tb; - TypeFunction tf = cast(TypeFunction)td.nextOf(); - - if (!tf.varargs && !(tf.arguments && tf.arguments.dim)) - { - return Expression.castTo(sc, t); - } - } -} - } - else - { - return e.Expression.castTo(sc, t); - } - } - e.type = t; + NullExp e; + Type tb; + + //printf("NullExp::castTo(t = %p)\n", t); + if (type is t) + { + committed = 1; + return this; + } + + e = cast(NullExp)copy(); + e.committed = 1; + tb = t.toBasetype(); + e.type = type.toBasetype(); + + if (tb !is e.type) + { + // null implicitly converts to any pointer type or dynamic array + if (e.type.ty == TY.Tpointer && e.type.nextOf().ty == TY.Tvoid && + (tb.ty == TY.Tpointer || tb.ty == TY.Tarray || tb.ty == TY.Taarray || + tb.ty == TY.Tdelegate)) + { +static if (false) { + if (tb.ty == TY.Tdelegate) + { + TypeDelegate td = cast(TypeDelegate)tb; + TypeFunction tf = cast(TypeFunction)td.nextOf(); + + if (!tf.varargs && !(tf.arguments && tf.arguments.dim)) + { + return Expression.castTo(sc, t); + } + } +} + } + else + { + return e.Expression.castTo(sc, t); + } + } + e.type = t; return e; } - Expression interpret(InterState istate) + override Expression interpret(InterState istate) { assert(false); } - elem* toElem(IRState* irs) + override elem* toElem(IRState* irs) { return el_long(type.totym(), 0); } - dt_t** toDt(dt_t** pdt) + override dt_t** toDt(dt_t** pdt) { - assert(type); + assert(type); return dtnzeros(pdt, cast(uint)type.size()); } }