From 2d8c58f028bbf2f0e0f86a3ccb1281c159ed50ed Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 1 Apr 2016 13:09:21 +0200 Subject: [PATCH] Clang Static Analyzer: Extract ExtraToolChainInfo Change-Id: I16527a4fe5a00327c97ae72f6b76a3daf86d60d1 Reviewed-by: Christian Stenger Reviewed-by: Christian Kandeler --- .../clangstaticanalyzerruncontrol.cpp | 45 ++++++++----------- .../clangstaticanalyzerruncontrol.h | 8 +++- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp index 69ff061c833..91b2d7995c2 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp @@ -71,7 +71,6 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl( const ProjectInfo &projectInfo) : AnalyzerRunControl(runConfiguration, runMode) , m_projectInfo(projectInfo) - , m_wordWidth(runConfiguration->abi().wordWidth()) , m_initialFilesToProcessSize(0) , m_filesAnalyzed(0) , m_filesNotAnalyzed(0) @@ -80,7 +79,11 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl( BuildConfiguration *buildConfiguration = target->activeBuildConfiguration(); QTC_ASSERT(buildConfiguration, return); m_environment = buildConfiguration->environment(); - m_targetTriple = ToolChainKitInformation::toolChain(target->kit())->originalTargetTriple(); + + ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit()); + QTC_ASSERT(toolChain, return); + m_extraToolChainInfo.wordWidth = runConfiguration->abi().wordWidth(); + m_extraToolChainInfo.targetTriple = toolChain->originalTargetTriple(); } static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments, unsigned char wordWidth) @@ -118,8 +121,7 @@ static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments, // Prepends -target if not already included. static QStringList tweakedArguments(const QString &filePath, const QStringList &arguments, - unsigned char wordWidth, - const QString &targetTriple) + const ExtraToolChainInfo &extraParams) { QStringList newArguments; @@ -139,8 +141,8 @@ static QStringList tweakedArguments(const QString &filePath, } QTC_CHECK(skip == false); - prependWordWidthArgumentIfNotIncluded(&newArguments, wordWidth); - prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple); + prependWordWidthArgumentIfNotIncluded(&newArguments, extraParams.wordWidth); + prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, extraParams.targetTriple); return newArguments; } @@ -167,8 +169,7 @@ class ClangStaticAnalyzerOptionsBuilder : public CompilerOptionsBuilder public: static QStringList build(const CppTools::ProjectPart &projectPart, CppTools::ProjectFile::Kind fileKind, - unsigned char wordWidth, - const QString &targetTriple) + const ExtraToolChainInfo &extraParams) { ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart); optionsBuilder.addLanguageOption(fileKind); @@ -192,8 +193,8 @@ public: optionsBuilder.add(QLatin1String("-fPIC")); // TODO: Remove? QStringList options = optionsBuilder.options(); - prependWordWidthArgumentIfNotIncluded(&options, wordWidth); - prependTargetTripleIfNotIncludedAndNotEmpty(&options, targetTriple); + prependWordWidthArgumentIfNotIncluded(&options, extraParams.wordWidth); + prependTargetTripleIfNotIncludedAndNotEmpty(&options, extraParams.targetTriple); return options; } @@ -240,8 +241,7 @@ private: static AnalyzeUnits unitsToAnalyzeFromCompilerCallData( const ProjectInfo::CompilerCallData &compilerCallData, - unsigned char wordWidth, - const QString &targetTriple) + const ExtraToolChainInfo &extraParams) { qCDebug(LOG) << "Taking arguments for analyzing from CompilerCallData."; @@ -253,7 +253,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData( const QString file = it.key(); const QList compilerCalls = it.value(); foreach (const QStringList &options, compilerCalls) { - const QStringList arguments = tweakedArguments(file, options, wordWidth, targetTriple); + const QStringList arguments = tweakedArguments(file, options, extraParams); unitsToAnalyze << AnalyzeUnit(file, arguments); } } @@ -262,8 +262,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData( } static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList projectParts, - unsigned char wordWidth, - const QString &targetTriple) + const ExtraToolChainInfo &extraParams) { qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts."; @@ -281,8 +280,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList const QStringList arguments = ClangStaticAnalyzerOptionsBuilder::build(*projectPart.data(), file.kind, - wordWidth, - targetTriple); + extraParams); unitsToAnalyze << AnalyzeUnit(file.path, arguments); } } @@ -297,15 +295,10 @@ AnalyzeUnits ClangStaticAnalyzerRunControl::sortedUnitsToAnalyze() AnalyzeUnits units; const ProjectInfo::CompilerCallData compilerCallData = m_projectInfo.compilerCallData(); - if (compilerCallData.isEmpty()) { - units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), - m_wordWidth, - m_targetTriple); - } else { - units = unitsToAnalyzeFromCompilerCallData(compilerCallData, - m_wordWidth, - m_targetTriple); - } + if (compilerCallData.isEmpty()) + units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), m_extraToolChainInfo); + else + units = unitsToAnalyzeFromCompilerCallData(compilerCallData, m_extraToolChainInfo); Utils::sort(units, [](const AnalyzeUnit &a1, const AnalyzeUnit &a2) -> bool { return a1.file < a2.file; diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.h b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.h index 17afdf2eee7..525b2a351d2 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.h +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.h @@ -48,6 +48,11 @@ struct AnalyzeUnit { }; typedef QList AnalyzeUnits; +struct ExtraToolChainInfo { + unsigned char wordWidth = 0; + QString targetTriple; +}; + class ClangStaticAnalyzerRunControl : public Debugger::AnalyzerRunControl { Q_OBJECT @@ -82,8 +87,7 @@ private: private: const CppTools::ProjectInfo m_projectInfo; - const unsigned char m_wordWidth; - QString m_targetTriple; + ExtraToolChainInfo m_extraToolChainInfo; Utils::Environment m_environment; QString m_clangExecutable;