@@ -97,13 +97,15 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback {
9797 } else {
9898 type = var->getUnderlyingType ();
9999 }
100- out_.at (var->getQualifiedNameAsString ()).src = Mapper::ToString (type);
100+ auto &rule = out_.at (var->getQualifiedNameAsString ());
101+ rule.src = Mapper::ToString (type);
102+ get<TypeRule>(rule.tgt ).src = rule.src ;
101103 return ;
102104 }
103105
104106 if (auto func = R.Nodes .getNodeAs <clang::FunctionDecl>(" func" )) {
105107 auto sym = func->getQualifiedNameAsString ();
106- auto add = [&](std::string src) { out_.at (sym).src = std::move (src); };
108+ auto add = [&](std::string && src) { out_.at (sym).src = std::move (src); };
107109
108110 if (const auto *fcall = R.Nodes .getNodeAs <clang::CallExpr>(" fcall" )) {
109111 if (fcall->getDirectCallee ()) {
@@ -837,10 +839,8 @@ ExprTgt ParseExprTgtJSON(const llvm::json::Object &obj) {
837839 return ir;
838840}
839841
840- TypeRule ParseTypeRuleJSON (const std::string &src,
841- const llvm::json::Object &obj) {
842+ TypeRule ParseTypeRuleJSON (const llvm::json::Object &obj) {
842843 TypeRule rule;
843- rule.src = src;
844844 if (auto init = obj.getString (" init" ))
845845 rule.initializer = init->str ();
846846 rule.type_info = ParseTypeInfoJSON (obj);
@@ -883,7 +883,7 @@ void LoadTgtFromIR(RuleMap &rules, const std::filesystem::path &json_path) {
883883 rule.tgt = ParseExprTgtJSON (*obj);
884884 std::get<ExprTgt>(rule.tgt ).validate (json_path.string () + ' :' + name);
885885 } else if (name[0 ] == ' t' ) {
886- rule.tgt = ParseTypeRuleJSON (name, *obj);
886+ rule.tgt = ParseTypeRuleJSON (*obj);
887887 } else {
888888 continue ;
889889 }
@@ -1024,15 +1024,15 @@ void ExprTgt::validate(const std::string &context) const {
10241024}
10251025
10261026RuleMap Load (const std::filesystem::path &path, Model model) {
1027- auto dir = path.parent_path ();
1028- auto unsafe_ir_path = dir / " ir_unsafe.json" ;
1029- auto refcount_ir_path = dir / " ir_refcount.json" ;
1030-
10311027 RuleMap rules;
1032- LoadTgtFromIR (rules, unsafe_ir_path);
1028+ auto dir = path.parent_path ();
1029+ LoadTgtFromIR (rules, dir / " ir_unsafe.json" );
10331030
1034- if (model == Model::kRefCount && std::filesystem::exists (refcount_ir_path)) {
1035- LoadTgtFromIR (rules, refcount_ir_path);
1031+ if (model == Model::kRefCount ) {
1032+ auto refcount_ir_path = dir / " ir_refcount.json" ;
1033+ if (std::filesystem::exists (refcount_ir_path)) {
1034+ LoadTgtFromIR (rules, refcount_ir_path);
1035+ }
10361036 }
10371037
10381038 LoadSrc (rules, path);
0 commit comments