MCPcopy Index your code
hub / github.com/python/cpython / CodeGen

Class CodeGen

Tools/clinic/libclinic/codegen.py:269–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267
268
269class CodeGen:
270 def __init__(self, limited_capi: bool) -> None:
271 self.limited_capi = limited_capi
272 self._ifndef_symbols: set[str] = set()
273 # dict: include name => Include instance
274 self._includes: dict[str, Include] = {}
275
276 def add_ifndef_symbol(self, name: str) -> bool:
277 if name in self._ifndef_symbols:
278 return False
279 self._ifndef_symbols.add(name)
280 return True
281
282 def add_include(self, name: str, reason: str,
283 *, condition: str | None = None) -> None:
284 try:
285 existing = self._includes[name]
286 except KeyError:
287 pass
288 else:
289 if existing.condition and not condition:
290 # If the previous include has a condition and the new one is
291 # unconditional, override the include.
292 pass
293 else:
294 # Already included, do nothing. Only mention a single reason,
295 # no need to list all of them.
296 return
297
298 self._includes[name] = Include(name, reason, condition)
299
300 def get_includes(self) -> list[Include]:
301 return sorted(self._includes.values(),
302 key=Include.sort_key)

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…