aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-03-22 00:08:40 +0000
committerChris Lattner <sabre@nondot.org>2008-03-22 00:08:40 +0000
commitc68ab77068d1aef6c31f18e941b79201be0f71f3 (patch)
tree7eca8b5b178dcb310df55a080fc112118f5fc4e4
parent21fbe0d9eaf7feac7b7593a3917a8b555eaec714 (diff)
Teach the rewriter how to respect the -o option.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48669 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/ASTConsumers.h1
-rw-r--r--Driver/RewriteTest.cpp37
-rw-r--r--Driver/clang.cpp2
-rw-r--r--test/Rewriter/objc-ivar-receiver-1.m2
4 files changed, 33 insertions, 9 deletions
diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h
index 9c8ae4064c..c72f95ec73 100644
--- a/Driver/ASTConsumers.h
+++ b/Driver/ASTConsumers.h
@@ -50,6 +50,7 @@ ASTConsumer* CreateCFRefChecker(Diagnostic &Diags,
const std::string& FunctionName);
ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
+ const std::string& OutFile,
Diagnostic &Diags,
const LangOptions &LOpts);
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index 239fa2d026..89de81bb38 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -23,7 +23,9 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/System/Path.h"
#include <sstream>
+#include <fstream>
using namespace clang;
using llvm::utostr;
@@ -81,6 +83,8 @@ namespace {
// Needed for header files being rewritten
bool IsHeader;
+ std::ostream &OutFile;
+
static const int OBJC_ABI_VERSION =7 ;
public:
void Initialize(ASTContext &context);
@@ -89,8 +93,9 @@ namespace {
// Top Level Driver code.
virtual void HandleTopLevelDecl(Decl *D);
void HandleDeclInMainFile(Decl *D);
- RewriteTest(bool isHeader, Diagnostic &D, const LangOptions &LOpts) :
- Diags(D), LangOpts(LOpts) {
+ RewriteTest(bool isHeader, std::ostream &outFile,
+ Diagnostic &D, const LangOptions &LOpts)
+ : Diags(D), LangOpts(LOpts), OutFile(outFile) {
IsHeader = isHeader;
RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning,
"rewriting sub-expression within a macro (may not be correct)");
@@ -231,9 +236,28 @@ static bool IsHeaderFile(const std::string &Filename) {
}
ASTConsumer *clang::CreateCodeRewriterTest(const std::string& InFile,
+ const std::string& OutFile,
Diagnostic &Diags,
const LangOptions &LOpts) {
- return new RewriteTest(IsHeaderFile(InFile), Diags, LOpts);
+ // Create the output file.
+
+ std::ostream *Out;
+ if (OutFile == "-") {
+ Out = llvm::cout.stream();
+ } else if (!OutFile.empty()) {
+ Out = new std::ofstream(OutFile.c_str(),
+ std::ios_base::binary|std::ios_base::out);
+ } else if (InFile == "-") {
+ Out = llvm::cout.stream();
+ } else {
+ llvm::sys::Path Path(InFile);
+ Path.eraseSuffix();
+ Path.appendSuffix("cpp");
+ Out = new std::ofstream(Path.toString().c_str(),
+ std::ios_base::binary|std::ios_base::out);
+ }
+
+ return new RewriteTest(IsHeaderFile(InFile), *Out, Diags, LOpts);
}
void RewriteTest::Initialize(ASTContext &context) {
@@ -429,13 +453,12 @@ RewriteTest::~RewriteTest() {
if (const RewriteBuffer *RewriteBuf =
Rewrite.getRewriteBufferFor(MainFileID)) {
//printf("Changed:\n");
- std::string S(RewriteBuf->begin(), RewriteBuf->end());
- printf("%s\n", S.c_str());
+ OutFile << std::string(RewriteBuf->begin(), RewriteBuf->end());
} else {
- printf("No changes\n");
+ fprintf(stderr, "No changes\n");
}
// Emit metadata.
- printf("%s", ResultStr.c_str());
+ OutFile << ResultStr;
}
//===----------------------------------------------------------------------===//
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index b2852e2cd9..f3b8765ea8 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -1044,7 +1044,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
return CreateASTSerializer(InFile, OutputFile, Diag, LangOpts);
case RewriteTest:
- return CreateCodeRewriterTest(InFile, Diag, LangOpts);
+ return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
}
}
diff --git a/test/Rewriter/objc-ivar-receiver-1.m b/test/Rewriter/objc-ivar-receiver-1.m
index 27287dc275..7b01124135 100644
--- a/test/Rewriter/objc-ivar-receiver-1.m
+++ b/test/Rewriter/objc-ivar-receiver-1.m
@@ -1,5 +1,5 @@
// RUN: clang -rewrite-test %s
-// RUN: clang -rewrite-test %s | grep 'newInv->_container'
+// RUN: clang -rewrite-test %s -o - | grep 'newInv->_container'
@interface NSMutableArray
- (void)addObject:(id)addObject;