-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparam_list.c
65 lines (53 loc) · 1.36 KB
/
param_list.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
#include "param_list.h"
#include <stdio.h>
#include <stdlib.h>
#include "symbol.h"
#include "scope.h"
extern int level;
struct param_list *param_list_create(char *name, struct type *type, struct param_list *next, int line) {
struct param_list *p = (struct param_list *)malloc(sizeof(struct param_list));
if(!p) {
fprintf(stdout, "malloc fails!\n");
exit(EXIT_FAILURE);
}
p->name = name;
p->type = type;
p->next = next;
p->line = line;
return p;
}
void param_list_print(struct param_list *p) {
if(!p) return;
printf("%s: ", p->name);
type_print(p->type);
if(p->next) {
printf(", ");
param_list_print(p->next);
}
}
int param_list_resolve(struct param_list *p, int seq) {
if(!p) return 0;
struct symbol *sym = symbol_create(SYMBOL_PARAM, seq, p->type, p->name, FUNC_NOT);
struct symbol *s = scope_lookup_local(p->name);
if(s) {
fprintf(stdout, "resolve error (line %d): %s has been defined as param %d (level %d)\n", p->line, p->name, s->which, level);
resolve_error_count += 1;
} else {
scope_bind(p->name, sym);
}
p->symbol = sym;
return param_list_resolve(p->next, seq+1) + 1;
}
int params_equals(struct param_list *p, struct param_list *q) {
if(!p && !q) {
return 1;
} else if((p && !q) || (!p && q)) {
return 0;
} else {
if(type_equals(p->type, q->type)) {
return params_equals(p->next, q->next);
} else {
return 0;
}
}
}