]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: More work towards
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 20 Aug 2013 00:07:23 +0000 (00:07 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 20 Aug 2013 00:07:23 +0000 (00:07 +0000)
insertion of ObjC audit pragmas.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188733 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Lexer.h
include/clang/Lex/Preprocessor.h
lib/ARCMigrate/ObjCMT.cpp
lib/Lex/Lexer.cpp

index 72c361dba875a65031f0769fc4fdd0c70c3fbcf2..9b386e100bf220f8d5b8706067de4ede579b1c9b 100644 (file)
@@ -288,7 +288,8 @@ public:
   /// \returns true if there was a failure, false on success.
   static bool getRawToken(SourceLocation Loc, Token &Result,
                           const SourceManager &SM,
-                          const LangOptions &LangOpts);
+                          const LangOptions &LangOpts,
+                          bool IgnoreWhiteSpace = false);
 
   /// \brief Given a location any where in a source buffer, find the location
   /// that corresponds to the beginning of the token in which the original
index 86eabf080d0cdb68c19d241a7b9e5c6f82798b6e..f197633c31ddf6f25639e27b43fe0ff12710d6b8 100644 (file)
@@ -1001,8 +1001,9 @@ public:
 
   /// \brief Relex the token at the specified location.
   /// \returns true if there was a failure, false on success.
-  bool getRawToken(SourceLocation Loc, Token &Result) {
-    return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts);
+  bool getRawToken(SourceLocation Loc, Token &Result,
+                   bool IgnoreWhiteSpace = false) {
+    return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace);
   }
 
   /// getSpellingOfSingleCharacterNumericConstant - Tok is a numeric constant
index ab2d7eac492545a0a6033c387cf1be3389e802c7..439b2d4fe4584d42e633e1f58b1c5cf584d43a90 100644 (file)
@@ -815,7 +815,15 @@ void ObjCMigrateASTConsumer::migrateCFFunctions(
     edit::Commit commit(*Editor);
     commit.insertBefore(FirstFD->getLocStart(), PragmaString);
     PragmaString = "\nCF_IMPLICIT_BRIDGING_DISABLED\n";
-    commit.insertAfterToken(LastFD->getLocEnd(), PragmaString);
+    SourceLocation EndLoc = LastFD->getLocEnd();
+    // get location just past end of function location.
+    EndLoc = PP.getLocForEndOfToken(EndLoc);
+    Token Tok;
+    // get locaiton of token that comes after end of function.
+    bool Failed = PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true);
+    if (!Failed)
+      EndLoc = Tok.getLocation();
+    commit.insertAfterToken(EndLoc, PragmaString);
     Editor->commit(commit);
     
     CFFunctionIBCandidates.clear();
index 71db68a58c029a622f3f2f1d96abb11c4c4b31a2..c28781dc5f2bef8e8739ae0bc355e8f8558fd71d 100644 (file)
@@ -430,7 +430,8 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
 /// \returns true if there was a failure, false on success.
 bool Lexer::getRawToken(SourceLocation Loc, Token &Result,
                         const SourceManager &SM,
-                        const LangOptions &LangOpts) {
+                        const LangOptions &LangOpts,
+                        bool IgnoreWhiteSpace) {
   // TODO: this could be special cased for common tokens like identifiers, ')',
   // etc to make this faster, if it mattered.  Just look at StrData[0] to handle
   // all obviously single-char tokens.  This could use
@@ -448,7 +449,7 @@ bool Lexer::getRawToken(SourceLocation Loc, Token &Result,
 
   const char *StrData = Buffer.data()+LocInfo.second;
 
-  if (isWhitespace(StrData[0]))
+  if (!IgnoreWhiteSpace && isWhitespace(StrData[0]))
     return true;
 
   // Create a lexer starting at the beginning of this token.