Skip to content

Commit c3a34fc

Browse files
committed
Optimize preprocessed src json file format
1 parent bdc7c3f commit c3a34fc

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

cpp2rust/converter/translation_rule.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,17 @@ void LoadIrSrc(ExprRules &exprs, TypeRules &types,
185185
}
186186

187187
for (auto &[entry_name, entry_val] : *root) {
188-
auto *obj = entry_val.getAsObject();
189-
if (!obj) {
190-
continue;
191-
}
192-
auto str = obj->getString("to_string");
193-
if (!str) {
194-
continue;
195-
}
196188
auto name = entry_name.str();
197-
if (name.empty()) {
198-
continue;
199-
}
189+
auto val = entry_val.getAsString();
200190
if (name[0] == 'f') {
201191
auto it = exprs.find(name);
202192
if (it != exprs.end()) {
203-
it->second.src = str->str();
193+
it->second.src = val->str();
204194
}
205195
} else if (name[0] == 't') {
206196
auto it = types.find(name);
207197
if (it != types.end()) {
208-
it->second.src = str->str();
198+
it->second.src = val->str();
209199
}
210200
}
211201
}

cpp2rust/cpp_rule_preprocessor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback {
9393
} else {
9494
type = var->getUnderlyingType();
9595
}
96-
out_[var->getQualifiedNameAsString()] =
97-
llvm::json::Object{{"to_string", Mapper::ToString(type)}};
96+
out_.try_emplace(var->getQualifiedNameAsString(), Mapper::ToString(type));
9897
return;
9998
}
10099

101100
if (auto func = R.Nodes.getNodeAs<clang::FunctionDecl>("func")) {
102101
auto add = [&](std::string &&src) {
103-
out_[func->getQualifiedNameAsString()] =
104-
llvm::json::Object{{"to_string", std::move(src)}};
102+
out_.try_emplace(func->getQualifiedNameAsString(), std::move(src));
105103
};
106104

107105
if (const auto *fcall = R.Nodes.getNodeAs<clang::CallExpr>("fcall")) {

0 commit comments

Comments
 (0)