WONKY



LOG | FILES | OVERVIEW


#ifndef WONKY_INITIALISER_C
#define WONKY_INITIALISER_C WONKY_INITIALISER_C
#include <initialiser.h>



struct Initialiser* get_denoted_initialiser(struct Denoted_Object *to_be_initialised,struct Initialiser *initialiser,struct Translation_Data *translation_data)
{
	struct Initialiser_Denoted *ret;

	ret=wonky_malloc(sizeof(struct Initialiser_Denoted));
	ret->kind=INITIALISER_DENOTED;
	ret->to_be_initialised=to_be_initialised;
	ret->initialiser=initialiser;

	if(constraint_check_denoted_initialiser(to_be_initialised,initialiser,translation_data))
	{
		wonky_assert(is_valid_initialiser_denoted(ret));
		return (struct Initialiser*)ret;	
	}
	else
	{
		return get_initialiser_error((struct Initialiser*)ret);
	}
}
struct Initialiser* get_indexed_initialiser(struct Type *type,size_t index,struct Initialiser *initialiser,struct Translation_Data *translation_data)
{
	struct Initialiser_Indexed *ret;

	ret=wonky_malloc(sizeof(struct Initialiser_Indexed));
	ret->kind=INITIALISER_INDEXED;
	ret->type=type;
	ret->index=index;
	ret->initialiser=initialiser;

	if(constraint_check_indexed_initialiser_by_index(type,index,initialiser,translation_data))
	{
		wonky_assert(is_valid_initialiser_indexed(ret));
		return (struct Initialiser*)ret;
	}
	else
	{
		return get_initialiser_error((struct Initialiser*)ret);
	}

}
struct Initialiser* get_initialiser_expression(struct AST_Expression *expression,struct Type* type_of_initialised,struct Translation_Data *translation_data)
{
	struct Initialiser_Expression *ret;

	ret=wonky_malloc(sizeof(struct Initialiser_Expression));
	ret->kind=INITIALISER_EXPRESSION;
	ret->expression=expression;
	
	if(constraint_check_expression_initialiser(expression,type_of_initialised,translation_data))
	{
		wonky_assert(is_valid_initialiser_expression(ret));
		return (struct Initialiser*)ret;
	}
	else
	{
		return get_initialiser_error((struct Initialiser*)ret);
	}
}
struct Initialiser* get_compound_initialiser(struct Type *type,struct Queue *components,struct Translation_Data *translation_data)
{
	struct Initialiser_Compound *ret;
	size_t i;

	ret=wonky_malloc(sizeof(struct Initialiser_Compound));
	ret->kind=INITIALISER_COMPOUND;
	ret->type=type;
	ret->number_of_components=components->size;

	ret->components=wonky_malloc(sizeof(struct Initialiser**)*components->size);
	
	for(i=0;components->size>0;++i)
		ret->components[i]=Queue_Pop(components);

	wonky_free(components);/*BEWARE*/

	if(constraint_check_compound_initialiser(ret,translation_data))
	{
		wonky_assert(is_valid_initialiser_compound(ret));
		return (struct Initialiser*)ret;
	}else 
	{
		return get_initialiser_error((struct Initialiser*)ret);
	}
}
struct Initialiser* get_initialiser_error(struct Initialiser *error)
{
	struct Initialiser_Error *ret;

	ret=wonky_malloc(sizeof(struct Initialiser_Error));
	ret->kind=INITIALISER_ERROR;
	ret->error=error;

	wonky_assert(is_valid_initialiser_error(ret));
	return (struct Initialiser*)ret;
}

#endif