Skip to content

Commit e95e599

Browse files
authored
MBT for COBOL
1 parent e9a6fc0 commit e95e599

File tree

6 files changed

+210
-39
lines changed

6 files changed

+210
-39
lines changed

ASTCompositeTerm.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41714,7 +41714,11 @@ public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4171441714
ASTTerm.setTaggedValue(fieldName, "width",
4171541715
"" + wdth);
4171641716
if (typ != null)
41717-
{ String dval = typ.defaultValue();
41717+
{ if ("String".equals(typ.getName()))
41718+
{ typ.setFixedSize(true,
41719+
new BasicExpression(wdth));
41720+
}
41721+
String dval = typ.defaultValue();
4171841722
ASTTerm.setTaggedValue(fieldName, "defaultValue",
4171941723
dval);
4172041724
}
@@ -41908,6 +41912,10 @@ else if (multiplicity == 1 & contMult > 1)
4190841912
Attribute att =
4190941913
new Attribute(fieldName, typ,
4191041914
ModelElement.INTERNAL);
41915+
if (typ != null && "String".equals(typ.getName()))
41916+
{ typ.setFixedSize(true,
41917+
new BasicExpression(wdth));
41918+
}
4191141919
att.setWidth(wdth);
4191241920
att.setMultiplicity(multiplicity);
4191341921

@@ -42235,17 +42243,22 @@ public static boolean is88Entry(ASTTerm trm)
4223542243
ASTTerm.setTaggedValue(fname, "width",
4223642244
"" + wdth);
4223742245

42238-
JOptionPane.showMessageDialog(null,
42246+
/* JOptionPane.showMessageDialog(null,
4223942247
"Type of " + fname + " is " + typ +
4224042248
" Signed: " + isSigned +
4224142249
" Width: " + wdth +
4224242250
" Integer width: " + intwidth +
4224342251
" Fract width: " + fractwidth,
4224442252
"",
42245-
JOptionPane.INFORMATION_MESSAGE);
42253+
JOptionPane.INFORMATION_MESSAGE); */
4224642254

4224742255
if (typ != null)
42248-
{ String dval = typ.defaultValue();
42256+
{ if ("String".equals(typ.getName()))
42257+
{ typ.setFixedSize(true,
42258+
new BasicExpression(wdth));
42259+
}
42260+
42261+
String dval = typ.defaultValue();
4224942262
ASTTerm.setTaggedValue(fname, "defaultValue",
4225042263
dval);
4225142264
Constraint consV =
@@ -42376,7 +42389,12 @@ public static boolean is88Entry(ASTTerm trm)
4237642389
ASTTerm.setTaggedValue(fieldName, "width",
4237742390
"" + wdth);
4237842391
if (typ != null)
42379-
{ String dval = typ.defaultValue();
42392+
{ if ("String".equals(typ.getName()))
42393+
{ typ.setFixedSize(true,
42394+
new BasicExpression(wdth));
42395+
}
42396+
42397+
String dval = typ.defaultValue();
4238042398
ASTTerm.setTaggedValue(
4238142399
fieldName, "defaultValue",
4238242400
dval);
@@ -42467,12 +42485,12 @@ public static boolean is88Entry(ASTTerm trm)
4246742485
Expression simpsubstr =
4246842486
substr.simplify();
4246942487

42470-
JOptionPane.showMessageDialog(null,
42488+
/* JOptionPane.showMessageDialog(null,
4247142489
progname + ":: " + fieldName +
4247242490
" = " + simpsubstr + "\n" +
4247342491
"Field width = " + fwdth,
4247442492
"",
42475-
JOptionPane.INFORMATION_MESSAGE);
42493+
JOptionPane.INFORMATION_MESSAGE); */
4247642494

4247742495
ASTTerm.setTaggedValue("" + simpsubstr,
4247842496
"width",

Attribute.java

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6364,7 +6364,9 @@ public double attributeSimilarity(Attribute other)
63646364
return sim;
63656365
}
63666366

6367-
public Vector testCases(String x, java.util.Map lowerBnds, java.util.Map upperBnds, Vector opTests)
6367+
public Vector testCases(String x,
6368+
java.util.Map lowerBnds,
6369+
java.util.Map upperBnds, Vector opTests)
63686370
{ Vector res = new Vector();
63696371
if (type == null)
63706372
{ return res; }
@@ -6580,12 +6582,34 @@ else if ("boolean".equals(t))
65806582
opTests.add(attname + " = false;");
65816583
}
65826584
else if ("String".equals(t))
6583-
{ res.add(nme + " = \"\"");
6584-
res.add(nme + " = \" abc_XZ \"");
6585-
res.add(nme + " = \"#�$* &~@':\"");
6586-
opTests.add(attname + " = \"\";");
6587-
opTests.add(attname + " = \" abc_XZ \";");
6588-
opTests.add(attname + " = \"#�$* &~@':\";");
6585+
{ JOptionPane.showMessageDialog(null,
6586+
">> Attribute " + this + " has fixed size: " +
6587+
type.getFixedSize() +
6588+
" Tests: " + res,
6589+
"",
6590+
JOptionPane.INFORMATION_MESSAGE);
6591+
if (type.hasFixedSize())
6592+
{ Expression fs = type.getFixedSize();
6593+
int fsize = Expression.convertInteger(fs + "");
6594+
// an fsize blank plus 2 random strings of the size
6595+
String allSpaces = AuxMath.nCopiesOfString(" ", fsize);
6596+
String random1 = ModelElement.randomString(fsize);
6597+
String random2 = ModelElement.randomString(fsize);
6598+
res.add(nme + " = \"" + allSpaces + "\"");
6599+
res.add(nme + " = \"" + random1 + "\"");
6600+
res.add(nme + " = \"" + random2 + "\"");
6601+
opTests.add(attname + " = \"" + allSpaces + "\";");
6602+
opTests.add(attname + " = \"" + random1 + "\";");
6603+
opTests.add(attname + " = \"" + random2 + "\";");
6604+
}
6605+
else
6606+
{ res.add(nme + " = \"\"");
6607+
res.add(nme + " = \" abc_XZ \"");
6608+
res.add(nme + " = \"#�$* &~@':\"");
6609+
opTests.add(attname + " = \"\";");
6610+
opTests.add(attname + " = \" abc_XZ \";");
6611+
opTests.add(attname + " = \"#�$* &~@':\";");
6612+
}
65896613
}
65906614
else if (vs != null && vs.size() > 0)
65916615
{ for (int j = 0; j < vs.size(); j++)
@@ -7443,12 +7467,28 @@ else if ("boolean".equals(t))
74437467
opTests.add(attname + " = false;");
74447468
}
74457469
else if ("String".equals(t))
7446-
{ res.add(nme + " = \"\"");
7447-
res.add(nme + " = \" abc_XZ \"");
7448-
res.add(nme + " = \"#�$* &~@':\"");
7449-
opTests.add(attname + " = \"\";");
7450-
opTests.add(attname + " = \" abc_XZ \";");
7451-
opTests.add(attname + " = \"#�$* &~@':\";");
7470+
{ if (type.hasFixedSize())
7471+
{ Expression fs = type.getFixedSize();
7472+
int fsize = Expression.convertInteger(fs + "");
7473+
// an fsize blank plus 2 random strings of the size
7474+
String allSpaces = AuxMath.nCopiesOfString(" ", fsize);
7475+
String random1 = ModelElement.randomString(fsize);
7476+
String random2 = ModelElement.randomString(fsize);
7477+
res.add(nme + " = \"" + allSpaces + "\"");
7478+
res.add(nme + " = \"" + random1 + "\"");
7479+
res.add(nme + " = \"" + random2 + "\"");
7480+
opTests.add(attname + " = \"" + allSpaces + "\";");
7481+
opTests.add(attname + " = \"" + random1 + "\";");
7482+
opTests.add(attname + " = \"" + random2 + "\";");
7483+
}
7484+
else
7485+
{ res.add(nme + " = \"\"");
7486+
res.add(nme + " = \" abc_XZ \"");
7487+
res.add(nme + " = \"#�$* &~@':\"");
7488+
opTests.add(attname + " = \"\";");
7489+
opTests.add(attname + " = \" abc_XZ \";");
7490+
opTests.add(attname + " = \"#�$* &~@':\";");
7491+
}
74527492
}
74537493
else if (vs != null && vs.size() > 0)
74547494
{ for (int j = 0; j < vs.size(); j++)
@@ -7706,12 +7746,28 @@ else if ("boolean".equals(t))
77067746
opTests.add(attname + " = false;");
77077747
}
77087748
else if ("String".equals(t))
7709-
{ res.add(nme + " = \"\"");
7710-
res.add(nme + " = \" abc_XZ \"");
7711-
res.add(nme + " = \"#�$* &~@':\"");
7712-
opTests.add(attname + " = \"\";");
7713-
opTests.add(attname + " = \" abc_XZ \";");
7714-
opTests.add(attname + " = \"#�$* &~@':\";");
7749+
{ if (type.hasFixedSize())
7750+
{ Expression fs = type.getFixedSize();
7751+
int fsize = Expression.convertInteger(fs + "");
7752+
// an fsize blank plus 2 random strings of the size
7753+
String allSpaces = AuxMath.nCopiesOfString(" ", fsize);
7754+
String random1 = ModelElement.randomString(fsize);
7755+
String random2 = ModelElement.randomString(fsize);
7756+
res.add(nme + " = \"" + allSpaces + "\"");
7757+
res.add(nme + " = \"" + random1 + "\"");
7758+
res.add(nme + " = \"" + random2 + "\"");
7759+
opTests.add(attname + " = \"" + allSpaces + "\";");
7760+
opTests.add(attname + " = \"" + random1 + "\";");
7761+
opTests.add(attname + " = \"" + random2 + "\";");
7762+
}
7763+
else
7764+
{ res.add(nme + " = \"\"");
7765+
res.add(nme + " = \" abc_XZ \"");
7766+
res.add(nme + " = \"#�$* &~@':\"");
7767+
opTests.add(attname + " = \"\";");
7768+
opTests.add(attname + " = \" abc_XZ \";");
7769+
opTests.add(attname + " = \"#�$* &~@':\";");
7770+
}
77157771
}
77167772
else if (vs != null && vs.size() > 0)
77177773
{ for (int j = 0; j < vs.size(); j++)

AuxMath.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,14 @@ else if (AuxMath.isNumeric(b) && AuxMath.isNumeric(c))
31853185
"(-" + b + " - †(" + b + "*" + b + " - 4*" + a + "*" + c + "))/(2*" + a + ")";
31863186
}
31873187

3188+
public static String nCopiesOfString(String x, int n)
3189+
{ String res = "";
3190+
for (int i = 1; i <= n; i++)
3191+
{ res = res + x; }
3192+
return res;
3193+
}
3194+
3195+
31883196
public static void main(String[] args)
31893197
{ /* Vector mm1 = new Vector();
31903198
mm1.add("3"); mm1.add("5");

Entity.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,28 @@ public void addAttribute(String nme, Type t)
11821182
{ Attribute att = new Attribute(nme, t, ModelElement.INTERNAL);
11831183
addAttribute(att);
11841184
}
1185+
1186+
// For COBOL:
1187+
public void setAttributeType(Attribute att, Type t)
1188+
{ String nme = att.getName();
1189+
Attribute attx =
1190+
(Attribute) ModelElement.lookupByName(nme,
1191+
attributes);
1192+
if (attx == null)
1193+
{ attx = new Attribute(nme, t, ModelElement.INTERNAL);
1194+
addAttribute(attx);
1195+
}
1196+
else
1197+
{ attx.setType(t); }
1198+
1199+
Expression expr = attx.getInitialExpression();
1200+
if (expr == null || ("" + expr).equals("\"\""))
1201+
{ String defValue = t.defaultValue();
1202+
Expression defExpr = new BasicExpression(defValue);
1203+
defExpr.setType(t);
1204+
attx.setInitialExpression(defExpr);
1205+
}
1206+
}
11851207

11861208
public void addAttribute(Attribute att)
11871209
{ if (att == null || attributes.contains(att))
@@ -6106,6 +6128,7 @@ public Vector attributeSumInvariants()
61066128
for (int i = 0; i < attributes.size(); i++)
61076129
{ Attribute att = (Attribute) attributes.get(i);
61086130
int awidth = att.getWidth();
6131+
Type atype = att.getType();
61096132
int amult = att.getMultiplicity();
61106133
String aname = att.getName();
61116134

@@ -6156,12 +6179,20 @@ public Vector attributeSumInvariants()
61566179
else
61576180
{ Vector exprs0 = new Vector();
61586181
exprs0.add(avalue);
6159-
exprs0.add(new BasicExpression(awidth));
6182+
Expression widthExpr = new BasicExpression(awidth);
6183+
exprs0.add(widthExpr);
61606184

61616185
expr =
61626186
BasicExpression.newStaticCallBasicExpression(
6163-
"leftAlignInto", "StringLib", exprs0);
6187+
"leftAlignInto", "StringLib", exprs0);
6188+
atype.setFixedSize(true, widthExpr);
61646189
}
6190+
6191+
JOptionPane.showMessageDialog(null,
6192+
">> Attribute " + att + " Type: " + atype +
6193+
" Type is fixed size: " + atype.hasFixedSize(),
6194+
"",
6195+
JOptionPane.INFORMATION_MESSAGE);
61656196
}
61666197

61676198
sumExpr =
@@ -6440,20 +6471,20 @@ else if (ent.cardinalityValue > 1 && att.isSequence())
64406471
}
64416472
}
64426473
}
6443-
}
6474+
} // These are fixed-size sequences.
64446475

64456476
public void addFillerAttributes(Entity root)
64466477
{ // For each FILLER, add to the CSTL-generated main class
6478+
// For each other String attribute, make its type fixed size
64476479

64486480
for (int i = 0; i < attributes.size(); i++)
64496481
{ Attribute att = (Attribute) attributes.get(i);
64506482
String aname = att.getName();
6451-
6483+
int wdth = att.getWidth();
6484+
64526485
if (aname.startsWith("FILLER_"))
6453-
{ int wdth = att.getWidth();
6454-
String spacesString = "";
6455-
for (int j = 0; j < wdth; j++)
6456-
{ spacesString = spacesString + " "; }
6486+
{ String spacesString =
6487+
AuxMath.nCopiesOfString(" ", wdth);
64576488
Expression fillerInit =
64586489
BasicExpression.newValueBasicExpression(
64596490
"\"" + spacesString + "\"");
@@ -6463,6 +6494,11 @@ public void addFillerAttributes(Entity root)
64636494
att.setInitialExpression(fillerInit);
64646495
root.addAttribute(att);
64656496
}
6497+
else if (att.isString())
6498+
{ Type typ = att.getType();
6499+
typ.setFixedSize(true, new BasicExpression(wdth));
6500+
root.setAttributeType(att,typ);
6501+
}
64666502
}
64676503
}
64686504

0 commit comments

Comments
 (0)