MCPcopy
hub / github.com/KhronosGroup/Vulkan-Docs / makeCParamDecl

Method makeCParamDecl

scripts/generator.py:1152–1202  ·  view source on GitHub ↗

Return a string which is an indented, formatted declaration for a ` ` or ` ` block (e.g. function parameter or structure/union member). - param - Element (` ` or ` `) to format - aligncol - if non-zero, attempt to align the nested ` ` e

(self, param, aligncol)

Source from the content-addressed store, hash-verified

1150 return f'({self.genOpts.apientryp}{prefix}{name}{tail})'
1151
1152 def makeCParamDecl(self, param, aligncol):
1153 """Return a string which is an indented, formatted
1154 declaration for a `<param>` or `<member>` block (e.g. function parameter
1155 or structure/union member).
1156
1157 - param - Element (`<param>` or `<member>`) to format
1158 - aligncol - if non-zero, attempt to align the nested `<name>` element
1159 at this column"""
1160 if self.genOpts is None:
1161 raise MissingGeneratorOptionsError()
1162 if self.genOpts.conventions is None:
1163 raise MissingGeneratorOptionsConventionsError()
1164 indent = ' '
1165 paramdecl = indent
1166 prefix = noneStr(param.text)
1167
1168 for elem in param:
1169 text = noneStr(elem.text)
1170 tail = noneStr(elem.tail)
1171
1172 if self.should_insert_may_alias_macro and self.genOpts.conventions.is_voidpointer_alias(elem.tag, text, tail):
1173 # OpenXR-specific macro insertion - but not in apiinc for the spec
1174 tail = self.genOpts.conventions.make_voidpointer_alias(tail)
1175 if elem.tag == 'name' and aligncol > 0:
1176 self.logMsg('diag', 'Aligning parameter', elem.text, 'to column', self.genOpts.alignFuncParam)
1177 # Align at specified column, if possible
1178 paramdecl = paramdecl.rstrip()
1179 oldLen = len(paramdecl)
1180 # This works around a problem where very long type names -
1181 # longer than the alignment column - would run into the tail
1182 # text.
1183 paramdecl = f"{paramdecl.ljust(aligncol - 1)} "
1184 newLen = len(paramdecl)
1185 self.logMsg('diag', 'Adjust length of parameter decl from', oldLen, 'to', newLen, ':', paramdecl)
1186
1187 if (self.misracppstyle() and prefix.find('const ') != -1):
1188 # Change pointer type order from e.g. "const void *" to "void const *".
1189 # If the string starts with 'const', reorder it to be after the first type.
1190 paramdecl += f"{prefix.replace('const ', '') + text} const{tail}"
1191 else:
1192 paramdecl += prefix + text + tail
1193
1194 # Clear prefix for subsequent iterations
1195 prefix = ''
1196
1197 paramdecl = paramdecl + prefix
1198
1199 if aligncol == 0:
1200 # Squeeze out multiple spaces other than the indentation
1201 paramdecl = indent + ' '.join(paramdecl.split())
1202 return paramdecl
1203
1204 def getCParamTypeLength(self, param):
1205 """Return the length of the type field is an indented, formatted

Callers 6

makeCDeclsMethod · 0.95
genStructBodyMethod · 0.80
genStructMethod · 0.80
genCmdMethod · 0.80
genTypeMethod · 0.80
makeStubMethod · 0.80

Calls 7

logMsgMethod · 0.95
misracppstyleMethod · 0.95
is_voidpointer_aliasMethod · 0.80
noneStrFunction · 0.70

Tested by

no test coverage detected