Skip to content

Commit ac588d0

Browse files
authored
Cobol85 record processing
1 parent e8ec350 commit ac588d0

File tree

8 files changed

+323
-72
lines changed

8 files changed

+323
-72
lines changed

ASTBasicTerm.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,6 +2687,26 @@ public int cobolDataWidth()
26872687
return 0;
26882688
}
26892689

2690+
public Type cobolDataType()
2691+
{ if ("integerLiteral".equals(tag) || "9".equals(value) ||
2692+
"S".equals(value))
2693+
{ return ASTCompositeTerm.intType; }
2694+
2695+
if ("X".equals(value) ||
2696+
",".equals(value) || "A".equals(value) ||
2697+
"B".equals(value) || "0".equals(value) ||
2698+
"/".equals(value) || "+".equals(value) ||
2699+
"-".equals(value) || "$".equals(value) ||
2700+
"£".equals(value) || ".".equals(value) ||
2701+
"Z".equals(value) || "*".equals(value))
2702+
{ return ASTCompositeTerm.stringType; }
2703+
2704+
if ("P".equals(value) || "V".equals(value))
2705+
{ return ASTCompositeTerm.doubleType; }
2706+
2707+
return null;
2708+
}
2709+
26902710
public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
26912711
{ // Each immediately higher level item becomes an attribute
26922712
// of container. If composite, it also becomes a class

ASTCompositeTerm.java

Lines changed: 161 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40172,7 +40172,61 @@ public int cobolDataWidth()
4017240172

4017340173
return 0;
4017440174
}
40175-
40175+
40176+
public Type cobolDataType()
40177+
{ if ("dataPictureClause".equals(tag))
40178+
{ // (PIC | PICTURE) IS? pictureString
40179+
40180+
int sze = terms.size();
40181+
ASTTerm ptrm = (ASTTerm) terms.get(sze-1);
40182+
return ptrm.cobolDataType();
40183+
}
40184+
40185+
if ("pictureString".equals(tag))
40186+
{ Type res = null;
40187+
for (int i = 0; i < terms.size(); i++)
40188+
{ ASTTerm tt = (ASTTerm) terms.get(i);
40189+
Type typ = tt.cobolDataType();
40190+
if (res == null)
40191+
{ res = typ; }
40192+
else if (typ == null) { } // no information
40193+
else if (typ == doubleType)
40194+
{ return typ; }
40195+
else if (res == intType && typ == intType)
40196+
{ res = intType; }
40197+
else // typ or res are String
40198+
{ res = stringType; }
40199+
}
40200+
return res;
40201+
}
40202+
40203+
if ("pictureCardinality".equals(tag))
40204+
{ return null; }
40205+
40206+
if ("pictureChars".equals(tag))
40207+
{ ASTTerm val = (ASTTerm) terms.get(0);
40208+
return val.cobolDataType();
40209+
}
40210+
40211+
return stringType;
40212+
}
40213+
40214+
public int cobolOccursTimes()
40215+
{ if ("dataOccursClause".equals(tag))
40216+
{ // OCCURS integerLiteral dataOccursTo? TIMES?
40217+
// (DEPENDING ON? qualifiedDataName)?
40218+
// dataOccursSort* (INDEXED BY? LOCAL? indexName+)?
40219+
ASTTerm times = (ASTTerm) terms.get(1);
40220+
String lit = times.literalForm();
40221+
try
40222+
{ int x = Integer.parseInt(lit);
40223+
return x;
40224+
} catch (Exception _ex) { }
40225+
}
40226+
return 1;
40227+
}
40228+
40229+
4017640230
public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4017740231
{ // Each non-filler item at level > 01 becomes an attribute
4017840232
// of a relevant container. If composite (no picture),
@@ -40294,25 +40348,43 @@ public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4029440348
{ fieldName = "FILLER"; }
4029540349

4029640350
Entity container = (Entity) context.get("container");
40351+
40352+
int multiplicity = 1;
40353+
if (ASTTerm.hasTag(terms,"dataOccursClause"))
40354+
{ ASTTerm occursClause =
40355+
ASTTerm.getTermByTag(terms,"dataOccursClause");
40356+
if (occursClause != null)
40357+
{ multiplicity =
40358+
((ASTCompositeTerm) occursClause).cobolOccursTimes();
40359+
}
40360+
}
4029740361

4029840362
if (ASTTerm.hasTag(terms,"dataPictureClause"))
4029940363
{ // It is a basic data item, not an entity
4030040364

4030140365
ASTTerm pictureClause =
4030240366
ASTTerm.getTermByTag(terms,"dataPictureClause");
40303-
int wdth = 0;
40304-
if (pictureClause != null)
40305-
{ wdth = pictureClause.cobolDataWidth(); }
40306-
// JOptionPane.showMessageDialog(null, "Width of " + fieldName + " is " + wdth,
40307-
// "",
40308-
// JOptionPane.INFORMATION_MESSAGE);
40367+
int wdth = 0;
40368+
Type typ = stringType;
4030940369

40370+
if (pictureClause != null)
40371+
{ wdth = pictureClause.cobolDataWidth() * multiplicity;
40372+
typ = pictureClause.cobolDataType();
40373+
if (multiplicity > 1)
40374+
{ Type elemT = typ;
40375+
typ = new Type("Sequence", null);
40376+
typ.setElementType(elemT);
40377+
}
40378+
JOptionPane.showMessageDialog(null, "Type of " + fieldName + " is " + typ,
40379+
"",
40380+
JOptionPane.INFORMATION_MESSAGE);
40381+
}
4031040382

4031140383
if (container == null) // no container, so top-level attribute
4031240384
{ if ("FILLER".equals(fieldName)) { }
4031340385
else
4031440386
{ Attribute att =
40315-
new Attribute(fieldName, new Type("String", null),
40387+
new Attribute(fieldName, typ,
4031640388
ModelElement.INTERNAL);
4031740389
res.add(att);
4031840390

@@ -40321,6 +40393,7 @@ public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4032140393
}
4032240394
else // basic attribute of some container
4032340395
{ int contLevel = container.levelNumber;
40396+
int contMult = container.cardinalityValue;
4032440397

4032540398
Integer startPosition = (Integer) context.get("startPosition");
4032640399
if (startPosition != null)
@@ -40333,31 +40406,76 @@ public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4033340406
cname.substring(0,cname.length()-6);
4033440407
String progname =
4033540408
(String) context.get("programName");
40336-
JOptionPane.showMessageDialog(null, progname + ":: " + fieldName +
40337-
" = " + ownername +
40338-
".subrange(" + startPos + "," + endPos + ")",
40409+
40410+
if (multiplicity >= 1 && contMult == 1)
40411+
{ // fieldName = owner.subrange(startPos,endPos)
40412+
40413+
JOptionPane.showMessageDialog(null, progname + ":: " + fieldName +
40414+
" = " + ownername +
40415+
".subrange(" + startPos + "," + endPos + ")",
40416+
"",
40417+
JOptionPane.INFORMATION_MESSAGE);
40418+
BasicExpression owner =
40419+
BasicExpression.newAttributeBasicExpression(
40420+
ownername, stringType);
40421+
BasicExpression attr =
40422+
BasicExpression.newAttributeBasicExpression(
40423+
fieldName,
40424+
typ);
40425+
Vector spars = new Vector();
40426+
spars.add(new BasicExpression(startPos));
40427+
spars.add(new BasicExpression(endPos));
40428+
BasicExpression substr =
40429+
BasicExpression.newFunctionBasicExpression(
40430+
"subrange", owner, spars);
40431+
BinaryExpression inv =
40432+
new BinaryExpression("=", attr, substr);
40433+
Constraint cons =
40434+
Constraint.getConstraint(inv);
40435+
cons.ownerName = progname;
40436+
invs.add(cons);
40437+
}
40438+
else if (multiplicity == 1 & contMult > 1)
40439+
{ // fieldName[i] = owner[i].subrange(...)
40440+
40441+
JOptionPane.showMessageDialog(null, progname + ":: " + fieldName +
40442+
"[i] = " + ownername +
40443+
"[i].subrange(" + startPos + "," + endPos + ")",
4033940444
"",
4034040445
JOptionPane.INFORMATION_MESSAGE);
40341-
BasicExpression owner =
40342-
BasicExpression.newAttributeBasicExpression(
40446+
40447+
BasicExpression indx =
40448+
BasicExpression.newVariableBasicExpression(
40449+
"indx",
40450+
intType);
40451+
40452+
Type seqType = new Type("Sequence", null);
40453+
seqType.setElementType(stringType);
40454+
Type typSeq = new Type("Sequence", null);
40455+
typSeq.setElementType(typ);
40456+
BasicExpression owner =
40457+
BasicExpression.newAttributeBasicExpression(
4034340458
ownername,
40344-
new Type("String", null));
40345-
BasicExpression attr =
40346-
BasicExpression.newAttributeBasicExpression(
40459+
seqType);
40460+
owner.setArrayIndex(indx);
40461+
BasicExpression attr =
40462+
BasicExpression.newAttributeBasicExpression(
4034740463
fieldName,
40348-
new Type("String", null));
40349-
Vector spars = new Vector();
40350-
spars.add(new BasicExpression(startPos));
40351-
spars.add(new BasicExpression(endPos));
40352-
BasicExpression substr =
40353-
BasicExpression.newFunctionBasicExpression(
40354-
"subrange", owner, spars);
40355-
BinaryExpression inv =
40356-
new BinaryExpression("=", attr, substr);
40357-
Constraint cons =
40358-
Constraint.getConstraint(inv);
40359-
cons.ownerName = progname;
40360-
invs.add(cons);
40464+
typSeq);
40465+
Vector spars = new Vector();
40466+
attr.setArrayIndex(indx);
40467+
spars.add(new BasicExpression(startPos));
40468+
spars.add(new BasicExpression(endPos));
40469+
BasicExpression substr =
40470+
BasicExpression.newFunctionBasicExpression(
40471+
"subrange", owner, spars);
40472+
BinaryExpression inv =
40473+
new BinaryExpression("=", attr, substr);
40474+
Constraint cons =
40475+
Constraint.getConstraint(inv);
40476+
cons.ownerName = progname;
40477+
invs.add(cons);
40478+
}
4036140479
}
4036240480
else
4036340481
{ context.put("startPosition", 1 + wdth); }
@@ -40370,7 +40488,7 @@ public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4037040488
if ("FILLER".equals(fieldName)) {}
4037140489
else
4037240490
{ Attribute att =
40373-
new Attribute(fieldName, new Type("String", null),
40491+
new Attribute(fieldName, typ,
4037440492
ModelElement.INTERNAL);
4037540493
container.addAttribute(att);
4037640494
} // could itself be composite
@@ -40382,7 +40500,7 @@ else if (levelNumber < prevLevel)
4038240500
if ("FILLER".equals(fieldName)) {}
4038340501
else
4038440502
{ Attribute att =
40385-
new Attribute(fieldName, new Type("String", null),
40503+
new Attribute(fieldName, typ,
4038640504
ModelElement.INTERNAL);
4038740505
Entity actualContainer =
4038840506
container.findContainer(levelNumber);
@@ -40401,11 +40519,21 @@ else if (levelNumber < prevLevel)
4040140519
else
4040240520
{ Entity newent = new Entity(fieldName + "_Class");
4040340521
newent.levelNumber = levelNumber;
40522+
newent.cardinalityValue = multiplicity;
40523+
40524+
Type typ = new Type(newent);
40525+
if (multiplicity > 1)
40526+
{ Type elemT = typ;
40527+
typ = new Type("Sequence", null);
40528+
typ.setElementType(elemT);
40529+
}
40530+
4040440531
Attribute att =
40405-
new Attribute(fieldName, new Type(newent),
40532+
new Attribute(fieldName, typ,
4040640533
ModelElement.INTERNAL);
4040740534

40408-
Integer previousLevel = (Integer) context.get("previousLevel");
40535+
Integer previousLevel =
40536+
(Integer) context.get("previousLevel");
4040940537

4041040538
int prevLevel = -1;
4041140539
if (previousLevel != null)

ASTSymbolTerm.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,26 @@ public int cobolDataWidth()
858858
return 0;
859859
}
860860

861+
public Type cobolDataType()
862+
{ if ("9".equals(symbol) ||
863+
"S".equals(symbol))
864+
{ return ASTCompositeTerm.intType; }
865+
866+
if ("X".equals(symbol) ||
867+
",".equals(symbol) || "A".equals(symbol) ||
868+
"B".equals(symbol) || "0".equals(symbol) ||
869+
"/".equals(symbol) || "+".equals(symbol) ||
870+
"-".equals(symbol) || "$".equals(symbol) ||
871+
"£".equals(symbol) || ".".equals(symbol) ||
872+
"Z".equals(symbol) || "*".equals(symbol))
873+
{ return ASTCompositeTerm.stringType; }
874+
875+
if ("P".equals(symbol) || "V".equals(symbol))
876+
{ return ASTCompositeTerm.doubleType; }
877+
878+
return null;
879+
}
880+
861881
public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
862882
{ Vector res = new Vector();
863883
return res;

ASTTerm.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,8 @@ public static Vector randomCompositeASTTermsForTag(
36673667

36683668
public abstract int cobolDataWidth();
36693669

3670+
public abstract Type cobolDataType();
3671+
36703672
public static void main(String[] args)
36713673
{ // ASTBasicTerm t = new ASTBasicTerm("OclBasicExpression", "true");
36723674
// System.out.println(t.isInteger());

BasicExpression.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ public static BasicExpression newAttributeBasicExpression(String value, Expressi
422422
return res;
423423
}
424424

425+
public static BasicExpression newAttributeBasicExpression(String value, Type typ)
426+
{ BasicExpression res = new BasicExpression(value);
427+
res.umlkind = ATTRIBUTE;
428+
res.type = typ;
429+
return res;
430+
}
431+
425432
public static BasicExpression newStaticAttributeBasicExpression(Attribute att)
426433
{ BasicExpression res = new BasicExpression(att.getName());
427434
res.umlkind = ATTRIBUTE;
@@ -4758,8 +4765,8 @@ else if (resType == null || resType.typeMultiplicity() == ModelElement.ONE)
47584765
private void adjustTypeForArrayIndex()
47594766
{ // if there is an arrayIndex, make type = elementType, etc
47604767

4761-
System.out.println("+++ Adjusting type " + type + " " +
4762-
elementType + " " + arrayIndex);
4768+
// System.out.println("+++ Adjusting type " + type + " " +
4769+
// elementType + " " + arrayIndex);
47634770

47644771
if (arrayIndex != null && type != null &&
47654772
"String".equals(type.getName()))
@@ -4812,8 +4819,8 @@ else if (arrayIndex != null)
48124819
private void adjustTypeForArrayIndex(Attribute var)
48134820
{ // if there is an arrayIndex, make type = elementType, etc
48144821

4815-
System.out.println("+++ Adjusting type " + type + " " +
4816-
elementType + " " + arrayIndex + " " + var);
4822+
// System.out.println("+++ Adjusting type " + type + " " +
4823+
// elementType + " " + arrayIndex + " " + var);
48174824

48184825
if (arrayIndex != null && "String".equals(type + ""))
48194826
{ elementType = new Type("String", null);
@@ -4840,8 +4847,8 @@ else if (arrayIndex != null)
48404847
} // Sequence access, defined type
48414848
}
48424849

4843-
System.out.println("+++ Adjusted type " + type + " " +
4844-
elementType);
4850+
// System.out.println("+++ Adjusted type " + type + " " +
4851+
// elementType);
48454852
}
48464853

48474854
private boolean eventTypeCheck(Vector types, Vector entities, Vector env)

0 commit comments

Comments
 (0)