Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
lupdatepreprocessoraction.h
Go to the documentation of this file.
1// Copyright (C) 2020 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 LUPDATEPREPROCESSORACTION_H
5#define LUPDATEPREPROCESSORACTION_H
6
7#include "cpp_clang.h"
8#include "synchronized.h"
9
10QT_WARNING_PUSH
11QT_WARNING_DISABLE_MSVC(4100)
12QT_WARNING_DISABLE_MSVC(4146)
13QT_WARNING_DISABLE_MSVC(4267)
14QT_WARNING_DISABLE_MSVC(4624)
15QT_WARNING_DISABLE_GCC("-Wnonnull")
16
17#include <clang/Frontend/CompilerInstance.h>
18#include <clang/Frontend/FrontendActions.h>
19#include <clang/Tooling/Tooling.h>
20#include <clang/Lex/PPCallbacks.h>
21#include <clang/Lex/Preprocessor.h>
22
23QT_WARNING_POP
24
25#include <memory>
26
27QT_BEGIN_NAMESPACE
28
29class LupdatePPCallbacks : public clang::PPCallbacks
30{
31public:
32 LupdatePPCallbacks(WriteSynchronizedRef<TranslationRelatedStore> *stores, clang::Preprocessor &pp)
33 : m_preprocessor(pp)
34 , m_stores(stores)
35 {
36 const auto &sm = m_preprocessor.getSourceManager();
37 m_inputFile = sm.getFileEntryRefForID(sm.getMainFileID())->getName();
38 }
39
40 ~LupdatePPCallbacks() override
41 {
42 m_stores->emplace_bulk(std::move(m_ppStores));
43 }
44
45private:
46 void MacroExpands(const clang::Token &token, const clang::MacroDefinition &macroDefinition,
47 clang::SourceRange sourceRange, const clang::MacroArgs *macroArgs) override;
48
49 void storeMacroArguments(const std::vector<QString> &args, TranslationRelatedStore *store);
50
51 void SourceRangeSkipped(clang::SourceRange sourceRange, clang::SourceLocation endifLoc) override;
53 void InclusionDirective(clang::SourceLocation /*hashLoc*/, const clang::Token &/*includeTok*/,
54 clang::StringRef /*fileName*/, bool /*isAngled*/,
55 clang::CharSourceRange /*filenameRange*/,
57 const clang::OptionalFileEntryRef file,
59 const clang::Optional<clang::FileEntryRef> file,
60#else
61 const clang::FileEntry *file,
62#endif
63 clang::StringRef /*searchPath*/, clang::StringRef /*relativePath*/,
64 const clang::Module */*imported*/,
65 clang::SrcMgr::CharacteristicKind /*fileType*/) override;
66#endif
67
68 std::string m_inputFile;
69 clang::Preprocessor &m_preprocessor;
70
71 TranslationStores m_ppStores;
72 WriteSynchronizedRef<TranslationRelatedStore> *m_stores { nullptr };
73};
74
75class LupdatePreprocessorAction : public clang::PreprocessOnlyAction
76{
77public:
78 LupdatePreprocessorAction(WriteSynchronizedRef<TranslationRelatedStore> *stores)
80 {}
81
82private:
92
93private:
95};
96
97class LupdatePreprocessorActionFactory : public clang::tooling::FrontendActionFactory
98{
99public:
100 explicit LupdatePreprocessorActionFactory(WriteSynchronizedRef<TranslationRelatedStore> *stores)
102 {}
103
106 {
108 }
109#else
114#endif
115
116private:
118};
119
120QT_END_NAMESPACE
121
122#endif
LupdateToolActionFactory(Stores *stores)
void setWarningOnly(bool isWarningOnly)
void setExtras(const ExtraData &extras)
void setLineNumber(int lineNumber)
static clang::tooling::ArgumentsAdjuster getClangArgumentAdjuster()
#define START_THREADS(RSV, WSV)
QByteArrayList getIncludePathsFromCompiler()
static bool generateCompilationDatabase(const QString &outputFilePath, const ConversionData &cd)
static void sortMessagesByFileOrder(ClangCppParser::TranslatorMessageVector &messages, const QStringList &files)
static QString getSysCompiler()
Definition cpp_clang.cpp:44
static QString ensureCanonicalPath(const QString &filePath)
static QByteArray frameworkSuffix()
Definition cpp_clang.cpp:97
static std::vector< std::string > aliasDefinition
#define JOIN_THREADS(WSV)
static QStringList getProjectDirsFromEnvironment()
Definition cpp_clang.cpp:81
static QByteArrayList getMSVCIncludePathsFromEnvironment()
Definition cpp_clang.cpp:68
#define LUPDATE_CLANG_VERSION
Definition cpp_clang.h:42
#define LUPDATE_CLANG_VERSION_CHECK(major, minor, patch)
Definition cpp_clang.h:41
std::vector< std::string > getAliasFunctionDefinition()
void finalize(ReadSynchronizedRef< TranslationRelatedStore > &ast, WriteSynchronizedRef< TranslationRelatedStore > &newAst)
bool stringContainsTranslationInformation(llvm::StringRef ba)
void correctAstTranslationContext(ReadSynchronizedRef< TranslationRelatedStore > &ast, WriteSynchronizedRef< TranslationRelatedStore > &newAst, const TranslationStores &qDecl)
void collectMessages(TranslatorMessageVector &result, TranslationRelatedStore &store)
TranslatorMessage translatorMessage(const TranslationRelatedStore &store, const QString &id, bool plural, bool isID, bool isWarningOnly=false)
void loadCPP(Translator &translator, const QStringList &filenames, ConversionData &cd, bool *fail)
QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
bool isValid(bool printwarning=false)
Definition cpp_clang.h:69