view dmd/DtorDeclaration.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 2e2a5c3f943a
line wrap: on
line source

module dmd.DtorDeclaration;

import dmd.FuncDeclaration;
import dmd.Loc;
import dmd.Global;
import dmd.Identifier;
import dmd.Dsymbol;
import dmd.Scope;
import dmd.LINK;
import dmd.AggregateDeclaration;
import dmd.TypeFunction;
import dmd.Type;
import dmd.OutBuffer;
import dmd.HdrGenState;
import dmd.STC;
import dmd.Id;

class DtorDeclaration : FuncDeclaration
{
    this(Loc loc, Loc endloc)
	{
		super(loc, endloc, Id.dtor, STCundefined, null);
	}

    this(Loc loc, Loc endloc, Identifier id)
	{
		assert(false);
		super(loc, endloc, null, STC.init, null);
	}

    Dsymbol syntaxCopy(Dsymbol)
	{
		assert(false);
	}
	
    void semantic(Scope sc)
	{
		//printf("DtorDeclaration::semantic() %s\n", toChars());
		//printf("ident: %s, %s, %p, %p\n", ident.toChars(), Id::dtor.toChars(), ident, Id::dtor);
		parent = sc.parent;
		Dsymbol parent = toParent();
		AggregateDeclaration ad = parent.isAggregateDeclaration();
		if (!ad)
		{
			error("destructors are only for class/struct/union definitions, not %s %s", parent.kind(), parent.toChars());
		}
		else if (ident == Id.dtor)
			ad.dtors.push(cast(void*)this);

		type = new TypeFunction(null, Type.tvoid, false, LINK.LINKd);

		sc = sc.push();
		sc.stc &= ~STCstatic;		// not a static destructor
		sc.linkage = LINK.LINKd;

		FuncDeclaration.semantic(sc);

		sc.pop();
	}
	
    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		assert(false);
	}
	
    string kind()
	{
		assert(false);
	}
	
    string toChars()
	{
		return "~this";
	}
	
    bool isVirtual()
	{
		/* This should be FALSE so that dtor's don't get put into the vtbl[],
		 * but doing so will require recompiling everything.
		 */
	version (BREAKABI) {
		return false;
	} else {
		return FuncDeclaration.isVirtual();
	}
	}
	
    bool addPreInvariant()
	{
		return (isThis() && vthis && global.params.useInvariants);
	}
	
    bool addPostInvariant()
	{
		return false;
	}
	
    bool overloadInsert(Dsymbol s)
	{
		assert(false);
	}
	
    void emitComment(Scope sc)
	{
		assert(false);
	}

    DtorDeclaration isDtorDeclaration() { return this; }
}