[PATCH] [PATCH] Repost using Phabricator of ArgumentsAdjuster change (part 1)
John Thompson
john.thompson.jtsoftware at gmail.com
Mon Aug 12 11:44:14 PDT 2013
Hi klimek,
This is just a repost of the patch from the email entitled "{PATCH] clang::tooling::ArgumentAdjuster - Add file name argument to Adjust callback" redone using Phabricator for the first time.
Note that there is another part coming from the separate repository for clang-extra-tools. Can these be put into one Phabricator post? Maybe I need to paste the combined text instead of a patch file link.
http://llvm-reviews.chandlerc.com/D1367
Files:
include/clang/Tooling/ArgumentsAdjusters.h
tools/clang-check/ClangCheck.cpp
unittests/Tooling/ToolingTest.cpp
lib/Tooling/ArgumentsAdjusters.cpp
lib/Tooling/Tooling.cpp
Index: include/clang/Tooling/ArgumentsAdjusters.h
===================================================================
--- include/clang/Tooling/ArgumentsAdjusters.h
+++ include/clang/Tooling/ArgumentsAdjusters.h
@@ -16,6 +16,7 @@
#ifndef LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
#define LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
+#include "llvm/ADT/StringRef.h"
#include <string>
#include <vector>
@@ -36,10 +37,12 @@
public:
/// \brief Returns adjusted command line arguments.
///
+ /// \param InputFile Input file.
/// \param Args Input sequence of command line arguments.
///
/// \returns Modified sequence of command line arguments.
- virtual CommandLineArguments Adjust(const CommandLineArguments &Args) = 0;
+ virtual CommandLineArguments Adjust(llvm::StringRef InputFile,
+ const CommandLineArguments &Args) = 0;
virtual ~ArgumentsAdjuster() {
}
};
@@ -49,13 +52,15 @@
/// This class implements ArgumentsAdjuster interface and converts input
/// command line arguments to the "syntax check only" variant.
class ClangSyntaxOnlyAdjuster : public ArgumentsAdjuster {
- virtual CommandLineArguments Adjust(const CommandLineArguments &Args);
+ virtual CommandLineArguments Adjust(llvm::StringRef InputFile,
+ const CommandLineArguments &Args);
};
/// \brief An argument adjuster which removes output-related command line
/// arguments.
class ClangStripOutputAdjuster : public ArgumentsAdjuster {
- virtual CommandLineArguments Adjust(const CommandLineArguments &Args);
+ virtual CommandLineArguments Adjust(llvm::StringRef InputFile,
+ const CommandLineArguments &Args);
};
} // end namespace tooling
Index: tools/clang-check/ClangCheck.cpp
===================================================================
--- tools/clang-check/ClangCheck.cpp
+++ tools/clang-check/ClangCheck.cpp
@@ -146,7 +146,8 @@
}
virtual CommandLineArguments
- Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE {
+ Adjust(llvm::StringRef InputFile,
+ const CommandLineArguments &Args) LLVM_OVERRIDE {
CommandLineArguments Return(Args);
CommandLineArguments::iterator I;
Index: unittests/Tooling/ToolingTest.cpp
===================================================================
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -196,18 +196,22 @@
struct CheckSyntaxOnlyAdjuster: public ArgumentsAdjuster {
bool &Found;
bool &Ran;
+ std::string &File;
- CheckSyntaxOnlyAdjuster(bool &Found, bool &Ran) : Found(Found), Ran(Ran) { }
+ CheckSyntaxOnlyAdjuster(bool &Found, bool &Ran, std::string &File)
+ : Found(Found), Ran(Ran), File(File) { }
virtual CommandLineArguments
- Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE {
+ Adjust(llvm::StringRef InputFile,
+ const CommandLineArguments &Args) LLVM_OVERRIDE {
Ran = true;
for (unsigned I = 0, E = Args.size(); I != E; ++I) {
if (Args[I] == "-fsyntax-only") {
Found = true;
break;
}
}
+ File = InputFile;
return Args;
}
};
@@ -220,18 +224,22 @@
bool Found = false;
bool Ran = false;
- Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran));
+ std::string File;
+ Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran, File));
Tool.run(newFrontendActionFactory<SyntaxOnlyAction>());
EXPECT_TRUE(Ran);
EXPECT_TRUE(Found);
+ EXPECT_TRUE(File.compare(File.length() - 4, 4, "a.cc") == 0);
Ran = Found = false;
+ File.clear();
Tool.clearArgumentsAdjusters();
- Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran));
+ Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran, File));
Tool.appendArgumentsAdjuster(new ClangSyntaxOnlyAdjuster());
Tool.run(newFrontendActionFactory<SyntaxOnlyAction>());
EXPECT_TRUE(Ran);
EXPECT_FALSE(Found);
+ EXPECT_TRUE(File.compare(File.length() - 4, 4, "a.cc") == 0);
}
} // end namespace tooling
Index: lib/Tooling/ArgumentsAdjusters.cpp
===================================================================
--- lib/Tooling/ArgumentsAdjusters.cpp
+++ lib/Tooling/ArgumentsAdjusters.cpp
@@ -24,7 +24,8 @@
/// Add -fsyntax-only option to the commnand line arguments.
CommandLineArguments
-ClangSyntaxOnlyAdjuster::Adjust(const CommandLineArguments &Args) {
+ClangSyntaxOnlyAdjuster::Adjust(StringRef InputFile,
+ const CommandLineArguments &Args) {
CommandLineArguments AdjustedArgs;
for (size_t i = 0, e = Args.size(); i != e; ++i) {
StringRef Arg = Args[i];
@@ -38,7 +39,8 @@
}
CommandLineArguments
-ClangStripOutputAdjuster::Adjust(const CommandLineArguments &Args) {
+ClangStripOutputAdjuster::Adjust(llvm::StringRef InputFile,
+ const CommandLineArguments &Args) {
CommandLineArguments AdjustedArgs;
for (size_t i = 0, e = Args.size(); i < e; ++i) {
StringRef Arg = Args[i];
Index: lib/Tooling/Tooling.cpp
===================================================================
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -308,7 +308,7 @@
CompileCommands[I].second.Directory + "\n!");
std::vector<std::string> CommandLine = CompileCommands[I].second.CommandLine;
for (unsigned I = 0, E = ArgsAdjusters.size(); I != E; ++I)
- CommandLine = ArgsAdjusters[I]->Adjust(CommandLine);
+ CommandLine = ArgsAdjusters[I]->Adjust(File, CommandLine);
assert(!CommandLine.empty());
CommandLine[0] = MainExecutable;
// FIXME: We need a callback mechanism for the tool writer to output a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1367.1.patch
Type: text/x-patch
Size: 5848 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130812/5a729d91/attachment.bin>
More information about the cfe-commits
mailing list