Skip to content

Commit 033889d

Browse files
committed
Iterate over all dirs in build/rules when addRulesFromDirectory
1 parent 649050f commit 033889d

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

cpp2rust/converter/mapper.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,22 @@ TranslationRule::TypeRule *search(clang::QualType qual_type) {
409409
}
410410

411411
void addRulesFromDirectory(const std::filesystem::path &dir, Model model) {
412-
for (const auto &entry : std::filesystem::recursive_directory_iterator(dir)) {
413-
auto &path = entry.path();
414-
if (entry.is_regular_file() &&
415-
(path.extension() == ".cpp" || path.extension() == ".c")) {
416-
auto [expr_rules, type_rules] = TranslationRule::Load(path, model);
417-
if (expr_rules.empty() && type_rules.empty()) {
418-
log() << "No rules found in " << path << '\n';
419-
continue;
420-
}
421-
for (auto &[_, rule] : expr_rules) {
422-
exprs_.emplace(GetExprMapKey(rule.src), std::move(rule));
423-
}
424-
for (auto &[_, rule] : type_rules) {
425-
types_.emplace(GetTypeMapKey(rule.src), std::move(rule));
426-
}
412+
namespace fs = std::filesystem;
413+
for (const auto &entry : fs::directory_iterator(dir)) {
414+
const auto &path = entry.path();
415+
assert(fs::exists(path / "ir_src.json") &&
416+
(fs::exists(path / "ir_unsafe.json") ||
417+
fs::exists(path / "ir_refcount.json")));
418+
auto [expr_rules, type_rules] = TranslationRule::Load(path, model);
419+
if (expr_rules.empty() && type_rules.empty()) {
420+
log() << "No rules found in " << path << '\n';
421+
continue;
422+
}
423+
for (auto &[_, rule] : expr_rules) {
424+
exprs_.emplace(GetExprMapKey(rule.src), std::move(rule));
425+
}
426+
for (auto &[_, rule] : type_rules) {
427+
types_.emplace(GetTypeMapKey(rule.src), std::move(rule));
427428
}
428429
}
429430
}

cpp2rust/converter/translation_rule.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,10 @@ void TypeRule::dump() const {
344344
}
345345
}
346346

347-
std::pair<ExprRules, TypeRules> Load(const std::filesystem::path &path,
347+
std::pair<ExprRules, TypeRules> Load(const std::filesystem::path &dir,
348348
Model model) {
349349
ExprRules exprs;
350350
TypeRules types;
351-
auto dir = path.parent_path();
352351
LoadTgtFromIR(exprs, types, dir / "ir_unsafe.json");
353352

354353
if (model == Model::kRefCount) {

cpp2rust/converter/translation_rule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ struct TypeRule {
9696
using ExprRules = std::unordered_map<std::string, ExprRule>;
9797
using TypeRules = std::unordered_map<std::string, TypeRule>;
9898

99-
std::pair<ExprRules, TypeRules> Load(const std::filesystem::path &path,
99+
std::pair<ExprRules, TypeRules> Load(const std::filesystem::path &dir,
100100
Model model);
101101
} // namespace cpp2rust::TranslationRule

0 commit comments

Comments
 (0)