aboutsummaryrefslogtreecommitdiff
path: root/src/tree.c
blob: 235d0e605fa6c06eb639ed795cd4d8440429198f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "include/tree.h"

tree_t* tree_init(int type) {
   tree_t* tree;

   tree = calloc(1, sizeof(struct TREE_STRUC));
   tree->type = type;
   
   switch (type) {
      case TREE_COMP:
         tree->data.comp.value         = NULL;
         tree->data.comp.size          = 0;
         break;
      case TREE_DEF:
         tree->data.def.type           = NULL;
         tree->data.def.tags           = NULL;
         tree->data.def.tags_size      = 0;
         tree->data.def.name           = NULL;
         tree->data.def.args           = NULL;
         tree->data.def.tags_size      = 0;
         tree->data.def.value          = NULL;
         break;
      case TREE_CALL:
         tree->data.call.target        = NULL;
         tree->data.call.args          = NULL;
         tree->data.call.args_size     = 0;
         break;
      case TREE_TYPE_STR: 
         tree->data.type_str.value     = NULL; 
         break; 
      case TREE_TYPE_INT: 
         tree->data.type_int.value     = 0; 
         break;
   }

   return tree;
}

void tree_destroy(tree_t* tree) {
   free(tree);
}