示例#1
0
 @Override
 public SignedExpression clone() {
   SignedExpression result = (SignedExpression) super.clone();
   result.expression = expression == null ? null : expression.clone();
   result.configureParentToAllChilds();
   return result;
 }
  @Override
  public Expression clone() {
    // TODO close prameter List

    if (target != null) return new NewExpression(target.clone(), classCreated, arguments);
    else return new NewExpression(null, classCreated, arguments);
  }
 @Override
 public AbstractVariableDeclaration clone() {
   AbstractVariableDeclaration clone = (AbstractVariableDeclaration) super.clone();
   clone.variable = variable == null ? null : variable.clone();
   clone.value = value == null ? null : value.clone();
   clone.configureParentToAllChilds();
   return clone;
 }
示例#4
0
 @Override
 public Expression clone() {
   LinkedList<Expression> cargs = new LinkedList<Expression>();
   for (Expression e : arguments) {
     cargs.add(e.clone());
   }
   return new InvokeExpression(this.invokedProcedure, cargs);
 }
示例#5
0
  /**
   * Returns a reconstructed Cetus expression from the simple expression.
   *
   * @return the Cetus expression.
   */
  protected Expression getExpression() {
    Expression ret = null;

    if (children.isEmpty()) ret = (Expression) expr.clone();
    else if (sop == TREE) {
      ret = (Expression) expr.clone();
      for (int i = 0; i < children.size(); ++i) ret.setChild(i, getChild(i).getExpression());
    } else if (cop.get(sop) instanceof UnaryOperator) {
      UnaryOperator uop = (UnaryOperator) cop.get(sop);
      ret = new UnaryExpression(uop, getChild(0).getExpression());
    } else if (cop.get(sop) instanceof BinaryOperator) {
      BinaryOperator bop = (BinaryOperator) cop.get(sop);
      Iterator<SimpleExpression> iter = children.iterator();
      if (iter.hasNext()) ret = iter.next().getExpression();
      while (iter.hasNext()) ret = new BinaryExpression(ret, bop, iter.next().getExpression());
    } else Tools.exit("[SimpleExpression] unknown simple expression");

    return ret;
  }
示例#6
0
 /**
  * Performs normalization of the non-identifier arguments. It creates a temporary compound
  * statement filled with the temporary assignments to set of identifiers that takes the original
  * arugments as RHS.
  */
 @SuppressWarnings("unchecked")
 protected void normalizeArguments() {
   if (exception != 0) { // no normalization is possible.
     return;
   }
   temp_assignments = new CompoundStatement();
   norm_arguments = new ArrayList<Expression>(4);
   for (int i = 0; i < arguments.size(); i++) {
     Symbol param = getParameters().get(i);
     Expression arg = Symbolic.simplify(arguments.get(i));
     // Allows normalization of identifers which are global array names.
     if (arg instanceof Identifier) {
       Symbol base = ((Identifier) arg).getSymbol();
       if (SymbolTools.isGlobal(base) && SymbolTools.isArray(base)) {
         arg =
             new UnaryExpression(
                 UnaryOperator.ADDRESS_OF, new ArrayAccess(arg.clone(), new IntegerLiteral(0)));
       }
     }
     Expression new_arg = arg;
     if (!(arg instanceof Literal || arg instanceof Identifier)) {
       arg = normalize(arg, param);
       List type_spec = param.getTypeSpecifiers();
       List array_spec = param.getArraySpecifiers();
       // Assumes there is only one element in array_spec.
       if (!array_spec.isEmpty()) {
         type_spec.add(PointerSpecifier.UNQUALIFIED);
       }
       new_arg = SymbolTools.getTemp(temp_assignments, type_spec, "arg");
       Expression assign =
           new AssignmentExpression(new_arg, AssignmentOperator.NORMAL, arg.clone());
       temp_assignments.addStatement(new ExpressionStatement(assign));
     }
     norm_arguments.add(new_arg);
   }
 }
示例#7
0
 /**
  * Creates a new object with the same primitive data, and recursively creates new member data
  * objects as well.
  *
  * @return The clone node.
  */
 public Object clone() {
   return new FieldAccess((Expression) object.clone(), name, -1, -1);
 }
示例#8
0
 /** Normalization for points-to analysis. */
 private static Expression normalize(Expression arg, Symbol param) {
   Expression ret = arg.clone(); // default behavior.
   // Converts array accesses to address-of expressions.
   if (ret instanceof ArrayAccess) {
     ArrayAccess array = (ArrayAccess) ret;
     // Normalize the array name.
     Expression name = normalize(array.getArrayName(), null);
     Symbol base = SymbolTools.getSymbolOf(name);
     if (base != null && param != null && SymbolTools.isPointerParameter(param)) {
       // case 1: the base symbol has an array specifier.
       // --> - keeps the array indices while adding trailing [0].
       //     - converts to address-of expression.
       //     - adds dereference operator if base is a formal parameter
       if (SymbolTools.isArray(base)) {
         // Adds a trailing subscript "[0]" intentionally.
         array.addIndex(new IntegerLiteral(0));
         ret = new UnaryExpression(UnaryOperator.ADDRESS_OF, ret);
         // Formal parameter is normalized: a[10] to (*a)[10].
         // This conversion is used only internally (not legal in C).
         if (SymbolTools.isPointerParameter(base)) {
           array
               .getArrayName()
               .swapWith(new UnaryExpression(UnaryOperator.DEREFERENCE, name.clone()));
         }
         // case 2: the base symbol does not have an array specifier.
         // --> just take the base object while converting a subscript
         // to a dereference.
       } else {
         ret = name;
         for (int i = 0; i < array.getNumIndices(); i++) {
           ret = new UnaryExpression(UnaryOperator.DEREFERENCE, ret.clone());
         }
       }
     } else { // just normalizes the array name.
       array.getArrayName().swapWith(name);
     }
     // Removes pointer access and adds trailing dummy index for pointer
     // type.
   } else if (ret instanceof AccessExpression) {
     AccessExpression access = (AccessExpression) ret;
     // POINTER_ACCESS to MEMBER_ACCESS
     if (access.getOperator() == AccessOperator.POINTER_ACCESS) {
       // Normalize the LHS.
       Expression lhs = normalize(access.getLHS(), null);
       ret =
           new AccessExpression(
               new UnaryExpression(UnaryOperator.DEREFERENCE, lhs.clone()),
               AccessOperator.MEMBER_ACCESS,
               access.getRHS().clone());
     }
     // Pointer type to address-of expression.
     if (param != null && SymbolTools.isPointerParameter(param)) {
       ret =
           new UnaryExpression(
               UnaryOperator.ADDRESS_OF, new ArrayAccess(ret.clone(), new IntegerLiteral(0)));
     }
     // Just normalize the expression child.
   } else if (ret instanceof UnaryExpression) {
     UnaryExpression ue = (UnaryExpression) ret;
     ue.setExpression(normalize(ue.getExpression(), null));
     // Tries to convert simple pointer arithmetic to array access.
   } else if (ret instanceof BinaryExpression) {
     BinaryExpression be = (BinaryExpression) ret;
     Expression lhs = normalize(be.getLHS(), null);
     Expression rhs = normalize(be.getRHS(), null);
     if (param != null
         && SymbolTools.isPointerParameter(param)
         && be.getOperator() == BinaryOperator.ADD) {
       if (isPointerArithmeticOperand(lhs, rhs)) {
         ret =
             new UnaryExpression(
                 UnaryOperator.ADDRESS_OF, new ArrayAccess(rhs.clone(), lhs.clone()));
       } else if (isPointerArithmeticOperand(rhs, lhs)) {
         ret =
             new UnaryExpression(
                 UnaryOperator.ADDRESS_OF, new ArrayAccess(lhs.clone(), rhs.clone()));
       }
     } else {
       ret = new BinaryExpression(lhs.clone(), be.getOperator(), rhs.clone());
     }
     // Type cast is discarded.
   } else if (ret instanceof Typecast) {
     ret = (Expression) ret.getChildren().get(0);
   }
   return ret;
 }
示例#9
0
 protected Object clone() throws CloneNotSupportedException {
   return new FromOrToExpressionClause(
       (Expression) expr.clone(), getOffset(), getOffset() + getLength());
 }