/**
* <copyright>
* </copyright>
*
* $Id$
*/
package net.sf.orcc.ir.impl;
import static net.sf.orcc.ir.util.IrUtil.getNameSSA;
import java.util.Collection;
import net.sf.orcc.ir.Def;
import net.sf.orcc.ir.Expression;
import net.sf.orcc.ir.InstLoad;
import net.sf.orcc.ir.IrPackage;
import net.sf.orcc.ir.Use;
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 Load</b></em>'. <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link net.sf.orcc.ir.impl.InstLoadImpl#getIndexes <em>Indexes</em>}</li>
* <li>{@link net.sf.orcc.ir.impl.InstLoadImpl#getSource <em>Source</em>}</li>
* <li>{@link net.sf.orcc.ir.impl.InstLoadImpl#getTarget <em>Target</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class InstLoadImpl extends InstructionImpl implements InstLoad {
/**
* 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 #getSource() <em>Source</em>}' containment reference.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getSource()
* @generated
* @ordered
*/
protected Use source;
/**
* 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;
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
protected InstLoadImpl() {
super();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetSource(Use newSource,
NotificationChain msgs) {
Use oldSource = source;
source = newSource;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this,
Notification.SET, IrPackage.INST_LOAD__SOURCE, oldSource,
newSource);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
/**
* <!-- 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_LOAD__TARGET, oldTarget,
newTarget);
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_LOAD__INDEXES:
return getIndexes();
case IrPackage.INST_LOAD__SOURCE:
return getSource();
case IrPackage.INST_LOAD__TARGET:
return getTarget();
}
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_LOAD__INDEXES:
return ((InternalEList<?>) getIndexes())
.basicRemove(otherEnd, msgs);
case IrPackage.INST_LOAD__SOURCE:
return basicSetSource(null, msgs);
case IrPackage.INST_LOAD__TARGET:
return basicSetTarget(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_LOAD__INDEXES:
return indexes != null && !indexes.isEmpty();
case IrPackage.INST_LOAD__SOURCE:
return source != null;
case IrPackage.INST_LOAD__TARGET:
return target != 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_LOAD__INDEXES:
getIndexes().clear();
getIndexes().addAll((Collection<? extends Expression>) newValue);
return;
case IrPackage.INST_LOAD__SOURCE:
setSource((Use) newValue);
return;
case IrPackage.INST_LOAD__TARGET:
setTarget((Def) newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return IrPackage.Literals.INST_LOAD;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case IrPackage.INST_LOAD__INDEXES:
getIndexes().clear();
return;
case IrPackage.INST_LOAD__SOURCE:
setSource((Use) null);
return;
case IrPackage.INST_LOAD__TARGET:
setTarget((Def) 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_LOAD__INDEXES);
}
return indexes;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Use getSource() {
return source;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Def getTarget() {
return target;
}
@Override
public boolean isInstAssign() {
return false;
}
@Override
public boolean isInstCall() {
return false;
}
@Override
public boolean isInstLoad() {
return true;
}
@Override
public boolean isInstPhi() {
return false;
}
@Override
public boolean isInstReturn() {
return false;
}
@Override
public boolean isInstStore() {
return false;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setSource(Use newSource) {
if (newSource != source) {
NotificationChain msgs = null;
if (source != null)
msgs = ((InternalEObject) source).eInverseRemove(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_LOAD__SOURCE,
null, msgs);
if (newSource != null)
msgs = ((InternalEObject) newSource).eInverseAdd(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_LOAD__SOURCE,
null, msgs);
msgs = basicSetSource(newSource, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
IrPackage.INST_LOAD__SOURCE, newSource, newSource));
}
/**
* <!-- 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_LOAD__TARGET,
null, msgs);
if (newTarget != null)
msgs = ((InternalEObject) newTarget).eInverseAdd(this,
EOPPOSITE_FEATURE_BASE - IrPackage.INST_LOAD__TARGET,
null, msgs);
msgs = basicSetTarget(newTarget, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
IrPackage.INST_LOAD__TARGET, newTarget, newTarget));
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(super.toString());
builder.append("Load(").append(getNameSSA(getTarget().getVariable()))
.append(", ").append(getSource().getVariable().getName());
for (Expression index : getIndexes()) {
builder.append("[");
builder.append(new ExpressionPrinter().doSwitch(index));
builder.append("]");
}
return builder.append(")").toString();
}
} // InstLoadImpl