Repository: carbon-language/carbon-lang
File: testing/file_test/autoupdate.h (C/C++)

Code before:
  // - If to_file_end, the end of the file.
  auto AddCheckLines(CheckLines& check_lines, bool to_file_end) -> void;

  // Adds remaining check lines for the current file. stderr is always included,
  // but stdout is only included when either any_attached_stdout_lines_ or
  // is_last_file is true.
  auto FinishFile(bool is_last_file) -> void;

  // Starts a new split file, updating file and line numbers. Advances past the
  // split line.
  auto StartSplitFile() -> void;

  // Passed-in state.
  const std::filesystem::path& file_test_path_;
  std::string test_command_;
  std::string dump_command_;
  llvm::StringRef input_content_;
  int autoupdate_line_number_;
  bool autoupdate_split_;
  const llvm::SmallVector<FileTestLine>& non_check_lines_;
  const std::optional<RE2>& default_file_re_;
  const llvm::SmallVector<LineNumberReplacement>& line_number_replacements_;
  std::function<auto(std::string&)->void> do_extra_check_replacements_;

  // If `autoupdate_split_` is true, the file number of the autoupdate split.
  // Otherwise, meaningless.
  int autoupdate_split_file_;

  // Generated TIP lines, from AddTips.
  llvm::SmallVector<TipLine> tips_;

  // Mapping from file names to file numbers.
  llvm::DenseMap<llvm::StringRef, int> file_to_number_map_;

  // The constructed CheckLine list and cursor.
  CheckLines stdout_;
  CheckLines stderr_;

  // Whether any stdout lines have an associated line number.
  bool any_attached_stdout_lines_;

  // Iterators for the main Run loop.
  const FileTestLine* non_check_line_;

  // Tracks the new last line numbers for each file.
  llvm::SmallVector<int> new_last_line_numbers_;

  // A reusable blank line. new_lines_ can contain a reference back to it.
  const FileTestLine blank_line_ = FileTestLine(-1, -1, "");

  // Stitched-together content.

Review comment (suggestion):
WDYT of setting `-1` when there is no split, and removing `autoupdate_split_`? I'm worried about confusion here, given they're relating similar information.

(you could also choose to replace `autoupdate_split` in the constructor)

Code after:
  // - If to_file_end, the end of the file.
  auto AddCheckLines(CheckLines& check_lines, bool to_file_end) -> void;

  // Adds remaining check lines for the current file. stderr is always included,
  // but stdout is only included when either any_attached_stdout_lines_ or
  // is_last_file is true.
  auto FinishFile(bool is_last_file) -> void;

  // Starts a new split file, updating file and line numbers. Advances past the
  // split line.
  auto StartSplitFile() -> void;

  // Passed-in state.
  const std::filesystem::path& file_test_path_;
  std::string test_command_;
  std::string dump_command_;
  llvm::StringRef input_content_;
  int autoupdate_line_number_;
  const llvm::SmallVector<FileTestLine>& non_check_lines_;
  const std::optional<RE2>& default_file_re_;
  const llvm::SmallVector<LineNumberReplacement>& line_number_replacements_;
  std::function<auto(std::string&)->void> do_extra_check_replacements_;

  // If we have an autoupdate split that still needs to be processed, the file
  // number of the autoupdate split. Otherwise, this is nullopt.
  std::optional<int> autoupdate_split_file_;

  // Generated TIP lines, from AddTips.
  llvm::SmallVector<TipLine> tips_;

  // Mapping from file names to file numbers.
  llvm::DenseMap<llvm::StringRef, int> file_to_number_map_;

  // The constructed CheckLine list and cursor.
  CheckLines stdout_;
  CheckLines stderr_;

  // Whether any stdout lines have an associated line number.
  bool any_attached_stdout_lines_;

  // Iterators for the main Run loop.
  const FileTestLine* non_check_line_;

  // Tracks the new last line numbers for each file.
  llvm::SmallVector<int> new_last_line_numbers_;

  // A reusable blank line. new_lines_ can contain a reference back to it.
  const FileTestLine blank_line_ = FileTestLine(-1, -1, "");

  // Stitched-together content.
  llvm::SmallVector<const FileTestLineBase*> new_lines_;