Example #1
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);
   }
 }
 protected Sexpr diff(Sexpr var) {
   return Symbolic.multiply(arg.diff(var), new Exp(arg));
 }
 public Sexpr eval(TreeMap<String, Sexpr> t) throws IOException {
   return Symbolic.exp(arg.eval(t));
 }