/** * Creates an array access with a single index expression. * * @param array An expression evaluating to an address. * @param index The expression with which to index the array. */ public ArrayAccess(Expression array, Expression index) { super(2); object_print_method = class_print_method; children.add(array); array.setParent(this); children.add(index); index.setParent(this); }
public ThrowExpression(Expression expr) { super(1); object_print_method = class_print_method; children.add(expr); expr.setParent(this); }
public OffsetofExpression(List<Specifier> pspecs, Expression expr) { object_print_method = class_print_method; children.add(expr); expr.setParent(this); specs = new LinkedList<Specifier>(); specs.addAll(pspecs); }
/** * Creates an array access with multiple index expressions. * * @param array An expression evaluating to an address. * @param indices A list of expressions with which to index the array. */ public ArrayAccess(Expression array, List indices) { super(indices.size() + 1); object_print_method = class_print_method; children.add(array); array.setParent(this); setIndices(indices); }
/** * Set the list of index expressions. * * @param indices A list of expressions. */ public void setIndices(List indices) { /* clear out everything but the first item */ Expression name = (Expression) children.get(0); children.clear(); children.add(name); Iterator iter = indices.iterator(); while (iter.hasNext()) { Expression expr = null; try { expr = (Expression) iter.next(); } catch (ClassCastException e) { throw new IllegalArgumentException(); } children.add(expr); expr.setParent(this); } }
public void addIndex(Expression expr) { if (expr.getParent() != null) throw new NotAnOrphanException(); children.add(expr); expr.setParent(this); }
/** * Sets the nth index expression of this array access. * * @param n The position of the index expression. * @param expr The expression to use for the index. * @throws IndexOutOfBoundsException if there is no expression at that position. */ public void setIndex(int n, Expression expr) { if (expr.getParent() != null) throw new NotAnOrphanException(); children.set(n + 1, expr); expr.setParent(this); }
/** * Creates a statement that returns an expression. * * @param expr The expression to return. */ public ReturnStatement(Expression expr) { object_print_method = class_print_method; children.add(expr); expr.setParent(this); }