Skip to content

GH-107603: Clinic: Pass specific attributes to print_block() #108581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,8 +2172,8 @@ def print_block(
self,
block: Block,
*,
clinic: Clinic,
core_includes: bool = False,
header_includes: dict[str, str] | None = None,
) -> None:
input = block.input
output = block.output
Expand Down Expand Up @@ -2212,11 +2212,10 @@ def print_block(

""")

if clinic is not None:
# Emit optional includes
for include, reason in sorted(clinic.includes.items()):
line = f'#include "{include}"'
line = line.ljust(35) + f'// {reason}\n'
if header_includes is not None:
# Emit optional "#include" directives for C headers
for include, reason in sorted(header_includes.items()):
line = f'#include "{include}"'.ljust(35) + f'// {reason}\n'
output += line

input = ''.join(block.input)
Expand Down Expand Up @@ -2531,7 +2530,7 @@ def parse(self, input: str) -> str:
self.parsers[dsl_name] = parsers[dsl_name](self)
parser = self.parsers[dsl_name]
parser.parse(block)
printer.print_block(block, clinic=self)
printer.print_block(block, header_includes=self.includes)

# these are destinations not buffers
for name, destination in self.destinations.items():
Expand All @@ -2546,7 +2545,7 @@ def parse(self, input: str) -> str:
block.input = "dump " + name + "\n"
warn("Destination buffer " + repr(name) + " not empty at end of file, emptying.")
printer.write("\n")
printer.print_block(block, clinic=self)
printer.print_block(block, header_includes=self.includes)
continue

if destination.type == 'file':
Expand All @@ -2571,7 +2570,7 @@ def parse(self, input: str) -> str:

block.input = 'preserve\n'
printer_2 = BlockPrinter(self.language)
printer_2.print_block(block, core_includes=True, clinic=self)
printer_2.print_block(block, core_includes=True, header_includes=self.includes)
write_file(destination.filename, printer_2.f.getvalue())
continue

Expand Down