Skip to content

Commit 619f1d3

Browse files
authored
Updated Go code generator & libraries
1 parent f71dc38 commit 619f1d3

File tree

7 files changed

+264
-24
lines changed

7 files changed

+264
-24
lines changed

ASTBasicTerm.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
406406
{ return new BasicExpression(65535); }
407407
if ("ULONG_MAX".equals(value))
408408
{ long mm = 1 + 2*(9223372036854775807L);
409-
return new BasicExpression(mm);
409+
Expression umax = new BasicExpression(mm);
410+
umax.setBrackets(true);
411+
return umax;
410412
}
411413
if ("FLT_RADIX".equals(value))
412414
{ return new BasicExpression(2); }
@@ -452,6 +454,10 @@ public Expression cexpressionToKM3(java.util.Map vartypes,
452454
}
453455
if ("DBL_MIN_EXP".equals(value))
454456
{ return new BasicExpression(-1021); }
457+
if ("EDOM".equals(value))
458+
{ return new BasicExpression(33); }
459+
if ("ERANGE".equals(value))
460+
{ return new BasicExpression(34); }
455461

456462

457463

ASTCompositeTerm.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ public String cgRules(CGSpec cgs, Vector rules)
201201
Vector vars = r.getVariables();
202202

203203
if (tokens.size() > terms.size())
204-
{ System.out.println("> " + tag + " rule " + r + " does not match " + this);
205-
System.out.println("!! Too many elements on rule LHS (" + tokens.size() + ") to match subterms: (" + terms.size() + ")");
204+
{ // System.out.println("> " + tag + " rule " + r + " does not match " + this);
205+
// System.out.println("!! Too many elements on rule LHS (" + tokens.size() + ") to match subterms: (" + terms.size() + ")");
206206
continue;
207207
}
208208
else if (vars.contains("_*") && terms.size() >= tokens.size())
@@ -235,7 +235,7 @@ else if (tokens.size() == terms.size())
235235
if (tokens.size() > j+1)
236236
{ nextTok = (String) tokens.get(j+1); }
237237

238-
System.out.println(">> End token for _* is: " + nextTok);
238+
// System.out.println(">> End token for _* is: " + nextTok);
239239
int remainingTokens = tokens.size() - (j+1);
240240

241241
boolean finished = false;
@@ -254,26 +254,26 @@ else if (remainingTokens > remainingTerms)
254254
{ rem.add(pterm);
255255
k++;
256256
}
257-
System.out.println(">>> Terms for _* are: " + rem);
257+
// System.out.println(">>> Terms for _* are: " + rem);
258258
}
259259
eargs.add(rem); // corresponds to _* variable
260260
}
261261
else if (vars.contains(tok))
262262
{ // allocate terms(j) to tok
263263

264-
System.out.println(">> Matched variable " + tok +
265-
" and term " + tm);
264+
// System.out.println(">> Matched variable " + tok +
265+
// " and term " + tm);
266266
eargs.add(tm);
267267
k++;
268268
}
269269
else if (tok.equals(tm.literalForm()))
270-
{ System.out.println(">> Matched token " + tok +
271-
" and term " + tm);
270+
{ // System.out.println(">> Matched token " + tok +
271+
// " and term " + tm);
272272
k++;
273273
}
274274
else
275-
{ System.out.println("> " + tag + " rule " + r + " does not match " + this);
276-
System.out.println(tok + " /= " + tm.literalForm());
275+
{ // System.out.println("> " + tag + " rule " + r + " does not match " + this);
276+
// System.out.println(tok + " /= " + tm.literalForm());
277277
k++;
278278
failed = true; // try next rule
279279
}
@@ -10759,13 +10759,12 @@ else if ("countTokens".equals(called))
1075910759
ASTTerm.setType(thisliteral,"int");
1076010760

1076110761
if (arg.expression != null)
10762-
{ BasicExpression elems =
10763-
BasicExpression.newBasicExpression(arg.expression,
10764-
"elements");
10765-
expression = new UnaryExpression("->size", elems);
10762+
{ expression =
10763+
BasicExpression.newCallBasicExpression(
10764+
"length", arg.expression);
1076610765
}
1076710766

10768-
return args + ".elements->size()";
10767+
return args + ".length()";
1076910768
}
1077010769
else if ("get".equals(called) || "elementAt".equals(called))
1077110770
{ ASTTerm callarg = (ASTTerm) callterms.get(2);
@@ -10787,6 +10786,15 @@ else if ("get".equals(called) || "elementAt".equals(called))
1078710786
}
1078810787
return args + "->at(" + callp + ")";
1078910788
}
10789+
else if ("OclIterator".equals(tt))
10790+
{ if (arg.expression != null &&
10791+
callarg.expression != null)
10792+
{ expression =
10793+
BasicExpression.newCallBasicExpression(
10794+
"at", arg.expression, callarg.expression);
10795+
}
10796+
return args + ".at(" + callp + ")";
10797+
}
1079010798
else
1079110799
{ if (arg.expression != null &&
1079210800
callarg.expression != null)
@@ -11247,7 +11255,7 @@ else if ("addAll".equals(called) && arg.isCollection())
1124711255
new AssignStatement(arg.expression, expression);
1124811256
}
1124911257

11250-
return args + " := " + args + ".subrange(1, " + callp1 + ")->union(" + callp2 + ")->union(" + args + ".subrange(" + callp1 + "+1))";
11258+
return args + " := " + args + ".insertInto(" + callp1 + "+1, " + callp2 + ")";
1125111259
}
1125211260
else
1125311261
{ if (arg.expression != null &&
@@ -14453,11 +14461,11 @@ else if (arg.isDate() &&
1445314461

1445414462
if (arg.expression != null)
1445514463
{ expression =
14456-
BasicExpression.newBasicExpression(
14457-
arg.expression, "time");
14464+
BasicExpression.newCallBasicExpression(
14465+
"getTime", arg.expression);
1445814466
}
1445914467

14460-
return args + ".time";
14468+
return args + ".getTime()";
1446114469
}
1446214470
else if (arg.isDate() &&
1446314471
"setTimeInMillis".equals(called))

BSystemTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5562,8 +5562,8 @@ public static String generateTimeOp()
55625562
}
55635563

55645564
public static String generateTimeOpCPP()
5565-
{ String res = " static long getTime()\n" +
5566-
" { return time(NULL); }\n\n";
5565+
{ String res = " static long long getTime()\n" +
5566+
" { return 1000*time(NULL); }\n\n";
55675567
res = res + " static struct tm* getDate()\n" +
55685568
" { time_t t = time(NULL);\n" +
55695569
" struct tm* res = localtime(&t);\n" +

PreProcessModels.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,80 @@ else if (operationExamples.size() > programOperationExamples.size())
972972

973973
}
974974

975+
public static void parseExamples(String fname, Vector sexamples, Vector texamples)
976+
{ // reads file fname, each line is an example
977+
// stext tabs ttext
978+
// sexamples will be the LHS texts, texamples the
979+
// RHS texts
980+
981+
try
982+
{ File tfile = new File(fname);
983+
984+
if (tfile == null) { return; }
985+
986+
System.out.println(">>> Loading examples from " + fname);
987+
988+
BufferedReader br = null;
989+
String s;
990+
boolean eof = false;
991+
992+
try
993+
{ br = new BufferedReader(new FileReader(tfile)); }
994+
catch (FileNotFoundException fnfe)
995+
{ System.out.println("File not found: " + tfile.getName());
996+
return;
997+
}
998+
999+
int linecount = 0;
1000+
1001+
while (!eof)
1002+
{ try
1003+
{ s = br.readLine(); }
1004+
catch (IOException ioe)
1005+
{ System.out.println("!! Reading " + tfile.getName() + " failed.");
1006+
return;
1007+
}
1008+
1009+
if (s == null)
1010+
{ eof = true;
1011+
break;
1012+
}
1013+
1014+
s = s.trim();
1015+
1016+
if (s.length() == 0)
1017+
{ continue; }
1018+
1019+
String progstring = "";
1020+
int tabindex = s.indexOf("\t");
1021+
if (tabindex >= 0)
1022+
{ progstring = s.substring(tabindex+1,s.length());
1023+
s = s.substring(0,tabindex);
1024+
tabindex = progstring.indexOf("\t");
1025+
while (tabindex >= 0)
1026+
{ progstring = progstring.substring(tabindex+1,progstring.length());
1027+
tabindex = progstring.indexOf("\t");
1028+
}
1029+
1030+
System.out.println(">> Source text: " + s);
1031+
sexamples.add(s);
1032+
1033+
System.out.println(">> Target text: " + progstring);
1034+
texamples.add(progstring);
1035+
}
1036+
1037+
linecount++;
1038+
}
1039+
1040+
br.close();
1041+
} catch(Exception e)
1042+
{ System.err.println(">>> Error processing " + fname); }
1043+
1044+
System.out.println(">> Source examples: " + sexamples);
1045+
System.out.println(">> Target examples: " + texamples);
1046+
}
1047+
1048+
9751049
public static void main(String[] args)
9761050
{ PreProcessModels.preprocess(); }
9771051

0 commit comments

Comments
 (0)