Skip to content

Commit

Permalink
C, fix debug functionality (#12194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobandersen committed Mar 24, 2024
1 parent f24eef7 commit 9e23972
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions sphinx/domains/c/_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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]:
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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('::')
Expand All @@ -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:
Expand Down

0 comments on commit 9e23972

Please sign in to comment.