changeset 543:af90edc74aa5 decl_data_fix

struct init fix
author kono
date Mon, 02 Jan 2006 09:49:35 +0900
parents 492f06738550
children dbfd6e88e2c3
files Changes mc-codegen.c mc-parse.c
diffstat 3 files changed, 40 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sun Jan 01 18:49:07 2006 +0900
+++ b/Changes	Mon Jan 02 09:49:35 2006 +0900
@@ -7750,3 +7750,15 @@
 
 #include の時にchptrsave stackは? top_init でclearするのは
 変だとしても。#define \n hoge \n #include とか? 冗談だろ。
+
+decl_data のINTの場合にcorret_typeするとsigned/byteの情報が
+失われてしまう。
+
+local struct init の場合に式を使うことができない。
+local struct static を切ればいいんだけど。式があったら、
+代入するようにすれば良いんだが。(ま、いいか?)
+
+
+
+
+
--- a/mc-codegen.c	Sun Jan 01 18:49:07 2006 +0900
+++ b/mc-codegen.c	Mon Jan 02 09:49:35 2006 +0900
@@ -2139,6 +2139,10 @@
     return(list4(UCOND,e1,e2,e3));
 }
 
+/*
+   assop
+      parse tree generation
+ */
 extern int
 assop(int e1,int e2,int op,int t,int no_float)
 {
@@ -2207,6 +2211,10 @@
 }
 
 
+/*
+   assop
+      code generation
+ */
 
 static void
 iassop(int e1)
@@ -3056,6 +3064,7 @@
     int type,sz,offset1=0;
     int smode=mode;
     mode = STADECL;
+    sz = size(n->ty);
     /*
          decl_str_init
             output delayed decl data
@@ -3961,6 +3970,13 @@
 extern int
 cexpr(int e)
 {
+    if (car(e) == CONV) {
+	switch(caddr(e)) {
+	case I2C: case I2S: case U2UC: case U2US:
+	    e=cadr(e); break;
+	default: error(-1); // illeagal int constant
+	}
+    }
     if (car(e) != CONST) error(CNERR);
     return (cadr(e));
 }
--- a/mc-parse.c	Sun Jan 01 18:49:07 2006 +0900
+++ b/mc-parse.c	Mon Jan 02 09:49:35 2006 +0900
@@ -1423,7 +1423,10 @@
 	mode = mode_save;
  	//if(car(e)!=CONST && t==CHAR)
  	//    error(TYERR);
-	e = correct_type(e,INT); // UNSIGND?
+	// correct_type is too weak, should hanle ADDRESS/ARRAY
+	//   assign_data call rvalue, this is a duplicate rvalue call (correct?)
+	if (!scalar(type) && (type>0 && (car(type)!=ADDRESS && car(type)!=ARRAY)))
+	    e = correct_type(rvalue(e),t0);
  	offset = assign_data(e,t,n,offset);
  	type=t;
 	return offset;
@@ -1432,7 +1435,7 @@
  	e=expr1();
 	if (lc) checksym(RC);
 	mode = mode_save;
-	e = correct_type(e,t0);
+	e = correct_type(rvalue(e),t0);
  	offset = assign_data(e,t,n,offset);
  	type=t;
 	return offset;
@@ -1490,7 +1493,9 @@
 #if LOCAL_STRUCT_INIT_STATIC 
 	if(mode==LDECL) {
 	    if (offset) error(-1);
-	    local_struct_static(n);
+	    local_struct_static(n); 
+	    // change mode to STADECL
+	    // decl_data_field(t,n,offset) is called inside;
 	} else
 #endif
 	    decl_data_field(t,n,offset);
@@ -1945,6 +1950,10 @@
 	    checkret();
 	if(sym==IDENT&&skipspc()==':') {
 	    dolabel();
+	    if (sym==RC) {
+		fprintf(stderr," error: label at end of compound statement\n");
+		return;
+	    }
 	    statement(use);
 	} else {
 	    if (inmode) {