@@ -69,7 +69,7 @@ struct LookupInfo {
6969
7070class Callback : public clang ::ast_matchers::MatchFinder::MatchCallback {
7171public:
72- explicit Callback (SrcStrings &strings ) : strings_(strings ) {}
72+ explicit Callback (llvm::json::Object &out ) : out_(out ) {}
7373
7474 void init (clang::Sema &sema) {
7575 sema_ = &sema;
@@ -87,13 +87,15 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback {
8787 } else {
8888 type = var->getUnderlyingType ();
8989 }
90- strings_.types [var->getQualifiedNameAsString ()] = Mapper::ToString (type);
90+ out_[var->getQualifiedNameAsString ()] =
91+ llvm::json::Object{{" to_string" , Mapper::ToString (type)}};
9192 return ;
9293 }
9394
9495 if (auto func = R.Nodes .getNodeAs <clang::FunctionDecl>(" func" )) {
9596 auto add = [&](std::string &&src) {
96- strings_.functions [func->getQualifiedNameAsString ()] = std::move (src);
97+ out_[func->getQualifiedNameAsString ()] =
98+ llvm::json::Object{{" to_string" , std::move (src)}};
9799 };
98100
99101 if (const auto *fcall = R.Nodes .getNodeAs <clang::CallExpr>(" fcall" )) {
@@ -168,7 +170,7 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback {
168170 }
169171
170172private:
171- SrcStrings &strings_ ;
173+ llvm::json::Object &out_ ;
172174 clang::Sema *sema_ = nullptr ;
173175 clang::SourceLocation loc_;
174176
@@ -644,7 +646,7 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback {
644646
645647class ActionFactory : public clang ::tooling::FrontendActionFactory {
646648public:
647- explicit ActionFactory (SrcStrings &strings ) : cb_(strings ) {
649+ explicit ActionFactory (llvm::json::Object &out ) : cb_(out ) {
648650 using namespace clang ::ast_matchers;
649651 finder_.addMatcher (
650652 returnStmt (
@@ -719,16 +721,14 @@ class ActionFactory : public clang::tooling::FrontendActionFactory {
719721
720722} // namespace
721723
722- SrcStrings Extract (const std::filesystem::path &src_path) {
723- SrcStrings strings;
724+ void Extract (const std::filesystem::path &src_path, llvm::json::Object &out) {
724725 auto flags = getPlatformClangBeginFlags ();
725726 auto end_flags = getPlatformClangEndFlags ();
726727 flags.insert (flags.end (), end_flags.begin (), end_flags.end ());
727728 clang::tooling::FixedCompilationDatabase compilations (" ." , flags);
728- ActionFactory factory (strings );
729+ ActionFactory factory (out );
729730 clang::tooling::ClangTool tool (compilations, {src_path.string ()});
730731 tool.run (&factory);
731- return strings;
732732}
733733
734734} // namespace cpp2rust::RuleSrcParser
0 commit comments