@@ -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)
0 commit comments