Skip to content

Commit 31ba21d

Browse files
authored
Updated Go code generator & libraries
1 parent 619f1d3 commit 31ba21d

File tree

11 files changed

+181
-39
lines changed

11 files changed

+181
-39
lines changed

BasicExpression.java

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ else if (objectRef != null)
730730

731731
res.prestate = prestate;
732732
res.atTime = atTime;
733-
res.downcast = downcast;
733+
res.downcast = downcast;
734+
res.isStatic = isStatic;
734735
return res;
735736
}
736737

@@ -3227,7 +3228,8 @@ else if (objectRef.elementType != null && objectRef.elementType.isEntity())
32273228
}
32283229
}
32293230

3230-
if ("newOclDate".equals(data))
3231+
if ("newOclDate".equals(data) ||
3232+
"newOclDate_Time".equals(data))
32313233
{ type = new Type("OclDate", null);
32323234
umlkind = UPDATEOP;
32333235
isStatic = true;
@@ -3296,7 +3298,7 @@ else if (createdClass.startsWith("OclIterator_String"))
32963298
new Attribute("ss", new Type("String", null), ModelElement.INTERNAL);
32973299
par1.formalParameter = fparss;
32983300
}
3299-
}
3301+
} // and String_String
33003302

33013303
return true;
33023304
}
@@ -3570,7 +3572,8 @@ else if (isCall(oref.data))
35703572

35713573
if (staticent != null)
35723574
{ objectRef.umlkind = Expression.CLASSID;
3573-
3575+
// isStatic = true;
3576+
35743577
BehaviouralFeature bf = staticent.getStaticOperation(data,parameters);
35753578

35763579
if (bf != null)
@@ -3614,8 +3617,8 @@ else if (staticent.hasDefinedAttribute(data))
36143617

36153618
arrayType = type;
36163619
adjustTypeForArrayIndex(att);
3617-
// System.out.println("*** Type of " + data + " is static ATTRIBUTE in entity " +
3618-
// staticent + " type is " + type + "(" + elementType + ") Modality = " + modality);
3620+
System.out.println("*** Type of " + data + " is static ATTRIBUTE in entity " +
3621+
staticent + " type is " + type + "(" + elementType + ") Modality = " + modality);
36193622
return res;
36203623
}
36213624
}
@@ -14119,14 +14122,36 @@ public String cg(CGSpec cgs)
1411914122
Vector eargs = new Vector();
1412014123
Vector textrules = new Vector();
1412114124

14125+
if (("displayString".equals(data) ||
14126+
"displayint".equals(data) ||
14127+
"displaylong".equals(data) ||
14128+
"displaydouble".equals(data) ||
14129+
"displayboolean".equals(data) ||
14130+
"displaySequence".equals(data) ||
14131+
"displaySet".equals(data) ||
14132+
"displayMap".equals(data)) &&
14133+
parameters != null &&
14134+
parameters.size() == 1)
14135+
{ Expression par1 = (Expression) parameters.get(0);
14136+
args.add(par1.cg(cgs));
14137+
eargs.add(par1);
14138+
CGRule r = cgs.matchedBasicExpressionRule(this,etext,textrules);
14139+
if (r != null)
14140+
{ System.out.println(">> Matched rule: " + r + " to: " + etext + " with arguments= " + args);
14141+
String res = r.applyRule(args,eargs,cgs);
14142+
return res;
14143+
}
14144+
}
14145+
14146+
1412214147
if (umlkind == FUNCTION)
1412314148
{ // process as the corresponding unary or binary expression
1412414149
if ("allInstances".equals(data))
14125-
{ args.add(objectRef + "");
14126-
eargs.add(objectRef);
14127-
CGRule r = cgs.matchedBasicExpressionRule(this,etext,textrules);
14128-
if (r != null)
14129-
{ // System.out.println(">> Matched rule: " + r + " to: " + etext + " with arguments= " + args);
14150+
{ args.add(objectRef + "");
14151+
eargs.add(objectRef);
14152+
CGRule r = cgs.matchedBasicExpressionRule(this,etext,textrules);
14153+
if (r != null)
14154+
{ // System.out.println(">> Matched rule: " + r + " to: " + etext + " with arguments= " + args);
1413014155
String res = r.applyRule(args,eargs,cgs);
1413114156
return res;
1413214157
}
@@ -14244,7 +14269,13 @@ else if (objectRef != null)
1424414269
{ parg = parg + ","; }
1424514270
// need special processig for parameters
1424614271
} */
14247-
dataexp.parameters = null;
14272+
dataexp.parameters = null;
14273+
14274+
System.out.println(dataexp + " is static: " + dataexp.isStatic);
14275+
String dexcg = dataexp.cg(cgs);
14276+
System.out.println(dexcg);
14277+
System.out.println();
14278+
1424814279
args.add(dataexp.cg(cgs));
1424914280
args.add(pars);
1425014281
eargs.add(dataexp);

BehaviouralFeature.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,19 @@ public Statement extendBehaviour()
808808
public String cg(CGSpec cgs)
809809
{ String etext = this + "";
810810
Vector args = new Vector();
811-
args.add(getParameterisedName());
811+
args.add(getName());
812812
Vector eargs = new Vector();
813813
eargs.add(this);
814-
String pars = "";
815814

815+
String typePar = "";
816+
if (typeParameters != null && typeParameters.size() > 0)
817+
{ Type tp = (Type) typeParameters.get(0);
818+
typePar = tp.getName();
819+
args.add(typePar);
820+
eargs.add(tp);
821+
}
822+
823+
String pars = "";
816824
if (parameters == null) {}
817825
else if (parameters.size() == 0) {}
818826
else
@@ -879,7 +887,7 @@ else if (parameters.size() == 0) {}
879887

880888
CGRule r = cgs.matchedOperationRule(this,etext);
881889
if (r != null)
882-
{ // System.out.println(">>> Matched operation rule: " + r + " with args " + args);
890+
{ System.out.println(">>> Matched operation rule: " + r + " with args " + args);
883891
return r.applyRule(args,eargs,cgs);
884892
}
885893
System.out.println("!!! No matching rule for operation " + getName());

BinaryExpression.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,13 @@ else if (operator.equals("->restrict"))
39103910
{ type = new Type("Map", null); }
39113911
}
39123912

3913+
if (operator.equals("->append") ||
3914+
operator.equals("->prepend") ||
3915+
operator.equals("^"))
3916+
{ if (type == null)
3917+
{ type = new Type("Sequence", null); }
3918+
}
3919+
39133920
Type etleft = left.getElementType();
39143921
Type etright = right.getElementType();
39153922
Type maxtype = etleft;
@@ -3933,22 +3940,26 @@ else if (operator.equals("->including") ||
39333940
{ Type newleftET = Type.refineType(etleft,right.getType());
39343941
System.out.println(">> Deduced element type of " + this + " = " + newleftET);
39353942
elementType = newleftET;
3943+
if (type == null)
3944+
{ type = new Type("Sequence", null); }
39363945
type.setElementType(newleftET);
39373946
}
39383947
else if (operator.equals("->union") ||
39393948
operator.equals("^"))
39403949
{ Type newleftET = Type.refineType(etleft,etright);
39413950
System.out.println(">> Deduced element type of " + this + " = " + newleftET);
39423951
elementType = newleftET;
3943-
type.setElementType(newleftET);
3952+
if (type != null)
3953+
{ type.setElementType(newleftET); }
39443954
}
39453955
else if (etleft != null) // if classes, take closest common super
39463956
{ elementType = maxtype;
3947-
type.setElementType(elementType);
3957+
if (type != null)
3958+
{ type.setElementType(elementType); }
39483959
if (etright == null)
39493960
{ right.setElementType(etleft); }
39503961
} // should be the same
3951-
else if (etright != null)
3962+
else if (etright != null && type != null)
39523963
{ elementType = maxtype;
39533964
type.setElementType(elementType);
39543965
left.setElementType(etright);

CGCondition.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ else if (m instanceof ASTTerm &&
143143
else
144144
{ return false; }
145145

146-
System.out.println(">>> Condition " + cond + " is satisfied by " + m);
146+
System.out.println("||| Condition " + cond + " is satisfied by " + m);
147147
}
148148
}
149149
}
@@ -161,14 +161,19 @@ public boolean stereotypeConditionSatisfied(ModelElement m, Vector entities)
161161
}
162162

163163
public boolean conditionSatisfied(Type t, Vector entities)
164-
{ System.out.println(">> Checking type condition " + t + " " + stereotype);
164+
{ System.out.println("||| Checking type condition " + t + " " + stereotype);
165165
System.out.println();
166166

167167
if ("string".equals(stereotype.toLowerCase()) && t.isStringType())
168168
{ return positive; }
169169

170170
if ("class".equals(stereotype.toLowerCase()) && t.isEntityType(entities))
171-
{ System.out.println(">> Condition class satisfied for " + t);
171+
{ System.out.println("||| Condition class satisfied for " + t);
172+
return positive;
173+
}
174+
175+
if ("interface".equals(stereotype.toLowerCase()) && t.isInterfaceType(entities))
176+
{ System.out.println("||| Condition interface satisfied for " + t);
172177
return positive;
173178
}
174179

@@ -213,10 +218,16 @@ public boolean conditionSatisfied(Type t, Vector entities)
213218
{ return positive; }
214219

215220
if ("class".equals(stereotype.toLowerCase()) && !(t.isEntityType(entities)))
216-
{ System.out.println(t + " is not a class");
221+
{ System.out.println("||| " + t + " is not a class");
222+
return !positive;
223+
}
224+
225+
if ("interface".equals(stereotype.toLowerCase()) && !(t.isInterfaceType(entities)))
226+
{ System.out.println("||| " + t + " is not an interface");
217227
return !positive;
218228
}
219229

230+
220231
if ("void".equals(stereotype.toLowerCase()) && t != null && !t.isVoidType())
221232
{ return !positive; }
222233

@@ -258,6 +269,8 @@ public boolean conditionSatisfied(Type t, Vector entities)
258269

259270
public boolean conditionSatisfied(Attribute a, Vector entities)
260271
{ if ("primary".equals(stereotype.toLowerCase()) && a.isPrimaryAttribute())
272+
{ return positive; }
273+
if ("static".equals(stereotype.toLowerCase()) && a.isStatic())
261274
{ return positive; }
262275
if (a.hasStereotype(stereotype))
263276
{ return positive; }
@@ -299,7 +312,7 @@ public boolean conditionSatisfied(Expression e, Vector entities)
299312
String tname = "";
300313

301314
if (t == null)
302-
{ System.err.println("!! ERROR: null type in: " + e);
315+
{ System.err.println("!! WARNING: null type in: " + e);
303316
// return false;
304317
}
305318
else
@@ -465,6 +478,12 @@ else if ("StringRef".equals(stereotype))
465478
else
466479
{ return !(tname.equals("Ref") && etname.equals("String")); }
467480
}
481+
else if ("static".equals(stereotype))
482+
{ if (positive)
483+
{ return e.isStatic(); }
484+
else
485+
{ return !(e.isStatic()); }
486+
}
468487
else if (edata.equals(stereotype))
469488
{ return positive; }
470489
else // _i is T T is int, double, long, etc, or a enumeration or class name

CGRule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,12 @@ else if ("type".equals(mffeat) &&
595595
String repl = t.cg(cgs);
596596
res = replaceByMetafeatureValue(res,mf,repl);
597597
}
598+
else if ("name".equals(mffeat) &&
599+
obj instanceof Expression)
600+
{ Expression e = (Expression) obj;
601+
String repl = e + "";
602+
res = replaceByMetafeatureValue(res,mf,repl);
603+
}
598604
else if ("type".equals(mffeat) &&
599605
obj instanceof Attribute)
600606
{ Attribute att = (Attribute) obj;

0 commit comments

Comments
 (0)