Skip to content

Commit 5818cb8

Browse files
authored
Latest code generators/libraries
1 parent e5f41a4 commit 5818cb8

16 files changed

+389
-164
lines changed

ASTCompositeTerm.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,15 @@ public String cg(CGSpec cgs)
362362
// the r LHS, then apply first rule to the cg results of
363363
// the LHS matchings.
364364

365+
// if already cached, return that value:
366+
String cachedValue = ASTTerm.getCg_cache(cgs,this);
367+
if (cachedValue != null)
368+
{ return cachedValue; }
369+
365370
Vector rules = cgs.getRulesForCategory(tag);
366-
return cgRules(cgs,rules);
371+
String res = cgRules(cgs,rules);
372+
ASTTerm.putCg_cache(cgs,this,res);
373+
return res;
367374
}
368375

369376
public String cgRules(CGSpec cgs, Vector rules)
@@ -376,7 +383,7 @@ public String cgRules(CGSpec cgs, Vector rules)
376383
Vector vars = r.getVariables();
377384

378385
java.util.HashMap matches = new java.util.HashMap();
379-
// vars --> terms
386+
// vars --> String
380387

381388
Vector matchedTerms = new Vector();
382389
Vector matchedTokens = new Vector();
@@ -409,6 +416,7 @@ else if (tokens.size() == terms.size())
409416
k < terms.size() && !failed; j++)
410417
{ String tok = (String) tokens.get(j);
411418
ASTTerm tm = (ASTTerm) terms.get(k);
419+
String tmliteral = tm.literalForm();
412420

413421
// System.out.println("$$$ matching token " + tok + " and term " + tm);
414422

@@ -501,26 +509,26 @@ else if (vars.contains(tok))
501509
matchedTokens.add(tok);
502510
matchedTerms.add(tm);
503511

504-
ASTTerm oldterm = (ASTTerm) matches.get(tok);
512+
String oldterm = (String) matches.get(tok);
505513
if (oldterm == null)
506-
{ matches.put(tok,tm);
514+
{ matches.put(tok,tmliteral);
507515

508516
eargs.add(tm);
509517
k++;
510518
}
511-
else if (oldterm.equals(tm))
519+
else if (oldterm.equals(tmliteral))
512520
{
513521
eargs.add(tm);
514522
k++;
515523
}
516524
else
517-
{ // System.err.println("!! Same variable " + tok +
518-
// " assigned different terms: " +
519-
// oldterm + " " + tm);
525+
{ System.err.println("!! Same variable " + tok +
526+
" assigned different terms: " +
527+
oldterm + " " + tm);
520528
failed = true;
521529
}
522530
}
523-
else if (tok.equals(tm.literalForm()))
531+
else if (tok.equals(tmliteral))
524532
{ // System.out.println(">> Matched token " + tok +
525533
// " and term " + tm);
526534
matchedTerms.add(tm);
@@ -529,7 +537,7 @@ else if (tok.equals(tm.literalForm()))
529537
}
530538
else
531539
{ // System.out.println("> " + tag + " rule " + r + " does not match " + this);
532-
// System.out.println(tok + " /= " + tm.literalForm());
540+
// System.out.println(tok + " /= " + tmliteral);
533541
k++;
534542
failed = true; // try next rule
535543
}
@@ -551,7 +559,9 @@ else if (tok.equals(tm.literalForm()))
551559

552560

553561
if (failed == false)
554-
{ System.out.println(">> Matched " + tag + " rule " + r + " for " + this);
562+
{ // System.out.println(">> Matched " + tag + " rule " + r + " for " + this);
563+
564+
// Repeated evaluation of term.cg(cgs). Must be cached
555565

556566
for (int p = 0; p < eargs.size(); p++)
557567
{ Object obj = eargs.get(p);
@@ -574,11 +584,11 @@ else if (obj instanceof Vector)
574584
Vector ents = new Vector();
575585

576586
if (r.satisfiesAllConditions(eargs,ents,cgs))
577-
{ System.out.println(">>>> Applying " + tag + " rule " + r);
587+
{ System.out.println(">>>> Applying " + tag + " rule " + r + " for " + this);
578588
return r.applyRule(args,eargs,cgs);
579589
}
580590
else
581-
{ System.out.println(">!> Conditions of " + r + " failed.");
591+
{ System.out.println(">!!> Conditions of rule " + r + " failed for " + this);
582592
}
583593
}
584594
}
@@ -591,6 +601,7 @@ else if (obj instanceof Vector)
591601
System.out.println(">> Applying default rule _0 |-->_0 to " + this);
592602
return this.cgRules(cgs,tagrules);
593603
}
604+
594605
return toString();
595606
}
596607

ASTTerm.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public abstract class ASTTerm
4848
// of identifiers
4949
// valid at the scope of the current term.
5050

51+
static java.util.Map cg_cache = new java.util.HashMap();
52+
// CGSpec --> (ASTTerm --> String)
53+
5154
static Vector cqueryfunctions = new Vector();
5255
static
5356
{ cqueryfunctions.add("sin");
@@ -132,6 +135,22 @@ public static Vector getLiteralForms(Vector trms)
132135
return res;
133136
}
134137

138+
public static void putCg_cache(CGSpec cgs, ASTTerm trm, String res)
139+
{ java.util.Map cgsmap = (java.util.Map) cg_cache.get(cgs);
140+
if (cgsmap == null)
141+
{ cgsmap = new java.util.HashMap(); }
142+
cgsmap.put(trm, res);
143+
cg_cache.put(cgs, cgsmap);
144+
}
145+
146+
public static String getCg_cache(CGSpec cgs, ASTTerm trm)
147+
{ java.util.Map cgsmap = (java.util.Map) cg_cache.get(cgs);
148+
if (cgsmap == null)
149+
{ return null; }
150+
String res = (String) cgsmap.get(trm);
151+
return res;
152+
}
153+
135154
public abstract ASTTerm removeWhitespaceTerms();
136155

137156
public abstract ASTTerm replaceCobolIdentifiers();

AppGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/* Package: Mobile */
55
/******************************
6-
* Copyright (c) 2003--2021 Kevin Lano
6+
* Copyright (c) 2003--2022 Kevin Lano
77
* This program and the accompanying materials are made available under the
88
* terms of the Eclipse Public License 2.0 which is available at
99
* http://www.eclipse.org/legal/epl-2.0

Association.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ public boolean isManyOne() // either way round
354354
card1 == ONE && card2 == MANY;
355355
}
356356

357+
public boolean isOneMany()
358+
{ return card1 == ONE && card2 == MANY; }
359+
357360
public boolean isZeroOne()
358361
{ return card2 == ZEROONE; }
359362

Entity.java

Lines changed: 100 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13661,29 +13661,61 @@ public String generateBean(Vector useCases, Vector cons, Vector entities,
1366113661
for (int i = 0; i < attributes.size(); i++)
1366213662
{ Attribute att = (Attribute) attributes.get(i);
1366313663
String attnme = att.getName();
13664-
String tname = att.getType().getName();
13665-
res = res + " private String " + attnme + " = \"\";\n";
13664+
Type atttype = att.getType();
13665+
String tname = atttype.getName();
13666+
13667+
res = res + " private String " + attnme + " = \"\";\n";
1366613668
if (tname.equals("int"))
13667-
{ res = res + " private int i" + attnme + " = 0;\n"; }
13669+
{ res = res + " private int i" + attnme + " = 0;\n"; }
1366813670
else if (tname.equals("double"))
13669-
{ res = res + " private double d" + attnme + " = 0;\n"; }
13671+
{ res = res + " private double d" + attnme + " = 0;\n"; }
13672+
else if (att.isEnumeration())
13673+
{ Vector vals = atttype.getValues();
13674+
res = res + " private " + tname + " e" + attnme + " = " + tname + "." + vals.get(0) + ";\n";
13675+
}
1367013676
// booleans are treated as strings.
13671-
}
13677+
}
13678+
13679+
for (int j = 0; j < associations.size(); j++)
13680+
{ Association ast = (Association) associations.get(j);
13681+
Entity ent2 = ast.getEntity2();
13682+
Attribute fkey = ent2.getPrincipalPrimaryKey();
13683+
if (fkey != null) // assume it is a string
13684+
{ String keynme = fkey.getName();
13685+
String keytype = fkey.getType().getName();
13686+
res = res + " private " + keytype + " " + keynme + ";\n";
13687+
}
13688+
}
13689+
1367213690
res = res + " private Vector errors = new Vector();\n\n" +
1367313691
" public " + ename + "Bean() {}\n\n";
13692+
1367413693
for (int i = 0; i < attributes.size(); i++)
1367513694
{ Attribute att = (Attribute) attributes.get(i);
1367613695
String attnme = att.getName();
1367713696
res = res + " public void set" + attnme + "(String " + attnme + "x)\n { " +
1367813697
attnme + " = " + attnme + "x; }\n\n";
1367913698
}
1368013699

13700+
for (int j = 0; j < associations.size(); j++)
13701+
{ Association ast = (Association) associations.get(j);
13702+
Entity ent2 = ast.getEntity2();
13703+
Attribute fkey = ent2.getPrincipalPrimaryKey();
13704+
if (fkey != null) // assume it is a string
13705+
{ String keynme = fkey.getName();
13706+
String keytype = fkey.getType().getName();
13707+
res = res + " public void set" + keynme + "(" + keytype + " " + keynme + "x)\n { " +
13708+
keynme + " = " + keynme + "x; }\n\n";
13709+
}
13710+
}
13711+
1368113712
res = res + " public void resetData()\n { ";
1368213713
for (int i = 0; i < attributes.size(); i++)
1368313714
{ Attribute att = (Attribute) attributes.get(i);
1368413715
String attname = att.getName();
1368513716
res = res + attname + " = \"\";\n ";
1368613717
}
13718+
1368713719
res = res + "}\n\n";
1368813720

1368913721
for (int j = 0; j < useCases.size(); j++)
@@ -13704,7 +13736,8 @@ else if (tname.equals("double"))
1370413736
res = res + check;
1370513737
}
1370613738

13707-
if (action.equals("create") || action.equals("edit") || action.equals("set"))
13739+
if (action.equals("create") ||
13740+
action.equals("edit") || action.equals("set"))
1370813741
{ Vector tests = getInvariantCheckTests(pars);
1370913742
for (int p = 0; p < tests.size(); p++)
1371013743
{ String test = (String) tests.get(p);
@@ -13742,7 +13775,8 @@ else if (tname.equals("double"))
1374213775
allinvs.addAll(invariants);
1374313776
allinvs.addAll(cons);
1374413777

13745-
correc = att.sqlSetOperations(this,allinvs,entities,types);
13778+
correc = att.sqlSetOperations(
13779+
this,allinvs,entities,types);
1374613780
res = res + odname + "(" + att.getBeanForm() +
1374713781
", i" + ename.toLowerCase() + "Id);\n ";
1374813782
}
@@ -13783,36 +13817,62 @@ public String generateJSPBean(String packageName, Vector useCases,
1378313817
{ String ename = getName();
1378413818
String res = "package " + packageName + ";\n\n" +
1378513819
"import java.util.Vector;\n" +
13786-
"import java.util.List;\n" +
13787-
"import java.util.Iterator;\n\n" +
13820+
"import java.util.List;\n" +
13821+
"import java.util.Iterator;\n\n" +
1378813822

1378913823
"public class " + ename + "Bean\n{ ModelFacade model;\n";
13824+
1379013825
for (int i = 0; i < attributes.size(); i++)
1379113826
{ Attribute att = (Attribute) attributes.get(i);
1379213827
String attnme = att.getName();
13793-
Type atttype = att.getType();
13828+
Type atttype = att.getType();
1379413829
String tname = atttype.getName();
1379513830
res = res + " private String " + attnme + " = \"\";\n";
1379613831
if (tname.equals("int") || tname.equals("long"))
1379713832
{ res = res + " private int i" + attnme + " = 0;\n"; }
1379813833
else if (tname.equals("double"))
1379913834
{ res = res + " private double d" + attnme + " = 0;\n"; }
13800-
else if (att.isEnumeration())
13801-
{ Vector vals = atttype.getValues();
13802-
res = res + " private " + tname + " e" + attnme + " = " + tname + "." + vals.get(0) + ";\n";
13803-
}
13835+
else if (att.isEnumeration())
13836+
{ Vector vals = atttype.getValues();
13837+
res = res + " private " + tname + " e" + attnme + " = " + tname + "." + vals.get(0) + ";\n";
13838+
}
1380413839
// booleans are treated as strings.
13805-
}
13840+
}
13841+
13842+
for (int j = 0; j < associations.size(); j++)
13843+
{ Association ast = (Association) associations.get(j);
13844+
Entity ent2 = ast.getEntity2();
13845+
Attribute fkey = ent2.getPrincipalPrimaryKey();
13846+
if (fkey != null)
13847+
{ String keynme = fkey.getName();
13848+
String keytype = fkey.getType().getName();
13849+
res = res + " private " + keytype + " " + keynme + ";\n";
13850+
}
13851+
}
13852+
1380613853
res = res + " private Vector errors = new Vector();\n\n" +
1380713854
" public " + ename + "Bean()\n" +
1380813855
" { model = ModelFacade.getInstance(); }\n\n";
13856+
1380913857
for (int i = 0; i < attributes.size(); i++)
1381013858
{ Attribute att = (Attribute) attributes.get(i);
1381113859
String attnme = att.getName();
1381213860
res = res + " public void set" + attnme + "(String " + attnme + "x)\n { " +
1381313861
attnme + " = " + attnme + "x; }\n\n";
1381413862
}
1381513863

13864+
for (int j = 0; j < associations.size(); j++)
13865+
{ Association ast = (Association) associations.get(j);
13866+
Entity ent2 = ast.getEntity2();
13867+
Attribute fkey = ent2.getPrincipalPrimaryKey();
13868+
if (fkey != null) // assume it is a string
13869+
{ String keynme = fkey.getName();
13870+
String keytype = fkey.getType().getName();
13871+
res = res + " public void set" + keynme + "(" + keytype + " " + keynme + "x)\n { " +
13872+
keynme + " = " + keynme + "x; }\n\n";
13873+
}
13874+
}
13875+
1381613876
res = res + " public void resetData()\n { ";
1381713877
for (int i = 0; i < attributes.size(); i++)
1381813878
{ Attribute att = (Attribute) attributes.get(i);
@@ -13839,7 +13899,8 @@ else if (att.isEnumeration())
1383913899
res = res + check;
1384013900
}
1384113901

13842-
if (action.equals("create") || action.equals("edit") || action.equals("set"))
13902+
if (action.equals("create") ||
13903+
action.equals("edit") || action.equals("set"))
1384313904
{ Vector tests = getInvariantCheckTests(types,entities,pars,cgs);
1384413905
for (int p = 0; p < tests.size(); p++)
1384513906
{ String test = (String) tests.get(p);
@@ -13869,14 +13930,16 @@ else if (att.isEnumeration())
1386913930
action.equals("add") || action.equals("remove") ||
1387013931
action.equals("edit") || action.equals("set"))
1387113932
{ res = res + " public void " + odname + "()\n" + " { ";
13872-
res = res + dbiop + "\n ";
13933+
res = res + dbiop + "\n ";
13934+
1387313935
/* if (action.equals("set"))
1387413936
{ Attribute att = (Attribute) pars.get(0);
1387513937
Vector allinvs = new Vector();
1387613938
allinvs.addAll(invariants);
1387713939
allinvs.addAll(cons);
1387813940

13879-
correc = att.sqlSetOperations(this,allinvs,entities,types);
13941+
correc = att.sqlSetOperations(
13942+
this,allinvs,entities,types);
1388013943
res = res + odname + "(" + att.getBeanForm() +
1388113944
", i" + ename.toLowerCase() + "Id);\n ";
1388213945
} */
@@ -13916,19 +13979,31 @@ public String generateAndroidBean(String packageName, Vector useCases,
1391613979
for (int i = 0; i < attributes.size(); i++)
1391713980
{ Attribute att = (Attribute) attributes.get(i);
1391813981
String attnme = att.getName();
13919-
Type atttype = att.getType();
13982+
Type atttype = att.getType();
1392013983
String tname = atttype.getName();
1392113984
res = res + " private String " + attnme + " = \"\";\n";
1392213985
if (tname.equals("int") || tname.equals("long"))
1392313986
{ res = res + " private int i" + attnme + " = 0;\n"; }
1392413987
else if (tname.equals("double"))
1392513988
{ res = res + " private double d" + attnme + " = 0;\n"; }
13926-
else if (att.isEnumeration())
13927-
{ Vector vals = atttype.getValues();
13928-
res = res + " private " + tname + " e" + attnme + " = " + tname + "." + vals.get(0) + ";\n";
13929-
}
13989+
else if (att.isEnumeration())
13990+
{ Vector vals = atttype.getValues();
13991+
res = res + " private " + tname + " e" + attnme + " = " + tname + "." + vals.get(0) + ";\n";
13992+
}
1393013993
// booleans are treated as strings.
1393113994
}
13995+
13996+
for (int j = 0; j < associations.size(); j++)
13997+
{ Association ast = (Association) associations.get(j);
13998+
Entity ent2 = ast.getEntity2();
13999+
Attribute fkey = ent2.getPrincipalPrimaryKey();
14000+
if (fkey != null) // assumed to be of string type
14001+
{ String keynme = fkey.getName();
14002+
String keytype = fkey.getType().getName();
14003+
res = res + " private " + keytype + " " + keynme + ";\n";
14004+
}
14005+
}
14006+
1393214007
res = res + " private Vector errors = new Vector();\n\n" +
1393314008
" public " + ename + "Bean(Context _c)\n" +
1393414009
" { model = ModelFacade.getInstance(_c); }\n\n";
@@ -13965,7 +14040,8 @@ else if (att.isEnumeration())
1396514040
res = res + check;
1396614041
}
1396714042

13968-
if (action.equals("create") || action.equals("edit") || action.equals("set"))
14043+
if (action.equals("create") ||
14044+
action.equals("edit") || action.equals("set"))
1396914045
{ Vector tests = getInvariantCheckTests(types,entities,pars,cgs);
1397014046
for (int p = 0; p < tests.size(); p++)
1397114047
{ String test = (String) tests.get(p);

0 commit comments

Comments
 (0)