Mesa (master): glapi: add methods to filter functions

Chia-I Wu olv at kemper.freedesktop.org
Sat Aug 13 00:14:39 PDT 2011


Module: Mesa
Branch: master
Commit: b8202b3d44b18a3db281c64d1ca01e851ae6deb1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8202b3d44b18a3db281c64d1ca01e851ae6deb1

Author: Chia-I Wu <olv at lunarg.com>
Date:   Sun Aug  7 23:19:51 2011 +0900

glapi: add methods to filter functions

add gl_api::filter_functions and gl_function::filter_entry_points to
filter out unwanted functions and entry points.

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mapi/glapi/gen/gl_XML.py |   46 +++++++++++++++++++++++++++++++++++------
 1 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
index 4d414e8..4dc2e8f 100644
--- a/src/mapi/glapi/gen/gl_XML.py
+++ b/src/mapi/glapi/gen/gl_XML.py
@@ -618,7 +618,7 @@ class gl_function( gl_item ):
 		# for each entry-point.  Otherwise, they may generate code
 		# that won't compile.
 
-		self.parameter_strings = {}
+		self.entry_point_parameters = {}
 
 		self.process_element( element )
 
@@ -703,12 +703,34 @@ class gl_function( gl_item ):
 
 		if element.children:
 			self.initialized = 1
-			self.parameter_strings[name] = create_parameter_string(parameters, 1)
+			self.entry_point_parameters[name] = parameters
 		else:
-			self.parameter_strings[name] = None
+			self.entry_point_parameters[name] = []
 
 		return
 
+	def filter_entry_points(self, entry_point_list):
+		"""Filter out entry points not in entry_point_list."""
+		if not self.initialized:
+			raise RuntimeError('%s is not initialized yet' % self.name)
+
+		entry_points = []
+		for ent in self.entry_points:
+			if ent not in entry_point_list:
+				if ent in self.static_entry_points:
+					self.static_entry_points.remove(ent)
+				self.entry_point_parameters.pop(ent)
+			else:
+				entry_points.append(ent)
+
+		if not entry_points:
+			raise RuntimeError('%s has no entry point after filtering' % self.name)
+
+		self.entry_points = entry_points
+		if self.name not in entry_points:
+			# use the first remaining entry point
+			self.name = entry_points[0]
+			self.parameters = self.entry_point_parameters[entry_points[0]]
 
 	def get_images(self):
 		"""Return potentially empty list of input images."""
@@ -721,11 +743,11 @@ class gl_function( gl_item ):
 
 	def get_parameter_string(self, entrypoint = None):
 		if entrypoint:
-			s = self.parameter_strings[ entrypoint ]
-			if s:
-				return s
+			params = self.entry_point_parameters[ entrypoint ]
+		else:
+			params = self.parameters
 		
-		return create_parameter_string( self.parameters, 1 )
+		return create_parameter_string( params, 1 )
 
 	def get_called_parameter_string(self):
 		p_string = ""
@@ -791,6 +813,16 @@ class gl_api:
 		typeexpr.create_initial_types()
 		return
 
+	def filter_functions(self, entry_point_list):
+		"""Filter out entry points not in entry_point_list."""
+		functions_by_name = {}
+		for func in self.functions_by_name.itervalues():
+			entry_points = [ent for ent in func.entry_points if ent in entry_point_list]
+			if entry_points:
+				func.filter_entry_points(entry_points)
+				functions_by_name[func.name] = func
+
+		self.functions_by_name = functions_by_name
 
 	def process_element(self, doc):
 		element = doc.children



More information about the mesa-commit mailing list