#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/CommandLine.h"
#include <sstream>
using namespace clang;
using llvm::utostr;
+static llvm::cl::opt<bool>
+SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false),
+ llvm::cl::desc("Silence ObjC rewriting warnings"));
+
namespace {
class RewriteTest : public ASTConsumer {
Rewriter Rewrite;
Diagnostic &Diags;
+ unsigned RewriteFailedDiag;
+
ASTContext *Context;
SourceManager *SM;
unsigned MainFileID;
CurMethodDecl = 0;
SuperStructDecl = 0;
BcLabelCount = 0;
-
+
// Get the ID and start/end of the main file.
MainFileID = SM->getMainFileID();
const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
// Top Level Driver code.
virtual void HandleTopLevelDecl(Decl *D);
void HandleDeclInMainFile(Decl *D);
- RewriteTest(bool isHeader, Diagnostic &D) : Diags(D) {IsHeader = isHeader;}
+ RewriteTest(bool isHeader, Diagnostic &D) : Diags(D) {
+ IsHeader = isHeader;
+ RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning,
+ "rewriting sub-expression within a macro (may not be correct)");
+ }
~RewriteTest();
// Syntactic Rewriting.
IV->getLocation());
if (Rewrite.ReplaceStmt(IV, Replacement)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = IV->getSourceRange();
- Diags.Report(Context->getFullLoc(IV->getLocation()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(IV->getLocation()), RewriteFailedDiag,
+ 0, 0, &Range, 1);
}
delete IV;
return Replacement;
ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), castExpr);
if (Rewrite.ReplaceStmt(IV->getBase(), PE)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = IV->getBase()->getSourceRange();
- Diags.Report(Context->getFullLoc(IV->getBase()->getLocStart()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(IV->getBase()->getLocStart()),
+ RewriteFailedDiag, 0, 0, &Range, 1);
}
delete IV->getBase();
return PE;
SourceLocation(), SourceLocation());
if (Rewrite.ReplaceStmt(Exp, Replacement)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = Exp->getSourceRange();
- Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), RewriteFailedDiag,
+ 0, 0, &Range, 1);
}
// Replace this subexpr in the parent.
&SelExprs[0], SelExprs.size());
if (Rewrite.ReplaceStmt(Exp, SelExp)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = Exp->getSourceRange();
- Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), RewriteFailedDiag,
+ 0, 0, &Range, 1);
}
delete Exp;
return SelExp;
CastExpr *cast = new CastExpr(Exp->getType(), call, SourceLocation());
if (Rewrite.ReplaceStmt(Exp, cast)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = Exp->getSourceRange();
- Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), RewriteFailedDiag,
+ 0, 0, &Range, 1);
}
delete Exp;
return cast;
// Now do the actual rewrite.
if (Rewrite.ReplaceStmt(Exp, ReplacingStmt)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = Exp->getSourceRange();
- Diags.Report(Context->getFullLoc(Exp->getLocStart()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(Exp->getLocStart()), RewriteFailedDiag,
+ 0, 0, &Range, 1);
}
delete Exp;
ProtoExprs.size());
if (Rewrite.ReplaceStmt(Exp, ProtoExp)) {
// replacement failed.
- unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Warning,
- "rewriting sub-expression within a macro (may not be correct)");
SourceRange Range = Exp->getSourceRange();
- Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ if (!SilenceRewriteMacroWarning)
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), RewriteFailedDiag,
+ 0, 0, &Range, 1);
}
delete Exp;
return ProtoExp;