77#include < clang/Tooling/CompilationDatabase.h>
88#include < clang/Tooling/Tooling.h>
99
10- #include < deque>
1110#include < filesystem>
12- #include < format>
13- #include < fstream>
14- #include < iterator>
1511
1612#include " compat/platform_flags.h"
1713#include " converter/converter.h"
1814#include " converter/models/converter_refcount.h"
19- #include " converter/rules/rules_epilogue.h"
2015#include " frontend_action.h"
2116
2217namespace cpp2rust {
@@ -31,18 +26,12 @@ std::string TranspileSrc(std::string_view cc_code, Model model,
3126 auto end_flags = getPlatformClangEndFlags ();
3227 tool_args.insert (tool_args.end (), end_flags.begin (), end_flags.end ());
3328
34- auto language = GetRulesLanguage (filename);
35- auto code = std::format (" {}\n #include \" {}\"\n " , cc_code,
36- GetRulesEpiloguePath (language));
37-
3829 std::string rs_code;
3930 clang::tooling::runToolOnCodeWithArgs (
4031 std::make_unique<FrontendAction>(rs_code, model, /* first=*/ true ,
4132 rules_dir),
42- code, tool_args, std::filesystem::path (filename).filename ().string (),
43- filename.ends_with (" .c" ) ? CLANG_C_COMPILER : CLANG_CXX_COMPILER ,
44- std::make_shared<clang::PCHContainerOperations>(),
45- {{GetRulesEpiloguePath (language), BuildRulesEpilogue (language)}});
33+ cc_code, tool_args, std::filesystem::path (filename).filename ().string (),
34+ filename.ends_with (" .c" ) ? CLANG_C_COMPILER : CLANG_CXX_COMPILER );
4635 Converter::EmitOpaqueRecords (rs_code);
4736 Converter::EmitVirtualMethods (rs_code);
4837 if (model == Model::kRefCount ) {
@@ -86,26 +75,6 @@ std::string TranspileDir(std::string_view build_dir, Model model,
8675 return result;
8776 });
8877
89- std::deque<std::string> mapped;
90- for (auto language : {RulesLanguage::kC , RulesLanguage::kCxx }) {
91- Tool.mapVirtualFile (mapped.emplace_back (GetRulesEpiloguePath (language)),
92- mapped.emplace_back (BuildRulesEpilogue (language)));
93- }
94- for (const auto &compile_command : compile_dbase->getAllCompileCommands ()) {
95- std::filesystem::path file_path (compile_command.Filename );
96- if (file_path.is_relative ()) {
97- file_path = std::filesystem::path (compile_command.Directory ) / file_path;
98- }
99- std::ifstream file (file_path);
100- std::string code{std::istreambuf_iterator<char >(file),
101- std::istreambuf_iterator<char >()};
102- Tool.mapVirtualFile (
103- mapped.emplace_back (file_path.string ()),
104- mapped.emplace_back (std::format (
105- " {}\n #include \" {}\"\n " , code,
106- GetRulesEpiloguePath (GetRulesLanguage (file_path.string ())))));
107- }
108-
10978 std::string rs_code;
11079 FrontendActionFactory factory (rs_code, model, rules_dir);
11180 Tool.run (&factory);
0 commit comments