Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions cpp2rust/converter/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,14 @@ matchTemplate(const std::string &template_str,
}
nextLit = template_str.substr(ti, scan - ti);

auto it = captured.find(name);
if (it != captured.end()) {
auto [it, inserted] = captured.try_emplace(std::move(name));
if (!inserted) {
size_t end_pos = 0;
if (!matchLiteralAt(instantiated, si, it->second, end_pos)) {
return std::nullopt;
}
si = end_pos;
} else {
std::string value;

if (!nextLit.empty()) {
size_t k = findNextLiteralSameDepth(instantiated, si, nextLit);
if (k == std::string::npos) {
Expand All @@ -232,7 +230,7 @@ matchTemplate(const std::string &template_str,
b--;
}

value = instantiated.substr(a, b - a);
it->second = instantiated.substr(a, b - a);
si = k;
} else {
size_t a = si;
Expand All @@ -245,11 +243,9 @@ matchTemplate(const std::string &template_str,
b--;
}

value = instantiated.substr(a, b - a);
it->second = instantiated.substr(a, b - a);
si = instantiated.size();
}

captured[name] = value;
}

if (!nextLit.empty()) {
Expand Down Expand Up @@ -676,12 +672,11 @@ void AddRuleForUserDefinedType(clang::NamedDecl *decl) {
auto cpp_name = ToString(decl);
auto rs_name = std::regex_replace(cpp_name, std::regex("::"), "_");

if (types_.contains(cpp_name)) {
if (!types_.try_emplace(cpp_name, TranslationRule::TypeTgt::Plain(rs_name))
.second) {
return;
}

types_[cpp_name] = TranslationRule::TypeTgt::Plain(rs_name);

if (auto record_decl = llvm::dyn_cast<clang::RecordDecl>(decl)) {
// Forward declaration
if (!record_decl->isThisDeclarationADefinition()) {
Expand Down
7 changes: 3 additions & 4 deletions rule-preprocessor/src/syntactic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,10 @@ impl<'a> FragmentCtx<'a> {
});
return;
}
if self.generic_names.contains(&token.text().to_string()) {
let text = token.text().to_string();
if self.generic_names.contains(&text) {
self.flush_text();
self.fragments.push(BodyFragment::Generic {
generic: token.text().to_string(),
});
self.fragments.push(BodyFragment::Generic { generic: text });
return;
}
}
Expand Down
Loading