[Mesa-dev] [PATCH 2/6] glapi: add methods to filter functions

Chia-I Wu olvaffe at gmail.com
Thu Aug 11 02:45:22 PDT 2011


From: Chia-I Wu <olv at lunarg.com>

add gl_api::filter_functions and gl_function::filter_entry_points to
filter out unwanted functions and entry points.
---
 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
-- 
1.7.5.4



More information about the mesa-dev mailing list