From fc4a1601a84d280d7e5c424b77843fdd743beec8 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 15 Aug 2007 22:33:19 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41113 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 36005223c7..a5aba76d75 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -375,6 +375,11 @@ public: 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; } -- 2.40.0