Skip to content

Commit 731cb52

Browse files
authored
Updated Go translator
1 parent 0bf6dc8 commit 731cb52

16 files changed

+398
-74
lines changed

ASTBasicTerm.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public void setTag(String t)
2626
public String getTag()
2727
{ return tag; }
2828

29+
public String tagFunction()
30+
{ return tag; }
31+
2932
public boolean hasTag(String tagx)
3033
{ return tagx.equals(tag); }
3134

ASTCompositeTerm.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ public boolean hasSingleTerm()
6262

6363
public int arity()
6464
{ return terms.size(); }
65+
66+
public String tagFunction()
67+
{ String res = "";
68+
for (int i = 0; i < terms.size(); i++)
69+
{ ASTTerm trm = (ASTTerm) terms.get(i);
70+
if (trm instanceof ASTSymbolTerm)
71+
{ if ("".equals(res))
72+
{ res = tag + "~"; }
73+
else
74+
{ res = res + "$" + tag + "~"; }
75+
}
76+
else
77+
{ String tstring = tag + "_" + trm.tagFunction();
78+
if ("".equals(res))
79+
{ res = tstring; }
80+
else
81+
{ res = res + "$" + tstring; }
82+
}
83+
}
84+
return res;
85+
}
6586

6687
public int nonSymbolArity()
6788
{ int res = 0;

ASTSymbolTerm.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public ASTSymbolTerm(String s)
1919
public String getTag()
2020
{ return symbol; }
2121

22+
public String tagFunction()
23+
{ return "~"; }
24+
2225
public boolean hasTag(String tagx)
2326
{ return false; }
2427

ASTTerm.java

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public abstract class ASTTerm
112112

113113
public abstract String literalForm();
114114

115+
public abstract String tagFunction();
116+
115117
public void addStereotype(String str)
116118
{ String lit = literalForm();
117119
Vector stereotypes =
@@ -1578,7 +1580,9 @@ public static Vector generateASTExamples(Vector javaASTs)
15781580

15791581
public static void entitiesFromASTs(Vector asts, String suff, Vector es)
15801582
{ // For each tag t, create entity t+suff. Add subclass for
1581-
// each different arity of t terms.
1583+
// each different arity of t terms.
1584+
// Nesting: (t (t1 x) (t2 y)) becomes
1585+
// t_t1$t_t2, etc.
15821586

15831587
Type treeType = new Type("OclAny", null);
15841588

@@ -1625,6 +1629,56 @@ public static void entitiesFromASTs(Vector asts, String suff, Vector es)
16251629
}
16261630
}
16271631

1632+
public static void deepEntitiesFromASTs(Vector asts, String suff, Vector es)
1633+
{ // For each different term t, create entity t' + suff.
1634+
// Nesting: (t (t1 x) (t2 y)) entity has name
1635+
// t_t1$t_t2, etc.
1636+
1637+
Type treeType = new Type("OclAny", null);
1638+
1639+
for (int i = 0; i < asts.size(); i++)
1640+
{ ASTTerm t = (ASTTerm) asts.get(i);
1641+
String tg = t.tagFunction() + suff;
1642+
String tgsup = t.getTag() + suff;
1643+
int n = t.arity();
1644+
if (n > 0)
1645+
{ Entity sup = (Entity) ModelElement.lookupByName(tgsup,es);
1646+
if (sup == null)
1647+
{ sup = new Entity(tgsup);
1648+
1649+
System.out.println("Created entity: " + sup);
1650+
1651+
if (suff.equals(""))
1652+
{ sup.addStereotype("source"); }
1653+
else
1654+
{ sup.addStereotype("target"); }
1655+
1656+
sup.setAbstract(true);
1657+
Attribute astatt =
1658+
new Attribute("ast", treeType, ModelElement.INTERNAL);
1659+
sup.addAttribute(astatt);
1660+
es.add(sup);
1661+
}
1662+
1663+
Entity ee = (Entity) ModelElement.lookupByName(tg,es);
1664+
if (ee == null)
1665+
{ ee = new Entity(tg);
1666+
1667+
System.out.println("Created entity: " + tg);
1668+
1669+
if (suff.equals(""))
1670+
{ ee.addStereotype("source"); }
1671+
else
1672+
{ ee.addStereotype("target"); }
1673+
1674+
ee.setSuperclass(sup);
1675+
sup.addSubclass(ee);
1676+
es.add(ee);
1677+
}
1678+
}
1679+
}
1680+
}
1681+
16281682
public static Vector entityMatchingsFromASTs(Vector sasts,
16291683
Vector tasts, Vector es)
16301684
{ // For corresponding s, t create entity matching
@@ -1640,7 +1694,7 @@ public static Vector entityMatchingsFromASTs(Vector sasts,
16401694
int m = t.arity();
16411695

16421696
if (n > 0 && m > 0)
1643-
{ String sentname = s.getTag() + "_" + n;
1697+
{ String sentname = s.tagFunction(); // Assume it is deep
16441698
Entity sent =
16451699
(Entity) ModelElement.lookupByName(sentname,es);
16461700
String tentname = t.getTag() + "$T_" + m;
@@ -1676,7 +1730,7 @@ public static void modelSpecificationFromASTs(Vector sasts,
16761730
int m = t.arity();
16771731

16781732
if (n > 0 && m > 0)
1679-
{ String sentname = s.getTag() + "_" + n;
1733+
{ String sentname = s.tagFunction();
16801734
String tentname = t.getTag() + "$T_" + m;
16811735
String sinst = sentname.toLowerCase() + "_" + i;
16821736
String tinst = tentname.toLowerCase() + "_" + i;
@@ -1745,6 +1799,24 @@ public static void main(String[] args)
17451799
// System.out.println(t.isInteger());
17461800
// System.out.println(t.isBoolean());
17471801

1802+
ASTBasicTerm tt1 = new ASTBasicTerm("t1", "aa");
1803+
ASTBasicTerm tt2 = new ASTBasicTerm("t2", "bb");
1804+
ASTSymbolTerm tts = new ASTSymbolTerm("&");
1805+
1806+
1807+
Vector vect = new Vector();
1808+
vect.add(tt1);
1809+
vect.add(tts);
1810+
vect.add(tt2);
1811+
1812+
ASTCompositeTerm ttc =
1813+
new ASTCompositeTerm("ct", vect);
1814+
1815+
System.out.println(ttc.tagFunction());
1816+
}
1817+
}
1818+
1819+
/*
17481820
Vector consts =
17491821
randomBasicASTTermsForTag("Const", 1, 50);
17501822
Vector ops = new Vector();
@@ -1944,8 +2016,9 @@ public static void main(String[] args)
19442016
catch (Exception _fex)
19452017
{ System.err.println("! No file: output/asts.txt"); }
19462018
1947-
}
1948-
}
2019+
} */
2020+
2021+
19492022

19502023
/* tree2tree dataset format: */
19512024

BasicExpression.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,12 @@ public Expression getParameter(int i)
10551055
return null;
10561056
}
10571057

1058+
public int arity()
1059+
{ if (parameters == null)
1060+
{ return 0; }
1061+
return parameters.size();
1062+
}
1063+
10581064
public String getData()
10591065
{ return data; }
10601066

CGSpec.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public void addCategoryRule(String category, CGRule r)
103103
{ Vector rules = (Vector) categoryRules.get(category);
104104
if (rules == null)
105105
{ rules = new Vector(); }
106+
if (rules.contains(r))
107+
{ return; }
106108
rules.add(r);
107109
categoryRules.put(category,rules);
108110
}
@@ -546,16 +548,16 @@ public void displayText(String str, PrintWriter out)
546548
for (int i = 0; i < n; i++)
547549
{ char x = str.charAt(i);
548550

549-
// if (x == '"' && !instring)
550-
// { instring = true; }
551-
// else if (x == '"' && instring)
552-
// { instring = false; }
551+
if (x == '"' && !instring)
552+
{ instring = true; }
553+
else if (x == '"' && instring)
554+
{ instring = false; }
553555

554-
if (x == '\n')
556+
if (x == '\n' && !instring)
555557
{ out.println(res);
556558
res = new StringBuffer();
557559
}
558-
else if (i < n-1 && x == '\\' && str.charAt(i+1) == 'n')
560+
else if (i < n-1 && x == '\\' && str.charAt(i+1) == 'n' && !instring)
559561
{ out.println(res);
560562
res = new StringBuffer();
561563
i++;

Compiler2.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,14 +4670,20 @@ public static String isKeywordOrPart(String st, String[] mess)
46704670

46714671
if ("operation".startsWith(st))
46724672
{ mess[0] = "Operation declaration:\noperation name(parameters) : Type\n" +
4673-
"pre: expression\npost: expression\nactivity: statement;";
4673+
"pre: expression\npost: expression\nactivity: statement;\n\n" +
4674+
"Or with a generic type parameter name T:\n" +
4675+
"operation name<T>(parameters) : Type\n" +
4676+
"pre: expression\npost: expression\nactivity: statement;\n";
46744677
return "operation";
46754678
}
46764679

46774680
if ("query".startsWith(st))
46784681
{ mess[0] = "Query operation declaration, returning a result value:\n" +
46794682
"query name(parameters) : Type\n" +
4680-
"pre: expression\npost: expression\nactivity: statement;";
4683+
"pre: expression\npost: expression\nactivity: statement;\n\n" +
4684+
"Or with a generic type parameter name T:\n" +
4685+
"query name<T>(parameters) : Type\n" +
4686+
"pre: expression\npost: expression\nactivity: statement;\n";;
46814687
return "query";
46824688
}
46834689

@@ -4784,7 +4790,8 @@ public static String isKeywordOrPart(String st, String[] mess)
47844790
}
47854791

47864792
if ("static".startsWith(st))
4787-
{ mess[0] = "static feature, ie., of class scope";
4793+
{ mess[0] = "static attribute or operation, ie., of class scope. Eg:\n" + "static attribute nobjs : int;\n" +
4794+
"static query pi() : double\npre: true post: result = 3.14159265\n";
47884795
return "static";
47894796
}
47904797

EntityMatching.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,21 @@ public class EntityMatching implements SystemTypes
3737
public EntityMatching(Entity asrc, Entity atrg)
3838
{ src = asrc;
3939
trg = atrg;
40-
srcname = src.getName();
41-
trgname = trg.getName();
40+
41+
if (src == null)
42+
{ System.err.println("!!! Null source in entity match to " + trg);
43+
return;
44+
}
45+
46+
if (trg == null)
47+
{ System.err.println("!!! Null target in entity match from " + src);
48+
return;
49+
}
50+
51+
if (src != null)
52+
{ srcname = src.getName(); }
53+
if (trg != null)
54+
{ trgname = trg.getName(); }
4255
realsrc = asrc;
4356
realtrg = atrg;
4457
}
@@ -1116,8 +1129,20 @@ public String getName()
11161129

11171130
public String toString()
11181131
{ String res = "";
1132+
String sname = "";
1133+
if (realsrc == null)
1134+
{ sname = ""; }
1135+
else
1136+
{ sname = realsrc.getName(); }
1137+
1138+
String tname = "";
1139+
if (realtrg == null)
1140+
{ tname = ""; }
1141+
else
1142+
{ tname = realtrg.getName(); }
1143+
11191144
if (condition == null)
1120-
{ res = realsrc.getName() + " |--> " + realtrg.getName(); }
1145+
{ res = sname + " |--> " + tname; }
11211146
else
11221147
{ res = "{ " + condition + " } " +
11231148
realsrc.getName() + " |--> " + realtrg.getName();
@@ -1131,6 +1156,7 @@ public String toString()
11311156
{ AttributeMatching am = (AttributeMatching) attributeMappings.get(i);
11321157
res = res + " " + am + "\n";
11331158
}
1159+
11341160
return res;
11351161
}
11361162

Expression.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public static String getCInputType(Type t)
171171
public int getUMLKind()
172172
{ return umlkind; }
173173

174+
public int arity()
175+
{ return 0; }
176+
174177
public static boolean isComparator(String opx)
175178
{ return comparitors.contains(opx); }
176179

0 commit comments

Comments
 (0)