Skip to content

Commit 3f85139

Browse files
committed
wip
1 parent 40901ce commit 3f85139

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

src/fortran/ofp/XMLPrinter.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fortran.ofp;
22

3+
import java.io.File;
4+
import java.io.IOException;
35
import java.util.ArrayList;
46
import java.util.Arrays;
57

@@ -8,6 +10,7 @@
810
import org.w3c.dom.Element;
911

1012
import fortran.ofp.parser.java.IFortranParser;
13+
import fortran.ofp.parser.java.TokensList;
1114

1215
/**
1316
* XML output generator for Open Fortran Parser.
@@ -2343,9 +2346,43 @@ public void dummy_arg_list(int count) {
23432346
contextClose();
23442347
}
23452348

2349+
protected void printTokens(Token... tokens) {
2350+
for (Token token : tokens) {
2351+
if (token == null) {
2352+
System.err.println("token is null");
2353+
continue;
2354+
}
2355+
int line = token.getLine();
2356+
int colBegin = token.getCharPositionInLine();
2357+
String text = token.getText();
2358+
int colEnd = colBegin + text.length();
2359+
System.err.println(filename + "@" + line + ":" + colBegin + "~" + colEnd + ": \"" + text + "\"");
2360+
}
2361+
/*
2362+
try {
2363+
TokensList tokens = new TokensList(new File(filename), false);
2364+
System.err.println("found tokens: " + tokens);
2365+
} catch (IOException e) {
2366+
}
2367+
*/
2368+
}
2369+
23462370
public void end_subroutine_stmt(Token label, Token keyword1, Token keyword2, Token name, Token eos) {
23472371
contextCloseAllInner("subroutine");
2372+
//System.err.println(Arrays.toString(getBounds(context)));
2373+
//updateBounds(name);
2374+
//updateBounds(eos);
2375+
//System.err.println(Arrays.toString(getBounds(context)));
2376+
System.err.println("end subroutine statments");
23482377
super.end_subroutine_stmt(label, keyword1, keyword2, name, eos);
2378+
System.err.println(Arrays.toString(getBounds(context)));
2379+
System.err.println(Arrays.toString(getBounds(context)));
2380+
updateBounds(label, keyword1, keyword2, name, eos);
2381+
System.err.println(Arrays.toString(getBounds(context)));
2382+
printTokens(label, keyword1, keyword2, name, eos);
2383+
System.err.println(Arrays.toString(getBounds(context)));
2384+
//updateBounds(eos);
2385+
//System.err.println(Arrays.toString(getBounds(context)));
23492386
contextClose();
23502387
}
23512388

src/fortran/ofp/XMLPrinterBase.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,16 +455,59 @@ protected void updateBounds(Element context, Integer new_line_begin, Integer new
455455
Integer new_col_end) {
456456
Integer[] bounds = getBounds(context);
457457
Integer line_begin = bounds[0], col_begin = bounds[1], line_end = bounds[2], col_end = bounds[3];
458-
if (new_line_begin != null && (line_begin == null || new_line_begin < line_begin))
458+
459+
if (new_line_begin == null && new_col_begin == null && new_line_end == null && new_col_end == null)
460+
return;
461+
if (new_line_begin == null || new_col_begin == null || new_line_end == null || new_col_end == null)
462+
throw new IllegalArgumentException("the implementation of this method is all-or-nothing");
463+
464+
boolean updateLineBegin = false;
465+
boolean updateColBegin = false;
466+
boolean updateLineEnd = false;
467+
boolean updateColEnd = false;
468+
469+
if (line_begin == null && col_begin == null && line_end == null && col_end == null) {
470+
updateLineBegin = true;
471+
updateColBegin = true;
472+
updateLineEnd = true;
473+
updateColEnd = true;
474+
} else if (line_begin == null || col_begin == null || line_end == null || col_end == null)
475+
throw new IllegalArgumentException("the implementation of this method is all-or-nothing");
476+
else {
477+
if (new_line_begin < line_begin)
478+
updateLineBegin = true;
479+
480+
if (updateLineBegin)
481+
updateColBegin = true;
482+
else if (new_line_begin == line_begin && new_col_begin < col_begin)
483+
updateColBegin = true;
484+
485+
if (new_line_end > line_end)
486+
updateLineEnd = true;
487+
488+
if (updateLineEnd)
489+
updateColEnd = true;
490+
else if (new_line_end == line_end && new_col_end > col_end)
491+
updateColEnd = true;
492+
493+
if (new_line_end == line_end && updateColEnd) {
494+
System.err.println("updating col_end in " + contextString(context));
495+
}
496+
497+
}
498+
499+
if (updateLineBegin)
459500
context.setAttribute(Y_MIN, new_line_begin.toString());
460-
if (new_col_begin != null && (col_begin == null || new_line_begin < line_begin
461-
|| new_line_begin == line_begin && new_col_begin < col_begin))
501+
if (updateColBegin)
462502
context.setAttribute(X_MIN, new_col_begin.toString());
463-
if (new_line_end != null && (line_end == null || new_line_end > line_end))
503+
if (updateLineEnd)
464504
context.setAttribute(Y_MAX, new_line_end.toString());
465-
if (new_col_end != null
466-
&& (col_end == null || new_line_end > line_end || new_line_end == line_end && new_col_end > col_end))
505+
if (updateColEnd)
467506
context.setAttribute(X_MAX, new_col_end.toString());
507+
508+
if (new_line_end == line_end && updateColEnd) {
509+
System.err.println("updated col_end in " + contextString(context));
510+
}
468511
}
469512

470513
protected void updateBounds(Element context, Token... newTokens) {

0 commit comments

Comments
 (0)