Skip to content

Commit

Permalink
#1146 improved (line mapping for code preview)
Browse files Browse the repository at this point in the history
  • Loading branch information
codemanyak committed Mar 19, 2024
1 parent e584c04 commit a2164fc
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/lu/fisch/structorizer/generators/OberonGenerator.java
Expand Up @@ -94,7 +94,7 @@
* Kay Gürtzig 2021-12-05 Bugfix #1024: Precautions against defective record initializers
* Kay Gürtzig 2023-09-28 Bugfix #1092: Sensible export of alias type definitions enabled
* Kay Gürtzig 2023-10-04 Bugfix #1093 Undue final return 0 on function diagrams
* Kay Gürtzig 2024-03-18 Bugfix #1146 Wrong END between THEN and ELSE on Alternative export,
* Kay Gürtzig 2024-03-18/19 Bugfix #1146 Wrong END between THEN and ELSE on Alternative export,
* missed opportunity to use ELSIF in IF chains now implemented
*
******************************************************************************************************
Expand Down Expand Up @@ -126,6 +126,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Stack;
import java.util.regex.Matcher;

import lu.fisch.utils.*;
Expand Down Expand Up @@ -1000,18 +1001,30 @@ protected void generateCode(Alternative _alt, String _indent)
// END KGU#453 2017-1102
_indent, isDisabled);
generateCode(_alt.qTrue, _indent+this.getIndent());

// START KGU#1135 2024-03-18: Issue #1146 We ought to make use of the ELSIf if possible
Element ele = null;
// We must cater for the code mapping of the chained sub-alternatives
Stack<Element> processedAlts = new Stack<Element>();
Stack<Integer> storedLineNos = new Stack<Integer>();
while (_alt.qFalse.getSize() == 1
&& (ele = _alt.qFalse.getElement(0)) instanceof Alternative
&& !ele.isDisabled(isDisabled)) {
_alt = (Alternative)ele;
// We must care for the code mapping explicitly here since we circumvent generateCode()
if (codeMap != null) {
int line0 = code.count();
codeMap.put(_alt, new int[]{line0, line0, _indent.length()});
processedAlts.push(_alt);
storedLineNos.push(line0);
}
appendComment(_alt, _indent);
addCode("ELSIF "+ transform(_alt.getUnbrokenText().getLongString()) + " THEN",
_indent, isDisabled);
generateCode(_alt.qTrue, _indent+this.getIndent());
}
// END KGU#1135 2024-03-18

if (_alt.qFalse.getSize() != 0)
{
// START KGU#1135 2024-03-18: Bugfix #1146 END is wrong here
Expand All @@ -1021,6 +1034,20 @@ protected void generateCode(Alternative _alt, String _indent)
generateCode(_alt.qFalse, _indent+this.getIndent());
}
addCode("END;", _indent, isDisabled);
// START KGU#1135 2024-03-18: Issue #1146 Accomplish the code map for the processed child alternatives
if (codeMap!= null) {
while (!processedAlts.isEmpty()) {
ele = processedAlts.pop();
int line0 = storedLineNos.pop();
int[] codeMapEntry = codeMap.get(ele);
if (codeMapEntry[0] > line0) {
// The element code was moved due to some insertions, update line0
line0 = codeMap.get(ele)[0];
}
codeMapEntry[1] += (code.count() - line0);
}
}
// END KGU#1135 2024-03-18
}

protected void generateCode(Case _case, String _indent)
Expand Down

0 comments on commit a2164fc

Please sign in to comment.