Return C prototype and function pointer typedef for a ` ` or `type category="funcpointer"` Element, as a two-element list of strings [prototype, typedef]. - cmd - Element containing a command or funcpointer tag
(self, cmd)
| 1374 | return required |
| 1375 | |
| 1376 | def makeCDecls(self, cmd): |
| 1377 | """Return C prototype and function pointer typedef for a |
| 1378 | `<command>` or `type category="funcpointer"` Element, as a |
| 1379 | two-element list of strings [prototype, typedef]. |
| 1380 | |
| 1381 | - cmd - Element containing a command or funcpointer tag""" |
| 1382 | if self.genOpts is None: |
| 1383 | raise MissingGeneratorOptionsError() |
| 1384 | |
| 1385 | isfuncpointer = (cmd.tag == 'type') |
| 1386 | |
| 1387 | proto = cmd.find('proto') |
| 1388 | params = cmd.findall('param') |
| 1389 | # Begin accumulating prototype and typedef strings |
| 1390 | pdecl = self.genOpts.apicall |
| 1391 | tdecl = 'typedef ' |
| 1392 | |
| 1393 | # Insert the function return type/name. |
| 1394 | # For prototypes, add APIENTRY macro before the name |
| 1395 | # For typedefs, add (APIENTRY *<name>) around the name and |
| 1396 | # use the PFN_cmdnameproc naming convention. |
| 1397 | # Done by walking the tree for <proto> element by element. |
| 1398 | # etree has elem.text followed by (elem[i], elem[i].tail) |
| 1399 | # for each child element and any following text |
| 1400 | # Leading text |
| 1401 | pdecl += noneStr(proto.text) |
| 1402 | tdecl += noneStr(proto.text) |
| 1403 | # For each child element, if it is a <name> wrap in appropriate |
| 1404 | # declaration. Otherwise append its contents and tail contents. |
| 1405 | for elem in proto: |
| 1406 | text = noneStr(elem.text) |
| 1407 | tail = noneStr(elem.tail) |
| 1408 | if elem.tag == 'name': |
| 1409 | pdecl += self.makeProtoName(text, tail) |
| 1410 | tdecl += self.makeTypedefName(text, tail, isfuncpointer) |
| 1411 | else: |
| 1412 | pdecl += text + tail |
| 1413 | tdecl += text + tail |
| 1414 | |
| 1415 | if self.genOpts.alignFuncParam == 0: |
| 1416 | # Squeeze out multiple spaces - there is no indentation |
| 1417 | pdecl = ' '.join(pdecl.split()) |
| 1418 | tdecl = ' '.join(tdecl.split()) |
| 1419 | |
| 1420 | # Now add the parameter declaration list, which is identical |
| 1421 | # for prototypes and typedefs. Concatenate all the text from |
| 1422 | # a <param> node without the tags. No tree walking required |
| 1423 | # since all tags are ignored. |
| 1424 | # Uses: self.indentFuncProto |
| 1425 | # self.indentFuncPointer |
| 1426 | # self.alignFuncParam |
| 1427 | n = len(params) |
| 1428 | # Indented parameters |
| 1429 | if n > 0: |
| 1430 | indentdecl = '(\n' |
| 1431 | indentdecl += ',\n'.join(self.makeCParamDecl(p, self.genOpts.alignFuncParam) |
| 1432 | for p in params) |
| 1433 | indentdecl += ');' |
no test coverage detected