diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2007-11-14 01:37:46 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2007-11-14 01:37:46 +0000 |
commit | fe38ba24afeb9b4305dfaf4f9e2955ad700a794c (patch) | |
tree | 29e97d2668799db2d5ad8d19f4f09e20250bfaa4 /clang/Driver/RewriteTest.cpp | |
parent | da6165c3dc83e40d66edd20e5da39e40c4d087af (diff) | |
download | bcm5719-llvm-fe38ba24afeb9b4305dfaf4f9e2955ad700a794c.tar.gz bcm5719-llvm-fe38ba24afeb9b4305dfaf4f9e2955ad700a794c.zip |
Rewrite @optional/@required directives used inside protocol definitions.
llvm-svn: 44096
Diffstat (limited to 'clang/Driver/RewriteTest.cpp')
-rw-r--r-- | clang/Driver/RewriteTest.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp index cd1e994bbfe..5538a900b1b 100644 --- a/clang/Driver/RewriteTest.cpp +++ b/clang/Driver/RewriteTest.cpp @@ -371,6 +371,9 @@ void RewriteTest::RewriteCategoryDecl(ObjcCategoryDecl *CatDecl) { } void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) { + std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID); + const char *MainBufStart = MainBuf.first; + SourceLocation LocStart = PDecl->getLocStart(); // FIXME: handle protocol headers that are declared across multiple lines. @@ -381,7 +384,31 @@ void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) { RewriteMethodDeclarations(PDecl->getNumClassMethods(), PDecl->getClassMethods()); // Lastly, comment out the @end. - Rewrite.ReplaceText(PDecl->getAtEndLoc(), 0, "// ", 3); + SourceLocation LocEnd = PDecl->getAtEndLoc(); + Rewrite.ReplaceText(LocEnd, 0, "// ", 3); + + // Must comment out @optional/@required + const char *startBuf = SM->getCharacterData(LocStart); + const char *endBuf = SM->getCharacterData(LocEnd); + for (const char *p = startBuf; p < endBuf; p++) { + if (*p == '@' && !strncmp(p+1, "optional", strlen("optional"))) { + std::string CommentedOptional = "/* @optional */"; + SourceLocation OptionalLoc = SourceLocation::getFileLoc(MainFileID, + p-MainBufStart); + Rewrite.ReplaceText(OptionalLoc, strlen("@optional"), + CommentedOptional.c_str(), CommentedOptional.size()); + + } + else if (*p == '@' && !strncmp(p+1, "required", strlen("required"))) { + std::string CommentedRequired = "/* @required */"; + SourceLocation OptionalLoc = SourceLocation::getFileLoc(MainFileID, + p-MainBufStart); + Rewrite.ReplaceText(OptionalLoc, strlen("@required"), + CommentedRequired.c_str(), CommentedRequired.size()); + + } + } + } void RewriteTest::RewriteForwardProtocolDecl(ObjcForwardProtocolDecl *PDecl) { |