-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtable.c
73 lines (60 loc) · 1.8 KB
/
vtable.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "vtable.h"
#include "error.h"
int nfuncs = 0;
tClase * vt_get_clase(char * id ){
tClase * aux = vclase;
while(aux!=NULL && strcmp(aux->nombre, id)!=0){
aux = (struct _nclase*)aux->next;
}
return aux;
}
tClase * vt_make_clase (char * id, NODE* ast, tClase * n){
tClase * nc = (tClase *) malloc(sizeof(tClase));
nc->nombre = strdup(id);
nc->ast=ast;
nc->init=0;
nc->next = n;
return nc;
}
/*Retorna el f_id asignado*/
int vt_add_function(const char * klass, const char * funcname, NODE * ast) {
if (funcname == NULL) {
fprintf(stderr, "Error vt_add_function: funcname es vacio\n");
return INTERNAL_ERROR;
}
nfuncs++;
ftable[nfuncs].klass = (klass != NULL) ? strdup(klass) : NULL;
ftable[nfuncs].func = strdup(funcname);
ftable[nfuncs].bloque = ast;
ftable[nfuncs].count_args = 0;
return nfuncs;
}
/* Agrega un parametro a una funcion */
void vt_add_argument(int func_id, const char * arg) {
if (nfuncs > func_id) {
fprintf(stderr, "Error vt_add_argument: func_id=%d fuera del rango (max_func_id=%d).", func_id, nfuncs);
} else {
ftable[func_id].args[ftable[func_id].count_args].id = strdup(arg);
ftable[func_id].count_args++;
}
}
/*Retorna 0 si njo existe y si existe retorna el f_id*/
vtable *
vt_get_function(const char * klass, const char * funcname) {
int i = 0;
while (i < nfuncs) {
i++;
if (!strcmp(ftable[i].func, funcname)) {
if (klass == NULL && ftable[i].klass == NULL)
return &ftable[i];
else if (klass != NULL && !strcmp(ftable[i].klass, klass))
return &ftable[i];
else
continue;
}
}
return NULL;
}