block.c 1.01 KB
#include <identList.h>
#include <stmtQueue.h>

typedef struct block s_block;

struct block					/* a stack of used blocks. */
{
	s_stmtQueue * stmts;
	s_identList * idl;

	s_block * prev;
};


	s_block *
blockNew (s_stmtQueue * stmts)
{
	s_block * new = (s_block *) malloc (sizeof (s_block));

	new->stmts = stmts;
	new->prev  = NULL;
	new->idl   = identListNew (new);

	return new;
}

	void
blockFree (s_block * bs)
{
	if (bs->prev != NULL)
		blockFree (bs->prev);

	if (bs->stmts != NULL)
		stmtQueueFree (bs->stmts);

	identListFree (bs->idl);

	free (bs);
}

	void
blockSetNonLocalId (s_block * bs, s_ident * id)
{
	s_identListPutVal (bs->idl, id);
}

	s_block *
blockPush (s_block ** bs, s_block * new)
{
	new->prev  = *bs;

	*bs = new;

	return *bs;
}

	s_block *
blockPop (s_block ** bs)
{
	s_block * ret = *bs;
	*bs = (*bs)->prev;

	return ret;
}

	s_block *
blockPrev (s_block * bs)
{
	return bs->prev;
}

	s_stmtQueue *
blockStmts (s_block * bs)
{
	return bs->stmts;
}

	s_identList *
blockIdl (s_block * bs)
{
	return bs->idl;
}