MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SignatureCollector.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7/** @brief One constructor parameter: its fully qualified type, its name and its default argument text. */
9 std::string type;
10 std::string name;
11 std::optional<std::string> default_value;
12};
13
14/** @brief One public constructor a Creator method is generated from. */
16 std::vector<SignatureParameter> parameters;
17};
18
19/**
20 * @struct SignatureClass
21 * @brief A registered class as the scan found it.
22 *
23 * includes holds, relative to the source root, the header of every MayaFlux type and enumerator
24 * the constructors' parameter types and default arguments name, except the registered classes
25 * themselves.
26 */
29 bool abstract {};
30 std::vector<ConstructorSignature> constructors;
31 std::set<std::filesystem::path> includes;
32};
33
34/**
35 * @class SignatureCollector
36 * @brief Reads the public constructors of each registered class from the scanned translation unit.
37 *
38 * Attach it to a MatchFinder, run the finder, then read classes(), missing() and errors().
39 * Parameter types are spelled fully qualified, so the generated methods compile in any scope.
40 * Default arguments are kept as written, with the class's nested type names qualified.
41 */
42class SignatureCollector : public clang::ast_matchers::MatchFinder::MatchCallback {
43public:
44 /**
45 * @param entries Registered classes, in registry order.
46 * @param source_root The directory MayaFlux/ sits in; headers are reported relative to it.
47 */
48 SignatureCollector(std::vector<SignatureEntry> entries, std::filesystem::path source_root);
49
50 /** @brief Registers the matcher for class definitions on @p finder. */
51 void attach(clang::ast_matchers::MatchFinder& finder);
52
53 void run(const clang::ast_matchers::MatchFinder::MatchResult& result) override;
54
55 /** @brief The registered classes that were found, in registry order. */
56 [[nodiscard]] std::vector<SignatureClass> classes() const;
57
58 /** @brief Registered classes the scan never reached a definition of. */
59 [[nodiscard]] std::vector<std::string> missing() const;
60
61 [[nodiscard]] const std::vector<std::string>& errors() const noexcept { return m_errors; }
62
63private:
64 std::vector<SignatureEntry> m_entries;
65 std::filesystem::path m_source_root;
66 std::vector<std::optional<SignatureClass>> m_found;
67 std::unordered_set<std::string> m_simple_names;
68 std::set<std::string> m_excluded;
69 std::vector<std::string> m_errors;
70};
71
72}
std::vector< SignatureClass > classes() const
The registered classes that were found, in registry order.
SignatureCollector(std::vector< SignatureEntry > entries, std::filesystem::path source_root)
std::unordered_set< std::string > m_simple_names
std::vector< std::string > missing() const
Registered classes the scan never reached a definition of.
const std::vector< std::string > & errors() const noexcept
std::vector< std::optional< SignatureClass > > m_found
void attach(clang::ast_matchers::MatchFinder &finder)
Registers the matcher for class definitions on finder.
void run()
Definition main.cpp:21
std::vector< SignatureParameter > parameters
One public constructor a Creator method is generated from.
std::vector< ConstructorSignature > constructors
std::set< std::filesystem::path > includes
A registered class as the scan found it.
One class of the Creator registry: the method name, its qualified type and its header.
One constructor parameter: its fully qualified type, its name and its default argument text.