Generate type. - For 'struct' or 'union' types, defer to genStruct() to add to the dictionary. - For 'bitmask' types, add the type name to the 'flags' dictionary, with the value being the corresponding 'enums' name defining the acceptable flag bits.
(self, typeinfo, name, alias)
| 193 | pdb.set_trace() |
| 194 | |
| 195 | def genType(self, typeinfo, name, alias): |
| 196 | """Generate type. |
| 197 | |
| 198 | - For 'struct' or 'union' types, defer to genStruct() to |
| 199 | add to the dictionary. |
| 200 | - For 'bitmask' types, add the type name to the 'flags' dictionary, |
| 201 | with the value being the corresponding 'enums' name defining |
| 202 | the acceptable flag bits. |
| 203 | - For 'enum' types, add the type name to the 'enums' dictionary, |
| 204 | with the value being '@STOPHERE@' (because this case seems |
| 205 | never to happen). |
| 206 | - For 'funcpointer' types, add the type name to the 'funcpointers' |
| 207 | dictionary. |
| 208 | - For 'handle' and 'define' types, add the handle or #define name |
| 209 | to the 'struct' dictionary, because that is how the spec sources |
| 210 | tag these types even though they are not structs.""" |
| 211 | OutputGenerator.genType(self, typeinfo, name, alias) |
| 212 | |
| 213 | typeElem = typeinfo.elem |
| 214 | # If the type is a struct type, traverse the embedded <member> tags |
| 215 | # generating a structure. Otherwise, emit the tag text. |
| 216 | category = typeElem.get('category') |
| 217 | |
| 218 | # Add a typeCategory{} entry for the category of this type. |
| 219 | self.addName(self.typeCategory, name, category) |
| 220 | |
| 221 | if category in ('struct', 'union'): |
| 222 | self.genStruct(typeinfo, name, alias) |
| 223 | else: |
| 224 | if alias: |
| 225 | # Add name -> alias mapping |
| 226 | self.addName(self.alias, name, alias) |
| 227 | |
| 228 | # Always emit an alias (?!) |
| 229 | count = 1 |
| 230 | |
| 231 | # May want to only emit full type definition when not an alias? |
| 232 | else: |
| 233 | # Extract the type name |
| 234 | # (from self.genOpts). Copy other text through unchanged. |
| 235 | # If the resulting text is an empty string, do not emit it. |
| 236 | count = len(noneStr(typeElem.text)) |
| 237 | for elem in typeElem: |
| 238 | count += len(noneStr(elem.text)) + len(noneStr(elem.tail)) |
| 239 | |
| 240 | if count > 0: |
| 241 | if category == 'bitmask': |
| 242 | # 'bitmask' are *Flags types. |
| 243 | # Try to determine the corresponding *FlagBits type and |
| 244 | # add that mapping to the 'flags' dictionary |
| 245 | # The FlagBits type is specified in the 'requires' |
| 246 | # attribute for 32-bit flags, and the 'bitvalues' |
| 247 | # attribute for 64-bit flags. |
| 248 | # It is possible for neither to be present, for example |
| 249 | # when a Flags type is defined as a placeholder, but no |
| 250 | # corresponding FlagBits are defined by an extension |
| 251 | # yet. |
| 252 |