Skip to content

Commit f71dc38

Browse files
authored
Updated executable, libraries & code generators
1 parent c142a66 commit f71dc38

File tree

9 files changed

+343
-45
lines changed

9 files changed

+343
-45
lines changed

ASTCompositeTerm.java

Lines changed: 158 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,10 @@ else if (t2.hasTag("pointer"))
22972297
{ // (structOrUnion struct) name
22982298
ASTTerm structOrunion = (ASTTerm) terms.get(0);
22992299
String sname = ((ASTTerm) terms.get(1)).literalForm();
2300+
2301+
if (sname.equals("tm"))
2302+
{ sname = "OclDate"; }
2303+
23002304
Entity ent =
23012305
(Entity) ModelElement.lookupByName(sname,entities);
23022306
if (ent == null)
@@ -4472,6 +4476,55 @@ else if ("++".equals(lex) || "--".equals(lex))
44724476
}
44734477

44744478

4479+
public BasicExpression cFieldApplication(Expression obj,
4480+
String f)
4481+
{ if ("tm_sec".equals(f))
4482+
{ return
4483+
BasicExpression.newQueryCallBasicExpression(
4484+
"getSecond",obj);
4485+
}
4486+
4487+
if ("tm_min".equals(f))
4488+
{ return
4489+
BasicExpression.newQueryCallBasicExpression(
4490+
"getMinute",obj);
4491+
}
4492+
4493+
if ("tm_hour".equals(f))
4494+
{ return
4495+
BasicExpression.newQueryCallBasicExpression(
4496+
"getHour",obj);
4497+
}
4498+
4499+
if ("tm_mday".equals(f))
4500+
{ return
4501+
BasicExpression.newQueryCallBasicExpression(
4502+
"getDate",obj);
4503+
}
4504+
4505+
if ("tm_mon".equals(f))
4506+
{ return
4507+
BasicExpression.newQueryCallBasicExpression(
4508+
"getMonth",obj);
4509+
}
4510+
4511+
if ("tm_year".equals(f))
4512+
{ return
4513+
BasicExpression.newQueryCallBasicExpression(
4514+
"getYear",obj);
4515+
}
4516+
4517+
if ("tm_wday".equals(f))
4518+
{ return
4519+
BasicExpression.newQueryCallBasicExpression(
4520+
"getDay",obj);
4521+
}
4522+
4523+
return BasicExpression.newAttributeBasicExpression(
4524+
f, obj);
4525+
}
4526+
4527+
44754528
public Expression cexpressionToKM3(java.util.Map vartypes,
44764529
java.util.Map varelemtypes, Vector types, Vector entities)
44774530
{ System.out.println(">> cexpressionToKM3 for " + tag + " with " + terms.size() + " terms");
@@ -4688,11 +4741,10 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
46884741
".".equals(terms.get(1) + ""))
46894742
{ // t1.f
46904743
ASTTerm t1 = (ASTTerm) terms.get(0);
4691-
Expression obj = t1.cexpressionToKM3(
4744+
String f = terms.get(2) + "";
4745+
Expression obj = t1.cexpressionToKM3(
46924746
vartypes, varelemtypes, types, entities);
4693-
BasicExpression res =
4694-
BasicExpression.newAttributeBasicExpression(
4695-
terms.get(2) + "", obj);
4747+
BasicExpression res = cFieldApplication(obj,f);
46964748
return res;
46974749
}
46984750

@@ -4741,13 +4793,19 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
47414793
"->".equals(terms.get(1) + ""))
47424794
{ // (!t1).f
47434795
ASTTerm t1 = (ASTTerm) terms.get(0);
4744-
BasicExpression res = new BasicExpression(terms.get(2) + "");
4796+
String f = terms.get(2) + "";
47454797
Expression obj = t1.cexpressionToKM3(
47464798
vartypes, varelemtypes, types, entities);
4747-
UnaryExpression deref = new UnaryExpression("!", obj);
4799+
4800+
Expression deref = new UnaryExpression("!", obj);
4801+
4802+
if (obj instanceof UnaryExpression &&
4803+
((UnaryExpression) obj).operator.equals("?"))
4804+
{ deref = ((UnaryExpression) obj).argument; }
47484805
deref.setBrackets(true);
4749-
res.setObjectRef(deref);
4750-
return res;
4806+
4807+
// res.setObjectRef(deref);
4808+
return cFieldApplication(deref,f);
47514809
}
47524810

47534811
if (terms.size() == 5 &&
@@ -4760,7 +4818,10 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
47604818
res1.setUmlKind(Expression.ATTRIBUTE);
47614819
Expression obj = t1.cexpressionToKM3(
47624820
vartypes, varelemtypes, types, entities);
4763-
UnaryExpression deref = new UnaryExpression("!", obj);
4821+
Expression deref = new UnaryExpression("!", obj);
4822+
if (obj instanceof UnaryExpression &&
4823+
((UnaryExpression) obj).operator.equals("?"))
4824+
{ deref = ((UnaryExpression) obj).argument; }
47644825
deref.setBrackets(true);
47654826
res1.setObjectRef(deref);
47664827
BasicExpression res =
@@ -7255,7 +7316,47 @@ else if ("time".equals(fname) && args.size() == 1)
72557316
{ Expression res =
72567317
BasicExpression.newStaticCallBasicExpression(
72577318
"getSystemTime", "OclDate");
7258-
res.setType(new Type("long", null));
7319+
res.setType(new Type("long", null));
7320+
Expression resx =
7321+
new BinaryExpression("/", res,
7322+
new BasicExpression(1000));
7323+
resx.setType(new Type("long", null));
7324+
return resx;
7325+
}
7326+
else if ("mktime".equals(fname) && args.size() == 1)
7327+
{ Expression arg1 = (Expression) args.get(0);
7328+
Expression dte = new UnaryExpression("!", arg1);
7329+
7330+
if (arg1 instanceof UnaryExpression &&
7331+
((UnaryExpression) arg1).operator.equals("?"))
7332+
{ dte = ((UnaryExpression) arg1).argument; }
7333+
7334+
dte.setBrackets(true);
7335+
7336+
Expression res =
7337+
BasicExpression.newCallBasicExpression(
7338+
"getTime", dte);
7339+
res.setType(new Type("long", null));
7340+
Expression resx =
7341+
new BinaryExpression("/", res,
7342+
new BasicExpression(1000));
7343+
resx.setType(new Type("long", null));
7344+
return resx;
7345+
}
7346+
else if ("asctime".equals(fname) && args.size() == 1)
7347+
{ Expression arg1 = (Expression) args.get(0);
7348+
Expression dte = new UnaryExpression("!", arg1);
7349+
7350+
if (arg1 instanceof UnaryExpression &&
7351+
((UnaryExpression) arg1).operator.equals("?"))
7352+
{ dte = ((UnaryExpression) arg1).argument; }
7353+
7354+
dte.setBrackets(true);
7355+
7356+
Expression res =
7357+
BasicExpression.newCallBasicExpression(
7358+
"toString", dte);
7359+
res.setType(new Type("String", null));
72597360
return res;
72607361
}
72617362
else if ("difftime".equals(fname) && args.size() == 2)
@@ -7264,8 +7365,55 @@ else if ("difftime".equals(fname) && args.size() == 2)
72647365
Expression res =
72657366
new BinaryExpression("-", arg1, arg2);
72667367
res.setType(new Type("double", null));
7368+
res.setBrackets(true);
72677369
return res;
72687370
}
7371+
else if (("localtime".equals(fname) ||
7372+
"gmtime".equals(fname)) && args.size() == 1)
7373+
{ // mktime(t) is OclDate.newOclDate_Time(
7374+
Expression arg1 = (Expression) args.get(0);
7375+
7376+
Expression par = new UnaryExpression("!", arg1);
7377+
7378+
if (arg1 instanceof UnaryExpression &&
7379+
((UnaryExpression) arg1).operator.equals("?"))
7380+
{ par = ((UnaryExpression) arg1).argument; }
7381+
7382+
Expression par1 =
7383+
new BinaryExpression("*",par,
7384+
new BasicExpression(1000));
7385+
Expression res =
7386+
BasicExpression.newStaticCallBasicExpression(
7387+
"newOclDate_Time", "OclDate", par1);
7388+
res.setType(new Type("OclDate", null));
7389+
Expression resx =
7390+
new UnaryExpression("?", res);
7391+
resx.setType(new Type("Ref", null));
7392+
resx.setElementType(new Type("OclDate", null));
7393+
return resx;
7394+
}
7395+
else if ("ctime".equals(fname) && args.size() == 1)
7396+
{ // create an OclDate for arg1 & display it.
7397+
Expression arg1 = (Expression) args.get(0);
7398+
7399+
Expression par = new UnaryExpression("!", arg1);
7400+
7401+
if (arg1 instanceof UnaryExpression &&
7402+
((UnaryExpression) arg1).operator.equals("?"))
7403+
{ par = ((UnaryExpression) arg1).argument; }
7404+
7405+
Expression par1 =
7406+
new BinaryExpression("*",par,
7407+
new BasicExpression(1000));
7408+
Expression res =
7409+
BasicExpression.newStaticCallBasicExpression(
7410+
"newOclDate_Time", "OclDate", par1);
7411+
Expression resx =
7412+
BasicExpression.newCallBasicExpression(
7413+
"toString", res);
7414+
resx.setType(new Type("String", null));
7415+
return resx;
7416+
}
72697417
else if ("printf".equals(fname) && args.size() > 1)
72707418
{ Expression fmt = (Expression) args.get(0);
72717419
Vector elems = new Vector();

ASTTerm.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,19 @@ public abstract class ASTTerm
9191
cqueryfunctions.add("strerror");
9292
cqueryfunctions.add("getenv");
9393
cqueryfunctions.add("bsearch");
94-
cqueryfunctions.add("time");
95-
cqueryfunctions.add("difftime");
9694
cqueryfunctions.add("toupper");
9795
cqueryfunctions.add("tolower");
9896
cqueryfunctions.add("fopen");
9997
cqueryfunctions.add("div");
100-
cqueryfunctions.add("ldiv");
98+
cqueryfunctions.add("ldiv");
99+
100+
cqueryfunctions.add("time");
101+
cqueryfunctions.add("difftime");
102+
cqueryfunctions.add("localtime");
103+
cqueryfunctions.add("mktime");
104+
cqueryfunctions.add("asctime");
105+
cqueryfunctions.add("ctime");
106+
cqueryfunctions.add("gmtime");
101107
}
102108

103109
public abstract String toString();
@@ -276,7 +282,19 @@ public boolean hasType(String str)
276282
public abstract Type pointersToRefType(String tname, Type t);
277283

278284
public static Entity introduceCStruct(String nme, Vector ents)
279-
{ Entity ent = (Entity) ModelElement.lookupByName(nme, ents);
285+
{ if (nme.equals("tm"))
286+
{ Entity ent =
287+
(Entity) ModelElement.lookupByName("OclDate", ents);
288+
if (ent != null)
289+
{ return ent; }
290+
ent = new Entity("OclDate");
291+
ent.addStereotype("component");
292+
ent.addStereotype("external");
293+
ents.add(ents.size()-1, ent);
294+
return ent;
295+
}
296+
297+
Entity ent = (Entity) ModelElement.lookupByName(nme, ents);
280298
if (ent != null)
281299
{ return ent; }
282300

@@ -304,7 +322,7 @@ else if ("ldiv_t".equals(nme))
304322
ModelElement.INTERNAL);
305323
ent.addAttribute(rem);
306324
}
307-
else if ("tm".equals(nme))
325+
/* else if ("tm".equals(nme))
308326
{ Attribute secs =
309327
new Attribute("tm_sec", new Type("int", null),
310328
ModelElement.INTERNAL);
@@ -341,7 +359,7 @@ else if ("tm".equals(nme))
341359
new Attribute("tm_isdst", new Type("int", null),
342360
ModelElement.INTERNAL);
343361
ent.addAttribute(isdst);
344-
}
362+
} */
345363

346364
return ent;
347365
}

BasicExpression.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,16 @@ public static BasicExpression newCallBasicExpression(String f, Expression obj)
557557
return res;
558558
}
559559

560+
public static BasicExpression newQueryCallBasicExpression(
561+
String f, Expression obj)
562+
{ BasicExpression res = new BasicExpression(f);
563+
res.setObjectRef(obj);
564+
res.umlkind = QUERY;
565+
res.parameters = new Vector();
566+
res.isEvent = true;
567+
return res;
568+
}
569+
560570
public static BasicExpression newStaticCallBasicExpression(
561571
BehaviouralFeature bf, Entity ent)
562572
{ BasicExpression obj = new BasicExpression(ent.getName());
@@ -14286,13 +14296,15 @@ else if (parameters != null)
1428614296
{ BasicExpression rootexp = (BasicExpression) clone();
1428714297
rootexp.parameters = null;
1428814298
String rootstring = rootexp + "";
14289-
String prefix = ModelElement.longestCommonPrefix(rootstring,tr.lhs);
14290-
String remstring = rootstring.substring(prefix.length(), rootstring.length());
14291-
Vector textargs = new Vector();
14292-
textargs.add(remstring);
14293-
String parstring = "";
14294-
for (int i = 0; i < parameters.size(); i++)
14295-
{ Expression par = (Expression) parameters.get(i);
14299+
String prefix = ModelElement.longestCommonPrefix(rootstring,tr.lhs);
14300+
String remstring =
14301+
rootstring.substring(
14302+
prefix.length(), rootstring.length());
14303+
Vector textargs = new Vector();
14304+
textargs.add(remstring);
14305+
String parstring = "";
14306+
for (int i = 0; i < parameters.size(); i++)
14307+
{ Expression par = (Expression) parameters.get(i);
1429614308
parstring = parstring + par.cg(cgs);
1429714309
if (i < parameters.size() - 1)
1429814310
{ parstring = parstring + ", "; }
@@ -14336,7 +14348,7 @@ else if (tr.variables.size() == 1 &&
1433614348
if (r != null)
1433714349
{ System.out.println(">>> Found basic expression text rule: " + r + " for " + this);
1433814350
return r.applyTextRule(etext);
14339-
}
14351+
}
1434014352
}
1434114353
return etext;
1434214354
}

0 commit comments

Comments
 (0)