Skip to content

Commit ccb0779

Browse files
authored
Updated COBOL85 reverse-engineering
1 parent 179de64 commit ccb0779

File tree

9 files changed

+402
-28
lines changed

9 files changed

+402
-28
lines changed

ASTBasicTerm.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ public ASTTerm replaceCobolIdentifiers()
4949
String vsub = vtrim.replace("-", "_");
5050
return new ASTBasicTerm(tag,vsub);
5151
}
52+
5253
if (tag.equals("numericLiteral"))
5354
{ String vtrim = value.trim();
54-
String vsub = vtrim.replace(",", ".");
55+
String vsub = vtrim.replace(",", ".");
56+
if (vsub.startsWith("."))
57+
{ vsub = "0" + vsub; }
5558
return new ASTBasicTerm(tag,vsub);
5659
}
60+
5761
return this;
5862
}
5963

@@ -2664,6 +2668,13 @@ public Vector normaliseAntlr()
26642668
alts.add(thisalt);
26652669
return alts;
26662670
}
2671+
2672+
public Vector cobolDataDefinitions(java.util.Map context)
2673+
{ // Each immediately higher level item becomes an attribute
2674+
// of container. If composite, it also becomes a class
2675+
Vector res = new Vector();
2676+
return res;
2677+
}
26672678

26682679
public static void main(String[] args)
26692680
{ ASTBasicTerm tt = new ASTBasicTerm("primaryExpression", "'a'");

ASTCompositeTerm.java

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40134,6 +40134,199 @@ else if ("*".equals(suf))
4013440134
return alternatives;
4013540135
}
4013640136

40137+
public Vector cobolDataDefinitions(java.util.Map context)
40138+
{ // Each non-filler item at level > 01 becomes an attribute
40139+
// of a relevant container. If composite (no picture),
40140+
// it also becomes a class & container in turn.
40141+
40142+
Vector res = new Vector();
40143+
40144+
if ("compilationUnit".equals(tag))
40145+
{ for (int i = 0; i < terms.size(); i++)
40146+
{ ASTTerm tt = (ASTTerm) terms.get(i);
40147+
Vector ttres = tt.cobolDataDefinitions(context);
40148+
res.addAll(ttres);
40149+
}
40150+
return res;
40151+
}
40152+
40153+
if ("programUnit".equals(tag))
40154+
{ for (int i = 0; i < terms.size(); i++)
40155+
{ ASTTerm tt = (ASTTerm) terms.get(i);
40156+
Vector ttres = tt.cobolDataDefinitions(context);
40157+
res.addAll(ttres);
40158+
}
40159+
return res;
40160+
}
40161+
40162+
if ("dataDivision".equals(tag))
40163+
{ // DATA DIVISION . dataDivisionSection*
40164+
40165+
for (int i = 3; i < terms.size(); i++)
40166+
{ ASTTerm tt = (ASTTerm) terms.get(i);
40167+
Vector ttres = tt.cobolDataDefinitions(context);
40168+
res.addAll(ttres);
40169+
}
40170+
return res;
40171+
}
40172+
40173+
if ("dataDivisionSection".equals(tag))
40174+
{ // fileSection | dataBaseSection |
40175+
// workingStorageSection | linkageSection | ...
40176+
40177+
ASTTerm tt = (ASTTerm) terms.get(0);
40178+
Vector ttres = tt.cobolDataDefinitions(context);
40179+
return ttres;
40180+
}
40181+
40182+
if ("workingStorageSection".equals(tag))
40183+
{ // WORKING-STORAGE SECTION . dataDescriptionEntry*
40184+
40185+
for (int i = 3; i < terms.size(); i++)
40186+
{ ASTTerm tt = (ASTTerm) terms.get(i);
40187+
Vector ttres = tt.cobolDataDefinitions(context);
40188+
res.addAll(ttres);
40189+
}
40190+
return res;
40191+
}
40192+
40193+
if ("dataDescriptionEntry".equals(tag))
40194+
{ // dataDescriptionEntryFormat1 |
40195+
// dataDescriptionEntryFormat2 |
40196+
// dataDescriptionEntryFormat3 |
40197+
// dataDescriptionEntryExecSql
40198+
40199+
ASTTerm tt = (ASTTerm) terms.get(0);
40200+
Vector ttres = tt.cobolDataDefinitions(context);
40201+
return ttres;
40202+
}
40203+
40204+
if ("dataDescriptionEntryFormat1".equals(tag))
40205+
{ // Level (FILLER | dataName)? dataClause* .
40206+
40207+
// If preceding item at lower or same levelnumber,
40208+
// container != null and this is attribute of
40209+
// container or padding (FILLER).
40210+
// If preceding item at higher levelnumber, or no
40211+
// preceding item (container = null), this is
40212+
// a new container class.
40213+
40214+
ASTTerm tt = (ASTTerm) terms.get(0);
40215+
String level = tt.literalForm();
40216+
int levelNumber = 0;
40217+
String fieldName = "";
40218+
40219+
if ("77".equals(level))
40220+
{ context.put("container", null);
40221+
return res;
40222+
}
40223+
40224+
try
40225+
{ levelNumber = Integer.parseInt(level); }
40226+
catch (Exception ex) { return res; }
40227+
40228+
if (terms.size() == 1)
40229+
{ return res; }
40230+
40231+
ASTTerm t2 = (ASTTerm) terms.get(1);
40232+
if ("FILLER".equals(t2 + "") ||
40233+
t2.getTag().equals("dataName"))
40234+
{ fieldName = t2.literalForm(); }
40235+
else
40236+
{ fieldName = "FILLER"; }
40237+
40238+
Entity container = (Entity) context.get("container");
40239+
40240+
if (ASTTerm.hasTag(terms,"dataPictureClause"))
40241+
{ // It is a basic item, not an entity
40242+
if (container == null) // no container, so top-level attribute
40243+
{ if ("FILLER".equals(fieldName)) { }
40244+
else
40245+
{ Attribute att =
40246+
new Attribute(fieldName, new Type("String", null),
40247+
ModelElement.INTERNAL);
40248+
res.add(att);
40249+
40250+
context.put("previousLevel", new Integer(levelNumber));
40251+
}
40252+
}
40253+
else // basic attribute of some container
40254+
{ int contLevel = container.levelNumber;
40255+
40256+
Integer previousLevel = (Integer) context.get("previousLevel");
40257+
40258+
int prevLevel = previousLevel.intValue();
40259+
40260+
if (levelNumber >= prevLevel)
40261+
{ // attribute of container
40262+
if ("FILLER".equals(fieldName)) {}
40263+
else
40264+
{ Attribute att =
40265+
new Attribute(fieldName, new Type("String", null),
40266+
ModelElement.INTERNAL);
40267+
container.addAttribute(att);
40268+
} // could itself be composite
40269+
context.put("previousLevel",
40270+
new Integer(levelNumber));
40271+
}
40272+
else if (levelNumber < prevLevel)
40273+
{ // attribute of another container
40274+
if ("FILLER".equals(fieldName)) {}
40275+
else
40276+
{ Attribute att =
40277+
new Attribute(fieldName, new Type("String", null),
40278+
ModelElement.INTERNAL);
40279+
Entity actualContainer =
40280+
container.findContainer(levelNumber);
40281+
if (actualContainer != null)
40282+
{ actualContainer.addAttribute(att);
40283+
context.put("container", actualContainer);
40284+
}
40285+
} // could itself be composite
40286+
context.put("previousLevel",
40287+
new Integer(levelNumber));
40288+
}
40289+
}
40290+
}
40291+
else // No PICTURE => new entity
40292+
{ if ("FILLER".equals(fieldName)) {}
40293+
else
40294+
{ Entity newent = new Entity(fieldName + "_Class");
40295+
newent.levelNumber = levelNumber;
40296+
Attribute att =
40297+
new Attribute(fieldName, new Type(newent),
40298+
ModelElement.INTERNAL);
40299+
40300+
Integer previousLevel = (Integer) context.get("previousLevel");
40301+
40302+
int prevLevel = -1;
40303+
if (previousLevel != null)
40304+
{ prevLevel = previousLevel.intValue(); }
40305+
40306+
res.add(newent);
40307+
if (container == null) // top-level
40308+
{ res.add(att); }
40309+
else if (levelNumber >= prevLevel)
40310+
{ newent.container = container;
40311+
container.addAttribute(att);
40312+
}
40313+
else
40314+
{ Entity actualContainer =
40315+
container.findContainer(levelNumber);
40316+
if (actualContainer != null)
40317+
{ newent.container = actualContainer;
40318+
actualContainer.addAttribute(att);
40319+
}
40320+
}
40321+
40322+
context.put("container", newent);
40323+
context.put("previousLevel", new Integer(levelNumber));
40324+
}
40325+
}
40326+
}
40327+
40328+
return res;
40329+
}
4013740330

4013840331
public static void convertAntlr2CSTL()
4013940332
{ // Testing of JS to KM3

ASTSymbolTerm.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,10 @@ public Vector normaliseAntlr()
841841

842842
public String antlrElement2cstl(Vector rulerefs, Vector conds)
843843
{ return symbol; }
844+
845+
public Vector cobolDataDefinitions(java.util.Map context)
846+
{ Vector res = new Vector();
847+
return res;
848+
}
849+
844850
}

ASTTerm.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,16 @@ public Entity getEntity()
10821082
return null;
10831083
}
10841084

1085+
public static boolean hasTag(Vector terms, String tag)
1086+
{ boolean res = false;
1087+
for (int i = 0; i < terms.size(); i++)
1088+
{ ASTTerm tt = (ASTTerm) terms.get(i);
1089+
if (tt.hasTag(tag))
1090+
{ return true; }
1091+
}
1092+
return res;
1093+
}
1094+
10851095
public abstract boolean hasTag(String tagx);
10861096

10871097
public abstract boolean hasSingleTerm();
@@ -3643,6 +3653,9 @@ public static Vector randomCompositeASTTermsForTag(
36433653

36443654
public abstract Vector normaliseAntlr();
36453655

3656+
public abstract Vector cobolDataDefinitions(java.util.Map context);
3657+
3658+
36463659
public static void main(String[] args)
36473660
{ // ASTBasicTerm t = new ASTBasicTerm("OclBasicExpression", "true");
36483661
// System.out.println(t.isInteger());

0 commit comments

Comments
 (0)