[cfe-commits] r43047 - in /cfe/trunk: AST/StmtDumper.cpp Analysis/DeadStores.cpp Analysis/UninitializedValues.cpp Driver/RewriteTest.cpp Driver/TextDiagnosticPrinter.cpp Rewrite/Rewriter.cpp Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Expr.h include/clang/AST/ExprCXX.h include/clang/AST/Stmt.h include/clang/Basic/SourceLocation.h include/clang/Rewrite/Rewriter.h

Chris Lattner sabre at nondot.org
Tue Oct 16 15:36:43 PDT 2007


Author: lattner
Date: Tue Oct 16 17:36:42 2007
New Revision: 43047

URL: http://llvm.org/viewvc/llvm-project?rev=43047&view=rev
Log:
Add a new Rewriter::getRangeSize method.
Rename SourceRange::Begin()/End() to getBegin()/getEnd() for
consistency with other code.
Start building the rewriter towards handling @encode.

Modified:
    cfe/trunk/AST/StmtDumper.cpp
    cfe/trunk/Analysis/DeadStores.cpp
    cfe/trunk/Analysis/UninitializedValues.cpp
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/Driver/TextDiagnosticPrinter.cpp
    cfe/trunk/Rewrite/Rewriter.cpp
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/Basic/SourceLocation.h
    cfe/trunk/include/clang/Rewrite/Rewriter.h

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Tue Oct 16 17:36:42 2007
@@ -164,10 +164,10 @@
   SourceRange R = Node->getSourceRange();
   
   fprintf(stderr, " <");
-  DumpLocation(R.Begin());
-  if (R.Begin() != R.End()) {
+  DumpLocation(R.getBegin());
+  if (R.getBegin() != R.getEnd()) {
     fprintf(stderr, ", ");
-    DumpLocation(R.End());
+    DumpLocation(R.getEnd());
   }
   fprintf(stderr, ">");
     

Modified: cfe/trunk/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DeadStores.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/Analysis/DeadStores.cpp Tue Oct 16 17:36:42 2007
@@ -40,7 +40,7 @@
         if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()))
           if (VD->hasLocalStorage() && !Live(VD,AD)) {
             SourceRange R = B->getRHS()->getSourceRange();
-            Diags.Report(DR->getSourceRange().Begin(), diag::warn_dead_store,
+            Diags.Report(DR->getSourceRange().getBegin(), diag::warn_dead_store,
                          0, 0, &R, 1);                                                                        
         }
     }

Modified: cfe/trunk/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UninitializedValues.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/Analysis/UninitializedValues.cpp Tue Oct 16 17:36:42 2007
@@ -218,7 +218,7 @@
     
     if (V(VD,AD) == Uninitialized)
       if (AlreadyWarned.insert(VD))
-        Diags.Report(DR->getSourceRange().Begin(), diag::warn_uninit_val);
+        Diags.Report(DR->getSourceRange().getBegin(), diag::warn_uninit_val);
   }
 };
 } // end anonymous namespace

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Oct 16 17:36:42 2007
@@ -36,6 +36,9 @@
 
     void HandleDeclInMainFile(Decl *D);
     void RewriteInclude(SourceLocation Loc);
+    
+    void RewriteFunctionBody(Stmt *S);
+    void RewriteAtEncode(ObjCEncodeExpr *Exp);
 
     ~RewriteTest();
   };
@@ -86,10 +89,36 @@
 /// HandleDeclInMainFile - This is called for each top-level decl defined in the
 /// main file of the input.
 void RewriteTest::HandleDeclInMainFile(Decl *D) {
+  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+    if (Stmt *Body = FD->getBody())
+      RewriteFunctionBody(Body);
   // Nothing yet.
 }
 
 
+void RewriteTest::RewriteFunctionBody(Stmt *S) {
+  // Handle specific things.
+  if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S))
+    return RewriteAtEncode(AtEncode);
+  
+  // Otherwise, just rewrite all children.
+  for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
+       CI != E; ++CI)
+    RewriteFunctionBody(*CI);
+}
+
+void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
+#if 0
+  int Size = Rewrite.getRangeSize(Exp->getSourceRange());
+  if (Size == -1) {
+    printf("BLAH!");
+  }
+  
+  Rewrite.RemoveText(Exp->getEncLoc(), Size);
+#endif
+}
+
+
 RewriteTest::~RewriteTest() {
   // Get the top-level buffer that this corresponds to.
   std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);

Modified: cfe/trunk/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Tue Oct 16 17:36:42 2007
@@ -54,16 +54,16 @@
          "Expect a correspondence between source and carat line!");
   if (!R.isValid()) return;
 
-  unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.Begin());
+  unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());
   if (StartLineNo > LineNo) return;  // No intersection.
   
-  unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.End());
+  unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());
   if (EndLineNo < LineNo) return;  // No intersection.
   
   // Compute the column number of the start.
   unsigned StartColNo = 0;
   if (StartLineNo == LineNo) {
-    StartColNo = SourceMgr.getLogicalColumnNumber(R.Begin());
+    StartColNo = SourceMgr.getLogicalColumnNumber(R.getBegin());
     if (StartColNo) --StartColNo;  // Zero base the col #.
   }
 
@@ -75,12 +75,12 @@
   // Compute the column number of the end.
   unsigned EndColNo = CaratLine.size();
   if (EndLineNo == LineNo) {
-    EndColNo = SourceMgr.getLogicalColumnNumber(R.End());
+    EndColNo = SourceMgr.getLogicalColumnNumber(R.getEnd());
     if (EndColNo) {
       --EndColNo;  // Zero base the col #.
       
       // Add in the length of the token, so that we cover multi-char tokens.
-      EndColNo += GetTokenLength(R.End());
+      EndColNo += GetTokenLength(R.getEnd());
     } else {
       EndColNo = CaratLine.size();
     }

Modified: cfe/trunk/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Rewrite/Rewriter.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/Rewrite/Rewriter.cpp Tue Oct 16 17:36:42 2007
@@ -141,6 +141,25 @@
 // Rewriter class
 //===----------------------------------------------------------------------===//
 
+/// getRangeSize - Return the size in bytes of the specified range if they
+/// are in the same file.  If not, this returns -1.
+int Rewriter::getRangeSize(SourceRange Range) const {
+  if (!isRewritable(Range.getBegin()) ||
+      !isRewritable(Range.getEnd())) return -1;
+  
+  unsigned StartOff, StartFileID;
+  unsigned EndOff  , EndFileID;
+  
+  StartOff = getLocationOffsetAndFileID(Range.getBegin(), StartFileID);
+  EndOff   = getLocationOffsetAndFileID(Range.getEnd(), EndFileID);
+  
+  if (StartFileID != EndFileID)
+    return -1;
+  
+  return EndOff-StartOff;
+}
+
+
 unsigned Rewriter::getLocationOffsetAndFileID(SourceLocation Loc,
                                               unsigned &FileID) const {
   std::pair<unsigned,unsigned> V = SourceMgr->getDecomposedFileLoc(Loc);

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Oct 16 17:36:42 2007
@@ -490,7 +490,7 @@
   // All of these full declarators require an identifier.  If it doesn't have
   // one, the ParsedFreeStandingDeclSpec action should be used.
   if (II == 0) {
-    Diag(D.getDeclSpec().getSourceRange().Begin(),
+    Diag(D.getDeclSpec().getSourceRange().getBegin(),
          diag::err_declarator_need_ident,
          D.getDeclSpec().getSourceRange(), D.getSourceRange());
     return 0;

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct 16 17:36:42 2007
@@ -742,7 +742,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Oct 16 17:36:42 2007
@@ -703,7 +703,7 @@
   Expr *getSubExpr() const { return Op; }
   
   virtual SourceRange getSourceRange() const {
-    return SourceRange(Loc, getSubExpr()->getSourceRange().End());
+    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
   }
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == CastExprClass; 

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Oct 16 17:36:42 2007
@@ -60,7 +60,7 @@
     }
     
     virtual SourceRange getSourceRange() const {
-      return SourceRange(Loc, getSubExpr()->getSourceRange().End());
+      return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
     }
     static bool classof(const Stmt *T) { 
       return T->getStmtClass() == CXXCastExprClass;

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Oct 16 17:36:42 2007
@@ -55,8 +55,8 @@
   /// value objects created/interpreted by SourceManager. We assume AST
   /// clients will have a pointer to the respective SourceManager.
   virtual SourceRange getSourceRange() const = 0;
-  SourceLocation getLocStart() const { return getSourceRange().Begin(); }
-  SourceLocation getLocEnd() const { return getSourceRange().End(); }
+  SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
+  SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
 
   // global temp stats (until we have a per-module visitor)
   static void addStmtClass(const StmtClass s);

Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Tue Oct 16 17:36:42 2007
@@ -166,8 +166,8 @@
   SourceRange(SourceLocation loc) : B(loc), E(loc) {}
   SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
     
-  SourceLocation Begin() const { return B; }
-  SourceLocation End() const { return E; }
+  SourceLocation getBegin() const { return B; }
+  SourceLocation getEnd() const { return E; }
   
   void setBegin(SourceLocation b) { B = b; }
   void setEnd(SourceLocation e) { E = e; }

Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=43047&r1=43046&r2=43047&view=diff

==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Tue Oct 16 17:36:42 2007
@@ -121,6 +121,10 @@
   static bool isRewritable(SourceLocation Loc) {
     return Loc.isFileID();
   }
+
+  /// getRangeSize - Return the size in bytes of the specified range if they
+  /// are in the same file.  If not, this returns -1.
+  int getRangeSize(SourceRange Range) const;
   
   /// InsertText - Insert the specified string at the specified location in the
   /// original buffer.  This method is only valid on rewritable source
@@ -128,8 +132,8 @@
   void InsertText(SourceLocation Loc, const char *StrData, unsigned StrLen);
   
   /// RemoveText - Remove the specified text region.  This method is only valid
-  /// on rewritable source locations.
-  void RemoveText(SourceLocation Start, SourceLocation End);
+  /// on a rewritable source location.
+  void RemoveText(SourceLocation Start, unsigned Length);
   
   /// ReplaceText - This method replaces a range of characters in the input
   /// buffer with a new string.  This is effectively a combined "remove/insert"





More information about the cfe-commits mailing list