changeset 107:a3a2f64cf8f4

modify implementation of rectype
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Thu, 14 Jun 2012 19:44:54 +0900
parents 85047c4f1ca4
children 7ad14f446135
files CbC-examples/rectypeTest/instruct.cbc CbC-examples/rectypeTest/typedef.cbc gcc/c-decl.c gcc/c-family/c-common.c gcc/c-family/c-pretty-print.c gcc/c-parser.c
diffstat 6 files changed, 37 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/CbC-examples/rectypeTest/instruct.cbc	Wed Jun 13 17:18:58 2012 +0900
+++ b/CbC-examples/rectypeTest/instruct.cbc	Thu Jun 14 19:44:54 2012 +0900
@@ -1,26 +1,28 @@
 #include <stdlib.h>
 
+// miss
 struct interface {
-	__rectype *next;
+  __rectype *next;
 };
 
-
 __code print(struct interface p) {
-	puts("print");
-	exit(0);
+  puts("print");
+  exit(0);
 }
 
 __code csA(struct interface p) {
-	struct interface ds = { csA };
-	goto p.next(ds);
+  struct interface ds;
+  ds.next = csA;
+  goto p.next(ds);
 }
 
 void main1() {
-	struct interface ds = { print };
-	goto csA(ds);
+  struct interface ds;
+  ds.next = print;
+  goto csA(ds);
 }
 
 int main() {
-	main1();
-	return 0;
+  main1();
+  return 0;
 }
--- a/CbC-examples/rectypeTest/typedef.cbc	Wed Jun 13 17:18:58 2012 +0900
+++ b/CbC-examples/rectypeTest/typedef.cbc	Thu Jun 14 19:44:54 2012 +0900
@@ -1,21 +1,24 @@
-#include <stdio.h>
+typedef __code (CS)(__rectype*); // CS *p
 
-//typedef __code (*csPtr)(__rectype);
-typedef __code (*csPtr)(__rectype*); // TODO:  error 
+//typedef __code (*CS)(__code(*p)());
+//typedef __code (CS)(__code(*p)()); // CS *p
 
-
-//__code print(csPtr p ) { TODO:
-__code print(__rectype *p ) {
-	puts("hello");
+#include <stdio.h>
+__code cs_end(CS *p)
+{
+  printf("end\n");
 }
 
-//__code func(csPtr p ) { TODO:
-__code func(__rectype *p ) {
-	goto p(func);
+__code cs(CS *p)
+{
+  CS *b; 
+  goto p(b);
+//  goto p("aaa"); //note: expected ‘void (*)’ but argument is of type ‘char
 }
 
-
 int main() {
-	goto func(print);
-	return 0;
+  CS *p;
+  p = cs_end;
+  goto cs(p);
+  return 0;
 }
--- a/gcc/c-decl.c	Wed Jun 13 17:18:58 2012 +0900
+++ b/gcc/c-decl.c	Thu Jun 14 19:44:54 2012 +0900
@@ -5159,6 +5159,7 @@
 #ifndef noCbC
   if ( declspecs->typespec_word == cts_CbC_rec )
     {
+      //      IS_RECTYPE(type) = 1;
       //      type = build_code_segment_type (type, NULL_TREE);
       IS_RECTYPE(type) = 1;
     }
--- a/gcc/c-family/c-common.c	Wed Jun 13 17:18:58 2012 +0900
+++ b/gcc/c-family/c-common.c	Thu Jun 14 19:44:54 2012 +0900
@@ -423,7 +423,7 @@
 #ifndef noCbC
   /* CbC project */
   { "__code",         RID_CbC_CODE,   0 },
-  { "code",         RID_CbC_CODE,   0 },
+  //  { "code",         RID_CbC_CODE,   0 },
   { "__rectype",       RID_CbC_REC,    0},
   { "selftype",       RID_CbC_SELFTYPE,    0},
 #endif
--- a/gcc/c-family/c-pretty-print.c	Wed Jun 13 17:18:58 2012 +0900
+++ b/gcc/c-family/c-pretty-print.c	Thu Jun 14 19:44:54 2012 +0900
@@ -547,7 +547,8 @@
 	  || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
 	pp_c_right_paren (pp);
 #ifndef noCbC
-      if(IS_RECTYPE(t)) return;
+      if(IS_RECTYPE(t)) 
+	return;
 #endif
       t = TREE_TYPE (t);
     }
--- a/gcc/c-parser.c	Wed Jun 13 17:18:58 2012 +0900
+++ b/gcc/c-parser.c	Thu Jun 14 19:44:54 2012 +0900
@@ -2144,7 +2144,8 @@
 	  t.kind = ctsk_resword;
 	  t.spec = c_parser_peek_token (parser)->value;
 	  declspecs_add_type (loc, specs, t);
-	  
+
+	  IS_RECTYPE(t.spec) = 1;
 	  /*
 	    attrs = get_identifier("fastcall");
 	    attrs = build_tree_list(attrs, NULL_TREE);
@@ -2520,7 +2521,9 @@
 	    while(TREE_CODE (TREE_TYPE (tmptype)) == POINTER_TYPE)
 	      tmptype = TREE_TYPE(tmptype);
 	    if(IS_SELFTYPE ( TREE_TYPE (tmptype))) TREE_TYPE(tmptype) = type;
-	    if(IS_RECTYPE ( TREE_TYPE (tmptype))) TREE_TYPE(tmptype) = type;
+	    //	    if(IS_RECTYPE ( TREE_TYPE (tmptype))) 
+	    if(IS_RECTYPE (tmptype)) 
+	      TREE_TYPE(tmptype) = type;
 	  }
 
 #endif