Update of /cvsroot/agd/server/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3038
Modified Files:
lang.y
Log Message:
Fixes for prototype defining.
Index: lang.y
===================================================================
RCS file: /cvsroot/agd/server/src/lang.y,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** lang.y 12 Mar 2004 16:03:10 -0000 1.2
--- lang.y 15 Mar 2004 18:48:13 -0000 1.3
***************
*** 96,106 ****
type L_IDENTIFIER
{
def_id_t *idp;
! idp = find_id($2);
! if(idp && idp->type != ID_FUN_PROT) {
! redeclaration_error(idp, ID_FUN);
} else {
define_id($2, ID_FUN_PROT, $1, NULL); /* define_id could return id_t*. */
$<id>$ = find_id($2);
}
}
--- 96,117 ----
type L_IDENTIFIER
{
+ /* Mid-rule action used only to store a value.
+ Feels hacky, but I don't want a global variable.
+
+ 1 if the function declaration was just added;
+ 0 if it already existed.
+ Makes sense only in regard to the next action. */
+ }
+ {
def_id_t *idp;
! $<id>$ = idp = find_id($2);
! if(idp) {
! $<i>3 = 0; /* Means it already existed. */
! if(idp->type != ID_FUN_PROT)
! redeclaration_error(idp, ID_FUN);
} else {
define_id($2, ID_FUN_PROT, $1, NULL); /* define_id could return id_t*. */
$<id>$ = find_id($2);
+ $<i>3 = 1; /* Means we just defined the prototype. */
}
}
***************
*** 109,120 ****
def_id_t *idp;
int i;
! idp = $<id>3;
! idp->args = copy_array(&$5, NULL);
scope_level++;
! for(i=0;i<$5.length;i++) {
variable_t *v;
def_id_t *id;
! v = $5.data[i];
id = find_id(v->name);
if(id) {
--- 120,131 ----
def_id_t *idp;
int i;
! idp = $<id>4;
! idp->args = copy_array(&$6, NULL);
scope_level++;
! for(i=0;i<$6.length;i++) {
variable_t *v;
def_id_t *id;
! v = $6.data[i];
id = find_id(v->name);
if(id) {
***************
*** 129,135 ****
block_or_semi
{
! if($8.length) {
! def_id_t *idp = $<id>3;
! if(idp->lpc_type != $1 || compare_args(idp->args, &$5)) {
char buf[256];
sprintf(buf, "definition doesn't match declaration for %s", $2);
--- 140,146 ----
block_or_semi
{
! if($9.length) {
! def_id_t *idp = $<id>4;
! if(idp->lpc_type != $1 || compare_args(idp->args, &$6)) {
char buf[256];
sprintf(buf, "definition doesn't match declaration for %s", $2);
***************
*** 140,155 ****
idp->type = ID_FUN;
! if((int)$8.data[$8.length-1] != F_RETURN) {
if($1 != T_VOID) {
comp_error("control reaches end of non-void function");
} else {
! array_push(&$8, (void *) F_PUSH_VOID);
! array_push(&$8, (void *) F_RETURN);
}
}
! add_function(idp, $<i>7, &$8);
} else {
! add_function($<id>3, 0, NULL);
}
pop_scope();
--- 151,174 ----
idp->type = ID_FUN;
! if((int)$9.data[$9.length-1] != F_RETURN) {
if($1 != T_VOID) {
comp_error("control reaches end of non-void function");
} else {
! array_push(&$9, (void *) F_PUSH_VOID);
! array_push(&$9, (void *) F_RETURN);
}
}
! add_function(idp, $<i>8, &$9);
} else {
! def_id_t *idp = $<id>4;
! if(idp->type == ID_FUN_PROT && !$<i>3) {
! char buf[256];
! sprintf(buf, "warning: repeated prototype for %s; using existing prototype", $2);
! display_error(buf);
! compile_warnings++;
! } else {
! add_function(idp, $<i>8, NULL);
! }
}
pop_scope();
***************
*** 1117,1123 ****
}
array_concat(&$$, realargs);
-
xfree(realargs);
! free_array(&$5, NULL);
array_concat(&$$, &$1.arr);
--- 1136,1141 ----
}
array_concat(&$$, realargs);
xfree(realargs);
!
array_concat(&$$, &$1.arr);
***************
*** 1125,1128 ****
--- 1143,1147 ----
array_push(&$$, $3);
array_push(&$$, (void *) $5.length);
+ free_array(&$5, NULL);
}
;
|