MCPcopy Create free account
hub / github.com/FastLED/FastLED / _insert_fl_noexcept_multiline

Function _insert_fl_noexcept_multiline

ci/refactor/add_fl_noexcept.py:251–352  ·  view source on GitHub ↗

Insert FL_NOEXCEPT into a function signature starting at start_line. Returns list of (line_index, new_line_content) replacements, or None if insertion is not possible or not needed.

(
    lines: list[str], start_line: int
)

Source from the content-addressed store, hash-verified

249
250
251def _insert_fl_noexcept_multiline(
252 lines: list[str], start_line: int
253) -> list[tuple[int, str]] | None:
254 """Insert FL_NOEXCEPT into a function signature starting at start_line.
255
256 Returns list of (line_index, new_line_content) replacements, or None if
257 insertion is not possible or not needed.
258 """
259 # Build the signature text from start_line through the end of the
260 # function signature (up to the first ; or { after balanced parens).
261 # Stop precisely at the terminator to avoid picking up FL_NOEXCEPT
262 # from a subsequent function on a nearby line.
263 sig_text = ""
264 depth = 0
265 found_open = False
266 sig_done = False
267 for li in range(start_line, min(start_line + 30, len(lines))):
268 for ci, ch in enumerate(lines[li]):
269 sig_text += ch
270 if ch == "(":
271 depth += 1
272 found_open = True
273 elif ch == ")":
274 depth -= 1
275 elif ch in ("{", ";") and found_open and depth == 0:
276 sig_done = True
277 break
278 if sig_done:
279 break
280 sig_text += " "
281
282 if re.search(r"\b(?:FL_NOEXCEPT|noexcept)\b", sig_text):
283 return None
284
285 # Skip destructors
286 if re.search(r"~\w+\s*\(", sig_text):
287 return None
288
289 # Find the balanced close paren
290 close_line, close_col = _find_balanced_close_paren(lines, start_line)
291 if close_line < 0:
292 return None
293
294 # For operator(), the first balanced () is the operator name, not the
295 # parameters. Check if text up to the close paren ends with "operator()".
296 # If so, advance to find the actual parameter parens.
297 text_up_to_close = lines[close_line][: close_col + 1]
298 if close_line > start_line:
299 # Multi-line: join text from start to close
300 parts = [lines[li] for li in range(start_line, close_line)]
301 parts.append(text_up_to_close)
302 text_up_to_close = " ".join(parts)
303 is_operator_call_parens = bool(
304 re.search(r"\boperator\s*\(\s*\)\s*$", text_up_to_close)
305 )
306 if is_operator_call_parens:
307 # Advance past the name paren and find the parameter paren
308 param_start_line = close_line

Callers 1

_apply_fixesFunction · 0.85

Calls 4

appendMethod · 0.45

Tested by

no test coverage detected