Skip to content

Commit 6db9776

Browse files
authored
Updates to CGBE and UML2C
1 parent 573f0f1 commit 6db9776

19 files changed

+260
-37
lines changed

ASTBasicTerm.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,22 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
370370

371371
if ("EOF".equals(value))
372372
{ return new BasicExpression(-1); }
373+
374+
373375
if ("HUGE_VAL".equals(value))
374376
{ Expression resx =
375377
new BasicExpression("Math_PINFINITY");
376378
resx.setType(new Type("double", null));
377379
return resx;
378380
}
379381

382+
if ("NAN".equals(value))
383+
{ Expression resx =
384+
new BasicExpression("Math_NaN");
385+
resx.setType(new Type("double", null));
386+
return resx;
387+
}
388+
380389
if ("CHAR_BIT".equals(value))
381390
{ return new BasicExpression(8); }
382391
if ("CHAR_MAX".equals(value))

ASTCompositeTerm.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6955,6 +6955,15 @@ else if ("toupper".equals(fname) && args.size() == 1)
69556955
res.setType(new Type("int", null));
69566956
return res;
69576957
}
6958+
else if ("isnan".equals(fname) &&
6959+
args.size() == 1)
6960+
{ Expression arg1 = (Expression) args.get(0);
6961+
6962+
UnaryExpression res =
6963+
new UnaryExpression("->oclIsInvalid", arg1);
6964+
res.setType(new Type("boolean", null));
6965+
return res;
6966+
}
69586967
else if ("strcpy".equals(fname) && args.size() == 2)
69596968
{ Expression arg1 = (Expression) args.get(1);
69606969
arg1.setType(new Type("String", null));

ASTTerm.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public abstract class ASTTerm
7575
cqueryfunctions.add("isgraph");
7676
cqueryfunctions.add("isprint");
7777
cqueryfunctions.add("ispunct");
78-
cqueryfunctions.add("isxdigit");
78+
cqueryfunctions.add("isxdigit");
79+
cqueryfunctions.add("isnan");
7980
cqueryfunctions.add("calloc");
8081
cqueryfunctions.add("malloc");
8182
// cqueryfunctions.add("realloc");
@@ -1317,6 +1318,61 @@ public static boolean lowerNonSymbolArity(ASTTerm[] xs, ASTTerm[] ys)
13171318
return false;
13181319
}
13191320

1321+
public static Vector targetBrackets(ASTTerm[] xs, ASTTerm[] ys)
1322+
{ // Is each ys[i].terms starts with same symbol and
1323+
// ends with another or same symbol? Return these symbols
1324+
Vector res = new Vector();
1325+
String startSymbol = null;
1326+
String endSymbol = null;
1327+
1328+
if (ys.length > 1 && xs.length == ys.length)
1329+
{ for (int i = 0; i < xs.length; i++)
1330+
{ ASTTerm xx = xs[i];
1331+
ASTTerm yy = ys[i];
1332+
1333+
if (xx == null || yy == null)
1334+
{ return null; }
1335+
1336+
int n = xx.arity();
1337+
int m = yy.arity();
1338+
1339+
if (m < 2)
1340+
{ return null; }
1341+
1342+
// ASTTerm s0 = xx.getTerm(0);
1343+
// ASTTerm sn = xx.getTerm(n-1);
1344+
1345+
ASTTerm t0 = yy.getTerm(0);
1346+
ASTTerm tn = yy.getTerm(m-1);
1347+
1348+
if (t0 instanceof ASTSymbolTerm &&
1349+
tn instanceof ASTSymbolTerm)
1350+
{ if (startSymbol == null)
1351+
{ startSymbol = t0.literalForm(); }
1352+
else if (startSymbol.equals(t0.literalForm())) { }
1353+
else
1354+
{ return null; } // not consistent start symbols
1355+
1356+
if (endSymbol == null)
1357+
{ endSymbol = tn.literalForm(); }
1358+
else if (endSymbol.equals(tn.literalForm())) { }
1359+
else
1360+
{ return null; } // not consistent end symbols
1361+
}
1362+
else
1363+
{ return null; }
1364+
// Should also be different to s0, sn
1365+
}
1366+
1367+
if (startSymbol != null && endSymbol != null)
1368+
{ res.add(startSymbol);
1369+
res.add(endSymbol);
1370+
return res;
1371+
}
1372+
}
1373+
return null;
1374+
}
1375+
13201376

13211377
/*
13221378
public static boolean embeddedTrees(ASTTerm[] xs, ASTTerm[] ys, ModelSpecification mod)

BasicExpression.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,14 @@ public static void updateVariableType(Expression lhs, Expression rhs)
780780
{ if (lhs instanceof BasicExpression)
781781
{ BasicExpression be = (BasicExpression) lhs;
782782
if (be.variable != null)
783-
{ Type elemType = rhs.getElementType();
783+
{ Type elemType = rhs.getElementType();
784+
785+
System.out.println(">>> RHS element type: " + elemType);
786+
784787
Type oldElemType = be.variable.getElementType();
788+
789+
System.out.println(">>> old element type: " + oldElemType);
790+
785791
be.variable.setElementType(
786792
Type.refineType(oldElemType,elemType));
787793
System.out.println(">> From " + lhs + " := " + rhs + " deduced element type " + be.variable.getElementType() + " for " + be.data);
@@ -2091,7 +2097,7 @@ public String toAST()
20912097
{ res = res + " ( ";
20922098

20932099
if (parameters.size() > 0)
2094-
{ res = res + "(ParameterArgument "; }
2100+
{ res = res + " (ParameterArguments "; }
20952101

20962102
for (int i = 0; i < parameters.size(); i++)
20972103
{ res = res + ((Expression) parameters.get(i)).toAST();
@@ -2102,7 +2108,7 @@ public String toAST()
21022108
if (parameters.size() > 0)
21032109
{ res = res + " ) "; }
21042110

2105-
res = res + " )";
2111+
res = res + " ) ";
21062112
}
21072113

21082114
if (arrayIndex != null)
@@ -2255,7 +2261,7 @@ else if (type != null && type.elementType != null)
22552261
out.println(res + ".elementType = " + tet);
22562262
}
22572263
else
2258-
{ System.err.println("Warning!: no element type for " + this);
2264+
{ System.err.println("!!! Warning!: no element type for " + this);
22592265
out.println(res + ".elementType = " + tname);
22602266
}
22612267

@@ -3126,6 +3132,8 @@ public boolean typeCheck(final Vector types, final Vector entities,
31263132
"OclDate".equals(data) || "OclAny".equals(data) ||
31273133
"OclType".equals(data) || "OclFile".equals(data) ||
31283134
"OclRandom".equals(data) ||
3135+
"OclAttribute".equals(data) ||
3136+
"OclOperation".equals(data) ||
31293137
Type.isOclExceptionType(data) ||
31303138
"OclProcess".equals(data) ||
31313139
"OclProcessGroup".equals(data))
@@ -3239,6 +3247,7 @@ else if (objectRef.elementType != null && objectRef.elementType.isEntity())
32393247
{ type = new Type("OclDate", null);
32403248
umlkind = UPDATEOP;
32413249
isStatic = true;
3250+
entity = (Entity) ModelElement.lookupByName("OclDate",entities);
32423251
multiplicity = ModelElement.ONE;
32433252
// set the formal parameters
32443253
if (parameters != null && parameters.size() > 0)
@@ -3332,16 +3341,21 @@ else if (createdClass.startsWith("OclIterator_String"))
33323341
{ type = new Type("long", null);
33333342
umlkind = ATTRIBUTE;
33343343
multiplicity = ModelElement.ONE;
3335-
3344+
entity = (Entity) ModelElement.lookupByName("OclDate",entities);
3345+
33363346
return true;
33373347
}
33383348
}
33393349

33403350
if ("getSystemTime".equals(data) && "OclDate".equals(objectRef + ""))
33413351
{ type = new Type("long", null);
33423352
umlkind = QUERY;
3343-
isStatic = true;
3353+
isStatic = true;
3354+
entity = (Entity) ModelElement.lookupByName("OclDate",entities);
3355+
33443356
multiplicity = ModelElement.ONE;
3357+
entity =
3358+
(Entity) ModelElement.lookupByName("OclDate",entities);
33453359

33463360
return true;
33473361
}
@@ -3352,7 +3366,8 @@ else if (createdClass.startsWith("OclIterator_String"))
33523366
objectRef.type.getName().equals("OclDate"))
33533367
{ umlkind = QUERY;
33543368
multiplicity = ModelElement.ONE;
3355-
type = new Type("long", null);
3369+
type = new Type("long", null);
3370+
entity = (Entity) ModelElement.lookupByName("OclDate",entities);
33563371
return true;
33573372
}
33583373
}
@@ -3364,6 +3379,8 @@ else if (createdClass.startsWith("OclIterator_String"))
33643379
{ type = new Type("void", null);
33653380
umlkind = UPDATEOP;
33663381
multiplicity = ModelElement.ONE;
3382+
entity =
3383+
(Entity) ModelElement.lookupByName("OclDate",entities);
33673384
// set the formal parameters
33683385
if (parameters != null && parameters.size() > 0)
33693386
{ Expression par1 = (Expression) parameters.get(0);
@@ -3383,7 +3400,8 @@ else if (createdClass.startsWith("OclIterator_String"))
33833400
objectRef.type.getName().equals("OclDate"))
33843401
{ type = new Type("boolean", null);
33853402
umlkind = QUERY;
3386-
multiplicity = ModelElement.ONE;
3403+
multiplicity = ModelElement.ONE;
3404+
entity = (Entity) ModelElement.lookupByName("OclDate",entities);
33873405
// set the formal parameters
33883406
if (parameters != null && parameters.size() > 0)
33893407
{ Expression par1 = (Expression) parameters.get(0);
@@ -3403,7 +3421,9 @@ else if (createdClass.startsWith("OclIterator_String"))
34033421
objectRef.type.getName().equals("OclDate"))
34043422
{ type = new Type("boolean", null);
34053423
umlkind = QUERY;
3406-
multiplicity = ModelElement.ONE;
3424+
multiplicity = ModelElement.ONE;
3425+
entity =
3426+
(Entity) ModelElement.lookupByName("OclDate",entities);
34073427
if (parameters != null && parameters.size() > 0)
34083428
{ Expression par1 = (Expression) parameters.get(0);
34093429
Attribute fpar1 = new Attribute("d",
@@ -3851,8 +3871,10 @@ else if (data.equals("size") || data.equals("floor") || data.equals("count") ||
38513871
{ type = new Type("int",null);
38523872
elementType = type;
38533873
}
3854-
else if (data.equals("sort") || data.equals("characters") ||
3855-
data.equals("sortedBy") || data.equals("asSequence") ||
3874+
else if (data.equals("sort") ||
3875+
data.equals("characters") ||
3876+
data.equals("sortedBy") ||
3877+
data.equals("asSequence") ||
38563878
data.equals("allInstances"))
38573879
{ type = new Type("Sequence",null);
38583880
elementType = objectRef.elementType;
@@ -3910,6 +3932,7 @@ else if (data.equals("reverse") ||
39103932
data.equals("tail") ||
39113933
data.equals("front") ||
39123934
data.equals("insertAt") ||
3935+
data.equals("insertInto") ||
39133936
data.equals("setAt"))
39143937
{ type = objectRef.getType(); // Sequence or String
39153938
elementType = objectRef.elementType;
@@ -4507,7 +4530,8 @@ else if (resType == null || resType.typeMultiplicity() == ModelElement.ONE)
45074530
private void adjustTypeForArrayIndex()
45084531
{ // if there is an arrayIndex, make type = elementType, etc
45094532

4510-
if (arrayIndex != null && "String".equals(type + ""))
4533+
if (arrayIndex != null && type != null &&
4534+
"String".equals(type.getName()))
45114535
{ elementType = new Type("String", null);
45124536
multiplicity = ModelElement.ONE;
45134537
}

BehaviouralFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,7 @@ public String toAST()
30993099
res = res + getName() + tpars + " ( ";
31003100

31013101
if (parameters != null && parameters.size() > 0)
3102-
{ res = res + "(OclParameterList ";
3102+
{ res = res + " (OclParameterList ";
31033103
for (int i = 0; i < parameters.size(); i++)
31043104
{ Attribute par = (Attribute) parameters.get(i);
31053105
String pnme = par.toASTParameter();

BinaryExpression.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,13 +3445,15 @@ else if (type.getElementType() != null)
34453445
{ elementType = left.getElementType(); }
34463446
}
34473447
else if ("->at".equals(operator))
3448-
{ if ("String".equals(left.type + ""))
3448+
{ if (left.type != null && "String".equals(left.type.getName()))
34493449
{ type = new Type("String", null);
34503450
elementType = type;
34513451
}
34523452
else
34533453
{ type = left.elementType;
3454-
if (type != null)
3454+
if (type != null && "String".equals(type.getName()))
3455+
{ elementType = type; }
3456+
else if (type != null)
34553457
{ elementType = type.getElementType(); }
34563458
else
34573459
{ Attribute leftvar = (Attribute) ModelElement.lookupByName(left + "", env);

Compiler2.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,12 +4805,17 @@ public static String isKeywordOrPart(String st, String[] mess)
48054805

48064806

48074807
if ("String".startsWith(st))
4808-
{ mess[0] = "String type. Empty string is \"\"\nOperators include: s->size() s1 + s2 s1->indexOf(s2) s->at(index) s->display() s->tail() s->first()\ns.subrange(i,j) s.subrange(i) s->isMatch(pattern) s->allMatches(patt) s->trim()\n";
4808+
{ mess[0] = "String type String. Empty string is \"\"\n" +
4809+
"Operators include: s->size() s1 + s2 s1->indexOf(s2) s->at(index)\n" +
4810+
"s->display() s->tail() s->first()\n" +
4811+
"s.subrange(i,j) s.subrange(i) s.setAt(i,ch)\n" +
4812+
"s->isMatch(pattern) s->allMatches(patt) s->trim()\n";
48094813
return "String";
48104814
}
48114815

48124816
if ("int".startsWith(st))
4813-
{ mess[0] = "32-bit integer type, from -(2->pow(31)) to 2->pow(31)-1\n" +
4817+
{ mess[0] = "32-bit integer type int,\n" +
4818+
"ranges from -(2->pow(31)) to 2->pow(31)-1\n" +
48144819
"Operators include: x mod y x div y\n" +
48154820
"and usual arithmetic operators * / - + < <= > >= = /= etc";
48164821
return "int";
@@ -5084,7 +5089,8 @@ public static String isKeywordOrPart(String st, String[] mess)
50845089

50855090

50865091
if ("long".startsWith(st))
5087-
{ mess[0] = "64-bit integer type, from -(2->pow(63)) to (2->pow(63)-1)\n" +
5092+
{ mess[0] = "64-bit integer type long,\n" +
5093+
"ranges from -(2->pow(63)) to (2->pow(63)-1)\n" +
50885094
"Operators include: x mod y x div y\n" +
50895095
"and usual arithmetic operators * / - + < <= > >= = /= etc";
50905096

@@ -5093,7 +5099,9 @@ public static String isKeywordOrPart(String st, String[] mess)
50935099

50945100

50955101
if ("boolean".startsWith(st))
5096-
{ mess[0] = "Boolean-values type, values are true and false\nOperators include: b1 & b2 b1 or b2 not(b) b1 => b2";
5102+
{ mess[0] = "Boolean-values type boolean,\n" +
5103+
"values are true and false\n" +
5104+
"Operators include: b1 & b2 b1 or b2 not(b) b1 => b2";
50975105
return "boolean";
50985106
}
50995107

Entity.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8518,12 +8518,12 @@ else if (interfaces.size() > 0)
85188518
if (Entity.isEmptyClass(this))
85198519
{ res = res + " " + nme + " { "; }
85208520
else
8521-
{ res = res + " " + nme + " (OclClassContents { "; }
8521+
{ res = res + " " + nme + " { (OclClassContents "; }
85228522

8523-
for (int i = 0; i < stereotypes.size(); i++)
8524-
{ String stereo = (String) stereotypes.get(i);
8525-
res = res + " stereotype " + stereo + " ; ";
8526-
}
8523+
// for (int i = 0; i < stereotypes.size(); i++)
8524+
// { String stereo = (String) stereotypes.get(i);
8525+
// res = res + " stereotype " + stereo + " ; ";
8526+
// }
85278527

85288528
for (int i = 0; i < invariants.size(); i++)
85298529
{ Constraint con = (Constraint) invariants.get(i);
@@ -8553,10 +8553,10 @@ else if (interfaces.size() > 0)
85538553
if (Entity.isEmptyClass(this))
85548554
{ res = res + " } )"; }
85558555
else
8556-
{ res = res + " } ) )"; }
8556+
{ res = res + " ) } )"; }
85578557

85588558
return res;
8559-
} // and operations
8559+
}
85608560

85618561

85628562
public String stereotypesKM3()

KM3Editor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public KM3Editor(UCDArea parent, Vector ents, Vector ucs)
100100
}
101101

102102
JScrollPane scrollPane = new JScrollPane(textPane);
103-
scrollPane.setPreferredSize(new Dimension(100, 300));
103+
scrollPane.setPreferredSize(new Dimension(150, 300));
104104

105-
messageArea = new JTextArea(20, 35);
105+
messageArea = new JTextArea(15, 45);
106106
messageArea.setEditable(false);
107107
JScrollPane scrollPaneForLog = new JScrollPane(messageArea);
108108

0 commit comments

Comments
 (0)