Author: Amaury Forgeot d'Arc <[email protected]>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r57723:ea51e86e4d9d
Date: 2012-10-01 23:54 +0200
http://bitbucket.org/pypy/pypy/changeset/ea51e86e4d9d/

Log:    Move the "preimpl" lines to their own file preimpl.h

        (provide well-known aliases to generated objects, e.g. #define
        RPyExc_TypeError
        (&pypy_g_exceptions_TypeError.te_super.se_super.e_super) )

diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -649,9 +649,8 @@
 class SourceGenerator:
     one_source_file = True
 
-    def __init__(self, database, preimplementationlines=[]):
+    def __init__(self, database):
         self.database = database
-        self.preimpl = preimplementationlines
         self.extrafiles = []
         self.path = None
         self.namespace = NameManager()
@@ -785,6 +784,8 @@
             gen_structdef(fi, self.database)
         with self.write_on_maybe_included_file(f, 'forwarddecl.h') as fi:
             gen_forwarddecl(fi, self.database)
+        with self.write_on_maybe_included_file(f, 'preimpl.h') as fi:
+            gen_preimpl(fi, self.database)
 
         #
         # Implementation of functions and global structures and arrays
@@ -795,8 +796,6 @@
         print >> f
 
         print >> f, '#define PYPY_FILE_NAME "%s"' % os.path.basename(f.name)
-        for line in self.preimpl:
-            print >> f, line
         print >> f, '#include "src/g_include.h"'
         print >> f
 
@@ -812,6 +811,7 @@
                     print >> fc, '#include "common_header.h"'
                     print >> fc, '#include "structdef.h"'
                     print >> fc, '#include "forwarddecl.h"'
+                    print >> fc, '#include "preimpl.h"'
                     print >> fc
                     print >> fc, '#include "src/g_include.h"'
                     print >> fc
@@ -821,7 +821,7 @@
                     print >> fc, MARKER
                 print >> fc, 
'/***********************************************************/'
 
-        nextralines = 8 + len(self.preimpl) + 4 + 1
+        nextralines = 12
         for name, nodeiter in self.splitnodesimpl('implement.c',
                                                    self.funcnodes,
                                                    nextralines, 1,
@@ -835,10 +835,7 @@
                     print >> fc, '#include "common_header.h"'
                     print >> fc, '#include "structdef.h"'
                     print >> fc, '#include "forwarddecl.h"'
-                    print >> fc
-                    for line in self.preimpl:
-                        print >> fc, line
-                    print >> fc
+                    print >> fc, '#include "preimpl.h"'
                     print >> fc, '#include "src/g_include.h"'
                     print >> fc
                 print >> fc, MARKER
@@ -873,6 +870,14 @@
         for line in node.forward_declaration():
             print >> f, line
 
+def gen_preimpl(f, database):
+    if database.translator is None or database.translator.rtyper is None:
+        return
+    preimplementationlines = pre_include_code_lines(
+        database, database.translator.rtyper)
+    for line in preimplementationlines:
+        print >> f, line
+
 def gen_startupcode(f, database):
     # generate the start-up code and put it into a function
     print >> f, 'char *RPython_StartupCode(void) {'
@@ -945,17 +950,11 @@
 
     fi.close()
 
-    if database.translator is None or database.translator.rtyper is None:
-        preimplementationlines = []
-    else:
-        preimplementationlines = list(
-            pre_include_code_lines(database, database.translator.rtyper))
-
     #
     # 1) All declarations
     # 2) Implementation of functions and global structures and arrays
     #
-    sg = SourceGenerator(database, preimplementationlines)
+    sg = SourceGenerator(database)
     sg.set_strategy(targetdir, split)
     database.prepare_inline_helpers()
     sg.gen_readable_parts_of_source(f)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to