forked from eclipse-agileuml/agileuml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTTerm.java
More file actions
4328 lines (3490 loc) · 131 KB
/
ASTTerm.java
File metadata and controls
4328 lines (3490 loc) · 131 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************
* Copyright (c) 2003--2023 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
import java.util.Vector;
import java.io.*;
import javax.swing.*;
public abstract class ASTTerm
{ String id = "";
// Vector stereotypes = new Vector();
// A programming language AST can be represented by
// one of the following UML/OCL things:
Expression expression = null;
Statement statement = null;
ModelElement modelElement = null;
Vector modelElements = null;
Vector expressions = null; // for parameter/argument lists
static Vector requiredLibraries = new Vector();
static String packageName = null;
static Vector enumtypes;
static Vector entities;
static Vector functionsInScope;
static Vector cobolClasses = new Vector();
static Entity currentClass = null; // Current context class
static java.util.Map metafeatures = new java.util.HashMap();
// String --> Vector(String),
// eg., recording the conceptual
// type of the element & stereotypes.
static java.util.Map types = new java.util.HashMap();
// String --> String for general type of identifiers
// valid at the scope of the current term.
static java.util.Map elementTypes = new java.util.HashMap();
// String --> String for general elementType
// of identifiers
// valid at the scope of the current term.
static java.util.Map cg_cache = new java.util.HashMap();
// CGSpec --> (ASTTerm --> String)
static Vector cqueryfunctions = new Vector();
static
{ cqueryfunctions.add("sin");
cqueryfunctions.add("cos");
cqueryfunctions.add("tan");
cqueryfunctions.add("asin");
cqueryfunctions.add("acos");
cqueryfunctions.add("atan");
cqueryfunctions.add("sinh");
cqueryfunctions.add("cosh");
cqueryfunctions.add("tanh");
cqueryfunctions.add("exp");
cqueryfunctions.add("log");
cqueryfunctions.add("log10");
cqueryfunctions.add("sqrt");
cqueryfunctions.add("ceil");
cqueryfunctions.add("floor");
cqueryfunctions.add("fabs");
cqueryfunctions.add("abs");
cqueryfunctions.add("labs");
cqueryfunctions.add("pow");
cqueryfunctions.add("atan2");
cqueryfunctions.add("ldexp");
cqueryfunctions.add("fmod");
cqueryfunctions.add("atof");
cqueryfunctions.add("atoi");
cqueryfunctions.add("atol");
cqueryfunctions.add("isalnum");
cqueryfunctions.add("isalpha");
cqueryfunctions.add("isspace");
cqueryfunctions.add("isdigit");
cqueryfunctions.add("isupper");
cqueryfunctions.add("islower");
cqueryfunctions.add("iscntrl");
cqueryfunctions.add("isgraph");
cqueryfunctions.add("isprint");
cqueryfunctions.add("ispunct");
cqueryfunctions.add("isxdigit");
cqueryfunctions.add("isnan");
cqueryfunctions.add("calloc");
cqueryfunctions.add("malloc");
// cqueryfunctions.add("realloc");
cqueryfunctions.add("strcmp");
cqueryfunctions.add("strncmp");
cqueryfunctions.add("strchr");
cqueryfunctions.add("strrchr");
cqueryfunctions.add("strlen");
cqueryfunctions.add("strstr");
cqueryfunctions.add("strpsn");
cqueryfunctions.add("strcpsn");
cqueryfunctions.add("strpbrk");
cqueryfunctions.add("strerror");
cqueryfunctions.add("getenv");
cqueryfunctions.add("bsearch");
cqueryfunctions.add("toupper");
cqueryfunctions.add("tolower");
cqueryfunctions.add("fopen");
cqueryfunctions.add("div");
cqueryfunctions.add("ldiv");
cqueryfunctions.add("time");
cqueryfunctions.add("difftime");
cqueryfunctions.add("localtime");
cqueryfunctions.add("mktime");
cqueryfunctions.add("asctime");
cqueryfunctions.add("ctime");
cqueryfunctions.add("gmtime");
}
public abstract String toString();
public abstract String getTag();
public abstract String literalForm();
public static Vector getLiteralForms(Vector trms)
{ Vector res = new Vector();
for (int i = 0; i < trms.size(); i++)
{ ASTTerm trm = (ASTTerm) trms.get(i);
res.add(trm.literalForm());
}
return res;
}
public static void putCg_cache(CGSpec cgs, ASTTerm trm, String res)
{ java.util.Map cgsmap = (java.util.Map) cg_cache.get(cgs);
if (cgsmap == null)
{ cgsmap = new java.util.HashMap(); }
cgsmap.put(trm, res);
cg_cache.put(cgs, cgsmap);
}
public static String getCg_cache(CGSpec cgs, ASTTerm trm)
{ java.util.Map cgsmap = (java.util.Map) cg_cache.get(cgs);
if (cgsmap == null)
{ return null; }
String res = (String) cgsmap.get(trm);
return res;
}
public abstract ASTTerm removeWhitespaceTerms();
public abstract ASTTerm removeExtraNewlines();
public abstract ASTTerm replaceCobolIdentifiers();
public abstract String tagFunction();
public static Vector allNestedTagsArities(Vector sasts)
{ // [tag,arity] for each inner term of sasts.
Vector res = new Vector();
for (int i = 0; i < sasts.size(); i++)
{ ASTTerm trm = (ASTTerm) sasts.get(i);
Vector trms = trm.getTerms();
for (int j = 0; j < trms.size(); j++)
{ ASTTerm tj = (ASTTerm) trms.get(j);
Vector alltags = tj.allNestedTagsArities();
res.addAll(alltags);
}
}
return res;
}
public static Vector allTagsArities(Vector sasts)
{ // [tag,arity] for each term of sasts and subterm,
// recursively.
Vector res = new Vector();
for (int i = 0; i < sasts.size(); i++)
{ ASTTerm trm = (ASTTerm) sasts.get(i);
Vector alltags = trm.allTagsArities();
res.addAll(alltags);
}
return res;
}
public abstract Vector allNestedTagsArities();
public abstract Vector allTagsArities();
public static Vector rulesFromTagsArities(Vector tagsarities)
{ // For each (tag,n) : tagsarities
// define CGRule tag:: _1 |-->_1 or _* |-->_*
java.util.Map cgrules = new java.util.HashMap();
for (int k = 0; k < tagsarities.size(); k++)
{ Vector tgar = (Vector) tagsarities.get(k);
String tg = (String) tgar.get(0);
int ar = (int) tgar.get(1);
Vector rls = (Vector) cgrules.get(tg);
if (rls == null)
{ rls = new Vector(); }
if (ar == 1)
{ if (rls.contains("_1 |-->_1")) { }
else
{ rls.add("_1 |-->_1"); }
}
else
{ if (rls.contains("_* |-->_*")) { }
else
{ rls.add("_* |-->_*"); }
}
cgrules.put(tg,rls);
}
Vector res = new Vector();
for (Object obj : cgrules.keySet())
{ String key = (String) obj;
Vector rls = (Vector) cgrules.get(key);
String rle = key + "::\n";
for (int p = 0; p < rls.size(); p++)
{ rle = rle + rls.get(p) + "\n"; }
res.add(rle);
}
return res;
}
public static boolean isSubterm(ASTTerm t1, ASTTerm t2)
{ if (t1 == null || t2 == null)
{ return false; }
String lit1 = t1.literalForm();
String lit2 = t2.literalForm();
if (lit1.equals(lit2))
{ return true; }
if (t2 instanceof ASTCompositeTerm)
{ ASTCompositeTerm ct = (ASTCompositeTerm) t2;
Vector trms = ct.getTerms();
for (int i = 0; i < trms.size(); i++)
{ ASTTerm subtrm =
(ASTTerm) trms.get(i);
if (ASTTerm.isSubterm(t1, subtrm))
{ return true; }
}
return false;
}
return false;
}
public void addStereotype(String str)
{ String lit = literalForm();
Object stereo = ASTTerm.metafeatures.get(lit);
Vector stereotypes = new Vector();
if (stereo == null)
{ ASTTerm.metafeatures.put(lit,stereotypes); }
else if (!(stereo instanceof Vector))
{ return; } // single-valued metafeature.
System.out.println(">++++> Adding stereotype " + str + " to " + lit);
if (stereotypes.contains(str)) {}
else
{ stereotypes.add(str);
ASTTerm.metafeatures.put(lit,stereotypes);
}
// JOptionPane.showMessageDialog(null,
// "*** addStereotype " + str + " to " + lit + " Metafeatures of " + lit + " are " + stereotypes, "",
// JOptionPane.INFORMATION_MESSAGE);
}
public static void addStereo(ASTTerm ast, String str)
{ if (ast == null) { return; }
String lit = ast.literalForm();
addStereo(lit,str);
}
public static void addStereo(String lit, String str)
{ Object mfs = ASTTerm.metafeatures.get(lit);
if (mfs == null)
{ mfs = new Vector();
ASTTerm.metafeatures.put(lit, mfs);
}
if (mfs instanceof Vector)
{
Vector stereotypes = (Vector) mfs;
if (stereotypes.contains(str)) {}
else
{ stereotypes.add(str);
ASTTerm.metafeatures.put(lit, stereotypes);
}
}
// JOptionPane.showMessageDialog(null,
// "*** addStereo " + str + " to " + lit + " Metafeatures of " + lit + " are " + mfs, "",
// JOptionPane.INFORMATION_MESSAGE);
}
public static void setTaggedValue(ASTTerm ast, String mf, String val)
{ // updates stereotypes of ast so that mf=val
String lit = ast.literalForm();
setTaggedValue(lit, mf, val);
}
public static void setTaggedValue(String lit, String mf, String val)
{ Object mfs = ASTTerm.metafeatures.get(lit);
System.out.println("*** " + lit + " has tagged values: " +
mfs);
if (mfs == null)
{ mfs = new Vector();
ASTTerm.metafeatures.put(lit,mfs);
}
if (mfs instanceof Vector)
{ Vector stereos = (Vector) mfs;
Vector newstereos = new Vector();
for (int x = 0; x < stereos.size(); x++)
{ String stereo = (String) stereos.get(x);
if (stereo.startsWith(mf + "="))
{ }
else
{ newstereos.add(stereo); }
}
newstereos.add(mf + "=" + val);
ASTTerm.metafeatures.put(lit,newstereos);
System.out.println("*** Set " + lit + " tagged values: " +
newstereos);
}
}
public void removeStereotype(String str)
{ String lit = literalForm();
Object mfs = ASTTerm.metafeatures.get(lit);
if (mfs == null)
{ mfs = new Vector();
ASTTerm.metafeatures.put(lit,mfs);
}
if (mfs instanceof Vector)
{
Vector stereotypes = (Vector) mfs;
Vector removed = new Vector();
removed.add(str);
stereotypes.removeAll(removed);
ASTTerm.metafeatures.put(lit,stereotypes);
}
}
public static void removeStereo(String lit, String str)
{ if (ASTTerm.metafeatures.get(lit) instanceof Vector)
{
Vector stereotypes =
(Vector) ASTTerm.metafeatures.get(lit);
if (stereotypes == null)
{ stereotypes = new Vector();
ASTTerm.metafeatures.put(lit,stereotypes);
}
Vector removed = new Vector();
removed.add(str);
stereotypes.removeAll(removed);
}
}
public boolean hasStereotype(String str)
{ String lit = literalForm();
Object mfs = ASTTerm.metafeatures.get(lit);
if (mfs == null)
{ return false; }
if (mfs instanceof Vector)
{ Vector stereotypes = (Vector) mfs;
return stereotypes.contains(str);
}
return false;
}
public static String getStereotypeValue(String lit)
{ Object stereo =
ASTTerm.metafeatures.get(lit);
System.out.println(">>>--- Global variable " + lit +
" has value " + stereo);
System.out.println();
if (stereo == null)
{ return ""; }
else
{ return "" + stereo; }
}
public static void setStereotypeValue(String lit, String val)
{ System.out.println(">>>--- Global variable " + lit +
" set to " + val);
System.out.println();
ASTTerm.metafeatures.put(lit,val);
}
public static Vector getStereotypes(String lit)
{ Object mfs = ASTTerm.metafeatures.get(lit);
if (mfs == null)
{ return new Vector(); }
if (mfs instanceof Vector)
{ return (Vector) mfs; }
return null;
}
public static Vector getStereotypes(ASTTerm t)
{ return getStereotypes(t.literalForm()); }
public static boolean hasTaggedValue(ASTTerm trm, String str)
{ String lit = trm.literalForm();
System.out.println("*** " + lit + " has tagged values: " +
ASTTerm.metafeatures.get(lit));
if (ASTTerm.metafeatures.get(lit) instanceof Vector)
{
Vector stereotypes =
(Vector) ASTTerm.metafeatures.get(lit);
if (stereotypes == null)
{ stereotypes = new Vector();
ASTTerm.metafeatures.put(lit,stereotypes);
}
for (int x = 0; x < stereotypes.size(); x++)
{ String stereo = (String) stereotypes.get(x);
if (stereo.startsWith(str + "="))
{ return true; }
}
return false;
}
return false;
}
public static String getTaggedValue(ASTTerm trm, String str)
{ String lit = trm.literalForm();
Object mfs = ASTTerm.metafeatures.get(lit);
if (mfs == null)
{ mfs = new Vector();
ASTTerm.metafeatures.put(lit,mfs);
}
System.out.println("*** " + lit + " gets tagged values: " +
mfs);
if (mfs instanceof Vector)
{ Vector stereotypes = (Vector) mfs;
for (int x = 0; x < stereotypes.size(); x++)
{ String stereo = (String) stereotypes.get(x);
if (stereo.startsWith(str + "="))
{ int indx = stereo.indexOf("=");
return stereo.substring(indx + 1);
}
}
}
return null;
}
public static void addRequiredLibrary(String lib)
{ if (requiredLibraries.contains(lib)) {}
else
{ requiredLibraries.add(lib); }
}
public static Vector getRequiredLibraries()
{ return requiredLibraries; }
public abstract ASTTerm removeOuterTag();
public abstract ASTTerm getTerm(int i);
public abstract Vector tokenSequence();
public abstract int termSize();
public abstract Vector getTerms();
public abstract Vector symbolTerms();
public abstract Vector nonSymbolTerms();
public abstract String toJSON();
public abstract String asTextModel(PrintWriter out);
public abstract String cg(CGSpec cgs);
public abstract String cgRules(CGSpec cgs, Vector rules);
// Only for programming languages.
public abstract boolean updatesObject(ASTTerm t);
public abstract boolean callSideEffect();
// Only for programming languages.
public abstract boolean hasSideEffect();
public abstract boolean isIdentifier();
public abstract String preSideEffect();
public abstract String postSideEffect();
public boolean hasMetafeature(String f)
{ String val = (String) metafeatures.get(f);
return val != null;
}
public void setMetafeature(String f, String val)
{ metafeatures.put(f,val); }
public String getMetafeatureValue(String f)
{ String val = (String) metafeatures.get(f);
return val;
}
public static void setType(ASTTerm t, String val)
{ String f = t.literalForm();
types.put(f,val);
}
public static void setElementType(ASTTerm t, String val)
{ String f = t.literalForm();
elementTypes.put(f,val);
}
public static void setType(String f, String val)
{ types.put(f,val); }
public static void setElementType(String f, String val)
{ elementTypes.put(f,val); }
public static String getType(String f)
{ String val = (String) types.get(f);
return val;
}
public static String getType(ASTTerm t)
{ String val = (String) types.get(t.literalForm());
if (val == null && t instanceof ASTBasicTerm)
{ ASTBasicTerm bt = (ASTBasicTerm) t;
return bt.getType();
}
return val;
}
public abstract Type deduceType();
public static String getElementType(ASTTerm t)
{ String val = ASTTerm.getType(t);
if (val != null)
{ Type typ = Type.getTypeFor(val,
ASTTerm.enumtypes, ASTTerm.entities);
if (typ != null && typ.elementType != null)
{ return typ.elementType + ""; }
}
val = (String) elementTypes.get(t.literalForm());
if (val != null)
{ Type etyp =
Type.getTypeFor(val,
ASTTerm.enumtypes, ASTTerm.entities);
if (etyp != null)
{ return etyp + ""; }
}
return "OclAny";
}
public boolean hasType(String str)
{ if ("character".equalsIgnoreCase(str))
{ return isCharacter(); }
if ("integer".equalsIgnoreCase(str) ||
"int".equals(str))
{ return isInteger(); }
if ("real".equalsIgnoreCase(str))
{ return isReal(); }
if ("boolean".equalsIgnoreCase(str))
{ return isBoolean(); }
if ("String".equalsIgnoreCase(str))
{ return isString(); }
if ("Sequence".equals(str))
{ return isSequence(); }
if ("StringSequence".equals(str))
{ return isStringSequence(); }
if ("IntegerSequence".equals(str))
{ return isIntegerSequence(); }
if ("RealSequence".equals(str))
{ return isRealSequence(); }
if ("BooleanSequence".equals(str))
{ return isBooleanSequence(); }
if ("Set".equals(str))
{ return isSet(); }
if ("Map".equals(str))
{ return isMap(); }
if ("Function".equals(str))
{ return isFunction(); }
if ("Collection".equals(str))
{ return isCollection(); }
if ("File".equals(str))
{ return isFile(); }
if ("Date".equals(str))
{ return isDate(); }
if ("Process".equals(str))
{ return isProcess(); }
String typ = ASTTerm.getType(this);
if (typ == null)
{ return false; }
return typ.equals(str);
}
public abstract boolean isLabeledStatement();
public abstract String getLabel();
public abstract Type pointersToRefType(String tname, Type t);
public static Entity introduceCStruct(String nme, Vector ents)
{ if (nme.equals("tm"))
{ Entity ent =
(Entity) ModelElement.lookupByName("OclDate", ents);
if (ent != null)
{ return ent; }
ent = new Entity("OclDate");
ent.addStereotype("component");
ent.addStereotype("external");
ents.add(ents.size()-1, ent);
return ent;
}
Entity ent = (Entity) ModelElement.lookupByName(nme, ents);
if (ent != null)
{ return ent; }
ent = new Entity(nme);
ent.addStereotype("struct");
ents.add(ents.size()-1, ent);
if ("div_t".equals(nme))
{ Attribute quot =
new Attribute("quot", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(quot);
Attribute rem =
new Attribute("rem", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(rem);
}
else if ("ldiv_t".equals(nme))
{ Attribute quot =
new Attribute("quot", new Type("long", null),
ModelElement.INTERNAL);
ent.addAttribute(quot);
Attribute rem =
new Attribute("rem", new Type("long", null),
ModelElement.INTERNAL);
ent.addAttribute(rem);
}
/* else if ("tm".equals(nme))
{ Attribute secs =
new Attribute("tm_sec", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(secs);
Attribute mins =
new Attribute("tm_min", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(mins);
Attribute hrs =
new Attribute("tm_hour", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(hrs);
Attribute days =
new Attribute("tm_mday", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(days);
Attribute months =
new Attribute("tm_mon", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(months);
Attribute years =
new Attribute("tm_year", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(years);
Attribute wday =
new Attribute("tm_wday", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(wday);
Attribute yday =
new Attribute("tm_yday", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(yday);
Attribute isdst =
new Attribute("tm_isdst", new Type("int", null),
ModelElement.INTERNAL);
ent.addAttribute(isdst);
} */
return ent;
}
public abstract Type cdeclarationToType(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract String cdeclarationStorageClass();
public abstract ModelElement cdeclaratorToModelElement(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Vector cdeclaratorToModelElements(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Vector cparameterListToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Attribute cparameterToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Statement cstatementToKM3(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Statement cupdateForm(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Statement cbasicUpdateForm(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Statement cpreSideEffect(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Statement cpostSideEffect(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Vector cstatementListToKM3(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
public static boolean cqueryFunction(String fname)
{ return cqueryfunctions.contains(fname); }
public abstract Vector cexpressionListToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Expression cexpressionToKM3(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
/* JavaScript abstraction: */
public abstract Vector jsclassDeclarationToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public boolean isDefinedFunction(Expression opexpr,
java.util.Map vartypes,
java.util.Map varelemtypes,
Vector types, Vector entities)
{ String opname = opexpr + "";
Type tt = (Type) vartypes.get(opname);
System.out.println(">>> Testing if " + opexpr + " : " + tt + " is a function");
if (tt != null && tt.isFunction())
{ return true; }
else if (tt != null)
{ return false; }
for (int i = 0; i < entities.size(); i++)
{ Entity ee = (Entity) entities.get(i);
if (ee.hasOperation(opname))
{ return true; }
}
for (int i = 0; i < entities.size(); i++)
{ Entity ee = (Entity) entities.get(i);
Attribute att = (Attribute) ee.getAttribute(opname);
if (att != null && att.isFunction())
{ return true; }
}
return false;
}
public abstract Expression jsexpressionToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector ents);
public abstract Vector jsexpressionListToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Vector jsupdateForm(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector ents);
public abstract Vector jscompleteUpdateForm(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector ents);
public abstract Vector jspreSideEffect(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector ents);
public abstract Vector jspostSideEffect(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector ents);
public abstract Vector jsvariableDeclarationToKM3(java.util.Map vartypes,
java.util.Map varelemtypes, Vector types, Vector entities);
public abstract Vector jsstatementToKM3(java.util.Map vartypes, java.util.Map varelemtypes, Vector types, Vector entities);
/* Java abstraction: */
public abstract String queryForm();
public abstract Vector getParameterExpressions();
public abstract String getJavaLabel();
public abstract boolean isJavaLabeledStatement();
public abstract ASTTerm getJavaLabeledStatement();
public abstract String getJSLabel();
public abstract boolean isJSLabeledStatement();
public abstract ASTTerm getJSLabeledStatement();
public abstract boolean isLocalDeclarationStatement();
public abstract String toKM3();
public abstract String toKM3type();
public abstract String typeArgumentsToKM3ElementType();
public abstract String lambdaParametersToKM3();
public boolean isAssignment()
{ return false; }
public boolean isCreation()
{ return false; }
public String toKM3Assignment()
{ return toKM3(); }
public String toKM3creation()
{ return toKM3(); }
public abstract String toKM3asObject(Entity ent);
public static boolean isInteger(String typ)
{ return
"int".equals(typ) || "short".equals(typ) ||
"byte".equals(typ) || "Integer".equals(typ) ||
"Short".equals(typ) || "Byte".equals(typ) ||
"BigInteger".equals(typ) || "integer".equals(typ) ||
"long".equals(typ) || "Long".equals(typ);
}
public static boolean isReal(String typ)
{ return
"float".equals(typ) || "double".equals(typ) ||
"BigDecimal".equals(typ) || "real".equals(typ) ||
"Float".equals(typ) || "Double".equals(typ);
}
public static boolean isString(String typ)
{ return
"String".equals(typ) || "Character".equals(typ) ||
"StringBuffer".equals(typ) || "char".equals(typ) ||
"StringBuilder".equals(typ);
}
public static boolean isBoolean(String typ)
{ return
"boolean".equals(typ) || "Boolean".equals(typ);
}
public boolean isString()
{ String litf = literalForm();
String typ = ASTTerm.getType(litf);
if (typ == null)
{ return Expression.isString(litf); }
return
"String".equals(typ) || "Character".equals(typ) ||
"StringBuffer".equals(typ) || "char".equals(typ) ||
"StringBuilder".equals(typ);
}
public boolean isCharacter()
{ String s = literalForm();
if (s.length() > 2 && s.startsWith("'") &&
s.endsWith("'"))
{ return true; }
return false;
}
public boolean isInteger()
{ String litf = literalForm();
String typ = ASTTerm.getType(litf);
if (typ == null)
{ return Expression.isInteger(litf) ||
Expression.isLong(litf);
}
return ASTTerm.isInteger(typ);
}
public boolean isReal()
{ String litf = literalForm();
String typ = ASTTerm.getType(litf);
if (typ == null)
{ return Expression.isDouble(litf); }
return ASTTerm.isReal(typ);
}
public boolean isNumber()
{ String litf = literalForm();
String typ = ASTTerm.getType(litf);
if (typ == null)
{ return Expression.isInteger(litf) ||
Expression.isLong(litf) ||
Expression.isDouble(litf);
}
return ASTTerm.isReal(typ) || ASTTerm.isInteger(typ);
}
public boolean isBoolean()
{ String litf = literalForm();
String typ = ASTTerm.getType(litf);
if (typ == null)
{ return "true".equalsIgnoreCase(litf) ||
"false".equalsIgnoreCase(litf);
}
return
"boolean".equals(typ) || "Boolean".equals(typ);
}
public boolean isCollection()
{ String typ = ASTTerm.getType(literalForm());
if (typ == null)
{ return false; }
if ("Sequence".equals(typ) || "Set".equals(typ) ||
"SortedSequence".equals(typ) ||
typ.startsWith("SortedSequence(") ||
typ.startsWith("Sequence(") || typ.startsWith("Set("))
{ return true; }
return false;
}
public boolean isSet()
{ String litform = literalForm();
if (litform != null &&
litform.startsWith("Set{") &&
litform.endsWith("}"))
{ return true; }
String typ = ASTTerm.getType(litform);
if (typ == null)
{ return false; }
if ("Set".equals(typ) || typ.startsWith("Set("))
{ return true; }
return false;
}
public boolean isSequence()
{ String litform = literalForm();
if (litform != null &&
litform.startsWith("Sequence{") &&
litform.endsWith("}"))
{ return true; }
String typ = ASTTerm.getType(litform);
if (typ == null)
{ return false; }
if ("Sequence".equals(typ) ||
typ.startsWith("Sequence(") ||
"SortedSequence".equals(typ) ||
typ.startsWith("SortedSequence("))
{ return true; }
return false;
}
public boolean isSortedSequence()
{ String litform = literalForm();