Skip to content

Commit

Permalink
Merge pull request #1153 from fesch/bugfix
Browse files Browse the repository at this point in the history
Version 3.32-19 candidate
  • Loading branch information
fesch authored Mar 21, 2024
2 parents 34beb4c + a2cc2f0 commit 09f6920
Show file tree
Hide file tree
Showing 21 changed files with 661 additions and 648 deletions.
4 changes: 2 additions & 2 deletions buildapp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
name="Structorizer"
displayname="Structorizer"
identifier="lu.fisch.Structorizer"
shortversion="3.32-18"
version="3.32-18"
shortversion="3.32-19"
version="3.32-19"
icon="icons/Structorizer.icns"
mainclassname="Structorizer"
copyright="Bob Fisch"
Expand Down
2 changes: 1 addition & 1 deletion src/lu/fisch/structorizer/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public String toString()
public static final long E_HELP_FILE_SIZE = 12300000;
public static final String E_DOWNLOAD_PAGE = "https://www.fisch.lu/Php/download.php";
// END KGU#791 2020-01-20
public static final String E_VERSION = "3.32-18";
public static final String E_VERSION = "3.32-19";
public static final String E_THANKS =
"Developed and maintained by\n"+
" - Robert Fisch <[email protected]>\n"+
Expand Down
28 changes: 27 additions & 1 deletion src/lu/fisch/structorizer/generators/BasGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
* Kay Gürtzig 2021-10-03/04 Bugfix #993: Wrong handling of constant parameters, array types, and mere declarations
* Kay Gürtzig 2021-12-05 Bugfix #1024: Precautions against defective record initializers
* Kay Gürtzig 2023-10-04 Bugfix #1093 Undue final return 0 on function diagrams
* Kay Gürtzig 2024-03-19 Issue #1148: Special indentation for "if else if" chains
*
******************************************************************************************************
*
Expand All @@ -91,6 +92,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.Map.Entry;

import lu.fisch.structorizer.elements.Alternative;
Expand Down Expand Up @@ -826,18 +828,42 @@ protected void generateCode(Alternative _alt, String _indent)
addCode(transformKeyword("IF ") + condition + " " + transformKeyword("THEN"), _indent, disabled);
// END KGU#277 2016-10-13
generateCode(_alt.qTrue, indentPlusOne);

// START KGU#1137 2024-03-19: Issue #1148 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
&& !this.optionCodeLineNumbering()) {
_alt = (Alternative)ele;
condition = transform(_alt.getUnbrokenText().getLongString()).trim();
// We must care for the code mapping explicitly here since we circumvent generateCode()
markElementStart(_alt, _indent, processedAlts, storedLineNos);
appendComment(_alt, _indent);
addCode(transformKeyword("ELSEIF ") + condition + " " + transformKeyword("THEN"),
_indent, _alt.isDisabled(false));
generateCode(_alt.qTrue, _indent+this.getIndent());
}
// END KGU#1137 2024-03-19

if(_alt.qFalse.getSize() > 0)
{
// START KGU#277 2016-10-13: Enh. #270
//code.add(this.getLineNumber() + _indent + "ELSE");
addCode(transformKeyword("ELSE"), _indent, disabled);
addCode(transformKeyword("ELSE"), _indent, _alt.isDisabled(false));
// END KGU#277 2016-10-13
generateCode(_alt.qFalse, indentPlusOne);
}
// START KGU#277 2016-10-13: Enh. #270
//code.add(this.getLineNumber() + _indent + "END IF");
addCode(transformKeyword("END IF"), _indent, disabled);
// END KGU#277 2016-10-13

// START KGU#1137 2024-03-19: Issue #1148 Accomplish the code map for the processed child alternatives
markElementEnds(processedAlts, storedLineNos);
// END KGU#1137 2024-03-19
}

@Override
Expand Down
27 changes: 27 additions & 0 deletions src/lu/fisch/structorizer/generators/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
* to top (to change execution order could severely compromise the algorithm!)
* Kay Gürtzig 2023-12-14 Bugfix #1118: The comment of Instructions without a line wasn't exported
* Kay Gürtzig 2023-12-26 Issue #1123: Translation of built-in function random() added.
* Kay Gürtzig 2024-03-19 Issue #1148: Special indentation for "if else if" chains
*
******************************************************************************************************
*
Expand Down Expand Up @@ -195,6 +196,7 @@

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;
import java.util.Map.Entry;
Expand Down Expand Up @@ -1778,11 +1780,36 @@ protected void generateCode(Alternative _alt, String _indent) {
generateCode(_alt.qTrue, _indent + this.getIndent());
appendBlockTail(_alt, null, _indent);

// START KGU#1137 2024-03-19: Issue #1148 We ought to make use of the ELSE IF 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) {
_alt = (Alternative)ele;
condition = transform(_alt.getUnbrokenText().getLongString(), false).trim();
if (!isParenthesized(condition)) {
condition = "(" + condition + ")";
}
// We must care for the code mapping explicitly here since we circumvent generateCode()
markElementStart(_alt, _indent, processedAlts, storedLineNos);
appendComment(_alt, _indent);
appendBlockHeading(_alt, "else if " + condition, _indent);
generateCode(_alt.qTrue, _indent + this.getIndent());
appendBlockTail(_alt, null, _indent);
}
// END KGU#1137 2024-03-19

if (_alt.qFalse.getSize() != 0) {
appendBlockHeading(_alt, "else", _indent);
generateCode(_alt.qFalse, _indent + this.getIndent());
appendBlockTail(_alt, null, _indent);
}

// START KGU#1137 2024-03-19: Issue #1148 Accomplish the code map for the processed child alternatives
markElementEnds(processedAlts, storedLineNos);
// END KGU#1137 2024-03-19
}

@Override
Expand Down
49 changes: 49 additions & 0 deletions src/lu/fisch/structorizer/generators/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
* Kay Gürtzig 2022-08-23 Issue #1068: Auxiliary method transformIndexLists(StringList) added
* Kay Gürtzig 2023-09-28 Bugfix #1092: Sensible export of alias type definitions enabled
* Kay Gürtzig 2024-03-14 Bugfix #1139: NullPointerException risk in generateCode(Try, String)
* Kay Gürtzig 2024-03-19 Issue #1148 Auxiliary methods markElementStart() and markElementEnds()
* moved up to Generator in order to facilitate IF ELSE IF chains
*
******************************************************************************************************
*
Expand Down Expand Up @@ -185,6 +187,7 @@
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;
import java.util.logging.Level;
Expand Down Expand Up @@ -3435,6 +3438,52 @@ protected void generateCode(Subqueue _subqueue, String _indent)
}
}

// START KGU#1135 2024-03-19: Issue #1146 Refactored to regain clarity
/**
* Marks the start of the instruction code for nested alternative {@code _alt}
* within the IF ELSIF chain for the code preview.
*
* @param _alt - nested alternative in the IF ELSIF sequence
* @param _indent - current indentation
* @param _processedAlts - stack of the marked nested Alternatives (to be modified)
* @param _storedLineNos - stack of the associated start line numbers (to be modified)
*/
protected void markElementStart(Alternative _alt, String _indent, Stack<Element> _processedAlts,
Stack<Integer> _storedLineNos) {
if (codeMap != null) {
int line0 = code.count();
codeMap.put(_alt, new int[]{line0, line0, _indent.length()});
_processedAlts.push(_alt);
_storedLineNos.push(line0);
}
}
/**
* Marks the common end of the instruction codes of all the alternatives
* gathered in stack {@code -processedAlts}, considering the differences
* between the start line numbers held in the {@link codeMap} and in the
* stack {@code _storedLineNos}.
*
* @param _processedAlts - stack of the marked nested Alternatives (to be emptied)
* @param _storedLineNos - stack of the associated start line numbers (to be emptied)
*/
protected void markElementEnds(Stack<Element> _processedAlts, Stack<Integer> _storedLineNos) {
Element ele;
assert _processedAlts.size() == _storedLineNos.size();
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

/******** Public Methods *************/

/**
Expand Down
57 changes: 6 additions & 51 deletions src/lu/fisch/structorizer/generators/OberonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
* Kay Gürtzig 2023-10-04 Bugfix #1093 Undue final return 0 on function diagrams
* 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
* Kay Gürtzig 2024-03-19 Issue #1148 Auxiliary methods markElementStart() and markElementEnds()
* moved up to Generator, reaction to disabled state improved
*
******************************************************************************************************
*
Expand Down Expand Up @@ -1002,20 +1004,19 @@ protected void generateCode(Alternative _alt, String _indent)
_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
// 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)) {
&& (ele = _alt.qFalse.getElement(0)) instanceof Alternative) {
_alt = (Alternative)ele;
// We must care for the code mapping explicitly here since we circumvent generateCode()
markElementStart(_alt, _indent, processedAlts, storedLineNos);
appendComment(_alt, _indent);
addCode("ELSIF "+ transform(_alt.getUnbrokenText().getLongString()) + " THEN",
_indent, isDisabled);
_indent, ele.isDisabled(false));
generateCode(_alt.qTrue, _indent+this.getIndent());
}
// END KGU#1135 2024-03-18
Expand All @@ -1025,7 +1026,7 @@ protected void generateCode(Alternative _alt, String _indent)
// START KGU#1135 2024-03-18: Bugfix #1146 END is wrong here
//addCode("END", _indent, isDisabled);
// END KGU#1135 2024-03-18
addCode("ELSE", _indent, isDisabled);
addCode("ELSE", _indent, _alt.isDisabled(false));
generateCode(_alt.qFalse, _indent+this.getIndent());
}
addCode("END;", _indent, isDisabled);
Expand All @@ -1034,52 +1035,6 @@ protected void generateCode(Alternative _alt, String _indent)
// END KGU#1135 2024-03-18
}

// START KGU#1135 2024-03-19: Issue #1146 Refactored to regain clarity
/**
* Marks the start of the instruction code for nested alternative {@code _alt}
* within the IF ELSIF chain for the code preview.
*
* @param _alt - nested alternative in the IF ELSIF sequence
* @param _indent - current indentation
* @param _processedAlts - stack of the marked nested Alternatives (to be modified)
* @param _storedLineNos - stack of the associated start line numbers (to be modified)
*/
private void markElementStart(Alternative _alt, String _indent, Stack<Element> _processedAlts,
Stack<Integer> _storedLineNos) {
if (codeMap != null) {
int line0 = code.count();
codeMap.put(_alt, new int[]{line0, line0, _indent.length()});
_processedAlts.push(_alt);
_storedLineNos.push(line0);
}
}
/**
* Marks the common end of the instruction codes of all the alternatives
* gathered in stack {@code -processedAlts}, considering the differences
* between the start line numbers held in the {@link codeMap} and in the
* stack {@code _storedLineNos}.
*
* @param _processedAlts - stack of the marked nested Alternatives (to be emptied)
* @param _storedLineNos - stack of the associated start line numbers (to be emptied)
*/
private void markElementEnds(Stack<Element> _processedAlts, Stack<Integer> _storedLineNos) {
Element ele;
assert _processedAlts.size() == _storedLineNos.size();
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)
{
boolean isDisabled = _case.isDisabled(false);
Expand Down
35 changes: 31 additions & 4 deletions src/lu/fisch/structorizer/generators/PHPGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* Kay Gürtzig 2023-10-13 Issue #980 Export of multi-variable declaration revised
* Kay Gürtzig 2023-10-18 Bugfix #1099: Handling of constants was not correct.
* Kay Gürtzig 2023-10-04 Bugfix #1093 Undue final return 0 on function diagrams
* Kay Gürtzig 2024-03-19 Issue #1148: Special indentation for "if else if" chains
*
******************************************************************************************************
*
Expand Down Expand Up @@ -140,6 +141,7 @@

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Stack;
import java.util.Map.Entry;

import lu.fisch.structorizer.elements.*;
Expand Down Expand Up @@ -730,15 +732,40 @@ protected void generateCode(Alternative _alt, String _indent)

addCode("if "+condition+"", _indent, isDisabled);
addCode("{", _indent, isDisabled);
generateCode(_alt.qTrue,_indent+this.getIndent());
generateCode(_alt.qTrue, _indent + this.getIndent());
addCode("}", _indent, isDisabled);

// START KGU#1137 2024-03-19: Issue #1148 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) {
_alt = (Alternative)ele;
isDisabled = _alt.isDisabled(false);
condition = transform(_alt.getUnbrokenText().getLongString()).trim();
// We must care for the code mapping explicitly here since we circumvent generateCode()
markElementStart(_alt, _indent, processedAlts, storedLineNos);
appendComment(_alt, _indent);
addCode("else if " + condition, _indent, isDisabled);
addCode("{", _indent, isDisabled);
generateCode(_alt.qTrue, _indent + this.getIndent());
addCode("}", _indent, isDisabled);
}
// END KGU#1137 2024-03-19

if(_alt.qFalse.getSize()!=0)
{
addCode("}", _indent, isDisabled);
addCode("else", _indent, isDisabled);
addCode("{", _indent, isDisabled);
generateCode(_alt.qFalse,_indent+this.getIndent());
generateCode(_alt.qFalse, _indent + this.getIndent());
addCode("}", _indent, isDisabled);
}
addCode("}", _indent, isDisabled);

// START KGU#1137 2024-03-19: Issue #1148 Accomplish the code map for the processed child alternatives
markElementEnds(processedAlts, storedLineNos);
// END KGU#1137 2024-03-19
}

@Override
Expand Down
Loading

0 comments on commit 09f6920

Please sign in to comment.