Skip to content

Commit ef5e489

Browse files
authored
Updated CGBE and libraries
1 parent b1c5e59 commit ef5e489

File tree

8 files changed

+478
-57
lines changed

8 files changed

+478
-57
lines changed

ASTCompositeTerm.java

Lines changed: 164 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9227,7 +9227,58 @@ else if ("swap".equals(called) &&
92279227
{ ASTTerm obj = (ASTTerm) cargs.get(1);
92289228
ASTTerm rep = (ASTTerm) cargs.get(2);
92299229
String objx = obj.toKM3();
9230-
String repx = rep.toKM3();
9230+
String repx = rep.toKM3();
9231+
9232+
if (callarg1.expression != null &&
9233+
obj.expression != null &&
9234+
rep.expression != null)
9235+
{ String x_1 = Identifier.nextIdentifier("x_");
9236+
Expression xbe =
9237+
BasicExpression.newVariableBasicExpression(
9238+
x_1);
9239+
Expression objind =
9240+
new BinaryExpression("+", obj.expression,
9241+
unitExpression);
9242+
Expression repind =
9243+
new BinaryExpression("+", rep.expression,
9244+
unitExpression);
9245+
Expression test1 =
9246+
new BinaryExpression("=", xbe, repind);
9247+
Expression test2 =
9248+
new BinaryExpression("=", xbe, objind);
9249+
9250+
Expression argobj =
9251+
BasicExpression.newIndexedBasicExpression(
9252+
callarg1.expression,objind);
9253+
Expression argrep =
9254+
BasicExpression.newIndexedBasicExpression(
9255+
callarg1.expression,repind);
9256+
Expression argx =
9257+
BasicExpression.newIndexedBasicExpression(
9258+
callarg1.expression,xbe);
9259+
9260+
Expression ifstat1 =
9261+
new ConditionalExpression(test1,argobj,argx);
9262+
Expression ifstat2 =
9263+
new ConditionalExpression(test2,
9264+
argrep,ifstat1);
9265+
Vector pars = new Vector();
9266+
pars.add(unitExpression);
9267+
pars.add(new UnaryExpression("->size",
9268+
callarg1.expression));
9269+
9270+
Expression subrang =
9271+
BasicExpression.newFunctionBasicExpression(
9272+
"subrange", "Integer", pars);
9273+
Expression colldom =
9274+
new BinaryExpression(":", xbe, subrang);
9275+
expression =
9276+
new BinaryExpression("|C", colldom, ifstat2);
9277+
statement =
9278+
new AssignStatement(callarg1.expression,
9279+
expression);
9280+
}
9281+
92319282
return callp1 + " := Integer.subrange(1," + callp1 + ".size)->collect(x_1 | if x_1 = " + objx + "+1 then " + callp1 + "[" + repx + "+1] else if x_1 = " + repx + "+1 then " + callp1 + "[" + objx + "+1] else " + callp1 + "[x_1] endif endif )";
92329283
}
92339284
return callp1;
@@ -9242,6 +9293,50 @@ else if ("rotate".equals(called) &&
92429293
if (cargs.size() > 1)
92439294
{ ASTTerm nn = (ASTTerm) cargs.get(1);
92449295
String nx = nn.toKM3();
9296+
9297+
if (callarg1.expression != null &&
9298+
nn.expression != null)
9299+
{ Expression argsize =
9300+
new UnaryExpression("->size",
9301+
callarg1.expression);
9302+
String x_1 = Identifier.nextIdentifier("x_");
9303+
Expression xbe =
9304+
BasicExpression.newVariableBasicExpression(
9305+
x_1);
9306+
Expression ind1 =
9307+
new BinaryExpression("-", xbe,
9308+
unitExpression);
9309+
Expression ind2 =
9310+
new BinaryExpression("-", ind1,
9311+
nn.expression);
9312+
ind2.setBrackets(true);
9313+
Expression ind3 =
9314+
new BinaryExpression("mod", ind2, argsize);
9315+
ind3.setBrackets(true);
9316+
Expression ind4 =
9317+
new BinaryExpression("+", ind3,
9318+
unitExpression);
9319+
9320+
Expression appl =
9321+
new BinaryExpression("->at",
9322+
callarg1.expression,ind4);
9323+
9324+
Vector pars = new Vector();
9325+
pars.add(unitExpression);
9326+
pars.add(argsize);
9327+
9328+
Expression subrang =
9329+
BasicExpression.newFunctionBasicExpression(
9330+
"subrange", "Integer", pars);
9331+
Expression colldom =
9332+
new BinaryExpression(":", xbe, subrang);
9333+
expression =
9334+
new BinaryExpression("|C", colldom, appl);
9335+
statement =
9336+
new AssignStatement(callarg1.expression,
9337+
expression);
9338+
}
9339+
92459340
return callp1 + " := Integer.subrange(1," + callp1 + ".size)->collect( x_1 | " + callp1 + "->at(((x_1-1-" + nx + ") mod " + callp1 + ".size) + 1) )";
92469341
}
92479342
return callp1;
@@ -9252,8 +9347,18 @@ else if ("shuffle".equals(called) &&
92529347
String callp1 = callarg1.toKM3();
92539348

92549349
ASTTerm.setType(thisliteral,"Sequence");
9350+
9351+
if (callarg1.expression != null)
9352+
{ expression =
9353+
BasicExpression.newStaticCallBasicExpression(
9354+
"randomiseSequence", "OclRandom",
9355+
callarg1.expression);
9356+
statement =
9357+
new AssignStatement(callarg1.expression,
9358+
expression);
9359+
}
92559360

9256-
return callp1 + " := Sequence{}->union(" + callp1 + "->asBag())";
9361+
return callp1 + " := OclRandom.randomiseSequence(" + callp1 + ")";
92579362
}
92589363
else if ("forName".equals(called) && "Class".equals(argliteral))
92599364
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
@@ -13511,6 +13616,16 @@ else if ("readBoolean".equals(called) && arg.isFile())
1351113616

1351213617
return "if " + args + ".readByte() = 0 then false else true endif";
1351313618
}
13619+
else if ("readChar".equals(called) &&
13620+
arg.isFile())
13621+
{ if (arg.expression != null)
13622+
{ expression =
13623+
BasicExpression.newCallBasicExpression("read", arg.expression);
13624+
}
13625+
ASTTerm.setType(this,"String");
13626+
13627+
return args + ".read()";
13628+
}
1351413629
else if (("readByte".equals(called) ||
1351513630
"readUnsignedByte".equals(called)) &&
1351613631
arg.isFile())
@@ -13521,7 +13636,53 @@ else if (("readByte".equals(called) ||
1352113636
ASTTerm.setType(this,"int");
1352213637

1352313638
return args + ".readByte()";
13524-
} // TODO: othercases
13639+
}
13640+
else if (("readShort".equals(called) ||
13641+
"readUnsignedShort".equals(called)) &&
13642+
arg.isFile())
13643+
{ Expression two = new BasicExpression(2);
13644+
if (arg.expression != null)
13645+
{ Expression callexpression =
13646+
BasicExpression.newCallBasicExpression(
13647+
"readNbytes", arg.expression, two);
13648+
expression =
13649+
BasicExpression.newStaticCallBasicExpression(
13650+
"bytes2integer", "MathLib", callexpression);
13651+
}
13652+
ASTTerm.setType(this,"int");
13653+
13654+
return "MathLib.bytes2integer(" + args + ".readNbytes(2))";
13655+
}
13656+
else if ("readInt".equals(called) &&
13657+
arg.isFile())
13658+
{ Expression four = new BasicExpression(4);
13659+
if (arg.expression != null)
13660+
{ Expression callexpression =
13661+
BasicExpression.newCallBasicExpression(
13662+
"readNbytes", arg.expression, four);
13663+
expression =
13664+
BasicExpression.newStaticCallBasicExpression(
13665+
"bytes2integer", "MathLib", callexpression);
13666+
}
13667+
ASTTerm.setType(this,"int");
13668+
13669+
return "MathLib.bytes2integer(" + args + ".readNbytes(4))";
13670+
}
13671+
else if ("readLong".equals(called) &&
13672+
arg.isFile())
13673+
{ Expression eight = new BasicExpression(8);
13674+
if (arg.expression != null)
13675+
{ Expression callexpression =
13676+
BasicExpression.newCallBasicExpression(
13677+
"readNbytes", arg.expression, eight);
13678+
expression =
13679+
BasicExpression.newStaticCallBasicExpression(
13680+
"bytes2integer", "MathLib", callexpression);
13681+
}
13682+
ASTTerm.setType(this,"int");
13683+
13684+
return "MathLib.bytes2integer(" + args + ".readNbytes(8))";
13685+
} // TODO: othercases. Float is 4 bytes, Double 8
1352513686
else if ("getInputStream".equals(called) &&
1352613687
arg.isFile())
1352713688
{ ASTTerm.setType(this,"OclFile");

0 commit comments

Comments
 (0)