Skip to content

Commit b5e7e79

Browse files
authored
Updated libraries and CSTL code
1 parent 523ff1f commit b5e7e79

File tree

11 files changed

+1038
-76
lines changed

11 files changed

+1038
-76
lines changed

ASTBasicTerm.java

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,98 @@ else if (Expression.isDouble(value))
555555
}
556556

557557

558+
/* JavaScript processing: */
559+
560+
public Expression jsexpressionToKM3(java.util.Map vartypes,
561+
java.util.Map varelemtypes, Vector types, Vector ents)
562+
{ if ("numericLiteral".equals(tag))
563+
{
564+
BasicExpression v = new BasicExpression(value);
565+
if (Expression.isInteger(value))
566+
{ v.setType(new Type("int",null));
567+
v.setUmlKind(Expression.VALUE);
568+
}
569+
else if (Expression.isLong(value))
570+
{ v.setType(new Type("long",null));
571+
v.setUmlKind(Expression.VALUE);
572+
}
573+
else if (Expression.isDouble(value))
574+
{ v.setType(new Type("double",null));
575+
v.setUmlKind(Expression.VALUE);
576+
}
577+
return v;
578+
}
579+
else if ("literal".equals(tag) ||
580+
"propertyName".equals(tag))
581+
{ if ("null".equals(value))
582+
{ return new BasicExpression("null"); }
583+
if ("true".equals(value))
584+
{ return new BasicExpression(true); }
585+
if ("false".equals(value))
586+
{ return new BasicExpression(false); }
587+
588+
BasicExpression v = new BasicExpression(value);
589+
if (Expression.isString(value))
590+
{ if ('\'' == value.charAt(0))
591+
{ BasicExpression ve = new BasicExpression("\"" + value.substring(1,value.length()-1) + "\"");
592+
ve.setType(new Type("String",null));
593+
ve.setUmlKind(Expression.VALUE);
594+
UnaryExpression res =
595+
new UnaryExpression("->char2byte", ve);
596+
res.setType(new Type("int", null));
597+
return res;
598+
}
599+
v.setType(new Type("String",null));
600+
v.setUmlKind(Expression.VALUE);
601+
return v;
602+
}
603+
}
604+
else if ("identifier".equals(tag))
605+
{ Type t = (Type) vartypes.get(value);
606+
if (t != null)
607+
{ BasicExpression be = new BasicExpression(value);
608+
be.setType(t);
609+
be.setElementType((Type) varelemtypes.get(value));
610+
return be;
611+
}
612+
613+
Entity mainC = (Entity) ModelElement.lookupByName(
614+
"FromC", ents);
615+
if (mainC != null)
616+
{ BehaviouralFeature bf = mainC.getOperation(value);
617+
618+
if (bf != null)
619+
{ System.out.println(">>> Function defined in main program: " + value + " " + bf.display() + " " + bf.isVarArg());
620+
BasicExpression bfcall =
621+
BasicExpression.newStaticCallBasicExpression(
622+
bf,mainC);
623+
Expression lam =
624+
UnaryExpression.newLambdaUnaryExpression(bfcall, bf);
625+
Type ftype = bf.getFunctionType();
626+
lam.setType(ftype);
627+
return lam;
628+
}
629+
630+
Attribute att = mainC.getAttribute(value);
631+
if (att != null)
632+
{ System.out.println(">>> Global attribute: " + value + " : " + att.getType());
633+
BasicExpression expr =
634+
BasicExpression.newStaticAttributeBasicExpression(
635+
att);
636+
expr.variable = att;
637+
return expr;
638+
}
639+
}
640+
641+
BasicExpression v = new BasicExpression(value);
642+
return v;
643+
}
644+
645+
return null;
646+
}
647+
648+
649+
/* Java processing */
558650

559651
public String queryForm()
560652
{ return toKM3(); }
@@ -567,7 +659,6 @@ public String toKM3()
567659
return "self";
568660
}
569661

570-
571662
if ("String".equals(value))
572663
{ modelElement = new Type("String", null);
573664
expression = new BasicExpression((Type) modelElement);

ASTCompositeTerm.java

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7949,7 +7949,118 @@ else if (bf != null)
79497949
}
79507950

79517951

7952+
/* JavaScript abstraction: */
79527953

7954+
public Expression jsexpressionToKM3(java.util.Map vartypes,
7955+
java.util.Map varelemtypes, Vector types, Vector entities)
7956+
{ System.out.println(">> cexpressionToKM3 for " + tag + " with " + terms.size() + " terms");
7957+
System.out.println();
7958+
7959+
if (terms.size() == 0)
7960+
{ return null; }
7961+
7962+
if (terms.size() == 1)
7963+
{ ASTTerm t1 = (ASTTerm) terms.get(0);
7964+
return t1.jsexpressionToKM3(
7965+
vartypes, varelemtypes, types, entities);
7966+
}
7967+
7968+
ASTTerm firstTerm = (ASTTerm) terms.get(0);
7969+
ASTTerm lastTerm = (ASTTerm) terms.get(terms.size()-1);
7970+
7971+
if ("singleExpression".equals(tag))
7972+
{ if (terms.size() == 3 && "(".equals(firstTerm + "") &&
7973+
")".equals(lastTerm + ""))
7974+
{ ASTTerm arg = (ASTTerm) terms.get(1);
7975+
Expression expr = arg.jsexpressionToKM3(vartypes,
7976+
varelemtypes,types,entities);
7977+
expr.setBrackets(true);
7978+
return expr;
7979+
}
7980+
}
7981+
7982+
if ("objectLiteral".equals(tag))
7983+
{ // JSON object literal --
7984+
// create a map
7985+
7986+
if (terms.size() == 2 && "{".equals(firstTerm + "") &&
7987+
"}".equals(lastTerm + ""))
7988+
{ // empty map
7989+
Expression expr = SetExpression.newMapSetExpression();
7990+
return expr;
7991+
}
7992+
7993+
if (terms.size() > 2 && "{".equals(firstTerm + "") &&
7994+
"}".equals(lastTerm + ""))
7995+
{ // non-empty map
7996+
SetExpression expr = SetExpression.newMapSetExpression();
7997+
for (int i = 1; i < terms.size()-1; i++)
7998+
{ ASTTerm tt = (ASTTerm) terms.get(i);
7999+
if (tt instanceof ASTSymbolTerm)
8000+
{ continue; }
8001+
8002+
Expression ttmaplet =
8003+
tt.jsexpressionToKM3(vartypes,
8004+
varelemtypes,types,entities);
8005+
expr.addElement(ttmaplet); // must be a maplet x |-> y
8006+
}
8007+
return expr;
8008+
}
8009+
}
8010+
8011+
if ("arrayLiteral".equals(tag))
8012+
{ // JSON array literal --
8013+
// create a sequence
8014+
8015+
if (terms.size() == 2 && "[".equals(firstTerm + "") &&
8016+
"]".equals(lastTerm + ""))
8017+
{ // empty sequence
8018+
Expression expr = new SetExpression(true);
8019+
return expr;
8020+
}
8021+
8022+
if (terms.size() == 3 && "[".equals(firstTerm + "") &&
8023+
"]".equals(lastTerm + ""))
8024+
{ // non-empty sequence
8025+
8026+
ASTCompositeTerm elems = (ASTCompositeTerm) terms.get(1);
8027+
Vector eterms = elems.getTerms();
8028+
8029+
SetExpression expr = new SetExpression(true);
8030+
for (int i = 0; i < eterms.size(); i++)
8031+
{ ASTTerm tt = (ASTTerm) eterms.get(i);
8032+
if (tt instanceof ASTSymbolTerm)
8033+
{ continue; }
8034+
8035+
Expression ttelem =
8036+
tt.jsexpressionToKM3(vartypes,
8037+
varelemtypes,types,entities);
8038+
expr.addElement(ttelem);
8039+
}
8040+
return expr;
8041+
}
8042+
}
8043+
8044+
if ("propertyAssignment".equals(tag) &&
8045+
terms.size() == 3 &&
8046+
":".equals(terms.get(1) + ""))
8047+
{ Expression ttlhs =
8048+
firstTerm.jsexpressionToKM3(vartypes,
8049+
varelemtypes,types,entities);
8050+
8051+
Expression ttrhs =
8052+
lastTerm.jsexpressionToKM3(vartypes,
8053+
varelemtypes,types,entities);
8054+
BinaryExpression res =
8055+
new BinaryExpression("|->", ttlhs, ttrhs);
8056+
return res;
8057+
}
8058+
8059+
return null;
8060+
}
8061+
8062+
8063+
/* Java abstraction: */
79538064

79548065
public boolean isAssignment()
79558066
{ if ("expression".equals(tag) && terms.size() == 3)
@@ -19894,7 +20005,7 @@ public boolean isIdentifier()
1989420005
}
1989520006

1989620007
public static void main(String[] args)
19897-
{ // Testing of C to KM3
20008+
{ // Testing of JS to KM3
1989820009

1989920010
BufferedReader br = null;
1990020011
Vector res = new Vector();
@@ -19946,14 +20057,18 @@ public static void main(String[] args)
1994620057
Vector v1 = new Vector();
1994720058
Vector v2 = new Vector();
1994820059

19949-
19950-
Statement stat = xx.cstatementToKM3(m1,m2,v1,v2);
20060+
Expression expr = xx.jsexpressionToKM3(m1,m2,v1,v2);
20061+
20062+
System.out.println(expr);
20063+
}
20064+
20065+
/* Statement stat = xx.cstatementToKM3(m1,m2,v1,v2);
1995120066
Entity fromC = new Entity("FromC");
1995220067
BehaviouralFeature bf = new BehaviouralFeature("op");
1995320068
bf.addStereotype("unsafe");
1995420069
bf.setActivity(stat);
1995520070
fromC.addOperation(bf);
19956-
v2.add(fromC);
20071+
v2.add(fromC); */
1995720072

1995820073
/* Type t = xx.cdeclarationToType(m1,m2,v1,v2);
1995920074
if (t != null && t.isEntity())
@@ -19967,7 +20082,7 @@ public static void main(String[] args)
1996720082
Vector mxs = ((ASTCompositeTerm) xx).cprogramToKM3(null,m1,m2,v1,v2); */
1996820083
// System.out.println(mx + "");
1996920084

19970-
for (int i = 0; i < v1.size(); i++)
20085+
/* for (int i = 0; i < v1.size(); i++)
1997120086
{ Type tt = (Type) v1.get(i);
1997220087
System.out.println(tt.getKM3());
1997320088
}
@@ -20006,6 +20121,6 @@ public static void main(String[] args)
2000620121
{ System.err.println("!! Error in file output/Program.cs ");
2000720122
_e.printStackTrace();
2000820123
}
20009-
}
20124+
} */
2001020125

2001120126
}

ASTSymbolTerm.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
180180
{ return new BasicExpression(symbol); }
181181

182182

183+
/* JavaScript abstraction: */
184+
185+
public Expression jsexpressionToKM3(java.util.Map vartypes,
186+
java.util.Map varelemtypes, Vector types, Vector ents)
187+
{ return new BasicExpression(symbol); }
188+
189+
190+
/* Java abstraction: */
183191

184192
public String queryForm()
185193
{ return toKM3(); }

0 commit comments

Comments
 (0)