| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef CLANGCODEPARSER_H |
| 5 | #define CLANGCODEPARSER_H |
| 6 | |
| 7 | #include "codeparser.h" |
| 8 | #include "parsererror.h" |
| 9 | #include "config.h" |
| 10 | |
| 11 | #include <QtCore/qtemporarydir.h> |
| 12 | #include <QtCore/QStringList> |
| 13 | |
| 14 | #include <optional> |
| 15 | |
| 16 | typedef struct CXTranslationUnitImpl *CXTranslationUnit; |
| 17 | |
| 18 | class CppCodeParser; |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | struct ParsedCppFileIR { |
| 23 | std::vector<UntiedDocumentation> untied; |
| 24 | std::vector<TiedDocumentation> tied; |
| 25 | }; |
| 26 | |
| 27 | struct PCHFile { |
| 28 | QTemporaryDir dir; |
| 29 | QByteArray name; |
| 30 | }; |
| 31 | |
| 32 | std::optional<PCHFile> ( |
| 33 | QDocDatabase* qdb, |
| 34 | QString , |
| 35 | const std::set<Config::HeaderFilePath>& , |
| 36 | const std::vector<QByteArray>& include_paths, |
| 37 | const QList<QByteArray>& defines |
| 38 | ); |
| 39 | |
| 40 | struct FnCommandParser { |
| 41 | FnCommandParser( |
| 42 | QDocDatabase* qdb, |
| 43 | const std::set<Config::HeaderFilePath>& , |
| 44 | const QList<QByteArray>& defines, |
| 45 | std::optional<std::reference_wrapper<const PCHFile>> pch |
| 46 | ) : m_qdb{qdb}, |
| 47 | m_allHeaders{all_headers}, |
| 48 | m_defines{defines}, |
| 49 | m_args{}, |
| 50 | m_pch{pch} |
| 51 | {} |
| 52 | |
| 53 | std::variant<Node*, FnMatchError> operator()( |
| 54 | const Location &location, |
| 55 | const QString &fnSignature, |
| 56 | const QString &idTag, |
| 57 | QStringList context |
| 58 | ); |
| 59 | |
| 60 | private: |
| 61 | QDocDatabase* m_qdb; |
| 62 | const std::set<Config::HeaderFilePath>& m_allHeaders; // file name->path |
| 63 | QList<QByteArray> m_defines {}; |
| 64 | std::vector<const char *> m_args {}; |
| 65 | std::optional<std::reference_wrapper<const PCHFile>> m_pch; |
| 66 | }; |
| 67 | |
| 68 | class ClangCodeParser |
| 69 | { |
| 70 | public: |
| 71 | ClangCodeParser( |
| 72 | QDocDatabase* qdb, |
| 73 | Config&, |
| 74 | const std::vector<QByteArray>& include_paths, |
| 75 | const QList<QByteArray>& defines, |
| 76 | std::optional<std::reference_wrapper<const PCHFile>> pch |
| 77 | ); |
| 78 | |
| 79 | ParsedCppFileIR parse_cpp_file(const QString &filePath); |
| 80 | |
| 81 | private: |
| 82 | QDocDatabase* m_qdb{}; |
| 83 | std::set<Config::HeaderFilePath> {}; // file name->path |
| 84 | const std::vector<QByteArray>& m_includePaths; |
| 85 | QList<QByteArray> m_defines {}; |
| 86 | std::vector<const char *> m_args {}; |
| 87 | QStringList m_namespaceScope {}; |
| 88 | QByteArray s_fn; |
| 89 | std::optional<std::reference_wrapper<const PCHFile>> m_pch; |
| 90 | }; |
| 91 | |
| 92 | QT_END_NAMESPACE |
| 93 | |
| 94 | #endif |
| 95 | |