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