Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 3 | # (C) Copyright IBM Corporation 2004, 2005 |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | # copy of this software and associated documentation files (the "Software"), |
| 8 | # to deal in the Software without restriction, including without limitation |
| 9 | # on the rights to use, copy, modify, merge, publish, distribute, sub |
| 10 | # license, and/or sell copies of the Software, and to permit persons to whom |
| 11 | # the Software is furnished to do so, subject to the following conditions: |
| 12 | # |
| 13 | # The above copyright notice and this permission notice (including the next |
| 14 | # paragraph) shall be included in all copies or substantial portions of the |
| 15 | # Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 20 | # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 23 | # IN THE SOFTWARE. |
| 24 | # |
| 25 | # Authors: |
| 26 | # Ian Romanick <idr@us.ibm.com> |
| 27 | |
| 28 | from xml.sax import saxutils |
| 29 | from xml.sax import make_parser |
| 30 | from xml.sax.handler import feature_namespaces |
| 31 | |
Brian Paul | 98fa2bf | 2004-10-28 21:11:02 +0000 | [diff] [blame] | 32 | import re |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 33 | |
Ian Romanick | 73b4c1b | 2005-04-14 23:00:34 +0000 | [diff] [blame] | 34 | def is_attr_true( attrs, name ): |
| 35 | """Read a name value from an element's attributes. |
| 36 | |
| 37 | The value read from the attribute list must be either 'true' or |
| 38 | 'false'. If the value is 'false', zero will be returned. If the |
| 39 | value is 'true', non-zero will be returned. An exception will be |
| 40 | raised for any other value.""" |
| 41 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 42 | value = attrs.get((None, name), "false") |
Ian Romanick | 73b4c1b | 2005-04-14 23:00:34 +0000 | [diff] [blame] | 43 | if value == "true": |
| 44 | return 1 |
| 45 | elif value == "false": |
| 46 | return 0 |
| 47 | else: |
| 48 | raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name)) |
| 49 | |
| 50 | |
Ian Romanick | 93d2d54 | 2005-04-18 19:42:23 +0000 | [diff] [blame^] | 51 | def parse_GL_API( handler, file_name ): |
| 52 | """Boiler-plate code to create an XML parser and use it. |
| 53 | |
| 54 | Creates an XML parser and uses that parser with the application |
| 55 | supplied SAX callback, which should be derived from |
| 56 | FilterGLAPISpecBase. |
| 57 | """ |
| 58 | parser = make_parser() |
| 59 | parser.setFeature(feature_namespaces, 1) |
| 60 | parser.setContentHandler( handler ) |
| 61 | |
| 62 | handler.printHeader() |
| 63 | parser.parse( file_name ) |
| 64 | |
| 65 | handler.printFooter() |
| 66 | return |
| 67 | |
| 68 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 69 | class glItem: |
| 70 | """Generic class on which all other API entity types are based.""" |
| 71 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 72 | def __init__(self, tag_name, name, context): |
| 73 | self.name = name |
| 74 | self.category = context.get_category_define() |
| 75 | self.context = context |
| 76 | self.tag_name = tag_name |
| 77 | |
| 78 | context.append(tag_name, self) |
| 79 | return |
| 80 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 81 | def startElementNS(self, name, qname, attrs): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 82 | """Generic startElement handler. |
| 83 | |
| 84 | The startElement handler is called for all elements except |
| 85 | the one that starts the object. For a foo element, the |
| 86 | XML "<foo><bar/></foo>" would cause the startElement handler |
| 87 | to be called once, but the endElement handler would be called |
| 88 | twice.""" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 89 | return |
| 90 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 91 | def endElementNS(self, name, qname): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 92 | """Generic endElement handler. |
| 93 | |
| 94 | Generic endElement handler. Returns 1 if the tag containing |
| 95 | the object is complete. Otherwise 0 is returned. All |
| 96 | derived class endElement handlers should call this method. If |
| 97 | the name of the ending tag is the same as the tag that |
| 98 | started this object, the object is assumed to be complete. |
| 99 | |
| 100 | This fails if a tag can contain another tag with the same |
| 101 | name. The XML "<foo><foo/><bar/></foo>" would fail. The |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 102 | object would end before the bar tag was processed. |
| 103 | |
| 104 | The endElement handler is called for every end element |
| 105 | associated with an object, even the element that started the |
| 106 | object. See the description of startElement an example.""" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 107 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 108 | if name == (None, self.tag_name): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 109 | return 1 |
| 110 | else: |
| 111 | return 0 |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 112 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 113 | def get_category_define(self): |
| 114 | return self.category |
| 115 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 116 | |
| 117 | class glEnum( glItem ): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 118 | """Subclass of glItem for representing GL enumerants. |
| 119 | |
| 120 | This class is not complete, and is not really used yet.""" |
| 121 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 122 | def __init__(self, context, name, attrs): |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 123 | self.value = int(attrs.get((None, 'value'), "0x0000"), 0) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 124 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 125 | enum_name = "GL_" + attrs.get((None, 'name'), None) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 126 | glItem.__init__(self, name, enum_name, context) |
| 127 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 128 | temp = attrs.get((None, 'count'), None) |
Ian Romanick | 80a939c | 2005-03-17 21:48:37 +0000 | [diff] [blame] | 129 | self.default_count = 0 |
| 130 | if temp == "?": |
| 131 | self.default_count = -1 |
| 132 | elif temp: |
Ian Romanick | 85f0fa3 | 2005-01-25 01:20:11 +0000 | [diff] [blame] | 133 | try: |
| 134 | c = int(temp) |
| 135 | except Exception,e: |
| 136 | raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) |
| 137 | |
| 138 | self.default_count = c |
| 139 | return |
| 140 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 141 | |
Ian Romanick | 5ff2b94 | 2005-01-24 21:29:13 +0000 | [diff] [blame] | 142 | def process_attributes(self, attrs): |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 143 | name = attrs.get((None, 'name'), None) |
Ian Romanick | 5ff2b94 | 2005-01-24 21:29:13 +0000 | [diff] [blame] | 144 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 145 | temp = attrs.get((None, 'count'), None) |
Ian Romanick | 85f0fa3 | 2005-01-25 01:20:11 +0000 | [diff] [blame] | 146 | if temp == None: |
| 147 | c = self.default_count |
| 148 | else: |
| 149 | try: |
| 150 | c = int(temp) |
| 151 | except Exception,e: |
| 152 | raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) |
Ian Romanick | 5ff2b94 | 2005-01-24 21:29:13 +0000 | [diff] [blame] | 153 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 154 | mode_str = attrs.get((None, 'mode'), "set") |
Ian Romanick | 85f0fa3 | 2005-01-25 01:20:11 +0000 | [diff] [blame] | 155 | if mode_str == "set": |
| 156 | mode = 1 |
| 157 | elif mode_str == "get": |
| 158 | mode = 0 |
| 159 | else: |
| 160 | raise RuntimeError("Invalid mode '%s' for function '%s' in enum '%s'." % (mode_str, self.context.name, self.name)) |
| 161 | |
| 162 | return [name, c, mode] |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 163 | |
| 164 | |
| 165 | class glType( glItem ): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 166 | """Subclass of glItem for representing GL types.""" |
| 167 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 168 | def __init__(self, context, name, attrs): |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 169 | self.size = int(attrs.get((None, 'size'), "0")) |
| 170 | self.glx_name = attrs.get((None, 'glx_name'), "") |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 171 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 172 | type_name = "GL" + attrs.get((None, 'name'), None) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 173 | glItem.__init__(self, name, type_name, context) |
| 174 | |
| 175 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 176 | class glParameter( glItem ): |
| 177 | """Parameter of a glFunction.""" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 178 | p_type = None |
| 179 | p_type_string = "" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 180 | p_count = 0 |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 181 | counter = None |
| 182 | is_output = 0 |
| 183 | is_counter = 0 |
| 184 | is_pointer = 0 |
| 185 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 186 | def __init__(self, context, name, attrs): |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 187 | p_name = attrs.get((None, 'name'), None) |
| 188 | self.p_type_string = attrs.get((None, 'type'), None) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 189 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 190 | temp = attrs.get((None, 'variable_param'), None) |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 191 | if temp: |
Ian Romanick | 067e788 | 2005-04-14 23:03:44 +0000 | [diff] [blame] | 192 | self.count_parameter_list = temp.split( ' ' ) |
Ian Romanick | ba09c19 | 2005-02-01 00:13:04 +0000 | [diff] [blame] | 193 | else: |
| 194 | self.count_parameter_list = [] |
| 195 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 196 | self.p_type = context.context.find_type(self.p_type_string) |
| 197 | if self.p_type == None: |
| 198 | raise RuntimeError("Unknown type '%s' in function '%s'." % (self.p_type_string, context.name)) |
| 199 | |
| 200 | |
| 201 | # The count tag can be either a numeric string or the name of |
| 202 | # a variable. If it is the name of a variable, the int(c) |
| 203 | # statement will throw an exception, and the except block will |
| 204 | # take over. |
| 205 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 206 | c = attrs.get((None, 'count'), "0") |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 207 | try: |
| 208 | self.p_count = int(c) |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 209 | self.counter = None |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 210 | except Exception,e: |
| 211 | self.p_count = 0 |
| 212 | self.counter = c |
| 213 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 214 | self.count_scale = int(attrs.get((None, 'count_scale'), "1")) |
| 215 | |
Ian Romanick | 73b4c1b | 2005-04-14 23:00:34 +0000 | [diff] [blame] | 216 | self.is_counter = is_attr_true( attrs, 'counter' ) |
| 217 | self.is_output = is_attr_true( attrs, 'output' ) |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 218 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 219 | |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 220 | # Pixel data has special parameters. |
| 221 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 222 | self.width = attrs.get((None, 'img_width'), None) |
| 223 | self.height = attrs.get((None, 'img_height'), None) |
| 224 | self.depth = attrs.get((None, 'img_depth'), None) |
| 225 | self.extent = attrs.get((None, 'img_extent'), None) |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 226 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 227 | self.img_xoff = attrs.get((None, 'img_xoff'), None) |
| 228 | self.img_yoff = attrs.get((None, 'img_yoff'), None) |
| 229 | self.img_zoff = attrs.get((None, 'img_zoff'), None) |
| 230 | self.img_woff = attrs.get((None, 'img_woff'), None) |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 231 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 232 | self.img_format = attrs.get((None, 'img_format'), None) |
| 233 | self.img_type = attrs.get((None, 'img_type'), None) |
| 234 | self.img_target = attrs.get((None, 'img_target'), None) |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 235 | |
Ian Romanick | 73b4c1b | 2005-04-14 23:00:34 +0000 | [diff] [blame] | 236 | self.img_pad_dimensions = is_attr_true( attrs, 'img_pad_dimensions' ) |
| 237 | self.img_null_flag = is_attr_true( attrs, 'img_null_flag' ) |
| 238 | self.img_send_null = is_attr_true( attrs, 'img_send_null' ) |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 239 | |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 240 | if self.p_count > 0 or self.counter or self.count_parameter_list: |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 241 | has_count = 1 |
| 242 | else: |
| 243 | has_count = 0 |
| 244 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 245 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 246 | # If there is a * anywhere in the parameter's type, then it |
| 247 | # is a pointer. |
| 248 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 249 | if re.compile("[*]").search(self.p_type_string): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 250 | # We could do some other validation here. For |
| 251 | # example, an output parameter should not be const, |
| 252 | # but every non-output parameter should. |
| 253 | |
| 254 | self.is_pointer = 1; |
| 255 | else: |
| 256 | # If a parameter is not a pointer, then there cannot |
| 257 | # be an associated count (either fixed size or |
| 258 | # variable) and the parameter cannot be an output. |
| 259 | |
| 260 | if has_count or self.is_output: |
| 261 | raise RuntimeError("Non-pointer type has count or is output.") |
| 262 | self.is_pointer = 0; |
| 263 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 264 | glItem.__init__(self, name, p_name, context) |
| 265 | return |
| 266 | |
| 267 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 268 | def is_variable_length_array(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 269 | """Determine if a parameter is a variable length array. |
| 270 | |
| 271 | A parameter is considered to be a variable length array if |
| 272 | its size depends on the value of another parameter that is |
| 273 | an enumerant. The params parameter to glTexEnviv is an |
| 274 | example of a variable length array parameter. Arrays whose |
| 275 | size depends on a count variable, such as the lists parameter |
| 276 | to glCallLists, are not variable length arrays in this |
| 277 | sense.""" |
| 278 | |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 279 | return self.count_parameter_list or self.counter or self.width |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 280 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 281 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 282 | def is_array(self): |
| 283 | return self.is_pointer |
| 284 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 285 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 286 | def count_string(self): |
| 287 | """Return a string representing the number of items |
| 288 | |
| 289 | Returns a string representing the number of items in a |
| 290 | parameter. For scalar types this will always be "1". For |
| 291 | vector types, it will depend on whether or not it is a |
| 292 | fixed length vector (like the parameter of glVertex3fv), |
| 293 | a counted length (like the vector parameter of |
| 294 | glDeleteTextures), or a general variable length vector.""" |
| 295 | |
| 296 | if self.is_array(): |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 297 | if self.count_parameter_list: |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 298 | return "compsize" |
| 299 | elif self.counter != None: |
| 300 | return self.counter |
| 301 | else: |
| 302 | return str(self.p_count) |
| 303 | else: |
| 304 | return "1" |
| 305 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 306 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 307 | def size(self): |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 308 | if self.count_parameter_list or self.counter or self.width or self.is_output: |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 309 | return 0 |
| 310 | elif self.p_count == 0: |
| 311 | return self.p_type.size |
| 312 | else: |
Ian Romanick | 0bd5373 | 2005-03-06 08:55:39 +0000 | [diff] [blame] | 313 | return self.p_type.size * self.p_count * self.count_scale |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 314 | |
Ian Romanick | 4f0a75e | 2004-12-01 00:29:48 +0000 | [diff] [blame] | 315 | def size_string(self): |
| 316 | s = self.size() |
| 317 | if s == 0: |
| 318 | a_prod = "compsize" |
| 319 | b_prod = self.p_type.size |
| 320 | |
Ian Romanick | ba09c19 | 2005-02-01 00:13:04 +0000 | [diff] [blame] | 321 | # Handle functions like glCompressedTexImage2D that |
| 322 | # have a counted 'void *' parameter. |
| 323 | |
| 324 | if b_prod == 0: b_prod = 1 |
| 325 | |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 326 | if not self.count_parameter_list and self.counter != None: |
Ian Romanick | 0bd5373 | 2005-03-06 08:55:39 +0000 | [diff] [blame] | 327 | if self.count_scale > 1: |
| 328 | a_prod = '(%s * %u)' % (self.counter, self.count_scale) |
| 329 | else: |
| 330 | a_prod = self.counter |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 331 | elif self.count_parameter_list and self.counter == None: |
Ian Romanick | 4f0a75e | 2004-12-01 00:29:48 +0000 | [diff] [blame] | 332 | pass |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 333 | elif self.count_parameter_list and self.counter != None: |
Ian Romanick | 0bd5373 | 2005-03-06 08:55:39 +0000 | [diff] [blame] | 334 | if self.count_scale > 1: |
| 335 | b_prod = '(%s * %u)' % (self.counter, self.count_scale) |
| 336 | else: |
| 337 | b_prod = self.counter |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 338 | elif self.width: |
| 339 | return "compsize" |
Ian Romanick | 4f0a75e | 2004-12-01 00:29:48 +0000 | [diff] [blame] | 340 | else: |
| 341 | raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self.name, self.context.name)) |
| 342 | |
| 343 | return "(%s * %s)" % (a_prod, b_prod) |
| 344 | else: |
| 345 | return str(s) |
| 346 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 347 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 348 | class glParameterIterator: |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 349 | """Class to iterate over a list of glParameters. |
| 350 | |
Ian Romanick | 1d27084 | 2004-12-21 21:26:36 +0000 | [diff] [blame] | 351 | Objects of this class are returned by the parameterIterator method of |
| 352 | the glFunction class. They are used to iterate over the list of |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 353 | parameters to the function.""" |
| 354 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 355 | def __init__(self, data): |
| 356 | self.data = data |
| 357 | self.index = 0 |
Ian Romanick | 1d27084 | 2004-12-21 21:26:36 +0000 | [diff] [blame] | 358 | |
| 359 | def __iter__(self): |
| 360 | return self |
| 361 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 362 | def next(self): |
| 363 | if self.index == len( self.data ): |
| 364 | raise StopIteration |
| 365 | i = self.index |
| 366 | self.index += 1 |
| 367 | return self.data[i] |
| 368 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 369 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 370 | class glFunction( glItem ): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 371 | def __init__(self, context, name, attrs): |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 372 | self.fn_alias = attrs.get((None, 'alias'), None) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 373 | self.fn_parameters = [] |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 374 | self.image = None |
Ian Romanick | ba09c19 | 2005-02-01 00:13:04 +0000 | [diff] [blame] | 375 | self.count_parameter_list = [] |
Ian Romanick | 3fec8c2 | 2005-02-02 00:54:45 +0000 | [diff] [blame] | 376 | self.fn_return_type = "void" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 377 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 378 | temp = attrs.get((None, 'offset'), None) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 379 | if temp == None or temp == "?": |
| 380 | self.fn_offset = -1 |
| 381 | else: |
| 382 | self.fn_offset = int(temp) |
| 383 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 384 | fn_name = attrs.get((None, 'name'), None) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 385 | if self.fn_alias != None: |
| 386 | self.real_name = self.fn_alias |
| 387 | else: |
| 388 | self.real_name = fn_name |
| 389 | |
Ian Romanick | ce77d37 | 2005-03-03 21:21:59 +0000 | [diff] [blame] | 390 | self.parameters_by_name = {} |
| 391 | self.variable_length_parameters = [] |
| 392 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 393 | glItem.__init__(self, name, fn_name, context) |
| 394 | return |
| 395 | |
| 396 | |
Ian Romanick | 1d27084 | 2004-12-21 21:26:36 +0000 | [diff] [blame] | 397 | def parameterIterator(self): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 398 | return glParameterIterator(self.fn_parameters) |
| 399 | |
| 400 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 401 | def startElementNS(self, name, qname, attrs): |
| 402 | [uri, true_name] = name |
| 403 | if true_name == "param": |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 404 | try: |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 405 | self.context.factory.create(self, true_name, attrs) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 406 | except RuntimeError: |
| 407 | print "Error with parameter '%s' in function '%s'." \ |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 408 | % (attrs.get((None, 'name'),'(unknown)'), self.name) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 409 | raise |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 410 | elif true_name == "return": |
| 411 | self.set_return_type(attrs.get((None, 'type'), None)) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 412 | |
| 413 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 414 | def endElementNS(self, name, qname): |
Ian Romanick | ce77d37 | 2005-03-03 21:21:59 +0000 | [diff] [blame] | 415 | """Handle the end of a <function> element. |
| 416 | |
| 417 | At the end of a <function> element, there is some semantic |
| 418 | checking that can be done. This prevents some possible |
| 419 | exceptions from being thrown elsewhere in the code. |
| 420 | """ |
| 421 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 422 | [uri, true_name] = name |
| 423 | if true_name == "function": |
Ian Romanick | ce77d37 | 2005-03-03 21:21:59 +0000 | [diff] [blame] | 424 | for p in self.variable_length_parameters: |
| 425 | if p.counter: |
| 426 | counter = self.parameters_by_name[ p.counter ] |
| 427 | if not self.parameters_by_name.has_key( p.counter ): |
| 428 | raise RuntimeError("Parameter '%s' of function '%s' has counter '%s', but function has no such parameter." % (p.name, self.name, p.counter)) |
| 429 | elif not self.parameters_by_name[ p.counter ].is_counter: |
| 430 | raise RuntimeError("Parameter '%s' of function '%s' has counter '%s', but '%s' is not marked as a counter." % (p.name, self.name, p.counter, p.counter)) |
| 431 | |
| 432 | for n in p.count_parameter_list: |
| 433 | if not self.parameters_by_name.has_key( n ): |
| 434 | raise RuntimeError("Parameter '%s' of function '%s' has size parameter '%s', but function has no such parameter." % (p.name, self.name, n)) |
| 435 | |
| 436 | return 1 |
| 437 | else: |
| 438 | return 0 |
| 439 | |
| 440 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 441 | def append(self, tag_name, p): |
| 442 | if tag_name != "param": |
| 443 | raise RuntimeError("Trying to append '%s' to parameter list of function '%s'." % (tag_name, self.name)) |
| 444 | |
Ian Romanick | 5f1f229 | 2005-01-07 02:39:09 +0000 | [diff] [blame] | 445 | if p.width: |
| 446 | self.image = p |
| 447 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 448 | self.fn_parameters.append(p) |
Ian Romanick | ba09c19 | 2005-02-01 00:13:04 +0000 | [diff] [blame] | 449 | if p.count_parameter_list != []: |
| 450 | self.count_parameter_list.extend( p.count_parameter_list ) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 451 | |
Ian Romanick | ce77d37 | 2005-03-03 21:21:59 +0000 | [diff] [blame] | 452 | if p.is_variable_length_array(): |
| 453 | self.variable_length_parameters.append(p) |
| 454 | |
| 455 | self.parameters_by_name[ p.name ] = p |
| 456 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 457 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 458 | def set_return_type(self, t): |
| 459 | self.fn_return_type = t |
| 460 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 461 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 462 | def get_parameter_string(self): |
| 463 | arg_string = "" |
| 464 | comma = "" |
Ian Romanick | 1d27084 | 2004-12-21 21:26:36 +0000 | [diff] [blame] | 465 | for p in glFunction.parameterIterator(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 466 | arg_string = arg_string + comma + p.p_type_string + " " + p.name |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 467 | comma = ", " |
| 468 | |
| 469 | if arg_string == "": |
| 470 | arg_string = "void" |
| 471 | |
| 472 | return arg_string |
| 473 | |
| 474 | |
| 475 | class glItemFactory: |
| 476 | """Factory to create objects derived from glItem.""" |
| 477 | |
| 478 | def create(self, context, name, attrs): |
| 479 | if name == "function": |
| 480 | return glFunction(context, name, attrs) |
| 481 | elif name == "type": |
| 482 | return glType(context, name, attrs) |
| 483 | elif name == "enum": |
| 484 | return glEnum(context, name, attrs) |
Ian Romanick | 4f0a75e | 2004-12-01 00:29:48 +0000 | [diff] [blame] | 485 | elif name == "param": |
| 486 | return glParameter(context, name, attrs) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 487 | else: |
| 488 | return None |
| 489 | |
| 490 | |
Ian Romanick | 38e6e09 | 2005-01-25 23:53:13 +0000 | [diff] [blame] | 491 | class glFunctionIterator: |
| 492 | """Class to iterate over a list of glFunctions |
| 493 | |
| 494 | Objects of this classare returned by |
| 495 | FilterGLAPISpecBase::functionIterator. This default version |
| 496 | iterates over the functions in order of dispatch table offset. All |
| 497 | of the "true" functions are iterated first, followed by the alias |
| 498 | functions.""" |
| 499 | |
| 500 | def __init__(self, context): |
| 501 | self.context = context |
| 502 | self.keys = context.functions.keys() |
| 503 | self.keys.sort() |
| 504 | |
| 505 | self.prevk = -1 |
| 506 | self.direction = 1 |
| 507 | |
| 508 | for self.index in range(0, len(self.keys)): |
| 509 | if self.keys[ self.index ] >= 0: break |
| 510 | |
| 511 | if self.index == len(self.keys): |
| 512 | self.direction = -1 |
| 513 | self.index -= 1 |
| 514 | |
| 515 | self.split = self.index - 1 |
| 516 | return |
| 517 | |
| 518 | |
| 519 | def __iter__(self): |
| 520 | return self |
| 521 | |
| 522 | |
| 523 | def next(self): |
| 524 | if self.index < 0: |
| 525 | raise StopIteration |
| 526 | |
| 527 | k = self.keys[ self.index ] |
| 528 | |
| 529 | #if self.context.functions[k].fn_alias == None: |
| 530 | # if k != self.prevk + 1: |
| 531 | # print 'Missing offset %d' % (prevk) |
| 532 | # self.prevk = int(k) |
| 533 | |
| 534 | self.index += self.direction |
| 535 | |
| 536 | if self.index == len(self.keys): |
| 537 | self.index = self.split |
| 538 | self.direction = -1 |
| 539 | |
| 540 | return self.context.functions[k] |
| 541 | |
| 542 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 543 | class FilterGLAPISpecBase(saxutils.XMLFilterBase): |
| 544 | name = "a" |
| 545 | license = "The license for this file is unspecified." |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 546 | next_alias = -2 |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 547 | current_object = None |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 548 | |
| 549 | def __init__(self): |
| 550 | saxutils.XMLFilterBase.__init__(self) |
| 551 | self.functions = {} |
| 552 | self.types = {} |
Ian Romanick | 6af6a69 | 2005-03-17 20:56:13 +0000 | [diff] [blame] | 553 | self.functions_by_name = {} |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 554 | self.factory = glItemFactory() |
Ian Romanick | 16c3c74 | 2005-01-28 19:00:54 +0000 | [diff] [blame] | 555 | self.header_tag = None |
Ian Romanick | c280358 | 2005-02-01 00:28:47 +0000 | [diff] [blame] | 556 | self.undef_list = [] |
Ian Romanick | 6af6a69 | 2005-03-17 20:56:13 +0000 | [diff] [blame] | 557 | self.current_category = "" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 558 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 559 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 560 | def find_type(self,type_name): |
| 561 | for t in self.types: |
| 562 | if re.compile(t).search(type_name): |
| 563 | return self.types[t] |
| 564 | print "Unable to find base type matching \"%s\"." % (type_name) |
| 565 | return None |
| 566 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 567 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 568 | def find_function(self,function_name): |
Ian Romanick | 6af6a69 | 2005-03-17 20:56:13 +0000 | [diff] [blame] | 569 | return self.functions_by_name[function_name] |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 570 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 571 | |
Ian Romanick | 38e6e09 | 2005-01-25 23:53:13 +0000 | [diff] [blame] | 572 | def functionIterator(self): |
| 573 | return glFunctionIterator(self) |
| 574 | |
| 575 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 576 | def printFunctions(self): |
Ian Romanick | 38e6e09 | 2005-01-25 23:53:13 +0000 | [diff] [blame] | 577 | for f in self.functionIterator(): |
| 578 | self.printFunction(f) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 579 | return |
| 580 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 581 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 582 | def printHeader(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 583 | """Print the header associated with all files and call the printRealHeader method.""" |
| 584 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 585 | print '/* DO NOT EDIT - This file generated automatically by %s script */' \ |
| 586 | % (self.name) |
| 587 | print '' |
| 588 | print '/*' |
| 589 | print ' * ' + self.license.replace('\n', '\n * ') |
| 590 | print ' */' |
| 591 | print '' |
Ian Romanick | 16c3c74 | 2005-01-28 19:00:54 +0000 | [diff] [blame] | 592 | if self.header_tag: |
| 593 | print '#if !defined( %s )' % (self.header_tag) |
| 594 | print '# define %s' % (self.header_tag) |
| 595 | print '' |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 596 | self.printRealHeader(); |
| 597 | return |
| 598 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 599 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 600 | def printFooter(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 601 | """Print the header associated with all files and call the printRealFooter method.""" |
| 602 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 603 | self.printFunctions() |
| 604 | self.printRealFooter() |
Ian Romanick | 16c3c74 | 2005-01-28 19:00:54 +0000 | [diff] [blame] | 605 | if self.header_tag: |
Ian Romanick | c280358 | 2005-02-01 00:28:47 +0000 | [diff] [blame] | 606 | if self.undef_list: |
| 607 | print '' |
| 608 | for u in self.undef_list: |
| 609 | print "# undef %s" % (u) |
| 610 | print '' |
| 611 | print '#endif /* !defined( %s ) */' % (self.header_tag) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 612 | |
| 613 | |
| 614 | def get_category_define(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 615 | """Convert the category name to the #define that would be found in glext.h""" |
| 616 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 617 | if re.compile("[1-9][0-9]*[.][0-9]+").match(self.current_category): |
| 618 | s = self.current_category |
| 619 | return "GL_VERSION_" + s.replace(".", "_") |
| 620 | else: |
| 621 | return self.current_category |
| 622 | |
| 623 | |
| 624 | def append(self, object_type, obj): |
| 625 | if object_type == "function": |
| 626 | # If the function is not an alias and has a negative |
| 627 | # offset, then we do not need to track it. These are |
| 628 | # functions that don't have an assigned offset |
| 629 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 630 | if not self.functions_by_name.has_key(obj.name): |
| 631 | self.functions_by_name[obj.name] = obj |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 632 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 633 | if obj.fn_offset >= 0 or obj.fn_alias != None: |
| 634 | if obj.fn_offset >= 0: |
| 635 | index = obj.fn_offset |
| 636 | else: |
| 637 | index = self.next_alias |
| 638 | self.next_alias -= 1 |
Ian Romanick | 6af6a69 | 2005-03-17 20:56:13 +0000 | [diff] [blame] | 639 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 640 | self.functions[index] = obj |
| 641 | else: |
| 642 | # We should do some checking here to make |
| 643 | # sure the functions are an identical match. |
| 644 | pass |
Ian Romanick | 6af6a69 | 2005-03-17 20:56:13 +0000 | [diff] [blame] | 645 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 646 | elif object_type == "type": |
| 647 | self.types[obj.name] = obj |
| 648 | |
| 649 | return |
| 650 | |
| 651 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 652 | def startElementNS(self, name, qname, attrs): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 653 | """Start a new element in the XML stream. |
| 654 | |
| 655 | Starts a new element. There are three types of elements that |
| 656 | are specially handled by this function. When a "category" |
| 657 | element is encountered, the name of the category is saved. |
| 658 | If an element is encountered and no API object is |
| 659 | in-progress, a new object is created using the API factory. |
| 660 | Any future elements, until that API object is closed, are |
| 661 | passed to the current objects startElement method. |
| 662 | |
| 663 | This paradigm was chosen becuase it allows subclasses of the |
| 664 | basic API types (i.e., glFunction, glEnum, etc.) to handle |
| 665 | additional XML data, GLX protocol information, that the base |
| 666 | classes do not know about.""" |
| 667 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 668 | [uri, true_name] = name |
| 669 | if uri is None: |
| 670 | if self.current_object != None: |
| 671 | self.current_object.startElementNS(name, qname, attrs) |
| 672 | elif true_name == "category": |
| 673 | self.current_category = attrs.get((None, 'name'), "") |
| 674 | elif true_name == "include": |
| 675 | self.next_include = attrs.get((None, 'name'), "") |
| 676 | else: |
| 677 | self.current_object = self.factory.create(self, true_name, attrs) |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 678 | return |
| 679 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 680 | |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 681 | def endElementNS(self, name, qname): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 682 | if self.current_object != None: |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 683 | if self.current_object.endElementNS(name, qname): |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 684 | self.current_object = None |
Ian Romanick | 6cfd4f7 | 2005-02-08 02:11:14 +0000 | [diff] [blame] | 685 | elif name == "include": |
| 686 | parser = make_parser() |
Ian Romanick | 2510ba6 | 2005-04-18 19:16:07 +0000 | [diff] [blame] | 687 | parser.setFeature(feature_namespaces, 1) |
Ian Romanick | 6cfd4f7 | 2005-02-08 02:11:14 +0000 | [diff] [blame] | 688 | parser.setContentHandler(self) |
| 689 | |
| 690 | f = open(self.next_include) |
| 691 | parser.parse(f) |
| 692 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 693 | return |
| 694 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 695 | |
Ian Romanick | c280358 | 2005-02-01 00:28:47 +0000 | [diff] [blame] | 696 | def printPure(self): |
| 697 | self.undef_list.append("PURE") |
| 698 | print """# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) |
| 699 | # define PURE __attribute__((pure)) |
| 700 | # else |
| 701 | # define PURE |
| 702 | # endif""" |
| 703 | |
| 704 | def printFastcall(self): |
| 705 | self.undef_list.append("FASTCALL") |
| 706 | print """# if defined(__i386__) && defined(__GNUC__) |
| 707 | # define FASTCALL __attribute__((fastcall)) |
| 708 | # else |
| 709 | # define FASTCALL |
| 710 | # endif""" |
| 711 | |
| 712 | def printVisibility(self, S, s): |
| 713 | self.undef_list.append(S) |
| 714 | print """# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) |
| 715 | # define %s __attribute__((visibility("%s"))) |
| 716 | # else |
| 717 | # define %s |
| 718 | # endif""" % (S, s, S) |
| 719 | |
| 720 | def printNoinline(self): |
| 721 | self.undef_list.append("NOINLINE") |
| 722 | print """# if defined(__GNUC__) |
| 723 | # define NOINLINE __attribute__((noinline)) |
| 724 | # else |
| 725 | # define NOINLINE |
| 726 | # endif""" |
| 727 | |
| 728 | def printHaveAlias(self): |
| 729 | self.undef_list.append("HAVE_ALIAS") |
| 730 | print """# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) |
| 731 | # define HAVE_ALIAS |
| 732 | # endif""" |
| 733 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 734 | def printFunction(self,offset): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 735 | """Print a single function. |
| 736 | |
| 737 | In the base class, this function is empty. All derived |
| 738 | classes should over-ride this function.""" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 739 | return |
| 740 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 741 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 742 | def printRealHeader(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 743 | """Print the "real" header for the created file. |
| 744 | |
| 745 | In the base class, this function is empty. All derived |
| 746 | classes should over-ride this function.""" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 747 | return |
| 748 | |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 749 | |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 750 | def printRealFooter(self): |
Ian Romanick | a9d033c | 2004-05-19 23:33:08 +0000 | [diff] [blame] | 751 | """Print the "real" footer for the created file. |
| 752 | |
| 753 | In the base class, this function is empty. All derived |
| 754 | classes should over-ride this function.""" |
Ian Romanick | 73f59b0 | 2004-05-18 18:33:40 +0000 | [diff] [blame] | 755 | return |