[pypy-commit] creflect default: progress

arigo noreply at buildbot.pypy.org
Mon Nov 17 22:51:42 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r57:9dd40ca6f5b6
Date: 2014-11-17 22:52 +0100
http://bitbucket.org/cffi/creflect/changeset/9dd40ca6f5b6/

Log:	progress

diff --git a/creflect/creflect.h b/creflect/creflect.h
--- a/creflect/creflect.h
+++ b/creflect/creflect.h
@@ -1,4 +1,5 @@
 #include <stddef.h>
+#include <string.h>
 
 
 typedef struct {
diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -97,12 +97,11 @@
         comment2 = inspect.get_comment(0, False, "an integer type")
         comment3 = inspect.get_comment(0, False, "not declared 'const'")
         block.writedecl("char b[sizeof(%s)];%s" % (star_p1, comment1))
+        if self.const:
+            block.writeline("memset(b, -1, sizeof(b));")
         inspect.assign_to_p1("b")
         block.writeline("(void)(%s << 1);%s" % (star_p1, comment2))
-        if self.const:
-            block.sprintf_add_left("const ")
-            block.writeline("memset(b, -1, sizeof(b));")
-        else:
+        if not self.const:
             block.writeline("%s = -1;%s" % (star_p1, comment3))
         t1 = block.add_crx_type_var()
         if self.is_integer_type():
@@ -148,11 +147,8 @@
                     ampersand_star_p1 = ampersand_star_p1[2:]
                 block.writeline("if ((void *)%s == (void *)%s) {" % (
                     ampersand_star_p1, star_p1))
-                block.writeline("    r = r0;")
-                block.sprintf(r"#error %s\n" % errmsg, indent=4)
-                block.tr.need_return_value()
-                block.writeline("    r1 = -1;")
-                block.writeline("    goto %s;" % block.get_skip_label())
+                block.writeline('    cb->error(cb, "%s");' % (errmsg,))
+                block.writeline("    return;")
                 block.writeline("}")
             inspect.after_star_p1_assignment.append(after)
         inspect.levels.append('*')
diff --git a/test/codegen/006.c b/test/codegen/006.c
--- a/test/codegen/006.c
+++ b/test/codegen/006.c
@@ -1,50 +1,19 @@
 typedef const unsigned int num_t;
 
 # ____________________________________________________________
-#include <string.h>
 
-int test006(char *r)
+void test006(crx_builder_t *cb)
 {
-    if (!r)
-        return 14 + 18 + 9;
+    crx_type_t *t1, *t2;
     {
         num_t *p1;
         char b[sizeof(*p1)];
         memset(b, -1, sizeof(b));
         p1 = (void *)b;
         (void)(*p1 << 1);  /* check that 'num_t' is an integer type */
-        r += sprintf(r, "typedef const ");
-        if (*p1 > 0) {
-            if (sizeof(*p1) == 1 && *p1 == 1)
-                r += sprintf(r, "_Bool");
-            else if (sizeof(*p1) == sizeof(unsigned int))
-                r += sprintf(r, "unsigned int");
-            else if (sizeof(*p1) == sizeof(unsigned short))
-                r += sprintf(r, "unsigned short");
-            else if (sizeof(*p1) == sizeof(unsigned char))
-                r += sprintf(r, "unsigned char");
-            else if (sizeof(*p1) == sizeof(unsigned long))
-                r += sprintf(r, "unsigned long");
-            else if (sizeof(*p1) == sizeof(unsigned long long))
-                r += sprintf(r, "unsigned long long");
-            else
-                r += sprintf(r, "uint%u_t", (int)sizeof(*p1) * 8);
-        }
-        else {
-            if (sizeof(*p1) == sizeof(int))
-                r += sprintf(r, "int");
-            else if (sizeof(*p1) == sizeof(short))
-                r += sprintf(r, "short");
-            else if (sizeof(*p1) == sizeof(signed char))
-                r += sprintf(r, "signed char");
-            else if (sizeof(*p1) == sizeof(long))
-                r += sprintf(r, "long");
-            else if (sizeof(*p1) == sizeof(long long))
-                r += sprintf(r, "long long");
-            else
-                r += sprintf(r, "int%u_t", (int)sizeof(*p1) * 8);
-        }
-        r += sprintf(r, " num_t;\n");
+        t1 = CRX_INT_TYPE(cb, *p1, "unsigned int");
+        t2 = cb->get_const_type(cb, t1);
+        cb->define_type(cb, "num_t", t2);
+#expect TYPEDEF num_t = CONST unsigned int
     }
-    return 0;
 }
diff --git a/test/codegen/006b.c b/test/codegen/006b.c
--- a/test/codegen/006b.c
+++ b/test/codegen/006b.c
@@ -2,59 +2,25 @@
 
 # ____________________________________________________________
 
-int test006b(char *r)
+void test006b(crx_builder_t *cb)
 {
-    int r1 = 0;
-    if (!r)
-        return 57 + 8 + 18 + 16;
+    crx_type_t *t1, *t2, *t3;
     {
         num_t *p1;
         char *p2;
         char b[sizeof(**p1)];  /* check that '*num_t' is a valid type */
-        char *r0 = r;
         p1 = (void *)&p2;
         p2 = (void *)b;
         if ((void *)p1 == (void *)*p1) {
-            r = r0;
-            r += sprintf(r, "#error type 'num_t' is not a pointer, but an array type\n");
-            r1 = -1;
-            goto f2;
+            cb->error(cb, "type 'num_t' is not a pointer, but an array type");
+            return;
         }
         (void)(**p1 << 1);  /* check that '*num_t' is an integer type */
-        r += sprintf(r, "typedef ");
         **p1 = -1;  /* check that '*num_t' is not declared 'const' */
-        if (**p1 > 0) {
-            if (sizeof(**p1) == 1 && **p1 == 1)
-                r += sprintf(r, "_Bool");
-            else if (sizeof(**p1) == sizeof(unsigned int))
-                r += sprintf(r, "unsigned int");
-            else if (sizeof(**p1) == sizeof(unsigned short))
-                r += sprintf(r, "unsigned short");
-            else if (sizeof(**p1) == sizeof(unsigned char))
-                r += sprintf(r, "unsigned char");
-            else if (sizeof(**p1) == sizeof(unsigned long))
-                r += sprintf(r, "unsigned long");
-            else if (sizeof(**p1) == sizeof(unsigned long long))
-                r += sprintf(r, "unsigned long long");
-            else
-                r += sprintf(r, "uint%u_t", (int)sizeof(**p1) * 8);
-        }
-        else {
-            if (sizeof(**p1) == sizeof(int))
-                r += sprintf(r, "int");
-            else if (sizeof(**p1) == sizeof(short))
-                r += sprintf(r, "short");
-            else if (sizeof(**p1) == sizeof(signed char))
-                r += sprintf(r, "signed char");
-            else if (sizeof(**p1) == sizeof(long))
-                r += sprintf(r, "long");
-            else if (sizeof(**p1) == sizeof(long long))
-                r += sprintf(r, "long long");
-            else
-                r += sprintf(r, "int%u_t", (int)sizeof(**p1) * 8);
-        }
-        r += sprintf(r, " *const num_t;\n");
-        f2:;
+        t1 = CRX_INT_TYPE(cb, **p1, "int");
+        t2 = cb->get_pointer_type(cb, t1);
+        t3 = cb->get_const_type(cb, t2);
+        cb->define_type(cb, "num_t", t3);
+#expect TYPEDEF num_t = CONST PTR int
     }
-    return r1;
 }


More information about the pypy-commit mailing list