Skip to content

Commit 5de8e0e

Browse files
authored
Extended cobol2UML abstractor
cg/cobol2UML.cstl now covers PERFORM, GOTO, etc
1 parent 8814c51 commit 5de8e0e

File tree

7 files changed

+190
-29
lines changed

7 files changed

+190
-29
lines changed

ASTCompositeTerm.java

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,14 @@ public String cgRules(CGSpec cgs, Vector rules)
350350
java.util.HashMap matches = new java.util.HashMap();
351351
// vars --> terms
352352

353+
Vector matchedTerms = new Vector();
354+
Vector matchedTokens = new Vector();
355+
353356
if (tokens.size() > terms.size())
354357
{ // System.out.println("> " + tag + " rule " + r + " does not match " + this);
355358
// System.out.println("!! Too many elements on rule LHS (" + tokens.size() + ") to match subterms: (" + terms.size() + ")");
356359
continue;
357-
}
360+
} // _* and _+ must match at least one term.
358361
else if (vars.contains("_*") && terms.size() >= tokens.size())
359362
{ } // ok
360363
else if (vars.contains("_+") && terms.size() >= tokens.size())
@@ -381,12 +384,7 @@ else if (tokens.size() == terms.size())
381384

382385
System.out.println("$$$ matching token " + tok + " and term " + tm);
383386

384-
if (tok.equals(tm.literalForm()))
385-
{ System.out.println(">> Matched token " + tok +
386-
" and term " + tm);
387-
k++;
388-
}
389-
else if ("_*".equals(tok) && vars.contains(tok))
387+
if ("_*".equals(tok) && vars.contains(tok))
390388
{ // remainder of terms is processed as a list
391389
// _* should be the last token, or terminated by
392390
// nextTok
@@ -410,15 +408,19 @@ else if ("_*".equals(tok) && vars.contains(tok))
410408
{ System.out.println("$$$ Matched terminator token " +
411409
nextTok +
412410
" for _* and term " + pterm);
413-
finished = true;
411+
finished = true;
412+
matchedTokens.add("_*");
414413
// k++; // next term after terminator
415414
// j++; // Next lhs token after _*
416415
// j++; // Next lhs token after terminator
417416
}
418417
else if (remainingTokens > remainingTerms)
419-
{ finished = true; }
418+
{ matchedTokens.add("_*");
419+
finished = true;
420+
}
420421
else
421422
{ rem.add(pterm);
423+
matchedTerms.add(pterm);
422424
k++;
423425
}
424426
System.out.println(">>> Terms for _* are: " + rem);
@@ -446,11 +448,16 @@ else if ("_+".equals(tok) && vars.contains(tok))
446448

447449
if (nextTok != null &&
448450
pterm.literalForm().equals(nextTok))
449-
{ finished = true; }
451+
{ finished = true;
452+
matchedTokens.add("_*");
453+
}
450454
else if (remainingTokens > remainingTerms)
451-
{ finished = true; }
455+
{ matchedTokens.add("_*");
456+
finished = true;
457+
}
452458
else
453-
{ rem.add(pterm);
459+
{ rem.add(pterm);
460+
matchedTerms.add(pterm);
454461
k++;
455462
}
456463
System.out.println(">>> Terms for _+ are: " + rem);
@@ -463,6 +470,9 @@ else if (vars.contains(tok))
463470
System.out.println(">> Matched variable " + tok +
464471
" and term " + tm);
465472

473+
matchedTokens.add(tok);
474+
matchedTerms.add(tm);
475+
466476
ASTTerm oldterm = (ASTTerm) matches.get(tok);
467477
if (oldterm == null)
468478
{ matches.put(tok,tm);
@@ -482,6 +492,13 @@ else if (oldterm.equals(tm))
482492
failed = true;
483493
}
484494
}
495+
else if (tok.equals(tm.literalForm()))
496+
{ System.out.println(">> Matched token " + tok +
497+
" and term " + tm);
498+
matchedTerms.add(tm);
499+
matchedTokens.add(tok);
500+
k++;
501+
}
485502
else
486503
{ // System.out.println("> " + tag + " rule " + r + " does not match " + this);
487504
// System.out.println(tok + " /= " + tm.literalForm());
@@ -490,6 +507,19 @@ else if (oldterm.equals(tm))
490507
}
491508
}
492509

510+
if (matchedTokens.containsAll(tokens) &&
511+
tokens.containsAll(matchedTokens))
512+
{ System.out.println("&&& All tokens matched: " + tokens); }
513+
// else
514+
// { failed = true; }
515+
516+
if (matchedTerms.containsAll(terms) &&
517+
terms.containsAll(matchedTerms))
518+
{ System.out.println("&&& All terms matched: " + terms); }
519+
else
520+
{ failed = true; }
521+
522+
493523
if (failed == false)
494524
{ System.out.println(">> Matched " + tag + " rule " + r + " for " + this);
495525

@@ -513,10 +543,13 @@ else if (obj instanceof Vector)
513543

514544
Vector ents = new Vector();
515545

516-
if (r.satisfiesConditions(eargs,ents,cgs))
546+
if (r.satisfiesAllConditions(eargs,ents,cgs))
517547
{ System.out.println(">>>> Applying " + tag + " rule " + r);
518548
return r.applyRule(args,eargs,cgs);
519549
}
550+
else
551+
{ System.out.println(">!> Conditions of " + r + " failed.");
552+
}
520553
}
521554
}
522555

BasicExpression.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9384,7 +9384,9 @@ public String updateFormEqJava7(java.util.Map env, String val2, Expression var,
93849384
{ return "{} /* can't assign to: " + data + " */"; }
93859385

93869386
if (umlkind == CLASSID && arrayIndex == null)
9387-
{ if (val2.equals("{}") || val2.equals("Set{}") || val2.equals("Sequence{}")) // delete the class extent
9387+
{ if (val2.equals("{}") ||
9388+
val2.equals("Set{}") ||
9389+
val2.equals("Sequence{}")) // delete the class extent
93889390
{ String datas = classExtentQueryFormJava7(env,local);
93899391
return "ArrayList<" + data + "> _" + data + " = new ArrayList<" + data + ">(); \n" +
93909392
" _" + data + ".addAll(" + datas + "); \n" +
@@ -9572,7 +9574,8 @@ public String updateFormEqCSharp(java.util.Map env,
95729574
{ String indopt = arrayIndex.queryFormCSharp(env,local);
95739575
String wind = arrayIndex.wrapCSharp(indopt);
95749576
String wval = var.wrapCSharp(val2);
9575-
if ("String".equals(arrayIndex.type + ""))
9577+
if ("String".equals(arrayIndex.type + "") ||
9578+
BasicExpression.isMapAccess(this))
95769579
{ return datax + "[" + wind + "] = " + wval + ";"; } // map[index] = val2
95779580
else
95789581
{ return datax + "[" + indopt + " -1] = " + wval + ";"; }
@@ -9605,7 +9608,9 @@ else if (type != null && var.type != null)
96059608
{ String ind = arrayIndex.queryFormCSharp(env,local);
96069609
String wind = arrayIndex.wrapCSharp(ind);
96079610
String wval = var.wrapCSharp(val2);
9608-
if (isQualified() || "String".equals(arrayIndex.type + ""))
9611+
if (isQualified() ||
9612+
"String".equals(arrayIndex.type + "") ||
9613+
BasicExpression.isMapAccess(this))
96099614
{ return data + "[" + wind + "] = " + wval + ";"; }
96109615
return data + "[" + ind + " - 1] = " + val2 + ";";
96119616
}
@@ -9644,7 +9649,9 @@ else if (type != null && var.type != null)
96449649

96459650
if (arrayIndex != null)
96469651
{ String ind = arrayIndex.queryFormCSharp(env,local);
9647-
if (isQualified())
9652+
if (isQualified() ||
9653+
"String".equals(arrayIndex.type + "") ||
9654+
BasicExpression.isMapAccess(this))
96489655
{ return cont + ".set" + data + "(" + target + ind + ", " + val2 + ");"; }
96499656
String indopt = evaluateString("-",ind,"1"); // not for qualified
96509657
return cont + ".set" + data + "(" + target + indopt + "," + val2 + ");";
@@ -9669,7 +9676,8 @@ else if (type != null && var.type != null)
96699676

96709677
if (entity != null && entity.isClassScope(data))
96719678
{ if (arrayIndex != null)
9672-
{ String indopt = arrayIndex.queryFormCSharp(env,local);
9679+
{ String indopt =
9680+
arrayIndex.queryFormCSharp(env,local);
96739681
return nme + ".set" + data + "((" + indopt + " -1), " + val2 + ");";
96749682
}
96759683
return nme + ".set" + data + "(" + val2 + ");";
@@ -9702,7 +9710,9 @@ else if (type != null && var.type != null)
97029710
{ cref = nme + "Ops"; }
97039711
if (arrayIndex != null)
97049712
{ String ind = arrayIndex.queryFormCSharp(env,local);
9705-
if (isQualified())
9713+
if (isQualified() ||
9714+
"String".equals(arrayIndex.type + "") ||
9715+
BasicExpression.isMapAccess(this))
97069716
{ return cref + ".setAll" + data + "(" + pre + "," + ind + "," +
97079717
val2 + ");";
97089718
}
@@ -9716,7 +9726,9 @@ else if (type != null && var.type != null)
97169726
{ if (local)
97179727
{ if (arrayIndex != null)
97189728
{ String ind = arrayIndex.queryFormCSharp(env,local);
9719-
if (isQualified())
9729+
if (isQualified() ||
9730+
"String".equals(arrayIndex.type + "") ||
9731+
BasicExpression.isMapAccess(this))
97209732
{ return pre + ".set" + data + "(" + ind + "," +
97219733
val2 + ");";
97229734
}
@@ -9727,7 +9739,9 @@ else if (type != null && var.type != null)
97279739
}
97289740
else if (arrayIndex != null)
97299741
{ String ind = arrayIndex.queryFormCSharp(env,local);
9730-
if (isQualified())
9742+
if (isQualified() ||
9743+
"String".equals(arrayIndex.type + "") ||
9744+
BasicExpression.isMapAccess(this))
97319745
{ return cont + ".set" + data + "(" + pre + "," + ind + "," + val2 + ");"; }
97329746
String indopt = evaluateString("-",ind,"1");
97339747
return cont + ".set" + data + "(" + pre + "," + indopt + "," +
@@ -9779,7 +9793,8 @@ public String updateFormEqCPP(java.util.Map env,
97799793
if (umlkind == VARIABLE)
97809794
{ if (arrayIndex != null)
97819795
{ String indopt = arrayIndex.queryFormCPP(env,local);
9782-
if ("String".equals(arrayIndex.type + ""))
9796+
if ("String".equals(arrayIndex.type + "") ||
9797+
BasicExpression.isMapAccess(this))
97839798
{ return "(*" + data + ")[" + indopt + "] = " + val2 + ";"; } // map[index] = val2
97849799
else
97859800
{ return "(*" + data + ")[" + indopt + " -1] = " + val2 + ";"; }
@@ -9796,7 +9811,9 @@ public String updateFormEqCPP(java.util.Map env,
97969811
{ if (local)
97979812
{ if (arrayIndex != null)
97989813
{ String ind = arrayIndex.queryFormCPP(env,local);
9799-
if (isQualified() || "String".equals(arrayIndex.type + ""))
9814+
if (isQualified() ||
9815+
"String".equals(arrayIndex.type + "") ||
9816+
BasicExpression.isMapAccess(this))
98009817
{ return "(*" + data + ")[" + ind + "] = " + val2 + ";"; }
98019818
return "(*" + data + ")[" + ind + " - 1] = " + val2 + ";";
98029819
}
@@ -9823,7 +9840,9 @@ public String updateFormEqCPP(java.util.Map env,
98239840

98249841
if (arrayIndex != null)
98259842
{ String ind = arrayIndex.queryFormCPP(env,local);
9826-
if (isQualified())
9843+
if (isQualified() ||
9844+
"String".equals(arrayIndex.type + "") ||
9845+
BasicExpression.isMapAccess(this))
98279846
{ return cont + "set" + data + "(" + target + ind + ", " + val2 + ");"; }
98289847
String indopt = evaluateString("-",ind,"1"); // not for qualified
98299848
return cont + "set" + data + "(" + target + indopt + "," + val2 + ");";
@@ -9858,7 +9877,9 @@ public String updateFormEqCPP(java.util.Map env,
98589877
if (objectRef.isMultiple())
98599878
{ if (arrayIndex != null)
98609879
{ String ind = arrayIndex.queryFormCPP(env,local);
9861-
if (isQualified())
9880+
if (isQualified() ||
9881+
"String".equals(arrayIndex.type + "") ||
9882+
BasicExpression.isMapAccess(this))
98629883
{ return nme + "::setAll" + data + "(" + pre + "," + ind + "," +
98639884
val2 + ");";
98649885
}
@@ -9872,7 +9893,9 @@ public String updateFormEqCPP(java.util.Map env,
98729893
{ if (local)
98739894
{ if (arrayIndex != null)
98749895
{ String ind = arrayIndex.queryFormCPP(env,local);
9875-
if (isQualified())
9896+
if (isQualified() ||
9897+
"String".equals(arrayIndex.type + "") ||
9898+
BasicExpression.isMapAccess(this))
98769899
{ return pre + "->set" + data + "(" + ind + "," + val2 + ");"; }
98779900
String indopt = evaluateString("-",ind,"1");
98789901
return pre + "->set" + data + "(" + indopt + "," + val2 + ");";
@@ -9881,7 +9904,9 @@ public String updateFormEqCPP(java.util.Map env,
98819904
}
98829905
else if (arrayIndex != null)
98839906
{ String ind = arrayIndex.queryFormCPP(env,local);
9884-
if (isQualified())
9907+
if (isQualified() ||
9908+
"String".equals(arrayIndex.type + "") ||
9909+
BasicExpression.isMapAccess(this))
98859910
{ return cont + "set" + data + "(" + pre + "," + ind + "," + val2 + ");"; }
98869911
String indopt = evaluateString("-",ind,"1");
98879912
return cont + "set" + data + "(" + pre + "," + indopt + "," +

CGCondition.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static boolean conditionsSatisfied(
242242
{ boolean res = true;
243243
for (int i = 0; i < args.size(); i++)
244244
{ Object m = args.get(i);
245-
String var = "_" + (i+1);
245+
String var = "_" + (i+1); // assumes numbered _1, _2 ...
246246

247247
for (int j = 0; j < conditions.size(); j++)
248248
{ CGCondition cond = (CGCondition) conditions.get(j);
@@ -260,6 +260,14 @@ public static boolean conditionsSatisfied(
260260
{ return false; }
261261
System.out.println("||| Condition " + cond + " is satisfied by " + m);
262262
}
263+
else if ("_+".equals(cvar) &&
264+
m instanceof Vector)
265+
{ if (cond.conditionSatisfied((Vector) m,entities,cgs))
266+
{ }
267+
else
268+
{ return false; }
269+
System.out.println("||| Condition " + cond + " is satisfied by " + m);
270+
}
263271
else if (var.equals(cvar))
264272
{ if (m instanceof Type &&
265273
cond.conditionSatisfied((Type) m, entities,cgs))
@@ -298,6 +306,77 @@ else if (m instanceof ASTTerm &&
298306
return res;
299307
}
300308

309+
public static boolean allConditionsSatisfied(CGRule r,
310+
Vector conditions, Vector args,
311+
Vector entities, CGSpec cgs)
312+
{ boolean res = true;
313+
314+
for (int j = 0; j < conditions.size(); j++)
315+
{ CGCondition cond = (CGCondition) conditions.get(j);
316+
if (cond.variable != null)
317+
{ String cvar = cond.variable;
318+
int mfindex = cvar.indexOf("`");
319+
if (mfindex > 0)
320+
{ cvar = cvar.substring(0,mfindex); }
321+
322+
int ind = r.variables.indexOf(cvar);
323+
// variablePosition for CGTL rules
324+
325+
if (ind >= 0 && ind < args.size())
326+
{ Object m = args.get(ind);
327+
328+
if ("_*".equals(cvar) &&
329+
m instanceof Vector)
330+
{ if (cond.conditionSatisfied((Vector) m,entities,cgs))
331+
{ }
332+
else
333+
{ return false; }
334+
System.out.println("||| Condition " + cond + " is satisfied by " + m);
335+
}
336+
else if ("_+".equals(cvar) &&
337+
m instanceof Vector)
338+
{ if (cond.conditionSatisfied((Vector) m,entities,cgs))
339+
{ }
340+
else
341+
{ return false; }
342+
System.out.println("||| Condition " + cond + " is satisfied by " + m);
343+
}
344+
else if (m instanceof Type &&
345+
cond.conditionSatisfied((Type) m, entities,cgs))
346+
{ }
347+
else if (m instanceof Expression &&
348+
cond.conditionSatisfied((Expression) m, entities,cgs))
349+
{ }
350+
else if (m instanceof Statement &&
351+
cond.conditionSatisfied((Statement) m, entities,cgs) )
352+
{ }
353+
else if (m instanceof Attribute &&
354+
cond.conditionSatisfied((Attribute) m, entities,cgs) )
355+
{ }
356+
else if (m instanceof ModelElement &&
357+
cond.stereotypeConditionSatisfied((ModelElement) m, entities,cgs))
358+
{ }
359+
else if (m instanceof Vector &&
360+
cond.conditionSatisfied((Vector) m, entities,cgs))
361+
{ }
362+
else if (m instanceof String &&
363+
cond.conditionSatisfied((String) m, entities,cgs))
364+
{ }
365+
else if (m instanceof ASTTerm &&
366+
cond.conditionSatisfied((ASTTerm) m, entities,cgs))
367+
{ System.out.println("||| ASTTerm condition " + cond + " satisfied by term " + m);
368+
System.out.println();
369+
}
370+
else
371+
{ return false; }
372+
373+
System.out.println("||| Condition " + cond + " is satisfied by " + m);
374+
}
375+
}
376+
}
377+
return res;
378+
}
379+
301380
public boolean stereotypeConditionSatisfied(ModelElement m, Vector entities, CGSpec cgs)
302381
{ if (m.hasStereotype(stereotype))
303382
{ return positive; }

0 commit comments

Comments
 (0)