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

74 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 *pName, node_info *pStmts) {
node_info *newNode = malloc(sizeof(node_info));
newNode->type = FUNCTION;
newNode->name = pName;
newNode->_function_body = malloc(sizeof(node_info));
newNode->_function_body->next = copy_linked_list(pStmts);
_free_linked_list(pStmts);
return newNode;
}
/**
* 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 *pName) {
node_info *newNode = malloc(sizeof(node_info));
newNode->type = FUNCTION_CALL;
newNode->name = pName;
newNode->next = NULL;
return newNode;
}
/**
* 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 == NULL) {
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; //make a temp of list head, so we can traverse it.
//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;
}