Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / glapi / gl_enums.py
index 615f79729cf2f2a8ffbfbfb3c641b5aff687bb6a..67fec7968a97d56b8900cf0dbc01321f771184c6 100644 (file)
@@ -30,11 +30,12 @@ import license
 import gl_XML
 import sys, getopt
 
-class PrintGlEnums(gl_XML.FilterGLAPISpecBase):
-       name = "gl_enums.py (from Mesa)"
+class PrintGlEnums(gl_XML.gl_print_base):
 
        def __init__(self):
-               gl_XML.FilterGLAPISpecBase.__init__(self)
+               gl_XML.gl_print_base.__init__(self)
+
+               self.name = "gl_enums.py (from Mesa)"
                self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2005 Brian Paul All Rights Reserved.""", "BRIAN PAUL")
                self.enum_table = {}
@@ -52,7 +53,7 @@ class PrintGlEnums(gl_XML.FilterGLAPISpecBase):
                print ''
                return
 
-       def printBody(self):
+       def print_code(self):
                print """
 #define Elements(x) sizeof(x)/sizeof(*x)
 
@@ -95,8 +96,10 @@ const char *_mesa_lookup_enum_by_nr( int nr )
 {
    unsigned * i;
 
-   i = (unsigned *)bsearch( & nr, reduced_enums, Elements(reduced_enums),
-                            sizeof(reduced_enums[0]), (cfunc) compar_nr );
+   i = (unsigned *) _mesa_bsearch(& nr, reduced_enums,
+                                  Elements(reduced_enums),
+                                  sizeof(reduced_enums[0]),
+                                  (cfunc) compar_nr);
 
    if ( i != NULL ) {
       return & enum_string_table[ all_enums[ *i ].offset ];
@@ -113,8 +116,10 @@ int _mesa_lookup_enum_by_name( const char *symbol )
    enum_elt * f = NULL;
 
    if ( symbol != NULL ) {
-      f = (enum_elt *)bsearch( symbol, all_enums, Elements(all_enums),
-                              sizeof( enum_elt ), (cfunc) compar_name );
+      f = (enum_elt *) _mesa_bsearch(symbol, all_enums,
+                                     Elements(all_enums),
+                                     sizeof( enum_elt ),
+                                     (cfunc) compar_name);
    }
 
    return (f != NULL) ? f->n : -1;
@@ -123,7 +128,10 @@ int _mesa_lookup_enum_by_name( const char *symbol )
 """
                return
 
-       def printFunctions(self):
+
+       def printBody(self, api):
+               self.process_enums( api )
+
                keys = self.enum_table.keys()
                keys.sort()
 
@@ -144,7 +152,7 @@ int _mesa_lookup_enum_by_name( const char *symbol )
 
                string_offsets = {}
                i = 0;
-               print 'static const char enum_string_table[] = '
+               print 'LONGSTRING static const char enum_string_table[] = '
                for [name, enum] in name_table:
                        print '   "%s\\0"' % (name)
                        string_offsets[ name ] = i
@@ -157,7 +165,7 @@ int _mesa_lookup_enum_by_name( const char *symbol )
                print 'static const enum_elt all_enums[%u] =' % (len(name_table))
                print '{'
                for [name, enum] in name_table:
-                       print '   { % 5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name)
+                       print '   { %5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name)
                print '};'
                print ''
 
@@ -170,48 +178,25 @@ int _mesa_lookup_enum_by_name( const char *symbol )
                        else:
                                i = name_table.index( [name, enum] )
 
-                               print '      % 4u, /* %s */' % (i, name)
+                               print '      %4u, /* %s */' % (i, name)
                print '};'
 
 
-               self.printBody();
+               self.print_code()
                return
 
 
-       def append(self, object_type, obj):
-               if object_type == "enum":
+       def process_enums(self, api):
+               self.enum_table = {}
+               
+               for obj in api.enumIterateByName():
                        if obj.value not in self.enum_table:
                                self.enum_table[ obj.value ] = []
 
 
-                       # Prevent duplicate names in the enum table.
-
-                       if obj.name not in self.enum_table[ obj.value ]:
-
-                               # Calculate a "priority" for this enum name.
-                               # When we lookup an enum by number, there may
-                               # be many possible names, but only one can be
-                               # returned.  The priority is used by this
-                               # script to select which name is the "best".
-                               #
-                               # Highest precedence is given to "core" name.
-                               # ARB extension names have the next highest,
-                               # followed by EXT extension names.  Vendor
-                               # extension names are the lowest.
-
-                               if obj.category.startswith( "GL_VERSION_" ):
-                                       priority = 0
-                               elif obj.category.startswith( "GL_ARB_" ):
-                                       priority = 1
-                               elif obj.category.startswith( "GL_EXT_" ):
-                                       priority = 2
-                               else:
-                                       priority = 3
-
-                               self.enum_table[ obj.value ].append( [obj.name, priority] )
-
-               else:
-                       gl_XML.FilterGLAPISpecBase.append(self, object_type, obj)
+                       name = "GL_" + obj.name
+                       priority = obj.priority()
+                       self.enum_table[ obj.value ].append( [name, priority] )
 
 
 def show_usage():
@@ -230,5 +215,7 @@ if __name__ == '__main__':
                if arg == "-f":
                        file_name = val
 
-       dh = PrintGlEnums()
-       gl_XML.parse_GL_API( dh, file_name )
+       api = gl_XML.parse_GL_API( file_name )
+
+       printer = PrintGlEnums()
+       printer.Print( api )