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/functions/functions.c

73 lines
1.9 KiB

5 years ago
#include <stdlib.h>
#include "functions.h"
#include "../linked_list/linked_list.h"
#include "../linked_list/linked_list.c"
/**
* Creates a function.
*
* @param char * to the name of the function
* @param nodeInfo * to statement list
* @return nodeInfo * to head
*/
node_info *create_function(char *p_name, node_info *p_stmts)
{
node_info *new_node = malloc(sizeof(node_info));
new_node->opperation = 7;
new_node->type = FUNCTION;
new_node->name = p_name;
new_node->_function_body = malloc(sizeof(node_info));
new_node->_function_body->next = copy_linked_list(p_stmts);
_free_linked_list(p_stmts);
return new_node;
5 years ago
}
/**
* Creates a function
*
* @param name of the function
* @return a node_info pointer to the head of the function
*/
node_info *create_function_call(char *p_name)
{
node_info *new_node = malloc(sizeof(node_info));
new_node->opperation = 7;
new_node->type = FUNCTION_CALL;
new_node->name = p_name;
new_node->next = NULL;
return new_node;
5 years ago
}
/**
* Creates a linked list inside of a linked list
*
* @param new_statement_list to be appended to list
* @param statement_head of linked list to append to
*/
node_info *create_compound_statement(node_info *new_statement_list, node_info *statement_head)
{
if(!statement_head)
{
5 years ago
statement_head = malloc(sizeof(node_info));
node_info *newNode = malloc(sizeof(node_info));
statement_head->opperation = 5;
statement_head->next = new_statement_list;
statement_head->next->next = NULL;
statement_head->statement_list = NULL;
}
else
{
node_info *p = statement_head;
5 years ago
//TODO update with doubly linked list
while(p->statement_list != NULL)
p = p->statement_list;
p->next = malloc(sizeof(node_info));
p->next = new_statement_list;
p->next->next = NULL;
}
return statement_head;
}