view dmd/EnumMember.d @ 79:43073c7c7769

updated to 2.035 also implemented a few missing functions still crashes in Import.importAll though
author Trass3r
date Mon, 30 Aug 2010 03:57:51 +0200
parents 2e2a5c3f943a
children e28b18c23469
line wrap: on
line source

module dmd.EnumMember;

import dmd.Dsymbol;
import dmd.Expression;
import dmd.Type;
import dmd.Loc;
import dmd.Identifier;
import dmd.Json;
import dmd.Scope;
import dmd.OutBuffer;
import dmd.HdrGenState;

class EnumMember : Dsymbol
{
	Expression value;
	Type type;

	this(Loc loc, Identifier id, Expression value, Type type)
	{
		super(id);

		this.value = value;
		this.type = type;
		this.loc = loc;
	}

	override Dsymbol syntaxCopy(Dsymbol s)
	{
		Expression e = null;
		if (value)
			e = value.syntaxCopy();

		Type t = null;
		if (type)
			t = type.syntaxCopy();

		EnumMember em;
		if (s)
		{	em = cast(EnumMember)s;
			em.loc = loc;
			em.value = e;
			em.type = t;
		}
		else
			em = new EnumMember(loc, ident, e, t);
		return em;
	}

	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		if (type)
			type.toCBuffer(buf, ident, hgs);
		else
			buf.writestring(ident.toChars());
		if (value)
		{
			buf.writestring(" = ");
			value.toCBuffer(buf, hgs);
		}
	}

	override void toJsonBuffer(OutBuffer buf)
	{
		//writef("EnumMember.toJsonBuffer()\n");
		buf.writestring("{\n");

		JsonProperty(buf, Pname, toChars());
		JsonProperty(buf, Pkind, kind());

		if (comment)
			JsonProperty(buf, Pcomment, comment);

		if (loc.linnum)
			JsonProperty(buf, Pline, loc.linnum);

		JsonRemoveComma(buf);
		buf.writestring("}\n");
	}

	override string kind()
	{
		return "enum member";
	}

	override void emitComment(Scope sc)
	{
		assert(false);
	}

	override void toDocBuffer(OutBuffer buf)
	{
		assert(false);
	}

	override EnumMember isEnumMember() { return this; }
}