Skip to content

Commit 1588190

Browse files
authored
Updated code generators and CGBE
1 parent 2d939c8 commit 1588190

14 files changed

+174
-26
lines changed

ASTCompositeTerm.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,9 +5246,22 @@ else if ("-".equals(op) && res != null)
52465246

52475247
Expression resx;
52485248
if ("!=".equals(op))
5249-
{ resx = new BinaryExpression("/=", res1, res2); }
5249+
{ if (res1.isString() || res1.isCollection())
5250+
{ BinaryExpression ineq =
5251+
new BinaryExpression("<>=", res1, res2);
5252+
resx = new UnaryExpression("not", ineq);
5253+
}
5254+
else
5255+
{ resx = new BinaryExpression("/=", res1, res2); }
5256+
resx.setType(new Type("boolean", null));
5257+
}
52505258
else if ("==".equals(op))
5251-
{ resx = new BinaryExpression("=", res1, res2); }
5259+
{ if (res1.isString() || res1.isCollection())
5260+
{ resx = new BinaryExpression("<>=", res1, res2); }
5261+
else
5262+
{ resx = new BinaryExpression("=", res1, res2); }
5263+
resx.setType(new Type("boolean", null));
5264+
}
52525265
else
52535266
{ resx = new BinaryExpression(op, res1, res2); }
52545267
resx.setType(new Type("boolean", null));
@@ -12031,11 +12044,11 @@ else if ("equals".equals(called))
1203112044
{ if (arg.expression != null &&
1203212045
callarg1.expression != null)
1203312046
{ expression =
12034-
new BinaryExpression("=",
12035-
new UnaryExpression("?", arg.expression),
12036-
new UnaryExpression("?", callarg1.expression));
12047+
new BinaryExpression("<>=",
12048+
arg.expression,
12049+
callarg1.expression);
1203712050
}
12038-
return "?" + args + " = ?" + callp1;
12051+
return args + " <>= " + callp1;
1203912052
}
1204012053

1204112054
if (arg.expression != null &&
@@ -17166,13 +17179,12 @@ else if (e1.isString() || e2.isString())
1716617179
if (e1.isIdentifier() && e2.isIdentifier() &&
1716717180
(e1.isCollection() || e2.isCollection()))
1716817181
{ if (e1.expression != null && e2.expression != null)
17169-
{ UnaryExpression ref1 = new UnaryExpression("?", e1.expression);
17170-
UnaryExpression ref2 = new UnaryExpression("?", e2.expression);
17171-
expression = new BinaryExpression("=", ref1, ref2);
17182+
{ expression = new BinaryExpression("<>=",
17183+
e1.expression, e2.expression);
1717217184
expression.setType(new Type("boolean", null));
1717317185
}
17174-
return "?" + e1xx + " = ?" + e2xx;
17175-
}
17186+
return e1xx + " <>= " + e2xx;
17187+
} // Also for strings and for !=
1717617188

1717717189
if (e1.expression != null && e2.expression != null)
1717817190
{ expression = new BinaryExpression("=", e1.expression, e2.expression);
@@ -17189,12 +17201,14 @@ else if (e1.isString() || e2.isString())
1718917201
if (e1.isIdentifier() && e2.isIdentifier() &&
1719017202
(e1.isCollection() || e2.isCollection()))
1719117203
{ if (e1.expression != null && e2.expression != null)
17192-
{ UnaryExpression ref1 = new UnaryExpression("?", e1.expression);
17193-
UnaryExpression ref2 = new UnaryExpression("?", e2.expression);
17194-
expression = new BinaryExpression("/=", ref1, ref2);
17204+
{ BinaryExpression expr =
17205+
new BinaryExpression("<>=", e1.expression,
17206+
e2.expression);
17207+
expr.setBrackets(true);
17208+
expression = new UnaryExpression("not", expr);
1719517209
expression.setType(new Type("boolean", null));
1719617210
}
17197-
return "?" + e1xx + " /= ?" + e2xx;
17211+
return "not(" + e1xx + " <>= " + e2xx + ")";
1719817212
}
1719917213

1720017214
if (e1.expression != null && e2.expression != null)

ASTTerm.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,12 @@ public static boolean functionalNestedSymbolMapping(ASTTerm[] strees, ASTTerm[]
791791

792792
public static TypeMatching createNewFunctionalMapping(String name, ASTTerm[] strees, ASTTerm[] ttrees)
793793
{ // The correspondence is functional.
794+
795+
// If an identity mapping, return _1 |-->_1
796+
797+
// A "default" case _1 |--> v is included where v is the
798+
// most frequent target of different source values.
799+
794800
Type str = new Type("String", null);
795801
TypeMatching tm = new TypeMatching(str,str);
796802
tm.setName(name);
@@ -804,7 +810,38 @@ public static TypeMatching createNewFunctionalMapping(String name, ASTTerm[] str
804810
for (int i = 0; i < ttrees.length; i++)
805811
{ tattvalues[i] = ttrees[i].literalForm(); }
806812

807-
tm.setStringValues(sattvalues,tattvalues);
813+
if (AuxMath.isIdentity(sattvalues,tattvalues))
814+
{ tm.addDefaultMapping("_1", "_1");
815+
return tm;
816+
}
817+
818+
/* Identify default mapping _1 |--> v */
819+
820+
String defaultValue = null;
821+
int defaultCount = 0;
822+
for (int i = 0; i < tattvalues.length; i++)
823+
{ String tval = tattvalues[i];
824+
java.util.HashSet svals = new java.util.HashSet();
825+
for (int j = 0; j < sattvalues.length &&
826+
j < tattvalues.length; j++)
827+
{ if (tattvalues[j].equals(tval))
828+
{ svals.add(sattvalues[j]); }
829+
}
830+
831+
if (svals.size() > defaultCount)
832+
{ defaultValue = tval;
833+
defaultCount = svals.size();
834+
}
835+
}
836+
837+
System.out.println(">> Default mapping is _1 |-->" + defaultValue);
838+
839+
840+
tm.setStringValues(sattvalues,tattvalues);
841+
842+
if (defaultValue != null)
843+
{ tm.addDefaultMapping("_1", defaultValue); }
844+
808845
return tm;
809846
}
810847

AuxMath.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Vector;
77

88
/******************************
9-
* Copyright (c) 2003--2021 Kevin Lano
9+
* Copyright (c) 2003--2022 Kevin Lano
1010
* This program and the accompanying materials are made available under the
1111
* terms of the Eclipse Public License 2.0 which is available at
1212
* http://www.eclipse.org/legal/epl-2.0
@@ -447,6 +447,26 @@ public static boolean isFunctional(String[] xs, String[] ys)
447447
return true;
448448
}
449449

450+
public static boolean isIdentity(String[] xs, String[] ys)
451+
{ // Each xs[i] = ys[i]
452+
453+
if (xs.length != ys.length)
454+
{ return false; }
455+
456+
for (int i = 0; i < xs.length; i++)
457+
{
458+
if (xs[i] == null)
459+
{ return false; }
460+
if (ys[i] == null)
461+
{ return false; }
462+
463+
if (xs[i].equals(ys[i])) { }
464+
else
465+
{ return false; }
466+
}
467+
return true;
468+
}
469+
450470
public static boolean isConstant(double[] ys)
451471
{ if (ys.length > 1)
452472
{ double y0 = ys[0];

BinaryExpression.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ public String toOcl(java.util.Map env, boolean local)
630630
return le + " " + operator + " " + re;
631631
} // - on collections is excludesAll in OCL? Plus set < elem, etc
632632

633+
// saveTextModel
633634
public String saveModelData(PrintWriter out)
634635
{ String id = Identifier.nextIdentifier("binaryexpression_");
635636
out.println(id + " : BinaryExpression");
@@ -3535,7 +3536,8 @@ else if (operator.equals("->sequenceRange"))
35353536
elementType = left.elementType;
35363537
type.setElementType(left.elementType);
35373538
}
3538-
else if (comparitors.contains(operator))
3539+
else if (operator.equals("<>=") ||
3540+
comparitors.contains(operator))
35393541
{ tcEq(tleft,tright,eleft,eright); }
35403542
else if (operator.equals("+"))
35413543
{ tcPlus(tleft,tright,eleft,eright); }
@@ -4684,7 +4686,9 @@ else if (left instanceof SetExpression)
46844686
}
46854687

46864688
if (!lmult && !rmult)
4687-
{ if (operator.equals("=")) // and comparitors
4689+
{ if (operator.equals("<>="))
4690+
{ res = lqf + " == " + rqf; }
4691+
else if (operator.equals("=")) // and comparitors
46884692
{ res = composeEqQueryForms(lqf,rqf,lprim,rprim); }
46894693
else if (operator.equals("/=") || operator.equals("!=") || operator.equals("<>"))
46904694
{ res = composeNeqQueryForms(lqf,rqf,lprim,rprim); }
@@ -4761,6 +4765,8 @@ else if (operator.equals("->prepend"))
47614765
{
47624766
res = "Set.concatenate(" + rss + "," + lqf + ")";
47634767
}
4768+
else if (operator.equals("<>="))
4769+
{ res = lqf + " == " + rqf; }
47644770
else if (operator.equals("="))
47654771
{ if (Type.isSetType(left.getType()))
47664772
{ res = "Set.equals(" + lqf + "," + rss + ")"; }
@@ -4815,6 +4821,8 @@ else if (rmult && !lmult)
48154821
else
48164822
{ res = ls + ".equals(" + rqf + ")"; }
48174823
}
4824+
else if (operator.equals("<>="))
4825+
{ res = lqf + " == " + rqf; }
48184826
else if (operator.equals("/=") || operator.equals("!=") || operator.equals("<>"))
48194827
{ if (Type.isSetType(right.getType()))
48204828
{ res = "!(Set.equals(" + ls + "," + rqf + "))"; }
@@ -4843,6 +4851,8 @@ else if (operator.equals("->lastIndexOf"))
48434851
{ res = "Collections.lastIndexOfSubList(" + lqf + "," + rqf + ") + 1";
48444852
bNeeded = true;
48454853
}
4854+
else if (operator.equals("<>="))
4855+
{ res = lqf + " == " + rqf; }
48464856
else
48474857
{ // res = lqf + " " + operator + " " + rqf;
48484858
res = composeSetQueryForms(lqf,rqf);
@@ -4967,6 +4977,13 @@ else if (left.hasSequenceType() && right.hasSequenceType())
49674977
if (operator.equals("->gcd"))
49684978
{ return "Set.gcd(" + lqf + "," + rqf + ")"; }
49694979

4980+
if (operator.equals("<>="))
4981+
{ res = lqf + " == " + rqf;
4982+
if (needsBracket)
4983+
{ res = "(" + res + ")"; }
4984+
return res;
4985+
}
4986+
49704987
if (operator.equals("->isUnique")) // and define for B
49714988
{ String fcollect = collectQueryFormJava6(lqf,rqf,rprim,env,local);
49724989
return "Set.isUnique(" + fcollect + ")";
@@ -5322,6 +5339,13 @@ else if (left.hasSequenceType() && right.hasSequenceType())
53225339
if (operator.equals("->gcd"))
53235340
{ return "Ocl.gcd(" + lqf + "," + rqf + ")"; }
53245341

5342+
if (operator.equals("<>="))
5343+
{ res = lqf + " == " + rqf;
5344+
if (needsBracket)
5345+
{ res = "(" + res + ")"; }
5346+
return res;
5347+
}
5348+
53255349
if (operator.equals("->isUnique")) // and define for B
53265350
{ String fcollect = collectQueryFormJava7(lqf,rqf,rprim,env,local);
53275351
return "Ocl.isUnique(" + fcollect + ")";
@@ -5683,6 +5707,13 @@ public String queryFormCSharp(java.util.Map env, boolean local)
56835707
if (operator.equals("->gcd"))
56845708
{ return "SystemTypes.gcd(" + lqf + "," + rqf + ")"; }
56855709

5710+
if (operator.equals("<>="))
5711+
{ res = lqf + " == " + rqf;
5712+
if (needsBracket)
5713+
{ res = "(" + res + ")"; }
5714+
return res;
5715+
}
5716+
56865717
if (operator.equals("->compareTo"))
56875718
{ if (left.isNumeric() && right.isNumeric())
56885719
{ res = "((" + lqf + " < " + rqf + ") ? -1 : ((" + lqf + " > " + rqf + ") ? 1 : 0))"; }
@@ -6085,6 +6116,13 @@ else if (entity != null)
60856116
if (operator.equals("->equalsIgnoreCase"))
60866117
{ return "UmlRsdsLib<" + lcet + ">::equalsIgnoreCase(" + lqf + "," + rqf + ")"; }
60876118

6119+
if (operator.equals("<>="))
6120+
{ res = lqf + " == " + rqf;
6121+
if (needsBracket)
6122+
{ res = "(" + res + ")"; }
6123+
return res;
6124+
}
6125+
60886126
if (operator.equals("->compareTo"))
60896127
{ res = "(" + lqf + " < " + rqf + ")?-1:((" + lqf + " > " + rqf + ")?1:0)";
60906128
return res;

Compiler2.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,8 @@ public Expression parse_eq_expression(int bc, int pstart,
23932393
{
23942394
String ss = lexicals.elementAt(i).toString();
23952395
if (ss.equals(":") || ss.equals("<:") ||
2396-
ss.equals("/:") || ss.equals("/<:") || ss.equals("<>") ||
2396+
ss.equals("/:") || ss.equals("/<:") ||
2397+
ss.equals("<>") || ss.equals("<>=") ||
23972398
Expression.comparitors.contains(ss))
23982399
{ e1 = parse_additive_expression(bc,pstart,i-1,entities,types);
23992400
e2 = parse_additive_expression(bc,i+1,pend,entities,types);

ConditionalExpression.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ public void setPre()
840840
}
841841

842842
public String saveModelData(PrintWriter out)
843-
{ String id = Identifier.nextIdentifier("conditionalexpression_");
843+
{ String id = Identifier.nextIdentifier(
844+
"conditionalexpression_");
844845
out.println(id + " : ConditionalExpression");
845846
out.println(id + ".expId = \"" + id + "\"");
846847

@@ -851,7 +852,23 @@ public String saveModelData(PrintWriter out)
851852
out.println(id + ".ifExpr = " + leftId);
852853
out.println(id + ".elseExpr = " + rightId);
853854
out.println(id + ".ifExp = " + leftId);
854-
out.println(id + ".elseExp = " + rightId);
855+
out.println(id + ".elseExp = " + rightId);
856+
857+
String tname = "void";
858+
if (type != null)
859+
{ tname = type.getUMLModelName(out); }
860+
out.println(id + ".type = " + tname);
861+
862+
if (elementType != null)
863+
{ String etname = elementType.getUMLModelName(out);
864+
out.println(id + ".elementType = " + etname);
865+
}
866+
else
867+
{ out.println(id + ".elementType = " + tname); }
868+
869+
out.println(id + ".needsBracket = " + needsBracket);
870+
out.println(id + ".umlKind = " + umlkind);
871+
855872
return id;
856873
}
857874

Entity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public boolean notEmpty()
6565
return false;
6666
} // or associations
6767

68+
public boolean isGenericParameter()
69+
{ return genericParameter; }
70+
6871
public boolean allSubclassesAreEmpty()
6972
{ boolean res = true;
7073
if (subclasses.size() == 0)

ModelSpecification.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,11 +5623,12 @@ public AttributeMatching composedTreeFunction(Entity sent,
56235623
Attribute var_1 =
56245624
new Attribute("_1", new Type("OclAny",null),
56255625
ModelElement.INTERNAL);
5626-
Expression var1expr = new BasicExpression(var_1);
5626+
BasicExpression var1expr = new BasicExpression(var_1);
56275627
Attribute var_star =
56285628
new Attribute("_*", new Type("OclAny",null),
56295629
ModelElement.INTERNAL);
5630-
Expression varstarexpr = new BasicExpression(var_star);
5630+
BasicExpression varstarexpr =
5631+
new BasicExpression(var_star);
56315632

56325633
System.out.println(">> Checking all combinations of tree functions based on source attributes: " + sourceatts);
56335634
System.out.println(">> Targets: " + tvalues);
@@ -5722,13 +5723,18 @@ else if (ASTTerm.allSymbolTerms(sattvalues) &&
57225723
TypeMatching tm =
57235724
ASTTerm.createNewFunctionalMapping(fid, sattvalues, targetValues);
57245725
System.out.println(">> New nested functional mapping of symbols: " + tm);
5725-
tms.add(tm);
5726+
if (tm.isVacuous()) { }
5727+
else
5728+
{ tms.add(tm); }
57265729

57275730
BasicExpression fexpr =
57285731
new BasicExpression(fid);
57295732
fexpr.setUmlKind(Expression.FUNCTION);
57305733
fexpr.addParameter(var1expr);
5731-
ams = new Vector();
5734+
ams = new Vector();
5735+
5736+
if (tm.isVacuous())
5737+
{ fexpr = var1expr; }
57325738
AttributeMatching amx =
57335739
new AttributeMatching(var1expr, fexpr);
57345740
return amx;

Type.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,9 @@ else if (nme.equals("Function"))
23372337
if (values == null && alias != null)
23382338
{ return alias.getUMLModelName(out); }
23392339

2340+
if (entity != null && entity.isGenericParameter())
2341+
{ return "OclAny"; }
2342+
23402343
return nme;
23412344
} // Function types for the future.
23422345

TypeMatching.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public void setStringValues(String[] svals, String[] tvals)
124124
}
125125
}
126126

127+
public void addDefaultMapping(String var, String val)
128+
{ Type stringtype = new Type("String", null);
129+
BasicExpression s = new BasicExpression(var);
130+
BasicExpression t = new BasicExpression(val);
131+
s.setType(stringtype);
132+
t.setType(stringtype);
133+
valueMappings.add(new ValueMatching(s,t));
134+
}
135+
127136
public void setValues(boolean[] svals, String[] tvals)
128137
{ Type stringtype = new Type("String", null);
129138
Type booltype = new Type("boolean", null);

0 commit comments

Comments
 (0)