[Mesa-dev] [PATCH 08/10] mapi_abi: Override 'hidden' and 'handcode' attributes using polymorphism.

Paul Berry stereotype441 at gmail.com
Fri Oct 12 12:53:37 PDT 2012


Previously, the ES1, ES2, and shared GLAPI printers passed a list of
function names to the base class constructor, which was used by the
_override_for_api() function to loop over all the API functions and
adjust their 'hidden' and 'handcode' attributes as appropriate for the
API flavour being code-generated.

This patch lifts the loop from _override_for_api() into its caller,
and makes it into a polymorphic function, so that the derived classes
can customize its behaviour directly.  In a future patch, this will
allow us to override the 'hidden' and 'handcode' attributes based on
information from the XML rather than a list of functions.
---
 src/mapi/mapi/mapi_abi.py | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/mapi/mapi/mapi_abi.py b/src/mapi/mapi/mapi_abi.py
index c2d9085..b1b08a2 100644
--- a/src/mapi/mapi/mapi_abi.py
+++ b/src/mapi/mapi/mapi_abi.py
@@ -688,8 +688,9 @@ class ABIPrinter(object):
 class GLAPIPrinter(ABIPrinter):
     """OpenGL API Printer"""
 
-    def __init__(self, entries, api=None):
-        self._override_for_api(entries, api)
+    def __init__(self, entries):
+        for ent in entries:
+            self._override_for_api(ent)
         super(GLAPIPrinter, self).__init__(entries)
 
         self.api_defines = ['GL_GLEXT_PROTOTYPES']
@@ -711,16 +712,11 @@ class GLAPIPrinter(ABIPrinter):
 
         self.c_header = self._get_c_header()
 
-    def _override_for_api(self, entries, api):
-        """Override the entry attributes according to API."""
-        # no override
-        if api is None:
-            return entries
-
-        for ent in entries:
-            # override 'hidden' and 'handcode'
-            ent.hidden = ent.name not in api
-            ent.handcode = False
+    def _override_for_api(self, ent):
+        """Override attributes of an entry if necessary for this
+        printer."""
+        # By default, no override is necessary.
+        pass
 
     def _get_c_header(self):
         header = """#ifndef _GLAPI_TMP_H_
@@ -743,10 +739,14 @@ class ES1APIPrinter(GLAPIPrinter):
     """OpenGL ES 1.x API Printer"""
 
     def __init__(self, entries):
-        super(ES1APIPrinter, self).__init__(entries, es1_api)
+        super(ES1APIPrinter, self).__init__(entries)
         self.prefix_lib = 'gl'
         self.prefix_warn = 'gl'
 
+    def _override_for_api(self, ent):
+        ent.hidden = ent.name not in es1_api
+        ent.handcode = False
+
     def _get_c_header(self):
         header = """#ifndef _GLAPI_TMP_H_
 #define _GLAPI_TMP_H_
@@ -760,10 +760,14 @@ class ES2APIPrinter(GLAPIPrinter):
     """OpenGL ES 2.x API Printer"""
 
     def __init__(self, entries):
-        super(ES2APIPrinter, self).__init__(entries, es2_api)
+        super(ES2APIPrinter, self).__init__(entries)
         self.prefix_lib = 'gl'
         self.prefix_warn = 'gl'
 
+    def _override_for_api(self, ent):
+        ent.hidden = ent.name not in es2_api
+        ent.handcode = False
+
     def _get_c_header(self):
         header = """#ifndef _GLAPI_TMP_H_
 #define _GLAPI_TMP_H_
@@ -777,7 +781,7 @@ class SharedGLAPIPrinter(GLAPIPrinter):
     """Shared GLAPI API Printer"""
 
     def __init__(self, entries):
-        super(SharedGLAPIPrinter, self).__init__(entries, [])
+        super(SharedGLAPIPrinter, self).__init__(entries)
 
         self.lib_need_table_size = True
         self.lib_need_noop_array = True
@@ -788,6 +792,10 @@ class SharedGLAPIPrinter(GLAPIPrinter):
         self.prefix_lib = 'shared'
         self.prefix_warn = 'gl'
 
+    def _override_for_api(self, ent):
+        ent.hidden = True
+        ent.handcode = False
+
     def _get_c_header(self):
         header = """#ifndef _GLAPI_TMP_H_
 #define _GLAPI_TMP_H_
-- 
1.7.12.2



More information about the mesa-dev mailing list