Skip to content

Commit

Permalink
Extensions for Pascal abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Dec 27, 2023
1 parent a9069d3 commit 1ea233d
Show file tree
Hide file tree
Showing 18 changed files with 647 additions and 188 deletions.
15 changes: 11 additions & 4 deletions ASTBasicTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ else if (tok.equals(value))

Vector ents = new Vector();

if (r.satisfiesConditions(eargs,ents,cgs))
/* JOptionPane.showMessageDialog(null,
"Checking basic term rule " + r + " for " +
args + " " + eargs, "",
JOptionPane.INFORMATION_MESSAGE); */

if (r.satisfiesAllConditions(args,eargs,ents,cgs))
// r.satisfiesConditions(eargs,ents,cgs))
{ System.out.println(">>>> Applying basic term " + tag + " rule " + r + " for " + this);
return r.applyRule(args,eargs,cgs);
}
Expand Down Expand Up @@ -2948,9 +2954,10 @@ public void checkMathOCL()

Object val = ASTTerm.mathoclvars.get(vv);
if (val == null)
{ JOptionPane.showMessageDialog(null,
"Warning!: variable " + vv + " does not have a definition", "",
JOptionPane.WARNING_MESSAGE);
{ // JOptionPane.showMessageDialog(null,
// "Warning!: variable " + vv + " does not have a definition", "",
// JOptionPane.WARNING_MESSAGE);
System.err.println("!! Warning: " + vv + " has no definition");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ASTCompositeTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -28622,7 +28622,7 @@ else if ("range".equals(called) &&
selrng);
}

return callp1 + "->oclType().allInstances()->select( _xx | _xx >= " + callp1 + " & _xx <= " + callp2 + ")";
return "(" + callp1 + "->oclType()).allInstances()->select( _xx | _xx >= " + callp1 + " & _xx <= " + callp2 + ")";
}
else if ("keySet".equals(called) && arg.isMap())
{ ASTTerm.setType(thisliteral,"Set");
Expand Down
63 changes: 52 additions & 11 deletions ASTTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@ public static String getTaggedValue(ASTTerm trm, String str)
ASTTerm.metafeatures.put(lit,mfs);
}

JOptionPane.showMessageDialog(null,
"Looking up: " + str + " of: " + lit +
" in: " + ASTTerm.metafeatures, "",
JOptionPane.INFORMATION_MESSAGE);
// JOptionPane.showMessageDialog(null,
// "Looking up: " + str + " of: " + lit +
// " in: " + ASTTerm.metafeatures, "",
// JOptionPane.INFORMATION_MESSAGE);

// System.out.println("*** " + lit +
// " gets tagged values: " +
Expand All @@ -577,6 +577,23 @@ public static String getTaggedValue(ASTTerm trm, String str)
return null;
}

public static String getTaggedValue(String lit, String str)
{ Object mfs = ASTTerm.metafeatures.get(lit);

if (mfs instanceof Vector)
{ Vector stereotypes = (Vector) mfs;
for (int x = 0; x < stereotypes.size(); x++)
{ String stereo = (String) stereotypes.get(x);
if (stereo.startsWith(str + "=")) // or " ="
{ int indx = stereo.indexOf("=");
return stereo.substring(indx + 1);
}
}
}

return null;
}

public static String cgtlOperation(String opname, Vector eargs)
{ System.out.println(">>> External operation: " + opname + " on " + eargs);

Expand Down Expand Up @@ -940,7 +957,13 @@ public static String getElementType(ASTTerm t)


public boolean hasType(String str)
{ if ("character".equalsIgnoreCase(str))
{ String alit = literalForm();

/* JOptionPane.showMessageDialog(null,
"=== Testing " + alit + " has type " + str, "",
JOptionPane.INFORMATION_MESSAGE); */

if ("character".equalsIgnoreCase(str))
{ return isCharacter(); }
if ("integer".equalsIgnoreCase(str) ||
"int".equals(str))
Expand Down Expand Up @@ -979,6 +1002,15 @@ public boolean hasType(String str)
if ("Process".equals(str))
{ return isProcess(); }

if ("Entity".equals(str) ||
"Class".equals(str))
{ if (metafeatures != null)
{ Vector vv = (Vector) metafeatures.get(alit);
if (vv != null && vv.contains(str))
{ return true; }
}
}

String typ = ASTTerm.getType(this);
if (typ == null)
{ return false; }
Expand Down Expand Up @@ -4770,16 +4802,25 @@ public static Vector powersOf(
String v = var.literalForm();
String elit = expr.literalForm();

if (v.equals(elit))
if (v.equals(elit) ||
(v + "^{1}").equals(elit) ||
(v + "^{1.0}").equals(elit))
{ res.add(1);
return res;
}

if ((v + "^{2}").equals(elit))
if ((v + "^{2}").equals(elit) ||
(v + "^{2.0}").equals(elit))
{ res.add(2);
return res;
}

if ((v + "^{3}").equals(elit) ||
(v + "^{3.0}").equals(elit))
{ res.add(3);
return res;
}

if (expr instanceof ASTCompositeTerm)
{ // (factorExpression _1 * _2), etc

Expand Down Expand Up @@ -4851,8 +4892,8 @@ public static Vector powersOf(
ASTTerm pow = (ASTTerm) subterms.get(3);
String powlit = pow.literalForm();

if (AuxMath.isNumeric(powlit))
{ double powd = Double.parseDouble(powlit);
if (AuxMath.isGeneralNumeric(powlit))
{ double powd = AuxMath.parseGeneralNumeric(powlit);
if (v.equals(arg.literalForm()))
{ res.add(powd);
return res;
Expand Down Expand Up @@ -9307,12 +9348,12 @@ else if (maxdp == 1 && vdiffs.size() == 2 &&
String dd2cnst =
ASTTerm.constantTerms(dd2vars,expr0);

JOptionPane.showMessageDialog(null,
/* JOptionPane.showMessageDialog(null,
">>> Coeffiecient of square of : " + vdiff + " in " + expr0 +
" = " + dd2coef2 + " Of " + vdiff + " = " + dd2coef1 +
" Constant: " + dd2cnst,
"",
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.INFORMATION_MESSAGE); */

String quadf1 =
AuxMath.quadraticFormula1(dd2coef2, dd2coef1,
Expand Down
29 changes: 23 additions & 6 deletions Association.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ public void generateJava(PrintWriter out)
{ qual = "final ";
initialiser = "";
}

if (role2 != null) // attribute of entity1
{ if (entity1.isAbstract())
{ out.print(" protected " + qual); }
Expand All @@ -716,15 +717,21 @@ public void generateJava(PrintWriter out)

if (qualifier != null)
{ out.println("java.util.HashMap " + role2 + " = new java.util.HashMap();"); }
else if (card2 == ONE && entity2 != null &&
initialExpression != null)
{ java.util.HashMap env = new java.util.HashMap();
out.println(entity2.getName() + " " + role2 + " = " +
initialExpression + ";");
}
else if (card2 == ONE && entity2 != null)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else if (entity2 != null)
{ out.println("List " +
role2 + initialiser + "; // of " +
entity2.getName());
}
else
{ out.println("Object " + role2 + "; // Undefined class type"); }
else
{ out.println("Object " + role2 + "; // Undefined class type"); }
}
} // not valid for a..b a > 0. Should be array then?

Expand All @@ -750,6 +757,11 @@ public void generateJava6(PrintWriter out)

if (qualifier != null)
{ out.println("java.util.HashMap " + role2 + " = new java.util.HashMap();"); }
else if (card2 == ONE && initialExpression != null)
{ java.util.HashMap env = new java.util.HashMap();
out.println(entity2.getName() + " " + role2 + " = " +
initialExpression + ";");
}
else if (card2 == ONE)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else if (ordered)
Expand All @@ -772,10 +784,10 @@ public void generateJava7(PrintWriter out)
String initialiser = "";
String reltype = e2name;

if (card2 == ONE)
{ initialiser = " = null";
reltype = e2name;
}
if (card2 == ONE)
{ initialiser = " = null";
reltype = e2name;
}
else if (ordered)
{ initialiser = " = new ArrayList<" + e2name + ">()";
reltype = "ArrayList<" + e2name + ">";
Expand Down Expand Up @@ -807,6 +819,11 @@ else if (sortedAsc)
{ out.println("java.util.HashMap<String, " + reltype + "> " + role2 +
" = new java.util.HashMap<String, " + reltype + ">();");
}
else if (card2 == ONE && initialExpression != null)
{ java.util.HashMap env = new java.util.HashMap();
out.println(entity2.getName() + " " + role2 + " = " +
initialExpression + ";");
}
else if (card2 == ONE)
{ out.println(entity2.getName() + " " + role2 + ";"); }
else
Expand Down
12 changes: 12 additions & 0 deletions Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,20 @@ public boolean typeInference(Vector types, Vector entities,
Vector env = new Vector();
initialExpression.typeCheck(types,entities,cntx,env);

if (type != null && type.isAliasType())
{ type = type.getActualType();
elementType = type.getElementType();
}

System.out.println(">> Type of attribute: " + name + " is " + type + "(" + elementType + ")");

if (initialExpression.type != null &&
initialExpression.type.isAliasType())
{ initialExpression.type =
initialExpression.type.getActualType();
elementType = initialExpression.type.getElementType();
}

if (Type.isVacuousType(type) &&
!Type.isVacuousType(initialExpression.type))
{ type = initialExpression.type;
Expand Down
3 changes: 3 additions & 0 deletions AuxMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -2806,6 +2806,9 @@ public static boolean isGeneralNumeric(String val)
return true;
}

public static double parseGeneralNumeric(String val)
{ return AuxMath.generalNumericValue(val); }

public static double generalNumericValue(String val)
{ if (val.startsWith("(") &&
val.endsWith(")"))
Expand Down
52 changes: 52 additions & 0 deletions BinaryExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -4497,6 +4497,9 @@ else if (operator.equals("\\/") ||
operator.equals("/<:") ||
operator.equals("->excludesAll"))
{ // both are maps or both are collections
left.multiplicity = ModelElement.MANY;
right.multiplicity = ModelElement.MANY;

if (left.isMap() && !right.isMap())
{ System.err.println("!! RHS of " + this +
" must be map");
Expand Down Expand Up @@ -4551,6 +4554,36 @@ else if (!left.isCollection() && right.isCollection())
vartypes.put(vname, left.getType());
}
}
else
{ System.err.println("!! Arguments of " + this +
" must be collections");
Type ltype = left.getType();
if (ltype.getAlias() != null &&
ltype.getAlias().isCollectionType())
{ left.setType(ltype.getAlias());
right.setType(ltype.getAlias());
}
else
{ Type newsettype = new Type("Set", null);
newsettype.setElementType(new Type("OclAny", null));
left.setType(newsettype);
right.setType(newsettype);
}
type = left.getType();
elementType = left.getElementType();

if (left instanceof BasicExpression)
{ String vname =
((BasicExpression) left).basicString();
vartypes.put(vname, left.getType());
}

if (right instanceof BasicExpression)
{ String vname =
((BasicExpression) right).basicString();
vartypes.put(vname, right.getType());
}
}
}
else if (operator.equals("^") ||
"->concatenate".equals(operator))
Expand Down Expand Up @@ -5688,6 +5721,7 @@ else if ("Set".equals(tlname))
else
{ System.err.println("!! WARNING: unknown type for LHS of " + this);
type = new Type("Set",null);
elementType = new Type("OclAny", null);
}
}
else if (operator.equals("->union") || operator.equals("\\/"))
Expand Down Expand Up @@ -7519,6 +7553,24 @@ else if (left.hasSequenceType() && right.hasSequenceType())
return lqf;
}

if (operator.equals("\\/") ||
operator.equals("->union"))
{ if (left.isMap() || right.isMap())
{ res = "Ocl.unionMap(" + lqf + "," + rqf + ")"; }
else if (left.isOrdered() && right.isOrdered())
{ res = "Ocl.concatenate(" + lqf + ", " + rqf + ")"; }
else
{ res = "Ocl.union(" + lqf + "," + rqf + ")"; }
}

if (operator.equals("/\\") ||
operator.equals("->intersection"))
{ if (left.isMap() && right.isMap())
{ res = "Ocl.intersectionMap(" + lqf + "," + rqf + ")"; }
else
{ res = "Ocl.intersection(" + lqf + "," + rqf + ")"; }
}

if (extensionoperators.containsKey(operator))
{ String op = operator;
String opjava = Expression.getOperatorJava(op);
Expand Down
Loading

0 comments on commit 1ea233d

Please sign in to comment.