-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.c
87 lines (79 loc) · 1.91 KB
/
actions.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "actions.h"
extern symnode *root,*Lroot;
extern int lineno;
int silc_on_func_header(int type,char *name,argnode *args)
{
Ldestruct(Lroot);
symnode *entry=lookup(name,root);
if(entry==NULL||entry->args==NULL)
function_not_declared_error(name);
printf("//arguments ");
if(compare_arglist(entry->args,args))
function_arglist_different(name);
printf("\n");
while(args!=NULL)
{
printf("//entering %s\n",args->name);
makeLSymEntry(args->name,Lroot,args->type,1,args->refer);
args=args->next;
}
return 0;
}
int return_type_check(char *name,node* rtrn)
{
printf("//function %s return type %s\n",name,getVarType(name,Lroot)==TYPE_INT?"integer":"boolean");
return typeCheckReturnStmt(getVarType(name,Lroot),rtrn);
}
int check_func_sign(char *name,node *args)
{
symnode *entry=lookup(name,root);
if(entry==NULL||entry->args==NULL)
function_not_declared_error(name);
}
int compare_arglist(argnode* decl,argnode *def)
{
if(decl==NULL&&def==NULL)
return 0;
if(decl!=NULL&&def==NULL)
return 1;
if(decl==NULL&&def!=NULL)
return 1;
printf("%s ",decl->name);
if(strcmp(decl->name,def->name)!=0||decl->type!=def->type)
return 1;
return compare_arglist(decl->next,def->next);
}
int compare_arglist2(argnode* decl,node *act)
{
if(decl==NULL&&act==NULL)
return 0;
if(decl!=NULL&&act==NULL)
return 1;
if(decl==NULL&&act!=NULL)
return 1;
if(decl->type!=act->type)
return 1;
if(decl->refer==1&&act->op!=CH_ADDR)
return 1;
return compare_arglist2(decl->next,act->right);
}
int function_not_declared_error(char *name)
{
char buf[50];
sprintf(buf,"Function %s was not declared",name);
yyerror(buf);
return 0;
}
int function_arglist_different(char *name)
{
char buf[90];
sprintf(buf,"The argument list of function %s is different from its declaration",name);
yyerror(buf);
return 0;
}
int arraydeclerror()
{
char buf[50];
sprintf(buf,"Size of array should be greater than zero");
yyerror(buf);
}