[pypy-commit] creflect default: Fix more tests

arigo noreply at buildbot.pypy.org
Mon Nov 17 22:28:46 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r54:cbf8158d85b4
Date: 2014-11-17 22:29 +0100
http://bitbucket.org/cffi/creflect/changeset/cbf8158d85b4/

Log:	Fix more tests

diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -15,6 +15,15 @@
                 for name in (self._attrs_ + 'const')]
 
     def inspect_type(self, block, inspect):
+        t1 = self.inspect_nonconst_type(block, inspect)
+        if self.const:
+            t2 = block.add_crx_type_var()
+            block.writeline('%s = cb->get_const_type(cb, %s);' % (t2, t1))
+            return t2
+        else:
+            return t1
+
+    def inspect_nonconst_type(self, block, inspect):
         raise NotImplementedError
 
     def __eq__(self, other):
@@ -35,7 +44,7 @@
         self.const = const
         self.c_name_with_marker = 'void &'
 
-    def inspect_type(self, block, inspect):
+    def inspect_nonconst_type(self, block, inspect):
         if inspect.started:
             inspect.assign_to_p1('0')
         t1 = block.add_crx_type_var()
@@ -82,7 +91,7 @@
     def is_float_type(self):
         return self.ALL_PRIMITIVE_TYPES[self.name] == 'f'
 
-    def inspect_type(self, block, inspect):
+    def inspect_nonconst_type(self, block, inspect):
         star_p1 = inspect.fetch_star_p1()
         comment1 = inspect.get_comment(0, False, "a valid type", minlevel=1)
         comment2 = inspect.get_comment(0, False, "an integer type")
@@ -116,21 +125,14 @@
 
 class PointerType(BaseType):
     _attrs_ = ('totype',)
-    _base_pattern       = {
-        (False, False): "*&",
-        (True, False): "(*&)",
-        (False, True): "*const &",
-        (True, True): "(*const &)",
-        }
 
     def __init__(self, totype, const):
         self.totype = totype
         self.const = const
         base = self.totype.c_name_with_marker
-        extra = self._base_pattern[self.totype.is_array_type, self.const]
-        self.c_name_with_marker = base.replace('&', extra)
+        self.c_name_with_marker = base.replace('&', '(*&)')
 
-    def inspect_type(self, block, inspect):
+    def inspect_nonconst_type(self, block, inspect):
         star_p1 = inspect.fetch_star_p1()
         new_var = 'p%d' % (len(inspect.levels) + 2,)
         block.writedecl("char *%s;" % (new_var,))
@@ -154,10 +156,10 @@
                 block.writeline("}")
             inspect.after_star_p1_assignment.append(after)
         inspect.levels.append('*')
-        self.totype.inspect_type(block, inspect)
-        #
-        extra = self._base_pattern[self.totype.is_array_type, self.const]
-        #block.sprintf_add_both_sides(extra)
+        t1 = self.totype.inspect_type(block, inspect)
+        t2 = block.add_crx_type_var()
+        block.writeline('%s = cb->get_pointer_type(cb, %s);' % (t2, t1))
+        return t2
 
 
 class ArrayType(BaseType):
@@ -178,7 +180,7 @@
         self.c_name_with_marker = (
             self.item.c_name_with_marker.replace('&', brackets))
 
-    def inspect_type(self, block, inspect):
+    def inspect_nonconst_type(self, block, inspect):
         star_p1 = inspect.fetch_star_p1()
         errmsg = "type '%s' is not an array, but a pointer type" % (
             inspect.get_comment_type(0, False),)


More information about the pypy-commit mailing list