summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/Core/Reformatting.h
blob: e63e51d21608f02ed6d36a6cd9825f8f50f3798e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//===-- Core/Reformatting.h - LibFormat integration -------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides the LibFormat integration used to reformat
/// migrated code.
///
//===----------------------------------------------------------------------===//

#ifndef CPP11_MIGRATE_REFORMATTING_H
#define CPP11_MIGRATE_REFORMATTING_H

#include "clang/Format/Format.h"

class SourceOverrides;
class ChangedRanges;

class Reformatter {
public:
  Reformatter(const clang::format::FormatStyle &Style) : Style(Style) {}

  /// \brief Reformat the changes made to the file overrides.
  ///
  /// \param Overrides Overriden source files to reformat. Note that since only
  /// the changes are reformatted, file change tracking has to be enabled.
  /// \param SM A SourceManager where the overridens files can be found.
  ///
  /// \sa \c SourceOverrides::isTrackingFileChanges()
  void reformatChanges(SourceOverrides &Overrides, clang::SourceManager &SM);

  /// \brief Overload of \c reformatChanges() providing it's own
  /// \c SourceManager.
  void reformatChanges(SourceOverrides &Overrides);

  /// \brief Produce a list of replacements to apply on \p FileName, only the
  /// ranges in \p Changes are replaced.
  ///
  /// Since this routine use \c clang::format::reformat() the rules that applies
  /// on the ranges are identical:
  ///
  /// \par
  /// Each range is extended on either end to its next bigger logic
  /// unit, i.e. everything that might influence its formatting or might be
  /// influenced by its formatting.
  /// -- \c clang::format::reformat()
  clang::tooling::Replacements reformatSingleFile(llvm::StringRef FileName,
                                                  const ChangedRanges &Changes,
                                                  clang::SourceManager &SM);

private:
  clang::format::FormatStyle Style;
};

#endif // CPP11_MIGRATE_REFORMATTING_H
OpenPOWER on IntegriCloud