Skip to content

Commit 2d939c8

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

19 files changed

+470
-155
lines changed

ASTBasicTerm.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public boolean hasTag(String tagx)
3535
public boolean hasSingleTerm()
3636
{ return true; }
3737

38+
public boolean isNestedSymbolTerm()
39+
{ return true; }
40+
3841
public int arity()
3942
{ return 1; }
4043

ASTCompositeTerm.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public String getTag()
6262
public boolean hasSingleTerm()
6363
{ return terms.size() == 1; }
6464

65+
public boolean isNestedSymbolTerm()
66+
{ if (terms.size() == 1)
67+
{ ASTTerm t0 = (ASTTerm) terms.get(0);
68+
return t0.isNestedSymbolTerm();
69+
}
70+
return false;
71+
}
72+
6573
public int arity()
6674
{ return terms.size(); }
6775

@@ -2314,6 +2322,15 @@ else if (t2.hasTag("pointer"))
23142322
return et;
23152323
}
23162324

2325+
if ("enumSpecifier".equals(tag) &&
2326+
terms.size() == 2 &&
2327+
"enum".equals(terms.get(0) + ""))
2328+
{ // enum name
2329+
String sname = ((ASTTerm) terms.get(1)).literalForm();
2330+
Type et = new Type(sname,null);
2331+
return et;
2332+
}
2333+
23172334

23182335
if ("structOrUnionSpecifier".equals(tag) &&
23192336
terms.size() == 2)
@@ -10870,7 +10887,7 @@ else if ("next".equals(called) || "nextElement".equals(called) || "nextToken".eq
1087010887
}
1087110888
else if ("countTokens".equals(called))
1087210889
{ String tt = ASTTerm.getType(args);
10873-
System.out.println(">>> Type of " + args + " is: " + tt);
10890+
// System.out.println(">>> Type of " + args + " is: " + tt);
1087410891
// if ("OclIterator".equals(tt))
1087510892
ASTTerm.setType(thisliteral,"int");
1087610893

ASTSymbolTerm.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public boolean hasTag(String tagx)
2828
public boolean hasSingleTerm()
2929
{ return false; }
3030

31+
public boolean isNestedSymbolTerm()
32+
{ return true; }
33+
3134
public String cg(CGSpec cgs)
3235
{ return symbol; }
3336

ASTTerm.java

Lines changed: 153 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,25 +695,57 @@ public static boolean allSymbolTerms(ASTTerm[] trees)
695695
}
696696

697697
public static boolean allNestedSymbolTerms(ASTTerm[] trees)
698-
{ if (trees.length == 0)
698+
{ // All either symbols or nested symbols
699+
700+
if (trees.length == 0)
699701
{ return false; }
702+
700703
for (int i = 0; i < trees.length; i++)
701704
{ ASTTerm tx = trees[i];
702705
if (tx == null)
703706
{ return false; }
704-
if (tx.arity() == 1)
705-
{ ASTTerm ttx = tx.getTerm(0);
706707

707-
if (ttx instanceof ASTSymbolTerm) { }
708-
else
709-
{ return false; }
708+
if (tx.arity() <= 1 && tx.isNestedSymbolTerm())
709+
{
710+
System.out.println(">>> Nested symbol term: " + tx);
710711
}
711712
else
712713
{ return false; }
713714
}
714715
return true;
715716
}
716717

718+
public abstract boolean isNestedSymbolTerm();
719+
720+
public static boolean recursivelyNestedEqual(
721+
ASTTerm[] strees, ASTTerm[] ttrees)
722+
{ // Each strees[i] is a symbol, literally equal
723+
// to the targets
724+
725+
if (strees.length == 0)
726+
{ return false; }
727+
728+
if (strees.length != ttrees.length)
729+
{ return false; }
730+
731+
for (int i = 0; i < strees.length; i++)
732+
{ ASTTerm sx = strees[i];
733+
ASTTerm tx = ttrees[i];
734+
735+
if (sx == null || tx == null)
736+
{ return false; }
737+
738+
String slit = sx.literalForm();
739+
String tlit = tx.literalForm();
740+
741+
if (slit.equals(tlit)) { }
742+
else
743+
{ return false; }
744+
}
745+
746+
return true;
747+
}
748+
717749

718750
public static boolean functionalSymbolMapping(ASTTerm[] strees, ASTTerm[] ttrees)
719751
{ // The correspondence is functional.
@@ -1110,6 +1142,121 @@ else if (xx.equals(yvect)) { }
11101142
return res;
11111143
}
11121144

1145+
public static Vector createGeneralisedMappings
1146+
(ASTTerm[] xs, Expression trg)
1147+
{ // Each xs[i] maps to same target.
1148+
// Create a separate mapping for each different arity
1149+
// of xs. Extract constant symbol values.
1150+
1151+
Vector res = new Vector();
1152+
java.util.Map aritymap = new java.util.HashMap();
1153+
Vector doms = new Vector();
1154+
1155+
if (xs.length > 1)
1156+
{ for (int i = 0; i < xs.length; i++)
1157+
{ ASTTerm xx = xs[i];
1158+
1159+
if (xx != null)
1160+
{ int n = xx.arity();
1161+
Integer nx = new Integer(n);
1162+
doms.add(nx);
1163+
Vector aritynterms =
1164+
(Vector) aritymap.get(nx);
1165+
if (aritynterms == null)
1166+
{ aritynterms = new Vector();
1167+
aritynterms.add(xx);
1168+
aritymap.put(nx,aritynterms);
1169+
}
1170+
else
1171+
{ aritynterms.add(xx); }
1172+
}
1173+
}
1174+
}
1175+
else
1176+
{ return res; }
1177+
1178+
for (int j = 0; j < doms.size(); j++)
1179+
{ // For each arity set aritymap(doms(j))
1180+
// identify the generalised form of the terms
1181+
1182+
Integer nx = (Integer) doms.get(j);
1183+
Vector arityns = (Vector) aritymap.get(nx);
1184+
1185+
System.out.println(">>> Arity " + nx + " source terms are: " + arityns);
1186+
System.out.println();
1187+
1188+
if (arityns.size() == 1)
1189+
{ ASTTerm st = (ASTTerm) arityns.get(0);
1190+
BasicExpression expr =
1191+
BasicExpression.newASTBasicExpression(st);
1192+
AttributeMatching am =
1193+
new AttributeMatching(expr,trg);
1194+
res.add(am);
1195+
}
1196+
else
1197+
{ ASTTerm st0 = (ASTTerm) arityns.get(0);
1198+
BasicExpression expr =
1199+
BasicExpression.newASTBasicExpression(st0);
1200+
int n = nx.intValue();
1201+
for (int p = 0; p < n; p++)
1202+
{ if (ASTTerm.constantTerms(arityns,p))
1203+
{ ASTTerm pterm = st0.getTerm(p);
1204+
String st0p = pterm.literalForm();
1205+
Expression exprp =
1206+
new BasicExpression(st0p);
1207+
expr.setParameter(p+1, exprp);
1208+
}
1209+
else
1210+
{ expr.setParameter(p+1,
1211+
new BasicExpression("_" + (p+1)));
1212+
}
1213+
}
1214+
AttributeMatching am =
1215+
new AttributeMatching(expr,trg);
1216+
res.add(am);
1217+
}
1218+
}
1219+
1220+
System.out.println(">>> Generalised matchings: " + res);
1221+
1222+
return res;
1223+
}
1224+
1225+
public static boolean constantTerms(Vector trms, int p)
1226+
{ // The p subterms of all trms are the same
1227+
1228+
if (trms.size() == 0)
1229+
{ return false; }
1230+
1231+
if (trms.size() == 1)
1232+
{ return true; }
1233+
1234+
ASTTerm t0 = (ASTTerm) trms.get(0);
1235+
if (t0.arity() <= p)
1236+
{ return false; }
1237+
1238+
ASTTerm subtermp = t0.getTerm(p);
1239+
1240+
String lit = subtermp.literalForm();
1241+
1242+
for (int i = 1; i < trms.size(); i++)
1243+
{ ASTTerm t = (ASTTerm) trms.get(i);
1244+
ASTTerm subterm = t.getTerm(p);
1245+
1246+
// System.out.println(" " + p + " subterm of " + t + " is " + subterm + " =? " + lit);
1247+
1248+
if (subterm != null &&
1249+
subterm.literalForm().equals(lit))
1250+
{ }
1251+
else
1252+
{ return false; }
1253+
}
1254+
1255+
// System.out.println(" " + p + " subterm is constant");
1256+
1257+
return true;
1258+
}
1259+
11131260
/* public static boolean matchingTrees(ASTTerm[] xs, ASTTerm[] ys, ModelSpecification mod)
11141261
{ // Is each ys[i] = xs[i], or corresponding under mod?
11151262

Attribute.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,9 +1795,21 @@ public String saveModelData(PrintWriter out)
17951795
out.println(cname + ".upper = 1");
17961796
}
17971797

1798-
if (!instanceScope) { out.println(cname + ".isStatic = true"); }
1799-
if (isFinal()) { out.println(cname + ".isReadOnly = true"); }
1800-
if (unique) { out.println(cname + ".isUnique = true"); }
1798+
if (instanceScope)
1799+
{ out.println(cname + ".isStatic = false"); }
1800+
else
1801+
{ out.println(cname + ".isStatic = true"); }
1802+
1803+
if (isFinal())
1804+
{ out.println(cname + ".isReadOnly = true"); }
1805+
else
1806+
{ out.println(cname + ".isReadOnly = false"); }
1807+
1808+
1809+
if (unique)
1810+
{ out.println(cname + ".isUnique = true"); }
1811+
else
1812+
{ out.println(cname + ".isUnique = false"); }
18011813

18021814
if (initialExpression != null)
18031815
{ String ini = initialExpression.saveModelData(out);

BasicExpression.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,8 @@ else if (objectRef.elementType != null && objectRef.elementType.isEntity())
32663266
{ type = new Type(createdClass,null);
32673267
umlkind = UPDATEOP;
32683268
isStatic = true;
3269+
entity = (Entity)
3270+
ModelElement.lookupByName(createdClass,entities);
32693271
multiplicity = ModelElement.ONE;
32703272
if (parameters != null)
32713273
{ for (int i = 0; i < parameters.size(); i++)
@@ -3290,6 +3292,8 @@ else if (createdClass.startsWith("OclIterator"))
32903292
{ type = new Type("OclIterator",null);
32913293
umlkind = UPDATEOP;
32923294
isStatic = true;
3295+
entity = (Entity)
3296+
ModelElement.lookupByName("OclIterator",entities);
32933297
multiplicity = ModelElement.ONE;
32943298
if (parameters != null && parameters.size() > 0)
32953299
{ Expression par1 = (Expression) parameters.get(0);
@@ -3443,7 +3447,9 @@ else if (createdClass.startsWith("OclIterator_String"))
34433447
if (objectRef.type != null &&
34443448
objectRef.type.getName().equals("OclIterator"))
34453449
{ type = new Type("Sequence", null);
3446-
3450+
entity = (Entity)
3451+
ModelElement.lookupByName("OclIterator",entities);
3452+
34473453
umlkind = ATTRIBUTE;
34483454
multiplicity = ModelElement.MANY;
34493455

@@ -3458,6 +3464,9 @@ else if (createdClass.startsWith("OclIterator_String"))
34583464
{ type = new Type("void", null);
34593465
umlkind = UPDATEOP;
34603466
multiplicity = ModelElement.ONE;
3467+
entity = (Entity)
3468+
ModelElement.lookupByName(objectRef.type.getName(),
3469+
entities);
34613470

34623471
return true;
34633472
}
@@ -3475,7 +3484,9 @@ else if (createdClass.startsWith("OclIterator_String"))
34753484
{ type = new Type("String", null);
34763485
umlkind = QUERY;
34773486
multiplicity = ModelElement.ONE;
3478-
3487+
entity = (Entity)
3488+
ModelElement.lookupByName("OclFile",entities);
3489+
34793490
return true;
34803491
}
34813492
}
@@ -3488,6 +3499,8 @@ else if (createdClass.startsWith("OclIterator_String"))
34883499
{ type = new Type("long", null);
34893500
umlkind = QUERY;
34903501
multiplicity = ModelElement.ONE;
3502+
entity = (Entity)
3503+
ModelElement.lookupByName("OclFile",entities);
34913504

34923505
return true;
34933506
}
@@ -3506,6 +3519,8 @@ else if (createdClass.startsWith("OclIterator_String"))
35063519
umlkind = QUERY;
35073520
multiplicity = ModelElement.ONE;
35083521
// set the formal parameters
3522+
entity = (Entity)
3523+
ModelElement.lookupByName("OclFile",entities);
35093524

35103525
return true;
35113526
}
@@ -3519,6 +3534,8 @@ else if (createdClass.startsWith("OclIterator_String"))
35193534
{ type = new Type("boolean", null);
35203535
umlkind = QUERY;
35213536
multiplicity = ModelElement.ONE;
3537+
entity = (Entity)
3538+
ModelElement.lookupByName("OclProcess",entities);
35223539
return true;
35233540
}
35243541
}
@@ -3531,6 +3548,9 @@ else if (createdClass.startsWith("OclIterator_String"))
35313548
{ type = new Type("String", null);
35323549
umlkind = QUERY;
35333550
multiplicity = ModelElement.ONE;
3551+
entity = (Entity)
3552+
ModelElement.lookupByName("OclProcess",entities);
3553+
35343554
return true;
35353555
} // and for OclType
35363556
}
@@ -3542,6 +3562,8 @@ else if (createdClass.startsWith("OclIterator_String"))
35423562
umlkind = QUERY;
35433563
multiplicity = ModelElement.ONE;
35443564
isStatic = true;
3565+
entity = (Entity)
3566+
ModelElement.lookupByName("OclProcess",entities);
35453567
return true;
35463568
}
35473569

@@ -3553,7 +3575,9 @@ else if (createdClass.startsWith("OclIterator_String"))
35533575
{ type = new Type("int", null);
35543576
umlkind = QUERY;
35553577
multiplicity = ModelElement.ONE;
3556-
3578+
entity = (Entity)
3579+
ModelElement.lookupByName("OclProcess",entities);
3580+
35573581
return true;
35583582
}
35593583
}

BehaviouralFeature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,7 @@ else if (entity != null)
31813181
String typeid = resultType.getUMLModelName(out);
31823182
out.println(opid + ".type = " + typeid);
31833183
if (rtname.equals("Set") || rtname.equals("Sequence") ||
3184+
rtname.equals("Ref") ||
31843185
rtname.equals("Map") || rtname.equals("Function") )
31853186
{ if (elementType == null)
31863187
{ System.err.println("Warning!: No element type for " + this);
@@ -3278,6 +3279,7 @@ public String saveAsUSEData()
32783279
if (i < parameters.size() - 1) { res = res + ", "; }
32793280
}
32803281
res = res + ") ";
3282+
32813283
if (resultType != null)
32823284
{ String rtname = resultType.getName();
32833285
if (rtname.equals("Set") || rtname.equals("Sequence"))

0 commit comments

Comments
 (0)