From 9ce6fbe1fa7f7f056421a0a1b7ca1fd3b102b19e Mon Sep 17 00:00:00 2001 From: "james.brodman" Date: Wed, 30 Oct 2013 17:07:26 -0400 Subject: [PATCH] Support using pointer arithmetic as lvalue --- expr.cpp | 16 ++++++++++++++-- expr.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/expr.cpp b/expr.cpp index 222c89a1..1cbebad5 100644 --- a/expr.cpp +++ b/expr.cpp @@ -2798,6 +2798,17 @@ BinaryExpr::TypeCheck() { } } +const Type * +BinaryExpr::GetLValueType() const { + const Type *t = GetType(); + if (CastType(t) != NULL) { + // Are we doing something like (basePtr + offset)[...] = ... + return t; + } + else { + return NULL; + } +} int BinaryExpr::EstimateCost() const { @@ -4266,8 +4277,9 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const { } else { Symbol *baseSym = GetBaseSymbol(); - if (dynamic_cast(baseExpr) == NULL) { - // Only check for non-function calls + if (dynamic_cast(baseExpr) == NULL && + dynamic_cast(baseExpr) == NULL) { + // Don't check if we're doing a function call or pointer arith AssertPos(pos, baseSym != NULL); } mask = lMaskForSymbol(baseSym, ctx); diff --git a/expr.h b/expr.h index f8b96abd..45780414 100644 --- a/expr.h +++ b/expr.h @@ -155,6 +155,7 @@ public: llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; + const Type *GetLValueType() const; void Print() const; Expr *Optimize();