view dmd/VersionSymbol.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children 010eb8f0e18d
line wrap: on
line source

module dmd.VersionSymbol;

import dmd.common;
import dmd.Dsymbol;
import dmd.Loc;
import dmd.Identifier;
import dmd.Module;
import dmd.Array;
import dmd.VersionCondition;
import dmd.Scope;
import dmd.ScopeDsymbol;
import dmd.HdrGenState;
import dmd.String;
import dmd.OutBuffer;

class VersionSymbol : Dsymbol
{
    uint level;

	/* VersionSymbol's happen for statements like:
	 *	version = identifier;
	 *	version = integer;
	 */
    this(Loc loc, Identifier ident)
	{
		super(ident);
		this.loc = loc;
	}
	
    this(Loc loc, uint level)
	{
		super();

		this.level = level;
		this.loc = loc;
	}
	
    override Dsymbol syntaxCopy(Dsymbol s)
	{
		assert(false);
	}
	
    override bool addMember(Scope sc, ScopeDsymbol s, bool memnum)
	{
		//printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars());

		// Do not add the member to the symbol table,
		// just make sure subsequent debug declarations work.
		Module m = s.isModule();
		if (ident)
		{
			VersionCondition.checkPredefined(loc, ident.toChars());
			if (!m)
				error("declaration must be at module level");
			else
			{
				if (findCondition(m.versionidsNot, ident))
					error("defined after use");
				if (!m.versionids)
					m.versionids = new Array();
				m.versionids.push(cast(void*)new String(ident.toChars()));
			}
		}
		else
		{
			if (!m)
				error("level declaration must be at module level");
			else
				m.versionlevel = level;
		}

		return false;
	}
	
    override void semantic(Scope sc)
	{
	}
	
    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		assert(false);
	}
	
    override string kind()
	{
		assert(false);
	}
}