Skip to content

Commit 36bd52b

Browse files
authored
Updated C code generator
1 parent 1588190 commit 36bd52b

12 files changed

+6851
-15
lines changed

ASTTerm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public static TypeMatching createNewFunctionalMapping(String name, ASTTerm[] str
794794

795795
// If an identity mapping, return _1 |-->_1
796796

797-
// A "default" case _1 |--> v is included where v is the
797+
// A "default" case _* |--> v is included where v is the
798798
// most frequent target of different source values.
799799

800800
Type str = new Type("String", null);
@@ -834,13 +834,13 @@ public static TypeMatching createNewFunctionalMapping(String name, ASTTerm[] str
834834
}
835835
}
836836

837-
System.out.println(">> Default mapping is _1 |-->" + defaultValue);
837+
System.out.println(">> Default mapping is _* |-->" + defaultValue);
838838

839839

840840
tm.setStringValues(sattvalues,tattvalues);
841841

842842
if (defaultValue != null)
843-
{ tm.addDefaultMapping("_1", defaultValue); }
843+
{ tm.addDefaultMapping("_*", defaultValue); }
844844

845845
return tm;
846846
}

CGCondition.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,9 @@ public boolean conditionSatisfied(Statement e, Vector entities)
507507
} // and for other kinds of statement also
508508

509509
public boolean conditionSatisfied(ASTTerm a, Vector entities)
510-
{ if (a instanceof ASTCompositeTerm)
510+
{ String alit = a.literalForm();
511+
512+
if (a instanceof ASTCompositeTerm)
511513
{ ASTCompositeTerm ac = (ASTCompositeTerm) a;
512514

513515
if (ac.tag.equalsIgnoreCase(stereotype))
@@ -534,6 +536,13 @@ else if (a instanceof ASTSymbolTerm)
534536
return positive;
535537
}
536538

539+
if ("Class".equals(stereotype))
540+
{ if (Type.isOclEntityType(alit,entities))
541+
{ return positive; }
542+
else
543+
{ return !positive; }
544+
}
545+
537546
if ("updatesObject".equals(stereotype))
538547
{ if (a.updatesObject(null))
539548
{ return positive; }

Compiler2.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,6 +3767,10 @@ public ASTTerm parseGeneralAST(String xstring)
37673767

37683768
public ASTTerm parseGeneralAST(int st, int en)
37693769
{ ASTTerm res = null;
3770+
3771+
if (lexicals == null || lexicals.size() == 0)
3772+
{ return res; }
3773+
37703774
String lex = lexicals.get(st) + "";
37713775

37723776
if (st == en)
@@ -9121,6 +9125,13 @@ public static void main(String[] args)
91219125
// Statement stat = c.parseStatement();
91229126
// System.out.println(stat);
91239127

9128+
Compiler2 comp = new Compiler2();
9129+
Vector vv = new Vector();
9130+
comp.nospacelexicalanalysis("x <>= y");
9131+
Expression tt = comp.parseExpression(vv,vv);
9132+
9133+
System.out.println(tt);
9134+
91249135
// c = new Compiler2();
91259136

91269137
// c.nospacelexicalanalysis("i < v->size() & i < w->size()");

ConditionalExpression.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ public String toString()
579579
}
580580

581581
public String toAST()
582-
{ String res = "(ConditionalExpression if " + test.toAST() + " then " + ifExp.toAST() + " else " + elseExp.toAST() + " endif )";
583-
if (needsBracket)
584-
{ res = "(BracketedExpression ( " + res + " ) )"; }
582+
{ String res = "(OclConditionalExpression if " + test.toAST() + " then " + ifExp.toAST() + " else " + elseExp.toAST() + " endif )";
583+
// if (needsBracket)
584+
// { res = "(BracketedExpression ( " + res + " ) )"; }
585585
return res;
586586
}
587587

Expression.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,12 +1564,13 @@ public static boolean isOclBinaryInfix(Expression expr)
15641564
String op = ue.getOperator();
15651565
if ("+".equals(op) || "-".equals(op) ||
15661566
"*".equals(op) || "&".equals(op) ||
1567-
"^".equals(op) ||
1567+
"^".equals(op) || "<>=".equals(op) ||
15681568
"/".equals(op) || "div".equals(op) ||
15691569
"mod".equals(op) || "and".equals(op) ||
15701570
"or".equals(op) || "xor".equals(op) ||
15711571
"<".equals(op) || "<=".equals(op) ||
15721572
"=".equals(op) || "/=".equals(op) ||
1573+
"=>".equals(op) ||
15731574
">".equals(op) || ">=".equals(op))
15741575
{ return true; }
15751576
if (op.startsWith("->"))

SetExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ else if (ordered)
215215
}
216216

217217
public String toAST()
218-
{ String res = "(OclSetExpression ";
218+
{ String res = "(OclCollectionExpression ";
219219

220220
if (type != null && "Ref".equals(type.getName()))
221221
{ res = "Ref { "; }
@@ -231,7 +231,7 @@ else if (ordered)
231231
return res;
232232
}
233233

234-
res = res + " (ElementList ";
234+
res = res + " (OclElementList ";
235235

236236
for (int i = 0; i < elements.size(); i++)
237237
{ Expression elem = (Expression) elements.get(i);

Type.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,21 @@ public boolean isEntityType(Vector ents)
159159
Entity ex = (Entity) ModelElement.lookupByName(name, ents);
160160
if (ex != null)
161161
{ return true; }
162-
if ("OclType".equals(name) || "OclAny".equals(name) ||
163-
"OclProcess".equals(name) ||
164-
"OclFile".equals(name) || "OclRandom".equals(name))
162+
if (isOclClassifierType(name))
165163
{ return true; }
166164
return false;
167165
}
168166

167+
public static boolean isOclEntityType(String tname, Vector ents)
168+
{ Entity ex = (Entity) ModelElement.lookupByName(tname, ents);
169+
if (ex != null)
170+
{ return true; }
171+
if (isOclClassifierType(tname))
172+
{ return true; }
173+
return false;
174+
}
175+
176+
169177
public boolean isInterfaceType(Vector ents)
170178
{ if (entity != null && entity.isInterface())
171179
{ return true; }
@@ -2074,9 +2082,19 @@ public static boolean isClassifierType(Type e)
20742082
{ if (e == null)
20752083
{ return false; }
20762084
String estr = e + "";
2085+
return isOclClassifierType(estr);
2086+
}
2087+
2088+
public static boolean isOclClassifierType(String estr)
2089+
{
20772090
if ("String".equals(estr) || "OclDate".equals(estr) ||
20782091
"OclAny".equals(estr) || "OclType".equals(estr) ||
2079-
"OclProcess".equals(estr) || "OclFile".equals(estr) ||
2092+
"OclAttribute".equals(estr) ||
2093+
"OclOperation".equals(estr) ||
2094+
"OclProcess".equals(estr) ||
2095+
"OclProcessGroup".equals(estr) ||
2096+
isExceptionType(estr) ||
2097+
"OclFile".equals(estr) ||
20802098
"OclRandom".equals(estr))
20812099
{ return true; }
20822100
return false;

UCDArea.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12765,7 +12765,7 @@ public void testCSTLwithASTS()
1276512765
if (xx == null)
1276612766
{ System.err.println("!!ERROR: Invalid text for general AST at line " + noflines + ":");
1276712767
System.err.println(c.lexicals);
12768-
return;
12768+
// return;
1276912769
}
1277012770
else
1277112771
{ res.add(xx); }

0 commit comments

Comments
 (0)