Small refactor. Move several utility functions from glX_XML.py to
authorIan Romanick <idr@us.ibm.com>
Tue, 1 Feb 2005 00:28:47 +0000 (00:28 +0000)
committerIan Romanick <idr@us.ibm.com>
Tue, 1 Feb 2005 00:28:47 +0000 (00:28 +0000)
FilterGLAPISpecBase (in gl_XML.py).  When these functions are used to emit
common #define lines, the will automatically be undefined in
FilterGLAPISpecBase::printFooter if header_tag is set (i.e., the file is a
header file).

These changes do not modify the generated code.

src/mesa/glapi/glX_XML.py
src/mesa/glapi/glX_proto_send.py
src/mesa/glapi/glX_proto_size.py
src/mesa/glapi/gl_XML.py

index 56a2113f0507a446b770a568d1ae5d75a0232aab..9a34111efe78ee5a0a82a8eec8453fcb964018e2 100644 (file)
@@ -34,39 +34,6 @@ import license
 import sys, getopt
 
 
-def printPure():
-       print """#  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
-#    define PURE __attribute__((pure))
-#  else
-#    define PURE
-#  endif"""
-
-def printFastcall():
-       print """#  if defined(__i386__) && defined(__GNUC__)
-#    define FASTCALL __attribute__((fastcall))
-#  else
-#    define FASTCALL
-#  endif"""
-
-def printVisibility(S, s):
-       print """#  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
-#    define %s  __attribute__((visibility("%s")))
-#  else
-#    define %s
-#  endif""" % (S, s, S)
-
-def printNoinline():
-       print """#  if defined(__GNUC__)
-#    define NOINLINE __attribute__((noinline))
-#  else
-#    define NOINLINE
-#  endif"""
-
-def printHaveAlias():
-       print """#  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-#    define HAVE_ALIAS
-#  endif"""
-
 class glXItemFactory(gl_XML.glItemFactory):
        """Factory to create GLX protocol oriented objects derived from glItem."""
     
index 146d6620790e878faba669f74e9fb443697eab1b..949a0c94334a70c576b9c4267a38c5f03ea4c7d1 100644 (file)
@@ -126,8 +126,8 @@ class PrintGlxProtoStubs(glX_XML.GlxProto):
                print ''
                print '#define __GLX_PAD(n) (((n) + 3) & ~3)'
                print ''
-               glX_XML.printFastcall()
-               glX_XML.printNoinline()
+               self.printFastcall()
+               self.printNoinline()
                print ''
                print '#if !defined __GNUC__ || __GNUC__ < 3'
                print '#  define __builtin_expect(x, y) x'
@@ -769,11 +769,7 @@ class PrintGlxProtoInit_h(glX_XML.GlxProto):
  * \\author Ian Romanick <idr@us.ibm.com>
  */
 """
-               glX_XML.printVisibility( "HIDDEN", "hidden" )
-
-
-       def printRealFooter(self):
-               print "#  undef HIDDEN"
+               self.printVisibility( "HIDDEN", "hidden" )
 
 
        def printFunction(self, f):
index e8a137c5e120a8ef1fec90261538e4d813245c9b..3030e7462b25acf90f53b1cfc937f683ac2dd16f 100644 (file)
@@ -170,13 +170,13 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
                print '#include "indirect_size.h"'
                
                print ''
-               glX_XML.printHaveAlias()
+               self.printHaveAlias()
                print ''
-               glX_XML.printPure()
+               self.printPure()
                print ''
-               glX_XML.printFastcall()
+               self.printFastcall()
                print ''
-               glX_XML.printVisibility( "INTERNAL", "internal" )
+               self.printVisibility( "INTERNAL", "internal" )
                print ''
                print ''
                print '#ifdef HAVE_ALIAS'
@@ -220,19 +220,13 @@ class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
  * \\author Ian Romanick <idr@us.ibm.com>
  */
 """
-               glX_XML.printPure();
+               self.printPure();
                print ''
-               glX_XML.printFastcall();
+               self.printFastcall();
                print ''
-               glX_XML.printVisibility( "INTERNAL", "internal" );
+               self.printVisibility( "INTERNAL", "internal" );
                print ''
 
-       def printRealFooter(self):
-               print ''
-               print "#  undef INTERNAL"
-               print "#  undef PURE"
-               print "#  undef FASTCALL"
-
 
        def printFunction(self, f):
                ef = self.glx_enum_functions[f.name]
@@ -250,16 +244,10 @@ class PrintGlxReqSize_h(glX_XML.GlxProto):
 
 
        def printRealHeader(self):
-               glX_XML.printVisibility("HIDDEN", "hidden")
-               print ''
-               glX_XML.printPure()
+               self.printVisibility("HIDDEN", "hidden")
                print ''
-
-
-       def printRealFooter(self):
+               self.printPure()
                print ''
-               print '#  undef HIDDEN'
-               print '#  undef PURE'
 
 
        def printFunction(self, f):
@@ -300,7 +288,7 @@ class PrintGlxReqSize_c(glX_XML.GlxProto):
                print ''
                print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
                print ''
-               glX_XML.printHaveAlias()
+               self.printHaveAlias()
                print ''
                print '#ifdef HAVE_ALIAS'
                print '#  define ALIAS2(from,to) \\'
index 086133cdf1e1c07d4ab4e7b6d2129d197722445f..1771975e843a228031cdff2a18ed3b0e73ed4bad 100644 (file)
@@ -509,6 +509,7 @@ class FilterGLAPISpecBase(saxutils.XMLFilterBase):
                self.xref = {}
                self.factory = glItemFactory()
                self.header_tag = None
+               self.undef_list = []
 
 
        def find_type(self,type_name):
@@ -558,8 +559,12 @@ class FilterGLAPISpecBase(saxutils.XMLFilterBase):
                self.printFunctions()
                self.printRealFooter()
                if self.header_tag:
-                   print ''
-                   print '#endif /* !defined( %s ) */' % (self.header_tag)
+                       if self.undef_list:
+                               print ''
+                               for u in self.undef_list:
+                                       print "#  undef %s" % (u)
+                       print ''
+                       print '#endif /* !defined( %s ) */' % (self.header_tag)
 
 
        def get_category_define(self):
@@ -625,6 +630,44 @@ class FilterGLAPISpecBase(saxutils.XMLFilterBase):
                return
 
 
+       def printPure(self):
+               self.undef_list.append("PURE")
+               print """#  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+#    define PURE __attribute__((pure))
+#  else
+#    define PURE
+#  endif"""
+
+       def printFastcall(self):
+               self.undef_list.append("FASTCALL")
+               print """#  if defined(__i386__) && defined(__GNUC__)
+#    define FASTCALL __attribute__((fastcall))
+#  else
+#    define FASTCALL
+#  endif"""
+
+       def printVisibility(self, S, s):
+               self.undef_list.append(S)
+               print """#  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+#    define %s  __attribute__((visibility("%s")))
+#  else
+#    define %s
+#  endif""" % (S, s, S)
+
+       def printNoinline(self):
+               self.undef_list.append("NOINLINE")
+               print """#  if defined(__GNUC__)
+#    define NOINLINE __attribute__((noinline))
+#  else
+#    define NOINLINE
+#  endif"""
+
+       def printHaveAlias(self):
+               self.undef_list.append("HAVE_ALIAS")
+               print """#  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+#    define HAVE_ALIAS
+#  endif"""
+
        def printFunction(self,offset):
                """Print a single function.