11import java.util.Vector;
22import java.io.*;
33
4+ import javax.swing.*;
5+
6+
47/******************************
58* Copyright (c) 2003--2022 Kevin Lano
69* This program and the accompanying materials are made available under the
@@ -40134,7 +40137,43 @@ else if ("*".equals(suf))
4013440137 return alternatives;
4013540138 }
4013640139
40137- public Vector cobolDataDefinitions(java.util.Map context)
40140+ public int cobolDataWidth()
40141+ { if ("dataPictureClause".equals(tag))
40142+ { // (PIC | PICTURE) IS? pictureString
40143+
40144+ int sze = terms.size();
40145+ ASTTerm ptrm = (ASTTerm) terms.get(sze-1);
40146+ return ptrm.cobolDataWidth();
40147+ }
40148+
40149+ if ("pictureString".equals(tag))
40150+ { int res = 0;
40151+ for (int i = 0; i < terms.size(); i++)
40152+ { ASTTerm tt = (ASTTerm) terms.get(i);
40153+ int wdth = tt.cobolDataWidth();
40154+ res = res + wdth;
40155+ }
40156+ return res;
40157+ }
40158+
40159+ if ("pictureCardinality".equals(tag))
40160+ { ASTTerm val = (ASTTerm) terms.get(1);
40161+ String lit = val.literalForm();
40162+ try {
40163+ int crd = Integer.parseInt(lit);
40164+ return crd-1;
40165+ } catch (Exception _ex) { return 0; }
40166+ }
40167+
40168+ if ("pictureChars".equals(tag))
40169+ { ASTTerm val = (ASTTerm) terms.get(0);
40170+ return val.cobolDataWidth();
40171+ }
40172+
40173+ return 0;
40174+ }
40175+
40176+ public Vector cobolDataDefinitions(java.util.Map context, Vector invs)
4013840177 { // Each non-filler item at level > 01 becomes an attribute
4013940178 // of a relevant container. If composite (no picture),
4014040179 // it also becomes a class & container in turn.
@@ -40144,7 +40183,7 @@ public Vector cobolDataDefinitions(java.util.Map context)
4014440183 if ("compilationUnit".equals(tag))
4014540184 { for (int i = 0; i < terms.size(); i++)
4014640185 { ASTTerm tt = (ASTTerm) terms.get(i);
40147- Vector ttres = tt.cobolDataDefinitions(context);
40186+ Vector ttres = tt.cobolDataDefinitions(context, invs );
4014840187 res.addAll(ttres);
4014940188 }
4015040189 return res;
@@ -40153,18 +40192,37 @@ public Vector cobolDataDefinitions(java.util.Map context)
4015340192 if ("programUnit".equals(tag))
4015440193 { for (int i = 0; i < terms.size(); i++)
4015540194 { ASTTerm tt = (ASTTerm) terms.get(i);
40156- Vector ttres = tt.cobolDataDefinitions(context);
40195+ Vector ttres = tt.cobolDataDefinitions(context, invs );
4015740196 res.addAll(ttres);
4015840197 }
4015940198 return res;
4016040199 }
4016140200
40201+ if ("identificationDivision".equals(tag))
40202+ { // (IDENTIFICATION | ID) DIVISION . programIdParagraph identificationDivisionBody*
40203+
40204+ for (int i = 0; i < terms.size(); i++)
40205+ { ASTTerm trm = (ASTTerm) terms.get(i);
40206+ if ("programIdParagraph".equals(trm.getTag()))
40207+ { trm.cobolDataDefinitions(context,invs); }
40208+ }
40209+ return res;
40210+ }
40211+
40212+ if ("programIdParagraph".equals(tag))
40213+ { // PROGRAM-ID . programName _*
40214+ ASTTerm nme = (ASTTerm) terms.get(2);
40215+ String pname = nme.literalForm() + "_Class";
40216+ context.put("programName", pname);
40217+ return res;
40218+ }
40219+
4016240220 if ("dataDivision".equals(tag))
4016340221 { // DATA DIVISION . dataDivisionSection*
4016440222
4016540223 for (int i = 3; i < terms.size(); i++)
4016640224 { ASTTerm tt = (ASTTerm) terms.get(i);
40167- Vector ttres = tt.cobolDataDefinitions(context);
40225+ Vector ttres = tt.cobolDataDefinitions(context, invs );
4016840226 res.addAll(ttres);
4016940227 }
4017040228 return res;
@@ -40175,7 +40233,7 @@ public Vector cobolDataDefinitions(java.util.Map context)
4017540233 // workingStorageSection | linkageSection | ...
4017640234
4017740235 ASTTerm tt = (ASTTerm) terms.get(0);
40178- Vector ttres = tt.cobolDataDefinitions(context);
40236+ Vector ttres = tt.cobolDataDefinitions(context, invs );
4017940237 return ttres;
4018040238 }
4018140239
@@ -40184,7 +40242,7 @@ public Vector cobolDataDefinitions(java.util.Map context)
4018440242
4018540243 for (int i = 3; i < terms.size(); i++)
4018640244 { ASTTerm tt = (ASTTerm) terms.get(i);
40187- Vector ttres = tt.cobolDataDefinitions(context);
40245+ Vector ttres = tt.cobolDataDefinitions(context, invs );
4018840246 res.addAll(ttres);
4018940247 }
4019040248 return res;
@@ -40197,7 +40255,7 @@ public Vector cobolDataDefinitions(java.util.Map context)
4019740255 // dataDescriptionEntryExecSql
4019840256
4019940257 ASTTerm tt = (ASTTerm) terms.get(0);
40200- Vector ttres = tt.cobolDataDefinitions(context);
40258+ Vector ttres = tt.cobolDataDefinitions(context, invs );
4020140259 return ttres;
4020240260 }
4020340261
@@ -40238,7 +40296,18 @@ public Vector cobolDataDefinitions(java.util.Map context)
4023840296 Entity container = (Entity) context.get("container");
4023940297
4024040298 if (ASTTerm.hasTag(terms,"dataPictureClause"))
40241- { // It is a basic item, not an entity
40299+ { // It is a basic data item, not an entity
40300+
40301+ ASTTerm pictureClause =
40302+ 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);
40309+
40310+
4024240311 if (container == null) // no container, so top-level attribute
4024340312 { if ("FILLER".equals(fieldName)) { }
4024440313 else
@@ -40253,8 +40322,47 @@ public Vector cobolDataDefinitions(java.util.Map context)
4025340322 else // basic attribute of some container
4025440323 { int contLevel = container.levelNumber;
4025540324
40256- Integer previousLevel = (Integer) context.get("previousLevel");
40325+ Integer startPosition = (Integer) context.get("startPosition");
40326+ if (startPosition != null)
40327+ { int startPos = startPosition.intValue();
40328+ int endPos = startPos + wdth - 1;
40329+ context.put("startPosition", endPos + 1);
40330+
40331+ String cname = container.getName();
40332+ String ownername =
40333+ cname.substring(0,cname.length()-6);
40334+ String progname =
40335+ (String) context.get("programName");
40336+ JOptionPane.showMessageDialog(null, progname + ":: " + fieldName +
40337+ " = " + ownername +
40338+ ".subrange(" + startPos + "," + endPos + ")",
40339+ "",
40340+ JOptionPane.INFORMATION_MESSAGE);
40341+ BasicExpression owner =
40342+ BasicExpression.newAttributeBasicExpression(
40343+ ownername,
40344+ new Type("String", null));
40345+ BasicExpression attr =
40346+ BasicExpression.newAttributeBasicExpression(
40347+ 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);
40361+ }
40362+ else
40363+ { context.put("startPosition", 1 + wdth); }
4025740364
40365+ Integer previousLevel = (Integer) context.get("previousLevel");
4025840366 int prevLevel = previousLevel.intValue();
4025940367
4026040368 if (levelNumber >= prevLevel)
@@ -40300,12 +40408,20 @@ else if (levelNumber < prevLevel)
4030040408 Integer previousLevel = (Integer) context.get("previousLevel");
4030140409
4030240410 int prevLevel = -1;
40303- if (previousLevel != null)
40304- { prevLevel = previousLevel.intValue(); }
40411+ if (previousLevel != null)
40412+ { prevLevel = previousLevel.intValue(); }
4030540413
4030640414 res.add(newent);
4030740415 if (container == null) // top-level
40308- { res.add(att); }
40416+ { String pname =
40417+ (String) context.get("programName");
40418+ if (pname != null)
40419+ { Entity prog = new Entity(pname);
40420+ prog.levelNumber = -1;
40421+ newent.container = prog;
40422+ }
40423+ res.add(att);
40424+ }
4030940425 else if (levelNumber >= prevLevel)
4031040426 { newent.container = container;
4031140427 container.addAttribute(att);
@@ -40320,7 +40436,8 @@ else if (levelNumber >= prevLevel)
4032040436 }
4032140437
4032240438 context.put("container", newent);
40323- context.put("previousLevel", new Integer(levelNumber));
40439+ context.put("previousLevel", new Integer(levelNumber));
40440+ context.put("startPosition", new Integer(1));
4032440441 }
4032540442 }
4032640443 }
0 commit comments