/*
 * function call hash: a set of all functions called
 */

#include <stdio.h>

#include <hash.h>
#include "types.h"
#include "callhash.h"


extern int yyerrors;
extern void yyerror(const char *str);
extern BOOL verbose;


/* the hash */
static hash callhash = NULL;


/* helper function: print (k,v) pair */
static void printkv( FILE *out, key k, value v )
{
	fprintf( out, "\t  %s\n", k );
}


/* helper function: free value (no value) */
static void freev( value v )
{
	/* DO NOTHING */
}


void init_callhash( void )
{
	callhash = hashCreate( &printkv, &freev, NULL );
	if( verbose )
	{
		fprintf( stderr, "\tInitialized callhash" );
		//hashDump( stderr, callhash );
		fprintf( stderr, "\n" );
	}
}


void destroy_callhash( void )
{
	hashFree( callhash );
}


void mark_called( char *name )
{
	hashSet( callhash, name, (value)1 );
	if( yyerrors==0 && verbose )
	{
		fprintf( stderr, "\t- marked call to function %s\n", name );
	}
}


void foreach_call( callcb cb )
{
	hashForeach( callhash, (foreachcbfunc)cb, NULL );
}


void print_callhash( FILE *out )
{
	fprintf( stderr, "callhash now contains: " );
	hashDump( out, callhash );
}
