From 9e239729d42453f179612ab656b1177304a16e12 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sun, 24 Mar 2024 14:44:19 +0100 Subject: [PATCH] C, fix debug functionality (#12194) --- sphinx/domains/c/_symbol.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/sphinx/domains/c/_symbol.py b/sphinx/domains/c/_symbol.py index c70130082fe..8547d6f286b 100644 --- a/sphinx/domains/c/_symbol.py +++ b/sphinx/domains/c/_symbol.py @@ -65,8 +65,9 @@ def __deepcopy__(self, memo: Any) -> Symbol: @staticmethod def debug_print(*args: Any) -> None: - logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end="") - logger.debug(*args) + msg = Symbol.debug_indent_string * Symbol.debug_indent + msg += "".join(str(e) for e in args) + logger.debug(msg) def _assert_invariants(self) -> None: if not self.parent: @@ -241,7 +242,7 @@ def _find_named_symbols(self, ident: ASTIdentifier, Symbol.debug_print("_find_named_symbols:") Symbol.debug_indent += 1 Symbol.debug_print("self:") - logger.debug(self.to_string(Symbol.debug_indent + 1), end="") + logger.debug(self.to_string(Symbol.debug_indent + 1, addEndNewline=False)) Symbol.debug_print("ident: ", ident) Symbol.debug_print("matchSelf: ", matchSelf) Symbol.debug_print("recurseInAnon: ", recurseInAnon) @@ -251,7 +252,7 @@ def candidates() -> Generator[Symbol, None, None]: s = self if Symbol.debug_lookup: Symbol.debug_print("searching in self:") - logger.debug(s.to_string(Symbol.debug_indent + 1), end="") + logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False)) while True: if matchSelf: yield s @@ -265,12 +266,12 @@ def candidates() -> Generator[Symbol, None, None]: s = s.siblingAbove if Symbol.debug_lookup: Symbol.debug_print("searching in sibling:") - logger.debug(s.to_string(Symbol.debug_indent + 1), end="") + logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False)) for s in candidates(): if Symbol.debug_lookup: Symbol.debug_print("candidate:") - logger.debug(s.to_string(Symbol.debug_indent + 1), end="") + logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False)) if s.ident == ident: if Symbol.debug_lookup: Symbol.debug_indent += 1 @@ -298,7 +299,7 @@ def _symbol_lookup( Symbol.debug_print("_symbol_lookup:") Symbol.debug_indent += 1 Symbol.debug_print("self:") - logger.debug(self.to_string(Symbol.debug_indent + 1), end="") + logger.debug(self.to_string(Symbol.debug_indent + 1, addEndNewline=False)) Symbol.debug_print("nestedName: ", nestedName) Symbol.debug_print("ancestorLookupType:", ancestorLookupType) Symbol.debug_print("matchSelf: ", matchSelf) @@ -325,7 +326,7 @@ def _symbol_lookup( if Symbol.debug_lookup: Symbol.debug_print("starting point:") - logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="") + logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1, addEndNewline=False)) # and now the actual lookup for ident in names[:-1]: @@ -345,7 +346,7 @@ def _symbol_lookup( if Symbol.debug_lookup: Symbol.debug_print("handle last name from:") - logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1), end="") + logger.debug(parentSymbol.to_string(Symbol.debug_indent + 1, addEndNewline=False)) # handle the last name ident = names[-1] @@ -596,14 +597,14 @@ def find_identifier(self, ident: ASTIdentifier, Symbol.debug_print("matchSelf: ", matchSelf) Symbol.debug_print("recurseInAnon: ", recurseInAnon) Symbol.debug_print("searchInSiblings:", searchInSiblings) - logger.debug(self.to_string(Symbol.debug_indent + 1), end="") + logger.debug(self.to_string(Symbol.debug_indent + 1, addEndNewline=False)) Symbol.debug_indent -= 2 current = self while current is not None: if Symbol.debug_lookup: Symbol.debug_indent += 2 Symbol.debug_print("trying:") - logger.debug(current.to_string(Symbol.debug_indent + 1), end="") + logger.debug(current.to_string(Symbol.debug_indent + 1, addEndNewline=False)) Symbol.debug_indent -= 2 if matchSelf and current.ident == ident: return current @@ -633,7 +634,7 @@ def direct_lookup(self, key: LookupKey) -> Symbol | None: Symbol.debug_print("name: ", name) Symbol.debug_print("id: ", id_) if s is not None: - logger.debug(s.to_string(Symbol.debug_indent + 1), end="") + logger.debug(s.to_string(Symbol.debug_indent + 1, addEndNewline=False)) else: Symbol.debug_print("not found") if s is None: @@ -673,7 +674,7 @@ def onMissingQualifiedSymbol( return None return symbols[0] - def to_string(self, indent: int) -> str: + def to_string(self, indent: int, *, addEndNewline: bool = True) -> str: res = [Symbol.debug_indent_string * indent] if not self.parent: res.append('::') @@ -691,7 +692,8 @@ def to_string(self, indent: int) -> str: res.append('\t(') res.append(self.docname) res.append(')') - res.append('\n') + if addEndNewline: + res.append('\n') return ''.join(res) def dump(self, indent: int) -> str: