From 26b6d2aff0076b44fac605de0d3dbfc3f55e64fb Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 4 Apr 2019 18:27:29 +0200 Subject: [PATCH] Refactor struct TargetFileSystemArtifact Creates base class TargetArtifactBase which enable to share code with future new functionalities. --- Source/cmGeneratorExpressionNode.cxx | 77 ++++++++++++++++++---------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 19d2b3a68b..481ea9ed3c 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2023,8 +2023,54 @@ struct TargetFilesystemArtifactResultGetter static std::string Get(const std::string& result) { return result; } }; +struct TargetArtifactBase : public cmGeneratorExpressionNode +{ + TargetArtifactBase() {} // NOLINT(modernize-use-equals-default) + +protected: + cmGeneratorTarget* GetTarget( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const + { + // Lookup the referenced target. + std::string name = parameters.front(); + + if (!cmGeneratorExpression::IsValidTargetName(name)) { + ::reportError(context, content->GetOriginalExpression(), + "Expression syntax not recognized."); + return nullptr; + } + cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name); + if (!target) { + ::reportError(context, content->GetOriginalExpression(), + "No target \"" + name + "\""); + return nullptr; + } + if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY && + target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) { + ::reportError(context, content->GetOriginalExpression(), + "Target \"" + name + + "\" is not an executable or library."); + return nullptr; + } + if (dagChecker && + (dagChecker->EvaluatingLinkLibraries(target) || + (dagChecker->EvaluatingSources() && + target == dagChecker->TopTarget()))) { + ::reportError(context, content->GetOriginalExpression(), + "Expressions which require the linker language may not " + "be used while evaluating link libraries"); + return nullptr; + } + + return target; + } +}; + template -struct TargetFilesystemArtifact : public cmGeneratorExpressionNode +struct TargetFilesystemArtifact : public TargetArtifactBase { TargetFilesystemArtifact() {} // NOLINT(modernize-use-equals-default) @@ -2036,34 +2082,9 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* dagChecker) const override { - // Lookup the referenced target. - std::string name = parameters.front(); - - if (!cmGeneratorExpression::IsValidTargetName(name)) { - ::reportError(context, content->GetOriginalExpression(), - "Expression syntax not recognized."); - return std::string(); - } - cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name); + cmGeneratorTarget* target = + this->GetTarget(parameters, context, content, dagChecker); if (!target) { - ::reportError(context, content->GetOriginalExpression(), - "No target \"" + name + "\""); - return std::string(); - } - if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY && - target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) { - ::reportError(context, content->GetOriginalExpression(), - "Target \"" + name + - "\" is not an executable or library."); - return std::string(); - } - if (dagChecker && - (dagChecker->EvaluatingLinkLibraries(target) || - (dagChecker->EvaluatingSources() && - target == dagChecker->TopTarget()))) { - ::reportError(context, content->GetOriginalExpression(), - "Expressions which require the linker language may not " - "be used while evaluating link libraries"); return std::string(); } context->DependTargets.insert(target);