//===--- SemaPseudoObject.cpp - Semantic Analysis for Pseudo-Objects ------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements semantic analysis for expressions involving
// pseudo-object references. Pseudo-objects are conceptual objects
// whose storage is entirely abstract and all accesses to which are
// translated through some sort of abstraction barrier.
//
// For example, Objective-C objects can have "properties", either
// declared or undeclared. A property may be accessed by writing
// expr.prop
// where 'expr' is an r-value of Objective-C pointer type and 'prop'
// is the name of the property. If this expression is used in a context
// needing an r-value, it is treated as if it were a message-send
// of the associated 'getter' selector, typically:
// [expr prop]
// If it is used as the LHS of a simple assignment, it is treated
// as a message-send of the associated 'setter' selector, typically:
// [expr setProp: RHS]
// If it is used as the LHS of a compound assignment, or the operand
// of a unary increment or decrement, both are required; for example,
// 'expr.prop *= 100' would be translated to:
// [expr setProp: [expr prop] * 100]
//
//===----------------------------------------------------------------------===//
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Initialization.h"
#include "clang/AST/ExprObjC.h"
#include "clang/Lex/Preprocessor.h"
using namespace clang;
using namespace sema;
namespace {
// Basically just a very focused copy of TreeTransform.
template <class T> struct Rebuilder {
Sema &S;
Rebuilder(Sema &S) : S(S) {}
T &getDerived() { return static_cast<T&>(*this); }
Expr *rebuild(Expr *e) {
// Fast path: nothing to look through.
if (typename T::specific_type *specific
= dyn_cast<typename T::specific_type>(e))
return getDerived().rebuildSpecific(specific);
// Otherwise, we should look through and rebuild anything that
// IgnoreParens would.
if (ParenExpr *parens = dyn_cast<ParenExpr>(e)) {
e = rebuild(parens->getSubExpr());
return new (S.Context) ParenExpr(parens->getLParen(),
parens->getRParen(),
e);
}
if (UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
assert(uop->getOpcode() == UO_Extension);
e = rebuild(uop->getSubExpr());
return new (S.Context) UnaryOperator(e, uop->getOpcode(),
uop->getType(),
uop->getValueKind(),
uop->getObjectKind(),
uop->getOperatorLoc());
}
if (GenericSelectionExpr *gse =