Build a C comment with an object's string representation. If the comment exceeds the line length limit, it's wrapped into a multiline string (with the extra lines indented to be aligned with the first line's comment). If it contains illegal characters, an empty stri
(self, obj: object, line: str)
| 237 | return ATTR_PREFIX + name |
| 238 | |
| 239 | def object_annotation(self, obj: object, line: str) -> str: |
| 240 | """Build a C comment with an object's string representation. |
| 241 | |
| 242 | If the comment exceeds the line length limit, it's wrapped into a |
| 243 | multiline string (with the extra lines indented to be aligned with |
| 244 | the first line's comment). |
| 245 | |
| 246 | If it contains illegal characters, an empty string is returned.""" |
| 247 | line_width = self._indent + len(line) |
| 248 | formatted = pprint.pformat(obj, compact=True, width=max(90 - line_width, 20)) |
| 249 | if any(x in formatted for x in ("/*", "*/", "\0")): |
| 250 | return "" |
| 251 | |
| 252 | if "\n" in formatted: |
| 253 | first_line, rest = formatted.split("\n", maxsplit=1) |
| 254 | comment_continued = textwrap.indent(rest, (line_width + 3) * " ") |
| 255 | return f" /* {first_line}\n{comment_continued} */" |
| 256 | else: |
| 257 | return f" /* {formatted} */" |
| 258 | |
| 259 | def emit_line(self, line: str = "", *, ann: object = None) -> None: |
| 260 | if line.startswith("}"): |