Skip to content

Commit b477558

Browse files
authored
Extended MathApp
1 parent 6b39395 commit b477558

File tree

12 files changed

+170
-27
lines changed

12 files changed

+170
-27
lines changed

BasicExpression.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,7 +3680,7 @@ else if (objectRef.type != null &&
36803680
bf = e.getDefinedOperation(data,parameters);
36813681

36823682
if (bf != null)
3683-
{ System.out.println("**Type of " + data + " is operation, of class: " + e);
3683+
{ System.out.println("*>>* Type of " + data + " is operation, of class: " + e);
36843684
entity = e;
36853685
if (bf.parametersMatch(parameters)) { }
36863686
else
@@ -5464,12 +5464,13 @@ else if (objectRef.type != null && objectRef.type.isEntity(entities))
54645464
bf = e.getDefinedOperation(data,parameters);
54655465

54665466
if (bf != null)
5467-
{ System.out.println("**Type of " + data + " is operation, of: " + e);
5467+
{ System.out.println("** Type of " + data + " is operation, of: " + e);
54685468
entity = e;
54695469
if (bf.parametersMatch(parameters)) { }
54705470
else
5471-
{ JOptionPane.showMessageDialog(null, "Parameters do not match operation pars: " + this + " " + bf,
5472-
"Type warning", JOptionPane.WARNING_MESSAGE);
5471+
{ JOptionPane.showMessageDialog(null,
5472+
"Parameters do not match operation pars: " + this + " " + bf,
5473+
"Type warning", JOptionPane.WARNING_MESSAGE);
54735474
continue;
54745475
}
54755476

@@ -5517,7 +5518,8 @@ else if (e.getEventNames().contains(data))
55175518
return true;
55185519
} // else, downcast if in a subclass
55195520
else
5520-
{ Entity subent = e.searchForSubclassWithOperation(data);
5521+
{ Entity subent =
5522+
e.searchForSubclassWithOperation(data);
55215523
if (subent != null)
55225524
{ downcast = true;
55235525
entity = subent;
@@ -5532,7 +5534,8 @@ else if (e.getEventNames().contains(data))
55325534
{ umlkind = QUERY; }
55335535
else
55345536
{ umlkind = UPDATEOP;
5535-
if (type == null || type.equals("") || type.equals("void"))
5537+
if (type == null || type.equals("") ||
5538+
type.equals("void"))
55365539
{ type = new Type("boolean",null); }
55375540
}
55385541
setObjectRefType();
@@ -5594,8 +5597,16 @@ else if (objectRef != null)
55945597
}
55955598
umlkind = UPDATEOP;
55965599
}
5600+
5601+
// System.err.println("Operation " + data + " at call " + this + ".\n");
5602+
// System.out.println(">> " + objectRef + " of type: " + objectRef.type);
5603+
// type = new Type("boolean",null);
5604+
// elementType = new Type("boolean",null);
5605+
// umlkind = UPDATEOP;
5606+
// }
55975607
}
55985608

5609+
55995610
if (isFunction(data))
56005611
{ umlkind = FUNCTION;
56015612
if (objectRef == null) // error

BehaviouralFeature.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,20 +3043,39 @@ public Expression determinate(Vector arguments)
30433043
}
30443044

30453045
public boolean parametersMatch(Vector pars)
3046-
{ if (pars == null || parameters == null) { return false; }
3046+
{ if (pars == null || parameters == null)
3047+
{ return false; }
3048+
3049+
System.out.println(">>> For operation " + name + " actual parameters are " + pars + " formal parameters are " + parameters);
3050+
30473051
if (pars.size() == parameters.size())
30483052
{ return true; }
3053+
3054+
return false;
3055+
} // and check the types
3056+
3057+
public boolean parametersSupset(Vector pars)
3058+
{ if (pars == null || parameters == null)
3059+
{ return false; }
3060+
3061+
if (pars.size() < parameters.size())
3062+
{ return true; }
3063+
30493064
return false;
30503065
} // and check the types
30513066

30523067
public boolean parameterMatch(Vector pars)
3053-
{ if (pars == null || parameters == null) { return false; }
3068+
{ if (pars == null || parameters == null)
3069+
{ return false; }
30543070
if (pars.size() != parameters.size())
30553071
{ return false; }
30563072
for (int i = 0; i < parameters.size(); i++)
30573073
{ Attribute par = (Attribute) parameters.get(i);
30583074
Expression arg = (Expression) pars.get(i);
3059-
if (Type.isSubType(arg.getType(), par.getType())) { } // = or a subtype
3075+
if (par.getType() == null ||
3076+
Type.isVacuousType(par.getType())) { }
3077+
else if (par.getType().equals(arg.getType())) { }
3078+
else if (Type.isSubType(arg.getType(), par.getType())) { } // = or a subtype
30603079
else
30613080
{ return false; }
30623081
}
@@ -3065,12 +3084,28 @@ public boolean parameterMatch(Vector pars)
30653084
} // and check the types
30663085

30673086
public void setFormalParameters(Vector pars)
3068-
{ if (pars == null || parameters == null) { return; }
3069-
for (int i = 0; i < parameters.size() && i < pars.size(); i++)
3087+
{ if (pars == null || parameters == null)
3088+
{ return; }
3089+
3090+
Vector extrapars = new Vector();
3091+
3092+
for (int i = 0; i < parameters.size(); i++)
30703093
{ Attribute par = (Attribute) parameters.get(i);
3071-
Expression arg = (Expression) pars.get(i);
3072-
arg.formalParameter = par;
3094+
Type pt = par.getType();
3095+
3096+
if (i < pars.size())
3097+
{ Expression arg = (Expression) pars.get(i);
3098+
arg.formalParameter = par;
3099+
}
3100+
else
3101+
{ Expression nullInit =
3102+
Type.nullInitialValueExpression(pt);
3103+
nullInit.formalParameter = par;
3104+
extrapars.add(nullInit);
3105+
}
30733106
}
3107+
3108+
pars.addAll(extrapars);
30743109
} // Used in code generation, eg., for Swift.
30753110

30763111
public Expression substituteParameters(Expression e, Vector arguments)

Entity.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7148,8 +7148,9 @@ public BehaviouralFeature getOperation(String nme, Vector parameters)
71487148
{ BehaviouralFeature res = null;
71497149
for (int i = 0; i < operations.size(); i++)
71507150
{ res = (BehaviouralFeature) operations.get(i);
7151-
if (nme.equals(res.getName()) && res.parametersMatch(parameters))
7152-
{ return res; }
7151+
if (nme.equals(res.getName()) &&
7152+
res.parametersMatch(parameters))
7153+
{ return res; }
71537154
}
71547155

71557156
return getOperation(nme);
@@ -7185,17 +7186,28 @@ public BehaviouralFeature getDefinedOperation(String nme)
71857186
return null;
71867187
}
71877188

7188-
public BehaviouralFeature getDefinedOperation(String nme, Vector parameters)
7189+
public BehaviouralFeature getDefinedOperation(String nme,
7190+
Vector parameters)
71897191
{ BehaviouralFeature res = null;
71907192
for (int i = 0; i < operations.size(); i++)
71917193
{ res = (BehaviouralFeature) operations.get(i);
7192-
if (nme.equals(res.getName()) && res.parametersMatch(parameters))
7194+
if (nme.equals(res.getName()) &&
7195+
res.parametersMatch(parameters))
71937196
{ return res; }
71947197
}
71957198

7199+
for (int i = 0; i < operations.size(); i++)
7200+
{ res = (BehaviouralFeature) operations.get(i);
7201+
if (nme.equals(res.getName()) &&
7202+
res.parametersSupset(parameters))
7203+
{ System.out.println("!! There is no operation " + nme + " in class " + name + " with " + parameters.size() + " parameters,\n but there is an operation with " + res.getParameters().size() + " parameters -- the call needs to be extended.");
7204+
}
7205+
}
7206+
71967207
if (superclass != null)
71977208
{ return superclass.getDefinedOperation(nme,parameters); }
71987209

7210+
71997211
return null;
72007212
}
72017213

MathApp.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ else if (chr.length() > 0 &&
562562
{ inserting = true;
563563
insertedText = insertedText + chr.charAt(0);
564564
if ("Define".equals(insertedText))
565-
{ thisLabel.setText("Define variable: Define v, Define v = expr, Define v = instruction, Define v ~ distribution"); }
565+
{ thisLabel.setText("Define variable: Define v, Define v = expr, Define v : type, Define v : type = expr, Define v = instruction, Define v ~ distribution"); }
566566
else if ("Solve".equals(insertedText))
567567
{ thisLabel.setText("Solve single quadratic or differential equations, and multiple linear equations: Solve eqns for vars"); }
568568
else if ("Prove".equals(insertedText))
@@ -1182,13 +1182,13 @@ public void actionPerformed(ActionEvent e)
11821182
{
11831183
umlPane = new JEditorPane();
11841184
umlPane.setEditable(false);
1185-
umlPane.setSize(300,400);
1185+
umlPane.setSize(400,400);
11861186
int w = getWidth();
11871187
int h = getHeight();
11881188

11891189
getContentPane().add(new JScrollPane(umlPane),
11901190
java.awt.BorderLayout.EAST);
1191-
setSize(w + 300, h);
1191+
setSize(w + 400, h);
11921192
umlPane.setVisible(true);
11931193

11941194
java.awt.LayoutManager ll = getLayout();
@@ -1423,7 +1423,9 @@ public void actionPerformed(ActionEvent e)
14231423

14241424
helpPane.setText("Specifications contain these elements: \n\n" +
14251425
"1. Define clauses, with syntax one of\n" +
1426-
" Define var = expr\n" +
1426+
" Define var = expr\n" +
1427+
" Define var : type\n" +
1428+
" Define var : type = expr\n" +
14271429
" Define funcn(pars) = expr\n" +
14281430
" Define var = instruction\n" +
14291431
" Define var ~ distribution\n\n" +

Statement.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,56 @@ public static Statement replaceReturnBySkip(Statement st)
269269
return st;
270270
} // Other cases, for all other forms of statement.
271271

272+
public static Vector getLocalDeclarations(Statement st)
273+
{ Vector res = new Vector();
274+
if (st == null)
275+
{ return res; }
276+
277+
if (st instanceof SequenceStatement)
278+
{ SequenceStatement sq = (SequenceStatement) st;
279+
Vector stats = sq.getStatements();
280+
for (int i = 0; i < stats.size(); i++)
281+
{ if (stats.get(i) instanceof Statement)
282+
{ Statement stat = (Statement) stats.get(i);
283+
res.addAll(Statement.getLocalDeclarations(stat));
284+
}
285+
}
286+
return res;
287+
}
288+
289+
if (st instanceof CreationStatement)
290+
{ res.add(st);
291+
return res;
292+
}
293+
294+
if (st instanceof ConditionalStatement)
295+
{ ConditionalStatement cs = (ConditionalStatement) st;
296+
res.addAll(getLocalDeclarations(cs.ifPart()));
297+
res.addAll(getLocalDeclarations(cs.elsePart()));
298+
return res;
299+
}
300+
301+
if (st instanceof WhileStatement)
302+
{ WhileStatement ws = (WhileStatement) st;
303+
res.addAll(getLocalDeclarations(ws.getLoopBody()));
304+
return res;
305+
}
306+
307+
if (st instanceof TryStatement)
308+
{ TryStatement ts = (TryStatement) st;
309+
res.addAll(getLocalDeclarations(ts.getBody()));
310+
Vector stats = ts.getClauses();
311+
for (int i = 0; i < stats.size(); i++)
312+
{ if (stats.get(i) instanceof Statement)
313+
{ Statement stat = (Statement) stats.get(i);
314+
res.addAll(getLocalDeclarations(stat));
315+
}
316+
}
317+
res.addAll(getLocalDeclarations(ts.getEndStatement()));
318+
}
319+
320+
return res;
321+
} // Other cases, for all other forms of statement.
272322

273323
public static Vector getBreaksContinues(Statement st)
274324
{ Vector res = new Vector();

Type.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,6 +2868,15 @@ else if (nme.equals("int") || nme.equals("long"))
28682868
return res;
28692869
}
28702870

2871+
public static Expression nullInitialValueExpression(Type t)
2872+
{ if (t == null)
2873+
{ return new BasicExpression("null"); }
2874+
String tname = t.getName();
2875+
if (tname.equals("double"))
2876+
{ return new BasicExpression("Math_NaN"); }
2877+
return new BasicExpression("null");
2878+
}
2879+
28712880
public static Expression defaultInitialValueExpression(Type t)
28722881
{ if (t == null)
28732882
{ return new BasicExpression("null"); }

UmlTool.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,13 @@ public UmlTool()
949949
"Splits operation code into segments where possible");
950950
qualityMenu.add(splitSegmentsop);
951951

952+
JMenuItem hoistDecsop =
953+
new JMenuItem("Hoist local declarations");
954+
hoistDecsop.addActionListener(this);
955+
hoistDecsop.setToolTipText(
956+
"Hoists local declarations to start of operation code");
957+
qualityMenu.add(hoistDecsop);
958+
952959
JMenuItem refineMenu = new JMenu("Refinement");
953960
transMenu.add(refineMenu);
954961

UnaryExpression.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,7 +3784,10 @@ else if (Type.isMapType(argument.type))
37843784
{ return qf + ".trim()"; }
37853785

37863786
if (operator.equals("->oclIsUndefined"))
3787-
{ return "(" + qf + " == null)"; }
3787+
{ if (argument.isNumeric())
3788+
{ return "Double.isNaN((double) " + qf + ")"; }
3789+
return "(" + qf + " == null)";
3790+
}
37883791

37893792
if (operator.equals("->oclIsInvalid"))
37903793
{ return "Double.isNaN(" + qf + ")"; }
@@ -4081,7 +4084,10 @@ else if (argument instanceof UnaryExpression)
40814084
{ return qf + ".trim()"; }
40824085

40834086
if (operator.equals("->oclIsUndefined"))
4084-
{ return "(" + qf + " == null)"; }
4087+
{ if (argument.isNumeric())
4088+
{ return "Double.isNaN((double) " + qf + ")"; }
4089+
return "(" + qf + " == null)";
4090+
}
40854091

40864092
if (operator.equals("->oclIsInvalid"))
40874093
{ return "Double.isNaN(" + qf + ")"; }
@@ -4448,7 +4454,10 @@ else if (argument instanceof UnaryExpression)
44484454
{ return qf + ".trim()"; }
44494455

44504456
if (operator.equals("->oclIsUndefined"))
4451-
{ return "(" + qf + " == null)"; }
4457+
{ if (argument.isNumeric())
4458+
{ return "Double.isNaN((double) " + qf + ")"; }
4459+
return "(" + qf + " == null)";
4460+
}
44524461

44534462
if (operator.equals("->oclIsInvalid"))
44544463
{ return "Double.isNaN(" + qf + ")"; }
@@ -4821,7 +4830,10 @@ public String queryFormCSharp(java.util.Map env, boolean local)
48214830
{ return "((ArrayList) SystemTypes.characters(" + qf + "))"; }
48224831

48234832
if (operator.equals("->oclIsUndefined"))
4824-
{ return "(" + qf + " == null)"; }
4833+
{ if (argument.isNumeric())
4834+
{ return "double.IsNaN((double) " + qf + ")"; }
4835+
return "(" + qf + " == null)";
4836+
}
48254837

48264838
if (operator.equals("->oclIsInvalid"))
48274839
{ return "double.IsNaN(" + qf + ")"; }
@@ -5158,10 +5170,15 @@ public String queryFormCPP(java.util.Map env, boolean local)
51585170
{ return "UmlRsdsLib<int>::byte2char(" + qf + ")"; }
51595171

51605172
if (operator.equals("->oclIsUndefined"))
5161-
{ return "(" + qf + " == NULL)"; }
5173+
{ if (argument.isNumeric())
5174+
{ return "_isnan((double) " + qf + ")"; }
5175+
return "(" + qf + " == NULL)";
5176+
}
51625177

51635178
if (operator.equals("->oclIsNew"))
5164-
{ return "(" + qf + " != NULL)"; }
5179+
{
5180+
return "(" + qf + " != NULL)";
5181+
}
51655182

51665183
if (operator.equals("->oclIsInvalid"))
51675184
{ // return "std::isnan(" + qf + ")";

cg.zip

4 KB
Binary file not shown.

libraries.zip

605 KB
Binary file not shown.

0 commit comments

Comments
 (0)