ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
AstExtractorRunner.h
Go to the documentation of this file.
1/*$!{
2* Aurora Clang AST Viewer (ACAV)
3*
4* Copyright (c) 2026 Min Liu
5* Copyright (c) 2026 Michael David Adams
6*
7* SPDX-License-Identifier: GPL-2.0-or-later
8*
9* This program is free software; you can redistribute it and/or modify
10* it under the terms of the GNU General Public License as published by
11* the Free Software Foundation; either version 2 of the License, or
12* (at your option) any later version.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License along
20* with this program; if not, see <https://www.gnu.org/licenses/>.
21}$!*/
22
25#pragma once
26
27#include "common/FileManager.h"
28#include "core/AstNode.h"
29#include "core/LogEntry.h"
30#include <QObject>
31#include <QString>
32#include <QStringList>
33#include <atomic>
34#include <cstddef>
35#include <functional>
36#include <memory>
37#include <string>
38
39namespace clang {
40class ASTUnit;
41} // namespace clang
42
43namespace acav {
44
45class AstContext; // Forward declaration
46struct DiagnosticMessage; // Forward declaration
47
50 std::size_t totalCount = 0; // Total nodes visited
51 std::size_t declCount = 0; // Declaration nodes
52 std::size_t stmtCount = 0; // Statement nodes
53 std::size_t typeCount = 0; // Type nodes (deduplicated)
54 std::size_t typeLocCount = 0; // TypeLoc nodes
55 std::size_t attrCount = 0; // Attribute nodes
56 std::size_t conceptRefCount = 0; // ConceptReference nodes
57 std::size_t cxxBaseSpecCount = 0; // CXXBaseSpecifier nodes
58 std::size_t ctorInitCount = 0; // CXXCtorInitializer nodes
59 std::size_t lambdaCaptureCount = 0; // LambdaCapture nodes
60 std::size_t nestedNameSpecCount = 0; // NestedNameSpecifier nodes
61 std::size_t nestedNameSpecLocCount = 0; // NestedNameSpecifierLoc nodes
62 std::size_t tempArgCount = 0; // TemplateArgument nodes
63 std::size_t tempArgLocCount = 0; // TemplateArgumentLoc nodes
64 std::size_t tempNameCount = 0; // TemplateName nodes
65 std::size_t commentCount = 0; // Comment nodes
66};
67
80class AstExtractorRunner : public QObject {
81 Q_OBJECT
82
83public:
91 using AstLoader = std::function<std::unique_ptr<clang::ASTUnit>(
92 const std::string &astFilePath, std::string &errorOut,
93 const std::string &compilationDbPath, const std::string &sourcePath)>;
94
96 explicit AstExtractorRunner(AstContext *context, FileManager &fileManager,
97 QObject *parent = nullptr);
98
100 explicit AstExtractorRunner(AstContext *context, FileManager &fileManager,
101 AstLoader loader, QObject *parent = nullptr);
102
103 ~AstExtractorRunner() override;
104
105 // Non-copyable, non-movable
106 AstExtractorRunner(const AstExtractorRunner &) = delete;
107 AstExtractorRunner &operator=(const AstExtractorRunner &) = delete;
109 AstExtractorRunner &operator=(AstExtractorRunner &&) = delete;
110
122 void run(const QString &astFilePath, const QStringList &tuFilePaths,
123 const QString &compilationDbPath = QString());
124
126 void setCommentExtractionEnabled(bool enabled);
127
128 bool commentExtractionEnabled() const { return commentExtractionEnabled_.load(); }
129
130signals:
131 void started(const QString &astFilePath);
132 void progress(const QString &message);
133 void statsUpdated(const AstExtractionStats &stats);
134 void finished(AstViewNode *root);
135 void error(const QString &message);
136 void logMessage(const LogEntry &entry);
137
138private:
139 void registerInputFiles(const QStringList &tuFilePaths);
140 AstViewNode *buildTreeFromASTUnit(clang::ASTUnit &astUnit);
141 void buildLocationIndex(AstViewNode *node);
142
143 AstContext *context_; // Not owned
144 FileManager &fileManager_; // Not owned
145 AstLoader astLoader_;
146 std::function<void(const DiagnosticMessage &)> diagnosticCallback_;
147 std::chrono::steady_clock::time_point start_;
148 std::atomic<bool> commentExtractionEnabled_{false};
149};
150
151} // namespace acav
AST data structures and memory management.
Centralized file registry with path-to-FileID mapping.
Memory manager for AST nodes in a translation unit.
Definition AstNode.h:66
void setCommentExtractionEnabled(bool enabled)
Enable or disable comment extraction in AST.
void run(const QString &astFilePath, const QStringList &tuFilePaths, const QString &compilationDbPath=QString())
Run extraction pipeline and emit lifecycle signals.
std::function< std::unique_ptr< clang::ASTUnit >( const std::string &astFilePath, std::string &errorOut, const std::string &compilationDbPath, const std::string &sourcePath)> AstLoader
Function type for loading AST from file.
AstExtractorRunner(AstContext *context, FileManager &fileManager, QObject *parent=nullptr)
Construct runner with default AST loader.
Represents node in AST tree hierarchy.
Definition AstNode.h:195
Centralized file registry providing path-to-FileID mapping.
Definition FileManager.h:45
Statistics collected during AST extraction.