Author: Armin Rigo <[email protected]>
Branch:
Changeset: r131:f96272960996
Date: 2014-11-30 23:15 +0100
http://bitbucket.org/cffi/creflect/changeset/f96272960996/
Log: progress
diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -121,16 +121,15 @@
assert isinstance(qualtp.type, model.FunctionType)
self.declarations.append(model.FuncDecl(decl.name, qualtp))
else:
- const = 'const' in decl.quals
if isinstance(node, pycparser.c_ast.Struct):
if node.decls is not None:
- self.get_struct_union_enum_type('struct', node, const)
+ self.get_struct_union_enum_type('struct', node)
elif isinstance(node, pycparser.c_ast.Union):
if node.decls is not None:
- self.get_struct_union_enum_type('union', node, const)
+ self.get_struct_union_enum_type('union', node)
elif isinstance(node, pycparser.c_ast.Enum):
if node.values is not None:
- self.get_struct_union_enum_type('enum', node, const)
+ self.get_struct_union_enum_type('enum', node)
elif not decl.name:
raise api.CDefError("construct does not declare any variable",
decl)
@@ -184,27 +183,29 @@
quals_num(typenode.quals))
#
if isinstance(typenode, pycparser.c_ast.TypeDecl):
- const = 'const' in typenode.quals
type = typenode.type
+ realtype = None
if isinstance(type, pycparser.c_ast.IdentifierType):
# assume a primitive type.
realtype = resolve_common_type(type.names)
- return model.QualType(realtype, quals_num(typenode.quals))
#
if isinstance(type, pycparser.c_ast.Struct):
# 'struct foobar'
- return self.get_struct_union_enum_type('struct', type, const,
- approx_name)
+ realtype = self.get_struct_union_enum_type('struct', type,
+ approx_name)
#
if isinstance(type, pycparser.c_ast.Union):
# 'union foobar'
- return self.get_struct_union_enum_type('union', type, const,
- approx_name)
+ realtype = self.get_struct_union_enum_type('union', type,
+ approx_name)
#
if isinstance(type, pycparser.c_ast.Enum):
# 'enum foobar'
- return self.get_struct_union_enum_type('enum', type, const,
- approx_name)
+ realtype = self.get_struct_union_enum_type('enum', type,
+ approx_name)
+
+ if realtype is not None:
+ return model.QualType(realtype, quals_num(typenode.quals))
#
if isinstance(typenode, pycparser.c_ast.FuncDecl):
# a function type (it is never qualified)
@@ -213,10 +214,10 @@
#
# nested anonymous structs or unions end up here
if isinstance(typenode, pycparser.c_ast.Struct):
- return self.get_struct_union_enum_type('struct', typenode, const,
+ return self.get_struct_union_enum_type('struct', typenode,
name, nested=True)
if isinstance(typenode, pycparser.c_ast.Union):
- return self.get_struct_union_enum_type('union', typenode, const,
+ return self.get_struct_union_enum_type('union', typenode,
name, nested=True)
#
raise api.FFIError(":%d: bad or unsupported type declaration" %
@@ -253,13 +254,13 @@
return 'const' in typenode.quals
return False
- def get_struct_union_enum_type(self, kind, type, const, approx_name=None):
+ def get_struct_union_enum_type(self, kind, type, approx_name=None):
name = type.name or approx_name
if not name or name.startswith('$$$'):
self.parse_error("not implemented: anonymous 'struct' elsewhere "
"than in 'typedef struct { ... } typename;' or "
"'typedef struct { ... } *typename;'", type)
- result = model.StructOrUnionOrEnum(kind, name, const)
+ result = model.StructOrUnionOrEnum(kind, name)
#
# get the type declaration or create it if needed
key = '%s %s' % (kind, name)
@@ -289,7 +290,7 @@
if typedecl.fldnames is not None:
raise api.CDefError("duplicate declaration of struct %s" % name)
fldnames = []
- fldtypes = []
+ fldqualtypes = []
fldbitsize = []
if len(fields) == 1 and fields[0].name == '__crx_empty__':
fields = []
@@ -298,17 +299,12 @@
bitsize = -1
else:
bitsize = self.parse_constant(decl.bitsize)
- self.partial_length = False
- type = self.get_type(decl.type)
- if self.partial_length:
- self.make_partial(tp, nested)
- #if isinstance(type, model.StructType) and type.partial:
- # self.make_partial(tp, nested)
+ qualtype = self.get_qualtype(decl.type)
fldnames.append(decl.name or '')
- fldtypes.append(type)
+ fldqualtypes.append(qualtype)
fldbitsize.append(bitsize)
typedecl.fldnames = tuple(fldnames)
- typedecl.fldtypes = tuple(fldtypes)
+ typedecl.fldqualtypes = tuple(fldqualtypes)
typedecl.fldbitsize = tuple(fldbitsize)
if fldbitsize != [-1] * len(fldbitsize):
xxxx
diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -472,8 +472,6 @@
self.kind = kind
self.name = name
self.c_name_with_marker = '%s %s &' % (self.kind, self.name)
- if const:
- self.c_name_with_marker = 'const ' + self.c_name_with_marker
def get_type_var(self, block):
return block.write_crx_type_var('cb->get_%s_type(cb, "%s")' % (
@@ -643,7 +641,7 @@
def __init__(self, type):
self.type = type
self.fldnames = None
- self.fldtypes = None
+ self.fldqualtypes = None
self.fldbitsize = None
def write_declaration(self, funcblock):
@@ -677,14 +675,14 @@
d1 = 'NULL'
t1 = self.type.get_type_var(funcblock)
#
- for i, (fldname, fldtype) in enumerate(
- zip(self.fldnames, self.fldtypes)):
+ for i, (fldname, fldqualtype) in enumerate(
+ zip(self.fldnames, self.fldqualtypes)):
block = CodeBlock(funcblock)
inspect = TypeInspector(block, insptp, fldname)
inspect.start()
# get the offset of the field
arraylevels = 0
- checktype = fldtype
+ checktype = fldqualtype.type
while isinstance(checktype, ArrayType):
arraylevels += 1
checktype = checktype.item
@@ -700,7 +698,7 @@
o_decl = ("size_t o = ((char *)&((%s)0)->%s)"
" - (char *)0;%s" % (ptrtp, fldname, comment))
#
- t2, q2 = fldtype.inspect_type(block, inspect)
+ t2, q2 = fldqualtype.inspect_qualtype(block, inspect)
inspect.stop()
block.writedecl(o_decl)
block.writeline('%s[%d].name = "%s";' % (d1, i, fldname))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit