summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp
blob: 0a8d0d2e3a800814e49893c1ddd6f9583884ec85 (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
//===-- UseAuto/UseAuto.cpp - Use auto type specifier ---------------------===//
//
//                     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 implementation of the UseAutoTransform class.
///
//===----------------------------------------------------------------------===//

#include "UseAuto.h"
#include "UseAutoActions.h"
#include "UseAutoMatchers.h"

using clang::ast_matchers::MatchFinder;
using namespace clang;
using namespace clang::tooling;

int UseAutoTransform::apply(FileOverrides &InputStates,
                            const clang::tooling::CompilationDatabase &Database,
                            const std::vector<std::string> &SourcePaths) {
  ClangTool UseAutoTool(Database, SourcePaths);

  unsigned AcceptedChanges = 0;

  MatchFinder Finder;
  IteratorReplacer ReplaceIterators(getReplacements(), AcceptedChanges,
                                    Options().MaxRiskLevel);
  NewReplacer ReplaceNew(getReplacements(), AcceptedChanges,
                         Options().MaxRiskLevel);

  Finder.addMatcher(makeIteratorDeclMatcher(), &ReplaceIterators);
  Finder.addMatcher(makeDeclWithNewMatcher(), &ReplaceNew);

  setOverrides(InputStates);

  if (int Result = UseAutoTool.run(createActionFactory(Finder))) {
    llvm::errs() << "Error encountered during translation.\n";
    return Result;
  }

  setAcceptedChanges(AcceptedChanges);

  return 0;
}
OpenPOWER on IntegriCloud