@@ -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();
0 commit comments