Skip to content

Commit f16570f

Browse files
committed
Delete the file.rs comment and single_file flag
1 parent e9d2681 commit f16570f

10 files changed

Lines changed: 15 additions & 27 deletions

File tree

cpp2rust/ast_consumer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
namespace cpp2rust {
99
void ASTConsumer::HandleTranslationUnit(clang::ASTContext &ctx) {
10-
auto converter =
11-
CreateConverter(rs_code_, ctx, model_, single_file_, rules_dir_);
10+
auto converter = CreateConverter(rs_code_, ctx, model_, rules_dir_);
1211
converter->SetSema(CI_.getSema());
1312
if (first_) {
1413
converter->EmitFilePreamble();

cpp2rust/ast_consumer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ namespace cpp2rust {
1515
class ASTConsumer : public clang::ASTConsumer {
1616
public:
1717
explicit ASTConsumer(std::string &rs_code, Model model, bool first,
18-
bool single_file, clang::CompilerInstance &CI,
18+
clang::CompilerInstance &CI,
1919
const std::string &rules_dir)
2020
: rs_code_(rs_code), model_(model), first_(first),
21-
single_file_(single_file), CI_(CI), rules_dir_(rules_dir) {}
21+
CI_(CI), rules_dir_(rules_dir) {}
2222

2323
void HandleTranslationUnit(clang::ASTContext &ctx) override;
2424

2525
private:
2626
std::string &rs_code_;
2727
Model model_;
2828
bool first_;
29-
bool single_file_;
3029
clang::CompilerInstance &CI_;
3130
const std::string &rules_dir_;
3231
};

cpp2rust/converter/converter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,6 @@ bool Converter::VisitUsingType(clang::UsingType *type) {
275275
bool Converter::Convert(clang::Decl *decl) { return TraverseDecl(decl); }
276276

277277
bool Converter::VisitTranslationUnitDecl(clang::TranslationUnitDecl *decl) {
278-
if (!single_file_) {
279-
StrCat("\n//", GetMainFileName(ctx_) + ".rs\n");
280-
}
281278
for (auto *child : decl->decls()) {
282279
if (IsConvertibleDecl(child) &&
283280
(IsInMainFile(child) || !decl_ids_.contains(GetID(child)))) {

cpp2rust/converter/converter.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
2424

2525
public:
2626
explicit Converter(std::string &rs_code, clang::ASTContext &ctx,
27-
bool single_file = false,
2827
const char *keyword_unsafe = "unsafe",
2928
const char *keyword_mut = "mut",
3029
const char *keyword_ptr_decay = ".as_mut_ptr()",
3130
const char *keyword_const_fn = keyword::kConst)
32-
: rs_code_(&rs_code), ctx_(ctx), single_file_(single_file),
31+
: rs_code_(&rs_code), ctx_(ctx),
3332
keyword_unsafe_(keyword_unsafe), keyword_mut_(keyword_mut),
3433
keyword_ptr_decay_(keyword_ptr_decay),
3534
keyword_const_fn_(keyword_const_fn) {}
@@ -527,7 +526,6 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
527526

528527
std::string *rs_code_;
529528
clang::ASTContext &ctx_;
530-
bool single_file_ = false;
531529
clang::FunctionDecl *curr_function_ = nullptr;
532530
bool in_function_formals_ = false;
533531
bool in_const_initializer_ = false;

cpp2rust/converter/factory.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ namespace cpp2rust {
1010

1111
std::unique_ptr<Converter> CreateConverter(std::string &rs_code,
1212
clang::ASTContext &ctx, Model model,
13-
bool single_file,
1413
const std::string &rules_dir) {
1514
Mapper::LoadTranslationRules(model, ctx, rules_dir);
1615
switch (model) {
1716
case Model::kUnsafe:
18-
return std::make_unique<Converter>(rs_code, ctx, single_file);
17+
return std::make_unique<Converter>(rs_code, ctx);
1918
case Model::kRefCount:
20-
return std::make_unique<ConverterRefCount>(rs_code, ctx, single_file);
19+
return std::make_unique<ConverterRefCount>(rs_code, ctx);
2120
}
2221
std::unreachable();
2322
}

cpp2rust/converter/factory.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ class Converter;
1818

1919
std::unique_ptr<Converter> CreateConverter(std::string &rs_code,
2020
clang::ASTContext &ctx, Model model,
21-
bool single_file,
2221
const std::string &rules_dir);
2322
} // namespace cpp2rust

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
namespace cpp2rust {
1616
ConverterRefCount::ConverterRefCount(std::string &rs_code,
17-
clang::ASTContext &ctx, bool single_file)
18-
: Converter(rs_code, ctx, single_file, "", "", ".as_pointer()", ""),
17+
clang::ASTContext &ctx)
18+
: Converter(rs_code, ctx, "", "", ".as_pointer()", ""),
1919
conversion_kind_({ConversionKind::Unboxed}) {}
2020

2121
void ConverterRefCount::EmitFilePreamble() {

cpp2rust/converter/models/converter_refcount.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
namespace cpp2rust {
99
class ConverterRefCount final : public Converter {
1010
public:
11-
ConverterRefCount(std::string &rs_code, clang::ASTContext &ctx,
12-
bool single_file = false);
11+
ConverterRefCount(std::string &rs_code, clang::ASTContext &ctx);
1312

1413
void EmitFilePreamble() override;
1514

cpp2rust/cpp2rust_lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::string TranspileSrc(std::string_view cc_code, Model model,
2626
std::string rs_code;
2727
clang::tooling::runToolOnCodeWithArgs(
2828
std::make_unique<FrontendAction>(rs_code, model, /*first=*/true,
29-
/*single_file=*/true, rules_dir),
29+
rules_dir),
3030
cc_code, tool_args, std::filesystem::path(filename).filename().string(),
3131
filename.ends_with(".c") ? CLANG_C_COMPILER : CLANG_CXX_COMPILER);
3232
return rs_code;

cpp2rust/frontend_action.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@ namespace cpp2rust {
1818
class FrontendAction : public clang::ASTFrontendAction {
1919
public:
2020
explicit FrontendAction(std::string &rs_code, Model model, bool first,
21-
bool single_file, const std::string &rules_dir)
21+
const std::string &rules_dir)
2222
: rs_code_(rs_code), model_(model), first_(first),
23-
single_file_(single_file), rules_dir_(rules_dir) {}
23+
rules_dir_(rules_dir) {}
2424

2525
std::unique_ptr<clang::ASTConsumer>
2626
CreateASTConsumer(clang::CompilerInstance &CI,
2727
llvm::StringRef InFile) override {
28-
return std::make_unique<ASTConsumer>(rs_code_, model_, first_, single_file_,
29-
CI, rules_dir_);
28+
return std::make_unique<ASTConsumer>(rs_code_, model_, first_, CI,
29+
rules_dir_);
3030
}
3131

3232
private:
3333
std::string &rs_code_;
3434
Model model_;
3535
bool first_;
36-
bool single_file_;
3736
const std::string &rules_dir_;
3837
};
3938

@@ -46,8 +45,7 @@ class FrontendActionFactory : public clang::tooling::FrontendActionFactory {
4645
std::unique_ptr<clang::FrontendAction> create() override {
4746
bool f = first_;
4847
first_ = false;
49-
return std::make_unique<FrontendAction>(rs_code_, model_, f,
50-
/*single_file=*/false, rules_dir_);
48+
return std::make_unique<FrontendAction>(rs_code_, model_, f, rules_dir_);
5149
}
5250

5351
private:

0 commit comments

Comments
 (0)