/**
* <copyright>
* </copyright>
*
* $Id$
*/
package net.sf.orcc.ir.impl;
import java.util.Collection;
import net.sf.orcc.ir.Def;
import net.sf.orcc.ir.Expression;
import net.sf.orcc.ir.InstStore;
import net.sf.orcc.ir.IrPackage;
import net.sf.orcc.ir.util.ExpressionPrinter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
/**
* <!-- begin-user-doc --> An implementation of the model object '
* <em><b>Inst Store</b></em>'. <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link net.sf.orcc.ir.impl.InstStoreImpl#getIndexes <em>Indexes</em>}</li>
* <li>{@link net.sf.orcc.ir.impl.InstStoreImpl#getTarget <em>Target</em>}</li>
* <li>{@link net.sf.orcc.ir.impl.InstStoreImpl#getValue <em>Value</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class InstStoreImpl extends InstructionImpl implements InstStore {
/**
* The cached value of the '{@link #getIndexes() <em>Indexes</em>}' containment reference list.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getIndexes()
* @generated
* @ordered
*/
protected EList<Expression> indexes;
/**
* The cached value of the '{@link #getTarget() <em>Target</em>}' containment reference.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getTarget()
* @generated
* @ordered
*/
protected Def target;
/**
* The cached value of the '{@link #getValue() <em>Value</em>}' containment reference.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getValue()
* @generated
* @ordered
*/
protected Expression value;
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
protected InstStoreImpl() {
super();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetTarget(Def newTarget,
NotificationChain msgs) {
Def oldTarget = target;
target = newTarget;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this,
Notification.SET, IrPackage.INST_STORE__TARGET, oldTarget,
newTarget);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetValue(Expression newValue,
NotificationChain msgs) {
Expression oldValue = value;
value = newValue;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this,
Notification.SET, IrPackage.INST_STORE__VALUE, oldValue,
newValue);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case IrPackage.INST_STORE__INDEXES:
return getIndexes();
case IrPackage.INST_STORE__TARGET:
return getTarget();
case IrPackage.INST_STORE__VALUE:
return getValue();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case IrPackage.INST_STORE__INDEXES:
return ((InternalEList<?>) getIndexes())
.basicRemove(otherEnd, msgs);
case IrPackage.INST_STORE__TARGET:
return basicSetTarget(null, msgs);
case IrPackage.INST_STORE__VALUE:
return basicSetValue(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case IrPackage.INST_STORE__INDEXES:
return indexes != null && !indexes.isEmpty();
case IrPackage.INST_STORE__TARGET:
return target != null;
case IrPackage.INST_STORE__VALUE:
return value != null;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case IrPackage.INST_STORE__INDEXES:
getIndexes().clear();
getIndexes().addAll((Collection<? extends Expression>) newValue);
return;
case IrPackage.INST_STORE__TARGET:
setTarget((Def) newValue);
return;
case IrPackage.INST_STORE__VALUE:
setValue((Expression) newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return IrPackage.Literals.INST_STORE;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case IrPackage.INST_STORE__INDEXES:
getIndexes().clear();
return;
case IrPackage.INST_STORE__TARGET:
setTarget((Def) null);
return;
case IrPackage.INST_STORE__VALUE:
setValue((Expression) null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public EList<Expression> getIndexes() {
if (indexes == null) {
indexes = new EObjectContainmentEList<Expression>(Expression.class,
this, IrPackage.INST_STORE__INDEXES);
}
return indexes;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Def getTarget() {
return target;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Expression getValue() {
return value;
}
@Override
public boolean isInstStore() {
return true;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setTarget(Def newTarget) {
if (newTarget != target) {
NotificationChain msgs = null;
if (target != null)
msgs = ((InternalEObject) target).eInverseRemove(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_STORE__TARGET,
null, msgs);
if (newTarget != null)
msgs = ((InternalEObject) newTarget).eInverseAdd(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_STORE__TARGET,
null, msgs);
msgs = basicSetTarget(newTarget, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
IrPackage.INST_STORE__TARGET, newTarget, newTarget));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setValue(Expression newValue) {
if (newValue != value) {
NotificationChain msgs = null;
if (value != null)
msgs = ((InternalEObject) value).eInverseRemove(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_STORE__VALUE,
null, msgs);
if (newValue != null)
msgs = ((InternalEObject) newValue).eInverseAdd(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_STORE__VALUE,
null, msgs);
msgs = basicSetValue(newValue, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
IrPackage.INST_STORE__VALUE, newValue, newValue));
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(super.toString());
builder.append("Store(").append(getTarget().getVariable().getName());
for (Expression index : getIndexes()) {
builder.append("[");
builder.append(new ExpressionPrinter().doSwitch(index));
builder.append("]");
}
return builder.append(", ")
.append(new ExpressionPrinter().doSwitch(getValue()))
.append(")").toString();
}
} // InstStoreImpl