10#include <QtCore/qloggingcategory.h>
11#include <QtCore/qregularexpression.h>
12#include <QtCore/qstring.h>
15QT_WARNING_DISABLE_MSVC(4100)
16QT_WARNING_DISABLE_MSVC(4146)
17QT_WARNING_DISABLE_MSVC(4267)
18QT_WARNING_DISABLE_MSVC(4624)
19QT_WARNING_DISABLE_GCC(
"-Wnonnull")
21#include <llvm/ADT/StringRef.h>
22#include <clang/Basic/SourceLocation.h>
23#include <clang/Basic/SourceManager.h>
24#include <clang/Basic/FileManager.h>
38 return QString::fromUtf8(str.data(), str.size());
41#define LUPDATE_CLANG_VERSION_CHECK(major, minor, patch) ((major<<16
)|(minor<<8
)|(patch))
43 LUPDATE_CLANG_VERSION_MINOR, LUPDATE_CLANG_VERSION_PATCH)
71 switch (trFunctionAliasManager.trFunctionByName(funcName)) {
74 if (contextArg.isEmpty()) {
76 std::stringstream warning;
77 warning << qPrintable(lupdateLocationFile) <<
":"
78 << lupdateLocationLine <<
":"
79 << locationCol <<
": "
80 <<
" \'" << qPrintable(funcName)
81 <<
"\' cannot be called without context."
82 <<
" The call is ignored." <<std::endl;
83 lupdateWarning.append(QString::fromStdString(warning.str()));
90 if (lupdateSource.isEmpty()) {
92 std::stringstream warning;
93 warning << qPrintable(lupdateLocationFile) <<
":"
94 << lupdateLocationLine <<
":"
95 << locationCol <<
": "
96 <<
" \'" << qPrintable(funcName)
97 <<
"\' cannot be called without source."
98 <<
" The call is ignored." << std::endl;
99 lupdateWarning.append(QString::fromStdString(warning.str()));
112 if (contextArg.isEmpty() || lupdateSource.isEmpty()) {
114 std::stringstream warning;
115 warning << qPrintable(lupdateLocationFile) <<
":"
116 << lupdateLocationLine <<
":"
117 << locationCol <<
": "
118 <<
" \'" << qPrintable(funcName)
119 <<
"\' cannot be called without context or source."
120 <<
" The call is ignored." << std::endl;
121 lupdateWarning.append(QString::fromStdString(warning.str()));
131 if (lupdateId.isEmpty()) {
133 std::stringstream warning;
134 warning << qPrintable(lupdateLocationFile) <<
":"
135 << lupdateLocationLine <<
":"
136 << locationCol <<
": "
137 <<
" \'" << qPrintable(funcName)
138 <<
"\' cannot be called without Id."
139 <<
" The call is ignored." << std::endl;
140 lupdateWarning.append(QString::fromStdString(warning.str()));
146 if (funcName == QStringLiteral(
"TRANSLATOR") && lupdateComment.isEmpty()) {
148 std::stringstream warning;
149 warning << qPrintable(lupdateLocationFile) <<
":"
150 << lupdateLocationLine <<
":"
151 << locationCol <<
": "
152 << qPrintable(funcName)
153 <<
" cannot be called without comment."
154 <<
" The call is ignored." << std::endl;
155 lupdateWarning.append(QString::fromStdString(warning.str()));
160 return !lupdateLocationFile.isEmpty() && (lupdateLocationLine > -1) && (locationCol > -1);
166 auto sourceFile = sourceManager.getFileManager()
167 .getFile(lupdateLocationFile.toStdString());
169 sourceLocation = sourceManager.translateFileLineCol(sourceFile.get(),
170 lupdateLocationLine, locationCol);
172 sourceLocation = sourceManager.translateFileLineCol(sourceFile, lupdateLocationLine,
181 qCDebug(lcClang) <<
"------------------ Printing Store----------------------------------\n";
183 <<
"callType : " << callType <<
"\n"
184 <<
"rawCode : \n" << rawCode <<
"\n"
185 <<
"funcName : " << funcName <<
"\n"
186 <<
"LocationCol : " << locationCol <<
"\n"
187 <<
"contextArg : " << contextArg <<
"\n"
188 <<
"contextRetrieved : " << contextRetrieved <<
"\n"
189 <<
"lupdateSource : " << lupdateSource <<
"\n"
190 <<
"lupdateLocationFile : " << lupdateLocationFile <<
"\n"
191 <<
"lupdateLocationLine : " << lupdateLocationLine <<
"\n"
192 <<
"lupdateId : " << lupdateId <<
"\n"
193 <<
"lupdateIdMetaData : " << lupdateIdMetaData <<
"\n"
194 <<
"lupdateMagicMetaData: " << lupdateMagicMetaData <<
"\n"
195 <<
"lupdateComment : " << lupdateComment <<
"\n"
196 <<
"lupdateExtraComment : " << lupdateExtraComment <<
"\n"
197 <<
"lupdatePlural : " << lupdatePlural;
198 qCDebug(lcClang) <<
"-------------------------------------------------------------------\n";
201using TranslationStores = std::vector<TranslationRelatedStore>;
205 Stores(TranslationStores &a, TranslationStores &qd, TranslationStores &qn)
224 result.replace(QLatin1String(
"\r\n"), QLatin1String(
"\n"));
240
241
242
243
244
250 if (!s.consume_front(
"\"") && ((quote &
Left) != 0))
252 if (!s.consume_back(
"\"") && ((quote &
Right) != 0))
254 return fixedLineEndings(toQt(s));
258
259
260
261
267 const QString string = fixedLineEndings(QString::fromStdString(token).trimmed());
268 const int index = string.indexOf(QLatin1Char(
'"'));
272 QRegularExpressionMatch result;
273 if (string.at(index - 1) == QLatin1Char(
'R')) {
274 static const QRegularExpression rawStringLiteral {
276 "(?:\\bu8|\\b[LuU])??R\\\"([^\\(\\)\\\\ ]{0,16})\\((?<characters>.*)\\)\\1\\\""
277 ), QRegularExpression::DotMatchesEverythingOption };
278 result = rawStringLiteral.match(string);
280 static const QRegularExpression stringLiteral {
282 "(?:\\bu8|\\b[LuU])+?\\\"(?<characters>[^\\\"\\\\]*(?:\\\\.[^\\\"\\\\]*)*)\\\""
285 result = stringLiteral.match(string);
287 if (result.hasMatch())
288 return result.captured(QStringLiteral(
"characters"));
301 const QString &id,
bool plural,
bool isID,
bool isWarningOnly =
false);
304 WriteSynchronizedRef<TranslationRelatedStore> &newAst,
const TranslationStores &qDecl);
306 WriteSynchronizedRef<TranslationRelatedStore> &newAst);
void HandleTranslationUnit(clang::ASTContext &context) override
LupdateASTConsumer(clang::ASTContext *context, Stores *stores)
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &compiler, llvm::StringRef) override
LupdateFrontendAction(Stores *stores)
bool operator()(const clang::RawComment &LHS, const clang::RawComment &RHS)
BeforeThanCompare(const clang::SourceManager &SM)
bool operator()(const clang::RawComment *LHS, const clang::RawComment *RHS)
bool VisitNamedDecl(clang::NamedDecl *namedDeclaration)
void findContextForTranslationStoresFromPP(clang::NamedDecl *namedDeclaration)
LupdateVisitor(clang::ASTContext *context, Stores *stores)
bool VisitCallExpr(clang::CallExpr *callExpression)
void processPreprocessorCalls()
QT_WARNING_PUSH QT_WARNING_POP QT_BEGIN_NAMESPACE QString toQt(llvm::StringRef str)
#define LUPDATE_CLANG_VERSION
#define LUPDATE_CLANG_VERSION_CHECK(major, minor, patch)
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)
bool hasQuote(llvm::StringRef source)
QString cleanQuote(const std::string &token)
void exploreChildrenForFirstStringLiteral(clang::Stmt *stmt, QString &context)
bool trFunctionPresent(llvm::StringRef text)
QString exploreBases(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm)
QString cleanQuote(llvm::StringRef s, QuoteCompulsary quote)
bool isPointWithin(const clang::SourceRange &sourceRange, const clang::SourceLocation &point, const clang::SourceManager &sm)
bool isQObjectOrQDeclareTrFunctionMacroDeclared(clang::CXXRecordDecl *recordDecl, QString &context, const clang::SourceManager &sm)
static bool capture(const QRegularExpression &exp, const QString &line, QString *i, QString *c)
bool isFileSignificant(const std::string &filePath)
QString fixedLineEndings(const QString &s)
QString contextForFunctionDecl(clang::FunctionDecl *func, const std::string &funcName)
QString contextForNoopMacro(clang::NamedDecl *namedDecl, const clang::SourceManager &sm)
QString lookForContext(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm)
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)
Stores(TranslationStores &a, TranslationStores &qd, TranslationStores &qn)
WriteSynchronizedRef< TranslationRelatedStore > QDeclareTrWithContext
WriteSynchronizedRef< TranslationRelatedStore > QNoopTranlsationWithContext
TranslationStores Preprocessor
WriteSynchronizedRef< TranslationRelatedStore > AST