Commit bba66f99 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

More fine-grained type declaration (makes new buffmt work in C++)

parent f397ad40
...@@ -607,6 +607,8 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth): ...@@ -607,6 +607,8 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth):
if dtype.is_error: return if dtype.is_error: return
complex_possible = dtype.is_struct_or_union and dtype.can_be_complex() complex_possible = dtype.is_struct_or_union and dtype.can_be_complex()
code = proto.globalstate['typeinfo']
if maxdepth <= 0: if maxdepth <= 0:
assert False assert False
...@@ -620,12 +622,12 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth): ...@@ -620,12 +622,12 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth):
assert len(fields) > 0 assert len(fields) > 0
types = [get_type_information_cname(proto, f.type, maxdepth - 1) types = [get_type_information_cname(proto, f.type, maxdepth - 1)
for f in fields] for f in fields]
impl.putln("static __Pyx_StructField %s[] = {" % structinfo_name, safe=True) code.putln("static __Pyx_StructField %s[] = {" % structinfo_name, safe=True)
for f, typeinfo in zip(fields, types): for f, typeinfo in zip(fields, types):
impl.putln(' {&%s, "%s", offsetof(%s, %s)},' % code.putln(' {&%s, "%s", offsetof(%s, %s)},' %
(typeinfo, f.name, dtype.declaration_code(""), f.cname), safe=True) (typeinfo, f.name, dtype.declaration_code(""), f.cname), safe=True)
impl.putln(' {NULL, NULL, 0}', safe=True) code.putln(' {NULL, NULL, 0}', safe=True)
impl.putln("};", safe=True) code.putln("};", safe=True)
else: else:
assert False assert False
...@@ -647,8 +649,7 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth): ...@@ -647,8 +649,7 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth):
print dtype print dtype
assert False assert False
proto.putln('static __Pyx_TypeInfo %s;' % name) code.putln(('static __Pyx_TypeInfo %s = { "%s", %s, sizeof(%s), \'%s\' };'
impl.putln(('static __Pyx_TypeInfo %s = { "%s", %s, sizeof(%s), \'%s\' };'
) % (name, ) % (name,
rep, rep,
structinfo_name, structinfo_name,
......
...@@ -230,15 +230,12 @@ class GlobalState(object): ...@@ -230,15 +230,12 @@ class GlobalState(object):
code_layout = [ code_layout = [
'h_code', 'h_code',
'type_declarations',
'module_declarations',
'typeinfo',
'before_global_var', 'before_global_var',
'global_var', 'global_var',
'after_global_var', 'all_the_rest',
'utility_proto',
'pystring_table',
'init_cached_builtins',
'init',
'utility_def',
] ]
......
...@@ -271,7 +271,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -271,7 +271,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_interned_string_decls(env, code) self.generate_interned_string_decls(env, code)
self.generate_py_string_decls(env, code) self.generate_py_string_decls(env, code)
code = globalstate['after_global_var'] code = globalstate['all_the_rest']
self.generate_cached_builtins_decls(env, code) self.generate_cached_builtins_decls(env, code)
self.body.generate_function_definitions(env, code) self.body.generate_function_definitions(env, code)
...@@ -290,7 +290,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -290,7 +290,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_filename_table(code) self.generate_filename_table(code)
self.generate_utility_functions(env, code, h_code) self.generate_utility_functions(env, code, h_code)
self.generate_declarations_for_modules(env, modules, h_code) self.generate_declarations_for_modules(env, modules, globalstate)
h_code.write('\n') h_code.write('\n')
globalstate.close_global_decls() globalstate.close_global_decls()
...@@ -399,18 +399,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -399,18 +399,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_exttype_vtable_struct(entry, code) self.generate_exttype_vtable_struct(entry, code)
self.generate_exttype_vtabptr_declaration(entry, code) self.generate_exttype_vtabptr_declaration(entry, code)
def generate_declarations_for_modules(self, env, modules, code): def generate_declarations_for_modules(self, env, modules, globalstate):
code.putln("") typecode = globalstate['type_declarations']
code.putln("/* Type declarations */") typecode.putln("")
typecode.putln("/* Type declarations */")
vtab_list, vtabslot_list = self.sort_type_hierarchy(modules, env) vtab_list, vtabslot_list = self.sort_type_hierarchy(modules, env)
self.generate_type_definitions( self.generate_type_definitions(
env, modules, vtab_list, vtabslot_list, code) env, modules, vtab_list, vtabslot_list, typecode)
modulecode = globalstate['module_declarations']
for module in modules: for module in modules:
defined_here = module is env defined_here = module is env
code.putln("/* Module declarations from %s */" % modulecode.putln("/* Module declarations from %s */" %
module.qualified_name.encode("ASCII", "ignore")) module.qualified_name.encode("ASCII", "ignore"))
self.generate_global_declarations(module, code, defined_here) self.generate_global_declarations(module, modulecode, defined_here)
self.generate_cfunction_predeclarations(module, code, defined_here) self.generate_cfunction_predeclarations(module, modulecode, defined_here)
def generate_module_preamble(self, env, cimported_modules, code): def generate_module_preamble(self, env, cimported_modules, code):
code.putln('/* Generated by Cython %s on %s */' % ( code.putln('/* Generated by Cython %s on %s */' % (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment