Update of /cvsroot/agd/server/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31709
Modified Files:
lang.y
Log Message:
Fixed some problems with T_ANY; no num_arg checking for varargs functions
Index: lang.y
===================================================================
RCS file: /cvsroot/agd/server/src/lang.y,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- lang.y 23 Jul 2004 17:03:56 -0000 1.26
+++ lang.y 24 Jul 2004 17:54:30 -0000 1.27
@@ -19,7 +19,7 @@
/* Used during compilation, replaced with F_JMP.
Need to use two separate numbers for both, because one
- could easily appear on it's own in code. */
+ could easily appear on its own in code. */
/* These are unnecessary with the add_token() system. */
#define L_BREAK_MAGIC1 -1
#define L_BREAK_MAGIC2 -2
@@ -48,6 +48,7 @@
int add_string_to_table(char *s);
void make_lvalue(int index);
+extern void add_function(def_id_t *idp);
%}
/* Makes bison define YYLTYPE */
@@ -150,7 +151,7 @@
str = type2str(DEFAULT_FUNCTION_TYPE);
buf = xmalloc(strlen(str) + 34);
sprintf(buf, "warning: return type defaults to %s", type2str(DEFAULT_FUNCTION_TYPE));
- display_error(buf);
+ do_error(buf);
compile_warnings++;
free(buf);
}
@@ -215,18 +216,18 @@
}
}
- add_function(idp, @$.first_line);
+ add_function(idp/*, @$.first_line*/);
curr_fun_type = 0;
} else {
def_id_t *idp = $<id>3;
if(idp->type == ID_FUN_PROT && !is_new_declaration) {
char *buf = xmalloc(strlen($2) + 64);
sprintf(buf, "warning: repeated prototype for %s; using existing prototype", $2);
- display_error(buf);
+ do_error(buf);
free(buf);
compile_warnings++;
} else {
- add_function(idp, @$.first_line);
+ add_function(idp/*, @$.first_line*/);
}
}
pop_scope();
@@ -278,8 +279,8 @@
$$.direct_type = 1;
$$.lval = 0;
-/* $$.type = $1 ? T_INT : T_ANY;*/
- $$.type = T_INT;
+ $$.type = $1 ? T_INT : T_ANY;
+/* $$.type = T_INT;*/
add_two_tokens(F_PUSH_INT, $1);
}
| defined_name /* This should not be a constant. */
@@ -582,12 +583,15 @@
if(!dont_add_pop) {
num = num_locals_pushed;
num += block_history[scope_level - 1];
- if(num)
+ if(num == 1)
+ add_token(F_POP);
+ else if(num > 1)
add_two_tokens(F_POP_N, num);
} else
dont_add_pop = 0;
num_locals_pushed = 0;
+ block_history[scope_level-1] = 0; /* XXX */
pop_scope();
}
;
@@ -719,7 +723,7 @@
char *buf;
buf = xmalloc(strlen($1) + 51);
sprintf(buf, "warning: declaration of %s shadows function argument", $1);
- display_error(buf);
+ do_error(buf);
free(buf);
compile_warnings++;
} else if(id->type == ID_DFUN) {
@@ -855,7 +859,7 @@
if($2.type) {
comp_error("return from a void function with a value");
}
- } else if($2.type != curr_fun_type) {
+ } else if($2.type != curr_fun_type && $2.type != T_ANY) {
comp_error("improper return type");
}
@@ -1047,6 +1051,7 @@
int i;
char *buf;
def_id_t *idp;
+ int type_mods;
$$.side_effect = 1;
$$.direct_type = 0;
@@ -1055,39 +1060,43 @@
break;
$$.type = $1->lpc_type;
+ type_mods = $$.type & MOD_ALL;
+ $$.type &= ~MOD_ALL;
- if($3.len > $1->num_arg) {
- buf = xmalloc(strlen($1->name) + 23);
- sprintf(buf, "too many arguments to %s", $1->name);
- comp_error(buf);
- free(buf);
- goto clean_up;
- } else if($3.len < $1->num_arg) {
- buf = xmalloc(strlen($1->name) + 22);
- sprintf(buf, "too few arguments to %s", $1->name);
- comp_error(buf);
- free(buf);
- goto clean_up;
- } else {
- for(i=0;i<$1->num_arg;i++) {
- if(($1->args[i] == T_ARRAY && ($3.data[i] & T_ARRAY)) ||
- ($3.data[i] == T_ARRAY && ($1->args[i] & T_ARRAY)))
- continue;
+ if(!(type_mods & MOD_VARARGS)) {
+ if($3.len > $1->num_arg) {
+ buf = xmalloc(strlen($1->name) + 23);
+ sprintf(buf, "too many arguments to %s", $1->name);
+ comp_error(buf);
+ free(buf);
+ goto clean_up;
+ } else if($3.len < $1->num_arg) {
+ buf = xmalloc(strlen($1->name) + 22);
+ sprintf(buf, "too few arguments to %s", $1->name);
+ comp_error(buf);
+ free(buf);
+ goto clean_up;
+ }
+ }
+
+ for(i=0;i</*$1->num_arg*/$3.len;i++) {
+ if(($1->args[i] == T_ARRAY && ($3.data[i] & T_ARRAY)) ||
+ ($3.data[i] == T_ARRAY && ($1->args[i] & T_ARRAY)))
+ continue;
- if($1->args[i] != T_ANY && $3.data[i] != T_ANY
- && $1->args[i] != $3.data[i]) {
- char *ts1, *ts2;
+ if($1->args[i] != T_ANY && $3.data[i] != T_ANY
+ && $1->args[i] != $3.data[i]) {
+ char *ts1, *ts2;
- ts1 = type2str($1->args[i]);
- ts2 = type2str($3.data[i]);
- buf = xmalloc(strlen($1->name) + strlen(ts1) + strlen(ts2) + 64);
- sprintf(buf, "argument %d type mismatch for %s - expected %s, got %s",
- i+1, $1->name, ts1, ts2);
- comp_error(buf);
- free(buf);
- goto clean_up;
- break;
- }
+ ts1 = type2str($1->args[i]);
+ ts2 = type2str($3.data[i]);
+ buf = xmalloc(strlen($1->name) + strlen(ts1) + strlen(ts2) + 64);
+ sprintf(buf, "argument %d type mismatch for %s - expected %s, got %s",
+ i+1, $1->name, ts1, ts2);
+ comp_error(buf);
+ free(buf);
+ goto clean_up;
+ break;
}
}
@@ -1204,7 +1213,7 @@
result->lval = 0;
- if(left->type && type2 && left->type != type2) {
+ if(left->type && type2 && left->type != type2 && type2 != T_ANY) {
comp_error("type mismatch");
}
check_operand(op, left->type, type2);
|