Lines Matching refs:self
21 def __init__(self,
92 GeneratorOptions.__init__(self, **kwargs)
94 self.prefixText = prefixText
97 self.genFuncPointers = genFuncPointers
100 self.protectFile = protectFile
103 self.protectFeature = protectFeature
106 self.protectProto = protectProto
109 self.protectProtoStr = protectProtoStr
112 self.protectExtensionProto = protectExtensionProto
115 self.protectExtensionProtoStr = protectExtensionProtoStr
118 self.apicall = apicall
121 self.apientry = apientry
124 self.apientryp = apientryp
127 self.indentFuncProto = indentFuncProto
130 self.indentFuncPointer = indentFuncPointer
133 self.alignFuncParam = alignFuncParam
136 self.genEnumBeginEndRange = genEnumBeginEndRange
139 self.genAliasMacro = genAliasMacro
142 self.genStructExtendsComment = genStructExtendsComment
145 self.aliasMacro = aliasMacro
148 self.misracstyle = misracstyle
151 self.misracppstyle = misracppstyle
154 self.codeGenerator = True
166 def __init__(self, *args, **kwargs):
169 self.sections = {section: [] for section in self.ALL_SECTIONS}
170 self.feature_not_empty = False
171 self.may_alias = None
173 def beginFile(self, genOpts):
174 OutputGenerator.beginFile(self, genOpts)
175 if self.genOpts is None:
180 if self.genOpts.protectFile and self.genOpts.filename:
182 os.path.basename(self.genOpts.filename)).upper()
183 write('#ifndef', headerSym, file=self.outFile)
184 write('#define', headerSym, '1', file=self.outFile)
185 self.newline()
190 write(s, file=self.outFile)
193 self.newline()
194 write('#ifdef __cplusplus', file=self.outFile)
195 write('extern "C" {', file=self.outFile)
196 write('#endif', file=self.outFile)
197 self.newline()
199 def endFile(self):
202 if self.genOpts is None:
204 self.newline()
205 write('#ifdef __cplusplus', file=self.outFile)
206 write('}', file=self.outFile)
207 write('#endif', file=self.outFile)
208 if self.genOpts.protectFile and self.genOpts.filename:
209 self.newline()
210 write('#endif', file=self.outFile)
212 OutputGenerator.endFile(self)
214 def beginFeature(self, interface, emit):
216 OutputGenerator.beginFeature(self, interface, emit)
221 self.sections = {section: [] for section in self.ALL_SECTIONS}
222 self.feature_not_empty = False
224 def _endProtectComment(self, protect_str, protect_directive='#ifdef'):
229 if not self.genOpts.conventions.protectProtoComment:
236 def endFeature(self):
239 if self.emit:
240 if self.feature_not_empty:
241 if self.genOpts is None:
243 if self.genOpts.conventions is None:
245 is_core = self.featureName and self.featureName.startswith(self.conventions.api_prefix + 'VERSION_')
246 if self.genOpts.conventions.writeFeature(self.featureExtraProtect, self.genOpts.filename):
247 self.newline()
248 if self.genOpts.protectFeature:
249 write('#ifndef', self.featureName, file=self.outFile)
254 if self.featureExtraProtect is not None:
255 write('#ifdef', self.featureExtraProtect, file=self.outFile)
256 self.newline()
259 write(f'// {self.featureName} is a preprocessor guard. Do not pass it to API calls.', file=self.outFile)
260 write('#define', self.featureName, '1', file=self.outFile)
261 for section in self.TYPE_SECTIONS:
262 contents = self.sections[section]
264 write('\n'.join(contents), file=self.outFile)
266 if self.genOpts.genFuncPointers and self.sections['commandPointer']:
267 write('\n'.join(self.sections['commandPointer']), file=self.outFile)
268 self.newline()
270 if self.sections['command']:
271 if self.genOpts.protectProto:
272 write(self.genOpts.protectProto,
273 self.genOpts.protectProtoStr, file=self.outFile)
274 if self.genOpts.protectExtensionProto and not is_core:
275 write(self.genOpts.protectExtensionProto,
276 self.genOpts.protectExtensionProtoStr, file=self.outFile)
277 write('\n'.join(self.sections['command']), end='', file=self.outFile)
278 if self.genOpts.protectExtensionProto and not is_core:
280 self._endProtectComment(protect_directive=self.genOpts.protectExtensionProto,
281 protect_str=self.genOpts.protectExtensionProtoStr),
282 file=self.outFile)
283 if self.genOpts.protectProto:
285 self._endProtectComment(protect_directive=self.genOpts.protectProto,
286 protect_str=self.genOpts.protectProtoStr),
287 file=self.outFile)
289 self.newline()
291 if self.featureExtraProtect is not None:
293 self._endProtectComment(protect_str=self.featureExtraProtect),
294 file=self.outFile)
296 if self.genOpts.protectFeature:
298 self._endProtectComment(protect_str=self.featureName),
299 file=self.outFile)
301 OutputGenerator.endFeature(self)
303 def appendSection(self, section, text):
307 self.logMsg('error', 'Missing section in appendSection (probably a <type> element missing its \'category\' attribute. Text:', text)
310 self.sections[section].append(text)
311 self.feature_not_empty = True
313 def genType(self, typeinfo, name, alias):
315 OutputGenerator.genType(self, typeinfo, name, alias)
333 self.genStruct(typeinfo, name, alias)
335 if self.genOpts is None:
343 # (from self.genOpts). Copy other text through unchanged.
348 body += self.genOpts.apientry + noneStr(elem.tail)
351 if category == 'define' and self.misracppstyle():
357 self.appendSection(section, body)
359 def genProtectString(self, protect_str):
383 def typeMayAlias(self, typeName):
384 if not self.may_alias:
385 if self.registry is None:
391 self.may_alias = set(typeName
392 for typeName, data in self.registry.typedict.items()
397 for otherType in self.registry.typedict.values())
398 self.may_alias.update(set(x for x in polymorphic_bases
400 return typeName in self.may_alias
402 def genStruct(self, typeinfo, typeName, alias):
414 OutputGenerator.genStruct(self, typeinfo, typeName, alias)
416 if self.genOpts is None:
425 (protect_begin, protect_end) = self.genProtectString(typeElem.get('protect'))
429 if self.genOpts.genStructExtendsComment:
438 if self.genOpts.genAliasMacro and self.typeMayAlias(typeName):
439 body += ' ' + self.genOpts.aliasMacro
443 targetLen = self.getMaxCParamTypeLength(typeinfo)
445 body += self.makeCParamDecl(member, targetLen + 4)
451 self.appendSection('struct', body)
453 def genGroup(self, groupinfo, groupName, alias=None):
460 OutputGenerator.genGroup(self, groupinfo, groupName, alias)
474 self.appendSection(section, body)
476 if self.genOpts is None:
478 (section, body) = self.buildEnumCDecl(self.genOpts.genEnumBeginEndRange, groupinfo, groupName)
479 self.appendSection(section, '\n' + body)
481 def genEnum(self, enuminfo, name, alias):
487 OutputGenerator.genEnum(self, enuminfo, name, alias)
489 body = self.buildConstantCDecl(enuminfo, name, alias)
490 self.appendSection('enum', body)
492 def genCmd(self, cmdinfo, name, alias):
494 OutputGenerator.genCmd(self, cmdinfo, name, alias)
500 if self.genOpts is None:
504 decls = self.makeCDecls(cmdinfo.elem)
505 self.appendSection('command', prefix + decls[0] + '\n')
506 if self.genOpts.genFuncPointers:
507 self.appendSection('commandPointer', decls[1])
509 def misracstyle(self):
510 return self.genOpts.misracstyle;
512 def misracppstyle(self):
513 return self.genOpts.misracppstyle;