WONKY



LOG | FILES | OVERVIEW


F diff --git a/src/backend/asm/intel/intel_asm.c b/src/backend/asm/intel/intel_asm.c --- a/src/backend/asm/intel/intel_asm.c +++ b/src/backend/asm/intel/intel_asm.c
for(it=program->translation_units->first;it!=NULL;it=it->prev)
compile_translation_unit_to_intel_asm(data,it->data);
- ret=malloc(sizeof(struct Compiled_Object_Intel_Asm));
+ ret=wonky_malloc(sizeof(struct Compiled_Object_Intel_Asm));
ret->type=COMPILE_TO_INTEL_ASM;
ret->errors=data->errors;
ret->instructions=data->instructions;
{
struct Compile_Data_Intel_Asm *ret;
- ret=malloc(sizeof(struct Compile_Data_Intel_Asm));
+ ret=wonky_malloc(sizeof(struct Compile_Data_Intel_Asm));
ret->type=COMPILE_TO_INTEL_ASM;
- ret->errors=malloc(sizeof(struct Queue));
+ ret->errors=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->errors);
- ret->data_block=malloc(sizeof(struct Queue));
+ ret->data_block=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->data_block);
- ret->instructions=malloc(sizeof(struct Queue));
+ ret->instructions=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->instructions);
ret->number_of_anon_labels=0;
F diff --git a/src/backend/asm/intel/intel_asm.h b/src/backend/asm/intel/intel_asm.h --- a/src/backend/asm/intel/intel_asm.h +++ b/src/backend/asm/intel/intel_asm.h
#include <ast.h>
#include <value.h>
#include <constant.h>
+ #include <wonky_malloc.h>
struct Compile_Data_Intel_Asm
{
void push_intel_asm_instruction(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Instruction *instruction);
- void free_space_taken_for_value_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Memory_Location *location);
+ void wonky_free_space_taken_for_value_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Memory_Location *location);
void memcpy_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Memory_Location *destination,struct Intel_Asm_Memory_Location *source);
F diff --git a/src/backend/asm/intel/intel_compile.c b/src/backend/asm/intel/intel_compile.c --- a/src/backend/asm/intel/intel_compile.c +++ b/src/backend/asm/intel/intel_compile.c
{
struct Queue_Node *it;
- for(it=statement->components.first;it!=NULL;it=it->prev)
+ for(it=statement->components->first;it!=NULL;it=it->prev)
compile_ast_to_intel_asm(compile_data,it->data);
}
void compile_for_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_For_Statement *statement)
F diff --git a/src/backend/asm/intel/intel_compile.h b/src/backend/asm/intel/intel_compile.h --- a/src/backend/asm/intel/intel_compile.h +++ b/src/backend/asm/intel/intel_compile.h
#include <intel_asm.h>
#include <ast.h>
#include <map.h>
+ #include <wonky_malloc.h>
void compile_binary_expression(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_unary_expression(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary);
F diff --git a/src/backend/asm/intel/intel_instruction.c b/src/backend/asm/intel/intel_instruction.c --- a/src/backend/asm/intel/intel_instruction.c +++ b/src/backend/asm/intel/intel_instruction.c
struct Intel_Asm_Label *ret;
- ret=malloc(sizeof(struct Intel_Asm_Label));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Label));
ret->type=type;
ret->label_name=label;
++compile_data->number_of_anon_labels;
- ret=malloc(sizeof(struct Intel_Asm_Label));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Label));
ret->type=INTEL_ASM_OP_LABEL;
ret->label_name=label;
struct Intel_Asm_Instruction* get_intel_asm_binary_instruction(struct Intel_Asm_Memory_Location *left,struct Intel_Asm_Memory_Location *right,enum Intel_Asm_Instruction_Type type)
{
struct Intel_Asm_Instruction_Binary *ret;
- ret=malloc(sizeof(struct Intel_Asm_Instruction_Binary));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Instruction_Binary));
ret->type=type;
ret->left=left;
ret->right=right;
struct Intel_Asm_Instruction* get_intel_asm_unary_instruction(struct Intel_Asm_Memory_Location *operand,enum Intel_Asm_Instruction_Type type)
{
struct Intel_Asm_Instruction_Unary *ret;
- ret=malloc(sizeof(struct Intel_Asm_Instruction_Unary));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Instruction_Unary));
ret->type=type;
ret->operand=operand;
struct Intel_Asm_Instruction* get_intel_asm_jump_instruction(struct Intel_Asm_Label *where_to,enum Intel_Asm_Instruction_Type type)
{
struct Intel_Asm_Instruction_Jump *ret;
- ret=malloc(sizeof(struct Intel_Asm_Instruction_Jump));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Instruction_Jump));
ret->type=INTEL_ASM_OP_JMP;
ret->where_to=where_to;
struct Intel_Asm_Instruction* get_intel_asm_simple_instruction(enum Intel_Asm_Instruction_Type type)
{
struct Intel_Asm_Instruction *ret;
- ret=malloc(sizeof(struct Intel_Asm_Instruction));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Instruction));
ret->type=type;
return ret;
{
struct Intel_Asm_Instruction_Define_Bytes *ret;
int i;
- ret=malloc(sizeof(struct Intel_Asm_Instruction_Define_Bytes));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Instruction_Define_Bytes));
ret->type=INTEL_ASM_OP_DEFINE_BYTES;
ret->number_of_bytes=number_of_bytes;
- ret->bytes=malloc(number_of_bytes);
+ ret->bytes=wonky_malloc(number_of_bytes);
for(i=0;i<number_of_bytes;++i)
ret->bytes[i]=bytes[i];
F diff --git a/src/backend/asm/intel/intel_instruction.h b/src/backend/asm/intel/intel_instruction.h --- a/src/backend/asm/intel/intel_instruction.h +++ b/src/backend/asm/intel/intel_instruction.h
#include <intel_asm.h>
#include <stdio.h>
#include <stdlib.h>
+ #include <wonky_malloc.h>
struct Intel_Asm_Instruction
{
F diff --git a/src/backend/asm/intel/intel_location.c b/src/backend/asm/intel/intel_location.c --- a/src/backend/asm/intel/intel_location.c +++ b/src/backend/asm/intel/intel_location.c
struct Intel_Asm_Memory_Location* get_intel_by_asm_register(enum Intel_Asm_Registers reg)
{
struct Intel_Asm_Memory_Location_By_Register *ret;
- ret=malloc(sizeof(struct Intel_Asm_Memory_Location_By_Register));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_By_Register));
ret->type=INTEL_ASM_MEMORY_LOCATION_BY_REGISTER;
ret->reg=reg;
struct Intel_Asm_Memory_Location* get_intel_asm_register(enum Intel_Asm_Registers reg)
{
struct Intel_Asm_Memory_Location_Register *ret;
- ret=malloc(sizeof(struct Intel_Asm_Memory_Location_Register));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_Register));
ret->type=INTEL_ASM_MEMORY_LOCATION_REGISTER;
ret->reg=reg;
{
struct Intel_Asm_Memory_Location_By_Label *ret;
- ret=malloc(sizeof(struct Intel_Asm_Memory_Location_By_Label));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_By_Label));
ret->type=INTEL_ASM_MEMORY_LOCATION_BY_LABEL;
ret->label=label;
struct Intel_Asm_Memory_Location* get_intel_asm_stack_offset(int offset)
{
struct Intel_Asm_Memory_Location_By_Stack_Offset *ret;
- ret=malloc(sizeof(struct Intel_Asm_Memory_Location_By_Stack_Offset));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_By_Stack_Offset));
ret->type=INTEL_ASM_MEMORY_LOCATION_BY_STACK_OFFSET;
ret->offset=offset;
{
struct Intel_Asm_Memory_Location_In_Instruction_Number *ret;
- ret=malloc(sizeof(struct Intel_Asm_Memory_Location_In_Instruction_Number));
+ ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_In_Instruction_Number));
ret->type=INTEL_ASM_MEMORY_LOCATION_IN_INSTRUCTION_NUMBER;
ret->number=number;
F diff --git a/src/backend/asm/intel/intel_location.h b/src/backend/asm/intel/intel_location.h --- a/src/backend/asm/intel/intel_location.h +++ b/src/backend/asm/intel/intel_location.h
#include <intel_asm.h>
#include <stdio.h>
#include <stdlib.h>
+ #include <wonky_malloc.h>
F diff --git a/src/backend/text/lines.c b/src/backend/text/lines.c --- a/src/backend/text/lines.c +++ b/src/backend/text/lines.c
void push_line(char *string,int indent,struct Queue *where_to_push_the_line)
{
struct Line *line;
- line=malloc(sizeof(struct Line));
+ line=wonky_malloc(sizeof(struct Line));
line->data=string;
line->indent=indent;
F diff --git a/src/backend/text/lines.h b/src/backend/text/lines.h --- a/src/backend/text/lines.h +++ b/src/backend/text/lines.h
#include <queue.h>
#include <gcc_string.h>
#include <wonky_assert.h>
+ #include <wonky_malloc.h>
struct Line
F diff --git a/src/backend/text/print/print.c b/src/backend/text/print/print.c --- a/src/backend/text/print/print.c +++ b/src/backend/text/print/print.c
{
struct Compiled_Object_Print *ret;
- ret=malloc(sizeof(struct Compiled_Object_Print));
+ ret=wonky_malloc(sizeof(struct Compiled_Object_Print));
ret->type=COMPILE_TO_PRINT;
ret->lines=lines;
{
struct Compile_Data_Print *ret;
- ret=malloc(sizeof(struct Compile_Data_Print));
+ ret=wonky_malloc(sizeof(struct Compile_Data_Print));
ret->type=COMPILE_TO_PRINT;
ret->indent=0;
- ret->lines=malloc(sizeof(struct Queue));
+ ret->lines=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->lines);
- ret->errors=malloc(sizeof(struct Queue));
+ ret->errors=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->errors);
return ret;
ret=get_print_compile_object(compile_data->lines);
- free(compile_data);
+ wonky_free(compile_data);
return ret;
}
{
struct Source_File *base_file;
- struct Memory *memory;
struct Translation_Data *hold_translation_data;
char *this_directory[]={"./",NULL};
char ret;
}
ret=0;
- memory=get_memory();
-
- hold_translation_data=get_translation_data(NULL,get_linkage(),get_linkage(),memory);
+ hold_translation_data=get_translation_data(NULL,get_linkage(),get_linkage());
do
{
base_file=get_source_file(*base_source_names,this_directory);
}while(*(++base_source_names));
/*TODO fix memory leak*/
- free(hold_translation_data);
+ wonky_free(hold_translation_data);
return ret;
struct Queue_Node *it;
push_line(gstr_to_heap("{"),compile_data->indent,compile_data->lines);
++compile_data->indent;
- for(it=comp->components.first;it!=NULL;it=it->prev)
+ for(it=comp->components->first;it!=NULL;it=it->prev)
{
push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);
print_ast(compile_data,(struct AST*)(struct AST*)(it->data));
case DT_Enum_Constant:
{
char *value;
- value=malloc(1024);
+ value=wonky_malloc(1024);
if(snprintf(value,1024,"%d ",((struct Denoted_Enum_Const*)denoted)->value)==1024)
value[1023]='\0';
append_to_last_line(value,compile_data->lines);
F diff --git a/src/backend/text/print/print.h b/src/backend/text/print/print.h --- a/src/backend/text/print/print.h +++ b/src/backend/text/print/print.h
#include <print.hh>
#include <stdio.h>
#include <wonky_assert.h>
+ #include <wonky_malloc.h>
#include <wonky.h>
#include <common.h>
#include <compile.h>
F diff --git a/src/debug/debug_ast.c b/src/debug/debug_ast.c --- a/src/debug/debug_ast.c +++ b/src/debug/debug_ast.c
else
{
struct Queue_Node *it;
- for(it=statement->components.first;it!=NULL;it=it->prev)
+ for(it=statement->components->first;it!=NULL;it=it->prev)
if(!is_valid_ast(it->data))
return 0;
F diff --git a/src/debug/wobler/wobler.c b/src/debug/wobler/wobler.c --- a/src/debug/wobler/wobler.c +++ b/src/debug/wobler/wobler.c
int main(int argc,char **argv)
{
+
if(argv[1]!=NULL)
{
log_dump_location=argv[1];
{
struct Program *program;
time_t time_in,time_out;
+ wonky_memory_init();
+
time(&time_in);
program=parse_program(filenames);
passes_test[current_test]= (program->errors->size==0);
test_times[current_test]=difftime(time_out,time_in);
print_result("did not compile when it should have",filenames,program);
+
delete_program(program);
+ wonky_memory_delete();
}
void should_not_compile(char **filenames)
{
struct Program *program;
time_t time_in,time_out;
+ wonky_memory_init();
+
time(&time_in);
program=parse_program(filenames);
passes_test[current_test] = (program->errors->size != 0);
test_times[current_test]=difftime(time_out,time_in);
print_result("compiled when it should NOT have",filenames,program);
+
delete_program(program);
+ wonky_memory_delete();
}
void print_result_summary()
{
F diff --git a/src/environment/command_arguments/gcc_arguments.h b/src/environment/command_arguments/gcc_arguments.h --- a/src/environment/command_arguments/gcc_arguments.h +++ b/src/environment/command_arguments/gcc_arguments.h
#include <gcc_string.h>
#include <stdio.h>
#include <common.h>
+ #include <wonky_malloc.h>
struct Command_Arguments
F diff --git a/src/environment/error/gcc_error.c b/src/environment/error/gcc_error.c --- a/src/environment/error/gcc_error.c +++ b/src/environment/error/gcc_error.c
gstr_dup(where_in_return_message,message_format+i,i+1)
);
- ret=malloc(sizeof(struct Translation_Message));
+ ret=wonky_malloc(sizeof(struct Translation_Message));
ret->message=hold_return_string;
ret->line=line;
ret->column=column;
void push_raw_translation_error(const char *error_message,size_t line,size_t column,const char *filename,struct Translation_Data *translation_data)
{
struct Translation_Message *hold_message;
- hold_message=malloc(sizeof(struct Translation_Message));
+ hold_message=wonky_malloc(sizeof(struct Translation_Message));
hold_message->message=gstr_to_heap(error_message);
hold_message->filename=filename;
hold_message->line=line;
}
void delete_translation_error(struct Translation_Message *translation_error)
{
- free(translation_error);
+ wonky_free(translation_error);
}
void print_compile_errors(FILE *out,struct Queue *errors)
{
F diff --git a/src/frontend/lex/lexer.c b/src/frontend/lex/lexer.c --- a/src/frontend/lex/lexer.c +++ b/src/frontend/lex/lexer.c
if(src->is_in_the_begining_of_line)
{
parse_preproc_line(src,translation_data);
- free(current_token);
+ wonky_free(current_token);
}else
{
push_lexing_error("preprocessing directive must be at the beggining of the line",src,translation_data);
- free(current_token);
+ wonky_free(current_token);
while((current_token=get_next_token(src,&chonky[0],0))->type!=KW_NOTYPE)
{
- free(current_token);
+ wonky_free(current_token);
}
- free(current_token);
+ wonky_free(current_token);
}
}else if(current_token->type!=KW_NOTYPE)
{
if(src->where_in_src!=src->src_size)
push_lexing_error("unexpected character",src,translation_data);
- free(current_token);
+ wonky_free(current_token);
return;
}
}
struct token_vector ret;
struct token *hold;
- ret.tokens=malloc(sizeof(struct token)*tokens->size);
+ ret.tokens=wonky_malloc(sizeof(struct token)*tokens->size);
ret.size=tokens->size;
for(i=0;tokens->size>0;++i)
{
hold=Queue_Pop(tokens);
ret.tokens[i]=*hold;
- free(hold);
+ wonky_free(hold);
}
Queue_Destroy(tokens);
}else
{
hold_token=Queue_Pop(translation_data->tokens);
- free(hold_token);
+ wonky_free(hold_token);
return 1;
}
}
}else
{
hold_token=Queue_Pop(translation_data->tokens);
- free(hold_token);
+ wonky_free(hold_token);
return 1;
}
}
void chomp(struct Translation_Data *translation_data)
{
- free(Queue_Pop(translation_data->tokens));
+ wonky_free(Queue_Pop(translation_data->tokens));
}
enum KEYWORDS kw_get(struct Translation_Data *translation_data)
struct token* copy_token(struct token *src)
{
struct token *cpy;
- cpy=malloc(sizeof(struct token));
+ cpy=wonky_malloc(sizeof(struct token));
*cpy=*src;
return cpy;
}
struct token* src_extract_token(struct Source_File *src,enum KEYWORDS kw)
{
struct token *ret;
- ret=malloc(sizeof(struct token));
+ ret=wonky_malloc(sizeof(struct token));
ret->type=kw;
ret->data_size=src->best_token_size;
void delete_source_file(struct Source_File *src)
{
delete_source_name(src->src_name);
- free(src->src);
- free(src);
+ wonky_free(src->src);
+ wonky_free(src);
}
void delete_source_name(struct Source_Name *name)
{
- free(name->filename);
- free(name->base);
- free(name);
+ wonky_free(name->filename);
+ wonky_free(name->base);
+ wonky_free(name);
}
void flush_tokens(struct Queue *tokens)
{
while(tokens->size>0)
- free(Queue_Pop(tokens));
+ wonky_free(Queue_Pop(tokens));
}
#endif
F diff --git a/src/frontend/lex/lexer.h b/src/frontend/lex/lexer.h --- a/src/frontend/lex/lexer.h +++ b/src/frontend/lex/lexer.h
#include <program.h>
#include <preprocessing.h>
#include <common.h>
+ #include <wonky_malloc.h>
extern char *well_known_locations_base[];
struct token
F diff --git a/src/frontend/lex/preprocessing.c b/src/frontend/lex/preprocessing.c --- a/src/frontend/lex/preprocessing.c +++ b/src/frontend/lex/preprocessing.c
switch(hold->type)
{
case PKW_INCLUDE:
- free(hold);
+ wonky_free(hold);
parse_include_line(src,translation_data);
return;
case PKW_DEFINE:
- free(hold);
+ wonky_free(hold);
parse_define_line(src,translation_data);
return;
case PKW_IF:
- free(hold);
+ wonky_free(hold);
parse_preproc_if_line(src,translation_data);
return;
case PKW_IFDEF:
- free(hold);
+ wonky_free(hold);
parse_preproc_ifdef_line(src,translation_data);
return;
case PKW_IFNDEF:
- free(hold);
+ wonky_free(hold);
parse_preproc_ifndef_line(src,translation_data);
return;
case PKW_UNDEF:
- free(hold);
+ wonky_free(hold);
parse_preproc_undef_line(src,translation_data);
return;
case PKW_ENDIF:
- free(hold);
+ wonky_free(hold);
push_lexing_error("unmatched endif",src,translation_data);
return;
case PKW_ELSE:
- free(hold);
+ wonky_free(hold);
push_lexing_error("unmatched else",src,translation_data);
return;
case PKW_ELIF:
- free(hold);
+ wonky_free(hold);
push_lexing_error("unmatched elif",src,translation_data);
return;
case PKW_LINE:
- free(hold);
+ wonky_free(hold);
parse_preproc_line_line(src,translation_data);
return;
case PKW_ERROR:
- free(hold);
+ wonky_free(hold);
parse_preproc_error_line(src,translation_data);
return;
default:
/*TODO error*/
- free(hold);
+ wonky_free(hold);
push_lexing_error("expected a preprocessing directive",src,translation_data);
return;
{
/*TODO error*/
push_lexing_error("file in include directive not found",src,translation_data);
- free(hold);
+ wonky_free(hold);
return;
}
}
lex_program(translation_data,hold_file);
- free(hold);
+ wonky_free(hold);
}else if(hold->type==KW_LESS)/*hack*/
{
struct Source_File *hold_file;
if(src->where_in_src==src->src_size)
{
/*TODO error*/
- free(hold);
+ wonky_free(hold);
return;
}
/*skip the >*/
{
/*TODO error*/
push_lexing_error("file in include directive not found",src,translation_data);
- free(hold);
+ wonky_free(hold);
return;
}
lex_program(translation_data,hold_file);
- free(hold);
+ wonky_free(hold);
}else
{
/*TODO error*/
push_lexing_error("include error",src,translation_data);
- free(hold);
+ wonky_free(hold);
return;
}
macro_name=get_next_token(src,&chonky[0],0);
if(macro_name->type!=KW_ID)
{
- free(macro_name);
+ wonky_free(macro_name);
push_lexing_error("expected id after #define",src,translation_data);
return;
}
hold_token=get_next_token(src,&chonky[0],0);
if(hold_token->type==KW_OPEN_NORMAL)
{
- free(hold_token);
+ wonky_free(hold_token);
while(1)
{
hold_token=get_next_token(src,&chonky[0],0);
if(hold_token->type!=KW_ID)
{
push_lexing_error("expected id in define argument list",src,translation_data);
- free(hold_token);
+ wonky_free(hold_token);
break;
}
- hold_index=malloc(sizeof(int));
+ hold_index=wonky_malloc(sizeof(int));
*hold_index=number_of_arguments;
++number_of_arguments;
- Map_Push(new_macro->arguments,hold_token->data,hold_token->data_size,hold_index,translation_data->memory);
- free(hold_token);
+ Map_Push(new_macro->arguments,hold_token->data,hold_token->data_size,hold_index);
+ wonky_free(hold_token);
hold_token=get_next_token(src,&chonky[0],0);
if(hold_token->type!=KW_COMMA)
{
if(hold_token->type==KW_CLOSE_NORMAL)
{
- free(hold_token);
+ wonky_free(hold_token);
break;
}else
{
push_lexing_error("expected ',' in define argument list",src,translation_data);
- free(hold_token);
+ wonky_free(hold_token);
break;
}
}
- free(hold_token);
+ wonky_free(hold_token);
}
}else if(hold_token->type==KW_NOTYPE)
{
- free(hold_token);
+ wonky_free(hold_token);
}
/*push things*/
}
/*removing the notype token*/
- free(hold_token);
+ wonky_free(hold_token);
translation_data->tokens=hold_tokens;
/*push the directive into the macro map*/
- Map_Push(translation_data->macros,macro_name->data,macro_name->data_size,new_macro,translation_data->memory);
- //free(macro_name);
+ Map_Push(translation_data->macros,macro_name->data,macro_name->data_size,new_macro);
+ //wonky_free(macro_name);
chase_new_line(src,translation_data);
}
struct define_directive* get_define_directive(struct token* macro_name)
{
struct define_directive *ret;
- ret=malloc(sizeof(struct token));
+ ret=wonky_malloc(sizeof(struct token));
ret->macro_name=macro_name;
- ret->macro_tokens=malloc(sizeof(struct Queue));
+ ret->macro_tokens=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->macro_tokens);
- ret->arguments=malloc(sizeof(struct Map));
+ ret->arguments=wonky_malloc(sizeof(struct Map));
Map_Init(ret->arguments);
ret->number_of_arguments=0;
if(number_of_arguments==0)
return NULL;
- ret=malloc(sizeof(struct Queue)*number_of_arguments);
+ ret=wonky_malloc(sizeof(struct Queue)*number_of_arguments);
for(i=0;i<number_of_arguments;++i)
{
return;
}
flush_macro_arguments(number_of_arguments,args);
- free(args);
+ wonky_free(args);
}
void expand_macro_argument(struct Queue *replacement_tokens,struct Source_File *src,struct Translation_Data *translation_data)
if(hold->type!=KW_OPEN_NORMAL)
{
push_lexing_error("expected '(' in macro expansion",src,translation_data);
- free(hold);
+ wonky_free(hold);
return;
}
- free(hold);
+ wonky_free(hold);
hack=translation_data->tokens;
for(i=0;i<number_of_arguments-1;++i)
if(hold->type==KW_NOTYPE)
{
push_lexing_error("expected ',' in macro argument list",src,translation_data);
- free(hold);
+ wonky_free(hold);
goto cleanup;
}
if(j==0)
{
push_lexing_error("expected argument in macro argument list",src,translation_data);
- free(hold);
+ wonky_free(hold);
goto cleanup;
}
if(hold->type==KW_NOTYPE)
{
push_lexing_error("expected ')' in macro argument list",src,translation_data);
- free(hold);
+ wonky_free(hold);
goto cleanup;
}
expand_macro(hold,src,translation_data);
if(j==0)
{
push_lexing_error("expected argument in macro argument list",src,translation_data);
- free(hold);
+ wonky_free(hold);
}
cleanup:
for(i=0;i<number_of_arguments;++i)
{
while(args[i].size>0)
- free(Queue_Pop(args+i));
+ wonky_free(Queue_Pop(args+i));
}
}
- /*macro name token is freed on expansion , if it is not a macro name it is pushed into token queue*/
+ /*macro name token is wonky_freed on expansion , if it is not a macro name it is pushed into token queue*/
void expand_macro(struct token* macro_name,struct Source_File *src,struct Translation_Data *translation_data)
{
struct define_directive *hold=NULL;
hold=Map_Check(translation_data->macros,macro_name->data,macro_name->data_size);
if(hold!=NULL)
{
- free(macro_name);
+ wonky_free(macro_name);
argument_list=make_define_argument_list(hold->number_of_arguments);
load_macro_arguments(argument_list,hold->number_of_arguments,src,translation_data);
if(translation_data->errors->size>0)
src->src[src->where_in_src]=just_in_case;
if(hold_token!=NULL)
- free(hold_token);
+ wonky_free(hold_token);
do
{
hold_token=preproc_find_else(src,translation_data,0);
if(hold_token)
- free(hold_token);
+ wonky_free(hold_token);
else
break;
}while(!has_new_errors(translation_data));
if(hold_token!=NULL)
{
- free(hold_token);
+ wonky_free(hold_token);
push_lexing_error("could not find matching #else, #elif or #endif",src,translation_data);
}
}
hold_token=get_next_token(src,&chonky[0],1);
if(hold_token->type==KW_HASHTAG)
{
- free(hold_token);
+ wonky_free(hold_token);
hold_token=get_next_token(src,&chonky_jr[0],0);
switch(hold_token->type)
{
break;
}
case PKW_NOTYPE:
- free(hold_token);
+ wonky_free(hold_token);
goto_new_line(src,translation_data);
return NULL;
}
- free(hold_token);
+ wonky_free(hold_token);
}else if(hold_token->type!=KW_NOTYPE)
{
- free(hold_token);
+ wonky_free(hold_token);
}else
{
if(src->where_in_src!=src->src_size)
push_lexing_error("unexpected character",src,translation_data);
- free(hold_token);
+ wonky_free(hold_token);
return NULL;
}
goto_new_line(src,translation_data);
hold_token=get_next_token(src,&chonky[0],0);
if(hold_token==NULL || hold_token->type!=KW_ID)
{
- free(hold_token);
+ wonky_free(hold_token);
push_lexing_error("expected an id here",src,translation_data);
chase_new_line(src,translation_data);
return;
preproc_lex_first_part(src,translation_data);
}else
{
- free(hold_token);
+ wonky_free(hold_token);
hold_token=preproc_find_else(src,translation_data,1);
preproc_lex_first_part(src,translation_data);
}
- free(hold_token);
+ wonky_free(hold_token);
}
}
{
push_lexing_error("expected an id here",src,translation_data);
chase_new_line(src,translation_data);
- free(hold_token);
+ wonky_free(hold_token);
return;
}else
{
if(!Map_Check(translation_data->macros,hold_token->data,hold_token->data_size))
{
- free(hold_token);
+ wonky_free(hold_token);
preproc_lex_first_part(src,translation_data);
}else
{
- free(hold_token);
+ wonky_free(hold_token);
hold_token=preproc_find_else(src,translation_data,1);
if(hold_token!=NULL && hold_token->type==PKW_ELIF)
preproc_find_else(src,translation_data,0);
preproc_lex_first_part(src,translation_data);
}
- free(hold_token);
+ wonky_free(hold_token);
}
}
Map_Remove(translation_data->macros,id->data,id->data_size);
}
}
- free(id);
+ wonky_free(id);
chase_new_line(src,translation_data);
}
void parse_preproc_error_line(struct Source_File *src,struct Translation_Data *translation_data)
hold_name->data[hold_name->data_size]='\0';
if(tokens->size>0)
{
- free(hold_line);
- free(hold_name);
+ wonky_free(hold_line);
+ wonky_free(hold_name);
flush_tokens(tokens);
push_lexing_error("expected a new line in #line preprocessing directive here",src,translation_data);
return;
}else if(tokens->size>0)
{
- free(hold_line);
+ wonky_free(hold_line);
flush_tokens(tokens);
push_lexing_error("expected a string or new line in #line preprocessing directive here",src,translation_data);
return;
}
void delete_macro(void *macro)
{
+ /*
#define AS_MACRO(x) ((struct define_directive*)macro)
- free(AS_MACRO(macro)->macro_name);
+ wonky_free(AS_MACRO(macro)->macro_name);
flush_tokens(AS_MACRO(macro)->macro_tokens);
- free(AS_MACRO(macro)->macro_tokens);
- Map_Map(AS_MACRO(macro)->arguments,free);
- free(AS_MACRO(macro)->arguments);
- free(macro);
+ wonky_free(AS_MACRO(macro)->macro_tokens);
+ Map_Map(AS_MACRO(macro)->arguments,wonky_free);
+ wonky_free(AS_MACRO(macro)->arguments);
+ wonky_free(macro);
#undef AS_MACRO
+ */
}
struct Queue* lex_line(struct Source_File *src,struct Translation_Data *translation_data,char lex_defined_token)
{
struct Queue *tokens;
char just_in_case;
- tokens=malloc(sizeof(struct Queue));
+ tokens=wonky_malloc(sizeof(struct Queue));
Queue_Init(tokens);
{
if(lex_defined_token && hold_token->type==KW_ID && hold_token->data_size==7 && gstrn_cmp(hold_token->data,"defined",7))
{
- free(hold_token);
+ wonky_free(hold_token);
hold_token=get_next_token(&temp_src,&chonky[0],0);
if(hold_token->type==KW_OPEN_NORMAL)
{
- free(hold_token);
+ wonky_free(hold_token);
hold_token=get_next_token(&temp_src,&chonky[0],0);
if(hold_token->type!=KW_ID)
{
Queue_Push(tokens,hold_token);
}
- free(hold_token);
+ wonky_free(hold_token);
src->src[src->where_in_src]=just_in_case;
return tokens;
F diff --git a/src/frontend/parse/parse_declaration.c b/src/frontend/parse/parse_declaration.c --- a/src/frontend/parse/parse_declaration.c +++ b/src/frontend/parse/parse_declaration.c
}
}
- free(prototype);
+ wonky_free(prototype);
}
{
struct Queue *hack;
struct Queue *hold;
- hack=malloc(sizeof(struct Queue));
+ hack=wonky_malloc(sizeof(struct Queue));
Queue_Init(hack);
while(!check(translation_data,KW_CLOSE_NORMAL,0))
base->denotation=DT_Error;
while(hack->size)
{
- free(Queue_Pop(hack));
+ wonky_free(Queue_Pop(hack));
}
- free(hack);
+ wonky_free(hack);
push_translation_error("declarator error",translation_data);
return;
}
- free(hack);
+ wonky_free(hack);
}else
{
function_prototype_scope=(struct Normal_Scope*)get_normal_scope(scope,FUNCTION_PROTOTYPE_SCOPE);
- parameters=malloc(sizeof(struct Queue));
+ parameters=wonky_malloc(sizeof(struct Queue));
Queue_Init(parameters);
is_variadic=parse_paramenter_list(translation_data,function_prototype_scope,parameters);
}else
{
- free(prototype);
+ wonky_free(prototype);
push_translation_error("there is a problem with the declarator",translation_data);
return 0;
}
if(!get_and_check(translation_data,KW_COMMA) && !check(translation_data,KW_SEMI_COLUMN,0))
{
- free(prototype);
+ wonky_free(prototype);
push_translation_error("semi column expected in struct declaration",translation_data);
return 0;
}
}
- free(prototype);
+ wonky_free(prototype);
return 1;
}
current_object=type_of_initialised->struct_union->members->first;
- components=malloc(sizeof(struct Queue));
+ components=wonky_malloc(sizeof(struct Queue));
Queue_Init(components);
do{
size_t current_object;
struct Initialiser *current_initialiser;
- components=malloc(sizeof(struct Queue));
+ components=wonky_malloc(sizeof(struct Queue));
Queue_Init(components);
do{
F diff --git a/src/frontend/parse/parse_expression.c b/src/frontend/parse/parse_expression.c --- a/src/frontend/parse/parse_expression.c +++ b/src/frontend/parse/parse_expression.c
return (struct AST_Expression*)get_error_tree(NULL);
}
hold_token=Queue_Pop(translation_data->tokens);
- switch(hold_token->type) /*the token is not freed so there is a memory leak here*/
+ switch(hold_token->type) /*the token is not wonky_freed so there is a memory leak here*/
{
case KW_STRING:
case KW_WIDE_STRING:
F diff --git a/src/frontend/parse/parse_statement.c b/src/frontend/parse/parse_statement.c --- a/src/frontend/parse/parse_statement.c +++ b/src/frontend/parse/parse_statement.c
while(!get_and_check(translation_data,KW_CLOSE_CURLY) && !has_no_tokens(translation_data))
{
if(is_type(translation_data,hold->scope,0))
- parse_declaration(translation_data,hold->scope,&hold->components);
+ parse_declaration(translation_data,hold->scope,hold->components);
else
- Queue_Push(&hold->components,parse_statement(translation_data,hold->scope,parse_data));
+ Queue_Push(hold->components,parse_statement(translation_data,hold->scope,parse_data));
if(has_new_errors(translation_data))
chase_next_semicolumn(translation_data);
F diff --git a/src/misc/gcc_string.c b/src/misc/gcc_string.c --- a/src/misc/gcc_string.c +++ b/src/misc/gcc_string.c
char* gstr_append(const char *lead,const char *follower)
{
char *ret,*hold;
- hold=ret=malloc(gstrlen(lead) + gstrlen(follower)+1);
+ hold=ret=wonky_malloc(gstrlen(lead) + gstrlen(follower)+1);
while(*(hold++)=*(lead++));
hold--;
while(*(hold++)=*(follower++));
}
char* gstrcpy(const char *str)
{
- char *temp=malloc(gstrlen(str)+1);
+ char *temp=wonky_malloc(gstrlen(str)+1);
for(size_t i=0;(temp[i]=str[i])!='\0';++i);
return temp;
}
char* gstrncpy(const char *str,size_t size)
{
size_t i;
- char *temp=malloc(size+1);
+ char *temp=wonky_malloc(size+1);
for(i=0;i<size;++i)
temp[i]=str[i];
return temp;
ret=gstr_append(lead,follower);
- free((void*)lead),free((void*)follower);
+ wonky_free((void*)lead);
+ wonky_free((void*)follower);
return ret;
}
if((ssize_t)diff<0 || (size_t)diff>=limit)
{
- ret=malloc(1);
+ ret=wonky_malloc(1);
ret[0]='\0';
return ret;
}else
{
- ret=malloc((size_t)diff+1);
+ ret=wonky_malloc((size_t)diff+1);
ret[(size_t)diff]='\0';
for(i=0;first+i!=last;++i)
literal_length=gstrlen(literal);
- ret=malloc(literal_length+1);
+ ret=wonky_malloc(literal_length+1);
for(i=0;i<=literal_length;++i)
ret[i]=literal[i];
F diff --git a/src/misc/gcc_string.h b/src/misc/gcc_string.h --- a/src/misc/gcc_string.h +++ b/src/misc/gcc_string.h
#include <stddef.h>
#include <wonky_assert.h>
#include <common.h>
+ #include <wonky_malloc.h>
F diff --git a/src/misc/map.c b/src/misc/map.c --- a/src/misc/map.c +++ b/src/misc/map.c
/*
* tree must not be null
* */
- void Map_Push(Map *tree,void *str,size_t size,void *id,struct Memory *mem)
+ void Map_Push(Map *tree,void *str,size_t size,void *id)
{
size_t temp;
Map_Scour(tree,str,size,&temp,&tree);
}
for(temp;temp<size;++temp)
{
- tree=tree->delta[((unsigned char*)str)[temp]]=wonky_malloc_map_node(mem);
+ tree=tree->delta[((unsigned char*)str)[temp]]=wonky_malloc_map_node();
/*
Map_Init(
- tree=tree->delta[((unsigned char*)str)[temp]]=malloc(sizeof(Map))
+ tree=tree->delta[((unsigned char*)str)[temp]]=wonky_malloc(sizeof(Map))
);
*/
}
Stack_Push(&stk,tree);
}
if(tree->delta[((unsigned char*)str)[where]] == NULL)return;
- free(tree->delta[((unsigned char*)str)[where]]);
- while(stk.size>1)free(Stack_Pop(&stk));
+ wonky_free_map_node(tree->delta[((unsigned char*)str)[where]]);
+ while(stk.size>1)wonky_free_map_node(Stack_Pop(&stk));
tree=(Map*)Stack_Pop(&stk);
tree->delta[(unsigned char)what_to_null]=NULL;
}
- /*this does not destroy(free) any memory pointed to by a node in the Map. This does not free() the root (Map *tree) */
+ /*this does not destroy(wonky_free) any memory pointed to by a node in the Map. This does not wonky_free() the root (Map *tree) */
/*This function especially does not require that the map has no loop ( for example after grepification )*/
void Map_Destroy(Map *tree)
{
while(nodes.size>1)
{
current_node=Stack_Pop(&nodes);
- /*Again the things that ID points to is not freed ( this structure is used to map the structure of data )
+ /*Again the things that ID points to is not wonky_freed ( this structure is used to map the structure of data )
deletion of it is up to you.
*/
- free(current_node);
+ wonky_free_map_node(current_node);
}
- /*this is where the root is at- we don't delete it , but we must free the last stack node*/
+ /*this is where the root is at- we don't delete it , but we must wonky_free the last stack node*/
Stack_Pop(&nodes);
return NULL;
}
- ret=malloc(sizeof(Map));
+ ret=wonky_malloc(sizeof(Map));
ret->is_final=cpy->is_final;
ret->ID=cpy->ID;
}
}
- struct Map* Map_Push_And_Get(struct Map* tree,void *str,size_t size,void *id,struct Memory *mem)
+ struct Map* Map_Push_And_Get(struct Map* tree,void *str,size_t size,void *id)
{
size_t temp;
Map_Scour(tree,str,size,&temp,&tree);
Map_Init(
tree=
tree->delta[((unsigned char*)str)[temp]]=
- malloc(sizeof(Map))
+ wonky_malloc(sizeof(Map))
);
}
return tree;
}
- void* Map_Check_And_Push(struct Map *tree,void *str,size_t size,void *id,struct Memory *mem)
+ void* Map_Check_And_Push(struct Map *tree,void *str,size_t size,void *id)
{
size_t temp;
Map_Scour(tree,str,size,&temp,&tree);
}
for(temp;temp<size;++temp)
{
- tree=tree->delta[((unsigned char*)str)[temp]]=calloc(1,sizeof(Map));
+ tree=tree->delta[((unsigned char*)str)[temp]]=wonky_malloc_map_node();
/*
Map_Init(
- tree=tree->delta[((unsigned char*)str)[temp]]=malloc(sizeof(Map))
+ tree=tree->delta[((unsigned char*)str)[temp]]=wonky_malloc(sizeof(Map))
);
*/
}
tree->is_final=1;
return NULL;
}
- /*requires that the map has no loops. does not free the root node*/
+ /*requires that the map has no loops. does not wonky_free the root node*/
/*TODO*/
void Map_Delete_Map(struct Map *tree)
{
F diff --git a/src/misc/map.h b/src/misc/map.h --- a/src/misc/map.h +++ b/src/misc/map.h
void Map_Init(Map *tree);
void Map_Scour(Map *tree,void *str,size_t size,size_t *where,Map **final_node);
- void Map_Push(Map *tree,void *str,size_t size,void *id,struct Memory *mem);
+ void Map_Push(Map *tree,void *str,size_t size,void *id);
void* Map_Check(Map *tree, void *str,size_t size);
struct Map* Map_Check_And_Get(Map *tree, void *str,size_t size);
void Map_Remove(Map *tree, void *str,size_t size);
void Map_Delete_Map(struct Map *tree);
struct Condensed_Map* Map_Condense(Map* tree);
- struct Map* Map_Push_And_Get(struct Map* tree,void *str,size_t size,void *id,struct Memory *mem);
+ struct Map* Map_Push_And_Get(struct Map* tree,void *str,size_t size,void *id);
/*returns NULL if id is not taken , returns pointer to taken id otherwise*/
- void* Map_Check_And_Push(struct Map *tree,void *str,size_t size,void *id,struct Memory *mem);
+ void* Map_Check_And_Push(struct Map *tree,void *str,size_t size,void *id);
#endif
F diff --git a/src/misc/queue.c b/src/misc/queue.c --- a/src/misc/queue.c +++ b/src/misc/queue.c
if(q==NULL)return;
if(q->first==NULL)
{
- q->first=q->last=malloc(sizeof(struct Queue_Node));
+ q->first=q->last=wonky_malloc(sizeof(struct Queue_Node));
q->first->data=data;
q->last->prev=NULL;
return;
}else
{
- struct Queue_Node *temp=malloc(sizeof(struct Queue_Node));
+ struct Queue_Node *temp=wonky_malloc(sizeof(struct Queue_Node));
q->last->prev=temp;
temp->data=data;
temp->prev=NULL;
if(q==NULL)return;
if(q->first==NULL)
{
- q->first=q->last=malloc(sizeof(struct Queue_Node));
+ q->first=q->last=wonky_malloc(sizeof(struct Queue_Node));
q->first->data=data;
q->last->prev=NULL;
++q->size;
}else
{
- struct Queue_Node *temp=malloc(sizeof(struct Queue_Node));
+ struct Queue_Node *temp=wonky_malloc(sizeof(struct Queue_Node));
temp->prev=q->first;
temp->data=data;
if(q->size==1)
{
- free(q->last);
+ wonky_free(q->last);
q->first=q->last=NULL;
q->size=0;
}else
{
struct Queue_Node *temp_first=q->first;
q->first=q->first->prev;
- free(temp_first);
+ wonky_free(temp_first);
--q->size;
}
return return_value;
{
temp_first=q->first;
q->first=q->first->prev;
- free(temp_first->data);
- free(temp_first);
+ wonky_free(temp_first->data);
+ wonky_free(temp_first);
}
}
F diff --git a/src/misc/queue.h b/src/misc/queue.h --- a/src/misc/queue.h +++ b/src/misc/queue.h
#include <stdlib.h>
#include <wonky_assert.h>
#include <common.h>
+ #include <wonky_malloc.h>
struct Queue
F diff --git a/src/misc/stack.c b/src/misc/stack.c --- a/src/misc/stack.c +++ b/src/misc/stack.c
#ifndef GSTACK_C
#define GSTACK_C GSTACK_C
- #include "stack.h"
+ #include <stack.h>
}
void Stack_Push(Stack *stack,void* data)
{
- struct Stack_Node *temp_node=malloc(sizeof(struct Stack_Node));
+ struct Stack_Node *temp_node=wonky_malloc(sizeof(struct Stack_Node));
temp_node->data=data;
temp_node->next=stack->first;
stack->first=temp_node;
--stack->size;
stack->first=stack->first->next;
- free(temp_first);
+ wonky_free(temp_first);
}
return return_value;
F diff --git a/src/misc/stack.h b/src/misc/stack.h --- a/src/misc/stack.h +++ b/src/misc/stack.h
#include <stdlib.h>
#include <common.h>
+ #include <wonky_malloc.h>
struct Stack_Node
F diff --git a/src/misc/wonky_malloc.c b/src/misc/wonky_malloc.c --- a/src/misc/wonky_malloc.c +++ b/src/misc/wonky_malloc.c
#define WONKY_MALLOC_C WONKY_MALLOC_C
#include <wonky_malloc.h>
- struct Memory* get_memory()
+
+ static struct Memory wonky_memory;
+
+ void wonky_memory_init()
{
- struct Memory *ret;
- ret=malloc(sizeof(struct Memory));
- if(ret==NULL)
- return NULL;
+ wonky_memory.map_nodes=
+ calloc_memory_segment(NULL,NUMBER_OF_MAP_NODES_IN_INCREMENTATION_OF_MAP_MEMORY_SEGMENT,sizeof(struct Map));
- ret->map_nodes=calloc_memory_segment(NULL,NUMBER_OF_MAP_NODES_IN_INCREMENTATION_OF_MAP_MEMORY_SEGMENT,sizeof(struct Map));
- if(ret->map_nodes==NULL)
- {
- free(ret);
- return NULL;
- }
+ if(wonky_memory.map_nodes==NULL)
+ wonky_memfail();
- ret->tokens=get_memory_segment(NULL);
- if(ret->tokens==NULL)
+ wonky_memory.generic=get_memory_segment(NULL,0);
+ if(wonky_memory.generic==NULL)
{
- delete_memory_segment(ret->map_nodes);
- free(ret);
- return NULL;
+ delete_memory_segment(wonky_memory.map_nodes);
+ wonky_memfail();
}
- ret->generic=calloc_memory_segment(NULL,NUMBER_OF_TOKENS_IN_INCREMENTATION_OF_TOKEN_MEMORY_SEGMENT,sizeof(struct token));
- if(ret->generic==NULL)
+ wonky_memory.tokens=
+ calloc_memory_segment(NULL,NUMBER_OF_TOKENS_IN_INCREMENTATION_OF_TOKEN_MEMORY_SEGMENT,sizeof(struct token));
+
+ if(wonky_memory.tokens==NULL)
{
- delete_memory_segment(ret->map_nodes);
- delete_memory_segment(ret->tokens);
- free(ret);
- return NULL;
+ delete_memory_segment(wonky_memory.map_nodes);
+ delete_memory_segment(wonky_memory.generic);
+ wonky_memfail();
}
-
- return ret;
}
- void delete_memory(struct Memory *mem)
+ void wonky_memory_delete()
{
struct Memory_Segment *current_segment;
struct Memory_Segment *hold_previous_segment;
- current_segment=mem->map_nodes;
+ current_segment=wonky_memory.map_nodes;
+
+ while(current_segment!=NULL)
+ {
+ hold_previous_segment=current_segment->previous;
+ delete_memory_segment(current_segment);
+ current_segment=hold_previous_segment;
+ }
+ current_segment=wonky_memory.tokens;
+
+ while(current_segment!=NULL)
+ {
+ hold_previous_segment=current_segment->previous;
+ delete_memory_segment(current_segment);
+ current_segment=hold_previous_segment;
+ }
+ current_segment=wonky_memory.generic;
while(current_segment!=NULL)
{
delete_memory_segment(current_segment);
current_segment=hold_previous_segment;
}
- free(mem);
}
void delete_memory_segment(struct Memory_Segment *segment)
{
free(segment->data);
free(segment);
}
- void* wonky_malloc(size_t size,struct Memory *mem)
+ void* wonky_malloc(size_t size)
{
- if(mem->generic->capacity - mem->generic->size < size)
+ if(wonky_memory.generic->capacity - wonky_memory.generic->size <= size)
{
- if(mem->generic->capacity/REALLOC_TRIGGER>=size)
- mem->generic=resize_memory_segment(mem->generic->size+size,mem->generic);
- else
- mem->generic=get_memory_segment(mem->generic);
+ wonky_memory.generic=get_memory_segment(wonky_memory.generic,size);
}
- mem->generic->size+=size;
- return mem->generic->data + mem->generic->size - size;
+ wonky_memory.generic->size+=size;
+ return wonky_memory.generic->data + wonky_memory.generic->size - size;
}
- struct Map* wonky_malloc_map_node(struct Memory *mem)
+ /*I know*/
+ void* wonky_calloc(size_t nmemb,size_t size)
{
- if(mem->map_nodes->size==mem->map_nodes->capacity)
- mem->map_nodes=calloc_memory_segment(mem->map_nodes,NUMBER_OF_MAP_NODES_IN_INCREMENTATION_OF_MAP_MEMORY_SEGMENT,sizeof(struct Map));
+ if(wonky_memory.generic->capacity - wonky_memory.generic->size <= size*nmemb)
+ {
+ wonky_memory.generic=get_memory_segment(wonky_memory.generic,size*nmemb);
+ }
+ for(size_t i=0;i<size*nmemb;++i)
+ {
+ wonky_memory.generic->data[i+wonky_memory.generic->size]=0;
+ }
+ wonky_memory.generic->size+=nmemb*size;
+ return wonky_memory.generic->data + wonky_memory.generic->size - nmemb*size;
+ }
+ struct Map* wonky_malloc_map_node()
+ {
+ if(wonky_memory.map_nodes->size==wonky_memory.map_nodes->capacity)
+ wonky_memory.map_nodes=calloc_memory_segment(wonky_memory.map_nodes,NUMBER_OF_MAP_NODES_IN_INCREMENTATION_OF_MAP_MEMORY_SEGMENT,sizeof(struct Map));
- ++mem->map_nodes->size;
- return (struct Map*) (mem->map_nodes->data + mem->map_nodes->size*sizeof(struct Map) - sizeof(struct Map));
+ ++wonky_memory.map_nodes->size;
+ return (struct Map*) (wonky_memory.map_nodes->data + wonky_memory.map_nodes->size*(sizeof(struct Map)-1));
}
- struct token* wonky_malloc_token(struct Memory *mem)
+ struct token* wonky_malloc_token()
{
- if(mem->tokens->size==mem->tokens->capacity)
- mem->tokens=calloc_memory_segment(mem->tokens,NUMBER_OF_TOKENS_IN_INCREMENTATION_OF_TOKEN_MEMORY_SEGMENT,sizeof(struct token));
+ if(wonky_memory.tokens->size==wonky_memory.tokens->capacity)
+ wonky_memory.tokens=calloc_memory_segment(wonky_memory.tokens,NUMBER_OF_TOKENS_IN_INCREMENTATION_OF_TOKEN_MEMORY_SEGMENT,sizeof(struct token));
- ++mem->tokens->size;
- return (struct token*) (mem->tokens->data + mem->tokens->size*sizeof(struct token) - sizeof(struct token));
+ ++wonky_memory.tokens->size;
+ return (struct token*) (wonky_memory.tokens->data + wonky_memory.tokens->size*sizeof(struct token) - sizeof(struct token));
}
- struct Memory_Segment* get_memory_segment(struct Memory_Segment *previous)
+ struct Memory_Segment* get_memory_segment(struct Memory_Segment *previous,size_t atleast_this_size)
{
struct Memory_Segment *ret;
if(previous==NULL)
{
ret=malloc(sizeof(struct Memory_Segment));
- ret->data=malloc(NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT);
+ if(ret==NULL)
+ wonky_memfail();
+ ret->data=malloc(atleast_this_size+NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT);
+ if(ret->data==NULL)
+ wonky_memfail();
- ret->capacity=NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT;
+ ret->capacity=atleast_this_size+NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT;
ret->size=0;
ret->previous=NULL;
}else
{
ret=malloc(sizeof(struct Memory_Segment));
- ret->data=malloc(NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT+previous->capacity);
+ if(ret==NULL)
+ wonky_memfail();
+ ret->data=malloc(atleast_this_size+NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT+previous->capacity);
+ if(ret->data==NULL)
+ wonky_memfail();
- ret->capacity=NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT+previous->capacity;
+ ret->capacity=atleast_this_size+NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT+previous->capacity;
ret->size=0;
ret->previous=previous;
}
return ret;
}
- struct Memory_Segment* resize_memory_segment(size_t new_capacity,struct Memory_Segment *to_be_resized)
- {
- struct Memory_Segment *ret;
-
- wonky_assert(to_be_resized!=NULL && to_be_resized->capacity<=new_capacity);
-
- ret=realloc(to_be_resized->data,new_capacity);
- ret->capacity=new_capacity;
-
- return ret;
- }
struct Memory_Segment* calloc_memory_segment(struct Memory_Segment *previous,size_t increment_size,size_t element_size)
{
struct Memory_Segment *ret;
if(previous==NULL)
{
ret=malloc(sizeof(struct Memory_Segment));
+
+ if(ret==NULL)
+ wonky_memfail();
+
ret->data=calloc(element_size,increment_size);
+ if(ret->data==NULL)
+ wonky_memfail();
+
ret->capacity=increment_size;
ret->size=0;
ret->previous=NULL;
}else
{
ret=malloc(sizeof(struct Memory_Segment));
+
+ if(ret==NULL)
+ wonky_memfail();
+
ret->data=calloc(element_size,increment_size+previous->capacity);
+ if(ret->data==NULL)
+ wonky_memfail();
+
ret->capacity=increment_size+previous->capacity;
ret->size=0;
ret->previous=previous;
return ret;
}
+ void wonky_memfail()
+ {
+ fprintf(stderr,"WONKY MEMFAIL");
+ abort();
+ }
#endif
F diff --git a/src/misc/wonky_malloc.h b/src/misc/wonky_malloc.h --- a/src/misc/wonky_malloc.h +++ b/src/misc/wonky_malloc.h
#include <lexer.h>
#include <stdlib.h>
+ #include <stdio.h>/*TODO remove this after implementing longjmp in memfail*/
- #define NUMBER_OF_MAP_NODES_IN_INCREMENTATION_OF_MAP_MEMORY_SEGMENT 1024
+ #define NUMBER_OF_MAP_NODES_IN_INCREMENTATION_OF_MAP_MEMORY_SEGMENT 2048
#define NUMBER_OF_TOKENS_IN_INCREMENTATION_OF_TOKEN_MEMORY_SEGMENT 1024
#define NUMBER_OF_BYTES_IN_INCREMENTATION_OF_GENERIC_MEMORY_SEGMENT 1024
/*
- if the memory requested in a wonky_malloc can't fit in the current segment
+ if the memory requested in a wonky_wonky_malloc can't fit in the current segment
then if it overflows by 1/REALLOC_TRIGGER of the capacity of the segment,
then the segment is realloced
*/
struct Memory_Segment *generic;
};
- struct Memory* get_memory();
- void delete_memory(struct Memory *mem);
+ void wonky_memory_init();
+ void wonky_memory_delete();
+
void delete_memory_segment(struct Memory_Segment *segment);
- void* wonky_malloc(size_t size,struct Memory *mem);
- struct Map* wonky_malloc_map_node(struct Memory *mem);
- struct token* wonky_malloc_token(struct Memory *mem);
+ void* wonky_malloc(size_t size);
+ void* wonky_calloc(size_t nmemb,size_t size);
+ struct Map* wonky_malloc_map_node();
+ struct token* wonky_malloc_token();
- struct Memory_Segment* get_memory_segment(struct Memory_Segment *previous);
- struct Memory_Segment* resize_memory_segment(size_t new_capacity,struct Memory_Segment *to_be_resized);
+ struct Memory_Segment* get_memory_segment(struct Memory_Segment *previous,size_t atleast_this_size);
+ void resize_memory_segment(size_t new_capacity,struct Memory_Segment *to_be_resized);
struct Memory_Segment* calloc_memory_segment(struct Memory_Segment *previous,size_t increment_size,size_t element_size);
- #define wonky_free(x)
- #define wonky_free_token(x)
- #define wonky_free_map_node(x)
+ void wonky_memfail();
+ static inline void wonky_free(void *x) {}
+ static inline void wonky_free_token(void *x) {}
+ static inline void wonky_free_map_node(void *x) {}
#endif
F diff --git a/src/semantics/ast.c b/src/semantics/ast.c --- a/src/semantics/ast.c +++ b/src/semantics/ast.c
struct AST_Error* get_error_tree(struct AST *error)
{
struct AST_Error *ret;
- ret=malloc(sizeof(struct AST_Error));
+ ret=wonky_malloc(sizeof(struct AST_Error));
ret->type=ERROR;
ret->error=error;
return ret;
{
struct AST_Declaration_Error *ret;
- ret=malloc(sizeof(struct AST_Declaration_Error));
+ ret=wonky_malloc(sizeof(struct AST_Declaration_Error));
ret->type=ERROR_DECLARATION;
ret->error=error;
return ret;
struct AST_Binary_Expression* get_binary_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Expression_Value *value,enum AST_Type type)
{
struct AST_Binary_Expression *ret;
- ret=malloc(sizeof(struct AST_Binary_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Binary_Expression));
ret->type=type;
ret->left=left;
ret->right=right;
if(!constraint_check_struct_union_member_expression(left,id,translation_data))
{
- free(id);/*welp*/
+ wonky_free(id);/*welp*/
return (struct AST_Binary_Expression*)get_error_tree((struct AST*)left);
}
wonky_assert(left_type->specifier==TS_STRUCT || left_type->specifier==TS_UNION);
- ret=malloc(sizeof(struct AST_Binary_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Binary_Expression));
ret->type=OP_MEMBER;
ret->right=(struct AST_Expression*)get_struct_union_member_tree_designator(id,left_type->struct_union->inner_namespace,translation_data);
struct AST_Conditional_Expression* get_conditional_expression_tree(struct AST_Expression *left,struct AST_Expression *center,struct AST_Expression *right,struct Translation_Data *translation_data)
{
struct AST_Conditional_Expression *ret;
- ret=malloc(sizeof(struct AST_Conditional_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Conditional_Expression));
ret->type=OP_COND;
ret->left=left;
ret->center=center;
return (struct AST_Function_Expression*)get_error_tree((struct AST*)id);
}
- ret=malloc(sizeof(struct AST_Function_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Function_Expression));
ret->type=OP_FUNCTION;
ret->value=NULL; /*So, we need to know if there is some error somewhere before we can begin extracting lvalue information*/
ret->id=id;
ret->number_of_arguments=arg_list->size;
- ret->arg_list=calloc(ret->number_of_arguments,sizeof(struct AST_Expression*));
+ ret->arg_list=wonky_calloc(ret->number_of_arguments,sizeof(struct AST_Expression*));
for(i=0;i<ret->number_of_arguments;++i)
{
{
struct AST_Unary_Expression *ret;
- ret=malloc(sizeof(struct AST_Unary_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Unary_Expression));
ret->operand=operand;
ret->type=type;
ret->value=value;
if(constraint_check_indirection_expression(operand,translation_data))
{
- ret=malloc(sizeof(struct AST_Unary_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Unary_Expression));
ret->type=OP_DEREFERENCE;
ret->operand=operand;
operand_type=(struct Type_Pointer*)extract_expresion_value_type(operand->value,translation_data);
struct Type *operand_type;
if(constraint_check_address_expression(operand,translation_data))
{
- ret=malloc(sizeof(struct AST_Unary_Expression));
+ ret=wonky_malloc(sizeof(struct AST_Unary_Expression));
ret->type=OP_ADDR_OF;
ret->operand=operand;
struct AST_Constant* get_constant_tree(struct Expression_Value_Constant *value)
{
struct AST_Constant *ret;
- ret=malloc(sizeof(struct AST_Constant));
+ ret=wonky_malloc(sizeof(struct AST_Constant));
ret->type=OP_CONSTANT;
ret->value=value;
return ret;
struct AST_String_Literal* get_string_literal_tree(struct Expression_Value_Constant *value)
{
struct AST_String_Literal *ret;
- ret=malloc(sizeof(struct AST_Constant));
+ ret=wonky_malloc(sizeof(struct AST_Constant));
ret->type=OP_STRING_LITERAL;
ret->value=value;
return ret;
struct Denoted *hold_denoted;
- ret=malloc(sizeof(struct AST_Designator));
+ ret=wonky_malloc(sizeof(struct AST_Designator));
ret->type=OP_DESIGNATOR;
if(hold_denoted==NULL)
{
push_translation_error("using undeclared id - %t, in expression",translation_data,id);
- free(ret);
+ wonky_free(ret);
return (struct AST_Expression*)get_error_tree(NULL);
}else
{
struct AST_Designator* get_designator_tree_from_denoted_object(struct Denoted_Object *object,struct Translation_Data *translation_data)
{
struct AST_Designator *ret;
- ret=malloc(sizeof(struct AST_Designator));
+ ret=wonky_malloc(sizeof(struct AST_Designator));
ret->type=OP_DESIGNATOR;
ret->value=get_expression_value_lvalue(object->object);
ret->id=object->id;
struct Denoted *hold_denoted;
- ret=malloc(sizeof(struct AST_Designator));
+ ret=wonky_malloc(sizeof(struct AST_Designator));
ret->type=OP_DESIGNATOR;
if(hold_denoted==NULL)
{
push_translation_error("%t is not a member of the structure",translation_data,id);
- free(ret);
+ wonky_free(ret);
return (struct AST_Designator*)get_error_tree(NULL);
}else
{
struct AST_Case_Statement* get_case_statement_tree(struct AST *statement,struct AST_Expression *control,struct AST_Switch_Statement *parent,struct Translation_Data *translation_data)
{
struct AST_Case_Statement *ret;
- ret=malloc(sizeof(struct AST_Case_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Case_Statement));
ret->type=ST_CASE;
ret->control=control;
struct AST_Labeled_Statement* get_labeled_statement_tree(struct token *label,struct AST* statement,enum AST_Type type,struct Translation_Data *translation_data,struct Scope *scope)
{
struct AST_Labeled_Statement *ret;
- ret=malloc(sizeof(struct AST_Labeled_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Labeled_Statement));
ret->type=type;
ret->label=(struct Denoted_Statement*)push_label(scope,label,statement,translation_data);
return ret;
struct AST_Default_Statement* get_default_statement_tree(struct AST *statement,struct Translation_Data *translation_data)
{
struct AST_Default_Statement *ret;
- ret=malloc(sizeof(struct AST_Default_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Default_Statement));
ret->type=ST_DEFAULT;
ret->statement=statement;
struct AST_Break_Continue_Statement* get_break_continue_statement_tree(struct AST *parent,struct Translation_Data *translation_data,enum AST_Type break_or_continue)
{
struct AST_Break_Continue_Statement *ret;
- ret=malloc(sizeof(struct AST_Break_Continue_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Break_Continue_Statement));
ret->type=break_or_continue;
ret->parent=parent;
if(constraint_check_break_continue_statement(ret,translation_data))
struct AST_Compound_Statement* get_compound_statement_tree(struct Scope *parent_scope)
{
struct AST_Compound_Statement *ret;
- ret=malloc(sizeof(struct AST_Compound_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Compound_Statement));
+ ret->components=wonky_malloc(sizeof(struct Queue));
+
ret->type=ST_COMPOUND;
- Queue_Init(&ret->components);
+
+ Queue_Init(ret->components);
+
ret->scope=get_normal_scope(parent_scope,BLOCK_SCOPE);
return ret;
}
struct AST_If_Statement* get_if_statement_tree()
{
struct AST_If_Statement *ret;
- ret=malloc(sizeof(struct AST_If_Statement));
+ ret=wonky_malloc(sizeof(struct AST_If_Statement));
ret->type=ST_IF;
return ret;
{
struct AST_Switch_Statement *ret;
- ret=malloc(sizeof(struct AST_Switch_Statement));
- ret->cases=malloc(sizeof(struct Queue));
+ ret=wonky_malloc(sizeof(struct AST_Switch_Statement));
+ ret->cases=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->cases);
struct AST_While_Statement* get_while_statement_tree()
{
struct AST_While_Statement *ret;
- ret=malloc(sizeof(struct AST_While_Statement));
+ ret=wonky_malloc(sizeof(struct AST_While_Statement));
ret->type=ST_WHILE;
return ret;
}
struct AST_Do_While_Statement* get_do_while_statement_tree()
{
struct AST_Do_While_Statement *ret;
- ret=malloc(sizeof(struct AST_Do_While_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Do_While_Statement));
ret->type=ST_DO_WHILE;
return ret;
}
struct AST_For_Statement* get_for_statement_tree()
{
struct AST_For_Statement *ret;
- ret=malloc(sizeof(struct AST_For_Statement));
+ ret=wonky_malloc(sizeof(struct AST_For_Statement));
ret->type=ST_FOR;
return ret;
}
if(constraint_check_return_statement(return_expression,return_type,translation_data))
{
- ret=malloc(sizeof(struct AST_If_Statement));
+ ret=wonky_malloc(sizeof(struct AST_If_Statement));
ret->type=ST_RETURN;
if(return_expression==NULL)
ret->return_expression=NULL;
struct AST_Goto_Statement *ret;
struct Denoted_Statement *hold_statement;
- ret=malloc(sizeof(struct AST_Goto_Statement));
+ ret=wonky_malloc(sizeof(struct AST_Goto_Statement));
ret->type=ST_GOTO;
hold_statement=check_label(scope,label);
struct AST* get_nop_tree()
{
struct AST_Expression* ret;
- ret=malloc(sizeof(struct AST_Expression*));
+ ret=wonky_malloc(sizeof(struct AST_Expression*));
ret->type=OP_NOP;
ret->value=get_expression_value_void();
return (struct AST*)ret;
struct AST_Type_Definition* get_type_definition_tree(struct Denoted_Type *definition)
{
struct AST_Type_Definition *ret;
- ret=malloc(sizeof(struct AST_Type_Definition));
+ ret=wonky_malloc(sizeof(struct AST_Type_Definition));
ret->type=ST_TYPE_DEFINITION;
ret->definition=definition;
struct AST_Object_Declaration* get_object_declaration_tree(struct Denoted_Object *object,struct Initialiser *initialiser)
{
struct AST_Object_Declaration *ret;
- ret=malloc(sizeof(struct AST_Object_Declaration));
+ ret=wonky_malloc(sizeof(struct AST_Object_Declaration));
ret->type=ST_OBJECT_DECLARATION;
ret->object=object;
ret->initializer=initialiser;
struct AST_Function_Definition* get_function_definition_tree(struct Scope *scope,struct Denoted_Function *function,struct AST_Compound_Statement *function_body,struct Translation_Data *translation_data)
{
struct AST_Function_Definition *ret;
- ret=malloc(sizeof(struct AST_Function_Definition));
+ ret=wonky_malloc(sizeof(struct AST_Function_Definition));
ret->type=ST_FUNCTION_DEFINITION;
ret->function=function;
ret->body=function_body;
struct AST_Function_Declaration* get_function_declaration_tree(struct Scope *scope,struct Denoted_Function *function)
{
struct AST_Function_Declaration *ret;
- ret=malloc(sizeof(struct AST_Function_Declaration));
+ ret=wonky_malloc(sizeof(struct AST_Function_Declaration));
ret->type=ST_FUNCTION_DECLARATION;
ret->function=function;
return ret;
struct AST_Translation_Unit* get_translation_unit_tree()
{
struct AST_Translation_Unit *ret;
- ret=malloc(sizeof(struct AST_Translation_Unit));
+ ret=wonky_malloc(sizeof(struct AST_Translation_Unit));
ret->type=TRANSLATION_UNIT;
- //ret->components=malloc(sizeof(struct Queue));
+ //ret->components=wonky_malloc(sizeof(struct Queue));
- ret->object_declarations=malloc(sizeof(struct Queue));
- ret->function_definitions=malloc(sizeof(struct Queue));
+ ret->object_declarations=wonky_malloc(sizeof(struct Queue));
+ ret->function_definitions=wonky_malloc(sizeof(struct Queue));
ret->internal_linkage=get_linkage();
ret->file_scope=get_normal_scope(NULL,FILE_SCOPE);
break;
case OP_NOP:
/*it is just a ast node*/
- free(ast);
+ wonky_free(ast);
break;
case OP_LOGICAL_NOT:
case OP_BITWISE_NOT:
{
if(error->error!=NULL)
delete_ast(error->error);
- free(error);
+ wonky_free(error);
}
void delete_ast_declaration_error(struct AST_Declaration_Error *error)
{
if(error->error!=NULL)
delete_denoted_error((struct Denoted_Error*)error->error);
- free(error);
+ wonky_free(error);
}
void delete_ast_binary_expression(struct AST_Binary_Expression *binary_expression)
{
if(binary_expression->right!=NULL)
delete_ast((struct AST*)binary_expression->right);
- free(binary_expression);
+ wonky_free(binary_expression);
}
void delete_ast_conditional_expression(struct AST_Conditional_Expression *cond_expression)
{
if(cond_expression->right!=NULL)
delete_ast((struct AST*)cond_expression->right);
- free(cond_expression);
+ wonky_free(cond_expression);
}
void delete_ast_function_expression(struct AST_Function_Expression *function_expression)
{
{
delete_ast((struct AST*)function_expression->arg_list[i]);
}
- free(function_expression->arg_list);
+ wonky_free(function_expression->arg_list);
}
- free(function_expression);
+ wonky_free(function_expression);
}
void delete_ast_designator_expression(struct AST_Designator *designator)
{
- free(designator);
+ wonky_free(designator);
}
void delete_ast_unary_expression(struct AST_Unary_Expression *unary_expression)
{
if(unary_expression->operand!=NULL)
delete_ast((struct AST*)unary_expression->operand);
- free(unary_expression);
+ wonky_free(unary_expression);
}
void delete_ast_labeled_statement(struct AST_Labeled_Statement *labeled_statement)
{
if(labeled_statement->label!=NULL)
delete_denoted((struct Denoted*)labeled_statement->label);
- free(labeled_statement);
+ wonky_free(labeled_statement);
}
void delete_ast_default_statement(struct AST_Default_Statement *default_statement)
{
- free(default_statement);
+ wonky_free(default_statement);
}
void delete_ast_break_continue_statement(struct AST_Break_Continue_Statement *break_continue)
{
- free(break_continue);
+ wonky_free(break_continue);
}
void delete_ast_compound_statement(struct AST_Compound_Statement *compound_statement)
{
if(compound_statement->scope!=NULL)
delete_scope(compound_statement->scope);
- while(compound_statement->components.size>0)
- delete_ast((struct AST*)Queue_Pop(&compound_statement->components));
- free(compound_statement);
+ while(compound_statement->components->size>0)
+ delete_ast((struct AST*)Queue_Pop(compound_statement->components));
+ wonky_free(compound_statement);
}
void delete_ast_for_statement(struct AST_For_Statement *for_statement)
{
delete_ast(for_statement->update);
if(for_statement->body_statement!=NULL)
delete_ast(for_statement->body_statement);
- free(for_statement);
+ wonky_free(for_statement);
}
void delete_ast_while_statemtent(struct AST_While_Statement *while_statement)
{
delete_ast(while_statement->condition);
if(while_statement->body_statement!=NULL)
delete_ast(while_statement->body_statement);
- free(while_statement);
+ wonky_free(while_statement);
}
void delete_ast_do_while_statement(struct AST_Do_While_Statement *do_while_statement)
{
delete_ast(do_while_statement->condition);
if(do_while_statement->body_statement!=NULL)
delete_ast(do_while_statement->body_statement);
- free(do_while_statement);
+ wonky_free(do_while_statement);
}
void delete_ast_if_statemtent(struct AST_If_Statement *if_statement)
{
delete_ast(if_statement->body_statement);
if(if_statement->else_statement!=NULL)
delete_ast(if_statement->else_statement);
- free(if_statement);
+ wonky_free(if_statement);
}
void delete_ast_goto_statemtent(struct AST_Goto_Statement *goto_statement)
{
- free(goto_statement);
+ wonky_free(goto_statement);
}
void delete_ast_switch_statement(struct AST_Switch_Statement *switch_statement)
{
while(switch_statement->cases->size>0)
Queue_Pop(switch_statement->cases);
- free(switch_statement->cases);
- free(switch_statement);
+ wonky_free(switch_statement->cases);
+ wonky_free(switch_statement);
}
void delete_ast_case_statement(struct AST_Case_Statement *case_statement)
{
delete_ast((struct AST*)case_statement->control);
if(case_statement->statement)
delete_ast(case_statement->statement);
- free(case_statement);
+ wonky_free(case_statement);
}
void delete_ast_return_statement(struct AST_Return_Statement *return_statement)
{
if(return_statement->return_expression!=NULL)
delete_ast(return_statement->return_expression);
- free(return_statement);
+ wonky_free(return_statement);
}
void delete_ast_type_definition(struct AST_Type_Definition *type_definition)
{
/*deleting denoted objects in scopes*/
- free(type_definition);
+ wonky_free(type_definition);
}
void delete_ast_object_declaration(struct AST_Object_Declaration *object_declaration)
{
- free(object_declaration);
+ wonky_free(object_declaration);
}
void delete_ast_function_definition(struct AST_Function_Definition *function_definition)
{
- free(function_definition);
+ wonky_free(function_definition);
}
void delete_ast_function_declaration(struct AST_Function_Declaration *function_declaration)
{
- free(function_declaration);
+ wonky_free(function_declaration);
}
void delete_ast_translation_unit(struct AST_Translation_Unit *translation_unit)
{
if(translation_unit->file_scope!=NULL)
delete_scope(translation_unit->file_scope);
delete_linkage(translation_unit->internal_linkage);
- free(translation_unit);
+ wonky_free(translation_unit);
}
void delete_ast_constant(struct AST_Constant *constant)
{
if(constant->value!=NULL)
- free(constant->value);
- free(constant);
+ wonky_free(constant->value);
+ wonky_free(constant);
}
void delete_ast_string_literal(struct AST_String_Literal *string)
{
- free(string);
+ wonky_free(string);
}
F diff --git a/src/semantics/ast.h b/src/semantics/ast.h --- a/src/semantics/ast.h +++ b/src/semantics/ast.h
enum AST_Type type;
struct Scope *scope;
- struct Queue components;
+ struct Queue *components;
};
struct AST_For_Statement
F diff --git a/src/semantics/identifiers/denoted.c b/src/semantics/identifiers/denoted.c --- a/src/semantics/identifiers/denoted.c +++ b/src/semantics/identifiers/denoted.c
struct Denoted* get_denoted_error(struct Denoted *error)
{
struct Denoted_Error *ret;
- ret=malloc(sizeof(struct Denoted_Error));
+ ret=wonky_malloc(sizeof(struct Denoted_Error));
ret->denotation=DT_Error;
ret->error=error;
struct Denoted_Base* get_denoted_base(struct Denotation_Prototype *prototype)
{
struct Denoted_Base *ret;
- ret=malloc(sizeof(struct Denoted_Base));
+ ret=wonky_malloc(sizeof(struct Denoted_Base));
ret->denotation=prototype->denotation;
ret->id=NULL;
ret->type=prototype->type;
struct Denoted* get_denoted_function(struct token *id,struct Type *type,enum Function_Specifier fs)
{
struct Denoted_Function *ret;
- ret=malloc(sizeof(struct Denoted_Function));
+ ret=wonky_malloc(sizeof(struct Denoted_Function));
ret->denotation=DT_Function;
ret->linkage=LINKAGE_NONE;
ret->id=id;
struct Denoted* get_denoted_object(struct token *id, enum Storage_Class_Specifier sc,struct Type *type,struct AST *initializer)
{
struct Denoted_Object *ret;
- ret=malloc(sizeof(struct Denoted_Object));
+ ret=wonky_malloc(sizeof(struct Denoted_Object));
ret->denotation=DT_Object;
ret->linkage=LINKAGE_NONE;
ret->id=id;
struct Denoted* get_denoted_typedef(struct Denoted_Base *base)
{
struct Denoted_Type *ret;
- ret=malloc(sizeof(struct Denoted_Type));
+ ret=wonky_malloc(sizeof(struct Denoted_Type));
ret->denotation=DT_Typedef;
ret->type=base->type;
ret->id=base->id;
struct Denoted* get_denoted_enum_const_expr(struct token *id,struct Enum *parent,struct AST* expression,struct Translation_Data *translation_data)
{
struct Denoted_Enum_Const *ret;
- ret=malloc(sizeof(struct Denoted_Enum_Const));
+ ret=wonky_malloc(sizeof(struct Denoted_Enum_Const));
ret->denotation=DT_Enum_Constant;
ret->id=id;
ret->parent=parent;
struct Denoted* get_denoted_enum_const_num(struct token *id,struct Enum *parent,int value)
{
struct Denoted_Enum_Const *ret;
- ret=malloc(sizeof(struct Denoted_Enum_Const));
+ ret=wonky_malloc(sizeof(struct Denoted_Enum_Const));
ret->denotation=DT_Enum_Constant;
ret->id=id;
ret->parent=parent;
struct Denoted* get_denoted_enum(struct Enum *enumerator)
{
struct Denoted_Enum *ret;
- ret=malloc(sizeof(struct Denoted_Enum));
+ ret=wonky_malloc(sizeof(struct Denoted_Enum));
ret->denotation=DT_Enum;
ret->enumeration=enumerator;
struct Denoted* get_denoted_struct_union(struct Struct_Union *struct_union)
{
struct Denoted_Struct_Union *ret;
- ret=malloc(sizeof(struct Denoted_Struct_Union));
+ ret=wonky_malloc(sizeof(struct Denoted_Struct_Union));
ret->denotation=DT_Struct_Union_Tag;
ret->struct_union=struct_union;
struct Denoted* get_denotation_prototype(struct Map *types)
{
struct Denotation_Prototype *ret;
- ret=malloc(sizeof(struct Denotation_Prototype));
+ ret=wonky_malloc(sizeof(struct Denotation_Prototype));
ret->denotation=DT_Prototype;
ret->type=NULL;
ret->node=types;
struct Denoted* get_denoted_statement(struct token *id,struct AST *statement,struct Denoted_Object *previous_denoted_object)
{
struct Denoted_Statement *ret;
- ret=malloc(sizeof(struct Denoted_Statement));
+ ret=wonky_malloc(sizeof(struct Denoted_Statement));
ret->denotation=DT_Statement;
ret->label=id;
ret->statement=statement;
ret->previous_denoted_object=previous_denoted_object;
- ret->gotos_jumping_to_this_statement=malloc(sizeof(struct Queue));
+ ret->gotos_jumping_to_this_statement=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->gotos_jumping_to_this_statement);
{
if(error->error!=NULL)
delete_denoted(error->error);
- free(error);
+ wonky_free(error);
}
void delete_denoted_function(struct Denoted_Function *function)
{
if(function->id!=NULL)
- free(function->id);
- free(function);
+ wonky_free(function->id);
+ wonky_free(function);
}
void delete_denoted_object(struct Denoted_Object *object)
{
if(object->id!=NULL)
- free(object->id);
+ wonky_free(object->id);
if(object->object!=NULL)
delete_object(object->object);
- free(object);
+ wonky_free(object);
}
void delete_denoted_typedef(struct Denoted_Type *typedefed)
{
if(typedefed->id!=NULL)
- free(typedefed->id);
- free(typedefed);
+ wonky_free(typedefed->id);
+ wonky_free(typedefed);
}
void delete_denoted_enum(struct Denoted_Enum *enumeration)
{
if(enumeration->enumeration!=NULL)
delete_enum(enumeration->enumeration);
- free(enumeration);
+ wonky_free(enumeration);
}
void delete_denoted_enum_constant(struct Denoted_Enum_Const *enum_const)
{
if(enum_const->id!=NULL)
- free(enum_const->id);
+ wonky_free(enum_const->id);
if(enum_const->expression!=NULL)
delete_ast(enum_const->expression);
- free(enum_const);
+ wonky_free(enum_const);
}
void delete_denoted_struct_union(struct Denoted_Struct_Union *su)
{
if(su->struct_union!=NULL)
delete_struct_union(su->struct_union);
- free(su);
+ wonky_free(su);
}
void delete_denoted_prototype(struct Denotation_Prototype *prototype)
{
- free(prototype);
+ wonky_free(prototype);
}
void delete_denoted_base(struct Denoted_Base *base)
{
- free(base);
+ wonky_free(base);
}
void delete_denoted_statement(struct Denoted_Statement *statement)
{
- if(statement->label) free(statement->label);
+ if(statement->label) wonky_free(statement->label);
if(statement->statement) delete_ast(statement->statement);
if(statement->gotos_jumping_to_this_statement)
{
while(statement->gotos_jumping_to_this_statement->size>0)
Queue_Pop(statement->gotos_jumping_to_this_statement);
}
- free(statement->gotos_jumping_to_this_statement);
- free(statement);
+ wonky_free(statement->gotos_jumping_to_this_statement);
+ wonky_free(statement);
}
void delete_denoted_wrapper(void *denoted)
{
F diff --git a/src/semantics/identifiers/linkage.c b/src/semantics/identifiers/linkage.c --- a/src/semantics/identifiers/linkage.c +++ b/src/semantics/identifiers/linkage.c
struct Linkage* get_linkage()
{
struct Linkage *ret;
- ret=malloc(sizeof(struct Linkage));
- ret->ids=malloc(sizeof(struct Map));
+ ret=wonky_malloc(sizeof(struct Linkage));
+ ret->ids=wonky_malloc(sizeof(struct Map));
Map_Init(ret->ids);
void delete_linkage(struct Linkage *linkage)
{
Map_Destroy(linkage->ids);
- free(linkage);
+ wonky_free(linkage);
}
if(possible_declaration==NULL)
{
if(object->object->linkage==LINKAGE_EXTERNAL)
- Map_Push(translation_data->external_linkage->ids,object->object->id->data,object->object->id->data_size,object,translation_data->memory);
+ Map_Push(translation_data->external_linkage->ids,object->object->id->data,object->object->id->data_size,object);
else if(object->object->linkage==LINKAGE_INTERNAL)
- Map_Push(translation_data->internal_linkage->ids,object->object->id->data,object->object->id->data_size,object,translation_data->memory);
+ Map_Push(translation_data->internal_linkage->ids,object->object->id->data,object->object->id->data_size,object);
}else
{
if(object->initializer!=NULL && possible_declaration->initializer!=NULL)
possible_declaration=Map_Check(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size);
if(function->function->linkage==LINKAGE_EXTERNAL)
- Map_Push(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size,function,translation_data->memory);
+ Map_Push(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size,function);
else
- Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->data_size,function,translation_data->memory);
+ Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->data_size,function);
if(possible_declaration!=NULL)
{
if(possible_definition==NULL)
{
if(function->function->linkage==LINKAGE_EXTERNAL)
- Map_Push(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size,function,translation_data->memory);
+ Map_Push(translation_data->external_linkage->ids,function->function->id->data,function->function->id->data_size,function);
else
- Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->data_size,function,translation_data->memory);
+ Map_Push(translation_data->internal_linkage->ids,function->function->id->data,function->function->id->data_size,function);
}
}
#endif
F diff --git a/src/semantics/identifiers/scope.c b/src/semantics/identifiers/scope.c --- a/src/semantics/identifiers/scope.c +++ b/src/semantics/identifiers/scope.c
wonky_assert(type==BLOCK_SCOPE || type==FILE_SCOPE || type==FUNCTION_PROTOTYPE_SCOPE);
- ret=malloc(sizeof(struct Normal_Scope));
+ ret=wonky_malloc(sizeof(struct Normal_Scope));
ret->type=type;
- ret->tags=malloc(sizeof(struct Map));
- ret->ordinary=malloc(sizeof(struct Map));
+ ret->tags=wonky_malloc(sizeof(struct Map));
+ ret->ordinary=wonky_malloc(sizeof(struct Map));
wonky_assert((type!=FILE_SCOPE) || parent==NULL);
ret->parent=parent;
- ret->object_order=malloc(sizeof(struct Queue));
+ ret->object_order=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->object_order);
struct Function_Scope *ret;
wonky_assert(parent!=NULL && parent->type==FILE_SCOPE);
- ret=malloc(sizeof(struct Function_Scope));
+ ret=wonky_malloc(sizeof(struct Function_Scope));
ret->type=FUNCTION_SCOPE;
ret->parent=parent;
ret->function=function;
- ret->labels=malloc(sizeof(struct Map));
+ ret->labels=wonky_malloc(sizeof(struct Map));
Map_Init(ret->labels);
- ret->label_order=malloc(sizeof(struct Queue));
+ ret->label_order=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->label_order);
wonky_assert(is_valid_function_scope(ret));
Map_Destroy(scope->ordinary);
while(scope->object_order->size>0)
Queue_Pop(scope->object_order);
- free(scope->object_order);
- free(scope);
+ wonky_free(scope->object_order);
+ wonky_free(scope);
}
void delete_function_scope(struct Function_Scope *scope)
Map_Destroy(scope->labels);
while(scope->label_order->size>0)
Queue_Pop(scope->label_order);
- free(scope->label_order);
- free(scope);
+ wonky_free(scope->label_order);
+ wonky_free(scope);
}
void delete_scope(struct Scope *scope)
{
hold_statement=(struct Denoted_Statement*)get_denoted_statement(label,statement,get_last_known_denoted_object((struct Normal_Scope*)current));
- Map_Push(current_function_scope->labels,label->data,label->data_size,hold_statement,translation_data->memory);
+ Map_Push(current_function_scope->labels,label->data,label->data_size,hold_statement);
Queue_Push(current_function_scope->label_order,hold_statement);
translation_data->number_of_errors_when_last_checked--;
}
}
- #define CHECK_AND_PUSH(thing,scope) Map_Check_And_Push(scope,thing->id->data,thing->id->data_size,thing,translation_data->memory)
+ #define CHECK_AND_PUSH(thing,scope) Map_Check_And_Push(scope,thing->id->data,thing->id->data_size,thing)
void push_typedef(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Type *denoted_typedef)
{
struct Denoted *hold_denotated;
void push_denoted_enum_tag(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Enum *denoted_enum)
{
struct Denoted *hold_denotated;
- hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_enum->enumeration->id->data,denoted_enum->enumeration->id->data_size,denoted_enum,translation_data->memory);
+ hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_enum->enumeration->id->data,denoted_enum->enumeration->id->data_size,denoted_enum);
if(hold_denotated)
{
delete_denoted_enum(denoted_enum);
void push_denoted_struct_union_tag(struct Scope *current,struct Translation_Data *translation_data,struct Denoted_Struct_Union *denoted_struct_union)
{
struct Denoted *hold_denotated;
- hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_struct_union->struct_union->id->data,denoted_struct_union->struct_union->id->data_size,denoted_struct_union,translation_data->memory);
+ hold_denotated=Map_Check_And_Push(AS_NORMAL_SCOPE(current)->tags,denoted_struct_union->struct_union->id->data,denoted_struct_union->struct_union->id->data_size,denoted_struct_union);
if(hold_denotated)
{
delete_denoted_struct_union(denoted_struct_union);
}
void* check_and_push_id(void *data,struct Map *scope_map,struct token *id,struct Translation_Data *translation_data)
{
- return Map_Check_And_Push(scope_map,id->data,id->data_size,data,translation_data->memory);
+ return Map_Check_And_Push(scope_map,id->data,id->data_size,data);
}
#endif
F diff --git a/src/semantics/memory/object.c b/src/semantics/memory/object.c --- a/src/semantics/memory/object.c +++ b/src/semantics/memory/object.c
struct Object* get_object(struct Type *type,enum Storage_Class_Specifier storage_class)
{
struct Object *ret;
- ret=malloc(sizeof(struct Object));
+ ret=wonky_malloc(sizeof(struct Object));
ret->kind=OBJECT_KIND_NORMAL;
ret->type=type;
ret->storage_class=storage_class;
void delete_object(struct Object *object)
{
- free(object);
+ wonky_free(object);
}
struct Object* retype_object(struct Object *object,struct Type *new_type)
if(object->kind==OBJECT_KIND_NORMAL)
{
struct Object *ret;
- ret=malloc(sizeof(struct Object));
+ ret=wonky_malloc(sizeof(struct Object));
ret->location=object->location;
ret->storage_class=object->storage_class;
ret->type=new_type;
{
struct Object_Bitfield *ret;
- ret=malloc(sizeof(struct Object_Bitfield));
+ ret=wonky_malloc(sizeof(struct Object_Bitfield));
ret->location=object->location;
ret->storage_class=object->storage_class;
ret->number_of_bits=((struct Object_Bitfield*)object)->number_of_bits;
struct Object* get_temp_object(struct Type *type)
{
struct Object *ret;
- ret=malloc(sizeof(struct Object));
+ ret=wonky_malloc(sizeof(struct Object));
ret->location=NULL;
ret->storage_class=SCS_NONE;
ret->type=type;
{
struct Object_Bitfield *ret;
long long int number_of_bits;
- ret=malloc(sizeof(struct Object_Bitfield));
+ ret=wonky_malloc(sizeof(struct Object_Bitfield));
*(struct Object*)ret=*object;
ret->kind=OBJECT_KIND_BITFIELD;
F diff --git a/src/semantics/program/program.c b/src/semantics/program/program.c --- a/src/semantics/program/program.c +++ b/src/semantics/program/program.c
struct Program* get_program()
{
struct Program *ret;
- ret=malloc(sizeof(struct Program));
- ret->translation_units=malloc(sizeof(struct Queue));
- ret->source_files=malloc(sizeof(struct Queue));
- ret->errors=malloc(sizeof(struct Queue));
- ret->types=malloc(sizeof(struct Map));
- ret->functions_without_a_definition=malloc(sizeof(struct Queue));
- ret->external_objects_without_an_initialiser=malloc(sizeof(struct Queue));
- ret->memory=get_memory();
+ ret=wonky_malloc(sizeof(struct Program));
+ ret->translation_units=wonky_malloc(sizeof(struct Queue));
+ ret->source_files=wonky_malloc(sizeof(struct Queue));
+ ret->errors=wonky_malloc(sizeof(struct Queue));
+ ret->types=wonky_malloc(sizeof(struct Map));
+ ret->functions_without_a_definition=wonky_malloc(sizeof(struct Queue));
+ ret->external_objects_without_an_initialiser=wonky_malloc(sizeof(struct Queue));
ret->external_linkage=get_linkage();
if(fseek(in,0,SEEK_SET)==-1)
return NULL;
- src=malloc(sizeof(struct Source_File));
+ src=wonky_malloc(sizeof(struct Source_File));
src->src_name=name;
- src->src=malloc(file_size+1);
+ src->src=wonky_malloc(file_size+1);
src->src_size=file_size;
src->where_in_src=0;
fclose(in);
return src;
}
- struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Linkage *external_linkage,struct Memory *program_memory)
+ struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Linkage *external_linkage)
{
struct Translation_Data *ret;
- ret=malloc(sizeof(struct Translation_Data));
- ret->tokens=malloc(sizeof(struct Queue));
- ret->errors=malloc(sizeof(struct Queue));
- ret->source_files=malloc(sizeof(struct Queue));
+ ret=wonky_malloc(sizeof(struct Translation_Data));
+ ret->tokens=wonky_malloc(sizeof(struct Queue));
+ ret->errors=wonky_malloc(sizeof(struct Queue));
+ ret->source_files=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->tokens);
Queue_Init(ret->errors);
Queue_Init(ret->source_files);
- ret->macros=malloc(sizeof(struct Map));
+ ret->macros=wonky_malloc(sizeof(struct Map));
Map_Init(ret->macros);
ret->types=types;
ret->external_linkage=external_linkage;
ret->internal_linkage=internal_linkage;
- ret->memory=program_memory;
return ret;
}
struct Source_Name* get_source_name(char *filename,char *base)
{
struct Source_Name *ret;
- ret=malloc(sizeof(struct Source_Name));
+ ret=wonky_malloc(sizeof(struct Source_Name));
ret->base=gstrcpy(base);
ret->filename=gstrcpy(filename);
normalise_source_name(ret);
{
temp_name=gstr_append(*where_to_search,filename);
in=fopen(temp_name,"r");
- free(temp_name);
+ wonky_free(temp_name);
if(in==NULL)
continue;
if(name->base==NULL)
{
offset=0;
- name->base=malloc(last_slash+1);
+ name->base=wonky_malloc(last_slash+1);
name->base[last_slash]='\0';
name->base[last_slash-1]='/';
}else
{
offset=gstrlen((char*)name->base);
- hold_base=malloc(offset+last_slash+2);
+ hold_base=wonky_malloc(offset+last_slash+2);
strmv(hold_base,(char*)name->base);
hold_base[last_slash+offset]='/';
hold_base[last_slash+offset+1]='\0';
- free((void*)name->base);
+ wonky_free((void*)name->base);
name->base=hold_base;
}
++i;
/*prune the filename*/
offset=gstrlen(name->filename+i);
- hold_base=malloc(offset+1);
+ hold_base=wonky_malloc(offset+1);
strmv(hold_base,name->filename+i);
- free(name->filename);
+ wonky_free(name->filename);
name->filename=hold_base;
}
program=get_program();
- hold_translation_data=get_translation_data(program->types,get_linkage(),program->external_linkage,program->memory);
+ hold_translation_data=get_translation_data(program->types,get_linkage(),program->external_linkage);
do
{
base_file=get_source_file(*base_source_names,this_directory);
if(base_file==NULL)
{
/*TODO error*/
- free(base_file);
+ wonky_free(base_file);
continue;
}else
{
{
while(program->translation_units->size>0)
delete_ast(Queue_Pop(program->translation_units));
- free(program->translation_units);
+ wonky_free(program->translation_units);
while(program->source_files->size>0)
delete_source_file(Queue_Pop(program->source_files));
- free(program->source_files);
+ wonky_free(program->source_files);
while(program->errors->size>0)
delete_translation_error(Queue_Pop(program->errors));
- free(program->errors);
+ wonky_free(program->errors);
delete_linkage(program->external_linkage);
/*BEWARE*/
Map_Map(program->types,delete_type);
Map_Destroy(program->types);
- free(program->types);
+ wonky_free(program->types);
- free(program);
+ wonky_free(program);
}
void delete_translation_data(struct Translation_Data *translation_data)
wonky_assert(translation_data->tokens->size==0 &&
translation_data->errors->size==0 &&
translation_data->source_files->size==0);
- free(translation_data->tokens);
- free(translation_data->errors);
- free(translation_data->source_files);
+ wonky_free(translation_data->tokens);
+ wonky_free(translation_data->errors);
+ wonky_free(translation_data->source_files);
Map_Map(translation_data->macros,delete_macro);
Map_Destroy(translation_data->macros);
- free(translation_data->macros);
+ wonky_free(translation_data->macros);
- free(translation_data);
+ wonky_free(translation_data);
}
void assimilate_translation_data(struct Program *program,struct Translation_Data *translation_data)
F diff --git a/src/semantics/program/program.h b/src/semantics/program/program.h --- a/src/semantics/program/program.h +++ b/src/semantics/program/program.h
/*ASTs*/
struct Queue *functions_without_a_definition;
struct Queue *external_objects_without_an_initialiser;
-
- struct Memory *memory;
};
struct Translation_Data
{
struct Map *types;
struct Linkage *external_linkage;
struct Linkage *internal_linkage;
- struct Memory *memory;
/*end of passed from program struct*/
};
struct Source_File* get_source_file(char *filename,char **where_to_search);
void normalise_source_name(struct Source_Name *name);
- struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Linkage *external_linkage,struct Memory *program_memory);
+ struct Translation_Data* get_translation_data(struct Map *types,struct Linkage *internal_linkage,struct Linkage *external_linkage);
struct Program* parse_program(char **base_source_names);
F diff --git a/src/semantics/value/constant.c b/src/semantics/value/constant.c --- a/src/semantics/value/constant.c +++ b/src/semantics/value/constant.c
void delete_constant(struct Constant *constant)
{
- free(constant->value);
- free(constant);
+ wonky_free(constant->value);
+ wonky_free(constant);
}
/*TODO*/
struct Constant *ret;
size_t i;
- ret_component=malloc(sizeof(unsigned long long int));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(unsigned long long int));
+ ret=wonky_malloc(sizeof(struct Constant));
for(i=0;i<token->data_size;++i)
cache*=10 , cache+=token->data[i]-'0';
struct Constant *ret;
size_t i;
- ret_component=malloc(sizeof(unsigned long long int));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(unsigned long long int));
+ ret=wonky_malloc(sizeof(struct Constant));
for(i=0;i<token->data_size;++i)
cache*=8 , cache+=token->data[i]-'0';
struct Constant *ret;
- ret_component=malloc(sizeof(unsigned long long int));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(unsigned long long int));
+ ret=wonky_malloc(sizeof(struct Constant));
/* skip the leading 0x */
for(i=2;i<token->data_size;++i)
long double *ret_component;
struct Constant *ret;
- ret_component=malloc(sizeof(double));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(double));
+ ret=wonky_malloc(sizeof(struct Constant));
*ret_component=.0l;
ret->value=ret_component;
long double *ret_component;
struct Constant *ret;
- ret_component=malloc(sizeof(double));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(double));
+ ret=wonky_malloc(sizeof(struct Constant));
*ret_component=.0l;
ret->value=ret_component;
char *ret_component;
struct Constant *ret;
- ret_component=malloc(sizeof(char));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(char));
+ ret=wonky_malloc(sizeof(struct Constant));
*ret_component=token->data[1];
ret->value=ret_component;
char *ret_component;
struct Constant *ret;
- ret_component=malloc(sizeof(char));
- ret=malloc(sizeof(struct Constant));
+ ret_component=wonky_malloc(sizeof(char));
+ ret=wonky_malloc(sizeof(struct Constant));
*ret_component=token->data[1];
ret->value=ret_component;
{
struct Constant *ret;
- ret=malloc(sizeof(struct Constant));
- ret->value=malloc(sizeof(int));
+ ret=wonky_malloc(sizeof(struct Constant));
+ ret->value=wonky_malloc(sizeof(int));
*((int*)ret->value)=constant->value;
ret->type=(struct Type*)get_type_insecure(INT_SIZE,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);
char *ret_component;
struct Constant *ret;
- ret=malloc(sizeof(struct Constant));
+ ret=wonky_malloc(sizeof(struct Constant));
ret_component=gstrncpy(token->data+1,token->data_size-2);
char *ret_component;
struct Constant *ret;
- ret=malloc(sizeof(struct Constant));
+ ret=wonky_malloc(sizeof(struct Constant));
ret_component=gstrncpy(token->data+1,token->data_size-2);
F diff --git a/src/semantics/value/initialiser.c b/src/semantics/value/initialiser.c --- a/src/semantics/value/initialiser.c +++ b/src/semantics/value/initialiser.c
{
struct Initialiser_Denoted *ret;
- ret=malloc(sizeof(struct Initialiser_Denoted));
+ ret=wonky_malloc(sizeof(struct Initialiser_Denoted));
ret->kind=INITIALISER_DENOTED;
ret->to_be_initialised=to_be_initialised;
ret->initialiser=initialiser;
{
struct Initialiser_Indexed *ret;
- ret=malloc(sizeof(struct Initialiser_Indexed));
+ ret=wonky_malloc(sizeof(struct Initialiser_Indexed));
ret->kind=INITIALISER_INDEXED;
ret->type=type;
ret->index=index;
{
struct Initialiser_Expression *ret;
- ret=malloc(sizeof(struct Initialiser_Expression));
+ ret=wonky_malloc(sizeof(struct Initialiser_Expression));
ret->kind=INITIALISER_EXPRESSION;
ret->expression=expression;
struct Initialiser_Compound *ret;
size_t i;
- ret=malloc(sizeof(struct Initialiser_Compound));
+ ret=wonky_malloc(sizeof(struct Initialiser_Compound));
ret->kind=INITIALISER_COMPOUND;
ret->type=type;
ret->number_of_components=components->size;
- ret->components=malloc(sizeof(struct Initialiser**)*components->size);
+ ret->components=wonky_malloc(sizeof(struct Initialiser**)*components->size);
for(i=0;components->size>0;++i)
ret->components[i]=Queue_Pop(components);
- free(components);/*BEWARE*/
+ wonky_free(components);/*BEWARE*/
if(constraint_check_compound_initialiser(ret,translation_data))
{
{
struct Initialiser_Error *ret;
- ret=malloc(sizeof(struct Initialiser_Error));
+ ret=wonky_malloc(sizeof(struct Initialiser_Error));
ret->kind=INITIALISER_ERROR;
ret->error=error;
F diff --git a/src/semantics/value/type.c b/src/semantics/value/type.c --- a/src/semantics/value/type.c +++ b/src/semantics/value/type.c
if(hold_node==NULL)
{
- type->node=Map_Push_And_Get(base,type,struct_size,type,translation_data->memory);
+ type->node=Map_Push_And_Get(base,type,struct_size,type);
return type;
}else
{
- free(type);
+ wonky_free(type);
wonky_assert(is_valid_type((struct Type*)hold_node->ID));
return (struct Type*)hold_node->ID;
{
struct Type_Error *ret;
- ret=calloc(1,sizeof(struct Type_Error));
+ ret=wonky_calloc(1,sizeof(struct Type_Error));
ret->specifier=TS_ERROR;
ret->error=type;
if(type!=NULL)
wonky_assert(prototype->denotation=DT_Prototype);
prototype->denotation=DT_Object;
- ret=calloc(1,sizeof(struct Type_Struct_Union));
+ ret=wonky_calloc(1,sizeof(struct Type_Struct_Union));
ret->specifier=prototype->specifier;
ret->struct_union=prototype->struct_union;
struct Struct_Union *ret;
- ret=calloc(1,sizeof(struct Struct_Union));
+ ret=wonky_calloc(1,sizeof(struct Struct_Union));
ret->specifier=struct_or_union;
- ret->members=malloc(sizeof(struct Queue));
+ ret->members=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->members);
ret->inner_namespace=(struct Normal_Scope*)get_normal_scope(NULL,BLOCK_SCOPE);
struct Enum *get_enum_base(struct token *id)
{
struct Enum *ret;
- ret=malloc(sizeof(struct Enum));
+ ret=wonky_malloc(sizeof(struct Enum));
ret->specifier=TS_ENUM;
- ret->consts=malloc(sizeof(struct Queue));
+ ret->consts=wonky_malloc(sizeof(struct Queue));
Queue_Init(ret->consts);
ret->is_finished=0;
struct Type* get_basic_type(struct Denotation_Prototype *prototype,struct Translation_Data *translation_data)
{
struct Type_Basic *ret;
- ret=calloc(1,sizeof(struct Type_Basic));
+ ret=wonky_calloc(1,sizeof(struct Type_Basic));
wonky_assert(prototype->denotation=DT_Prototype);
struct Type* get_pointer_type(struct Type *points_to,_Bool is_const,_Bool is_volatile,struct Translation_Data *translation_data)
{
struct Type_Pointer *ret;
- ret=calloc(1,sizeof(struct Type_Pointer));
+ ret=wonky_calloc(1,sizeof(struct Type_Pointer));
ret->specifier=TS_POINTER;
ret->size=PTR_SIZE;
ret->points_to=points_to;
struct Type* get_array_type(struct Type *array_of,struct AST* number_of_elements,struct Translation_Data *translation_data)
{
struct Type_Array *ret;
- ret=calloc(1,sizeof(struct Type_Array));
+ ret=wonky_calloc(1,sizeof(struct Type_Array));
ret->specifier=TS_ARRAY;
ret->size=0;
if(number_of_elements!=NULL)
struct Type* get_array_type_raw(struct Type *array_of,size_t size,struct Translation_Data *translation_data)
{
struct Type_Array *ret;
- ret=calloc(1,sizeof(struct Type_Array));
+ ret=wonky_calloc(1,sizeof(struct Type_Array));
ret->specifier=TS_ARRAY;
ret->size=size;
ret->is_array_of=array_of;
wonky_assert(prototype->denotation=DT_Prototype);
prototype->denotation=DT_Object;
- ret=calloc(1,sizeof(struct Type_Enum));
+ ret=wonky_calloc(1,sizeof(struct Type_Enum));
ret->specifier=TS_ENUM;
ret->enumeration=prototype->enumerator;
ret->is_const=prototype->is_const;
size_t i;
struct Map *hold_node;
- ret=calloc(1,sizeof(struct Type_Function));
+ ret=wonky_calloc(1,sizeof(struct Type_Function));
ret->specifier=TS_FUNC;
ret->return_type=return_type;
ret->number_of_arguments=parameters->size;
- ret->arguments=malloc(sizeof(struct Denoted_Object*)*ret->number_of_arguments);
+ ret->arguments=wonky_malloc(sizeof(struct Denoted_Object*)*ret->number_of_arguments);
ret->is_variadic=is_variadic;
for(i=0;parameters->size>0;++i)
{
ret->arguments[i]=(struct Denoted_Object*)Queue_Pop(parameters);
}
- free(parameters);
+ wonky_free(parameters);
ret=(struct Type_Function*)type_check_and_push((struct Type*)ret,return_type->node,sizeof(struct Type_Function),translation_data);
if(is_variadic && ret->number_of_arguments==0)
void delete_enum(struct Enum *enumeration)
{
if(enumeration->id!=NULL)
- free(enumeration->id);
+ wonky_free(enumeration->id);
while(enumeration->consts->size>0)
Queue_Pop(enumeration->consts);
- free(enumeration);
+ wonky_free(enumeration);
}
void delete_struct_union(struct Struct_Union *su)
{
if(su->id!=NULL)
- free(su->id);
+ wonky_free(su->id);
delete_scope((struct Scope*)su->inner_namespace);
while(su->members->size>0)
Queue_Pop(su->members);
- free(su);
+ wonky_free(su);
}
void delete_type(void *type)
{
if(((struct Type*)type)->specifier!=TS_FUNC)
{
- free(type);
+ wonky_free(type);
}else
{
delete_normal_scope(AS_TYPE_FUNC_PTR(type)->function_prototype_scope);
- free(AS_TYPE_FUNC_PTR(type)->arguments);
- free(type);
+ wonky_free(AS_TYPE_FUNC_PTR(type)->arguments);
+ wonky_free(type);
}
}
struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size,struct Translation_Data *translation_data)
{
struct Type_Basic *ret;
- ret=calloc(1,sizeof(struct Type_Basic));
+ ret=wonky_calloc(1,sizeof(struct Type_Basic));
ret->specifier=type_specifier;
ret->size=type_size;
F diff --git a/src/semantics/value/value.c b/src/semantics/value/value.c --- a/src/semantics/value/value.c +++ b/src/semantics/value/value.c
struct Expression_Value* get_expression_value_void()
{
struct Expression_Value *ret;
- ret=malloc(sizeof(struct Expression_Value));
+ ret=wonky_malloc(sizeof(struct Expression_Value));
ret->type=VALUE_VOID;
wonky_assert(is_valid_value(ret));
struct Expression_Value* get_expression_value_lvalue(struct Object *object)
{
struct Expression_Value_LValue *ret;
- ret=malloc(sizeof(struct Expression_Value_LValue));
+ ret=wonky_malloc(sizeof(struct Expression_Value_LValue));
ret->type=VALUE_LVALUE;
ret->object=object;
if(type_is_constant_or_has_constant_member(object->type))
struct Expression_Value_Constant* get_expression_value_constant(struct Constant *constant)
{
struct Expression_Value_Constant *ret;
- ret=malloc(sizeof(struct Expression_Value_Constant));
+ ret=wonky_malloc(sizeof(struct Expression_Value_Constant));
ret->type=VALUE_CONSTANT;
ret->constant=constant;
struct Expression_Value* get_expression_value_rvalue(struct Object *temp_object)
{
struct Expression_Value_RValue *ret;
- ret=malloc(sizeof(struct Expression_Value_RValue));
+ ret=wonky_malloc(sizeof(struct Expression_Value_RValue));
ret->type=VALUE_TEMP;
ret->temp_object=temp_object;
struct Expression_Value* get_expression_value_function_designator(struct Denoted_Function *function)
{
struct Expression_Value_Function_Designator *ret;
- ret=malloc(sizeof(struct Expression_Value_Function_Designator));
+ ret=wonky_malloc(sizeof(struct Expression_Value_Function_Designator));
ret->type=VALUE_FUNCTION_DESIGNATOR;
ret->function=function;
}
void delete_expression_value_void(struct Expression_Value *void_expression_value)
{
- free(void_expression_value);
+ wonky_free(void_expression_value);
}
void delete_expression_value_lvalue(struct Expression_Value_LValue *lvalue)
{
- free(lvalue);
+ wonky_free(lvalue);
}
void delete_expression_value_constant(struct Expression_Value_Constant *constant_expression_value)
{
delete_constant(constant_expression_value->constant);
- free(constant_expression_value);
+ wonky_free(constant_expression_value);
}
void delete_expression_value_rvalue(struct Expression_Value_RValue *temp_value)
{
delete_object(temp_value->temp_object);
- free(temp_value);
+ wonky_free(temp_value);
}
void delete_expression_value_function_designator(struct Expression_Value_Function_Designator *function_designator)
{
- free(function_designator);
+ wonky_free(function_designator);
}
#endif
F diff --git a/src/wonky.c b/src/wonky.c --- a/src/wonky.c +++ b/src/wonky.c
struct Command_Arguments *command_arguments;
struct Program *program;
+ wonky_memory_init();
+
command_arguments=parse_command_arguments(argv);
+
if(command_arguments->error_message!=NULL)
{
+ wonky_memory_delete();
fprintf(stderr,command_arguments->error_message);
return 1;
}
if(command_arguments->print_tokens && !command_arguments->is_quiet)
{
+ wonky_memory_delete();
return print_tokens_of_program(stdout,command_arguments->source_names);
}else
{
program=parse_program(command_arguments->source_names);
if(program==NULL)
+ {
+ wonky_memory_delete();
return 0;
+ }
if(program->errors->size>0)
{
if(!command_arguments->is_quiet)
}
delete_command_arguments(command_arguments);
delete_program(program);
+ wonky_memory_delete();
return 1;
}else if(command_arguments->print_ast && !command_arguments->is_quiet)
{
delete_command_arguments(command_arguments);
delete_program(program);
+
+ wonky_memory_delete();
return 0;
}