-
Notifications
You must be signed in to change notification settings - Fork 7
/
XMLPrinter.java
2486 lines (2230 loc) · 70.2 KB
/
XMLPrinter.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
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
package fortran.ofp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.antlr.runtime.Token;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import fortran.ofp.parser.java.IActionEnums;
import fortran.ofp.parser.java.IFortranParser;
/**
* XML output generator for Open Fortran Parser.
*
* @author Mateusz Bysiek https://mbdevpl.github.io/
*/
public class XMLPrinter extends XMLPrinterBase {
private static final Logger LOG = Logger.getLogger(XMLPrinter.class.getName());
public XMLPrinter(String[] args, IFortranParser parser, String filename) {
super(args, parser, filename);
}
protected void genericOperationForceOpen(int nodesCount) {
ArrayList<Element> nodes = contextNodes(-nodesCount, nodesCount);
contextOpen("operation");
if (nodesCount == 2)
setAttribute("type", "unary");
else if (nodesCount > 2)
setAttribute("type", "multiary");
else
cleanUpAfterError("didn't expect nodesCount=" + nodesCount);
for (Element node : nodes) {
boolean needsTransform = !node.getTagName().equals("operand") && !node.getTagName().equals("operator");
if (needsTransform)
contextOpen("operand");
moveHere(node);
if (needsTransform)
contextClose();
}
}
protected void genericOperationOpen(int numberOfOperators) {
if (numberOfOperators > 0) {
int nodesCount = 2 * numberOfOperators + 1;
genericOperationForceOpen(nodesCount);
}
}
protected void genericOperationClose(int numberOfOperators) {
if (numberOfOperators > 0)
contextClose();
}
protected void genericLoopControl(boolean hasStep) {
String[] contexts = { "lower-bound", "upper-bound", "step" };
int takenNodesCount = hasStep ? 3 : 2;
ArrayList<Element> takenNodes = contextNodes(-takenNodesCount, takenNodesCount);
context = contextNode(-takenNodesCount - 1);
for (int i = 0; i < takenNodes.size(); ++i) {
contextOpen(contexts[i]);
moveHere(takenNodes.get(i));
contextClose();
}
contextClose();
}
public void generic_name_list_part(Token id) {
contextOpen("name");
setAttribute("id", id);
if (verbosity >= 100)
super.generic_name_list_part(id);
contextClose();
}
public void generic_name_list__begin() {
if (context.getTagName().equals("specification") || context.getTagName().equals("file"))
contextOpen("declaration");
super.generic_name_list__begin();
}
public void specification_part(int numUseStmts, int numImportStmts, int numImplStmts, int numDeclConstructs) {
if (context.getTagName().equals("header")) {
contextClose("header");
contextOpen("body");
}
if (context.getTagName().equals("declaration")) {
LOG.log(Level.FINER, "closing unclosed declaration at specification_part");
contextClose("declaration");
}
if (!context.getTagName().equals("specification"))
contextOpen("specification");
contextCloseAllInner("specification");
if (verbosity >= 80)
super.specification_part(numUseStmts, numImportStmts, numImplStmts, numDeclConstructs);
setAttribute("uses", numUseStmts);
setAttribute("imports", numImportStmts);
setAttribute("implicits", numImplStmts);
setAttribute("declarations", numDeclConstructs);
contextClose();
contextOpen("statement");
}
public void declaration_construct() {
contextClose("declaration");
if (verbosity >= 100)
super.declaration_construct();
contextOpen("declaration");
}
public void execution_part_construct() {
if (verbosity >= 100)
super.execution_part_construct();
}
public void specification_stmt() {
if (verbosity >= 100)
super.specification_stmt();
}
public void executable_construct() {
if (verbosity >= 100)
super.executable_construct();
}
public void action_stmt() {
if (contextTryFind("statement") == null) {
// TODO this ugly workaround should be removed
contextClose();
Element element = contextNode(-1);
contextOpen("statement");
moveHere(element);
}
if (verbosity >= 100)
super.action_stmt();
contextClose("statement");
contextOpen("statement");
}
public void keyword() {
if (verbosity >= 100)
super.keyword();
}
public void name(Token id) {
super.name(id);
}
public void constant(Token id) {
super.constant(id);
}
public void scalar_constant() {
if (verbosity >= 100)
super.scalar_constant();
}
public void literal_constant() {
if (verbosity >= 100)
super.literal_constant();
contextClose("literal");
}
public void label(Token lbl) {
boolean closedLoop = false;
Element outerContext = context;
while (outerContext != root) {
if (outerContext.getTagName().equals("loop") && outerContext.getAttribute("label").equals(lbl.getText())) {
context = outerContext;
closedLoop = true;
break;
}
outerContext = (Element) outerContext.getParentNode();
}
super.label(lbl);
if (closedLoop)
contextOpen("statement");
}
public void type_param_value(boolean hasExpr, boolean hasAsterisk, boolean hasColon) {
Element value = hasExpr ? contextNode(-1): null;
contextOpen("type-attribute");
if (hasExpr)
moveHere(value);
super.type_param_value(hasExpr, hasAsterisk, hasColon);
contextClose();
}
public void intrinsic_type_spec(Token keyword1, Token keyword2, int type, boolean hasKindSelector) {
if (!context.getTagName().equals("declaration")) {
// TODO: ensure being in body
contextOpen("declaration");
}
setAttribute("type", "variable");
super.intrinsic_type_spec(keyword1, keyword2, type, hasKindSelector);
}
public void kind_selector(Token token1, Token token2, boolean hasExpression) {
if (hasExpression) {
Element value = contextNode(-1);
contextOpen("kind");
moveHere(value);
} else {
contextOpen("kind");
setAttribute("value", token2);
}
super.kind_selector(token1, token2, hasExpression);
contextClose();
}
public void int_literal_constant(Token digitString, Token kindParam) {
if (kindParam != null) {
Element kind = contextNode(-1);
assert kind.getTagName().equals("kind-param");
contextOpen("literal");
moveHere(kind);
} else {
contextOpen("literal");
}
setAttribute("type", "int");
setAttribute("value", digitString);
super.int_literal_constant(digitString, kindParam);
}
public void boz_literal_constant(Token constant) {
contextOpen("literal");
setAttribute("type", "int");
setAttribute("value", constant);
super.boz_literal_constant(constant);
}
public void real_literal_constant(Token realConstant, Token kindParam) {
if (kindParam != null) {
Element kind = contextNode(-1);
assert kind.getTagName().equals("kind-param");
contextOpen("literal");
moveHere(kind);
} else {
contextOpen("literal");
}
setAttribute("type", "real");
setAttribute("value", realConstant);
super.real_literal_constant(realConstant, kindParam);
}
public void char_selector(Token tk1, Token tk2, int kindOrLen1, int kindOrLen2, boolean hasAsterisk) {
int[] attribute_types = new int[]{kindOrLen2, kindOrLen1};
contextOpen("type-attributes");
Element localContext = context;
contextClose();
Element value = null;
for(int attribute_type: attribute_types) {
switch (attribute_type) {
case IActionEnums.KindLenParam_none:
break;
case IActionEnums.KindLenParam_len:
value = contextNode(-2);
moveTo(localContext, value);
contextRename(value, "type-attribute", "length");
break;
case IActionEnums.KindLenParam_kind:
value = contextNode(-2);
Element prevContext = context;
context = localContext;
contextOpen("kind");
moveHere(value);
contextClose();
context = prevContext;
break;
default:
throw new IllegalArgumentException(Integer.toString(attribute_type));
}
}
context = localContext;
if (value == null) {
contextClose();
context.removeChild(localContext);
}
super.char_selector(tk1, tk2, kindOrLen1, kindOrLen2, hasAsterisk);
if (value != null)
contextClose();
}
public void char_length(boolean hasTypeParamValue) {
Element value = contextNode(-1);
contextOpen("length");
moveHere(value);
if (hasTypeParamValue) {
moveHere(contextNodes(value));
context.removeChild(value);
}
super.char_length(hasTypeParamValue);
contextClose();
}
public void scalar_int_literal_constant() {
if (verbosity >= 100)
super.scalar_int_literal_constant();
contextClose("literal");
}
public void char_literal_constant(Token digitString, Token id, Token str) {
contextOpen("literal");
setAttribute("type", "char");
setAttribute("value", str);
super.char_literal_constant(digitString, id, str);
}
public void logical_literal_constant(Token logicalValue, boolean isTrue, Token kindParam) {
if (kindParam != null) {
Element kind = contextNode(-1);
assert kind.getTagName().equals("kind-param");
contextOpen("literal");
moveHere(kind);
} else {
contextOpen("literal");
}
setAttribute("type", "bool");
setAttribute("value", isTrue);
super.logical_literal_constant(logicalValue, isTrue, kindParam);
}
public void derived_type_stmt(Token label, Token keyword, Token id, Token eos, boolean hasTypeAttrSpecList,
boolean hasGenericNameList) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "type");
super.derived_type_stmt(label, keyword, id, eos, hasTypeAttrSpecList, hasGenericNameList);
}
public void derived_type_spec(Token typeName, boolean hasTypeParamSpecList) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "variable");
super.derived_type_spec(typeName, hasTypeParamSpecList);
}
public void array_constructor() {
context = contextNode(-1); // temporarily reopen previously-closed context
if (verbosity >= 100)
super.array_constructor();
contextClose(); // re-close previously closed context
}
public void ac_spec() {
context = contextNode(-1); // temporarily reopen previously-closed context
if (verbosity >= 100)
super.ac_spec();
contextClose(); // re-close previously closed context
}
public void ac_value() {
contextClose("value");
if (verbosity >= 100)
super.ac_value();
contextOpen("value");
}
public void ac_value_list__begin() {
contextOpen("array-constructor-values");
if (verbosity >= 100)
super.ac_value_list__begin();
contextOpen("value");
}
public void ac_value_list(int count) {
contextClose("value");
contextCloseAllInner("array-constructor-values", "array-constructor");
setAttribute("count", count);
if (verbosity >= 100)
super.ac_value_list(count);
contextClose();
}
public void ac_implied_do() {
super.ac_implied_do();
contextRename("array-constructor-values", "array-constructor");
contextOpen("value");
}
public void ac_implied_do_control(boolean hasStride) {
genericLoopControl(hasStride);
Element element = contextNode(-1);
contextClose("value");
contextOpen("header");
moveHere(element);
// contextClose("index-variable");
super.ac_implied_do_control(hasStride);
contextClose();
}
public void type_declaration_stmt(Token label, int numAttributes, Token eos) {
super.type_declaration_stmt(label, numAttributes, eos);
}
public void declaration_type_spec(Token udtKeyword, int type) {
ArrayList<Element> typeDeclarations = contextNodes();
contextOpen("type");
setAttribute("hasLength", false);
setAttribute("hasKind", false);
setAttribute("hasAttributes", false);
Attr n;
for (Element declaration : typeDeclarations) {
switch (declaration.getTagName()) {
case "intrinsic-type-spec":
n = getAttribute("name");
if (n != null)
new IllegalArgumentException(declaration.getTagName());
String name = declaration.getAttribute("keyword1");
if (declaration.getAttribute("keyword2").length() > 0)
name += " " + declaration.getAttribute("keyword2");
setAttribute("name", name);
setAttribute("type", "intrinsic");
break;
case "derived-type-spec":
n = getAttribute("name");
if (n != null)
new IllegalArgumentException(declaration.getTagName());
setAttribute("name", declaration.getAttribute("typeName"));
setAttribute("type", "derived");
break;
case "length":
setAttribute("hasLength", true);
break;
case "kind":
setAttribute("hasKind", true);
break;
case "type-attributes":
setAttribute("hasAttributes", true);
break;
default:
break;
}
moveHere(declaration);
}
super.declaration_type_spec(udtKeyword, type);
contextClose();
}
public void attr_spec(Token attrKeyword, int attr) {
Element preceeding = null;
String nestIn = "";
switch (attr) {
case IActionEnums.AttrSpec_access:
preceeding = contextNode(-1);
int accessType = Integer.parseInt(getAttribute("type", preceeding).getValue());
switch (accessType) {
case IActionEnums.AttrSpec_PUBLIC:
nestIn = "public";
break;
case IActionEnums.AttrSpec_PROTECTED:
nestIn = "protected";
break;
case IActionEnums.AttrSpec_PRIVATE:
nestIn = "private";
break;
default:
throw new IllegalArgumentException(Integer.toString(attr) + " - " + attrKeyword + ", type=" + Integer.toString(accessType));
}
break;
case IActionEnums.AttrSpec_language_binding:
// bind
break;
case IActionEnums.AttrSpec_ALLOCATABLE:
nestIn = "allocatable";
break;
case IActionEnums.AttrSpec_ASYNCHRONOUS:
nestIn = "asynchronous";
break;
case IActionEnums.AttrSpec_CODIMENSION:
nestIn = "codimension";
break;
case IActionEnums.AttrSpec_DIMENSION:
// dimension
break;
case IActionEnums.AttrSpec_EXTERNAL:
nestIn = "external";
break;
case IActionEnums.AttrSpec_INTENT:
// intent
break;
case IActionEnums.AttrSpec_INTRINSIC:
nestIn = "intrinsic";
break;
case IActionEnums.AttrSpec_OPTIONAL:
nestIn = "optional";
break;
case IActionEnums.AttrSpec_PARAMETER:
nestIn = "parameter";
break;
case IActionEnums.AttrSpec_POINTER:
nestIn = "pointer";
break;
case IActionEnums.AttrSpec_PROTECTED:
nestIn = "protected";
break;
case IActionEnums.AttrSpec_SAVE:
nestIn = "save";
break;
case IActionEnums.AttrSpec_TARGET:
nestIn = "target";
break;
case IActionEnums.AttrSpec_VALUE:
nestIn = "value";
break;
case IActionEnums.AttrSpec_VOLATILE:
nestIn = "volatile";
break;
default:
throw new IllegalArgumentException(Integer.toString(attr) + " - " + attrKeyword);
}
if (nestIn.length() > 0)
contextOpen("attribute-" + nestIn);
if (preceeding != null)
moveHere(preceeding);
super.attr_spec(attrKeyword, attr);
if (nestIn.length() > 0)
contextClose();
}
public void entity_decl(Token id, boolean hasArraySpec, boolean hasCoarraySpec, boolean hasCharLength,
boolean hasInitialization) {
contextCloseAllInner("variable");
super.entity_decl(id, hasArraySpec, hasCoarraySpec, hasCharLength, hasInitialization);
setAttribute("name", id);
setAttribute("hasInitialValue", hasInitialization);
contextClose();
contextOpen("variable");
}
public void entity_decl_list__begin() {
super.entity_decl_list__begin();
contextOpen("variable");
}
public void entity_decl_list(int count) {
contextClose("variable");
super.entity_decl_list(count);
}
public void initialization(boolean hasExpr, boolean hasNullInit) {
Element initialValue = contextNode(-1);
contextOpen("initial-value");
moveHere(initialValue);
super.initialization(hasExpr, hasNullInit);
contextClose();
}
public void access_spec(Token keyword, int type) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
super.access_spec(keyword, type);
}
public void language_binding_spec(Token keyword, Token id, boolean hasName) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
super.language_binding_spec(keyword, id, hasName);
}
public void array_spec(int count) {
contextCloseAllInner("dimensions");
if (verbosity >= 100)
super.array_spec(count);
setAttribute("count", count);
contextClose();
}
public void array_spec_element(int type) {
Element value = null;
Element value2 = null;
switch (type) {
case IActionEnums.ArraySpecElement_expr_colon_expr:
value2 = contextNode(-2);
case IActionEnums.ArraySpecElement_expr:
case IActionEnums.ArraySpecElement_expr_colon:
case IActionEnums.ArraySpecElement_expr_colon_asterisk:
value = contextNode(-1);
break;
case IActionEnums.ArraySpecElement_asterisk:
case IActionEnums.ArraySpecElement_colon:
break;
default:
throw new IllegalArgumentException(Integer.toString(type));
}
if (!context.getTagName().equals("dimensions"))
contextOpen("dimensions");
contextOpen("dimension");
switch (type) {
case IActionEnums.ArraySpecElement_expr:
setAttribute("type", "simple"); // (a)
moveHere(value);
break;
case IActionEnums.ArraySpecElement_expr_colon:
setAttribute("type", "upper-bound-assumed-shape"); // (a:)
moveHere(value);
break;
case IActionEnums.ArraySpecElement_expr_colon_expr:
setAttribute("type", "range"); // (a:b)
contextOpen("range");
contextOpen("lower-bound");
moveHere(value2);
contextClose();
contextOpen("upper-bound");
moveHere(value);
contextClose();
contextClose();
break;
case IActionEnums.ArraySpecElement_expr_colon_asterisk:
setAttribute("type", "upper-bound-assumed-size"); // (a:*)
moveHere(value);
break;
case IActionEnums.ArraySpecElement_asterisk:
setAttribute("type", "assumed-size"); // (*)
break;
case IActionEnums.ArraySpecElement_colon:
setAttribute("type", "assumed-shape"); // (:)
break;
default:
throw new IllegalArgumentException(Integer.toString(type));
}
super.array_spec_element(type);
contextClose();
}
public void intent_spec(Token intentKeyword1, Token intentKeyword2, int intent) {
contextOpen("intent");
switch (intent) {
case IActionEnums.IntentSpec_IN:
setAttribute("type", "in");
break;
case IActionEnums.IntentSpec_OUT:
setAttribute("type", "out");
break;
case IActionEnums.IntentSpec_INOUT:
setAttribute("type", "inout");
break;
default:
throw new IllegalArgumentException(Integer.toString(intent));
}
if (verbosity >= 100)
super.intent_spec(intentKeyword1, intentKeyword2, intent);
contextClose();
}
public void access_stmt(Token label, Token eos, boolean hasList) {
if (!context.getTagName().equals("declaration"))
cleanUpAfterError("tag name is not 'declaration' but '" + context.getTagName() + "'");
setAttribute("type", "access");
super.access_stmt(label, eos, hasList);
}
public void allocatable_decl_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "allocatables");
super.allocatable_decl_list__begin();
}
public void asynchronous_stmt(Token label, Token keyword, Token eos) {
if (!context.getTagName().equals("declaration")) {
Element value = contextNode(-1);
if (value.getTagName() != "names")
cleanUpAfterError("tag name is not 'names' but '" + value.getTagName() + "'");
contextOpen("declaration");
moveHere(value);
}
super.asynchronous_stmt(label, keyword, eos);
}
public void codimension_decl_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "codimensions");
super.codimension_decl_list__begin();
}
public void data_stmt_object() {
if (verbosity >= 100)
super.data_stmt_object();
}
public void data_stmt_object_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "data");
super.data_stmt_object_list__begin();
}
public void data_stmt_value(Token asterisk) {
contextCloseAllInner("values");
if (verbosity >= 100)
super.data_stmt_value(asterisk);
}
public void hollerith_literal_constant(Token hollerithConstant) {
contextOpen("literal");
setAttribute("type", "hollerith");
setAttribute("value", hollerithConstant);
super.hollerith_literal_constant(hollerithConstant);
}
public void dimension_stmt(Token label, Token keyword, Token eos, int count) {
contextCloseAllInner("variables");
setAttribute("count", count);
super.dimension_stmt(label, keyword, eos, count);
contextClose();
setAttribute("type", "variable-dimensions");
}
public void dimension_decl(Token id) {
Element value = contextNode(-1);
if (!context.getTagName().equals("variables")) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
contextOpen("variables");
}
contextOpen("variable");
setAttribute("name", id);
moveHere(value);
/*
if (contextTryFind("declaration") == null) {
contextOpen("declaration");
setAttribute("type", "dimension");
}
*/
super.dimension_decl(id);
contextClose("variable");
}
public void named_constant_def_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "parameter");
super.named_constant_def_list__begin();
}
public void named_constant_def(Token id) {
Element value = contextNode(-1);
contextOpen("constant");
setAttribute("name", id);
moveHere(value);
if (verbosity >= 100)
super.named_constant_def(id);
contextClose();
}
public void pointer_stmt(Token label, Token keyword, Token eos) {
super.pointer_stmt(label, keyword, eos);
if (!context.getTagName().equals("declaration"))
LOG.warning("pointer_stmt in unexpected context");
setAttribute("type", "pointer");
}
public void pointer_decl_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
super.pointer_decl_list__begin();
}
public void pointer_decl(Token id, boolean hasSpecList) {
contextOpen("name");
super.pointer_decl(id, hasSpecList);
setAttribute("id", id);
contextClose("name");
}
public void save_stmt(Token label, Token keyword, Token eos, boolean hasSavedEntityList) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "save");
super.save_stmt(label, keyword, eos, hasSavedEntityList);
}
public void saved_entity(Token id, boolean isCommonBlockName) {
contextOpen("name");
super.saved_entity(id, isCommonBlockName);
setAttribute("id", id);
contextClose();
}
public void target_decl_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "targets");
if (verbosity >= 100)
super.target_decl_list__begin();
}
public void target_decl_list(int count) {
// TODO Auto-generated method stub
super.target_decl_list(count);
}
public void value_stmt(Token label, Token keyword, Token eos) {
// TODO: get also label node if there is one
Element value = contextNode(-1);
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "value");
moveHere(value);
super.value_stmt(label, keyword, eos);
}
public void volatile_stmt(Token label, Token keyword, Token eos) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "volatile");
super.volatile_stmt(label, keyword, eos);
}
public void implicit_stmt(Token label, Token implicitKeyword, Token noneKeyword, Token eos,
boolean hasImplicitSpecList) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
if (verbosity >= 20)
super.implicit_stmt(label, implicitKeyword, noneKeyword, eos, hasImplicitSpecList);
setAttribute("type", "implicit");
setAttribute("subtype", noneKeyword == null ? "some" : "none");
contextClose("declaration");
contextOpen("declaration");
}
public void letter_spec(Token id1, Token id2) {
contextOpen("letter-range");
setAttribute("begin", id1);
setAttribute("end", id2);
if (verbosity >= 100)
super.letter_spec(id1, id2);
contextClose();
}
public void namelist_stmt(Token label, Token keyword, Token eos, int count) {
contextCloseAllInner("namelists");
super.namelist_stmt(label, keyword, eos, count);
setAttribute("count", count);
}
public void namelist_group_name(Token id) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "namelists");
contextOpen("namelists");
contextOpen("names");
if (verbosity >= 100)
super.namelist_group_name(id);
setAttribute("id", id);
}
public void namelist_group_object_list(int count) {
contextCloseAllInner("names");
setAttribute("count", count);
if (verbosity >= 100)
super.namelist_group_object_list(count);
contextClose();
}
public void equivalence_set_list__begin() {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "equivalence");
super.equivalence_set_list__begin();
contextOpen("equivalent");
}
public void equivalence_set_list(int count) {
contextClose("equivalent");
super.equivalence_set_list(count);
}
public void equivalence_object() {
contextClose("equivalent");
if (verbosity >= 100)
super.equivalence_object();
contextOpen("equivalent");
}
public void equivalence_object_list__begin() {
// TODO Auto-generated method stub
super.equivalence_object_list__begin();
}
public void equivalence_object_list(int count) {
// TODO Auto-generated method stub
super.equivalence_object_list(count);
}
public void common_block_name(Token id) {
if (!context.getTagName().equals("declaration"))
contextOpen("declaration");
setAttribute("type", "common");
super.common_block_name(id);
}
public void variable() {
if (verbosity >= 100)
super.variable();
setAttribute("type", "variable");
contextClose("name");
}
public void designator_or_func_ref() {
if (verbosity >= 100)
super.designator_or_func_ref();
setAttribute("type", "ambiguous");
contextClose("name");
}
public void substring_range(boolean hasLowerBound, boolean hasUpperBound) {
Element lowerBound = null;
Element upperBound = null;
if (hasLowerBound)
lowerBound = contextNode(-1);
if (hasUpperBound) {
upperBound = lowerBound;
if (hasLowerBound)
lowerBound = contextNode(-2);
else
lowerBound = null;
}
contextOpen("name");
contextOpen("range");
if (lowerBound != null) {
contextOpen("lower-bound");
moveHere(lowerBound);
contextClose();
}
if (upperBound != null) {
contextOpen("upper-bound");
moveHere(upperBound);
contextClose();
}
if (verbosity >= 100)
super.substring_range(hasLowerBound, hasUpperBound);
contextClose();
}
public void data_ref(int numPartRef) {
for (int i = 1; i < numPartRef; ++i) {
assert context.getTagName().equals("name");
Element innerName = context;
ArrayList<Element> elements = contextNodes();
Attr innerNameId = getAttribute("id");
contextClose();
assert context.getTagName().equals("name");
moveHere(elements);
setAttribute("id", getAttribute("id").getValue() + "%" + innerNameId.getValue());
context.removeChild(innerName);
}
super.data_ref(numPartRef);
}
public void part_ref(Token id, boolean hasSectionSubscriptList, boolean hasImageSelector) {
Element e = null;
if (hasSectionSubscriptList) {
e = contextNode(-1);
if (!e.getTagName().equals("subscripts"))
cleanUpAfterError("tag name is not 'subscripts' but '" + e.getTagName() + "'");
}
contextOpen("name");
setAttribute("id", id);
setAttribute("hasSubscripts", hasSectionSubscriptList);
if (hasSectionSubscriptList)
moveHere(e);
if (verbosity >= 60)
super.part_ref(id, hasSectionSubscriptList, hasImageSelector);
}
public void section_subscript(boolean hasLowerBound, boolean hasUpperBound, boolean hasStride,
boolean isAmbiguous) {
// contextCloseAllInner("subscript");
Element outerContext = context;
contextOpen("subscript");
if (!hasLowerBound && !hasUpperBound && !hasStride)
setAttribute("type", "empty");
else if (hasLowerBound && !hasUpperBound && !hasStride) {
setAttribute("type", "simple");
moveHere(contextNode(outerContext, -2));
} else {
setAttribute("type", "range");
Element lowerBound = null;
Element upperBound = null;
Element step = null;
contextOpen("range");
if (hasLowerBound) {
lowerBound = contextOpen("lower-bound");
contextClose();
}
if (hasUpperBound) {
upperBound = contextOpen("upper-bound");
contextClose();
}
if (hasStride) {
step = contextOpen("step");