/* ArrayAccessExpression -- Automatically generated by TreeBuilder (2024-10-27T16:47Z) */ package de.uni_freiburg.informatik.ultimate.model.acsl.ast; import java.util.List; import java.util.Arrays; import java.util.ArrayList; import de.uni_freiburg.informatik.ultimate.model.acsl.ACSLNode; /** * Represents a array access expression which is a special form of a expression. */ public class ArrayAccessExpression extends Expression { private static final java.util.function.Predicate VALIDATOR = ACSLNode.VALIDATORS.get(ArrayAccessExpression.class); /** * The array of this array access expression. */ Expression array; /** * The indices of this array access expression. */ Expression[] indices; /** * The constructor taking initial values. * @param array the array of this array access expression. * @param indices the indices of this array access expression. */ public ArrayAccessExpression(Expression array, Expression[] indices) { super(); this.array = array; this.indices = indices; assert VALIDATOR == null || VALIDATOR.test(this) : "Invalid ArrayAccessExpression: " + this; } /** * The constructor taking initial values. * @param type the type of this expression. * @param array the array of this array access expression. * @param indices the indices of this array access expression. */ public ArrayAccessExpression(ACSLType type, Expression array, Expression[] indices) { super(type); this.array = array; this.indices = indices; assert VALIDATOR == null || VALIDATOR.test(this) : "Invalid ArrayAccessExpression: " + this; } /** * Returns a textual description of this object. */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append("ArrayAccessExpression").append('['); sb.append(array); sb.append(','); if (indices == null) { sb.append("null"); } else { sb.append('['); for(int i1 = 0; i1 < indices.length; i1++) { if (i1 > 0) sb.append(','); sb.append(indices[i1]); } sb.append(']'); } return sb.append(']').toString(); } /** * Gets the array of this array access expression. * @return the array of this array access expression. */ public Expression getArray() { return array; } /** * Gets the indices of this array access expression. * @return the indices of this array access expression. */ public Expression[] getIndices() { return indices; } public List getOutgoingNodes() { List children = super.getOutgoingNodes(); children.add(array); if(indices!=null){ children.addAll(Arrays.asList(indices)); } return children; } public void accept(ACSLVisitor visitor) { if (visitor.visit((Expression)this)) { //visit parent types higher up if necessary } else { return; } if (visitor.visit(this)) { if(array!=null){ array.accept(visitor); } if(indices!=null){ for (Expression elem : indices) { elem.accept(visitor); } } if(type!=null){ type.accept(visitor); } } } public Expression accept(ACSLTransformer visitor) { Expression node = visitor.transform(this); if(node != this){ return node; } Expression newarray = null; if(array != null){ newarray = (Expression)array.accept(visitor); } boolean isChanged=false; ArrayList tmpListnewindices = new ArrayList<>(); if(indices != null){ for(Expression elem : indices){ Expression newindices = (Expression)elem.accept(visitor); isChanged = isChanged || newindices != elem; tmpListnewindices.add(newindices); } } ACSLType newtype = null; if(type != null){ newtype = (ACSLType)type.accept(visitor); } if(isChanged || array != newarray || type != newtype){ return new ArrayAccessExpression(newtype, newarray, tmpListnewindices.toArray(new Expression[0])); } return this; } }