view dmd/DsymbolTable.d @ 177:1475fd394c9e

bug fixes
author korDen
date Sun, 10 Oct 2010 10:38:55 +0400
parents e28b18c23469
children e3afd1303184
line wrap: on
line source

module dmd.DsymbolTable;

import dmd.common;
import dmd.StringTable;
import dmd.Dsymbol;
import dmd.Identifier;
import dmd.StringValue;

import std.stdio;

class DsymbolTable
{
    StringTable tab;

    this()
	{
		tab = new StringTable;
	}
	
    ~this()
	{
	}

    // Look up Identifier. Return Dsymbol if found, NULL if not.
    Dsymbol lookup(Identifier ident)
	{
debug {
		assert(ident);
		assert(tab);
}
		StringValue* sv = tab.lookup(ident.string_);
		return (sv ? cast(Dsymbol)sv.ptrvalue : null);
	}

    // Insert Dsymbol in table. Return NULL if already there.
    Dsymbol insert(Dsymbol s)
	{
		Identifier ident = s.ident;
debug {
		assert(ident);
		assert(tab);
}

		return insert(ident, s);
	}

    // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
    Dsymbol update(Dsymbol s)
	{
		assert(false);
	}
	
    Dsymbol insert(Identifier ident, Dsymbol s)	// when ident and s are not the same
	{
		StringValue* sv = tab.insert(ident.toChars());
		if (sv is null) {
			return null;		// already in table
		}

		sv.ptrvalue = cast(void*)s;
		return s;
	}
}