Skip to content

Commit c142a66

Browse files
authored
Extended CSTL and libraries
Added <action> clause to CSTL code generator. Enhanced libraries and code generators. Go code generator is now complete for the principal OCL 2.4 sequence and set operations and string and numeric types. Only ->sortedBy and ->maximalElements/->minimalElements remain to be implemented.
1 parent ef5e489 commit c142a66

File tree

12 files changed

+671
-31
lines changed

12 files changed

+671
-31
lines changed

ASTBasicTerm.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,42 +979,56 @@ public String toKM3()
979979
{ modelElement = new Type("ProgramException", null);
980980
expression = new BasicExpression((Type) modelElement);
981981
return "ProgramException"; }
982-
if ("IOException".equals(value) ||
982+
if ("IOException".equals(value) ||
983+
"SQLException".equals(value) ||
983984
"EOFException".equals(value) ||
984985
"SocketException".equals(value))
985986
{ modelElement = new Type("IOException", null);
986987
expression = new BasicExpression((Type) modelElement);
987-
return "IOException"; }
988+
return "IOException";
989+
}
990+
988991
if ("ClassCastException".equals(value))
989992
{ modelElement = new Type("CastingException", null);
990993
expression = new BasicExpression((Type) modelElement);
991-
return "CastingException"; }
994+
return "CastingException";
995+
}
996+
992997
if ("NullPointerException".equals(value))
993998
{ modelElement = new Type("NullAccessException", null);
994999
expression = new BasicExpression((Type) modelElement);
995-
return "NullAccessException"; }
1000+
return "NullAccessException";
1001+
}
1002+
9961003
if ("ArithmeticException".equals(value))
9971004
{ modelElement = new Type("ArithmeticException", null);
9981005
expression = new BasicExpression((Type) modelElement);
999-
return "ArithmeticException"; }
1006+
return "ArithmeticException";
1007+
}
1008+
10001009
if (value.endsWith("IndexOutOfBoundsException") ||
10011010
"ArrayStoreException".equals(value))
10021011
{ modelElement = new Type("IndexingException", null);
10031012
expression = new BasicExpression((Type) modelElement);
10041013
return "IndexingException";
10051014
}
1015+
10061016
if ("NoSuchElementException".equals(value) ||
1017+
"MalformedURLException".equals(value) ||
10071018
"UnknownHostException".equals(value))
10081019
{ modelElement = new Type("IncorrectElementException", null);
10091020
expression = new BasicExpression((Type) modelElement);
10101021
return "IncorrectElementException";
10111022
}
1023+
10121024
if ("InputMismatchException".equals(value) ||
10131025
"UnsupportedOperationException".equals(value) ||
1026+
"IllegalStateException".equals(value) ||
10141027
"NumberFormatException".equals(value))
10151028
{ modelElement = new Type("IncorrectElementException", null);
10161029
expression = new BasicExpression((Type) modelElement);
1017-
return "IncorrectElementException"; }
1030+
return "IncorrectElementException";
1031+
}
10181032
// if ("ArrayIndexOutOfBoundsException".equals(value) ||
10191033
// "StringIndexOutOfBoundsException".equals(value))
10201034
// { return "IndexingException"; }
@@ -1025,7 +1039,8 @@ public String toKM3()
10251039
"BindException".equals(value))
10261040
{ modelElement = new Type("AccessingException", null);
10271041
expression = new BasicExpression((Type) modelElement);
1028-
return "AccessingException"; }
1042+
return "AccessingException";
1043+
}
10291044
if (value.endsWith("Exception"))
10301045
{ modelElement = new Type("ProgramException", null);
10311046
expression = new BasicExpression((Type) modelElement);

ASTCompositeTerm.java

Lines changed: 150 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5950,14 +5950,17 @@ else if ("fread".equals(fname) && args.size() == 4)
59505950
else if ("fwrite".equals(fname) && args.size() == 4)
59515951
{ Expression fle = (Expression) args.get(3);
59525952
Expression data = (Expression) args.get(0);
5953+
Expression sze = (Expression) args.get(1);
59535954
Expression n = (Expression) args.get(2);
5955+
59545956
if (data.isStringSequence())
5955-
{ Vector pars = new Vector();
5957+
{ // fle.write(data.subrange(1,n)->sum())
5958+
Vector pars = new Vector();
59565959
pars.add(unitExpression);
59575960
pars.add(n);
59585961
Expression subrng =
5959-
BasicExpression.newFunctionBasicExpression("subrange",
5960-
data, pars);
5962+
BasicExpression.newFunctionBasicExpression(
5963+
"subrange", data, pars);
59615964
Expression sumexpr =
59625965
new UnaryExpression("->sum", subrng);
59635966
BasicExpression res =
@@ -5975,8 +5978,8 @@ else if (data.isIntSequence())
59755978
pars.add(unitExpression);
59765979
pars.add(n);
59775980
Expression subrng =
5978-
BasicExpression.newFunctionBasicExpression("subrange",
5979-
data, pars);
5981+
BasicExpression.newFunctionBasicExpression(
5982+
"subrange", data, pars);
59805983
BasicExpression chr =
59815984
BasicExpression.newVariableBasicExpression("_chr");
59825985
chr.setType(new Type("int", null));
@@ -5997,13 +6000,55 @@ else if (data.isIntSequence())
59976000
sumexpr);
59986001
return ee;
59996002
}
6003+
else if (data.isLongSequence())
6004+
{ // fle.writeNbytes(data.subrange(1,n)->collect(
6005+
// _z| MathLib.integer2Nbytes(_z,sze)),n*sze)
6006+
6007+
Vector pars0 = new Vector();
6008+
pars0.add(unitExpression);
6009+
pars0.add(n);
6010+
Expression subrng =
6011+
BasicExpression.newFunctionBasicExpression(
6012+
"subrange", data, pars0);
6013+
BasicExpression chr =
6014+
BasicExpression.newVariableBasicExpression("_z");
6015+
chr.setType(new Type("long", null));
6016+
Expression coldom =
6017+
new BinaryExpression(":", chr, subrng);
6018+
Vector pars1 = new Vector();
6019+
pars1.add(chr);
6020+
pars1.add(sze);
6021+
Expression colrng =
6022+
BasicExpression.newStaticCallBasicExpression(
6023+
"integer2bytes", "MathLib", pars1);
6024+
Expression colexpr =
6025+
new BinaryExpression("|C", coldom, colrng);
6026+
Expression prd =
6027+
new BinaryExpression("*", n, sze);
6028+
Vector pars2 = new Vector();
6029+
pars2.add(colexpr);
6030+
pars2.add(prd);
6031+
6032+
BasicExpression res =
6033+
BasicExpression.newCallBasicExpression(
6034+
"writeNbytes", fle, pars2);
6035+
InvocationStatement ee =
6036+
InvocationStatement.newInvocationStatement(res,
6037+
pars2);
6038+
return ee;
6039+
}
60006040
}
60016041
else if (("putc".equals(fname) ||
60026042
"fputc".equals(fname)) && args.size() == 2)
60036043
{ Expression fle = (Expression) args.get(1);
60046044
Expression chr = (Expression) args.get(0);
60056045
Expression par =
60066046
new UnaryExpression("->byte2char", chr);
6047+
6048+
if (chr instanceof UnaryExpression &&
6049+
((UnaryExpression) chr).operator.equals("->char2byte"))
6050+
{ par = ((UnaryExpression) chr).argument; }
6051+
60076052
BasicExpression res =
60086053
BasicExpression.newCallBasicExpression(
60096054
"write", fle, par);
@@ -13914,6 +13959,106 @@ else if ("writeBytes".equals(called) && arg.isFile())
1391413959
return args + ".write(" + callp1 + ")";
1391513960
}
1391613961
}
13962+
else if (("writeChar".equals(called) ||
13963+
"writeShort".equals(called)) && arg.isFile())
13964+
{ if (cargs.size() == 1)
13965+
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
13966+
String callp1 = callarg1.toKM3();
13967+
if (arg.expression != null &&
13968+
callarg1.expression != null)
13969+
{ Vector pars1 = new Vector();
13970+
pars1.add(callarg1.expression);
13971+
pars1.add(new BasicExpression(2));
13972+
Expression int2byts =
13973+
BasicExpression.newStaticCallBasicExpression(
13974+
"integer2bytes", "MathLib", pars1);
13975+
Vector pars2 = new Vector();
13976+
pars2.add(int2byts);
13977+
pars2.add(new BasicExpression(2));
13978+
expression =
13979+
BasicExpression.newCallBasicExpression(
13980+
"writeNbytes", arg.expression, pars2);
13981+
statement =
13982+
InvocationStatement.newInvocationStatement(
13983+
expression, pars2);
13984+
}
13985+
13986+
return args + ".writeNbytes(MathLib.integer2bytes(" + callp1 + ",2),2)";
13987+
}
13988+
}
13989+
else if ("writeInt".equals(called) && arg.isFile())
13990+
{ if (cargs.size() == 1)
13991+
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
13992+
String callp1 = callarg1.toKM3();
13993+
if (arg.expression != null &&
13994+
callarg1.expression != null)
13995+
{ Vector pars1 = new Vector();
13996+
pars1.add(callarg1.expression);
13997+
pars1.add(new BasicExpression(4));
13998+
Expression int2byts =
13999+
BasicExpression.newStaticCallBasicExpression(
14000+
"integer2bytes", "MathLib", pars1);
14001+
Vector pars2 = new Vector();
14002+
pars2.add(int2byts);
14003+
pars2.add(new BasicExpression(4));
14004+
expression =
14005+
BasicExpression.newCallBasicExpression(
14006+
"writeNbytes", arg.expression, pars2);
14007+
statement =
14008+
InvocationStatement.newInvocationStatement(
14009+
expression, pars2);
14010+
}
14011+
14012+
return args + ".writeNbytes(MathLib.integer2bytes(" + callp1 + ",4),4)";
14013+
}
14014+
}
14015+
else if ("writeLong".equals(called) && arg.isFile())
14016+
{ if (cargs.size() == 1)
14017+
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
14018+
String callp1 = callarg1.toKM3();
14019+
if (arg.expression != null &&
14020+
callarg1.expression != null)
14021+
{ Vector pars1 = new Vector();
14022+
pars1.add(callarg1.expression);
14023+
pars1.add(new BasicExpression(8));
14024+
Expression int2byts =
14025+
BasicExpression.newStaticCallBasicExpression(
14026+
"integer2bytes", "MathLib", pars1);
14027+
Vector pars2 = new Vector();
14028+
pars2.add(int2byts);
14029+
pars2.add(new BasicExpression(8));
14030+
expression =
14031+
BasicExpression.newCallBasicExpression(
14032+
"writeNbytes", arg.expression, pars2);
14033+
statement =
14034+
InvocationStatement.newInvocationStatement(
14035+
expression, pars2);
14036+
}
14037+
14038+
return args + ".writeNbytes(MathLib.integer2bytes(" + callp1 + ",8),8)";
14039+
}
14040+
}
14041+
else if ("writeBoolean".equals(called) && arg.isFile())
14042+
{ if (cargs.size() == 1)
14043+
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
14044+
String callp1 = callarg1.toKM3();
14045+
if (arg.expression != null &&
14046+
callarg1.expression != null)
14047+
{ Expression int2byts =
14048+
new ConditionalExpression(callarg1.expression,
14049+
unitExpression,
14050+
zeroExpression);
14051+
expression =
14052+
BasicExpression.newCallBasicExpression(
14053+
"writeByte", arg.expression, int2byts);
14054+
statement =
14055+
InvocationStatement.newInvocationStatement(
14056+
expression, int2byts);
14057+
}
14058+
14059+
return args + ".writeByte(if " + callp1 + " then 1 else 0 endif)";
14060+
}
14061+
}
1391714062
else if ("newLine".equals(called) && arg.isFile())
1391814063
{ if (arg.expression != null)
1391914064
{ Vector pars = new Vector();

0 commit comments

Comments
 (0)