Skip to content

Commit

Permalink
further program reductions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Feb 12, 2025
1 parent 865651c commit 222857a
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 0 deletions.
Binary file modified AssertStatement.class
Binary file not shown.
Binary file modified AssignStatement.class
Binary file not shown.
Binary file modified BasicExpression.class
Binary file not shown.
15 changes: 15 additions & 0 deletions BasicExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,21 @@ public static BasicExpression newStaticCallBasicExpression(
return res;
}

public static BasicExpression newStaticCallExpression(
String cls, String op, Expression par)
{ Vector pars = new Vector();
pars.add(par);
BasicExpression res = new BasicExpression(op);
BasicExpression obj = new BasicExpression(cls);
obj.umlkind = CLASSID;
res.setObjectRef(obj);
res.umlkind = UPDATEOP;
res.isStatic = true;
res.isEvent = true;
res.parameters = pars;
return res;
}

public static BasicExpression newStaticCallBasicExpression(
String f, Expression obj, Expression par)
{ Vector pars = new Vector();
Expand Down
Binary file modified BreakStatement.class
Binary file not shown.
Binary file modified CaseStatement.class
Binary file not shown.
Binary file modified CatchStatement.class
Binary file not shown.
Binary file modified ConditionalStatement.class
Binary file not shown.
Binary file modified ContinueStatement.class
Binary file not shown.
Binary file modified CreationStatement.class
Binary file not shown.
Binary file modified ErrorStatement.class
Binary file not shown.
Binary file modified FinalStatement.class
Binary file not shown.
Binary file modified IfCase.class
Binary file not shown.
Binary file modified IfStatement.class
Binary file not shown.
Binary file modified ImplicitInvocationStatement.class
Binary file not shown.
Binary file modified InvocationStatement.class
Binary file not shown.
Binary file modified ReturnStatement.class
Binary file not shown.
Binary file modified SequenceStatement.class
Binary file not shown.
Binary file modified Statement.class
Binary file not shown.
70 changes: 70 additions & 0 deletions Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ else if (st instanceof SequenceStatement)

if (sq.size() == 2)
{ // patterns are I := I + 1; V := V + I
// I := I + 1; V := V - I
// I := I + 1; V := V * I var /= I

Statement stat1 = sq.getStatement(0);
Expand Down Expand Up @@ -554,6 +555,75 @@ else if ((lhs2 + " + 1").equals("" + rhs2) &&

JOptionPane.showInputDialog(">> Code reduction of " + st + " to: " + ss);

return ss;
}
else if ((lhs1 + " + 1").equals("" + rhs1) &&
(lhs2 + " * " + lhs1).equals("" + rhs2))
{ // I := I + 1; V := V * I
// reduces to V := V * MathLib.factorial(I + n)/
// MathLib.factorial(I);
// I := I + n

Expression rsize =
Expression.simplifySize(rng);
Expression rsize1 =
new BinaryExpression("+", lhs1, rsize);
Expression fact1 =
BasicExpression.newStaticCallExpression("MathLib",
"factorial", rsize1);
Expression fact2 =
BasicExpression.newStaticCallExpression("MathLib",
"factorial", lhs1);

BinaryExpression idiv =
new BinaryExpression("/", fact1, fact2);
AssignStatement asn1 =
new AssignStatement(lhs2,
new BinaryExpression("*", lhs2, idiv));
AssignStatement asn2 =
new AssignStatement(lhs1,
new BinaryExpression("+", lhs1, rsize));
SequenceStatement ss = new SequenceStatement();
ss.addStatement(asn1);
ss.addStatement(asn2);

JOptionPane.showInputDialog(">> Code reduction of " + st + " to: " + ss);

return ss;
}
else if ((lhs2 + " + 1").equals("" + rhs2) &&
(lhs1 + " * " + lhs2).equals("" + rhs1))
{ // V := V * I ; I := I + 1
// reduces to V := V * (I+n-1)!/I!;
// I := I + n

Expression rsize =
Expression.simplifySize(rng);
Expression rsize1 =
new BinaryExpression("+", lhs2,
new BinaryExpression("-", rsize,
new BasicExpression(1)));
Expression fact1 =
BasicExpression.newStaticCallExpression("MathLib",
"factorial", rsize1);
Expression fact2 =
BasicExpression.newStaticCallExpression("MathLib",
"factorial", lhs2);

BinaryExpression idiv =
new BinaryExpression("/", fact1, fact2);
AssignStatement asn1 =
new AssignStatement(lhs1,
new BinaryExpression("*", lhs1, idiv));
AssignStatement asn2 =
new AssignStatement(lhs2,
new BinaryExpression("+", lhs2, rsize));
SequenceStatement ss = new SequenceStatement();
ss.addStatement(asn1);
ss.addStatement(asn2);

JOptionPane.showInputDialog(">> Code reduction of " + st + " to: " + ss);

return ss;
}
}
Expand Down
Binary file modified TryStatement.class
Binary file not shown.
Binary file modified WhileStatement.class
Binary file not shown.

0 comments on commit 222857a

Please sign in to comment.