[llvm-branch-commits] [clang] [SSAF][Analyses] Add an AST visitor for the contribution model (PR #191933)
Balázs Benics via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 21 01:49:29 PDT 2026
================
@@ -0,0 +1,109 @@
+//===- SSAFAnalysesCommon.cpp ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SSAFAnalysesCommon.h"
+
+using namespace clang;
+
+namespace {
+// Traverses the AST and finds contributors.
+class ContributorFinder : public DynamicRecursiveASTVisitor {
+public:
+ std::vector<const NamedDecl *> Contributors;
+
+ bool VisitFunctionDecl(FunctionDecl *D) override {
+ Contributors.push_back(D);
+ return true;
+ }
+
+ bool VisitRecordDecl(RecordDecl *D) override {
+ Contributors.push_back(D);
+ return true;
+ }
+
+ bool VisitVarDecl(VarDecl *D) override {
+ DeclContext *DC = D->getDeclContext();
+
+ if (DC->isFileContext() || DC->isNamespace())
+ Contributors.push_back(D);
+ return true;
+ }
+};
+
+// An AST visitor that skips the root node's strict-descendants that are
+// callable Decls and record Decls, because those are separate contributors.
+//
+// Clients need to implement their own `MatchAction`, which is a function that
+// takes a `DynTypedNode`, decides if it matches and performs any further
+// callback actions.
+class ContributorFactFinder : public DynamicRecursiveASTVisitor {
+ llvm::function_ref<void(const DynTypedNode &)> MatchAction;
----------------
steakhal wrote:
I think it's pretty unlikely we want view data members. One usually expect owner member types unless the name of the type expresses that we are a view as well. However, `ContributorFactFinder` doesn't seem to suggests that it's a view (non-owner).
https://github.com/llvm/llvm-project/pull/191933
More information about the llvm-branch-commits
mailing list