forked from ag2888/translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateCplusplusHeader.java
941 lines (589 loc) · 37 KB
/
CreateCplusplusHeader.java
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
package oop;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import xtc.lang.JavaFiveParser;
import xtc.lang.CParser;
import xtc.lang.JavaPrinter;
import xtc.lang.CPrinter;
import java.util.regex.*;
import xtc.parser.ParseException;
import xtc.parser.Result;
import xtc.tree.GNode;
import xtc.tree.Node;
import xtc.tree.Visitor;
import java.util.*;
import xtc.util.Tool;
import oop.GetDependencies;
import oop.InheritanceHandler;
import oop.ASTConverter;
import oop.CPPrinter;
import java.io.*;
/* Created by Ankit Goel**/
public class CreateCplusplusHeader extends xtc.util.Tool {
final GNode classTree;
GNode createCplusplusHeader;
public CreateCplusplusHeader(GNode n) {
classTree = n;
/*Debug**/
// p1.println(classTree.size());
final PrintWriter p1;
final GNode[] containsRelevantClasses;
final ArrayList<String> stringClasses = new ArrayList<String>();
final ArrayList<Integer> countClasses = new ArrayList<Integer>();
final ArrayList<Integer> countChildren = new ArrayList<Integer>();
final GNode stac = GNode.create("Holder");
File headerFile;
File newDirectory;
try {
newDirectory = new File("cplusplusfiles");
newDirectory.mkdir();
headerFile = new File("cplusplusfiles", "Header.h");
headerFile.createNewFile();
p1 = new PrintWriter(headerFile);
/*Remove comments below to Debug**/
// p1.println(classTree.size());
// p1.println(containsRelevantClasses.size());
// p1.println(countClasses);
// p1.println(countChildren);
p1.println("// Ankit Goel's Header");
p1.println("#pragma once");
p1.println();
p1.println("#include <stdint.h>");
p1.println("#include <string>");
p1.println();
p1.println("using namespace java::lang;");
p1.println("// Foward Declarations ");
p1.println();
/* Remove comments below to Debug**/
// String s = classTree.getNode(1).getNode(0).getNode(0).getName();
// p1.println(s);
// p1.flush();
// p1.close();
new Visitor() {
int counter22 = 0;
public void visitClass(GNode n ) {
counter22++;
countChildren.add(n.size());
countClasses.add(counter22);
visit(n);
}
public void visitClassHeaderDeclaration(GNode n) {
stac.add(n);
/*Remove comments below to Debug**/
//p1.println(n.getNode(0).getName());
//containsRelevantClasses[counter22] = (GNode) n;
}
public void visit(Node n) {
for (Object o : n) if (o instanceof Node) dispatch((Node) o);
}
}.dispatch(classTree);
/*Remove comments below to Debug**/
// p1.println(stac.size());
String globalVariableArrayCheck;
for ( int b = 4; b < stac.size(); b++) {
createCplusplusHeader = (GNode)stac.getNode(b);
GNode vMethods = (GNode) createCplusplusHeader.getNode(0);
//p1.println(createCplusplusHeader.getName());
/*Remove comments below to Debug**/
// p1.println(vMethods.getName());
// We need a mapping of methodName to accessibility
final HashMap<String,String> mNAccess = new HashMap<String,String>();
/*Remove comments below to Debug**/
// We need a mapping to methodName to whetherItsStatic
// p1.println(mNAccess);
// p1.println(mNAccess.get("goel"));
final GNode constructorPrinter = GNode.create("ConstructorPrinter");
final ArrayList<Integer> getCounter = new ArrayList<Integer>();
new Visitor() {
int counter2 = 0;
public void visitVirtualMethodDeclaration(GNode n ) {
counter2++;
getCounter.add(counter2);
}
public void visit(Node n) {
for (Object o : n) if (o instanceof Node) dispatch((Node) o);
}
}.dispatch(vMethods);
int startHere = getCounter.get(getCounter.size()-1) + 1;
/*Remove comments below to Debug**/
// p1.println(startHere);
final String className = vMethods.getNode(startHere).getNode(4).getNode(0).getString(0);
final String plainClassName = className.substring(2, className.length());
final GNode ARRAYTRACKER = GNode.create("ArrayTracker");
// Need another dispatch for constructor heeader node
new Visitor() {
public void visitConstructorHeader(GNode n ) {
// Add each node
if(n.getString(0).equals(plainClassName))
constructorPrinter.add(n);
}
public void visitCustomArrayDeclaration(GNode n) {
ARRAYTRACKER.add(n);
}
public void visit(Node n) {
for (Object o : n) if (o instanceof Node) dispatch((Node) o);
}
}.dispatch(createCplusplusHeader);
// p1.println(constructorPrinter.size());
// Find out when the virtual method declarations ends
/*Remove comments below to Debug**/
// p1.println(getCounter);
p1.println("struct __" + plainClassName + ";");
p1.println();
p1.println("struct __" + plainClassName + "_VT;");
p1.println();
p1.println("typedef __rt::Ptr<" + "__" + plainClassName + "> " + plainClassName + ";");
p1.println();
p1.println("struct __" + plainClassName + " { " );
p1.println();
p1.println(" // The data layout for java.lang.plainClassName");
p1.println(" " + "__" + plainClassName + "_VT* __vptr;");
// Get the Field Decl in this
final GNode fields = GNode.create("Fields");
new Visitor() {
public void visitDataLayoutDeclaration(GNode n) {
visit(n);
}
public void visitDataFieldList(GNode n) {
fields.add(n);
}
public void visit(Node n) {
for (Object o : n) if (o instanceof Node) dispatch((Node) o);
}
}.dispatch(createCplusplusHeader);
// p1.println(fields.size());
final ArrayList<String> privateOrpublic = new ArrayList<String>();
final ArrayList<String> PrimitiveType = new ArrayList<String>();
final ArrayList<String> Decl = new ArrayList<String>();
new Visitor() {
public void visitDataFieldList(GNode n) {
visit(n);
}
public void visitFieldDeclaration(GNode n) {
//if (n.getNode(0).size() > 0 )
//privateOrpublic.add(n.getNode(0).getNode(0).getString(0));
/*
if (n.getNode(0).getNode(0).getString(0).equals("static") && n.getNode(1).getNode(0).getString(0).equals("int") )
PrimitiveType.add("static const int32_t ");
**/
if ( n.getNode(1).getNode(0).getString(0).equals("int") && n.toString().contains("static"))
PrimitiveType.add(" static int32_t");
else
PrimitiveType.add(n.getNode(1).getNode(0).getString(0));
Decl.add(n.getNode(2).getNode(0).getString(0));
/*
else
Decl.add(n.getNode(2).getNode(0).getString(0) + " = " + n.getNode(2).getNode(0).getNode(2).getString(0));
**/
}
public void visit(Node n) {
for (Object o : n) if (o instanceof Node) dispatch((Node) o);
}
}.dispatch(fields);
// Print out the Data Fields
for ( int c = 0; c < Decl.size(); c++) {
p1.println();
p1.println( " " + PrimitiveType.get(c) + " " + Decl.get(c) + ";");
}
List<String> typeOfParameter = new ArrayList<String>();
List<String> DECLARATOR = new ArrayList<String>();
//p1.println(constructorPrinter);
for ( int ccd = 0; ccd < constructorPrinter.size(); ccd++) {
// There is more than one parameter
if(constructorPrinter.getNode(ccd).getNode(1).size() >= 1) {
GNode GETPARAMS = GNode.create("GETPARAMS");
GETPARAMS.add(constructorPrinter.getNode(ccd).getNode(1));
//p1.println(GETPARAMS);
// Now Go through the Formal Parameters
for ( int dcc = 0; dcc < GETPARAMS.size(); dcc++) {
typeOfParameter.add(GETPARAMS.getNode(0).getNode(dcc).getNode(1).getNode(0).getString(0));
DECLARATOR.add(GETPARAMS.getNode(0).getNode(dcc).getString(3));
}
}
else {
p1.println();
p1.println(" " + className + "();");
}
}
if ( DECLARATOR.size() >= 1 && typeOfParameter.size() >= 1) {
p1.print(className + "( ");
for ( int goela = 0; goela < typeOfParameter.size(); goela++) {
if(goela != typeOfParameter.size()-1)
p1.print( typeOfParameter.get(goela) + " " + DECLARATOR.get(goela) + ",");
else
p1.print( typeOfParameter.get(goela) + " " + DECLARATOR.get(goela) + ");");
}
}
p1.println();
if ( (constructorPrinter.size() == 0)) {
p1.println();
p1.println(" " + "// The Constructor");
p1.println();
p1.println(" " + "__" + plainClassName + "(); ");
}
//Find Instance Methods of the class Basically go through vtMethodPointersList and
// go through its children and check if the qualified identifier is the same as the clas name
// Store the names in a Arraylist type
final List<String> names = new ArrayList<String>();
List<String> types2 = new ArrayList<String>();
final List<Integer> indexx = new ArrayList<Integer>();
final HashMap<Integer, String> checkForOtherSuperClass = new HashMap<Integer, String>();
//final HashMap<String,String> checkForPredefinedMethods = new HashMap<String,String>();
// Basically You need to consider this fact there will be however so many Constructors and you need to keep a tally to start it like that and
// Ignore those indices
final List<Integer> constuctorIndex = new ArrayList<Integer>();
final GNode constructors = GNode.create("CONSTRUCTOR");
final String constructorNameGetter = plainClassName;
// p1.println(constructors.size());
//p1.println(constructorNameGetter);
// Lets find out which methods are unique
new Visitor() {
public int counter = 0;
public void visitVTConstructorDeclaration(GNode n) {
visit(n);
}
public void visitvtMethodPointersList(GNode n) {
visit(n);
}
public void visitvtMethodPointer(GNode n) {
counter++;
if( !(n.getNode(1).getString(1).equals("__Object")) && !(n.getString(0).equals("main_String")) ) {
// constructorIndex.add(counter);
// p1.println(n.getString(0));
indexx.add(counter);
names.add(n.getString(0));
// There needs to be a check for the other than __Object && __SuperClass
checkForOtherSuperClass.put(counter, n.getNode(1).getString(1));
// checkForPredefinedMethods.put(n.getString(0), n.getNode(1).getString(1));
}
else {
checkForOtherSuperClass.put(counter, n.getNode(1).getString(1));
// constructors.add(n);
}
}
public void visit(Node n) {
for (Object o : n) if (o instanceof Node) dispatch((Node) o);
}
}.dispatch(vMethods);
// p1.println(names);
// p1.println("Constructors" + constructors.size());
// p1.println(checkForOtherSuperClass);
// System.out.println("ARRAY CONTENTS" + names);
// Now lets get the type of the method and store it in Types arraylist
// Visit the Method Declarations of the Java AST and store the types in order into an array. Then
// store the corresponding names of the methods in another array then do matching to determine the
// the types of the method
// p1.println(checkForOtherSuperClass);
for ( int i = 0; i < indexx.size(); i++ ) {
if( vMethods.getNode(indexx.get(i)).getGeneric(0) != null ) {
if(vMethods.getNode(indexx.get(i)).getNode(0).getName().equals("Type")) {
// I think there only needs to be one check for a bool value the rest translate as is
if(vMethods.getNode(indexx.get(i)).getNode(0).getNode(0).getString(0).equals("boolean"))
types2.add("bool");
else
types2.add(vMethods.getNode(indexx.get(i)).getNode(0).getNode(0).getString(0));
}
else
types2.add("void");
}
else {
types2.add(" ");
}
}
//p1.println(types2);
// p1.println(names);
// params are appended to the methods name
List<String> specialnames = new ArrayList<String>();
// A single method name which is a string could essential map to however many Strings
Map<String, String> parameters = new HashMap<String,String>();
// Remove anything after _ in the method these are the parameters that are appended to it
for ( int i = 0; i < names.size(); i++ ) {
Pattern p = Pattern.compile("_");
Matcher m = p.matcher(names.get(i));
if(m.find()) {
// p1.println("FOUND");
// p1.println(m.start());
// ****** Changed
// specialnames.add(names.get(i).substring(0,m.start()));
specialnames.add(names.get(i));
// Money.add(names.get(i));
parameters.put(specialnames.get(i), names.get(i).substring(m.start(),names.get(i).length()));
}
else {
specialnames.add(names.get(i));
// The hashmap needs to be consistent
parameters.put(names.get(i), "ZeroParams");
}
}
//p1.println(names);
// p1.println(parameters);
//p1.println(types2);
//p1.println(parameters);
// Now print the instance methods using the types and names
p1.println(" // The instance methods of java.lang.plainClassName");
// p1.println(specialnames);
// Constructor Initializeer
p1.println(" static " + plainClassName + " init_Construct( " + plainClassName + "); ");
for ( int i = 0; i < types2.size(); i++) {
if ( parameters.get(specialnames.get(i)).equals("ZeroParams") && !(specialnames.get(i).equals(plainClassName)))
p1.println(" " + "static " + types2.get(i) + " " + specialnames.get(i) + "( " + plainClassName + ")" + ";" );
else {
if ( !(specialnames.get(i).equals(plainClassName)) ) {
ArrayList<Integer> getTheParameters = new ArrayList<Integer>();
p1.print(" " + "static " + types2.get(i) + " " + specialnames.get(i) + "( " + plainClassName + " , " );
Pattern pp = Pattern.compile("_");
Matcher mm = pp.matcher(parameters.get(specialnames.get(i)));
while (mm.find()) {
getTheParameters.add(mm.start());
}
for ( int cc = 0; cc < getTheParameters.size(); cc++ ) {
if ( cc != getTheParameters.size()-1) {
p1.print( parameters.get(specialnames.get(i)).substring(getTheParameters.get(cc) + 1, getTheParameters.get(cc+1)) + " , ");
}
else {
int length = parameters.get(specialnames.get(i)).length();
p1.print( parameters.get(specialnames.get(i)).substring(getTheParameters.get(cc) + 1, length) + ");");
}
}
p1.println();
}
}
}
p1.println();
p1.println(" // The Function returning the class Object representing java.lang.plainClassName " );
p1.println(" static Class __class(); ");
p1.println(" static void init( " + "__" + plainClassName+ "*" + " );");
p1.println();
// Changes for Command line arguements
if ( plainClassName.contains("Test")) {
p1.println(" static void main(__rt::Ptr<__rt::Array<String> > args);");
}
p1.println(" static __" + plainClassName + "_" + "VT " + "__vtable;");
p1.println();
p1.println(" };");
p1.println();
// Now print the Constructor taking into account which ones are implemented by the given class
p1.println("struct __" + plainClassName + "_" + "VT" + "{");
p1.println(" Class __isa;");
// Introduce some logic to differentiate between new methods and predefined inherited method from Object
List<String> arr1 = new ArrayList<String>();
arr1.add("hashcode");
arr1.add("equals");
arr1.add("getClass");
arr1.add("toString");
arr1.add("getName");
arr1.add("getSuperClass");
arr1.add("isInstance");
// Basically iterate through map and add any methods that have a type not equal to the
// You need to add the inherited types
p1.println(" void (*__delete)(__" + plainClassName + "*);");
p1.println(" int32_t (*hashCode)(" + plainClassName + ");");
p1.println(" bool (*equals)(" + plainClassName + " , " + "Object);");
p1.println(" Class (*getClass)(" + plainClassName + ");");
p1.println(" String (*toString) (" + plainClassName + ");");
for ( int i = 0; i < names.size(); i++ ) {
if ( !(arr1.contains(names.get(i)))) {
p1.println();
ArrayList<Integer> getTheParameters = new ArrayList<Integer>();
if ( parameters.get(specialnames.get(i)).equals("ZeroParams") && !(specialnames.get(i).equals(plainClassName)))
p1.println(" " + types2.get(i) + " (*" + specialnames.get(i) + ") (" + plainClassName + ");" );
else {
if ( !(specialnames.get(i).equals(plainClassName)) ) {
Pattern pp = Pattern.compile("_");
Matcher mm = pp.matcher(parameters.get(specialnames.get(i)));
while (mm.find()) {
getTheParameters.add(mm.start());
}
p1.print(" " + types2.get(i) + " (*" + specialnames.get(i) + ") (" + plainClassName + " , " );
for ( int cc = 0; cc < getTheParameters.size(); cc++ ) {
if ( cc != getTheParameters.size()-1) {
p1.print( parameters.get(specialnames.get(i)).substring(getTheParameters.get(cc) + 1, getTheParameters.get(cc+1)) + " , ");
}
else {
int length = parameters.get(specialnames.get(i)).length();
p1.print( parameters.get(specialnames.get(i)).substring(getTheParameters.get(cc) + 1, length) + ");");
}
}
}
//p1.println(getTheParameters);
}
}
}
p1.println();
p1.println();
// Now the constructor initilization inlined in the header
p1.println(" __" + plainClassName + "_VT()");
p1.println(" : __isa(__" + plainClassName + "::__class()),");
List<String> getImplementation = new ArrayList<String>();
int COUNT = 0;
// Are there any instance methods
for ( int i = 0; i < specialnames.size(); i++ ) {
if ( !(specialnames.equals(plainClassName)))
COUNT++;
}
// p1.println(COUNT);
for ( int i = 0; i < arr1.size(); i++) {
if( names.contains(arr1.get(i)) ) {
// Suppose a super class defines an Object method then this is wrong so add an additional check
//if(checkForPredefinedMethods.get(arr1.get(i)).equals("__" + plainClassName))
getImplementation.add(plainClassName);
//else
// getImplementation.add(checkForPredefinedMethods.get(arr1.get(i)));
}
else {
getImplementation.add("Object");
}
}
// Remove comment to Debug
//p1.println(getImplementation);
p1.println(" __delete(&__rt::__delete<__" + plainClassName + ">),");
// Hardcoded May Need to Change in the final Phase
if ( getImplementation.get(0).equals("Object"))
p1.println(" hashCode((int32_t(*)(" + plainClassName + "))" + "&__" + getImplementation.get(0) + "::hashCode),");
else
p1.println(" hashCode(&__" + plainClassName + "::hashCode),");
if (getImplementation.get(1).equals("Object"))
p1.println(" equals((bool(*)(" + plainClassName + " , Object)) &__" + getImplementation.get(1) + "::equals), ");
else
p1.println(" equals(&__" + plainClassName + "::equals");
if (getImplementation.get(2).equals("Object"))
p1.println(" getClass((Class(*)(" + plainClassName + ")) &__" + getImplementation.get(2) + "::getClass), ");
else
p1.println(" getClass(&__" + plainClassName + ")");
// Remember to Take care of the comma issue
if (getImplementation.get(3).equals("Object") /*|| !(getImplementation.get(3).equals("__" + plainClassName))**/) {
if(COUNT != 0)
p1.println(" toString((String(*)(" + plainClassName + ")) &__" + getImplementation.get(3) + "::toString), ");
else
p1.println(" toString((String(*)(" + plainClassName + ")) &__" + getImplementation.get(3) + "::toString) { ");
}
else {
int x = names.size();
boolean bat = false;
if((x==1) && (names.get(0).equals("toString")))
bat = true;
if(COUNT != 0 && !(bat) )
p1.println(" toString(&__" + getImplementation.get(3) + "::toString),");
else
p1.println(" toString(&__" + getImplementation.get(3) + "::toString) {");
}
//p1.println(names);
//
for ( int uniqueNames = 0; uniqueNames < names.size(); uniqueNames++) {
// Remove Unnecessary Methods
if(arr1.contains(names.get(uniqueNames))) {
names.remove(uniqueNames);
specialnames.remove(uniqueNames);
types2.remove(uniqueNames);
}
}
//p1.println(types2);
// p1.println(names);
// ADD Remaining Methods to implementation
for ( int i = 0; i < names.size(); i++) {
if(!(arr1.contains(specialnames.get(i))) && checkForOtherSuperClass.get(i+6).equals(className) && (i==names.size()-1) && !(specialnames.get(i).equals(plainClassName))) {
// Remember to Fix this later
p1.println();
p1.println(" " + specialnames.get(i) + "(&__" + plainClassName + "::" + specialnames.get(i) + ") {");
}
// Finally Add Parameters Here
else {
if ( parameters.get(specialnames.get(i)).equals("ZeroParams") && !(specialnames.get(i).equals(plainClassName)) && !(arr1.contains(specialnames.get(i)))){
if(i!=names.size()-1)
p1.println(" " + specialnames.get(i) + "((" + types2.get(i) + "(*)" + "(" + plainClassName + "))" + "&" + checkForOtherSuperClass.get(i+6) + "::" + specialnames.get(i) + "),");
else
p1.println(" " + specialnames.get(i) + "((" + types2.get(i) + "(*)" + "(" + plainClassName + "))" + "&" + checkForOtherSuperClass.get(i+6) + "::" + specialnames.get(i) + ") {");
p1.println();
}
else {
if(!(specialnames.get(i).equals(plainClassName)) && !(arr1.contains(specialnames.get(i))) ) {
ArrayList<Integer> getTheParameters = new ArrayList<Integer>();
p1.print(" " + specialnames.get(i) + "((" + types2.get(i) + "(*)" + "(" + plainClassName + " , ");
Pattern pp = Pattern.compile("_");
Matcher mm = pp.matcher(parameters.get(specialnames.get(i)));
while (mm.find()) {
getTheParameters.add(mm.start());
}
for ( int cc = 0; cc < getTheParameters.size(); cc++ ) {
if ( cc != getTheParameters.size()-1) {
p1.print( parameters.get(specialnames.get(i)).substring(getTheParameters.get(cc) + 1, getTheParameters.get(cc+1)) + " , ");
}
else {
int length = parameters.get(specialnames.get(i)).length();
p1.print( parameters.get(specialnames.get(i)).substring(getTheParameters.get(cc) + 1, length));
if(i!=names.size()-1)
p1.print("))" + "&" + checkForOtherSuperClass.get(i+6) + "::" + specialnames.get(i) + "),");
else
p1.print("))" + "&" + checkForOtherSuperClass.get(i+6) + "::" + specialnames.get(i) + ") {");
p1.println();
}
}
//p1.println(getTheParameters);
}
}
}
}
p1.println(" }");
p1.println("};");
p1.println();
p1.println();
p1.println();
/*Remove comments below to Debug**/
}
//p1.println(names);
p1.flush();
p1.close();
}
catch ( Exception e) {
}
}
public String getName() {
return "Java to C++ Translator";
}
public String getCopy() {
return "(C) 2013 Group Group";
}
public void init() {
super.init();
// Declare command line arguments.
runtime.
bool("printJavaAST", "printJavaAST", false, "Print Java AST.").
bool("printJavaCode", "printJavaCode", false, "Print Java code.").
bool("countMethods", "countMethods", false, "Count all Java methods.").
bool("translate", "translate", false, "Translate from Java to C++.").
bool("findDependencies", "findDependencies", false, "Find all Dependencies of given Java file.");
}
public void prepare() {
super.prepare();
// Perform consistency checks on command line arguments.
}
public File locate(String name) throws IOException {
File file = super.locate(name);
if (Integer.MAX_VALUE < file.length()) {
throw new IllegalArgumentException(file + ": file too large");
}
return file;
}
public Node parse(Reader in, File file) throws IOException, ParseException {
JavaFiveParser parser =
new JavaFiveParser(in, file.toString(), (int)file.length());
Result result = parser.pCompilationUnit(0);
return (Node)parser.value(result);
}
public Node Cparse(Reader in, File file) throws IOException, ParseException {
CParser parser =
new CParser(in, file.toString(), (int)file.length());
Result result = parser.pTranslationUnit(0);
return (Node)parser.value(result);
}
public void process(Node node) {
if (runtime.test("printJavaAST")) {
runtime.console().format(node).pln().flush();
}
if (runtime.test("printJavaCode")) {
new CPrinter(runtime.console()).dispatch(node);
runtime.console().flush();
}
}
}