forked from tewk/refactorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethodMove.cpp
More file actions
71 lines (57 loc) · 2.1 KB
/
methodMove.cpp
File metadata and controls
71 lines (57 loc) · 2.1 KB
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
61
62
63
64
65
66
67
68
69
70
71
#include <yaml-cpp/yaml.h>
#include "yaml-util.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/AST.h"
#include <clang/Sema/SemaConsumer.h>
#include "clang/Frontend/CompilerInstance.h"
#include "llvm/Support/raw_ostream.h"
#include <clang/Tooling/CompilationDatabase.h>
#include <clang/Tooling/Tooling.h>
#include "Refactoring.h"
#include <iostream>
#include <fstream>
#include <unistd.h>
using namespace clang;
using namespace std;
#include "Transforms/Transforms.h"
int main(int argc, char **argv)
{
string errorMessage("Could not load compilation database");
// YAML::Node compileCommands = YAML::LoadFile("compile_commands.json");
// vector<YAML::Node> config = YAML::LoadAll(cin);
// for(auto configSectionIter = config.begin(); configSectionIter != config.end(); ++configSectionIter)
// {
// TransformRegistry::get().config = YAML::Node();
// //figure out which files we need to work on
// YAML::Node& configSection = *configSectionIter;
// vector<string> inputFiles;
// if(configSection["Files"])
// inputFiles = configSection["Files"].as<vector<string> >();
// else
// {
// llvm::errs() << "Warning: No files selected. Operating on all files.\n";
// for(auto iter = compileCommands.begin(); iter != compileCommands.end(); ++iter)
// {
// inputFiles.push_back((*iter)["file"].as<string>());
// }
// }
// if(!configSection["Transforms"])
// {
// llvm::errs() << "No transforms specified in this configuration section:\n";
// llvm::errs() << YAML::Dump(configSection) << "\n";
// }
// }
vector<string> inputFiles;
inputFiles.push_back( argv[2] );
//load up the compilation database
std::unique_ptr<tooling::CompilationDatabase> Compilations(tooling::CompilationDatabase::loadFromDirectory(".", errorMessage));
RefactoringTool rt(*Compilations, inputFiles);
YAML::Node config;
YAML::Node data;
data[ argv[1] ] = argv[2];
config["MethodMove"] = data;
TransformRegistry::get().config = config;
TransformRegistry::get().replacements = &rt.getReplacements();
rt.run(new TransformFactory(TransformRegistry::get()["MethodMoveTransform"]));
return 0;
}