Path: blob/main/contrib/llvm-project/clang/lib/Format/FormatInternal.h
35233 views
//===--- FormatInternal.h - Format C++ code ---------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file declares Format APIs to be used internally by the10/// formatting library implementation.11///12//===----------------------------------------------------------------------===//1314#ifndef LLVM_CLANG_LIB_FORMAT_FORMATINTERNAL_H15#define LLVM_CLANG_LIB_FORMAT_FORMATINTERNAL_H1617#include "clang/Basic/LLVM.h"18#include "clang/Format/Format.h"19#include "clang/Tooling/Core/Replacement.h"20#include <utility>2122namespace clang {23namespace format {24namespace internal {2526/// Reformats the given \p Ranges in the code fragment \p Code.27///28/// A fragment of code could conceptually be surrounded by other code that might29/// constrain how that fragment is laid out.30/// For example, consider the fragment of code between 'R"(' and ')"',31/// exclusive, in the following code:32///33/// void outer(int x) {34/// string inner = R"(name: data35/// ^ FirstStartColumn36/// value: {37/// x: 138/// ^ NextStartColumn39/// }40/// )";41/// ^ LastStartColumn42/// }43///44/// The outer code can influence the inner fragment as follows:45/// * \p FirstStartColumn specifies the column at which \p Code starts.46/// * \p NextStartColumn specifies the additional indent dictated by the47/// surrounding code. It is applied to the rest of the lines of \p Code.48/// * \p LastStartColumn specifies the column at which the last line of49/// \p Code should end, in case the last line is an empty line.50///51/// In the case where the last line of the fragment contains content,52/// the fragment ends at the end of that content and \p LastStartColumn is53/// not taken into account, for example in:54///55/// void block() {56/// string inner = R"(name: value)";57/// }58///59/// Each range is extended on either end to its next bigger logic unit, i.e.60/// everything that might influence its formatting or might be influenced by its61/// formatting.62///63/// Returns a pair P, where:64/// * P.first are the ``Replacements`` necessary to make all \p Ranges comply65/// with \p Style.66/// * P.second is the penalty induced by formatting the fragment \p Code.67/// If the formatting of the fragment doesn't have a notion of penalty,68/// returns 0.69///70/// If ``Status`` is non-null, its value will be populated with the status of71/// this formatting attempt. See \c FormattingAttemptStatus.72std::pair<tooling::Replacements, unsigned>73reformat(const FormatStyle &Style, StringRef Code,74ArrayRef<tooling::Range> Ranges, unsigned FirstStartColumn,75unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName,76FormattingAttemptStatus *Status);7778} // namespace internal79} // namespace format80} // namespace clang8182#endif838485