[cfe-commits] r41113 - /cfe/trunk/include/clang/AST/Expr.h

Ted Kremenek kremenek at apple.com
Wed Aug 15 15:33:19 PDT 2007


Author: kremenek
Date: Wed Aug 15 17:33:19 2007
New Revision: 41113

URL: http://llvm.org/viewvc/llvm-project?rev=41113&view=rev
Log:
Added a comment to ArraySubscriptExpr to note that the expressions like
"A[4]" are equivalent to "4[A]", and that a test that the expression
returned by "getBase()" has a pointer type is required to resolve which
subexpression is the "true" base expression of the array index.

Modified:
    cfe/trunk/include/clang/AST/Expr.h

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Aug 15 17:33:19 2007
@@ -375,6 +375,11 @@
     Expr(ArraySubscriptExprClass, t),
     Base(base), Idx(idx), RBracketLoc(rbracketloc) {}
   
+  // NOTE: An array access can be written A[4] or 4[A] (both are equivalent).
+  // In the second case, getBase() actually returns the index and getIdx()
+  // returns the offset.  Only one of the subexpressions will have a pointer
+  // type (the base), so the second case can be identified using the
+  // expression getBase()->getType()->isPointerType().
   Expr *getBase() { return Base; }
   const Expr *getBase() const { return Base; }
   Expr *getIdx() { return Idx; }





More information about the cfe-commits mailing list