Skip to content

Commit cc3017f

Browse files
authored
Merge pull request #1185 from fesch/bugfix
Version 3.32-25 candidate
2 parents ba0c03c + b0ce07a commit cc3017f

8 files changed

Lines changed: 97 additions & 20 deletions

File tree

buildapp.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
name="Structorizer"
1616
displayname="Structorizer"
1717
identifier="lu.fisch.Structorizer"
18-
shortversion="3.32-24"
19-
version="3.32-24"
18+
shortversion="3.32-25"
19+
version="3.32-25"
2020
icon="icons/Structorizer.icns"
2121
mainclassname="Structorizer"
2222
copyright="Bob Fisch"

src/lu/fisch/structorizer/elements/Element.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public String toString()
312312
public static final long E_HELP_FILE_SIZE = 12300000;
313313
public static final String E_DOWNLOAD_PAGE = "https://www.fisch.lu/Php/download.php";
314314
// END KGU#791 2020-01-20
315-
public static final String E_VERSION = "3.32-24";
315+
public static final String E_VERSION = "3.32-25";
316316
public static final String E_THANKS =
317317
"Developed and maintained by\n"+
318318
" - Robert Fisch <robert.fisch@education.lu>\n"+
@@ -1566,12 +1566,12 @@ public static boolean isSwitchTextCommentMode()
15661566
{
15671567
// Root root = getRoot(this);
15681568
// return (root != null && root.isSwitchTextAndComments());
1569-
// START KGU#227 2016-07-31: Enh. #128 - Mode "comments and text" overrides "switch text/comments"
1570-
//return Element.E_TOGGLETC;
1571-
return !Element.E_COMMENTSPLUSTEXT && Element.E_TOGGLETC;
1572-
// END KGU#227 2016-07-31
1569+
// START KGU#227 2016-07-31: Enh. #128 - Mode "comments and text" overrides "switch text/comments"
1570+
//return Element.E_TOGGLETC;
1571+
return !Element.E_COMMENTSPLUSTEXT && Element.E_TOGGLETC;
1572+
// END KGU#227 2016-07-31
15731573
}
1574-
/* END KGU#172 2916-04-01 */
1574+
/* END KGU#172 2016-04-01 */
15751575

15761576
/**
15771577
* Returns whether this element appears as selected in the standard {@link DrawingContext}.

src/lu/fisch/structorizer/elements/Instruction.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
* Kay Gürtzig 2024-04-02 Bugfix #1156: getAssignedVarName used to return null on typed constant definitions
8282
* Kay Gürtzig 2024-04-16 Bugfix #1160: Drawing of rotated elements fixed,
8383
* issues #161, #1161: Method mayPassControl() overridden
84+
* Kay Gürtzig 2025-01-17 Bugfix #1183: updateTypeMap was caught in an eternal loop by assignment
85+
* lines like "m[i][j] <- something"
8486
*
8587
******************************************************************************************************
8688
*
@@ -1597,7 +1599,11 @@ else if (posAsgnmt > 0 && !token0.equals("var") && !token0.equals("dim")) {
15971599
// Don't mistake an index as a size, so better don't specify size
15981600
while ((pos = declZone.indexOf("[")) == 1) {
15991601
// There might be more than one index in the bracket
1600-
StringList indices = Element.splitExpressionList(declZone.subSequence(2, declZone.count()), ",", true);
1602+
// START KGU#1168 2025-10-17: Bugfix #1183 endless loop in case of "[i][j]"
1603+
//StringList indices = Element.splitExpressionList(declZone.subSequence(2, declZone.count()), ",", true);
1604+
declZone = declZone.subSequence(2, declZone.count());
1605+
StringList indices = Element.splitExpressionList(declZone, ",", true);
1606+
// END KGU#1168 2025-01-17
16011607
if (indices.get(indices.count()-1).startsWith("]")) {
16021608
declZone.remove(0, declZone.indexOf("]"));
16031609
}

src/lu/fisch/structorizer/executor/Executor.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
* (where Arranger will already have been registered if instantiated).
228228
* Kay Gürtzig 2024-11-27 Bugfix #1181: Execution highlighting in the code preview was compromised
229229
* after Calls and within multi-line Calls
230+
* Kay Gürtzig 2025-01-21 Enh. #1184: Lazy multi-dimensional array creation on first element assignment
230231
*
231232
******************************************************************************************************
232233
*
@@ -4389,16 +4390,27 @@ else if (isConstant && content instanceof HashMap<?,?>) {
43894390
// Adjust the basic level - find the variable or object or create it
43904391
int level = 0;
43914392
boolean arrayWanted = false;
4392-
if ((targetObject == null) && accessPath.count() < 3) {
4393+
// START KGU#1169 2025-01-17: Issue #1184 Allow creation of multidimensional arrays
4394+
//if ((targetObject == null) && accessPath.count() < 3) {
4395+
int nPathItems = accessPath.count();
4396+
boolean onlyIndices = accessPath.get(1).startsWith("[");
4397+
for (int i = 2; onlyIndices && i < nPathItems; i++) {
4398+
onlyIndices = accessPath.get(i).startsWith("[");
4399+
}
4400+
if ((targetObject == null) && (onlyIndices || nPathItems < 3)) {
4401+
// END KGU#1169 2025-01-17
43934402
// We may generously create it, in particular if the type is declared
43944403
String access = accessPath.get(1);
43954404
if ((arrayWanted = access.startsWith("["))
43964405
&& (targetType == null || targetType.isArray())) {
4397-
int index = Integer.parseInt(access = access.substring(1));
4398-
targetObject = objectArray = new ArrayList<Object>(index+1);
4399-
for (int i = 0; i <= index; i++) {
4400-
objectArray.add(0);
4401-
}
4406+
// START KGU#1169 2025-01-21: Issue #1184
4407+
//int index = Integer.parseInt(access = access.substring(1));
4408+
//targetObject = objectArray = new ArrayList<Object>(index+1);
4409+
//for (int i = 0; i <= index; i++) {
4410+
// objectArray.add(0);
4411+
//}
4412+
targetObject = objectArray = createArrayForIndexList(accessPath.subSequence(1, nPathItems), true);
4413+
// END KGU#1169 2025-01-21
44024414
if (typeStr == null) {
44034415
typeStr = "@???";
44044416
}
@@ -4685,6 +4697,37 @@ else if (compObject != null){
46854697
return target; // Base name of the assigned variable or constant
46864698
// END KGU#580 2018-09-24
46874699
}
4700+
4701+
// START KGU#1169 2025-01-21: Issue #1184
4702+
/**
4703+
* Recursive routine to construct a mult-dimensional array structure containing
4704+
* at least the index path symbolized by {@code indexPath}.
4705+
*
4706+
* @param indexPath - a StringList expected to contain strings of form {@code "[<int>"}
4707+
* where {@code <int>} is meant to be an unsigned integer literal
4708+
* @param fill TODO
4709+
* @return An ArrayList containing as many elements as the integer literal in
4710+
* the first element of {@code indexPath}. If {@code indexPath} has length
4711+
* 1 then the ArrayList element will be 0, otherwise they will be ArrayLists
4712+
* themselves
4713+
*/
4714+
private ArrayList<Object> createArrayForIndexList(StringList indexPath, boolean fill)
4715+
{
4716+
String access = indexPath.get(0);
4717+
boolean interLevel = indexPath.count() > 1;
4718+
int index = Integer.parseInt(access = access.substring(1));
4719+
ArrayList<Object> targetArray = new ArrayList<Object>(index+1);
4720+
for (int i = 0; i <= index; i++) {
4721+
if (interLevel) {
4722+
targetArray.add(createArrayForIndexList(indexPath.subSequence(1, indexPath.count()), fill && i == index));
4723+
}
4724+
else if (fill) {
4725+
targetArray.add(0);
4726+
}
4727+
}
4728+
return targetArray;
4729+
}
4730+
// END KGU#1169 2025-01-21
46884731

46894732
/**
46904733
* Checks compatibility of types between {@code target} (i.e. {@code targetType}

src/lu/fisch/structorizer/generators/CGenerator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
* Kay Gürtzig 2023-12-14 Bugfix #1118: The comment of Instructions without a line wasn't exported
126126
* Kay Gürtzig 2023-12-26 Issue #1123: Translation of built-in function random() added.
127127
* Kay Gürtzig 2024-03-19 Issue #1148: Special indentation for "if else if" chains
128+
* Kay Gürtzig 2024-12-19 Issue #423: Recursive record definitions via array components weren't
129+
* correctly translated (pointer insertion failed)
128130
*
129131
******************************************************************************************************
130132
*
@@ -1001,10 +1003,20 @@ protected String transformTypeFromEntry(TypeMapEntry typeInfo, TypeMapEntry defi
10011003
// END KGU#1082 2023-09-28
10021004
int nLevels = canonType.lastIndexOf('@')+1;
10031005
String elType = (canonType.substring(nLevels)).trim();
1006+
// START KGU#1167 2024-12-19: Bugfix #423 With a missing backlink it didn't work
1007+
//if (nLevels > 0 && typeInfo.getTypeMap() != null && typeInfo.getTypeMap().containsKey(":"+elType)) {
1008+
// elTypeInfo = typeInfo.getTypeMap().get(":" + elType);
1009+
//}
10041010
TypeMapEntry elTypeInfo = typeInfo;
1005-
if (nLevels > 0 && typeInfo.getTypeMap() != null && typeInfo.getTypeMap().containsKey(":"+elType)) {
1006-
elTypeInfo = typeInfo.getTypeMap().get(":" + elType);
1011+
HashMap<String, TypeMapEntry> myTypeMap = typeInfo.getTypeMap();
1012+
if (myTypeMap == null) {
1013+
myTypeMap = typeMap;
1014+
}
1015+
if (nLevels > 0 && myTypeMap != null && myTypeMap.containsKey(":"+elType)) {
1016+
elTypeInfo = myTypeMap.get(":" + elType);
10071017
}
1018+
// END KGU#1167 2024-12-19
1019+
// FIXME KGU#1167 This might still fail with alias types...
10081020
if (elTypeInfo.isRecord() && elType.equals(elTypeInfo.typeName)) {
10091021
elType = transformRecordTypeRef(elType, elTypeInfo == definingWithin);
10101022
}

src/lu/fisch/structorizer/generators/JsGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ protected String transformRecordInit(String constValue, TypeMapEntry typeInfo) {
321321
else {
322322
recordInit.append(", ");
323323
}
324-
recordInit.append(compName + ":");
324+
recordInit.append(compName + ": ");
325325
if (compType != null && compType.isRecord()) {
326326
recordInit.append(transformRecordInit(compVal, compType));
327327
}

src/lu/fisch/structorizer/generators/PasGenerator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
* Kay Gürtzig 2023-11-08 Bugfix #1109: generateCode(Jump) revised for throw
103103
* Kay Gürtzig 2024-04-02 Bugfix #1155: Risk of stack overflow on type conversion averted
104104
* Kay Gürtzig 2024-04-03 Issue #1148: Optimised code generation for "if else if" chains
105+
* Kay Gürtzig 2024-12-18 Issue #423: Force pointer symbols in directly recursive record definitions
105106
*
106107
******************************************************************************************************
107108
*
@@ -529,6 +530,12 @@ protected String transformTypeFromEntry(TypeMapEntry typeInfo, TypeMapEntry defi
529530
int nLevels = canonType.lastIndexOf('@')+1;
530531
String elType = (canonType.substring(nLevels)).trim();
531532
elType = transformType(elType, "(*???*)");
533+
// START KGU#1025 2024-12-18: Issue #423 Add pointer symbol for recursive records
534+
if (definingWithin != null && definingWithin.isRecord() &&
535+
(typeInfo == definingWithin || elType.equals(definingWithin.typeName))) {
536+
elType = "^" + elType;
537+
}
538+
// END KGU#1025 2024-12-18
532539
_typeDescr = "";
533540
for (int i = 0; i < nLevels; i++) {
534541
_typeDescr += "array ";
@@ -2195,7 +2202,10 @@ private boolean generateTypeDef(Root _root, String _typeName, TypeMapEntry _type
21952202
if (_type.isRecord()) {
21962203
code.add(indentPlus1 + _typeName + " = RECORD");
21972204
for (Entry<String, TypeMapEntry> compEntry: _type.getComponentInfo(false).entrySet()) {
2198-
code.add(indentPlus3 + compEntry.getKey() + ":\t" + transformTypeFromEntry(compEntry.getValue(), null, true) + ";");
2205+
// START KGU#1025 2024-12-18: Issue #423 Special treatment for recursive record defs
2206+
//code.add(indentPlus3 + compEntry.getKey() + ":\t" + transformTypeFromEntry(compEntry.getValue(), null, true) + ";");
2207+
code.add(indentPlus3 + compEntry.getKey() + ":\t" + transformTypeFromEntry(compEntry.getValue(), _type, true) + ";");
2208+
// END#1025 2024-12-18
21992209
}
22002210
code.add(indentPlus2 + "END;");
22012211
}

src/lu/fisch/structorizer/gui/changelog.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Known issues (also see https://github.com/fesch/Structorizer.Desktop/issues):
2525
- ARM export is still experimental and relies on a specific and very restricted
2626
syntax for the element contents in order to produce meaningful results.
2727

28-
Current development version 3.32-24 (2024-11-27)
28+
Current development version 3.32-25 (2025-01-21)
2929
- 01: Bugfix #987: Duplicate subroutine comment export by Pascal generator <2>
3030
- 01: Bugfix #988: Syntax error in Structorizer.bat and Arranger.bat fixed <2>
3131
- 01: Bugfix #989: Expressions in EXIT elements (e.g. return) were forgotten
@@ -260,6 +260,12 @@ Current development version 3.32-24 (2024-11-27)
260260
- 24: Redundant routine pool reference compromised Executor efficiency <2>
261261
- 24: Bugfix #1181 Code preview highlighting wasn't always consistent with
262262
execution progress (particularly around Calls) <2>
263+
- 25: Issue #423: Code generation deficiencies on recursive record types
264+
fixed for Pascal, C, and C++ <2>
265+
- 25: Bugfix #1183: Structorizer got stuck with multi-dimensional array
266+
assignments like "field[i][j] <- expr" <2>
267+
- 25: Enh. #1184: Executor now manages to establish even multi-dimensional
268+
arrays on first element assignment (though lazily filled) <2>
263269

264270
Version 3.32 (2021-09-19) requiring Java 11 or newer
265271
- 01: Bugfix #851/2: SPECIAL-NAMES sections caused COBOL parser abort <2>

0 commit comments

Comments
 (0)