r218379 - Clean up ClangTool's argument adjuster handling a bit with unique_ptr.
Benjamin Kramer
benny.kra at googlemail.com
Wed Sep 24 04:47:42 PDT 2014
Author: d0k
Date: Wed Sep 24 06:47:42 2014
New Revision: 218379
URL: http://llvm.org/viewvc/llvm-project?rev=218379&view=rev
Log:
Clean up ClangTool's argument adjuster handling a bit with unique_ptr.
Make the dtor non-virtual while there. No functionality change.
Modified:
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/Tooling.cpp
Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=218379&r1=218378&r2=218379&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Wed Sep 24 06:47:42 2014
@@ -203,7 +203,9 @@ class ToolInvocation {
~ToolInvocation();
/// \brief Set a \c DiagnosticConsumer to use during parsing.
- void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer);
+ void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {
+ this->DiagConsumer = DiagConsumer;
+ }
/// \brief Map a virtual file to be used while running the tool.
///
@@ -250,10 +252,12 @@ class ClangTool {
ClangTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths);
- virtual ~ClangTool() { clearArgumentsAdjusters(); }
+ ~ClangTool();
/// \brief Set a \c DiagnosticConsumer to use during parsing.
- void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer);
+ void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) {
+ this->DiagConsumer = DiagConsumer;
+ }
/// \brief Map a virtual file to be used while running the tool.
///
@@ -261,14 +265,6 @@ class ClangTool {
/// \param Content A null terminated buffer of the file's content.
void mapVirtualFile(StringRef FilePath, StringRef Content);
- /// \brief Install command line arguments adjuster.
- ///
- /// \param Adjuster Command line arguments adjuster.
- //
- /// FIXME: Function is deprecated. Use (clear/append)ArgumentsAdjuster instead.
- /// Remove it once all callers are gone.
- void setArgumentsAdjuster(ArgumentsAdjuster *Adjuster);
-
/// \brief Append a command line arguments adjuster to the adjuster chain.
///
/// \param Adjuster An argument adjuster, which will be run on the output of
@@ -300,7 +296,7 @@ class ClangTool {
// Contains a list of pairs (<file name>, <file content>).
std::vector< std::pair<StringRef, StringRef> > MappedFileContents;
- SmallVector<ArgumentsAdjuster *, 2> ArgsAdjusters;
+ SmallVector<std::unique_ptr<ArgumentsAdjuster>, 2> ArgsAdjusters;
DiagnosticConsumer *DiagConsumer;
};
Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=218379&r1=218378&r2=218379&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Wed Sep 24 06:47:42 2014
@@ -186,10 +186,6 @@ ToolInvocation::~ToolInvocation() {
delete Action;
}
-void ToolInvocation::setDiagnosticConsumer(DiagnosticConsumer *D) {
- DiagConsumer = D;
-}
-
void ToolInvocation::mapVirtualFile(StringRef FilePath, StringRef Content) {
SmallString<1024> PathStorage;
llvm::sys::path::native(FilePath, PathStorage);
@@ -275,30 +271,21 @@ ClangTool::ClangTool(const CompilationDa
ArrayRef<std::string> SourcePaths)
: Compilations(Compilations), SourcePaths(SourcePaths),
Files(new FileManager(FileSystemOptions())), DiagConsumer(nullptr) {
- ArgsAdjusters.push_back(new ClangStripOutputAdjuster());
- ArgsAdjusters.push_back(new ClangSyntaxOnlyAdjuster());
+ appendArgumentsAdjuster(new ClangStripOutputAdjuster());
+ appendArgumentsAdjuster(new ClangSyntaxOnlyAdjuster());
}
-void ClangTool::setDiagnosticConsumer(DiagnosticConsumer *D) {
- DiagConsumer = D;
-}
+ClangTool::~ClangTool() {}
void ClangTool::mapVirtualFile(StringRef FilePath, StringRef Content) {
MappedFileContents.push_back(std::make_pair(FilePath, Content));
}
-void ClangTool::setArgumentsAdjuster(ArgumentsAdjuster *Adjuster) {
- clearArgumentsAdjusters();
- appendArgumentsAdjuster(Adjuster);
-}
-
void ClangTool::appendArgumentsAdjuster(ArgumentsAdjuster *Adjuster) {
- ArgsAdjusters.push_back(Adjuster);
+ ArgsAdjusters.push_back(std::unique_ptr<ArgumentsAdjuster>(Adjuster));
}
void ClangTool::clearArgumentsAdjusters() {
- for (unsigned I = 0, E = ArgsAdjusters.size(); I != E; ++I)
- delete ArgsAdjusters[I];
ArgsAdjusters.clear();
}
@@ -341,7 +328,7 @@ int ClangTool::run(ToolAction *Action) {
llvm::report_fatal_error("Cannot chdir into \"" +
Twine(CompileCommand.Directory) + "\n!");
std::vector<std::string> CommandLine = CompileCommand.CommandLine;
- for (ArgumentsAdjuster *Adjuster : ArgsAdjusters)
+ for (const auto &Adjuster : ArgsAdjusters)
CommandLine = Adjuster->Adjust(CommandLine);
assert(!CommandLine.empty());
CommandLine[0] = MainExecutable;
More information about the cfe-commits
mailing list