diff options
author | Chris Lattner <sabre@nondot.org> | 2007-10-17 22:35:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-10-17 22:35:30 +0000 |
commit | 01c5748c29e75b29cab5fc7d8ad1b173b29c7ecf (patch) | |
tree | 3f625a44b7a88371f36b44fb582f8d35608cd43d /Driver/RewriteTest.cpp | |
parent | 5075477aad33b82b3657e5363459045e230f865d (diff) |
Add new API to rewrite one stmt/expr with another.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r-- | Driver/RewriteTest.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 6972f35853..508f799608 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -22,14 +22,16 @@ using namespace clang; namespace { class RewriteTest : public ASTConsumer { Rewriter Rewrite; + ASTContext *Context; SourceManager *SM; unsigned MainFileID; SourceLocation LastIncLoc; public: - void Initialize(ASTContext &Context, unsigned mainFileID) { - SM = &Context.SourceMgr; + void Initialize(ASTContext &context, unsigned mainFileID) { + Context = &context; + SM = &Context->SourceMgr; MainFileID = mainFileID; - Rewrite.setSourceMgr(Context.SourceMgr); + Rewrite.setSourceMgr(Context->SourceMgr); } virtual void HandleTopLevelDecl(Decl *D); @@ -109,13 +111,12 @@ void RewriteTest::RewriteFunctionBody(Stmt *S) { } void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { - int Size = Rewrite.getRangeSize(Exp->getSourceRange()); - if (Size == -1) { - printf("BLAH!"); - return; - } - - Rewrite.ReplaceText(Exp->getAtLoc(), Size, "\"foo\"", 5); + // Create a new string expression. + QualType StrType = Context->getPointerType(Context->CharTy); + Expr *Replacement = new StringLiteral("foo", 3, false, StrType, + SourceLocation(), SourceLocation()); + Rewrite.ReplaceStmt(Exp, Replacement); + delete Replacement; } |