Skip to content

Commit 9e23972

Browse files
C, fix debug functionality (#12194)
1 parent f24eef7 commit 9e23972

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

sphinx/domains/c/_symbol.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def __deepcopy__(self, memo: Any) -> Symbol:
6565

6666
@staticmethod
6767
def debug_print(*args: Any) -> None:
68-
logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end="")
69-
logger.debug(*args)
68+
msg = Symbol.debug_indent_string * Symbol.debug_indent
69+
msg += "".join(str(e) for e in args)
70+
logger.debug(msg)
7071

7172
def _assert_invariants(self) -> None:
7273
if not self.parent:
@@ -241,7 +242,7 @@ def _find_named_symbols(self, ident: ASTIdentifier,
241242
Symbol.debug_print("_find_named_symbols:")
242243
Symbol.debug_indent += 1
243244
Symbol.debug_print("self:")
244-
logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
245+
logger.debug(self.to_string(Symbol.debug_indent + 1, addEndNewline=False))
245246
Symbol.debug_print("ident: ", ident)
246247
Symbol.debug_print("matchSelf: ", matchSelf)
247248
Symbol.debug_print("recurseInAnon: ", recurseInAnon)
@@ -251,7 +252,7 @@ def candidates() -> Generator[Symbol, None, None]:
251252
s = self
252253
if Symbol.debug_lookup:
253254
Symbol.debug_print("searching in self:")
254-
logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
255+
logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False))
255256
while True:
256257
if matchSelf:
257258
yield s
@@ -265,12 +266,12 @@ def candidates() -> Generator[Symbol, None, None]:
265266
s = s.siblingAbove
266267
if Symbol.debug_lookup:
267268
Symbol.debug_print("searching in sibling:")
268-
logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
269+
logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False))
269270

270271
for s in candidates():
271272
if Symbol.debug_lookup:
272273
Symbol.debug_print("candidate:")
273-
logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
274+
logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False))
274275
if s.ident == ident:
275276
if Symbol.debug_lookup:
276277
Symbol.debug_indent += 1
@@ -298,7 +299,7 @@ def _symbol_lookup(
298299
Symbol.debug_print("_symbol_lookup:")
299300
Symbol.debug_indent += 1
300301
Symbol.debug_print("self:")
301-
logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
302+
logger.debug(self.to_string(Symbol.debug_indent + 1, addEndNewline=False))
302303
Symbol.debug_print("nestedName: ", nestedName)
303304
Symbol.debug_print("ancestorLookupType:", ancestorLookupType)
304305
Symbol.debug_print("matchSelf: ", matchSelf)
@@ -325,7 +326,7 @@ def _symbol_lookup(
325326

326327
if Symbol.debug_lookup:
327328
Symbol.debug_print("starting point:")
328-
logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
329+
logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1, addEndNewline=False))
329330

330331
# and now the actual lookup
331332
for ident in names[:-1]:
@@ -345,7 +346,7 @@ def _symbol_lookup(
345346

346347
if Symbol.debug_lookup:
347348
Symbol.debug_print("handle last name from:")
348-
logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="")
349+
logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1, addEndNewline=False))
349350

350351
# handle the last name
351352
ident = names[-1]
@@ -596,14 +597,14 @@ def find_identifier(self, ident: ASTIdentifier,
596597
Symbol.debug_print("matchSelf: ", matchSelf)
597598
Symbol.debug_print("recurseInAnon: ", recurseInAnon)
598599
Symbol.debug_print("searchInSiblings:", searchInSiblings)
599-
logger.debug(self.to_string(Symbol.debug_indent + 1), end="")
600+
logger.debug(self.to_string(Symbol.debug_indent + 1, addEndNewline=False))
600601
Symbol.debug_indent -= 2
601602
current = self
602603
while current is not None:
603604
if Symbol.debug_lookup:
604605
Symbol.debug_indent += 2
605606
Symbol.debug_print("trying:")
606-
logger.debug(current.to_string(Symbol.debug_indent + 1), end="")
607+
logger.debug(current.to_string(Symbol.debug_indent + 1, addEndNewline=False))
607608
Symbol.debug_indent -= 2
608609
if matchSelf and current.ident == ident:
609610
return current
@@ -633,7 +634,7 @@ def direct_lookup(self, key: LookupKey) -> Symbol | None:
633634
Symbol.debug_print("name: ", name)
634635
Symbol.debug_print("id: ", id_)
635636
if s is not None:
636-
logger.debug(s.to_string(Symbol.debug_indent + 1), end="")
637+
logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False))
637638
else:
638639
Symbol.debug_print("not found")
639640
if s is None:
@@ -673,7 +674,7 @@ def onMissingQualifiedSymbol(
673674
return None
674675
return symbols[0]
675676

676-
def to_string(self, indent: int) -> str:
677+
def to_string(self, indent: int, *, addEndNewline: bool = True) -> str:
677678
res = [Symbol.debug_indent_string * indent]
678679
if not self.parent:
679680
res.append('::')
@@ -691,7 +692,8 @@ def to_string(self, indent: int) -> str:
691692
res.append('\t(')
692693
res.append(self.docname)
693694
res.append(')')
694-
res.append('\n')
695+
if addEndNewline:
696+
res.append('\n')
695697
return ''.join(res)
696698

697699
def dump(self, indent: int) -> str:

0 commit comments

Comments
 (0)