/**
   * 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);
  }
Beispiel #2
0
 /*
  * If we visit a nested abstraction, we just launch a new lift operation on
  * this abstraction using current context as namespace and returns an
  * Application object
  *
  * @see jaskell.compiler.JaskellVisitor#visit(jaskell.compiler.core.Abstraction)
  */
 public Object visit(Abstraction a) {
   if (!lift) {
       /* top level abstractions */
     lift = true;
     a.setBody((Expression) a.getBody().visit(this));
     return a;
   }
   /* first visit body */
   a.setBody((Expression) a.getBody().visit(this));
   /* retrieve outer LocalBindings */
   Set captured = new HashSet();
   CaptureCollector cc = new CaptureCollector(captured);
   a.visit(cc);
   /* return the newly computed abstraction as an application spine */
   String vname;
   try {
     vname = lift(a, captured);
     Expression ex = applyLifted(vname, captured);
     ex.setParent(a.getParent());
     return ex;
   } catch (SymbolException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return null;
   }
 }
Beispiel #3
0
  public ThrowExpression(Expression expr) {
    super(1);

    object_print_method = class_print_method;

    children.add(expr);
    expr.setParent(this);
  }
Beispiel #4
0
  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);
  }
 public void setParser(Parser parser) {
   super.setParser(parser);
   if (_arguments != null) {
     final int n = _arguments.size();
     for (int i = 0; i < n; i++) {
       final Expression exp = (Expression) _arguments.elementAt(i);
       exp.setParser(parser);
       exp.setParent(this);
     }
   }
 }
  public void setRight(Expression right) {
    if (this.right != null) {
      // unset left's parent
      this.right.setParent(null);
    }

    this.right = right;

    if (right != null) {
      right.setParent(this);
    }
  }
  public void setLeft(Expression left) {
    if (this.left != null) {
      // unset left's parent
      this.left.setParent(null);
    }

    this.left = left;

    if (left != null) {
      left.setParent(this);
    }
  }
Beispiel #9
0
 /*
  * Definitions in the let block are lifted to top-level and the corresponding
  * references in the body are replaced by new definitions.
  *
  * @see jaskell.compiler.JaskellVisitor#visit(jaskell.compiler.core.Let)
  */
 public Object visit(Let let) {
   HashMap subst = new HashMap(); /* substitution map */
   Set lambdas = new HashSet(); /* newly created toplevels ? */
   Iterator it = let.getBindings().entrySet().iterator();
   /* first lift all definitions in this let */
   while (it.hasNext()) {
     Map.Entry entry = (Map.Entry) it.next();
     String name = (String) entry.getKey();
     Expression e = (Expression) entry.getValue();
     /* reset lift flag */
     lift = false;
     Expression ndef = (Expression) e.visit(this);
     ndef.setParent(let);
     /* lift new definition */
     Set captured = new HashSet();
     CaptureCollector cc = new CaptureCollector(captured);
     ndef.visit(cc);
     String vname;
     try {
       vname = lift(ndef, captured);
       lambdas.add(vname);
       /*
        * store new application spine in a map for later substitution
        */
       subst.put(name, applyLifted(vname, captured));
     } catch (SymbolException e1) {
       e1.printStackTrace();
     }
   }
   /* second, replace old occurences in new definitions */
   it = lambdas.iterator();
   while (it.hasNext()) {
     String n = (String) it.next();
     Expression e;
     try {
       e = (Expression) ns.resolve(n);
       ns.rebind(n, (Expression) e.visit(new Substitution(subst)));
     } catch (SymbolException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
   /* thirs, replace occurences in body of let and return it */
   return let.getBody().visit(new Substitution(subst));
 }
  /**
   * 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);
    }
  }
Beispiel #11
0
 public void setOperands(Expression op, Expression ignore) {
   children = new Expression[] {op};
   op.setParent(this);
 }
Beispiel #12
0
 /** Initializes a predicate. */
 public Predicate(Expression exp) {
   _exp = exp;
   _exp.setParent(this);
 }
Beispiel #13
0
 public void setParameter(Expression parameter) throws ParseException {
   if (this.parameter != null) throw new ParseException("Can not modify parameter.", getOffset());
   this.parameter = parameter;
   parameter.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);
  }
Beispiel #15
0
 /**
  * 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);
 }
  public FromOrToExpressionClause(Expression expr, int startOffset, int endOffset) {
    super(startOffset, endOffset);

    this.expr = expr;
    expr.setParent(this);
  }
Beispiel #17
0
 public void setOperands(Expression left, Expression right) {
   children[0] = left;
   children[1] = right;
   left.setParent(this);
   right.setParent(this);
 }
  public void addIndex(Expression expr) {
    if (expr.getParent() != null) throw new NotAnOrphanException();

    children.add(expr);
    expr.setParent(this);
  }