Skip to content

Commit

Permalink
bitrotation operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Aug 23, 2024
1 parent dc8a3a6 commit 3235439
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
74 changes: 66 additions & 8 deletions ASTCompositeTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20724,8 +20724,9 @@ public String queryForm()
return "MathLib.bitwiseAnd(" + e1x + ", " + e2x + ")";
}

if ("|".equals(op + "") && e1.isInteger() &&
e2.isInteger())
if ("|".equals(op + "") &&
(e1.isInteger() ||
e2.isInteger()))
{ ASTTerm.setType(this, "int");

if (e1.expression != null &&
Expand All @@ -20739,10 +20740,13 @@ public String queryForm()
return "MathLib.bitwiseOr(" + e1x + ", " + e2x + ")";
}

if ("^".equals(op + "") && e1.isInteger() &&
e2.isInteger())
if ("^".equals(op + "") &&
(e1.isInteger() ||
e2.isInteger()))
{ ASTTerm.setType(this, "int");

// JOptionPane.showInputDialog("bitwiseOr for " + e1 + " " + e2);

if (e1.expression != null &&
e2.expression != null)
{ Vector parms = new Vector();
Expand Down Expand Up @@ -24898,6 +24902,54 @@ else if (("decode".equals(called) ||

return "(" + callp1 + ")->toLong()";
}
else if ("rotateRight".equals(called) &&
"Integer".equals(argliteral))
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
ASTTerm callarg2 = (ASTTerm) cargs.get(1);

String callp1 = callarg1.toKM3();
String callp2 = callarg2.toKM3();

ASTTerm.setType(thisliteral,"int");

if (callarg1.expression != null &&
callarg2.expression != null)
{ Vector rargs = new Vector();
rargs.add(callarg1.expression);
rargs.add(callarg2.expression);

expression =
BasicExpression.newStaticCallBasicExpression(
"bitwiseRotateRight", "MathLib",
rargs);
}

return "MathLib.bitwiseRotateRight(" + callp1 + "," + callp2 + ")";
}
else if ("rotateLeft".equals(called) &&
"Integer".equals(argliteral))
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
ASTTerm callarg2 = (ASTTerm) cargs.get(1);

String callp1 = callarg1.toKM3();
String callp2 = callarg2.toKM3();

ASTTerm.setType(thisliteral,"int");

if (callarg1.expression != null &&
callarg2.expression != null)
{ Vector rargs = new Vector();
rargs.add(callarg1.expression);
rargs.add(callarg2.expression);

expression =
BasicExpression.newStaticCallBasicExpression(
"bitwiseRotateLeft", "MathLib",
rargs);
}

return "MathLib.bitwiseRotateLeft(" + callp1 + "," + callp2 + ")";
}
else if ("longBitsToDouble".equals(called) &&
"Double".equals(argliteral))
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
Expand Down Expand Up @@ -35848,7 +35900,7 @@ else if (postse == null)
expression.setType(new Type("long", null));
}
return "(" + e1x + "/(2->pow(" + e2x + ")))->oclAsType(long)";
}
} // But >>> is different to >>

if ("instanceof".equals(op + ""))
{ ASTTerm.setType(this, "boolean");
Expand Down Expand Up @@ -36035,10 +36087,16 @@ else if (e1.isString() || e2.isString())
}


if ("^".equals(op + "") && e1.isInteger() &&
e2.isInteger())
if ("^".equals(op + "") &&
(e1.isInteger() ||
e2.isInteger()))
{ ASTTerm.setType(this, "int");

String e1xx = e1.toKM3();
String e2xx = e2.toKM3();

JOptionPane.showInputDialog("bitwiseOr for " + e1 + " " + e2 + " " + e1.expression + " " + e2.expression);

if (e1.expression != null &&
e2.expression != null)
{ Vector parms = new Vector();
Expand All @@ -36048,7 +36106,7 @@ else if (e1.isString() || e2.isString())
expression.setType(new Type("int", null));
}

return "MathLib.bitwiseXor(" + e1x + ", " + e2x + ")";
return "MathLib.bitwiseXor(" + e1xx + ", " + e2xx + ")";
}


Expand Down
6 changes: 5 additions & 1 deletion ASTTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1366,12 +1366,16 @@ public boolean isCharacter()
}

public boolean isInteger()
{ String litf = literalForm();
{
String litf = literalForm();
String typ = ASTTerm.getType(litf);
if (typ == null)
{ return Expression.isInteger(litf) ||
Expression.isLong(litf);
}

// JOptionPane.showInputDialog("isInteger for " + this + " " + typ);

return ASTTerm.isInteger(typ);
}

Expand Down
14 changes: 10 additions & 4 deletions UCDArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -9913,7 +9913,8 @@ public void generateCSharp(PrintWriter out, PrintWriter out2)
out.println("using System.Data.SqlClient;");
out.println("using System.Net.Sockets;");
out.println("using System.Net.Http;");

out.println("using System.Numerics;");

out.println("using System.Windows.Forms;\n\n");

out.println("");
Expand Down Expand Up @@ -10103,6 +10104,7 @@ public void generateCPP(PrintWriter out, PrintWriter out2)
out2.println("#include <functional>");
out2.println("#include <cstdlib>");
out2.println("#include <condition_variable>");
out2.println("#include <bit>");
out2.println("#include <sys/stat.h>");
out2.println("#include <direct.h>");
out2.println("#include <winsock2.h>");
Expand Down Expand Up @@ -10744,7 +10746,9 @@ public void generateJava7(PrintWriter out, PrintWriter out2)
Entity oclrandom =
(Entity) ModelElement.lookupByName("OclRandom", entities);
if (oclrandom != null)
{ BSystemTypes.generateLibraryJava7("OclRandom",out); }
{ BSystemTypes.generateLibraryJava7("OclRandom",out);
BSystemTypes.generateLibraryJava7("Pcg32",out);
}

Entity oclfile =
(Entity) ModelElement.lookupByName("OclFile", entities);
Expand Down Expand Up @@ -10885,7 +10889,8 @@ public void printCSharpHeader(PrintWriter out)
out.println("using System.Data.Common;");
out.println("using System.Data.SqlClient;");
out.println("using System.Net.Sockets;");

out.println("using System.Numerics;");

out.println("using System.Windows.Forms;");

for (int i = 0; i < importList.size(); i++)
Expand Down Expand Up @@ -27427,7 +27432,8 @@ public void generateMutationTesterCSharp()
mtout.println("using System.Data.Common;");
mtout.println("using System.Data.SqlClient;");
mtout.println("using System.Net.Sockets;");

mtout.println("using System.Numerics;");

mtout.println();
mtout.println("public class MutationTest");
mtout.println("{");
Expand Down

0 comments on commit 3235439

Please sign in to comment.