[cfe-commits] r39685 - in /cfe/cfe/trunk: AST/Expr.cpp Sema/SemaStmt.cpp include/clang/AST/Expr.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:47:08 PDT 2007


Author: clattner
Date: Wed Jul 11 11:47:08 2007
New Revision: 39685

URL: http://llvm.org/viewvc/llvm-project?rev=39685&view=rev
Log:
add a method to get more precise arrow positioning for expressions.  Rename
some ivars to more obvious names, eliminating some comments.

Modified:
    cfe/cfe/trunk/AST/Expr.cpp
    cfe/cfe/trunk/Sema/SemaStmt.cpp
    cfe/cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=39685&r1=39684&r2=39685&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:47:08 2007
@@ -76,12 +76,12 @@
 //===----------------------------------------------------------------------===//
 
 CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
-                   SourceLocation l)
+                   SourceLocation rparenloc)
   : Expr(CallExprClass, t), Fn(fn), NumArgs(numargs) {
   Args = new Expr*[numargs];
   for (unsigned i = 0; i != numargs; ++i)
     Args[i] = args[i];
-  Loc = l;
+  RParenLoc = rparenloc;
 }
 
 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it

Modified: cfe/cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaStmt.cpp?rev=39685&r1=39684&r2=39685&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaStmt.cpp Wed Jul 11 11:47:08 2007
@@ -26,8 +26,7 @@
   // Exprs are statements, so there is no need to do a conversion here. However,
   // diagnose some potentially bad code.
   if (!E->hasLocalSideEffect())
-    Diag(E->getLocStart()/*
-          getExprLoc()*/, diag::warn_unused_expr, E->getSourceRange());
+    Diag(E->getExprLoc(), diag::warn_unused_expr, E->getSourceRange());
   
   return E;
 }

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:47:08 2007
@@ -42,6 +42,10 @@
   SourceLocation getLocStart() const { return getSourceRange().Begin(); }
   SourceLocation getLocEnd() const { return getSourceRange().End(); }
 
+  /// getExprLoc - Return the preferred location for the arrow when diagnosing
+  /// a problem with a generic expression.
+  virtual SourceLocation getExprLoc() const { return getLocStart(); }
+  
   /// hasLocalSideEffect - Return true if this immediate expression has side
   /// effects, not counting any sub-expressions.
   bool hasLocalSideEffect() const;
@@ -284,6 +288,7 @@
     else
       return SourceRange(Loc, Val->getLocEnd());
   }
+  virtual SourceLocation getExprLoc() const { return Loc; }
   
   virtual void visit(StmtVisitor &Visitor);
   static bool classof(const Stmt *T) { 
@@ -322,11 +327,12 @@
 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
 class ArraySubscriptExpr : public Expr {
   Expr *Base, *Idx;
-  SourceLocation Loc; // the location of the right bracket
+  SourceLocation RBracketLoc;
 public:
-  ArraySubscriptExpr(Expr *base, Expr *idx, QualType t, SourceLocation l) : 
+  ArraySubscriptExpr(Expr *base, Expr *idx, QualType t,
+                     SourceLocation rbracketloc) : 
     Expr(ArraySubscriptExprClass, t),
-    Base(base), Idx(idx), Loc(l) {}
+    Base(base), Idx(idx), RBracketLoc(rbracketloc) {}
   
   Expr *getBase() { return Base; }
   const Expr *getBase() const { return Base; }
@@ -334,8 +340,10 @@
   const Expr *getIdx() const { return Idx; }
   
   SourceRange getSourceRange() const { 
-    return SourceRange(Base->getLocStart(), Loc);
+    return SourceRange(Base->getLocStart(), RBracketLoc);
   }
+  virtual SourceLocation getExprLoc() const { return RBracketLoc; }
+
   virtual void visit(StmtVisitor &Visitor);
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == ArraySubscriptExprClass; 
@@ -350,10 +358,10 @@
   Expr *Fn;
   Expr **Args;
   unsigned NumArgs;
-  SourceLocation Loc; // the location of the right paren
+  SourceLocation RParenLoc;
 public:
   CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, 
-           SourceLocation l);
+           SourceLocation rparenloc);
   ~CallExpr() {
     delete [] Args;
   }
@@ -380,7 +388,7 @@
   unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
 
   SourceRange getSourceRange() const { 
-    return SourceRange(Fn->getLocStart(), Loc);
+    return SourceRange(Fn->getLocStart(), RParenLoc);
   }
   
   virtual void visit(StmtVisitor &Visitor);
@@ -409,6 +417,8 @@
   virtual SourceRange getSourceRange() const {
     return SourceRange(getBase()->getLocStart(), MemberLoc);
   }
+  virtual SourceLocation getExprLoc() const { return MemberLoc; }
+
   virtual void visit(StmtVisitor &Visitor);
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == MemberExprClass; 





More information about the cfe-commits mailing list