From 945a3b145a857737ff49e233f9549be569762f3e Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Mon, 10 Mar 2008 20:43:59 +0000 Subject: [PATCH] Pass LangOptions to RewriteTest(). llvm-svn: 48172 --- clang/Driver/ASTConsumers.h | 3 ++- clang/Driver/RewriteTest.cpp | 23 +++++++++++++++++++---- clang/Driver/clang.cpp | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index 63f769f06a39..815f3cc43865 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -50,7 +50,8 @@ ASTConsumer* CreateCFRefChecker(Diagnostic &Diags, const std::string& FunctionName); ASTConsumer *CreateCodeRewriterTest(const std::string& InFile, - Diagnostic &Diags); + Diagnostic &Diags, + const LangOptions &LOpts); ASTConsumer *CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr, diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp index 097aa1b3a598..2b48a6358730 100644 --- a/clang/Driver/RewriteTest.cpp +++ b/clang/Driver/RewriteTest.cpp @@ -35,6 +35,7 @@ namespace { class RewriteTest : public ASTConsumer { Rewriter Rewrite; Diagnostic &Diags; + const LangOptions &LangOpts; unsigned RewriteFailedDiag; ASTContext *Context; @@ -84,7 +85,8 @@ namespace { // Top Level Driver code. virtual void HandleTopLevelDecl(Decl *D); void HandleDeclInMainFile(Decl *D); - RewriteTest(bool isHeader, Diagnostic &D) : Diags(D) { + RewriteTest(bool isHeader, Diagnostic &D, const LangOptions &LOpts) : + Diags(D), LangOpts(LOpts) { IsHeader = isHeader; RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning, "rewriting sub-expression within a macro (may not be correct)"); @@ -224,8 +226,9 @@ static bool IsHeaderFile(const std::string &Filename) { } ASTConsumer *clang::CreateCodeRewriterTest(const std::string& InFile, - Diagnostic &Diags) { - return new RewriteTest(IsHeaderFile(InFile), Diags); + Diagnostic &Diags, + const LangOptions &LOpts) { + return new RewriteTest(IsHeaderFile(InFile), Diags, LOpts); } void RewriteTest::Initialize(ASTContext &context) { @@ -298,6 +301,11 @@ void RewriteTest::Initialize(ASTContext &context) { "unsigned long extra[5];\n};\n" "#define __FASTENUMERATIONSTATE\n" "#endif\n"; + if (LangOpts.Microsoft) { + std::string S = s; + S += "#define __attribute__(X)\n"; + s = S.c_str(); + } if (IsHeader) { // insert the whole string when rewriting a header file InsertText(SourceLocation::getFileLoc(MainFileID, 0), s, strlen(s)); @@ -2852,6 +2860,13 @@ void RewriteTest::RewriteImplementations(std::string &Result) { Result += "\t" + utostr(OBJC_ABI_VERSION) + ", sizeof(struct _objc_module), \"\", &_OBJC_SYMBOLS\n"; Result += "};\n\n"; - + + if (LangOpts.Microsoft) { + Result += "#pragma section(\".objc_module_info$B\",long,read,write)\n"; + Result += "#pragma data_seq(push, \".objc_module_info$B\")\n"; + Result += "static struct _objc_module *_POINTER_OBJC_MODULES = "; + Result += "&_OBJC_MODULES;\n"; + Result += "#pragma data_seg(pop)\n\n"; + } } diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 896479aa5db2..5f3f168ff798 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -1032,7 +1032,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, return CreateASTSerializer(InFile, OutputFile, Diag, LangOpts); case RewriteTest: - return CreateCodeRewriterTest(InFile, Diag); + return CreateCodeRewriterTest(InFile, Diag, LangOpts); } }