From c81e2906c15fc34a1801624838daa0af3b2cab4c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 10 Mar 2014 17:55:02 +0000 Subject: [PATCH] [C++11] Avoid implicit conversion of ArrayRef to std::vector and use move semantics where appropriate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203477 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchersInternal.h | 13 +++++++------ include/clang/ASTMatchers/Dynamic/VariantValue.h | 4 ++-- include/clang/Tooling/CompilationDatabase.h | 4 ++-- lib/ASTMatchers/Dynamic/Marshallers.h | 4 ++-- lib/ASTMatchers/Dynamic/VariantValue.cpp | 16 ++++++++-------- lib/Basic/VirtualFileSystem.cpp | 6 +----- lib/StaticAnalyzer/Core/BugReporter.cpp | 6 ++---- lib/Tooling/CompilationDatabase.cpp | 3 ++- 8 files changed, 26 insertions(+), 30 deletions(-) diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index dff7fd7aa5..45c5d7ae6e 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1106,8 +1106,8 @@ template class VariadicOperatorMatcherInterface : public MatcherInterface { public: VariadicOperatorMatcherInterface(VariadicOperatorFunction Func, - ArrayRef InnerMatchers) - : Func(Func), InnerMatchers(InnerMatchers) {} + std::vector InnerMatchers) + : Func(Func), InnerMatchers(std::move(InnerMatchers)) {} virtual bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const { @@ -1150,7 +1150,8 @@ public: addMatcher(Param3, Matchers); addMatcher(Param4, Matchers); addMatcher(Param5, Matchers); - return Matcher(new VariadicOperatorMatcherInterface(Func, Matchers)); + return Matcher( + new VariadicOperatorMatcherInterface(Func, std::move(Matchers))); } private: @@ -1246,8 +1247,8 @@ bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode DynNode, template inline Matcher DynTypedMatcher::unconditionalConvertTo() const { - return Matcher( - new VariadicOperatorMatcherInterface(AllOfVariadicOperator, *this)); + return Matcher(new VariadicOperatorMatcherInterface( + AllOfVariadicOperator, llvm::makeArrayRef(*this))); } /// \brief Creates a Matcher that matches if all inner matchers match. @@ -1259,7 +1260,7 @@ BindableMatcher makeAllOfComposite( DynMatchers.push_back(*InnerMatchers[i]); } return BindableMatcher(new VariadicOperatorMatcherInterface( - AllOfVariadicOperator, DynMatchers)); + AllOfVariadicOperator, std::move(DynMatchers))); } /// \brief Creates a Matcher that matches if diff --git a/include/clang/ASTMatchers/Dynamic/VariantValue.h b/include/clang/ASTMatchers/Dynamic/VariantValue.h index 1a69a64127..c6853572ec 100644 --- a/include/clang/ASTMatchers/Dynamic/VariantValue.h +++ b/include/clang/ASTMatchers/Dynamic/VariantValue.h @@ -78,14 +78,14 @@ public: /// \brief Clones the provided matchers. /// /// They should be the result of a polymorphic matcher. - static VariantMatcher PolymorphicMatcher(ArrayRef Matchers); + static VariantMatcher PolymorphicMatcher(std::vector Matchers); /// \brief Creates a 'variadic' operator matcher. /// /// It will bind to the appropriate type on getTypedMatcher(). static VariantMatcher VariadicOperatorMatcher( ast_matchers::internal::VariadicOperatorFunction Func, - ArrayRef Args); + std::vector Args); /// \brief Makes the matcher the "null" matcher. void reset(); diff --git a/include/clang/Tooling/CompilationDatabase.h b/include/clang/Tooling/CompilationDatabase.h index 33a9eea0fb..3edd0d164b 100644 --- a/include/clang/Tooling/CompilationDatabase.h +++ b/include/clang/Tooling/CompilationDatabase.h @@ -42,8 +42,8 @@ namespace tooling { /// \brief Specifies the working directory and command of a compilation. struct CompileCommand { CompileCommand() {} - CompileCommand(Twine Directory, ArrayRef CommandLine) - : Directory(Directory.str()), CommandLine(CommandLine) {} + CompileCommand(Twine Directory, std::vector CommandLine) + : Directory(Directory.str()), CommandLine(std::move(CommandLine)) {} /// \brief The working directory the command was executed from. std::string Directory; diff --git a/lib/ASTMatchers/Dynamic/Marshallers.h b/lib/ASTMatchers/Dynamic/Marshallers.h index d2259c4e93..77268076f0 100644 --- a/lib/ASTMatchers/Dynamic/Marshallers.h +++ b/lib/ASTMatchers/Dynamic/Marshallers.h @@ -260,7 +260,7 @@ static VariantMatcher outvalueToVariantMatcher(const T &PolyMatcher, NULL) { std::vector Matchers; mergePolyMatchers(PolyMatcher, Matchers, typename T::ReturnTypes()); - VariantMatcher Out = VariantMatcher::PolymorphicMatcher(Matchers); + VariantMatcher Out = VariantMatcher::PolymorphicMatcher(std::move(Matchers)); return Out; } @@ -609,7 +609,7 @@ public: } InnerArgs.push_back(Value.getMatcher()); } - return VariantMatcher::VariadicOperatorMatcher(Func, InnerArgs); + return VariantMatcher::VariadicOperatorMatcher(Func, std::move(InnerArgs)); } bool isVariadic() const { return true; } diff --git a/lib/ASTMatchers/Dynamic/VariantValue.cpp b/lib/ASTMatchers/Dynamic/VariantValue.cpp index 70d37ca399..9c7262e34f 100644 --- a/lib/ASTMatchers/Dynamic/VariantValue.cpp +++ b/lib/ASTMatchers/Dynamic/VariantValue.cpp @@ -48,8 +48,8 @@ private: class VariantMatcher::PolymorphicPayload : public VariantMatcher::Payload { public: - PolymorphicPayload(ArrayRef MatchersIn) - : Matchers(MatchersIn) {} + PolymorphicPayload(std::vector MatchersIn) + : Matchers(std::move(MatchersIn)) {} virtual ~PolymorphicPayload() {} @@ -98,8 +98,8 @@ public: class VariantMatcher::VariadicOpPayload : public VariantMatcher::Payload { public: VariadicOpPayload(ast_matchers::internal::VariadicOperatorFunction Func, - ArrayRef Args) - : Func(Func), Args(Args) {} + std::vector Args) + : Func(Func), Args(std::move(Args)) {} virtual llvm::Optional getSingleMatcher() const { return llvm::Optional(); @@ -131,14 +131,14 @@ VariantMatcher VariantMatcher::SingleMatcher(const DynTypedMatcher &Matcher) { } VariantMatcher -VariantMatcher::PolymorphicMatcher(ArrayRef Matchers) { - return VariantMatcher(new PolymorphicPayload(Matchers)); +VariantMatcher::PolymorphicMatcher(std::vector Matchers) { + return VariantMatcher(new PolymorphicPayload(std::move(Matchers))); } VariantMatcher VariantMatcher::VariadicOperatorMatcher( ast_matchers::internal::VariadicOperatorFunction Func, - ArrayRef Args) { - return VariantMatcher(new VariadicOpPayload(Func, Args)); + std::vector Args) { + return VariantMatcher(new VariadicOpPayload(Func, std::move(Args))); } llvm::Optional VariantMatcher::getSingleMatcher() const { diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index bfc2db73e8..9a88cfd389 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -253,13 +253,9 @@ class DirectoryEntry : public Entry { public: virtual ~DirectoryEntry(); -#if LLVM_HAS_RVALUE_REFERENCES DirectoryEntry(StringRef Name, std::vector Contents, Status S) : Entry(EK_Directory, Name), Contents(std::move(Contents)), S(std::move(S)) {} -#endif - DirectoryEntry(StringRef Name, ArrayRef Contents, const Status &S) - : Entry(EK_Directory, Name), Contents(Contents), S(S) {} Status getStatus() { return S; } typedef std::vector::iterator iterator; iterator contents_begin() { return Contents.begin(); } @@ -612,7 +608,7 @@ class VFSFromYAMLParser { for (sys::path::reverse_iterator I = sys::path::rbegin(Parent), E = sys::path::rend(Parent); I != E; ++I) { - Result = new DirectoryEntry(*I, Result, + Result = new DirectoryEntry(*I, llvm::makeArrayRef(Result), Status("", "", getNextVirtualUniqueID(), sys::TimeValue::now(), 0, 0, 0, file_type::directory_file, sys::fs::all_all)); } diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index db684883af..1b55cdec58 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -3399,10 +3399,8 @@ void BugReporter::FlushReport(BugReportEquivClass& EQ) { SmallVector bugReports; BugReport *exampleReport = FindReportInEquivalenceClass(EQ, bugReports); if (exampleReport) { - const PathDiagnosticConsumers &C = getPathDiagnosticConsumers(); - for (PathDiagnosticConsumers::const_iterator I=C.begin(), - E=C.end(); I != E; ++I) { - FlushReport(exampleReport, **I, bugReports); + for (PathDiagnosticConsumer *PDC : getPathDiagnosticConsumers()) { + FlushReport(exampleReport, *PDC, bugReports); } } } diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 57424e37e9..b513446a54 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -303,7 +303,8 @@ FixedCompilationDatabase(Twine Directory, ArrayRef CommandLine) { std::vector ToolCommandLine(1, "clang-tool"); ToolCommandLine.insert(ToolCommandLine.end(), CommandLine.begin(), CommandLine.end()); - CompileCommands.push_back(CompileCommand(Directory, ToolCommandLine)); + CompileCommands.push_back( + CompileCommand(Directory, std::move(ToolCommandLine))); } std::vector -- 2.40.0