You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
eon/eon-unix/functions/functions.c

109 lines
3.0 KiB

5 years ago
#ifndef FUNCTIONS_C
#define FUNCTIONC_C
#include "functions.h"
/*
Author: xerox
Update: 1/20/2020
create a function given the name of the function and the statements
*/
static node_info* create_function(char* p_name, node_info* p_stmts)
5 years ago
{
if (!p_name || !p_stmts)
5 years ago
return NULL;
node_info *new_node = malloc(sizeof(node_info));
5 years ago
new_node->function_body = malloc(sizeof(node_info));
new_node->operation = FUNCTION_OPERATION;
new_node->operation_type.func = FUNCTION;
new_node->name = p_name;
new_node->next = NULL;
new_node->function_body->statement_list = p_stmts;
return new_node;
}
/*
Author: xerox
Update: 1/20/2020
create a function call given the name
TODO add scope.
*/
static node_info* create_function_call(char* p_name)
5 years ago
{
if (!p_name)
5 years ago
return NULL;
node_info *new_node = malloc(sizeof(node_info));
5 years ago
new_node->operation = FUNCTION_OPERATION;
new_node->operation_type.func = FUNCTION_CALL;
new_node->name = p_name;
new_node->next = NULL;
return new_node;
}
/*
Author: xerox
Update: 1/20/2020
create compound statement given statement list and head of linked list.
*/
static node_info* create_compound_statement(node_info* new_statement_list, node_info* statement_head)
5 years ago
{
if (!new_statement_list)
return NULL;
if(!statement_head)
{
statement_head = malloc(sizeof(node_info));
node_info* new_node = malloc(sizeof(node_info));
statement_head->statement_list = malloc(sizeof(node_info));
statement_head->operation = EXEC_STMT_LIST_OPERATION;
statement_head->statement_list->operation = EXEC_STMT_LIST_OPERATION;
statement_head->statement_list->next = new_statement_list;
statement_head->next = NULL;
5 years ago
statement_head->statement_list->statement_list = NULL;
}
else
{
node_info *p_temp_head = statement_head;
//TODO update with doubly linked list
while(p_temp_head->statement_list != NULL)
p_temp_head = p_temp_head->statement_list;
p_temp_head->statement_list = malloc(sizeof(node_info));
p_temp_head->operation = EXEC_STMT_LIST_OPERATION;
p_temp_head->statement_list->operation = EXEC_STMT_LIST_OPERATION;
5 years ago
p_temp_head->statement_list->next = new_statement_list;
p_temp_head->statement_list->statement_list = NULL;
}
return statement_head;
}
/*
Author: xerox
Update: 1/20/2020
add to compound statement given new statement and head of statement,
*/
static node_info* add_to_compound_statement(node_info* new_statement, node_info* statement_head)
{
if (!new_statement || !statement_head)
return NULL;
node_info* p_head_tmp = statement_head;
while (p_head_tmp->statement_list)
p_head_tmp = p_head_tmp->statement_list;
while (p_head_tmp->next)
p_head_tmp = p_head_tmp->next;
p_head_tmp->next = malloc(sizeof(node_info));
p_head_tmp->next = new_statement;
return statement_head;
}
#endif