MCPcopy Index your code
hub / github.com/python/cpython / print_block

Method print_block

Tools/clinic/libclinic/codegen.py:103–173  ·  view source on GitHub ↗
(
        self,
        block: Block,
        *,
        header_includes: list[Include] | None = None,
    )

Source from the content-addressed store, hash-verified

101 INCLUDE_COMMENT_COLUMN: Final[int] = 35
102
103 def print_block(
104 self,
105 block: Block,
106 *,
107 header_includes: list[Include] | None = None,
108 ) -> None:
109 input = block.input
110 output = block.output
111 dsl_name = block.dsl_name
112 write = self.f.write
113
114 assert not ((dsl_name is None) ^ (output is None)), "you must specify dsl_name and output together, dsl_name " + repr(dsl_name)
115
116 if not dsl_name:
117 write(input)
118 return
119
120 write(self.language.start_line.format(dsl_name=dsl_name))
121 write("\n")
122
123 body_prefix = self.language.body_prefix.format(dsl_name=dsl_name)
124 if not body_prefix:
125 write(input)
126 else:
127 for line in input.split('\n'):
128 write(body_prefix)
129 write(line)
130 write("\n")
131
132 write(self.language.stop_line.format(dsl_name=dsl_name))
133 write("\n")
134
135 output = ''
136 if header_includes:
137 # Emit optional "#include" directives for C headers
138 output += '\n'
139
140 current_condition: str | None = None
141 for include in header_includes:
142 if include.condition != current_condition:
143 if current_condition:
144 output += '#endif\n'
145 current_condition = include.condition
146 if include.condition:
147 output += f'{include.condition}\n'
148
149 if current_condition:
150 line = f'# include "{include.filename}"'
151 else:
152 line = f'#include "{include.filename}"'
153 if include.reason:
154 comment = f'// {include.reason}\n'
155 line = line.ljust(self.INCLUDE_COMMENT_COLUMN - 1) + comment
156 output += line
157
158 if current_condition:
159 output += '#endif\n'
160

Callers 2

_testMethod · 0.95
parseMethod · 0.95

Calls 6

writeFunction · 0.50
formatMethod · 0.45
splitMethod · 0.45
ljustMethod · 0.45
joinMethod · 0.45
endswithMethod · 0.45

Tested by 1

_testMethod · 0.76