1. Pypy
  2. Untitled project
  3. pypy

Commits

Amaury Forgeot d'Arc  committed ea51e86

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)
)

  • Participants
  • Parent commits 72618a2
  • Branches remove-PYPY_NOT_MAIN_FILE

Comments (0)

Files changed (1)

File pypy/translator/c/genc.py

View file
  • Ignore whitespace
 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()
             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
         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
 
                     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
                     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,
                     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
         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) {'
 
     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)