Skip to content

Commit

Permalink
Issue combination #738 / #967: code map mended in ARMGenerator, Strin…
Browse files Browse the repository at this point in the history
…gList method renamed
  • Loading branch information
codemanyak committed Apr 14, 2021
1 parent dec5a8f commit e5f375b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 42 deletions.
3 changes: 2 additions & 1 deletion src/lu/fisch/structorizer/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public String toString()
public static final long E_HELP_FILE_SIZE = 10700000;
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.31-02";
public static final String E_VERSION = "3.31-03";
public static final String E_THANKS =
"Developed and maintained by\n"+
" - Robert Fisch <[email protected]>\n"+
Expand All @@ -315,6 +315,7 @@ public String toString()
" - BASIC: Jacek Dzieniewicz\n" +
" - Python: Daniel Spittank <[email protected]>\n"+
" - Javascript: Kay Gürtzig <[email protected]>\n"+
" - ARM code: Alessandro Simonetta <[email protected]>\n"+
" - PapDesigner: Kay Gürtzig <[email protected]>\n"+
"Import grammars and parsers written and maintained by\n"+
" - ANSI-C: Kay Gürtzig <[email protected]>\n"+
Expand Down
66 changes: 44 additions & 22 deletions src/lu/fisch/structorizer/generators/ArmGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* ------ ---- -----------
* See @author 2021-03-25 Provided per Pull request on Enh. #96
* A. Simonetta 2021-04-02 Several revisions as requested
* Kay Gürtzig 2020-04-09 Syntax correction, some adaptations to fit into Structorizer environment
* Kay Gürtzig 2021-04-09 Syntax correction, some adaptations to fit into Structorizer environment
* Kay Gürtzig 2021-04-14 Issue #738: Highlighting map faults mended
*
******************************************************************************************************
*
Expand Down Expand Up @@ -227,20 +228,40 @@ protected String getOutputReplacer() {

@Override
public String generateCode(Root _root, String _indent, boolean _public) {
if (topLevel && gnuEnabled) {
code.add(difference[0][2]);
code.add(difference[0][3] + "\n");
} else if (topLevel) {
code.add(difference[1][2]);
code.add(difference[1][3] + "\n");
// START KGU#705 2021-04-14: Enh. #738 (Direct code changes compromise codeMap)
//if (topLevel && gnuEnabled) {
// code.add(difference[0][2]);
// code.add(difference[0][3] + "\n");
//} else if (topLevel) {
// code.add(difference[1][2]);
// code.add(difference[1][3] + "\n");
//}
int line0 = code.count();
if (codeMap!= null) {
// register the triple of start line no, end line no, and indentation depth
// (tab chars count as 1 char for the text positioning!)
codeMap.put(_root, new int[]{line0, line0, _indent.length()});
}
if (topLevel) {
int variant = gnuEnabled ? 0 : 1;
addCode(difference[variant][2], "", false);
addCode(difference[variant][3], "", false);
addCode("", "", false); // Just a newline
}
// END KGU#705 2021-04-14

for (Map.Entry<String, String> entry : mVariables.entrySet()) {
mVariables.put(entry.getKey(), "");
}

generateBody(_root, _indent);

// START KGU#705 2019-09-23: Enh. #738
if (codeMap != null) {
// Update the end line no relative to the start line no
codeMap.get(_root)[1] += (code.count() - line0);
}
// END KGU#705 2019-09-23
return code.getText();
}

Expand Down Expand Up @@ -393,14 +414,14 @@ protected void generateCode(Case _case, String _indent) {
protected void generateCode(For _for, String _indent) {
appendComment(_for, _indent + getIndent());

String colon = difference[1][0];

// Check if the variable gnuEnabled is set on GNU or Keil.
if (gnuEnabled) {
colon = difference[0][0];
}
// Check if option gnuEnabled is set on GNU or Keil.
int variant = gnuEnabled ? 0 : 1;
String colon = difference[variant][0];

boolean isDisabled = _for.isDisabled(true);
// START KGU 2021-04-14 Argument was wrong
//boolean isDisabled = _for.isDisabled(true);
boolean isDisabled = _for.isDisabled(false);
// END KGU 2021-04-14

// Extract all the text from the block.
String counterStr = _for.getCounterVar();
Expand Down Expand Up @@ -461,10 +482,11 @@ protected void generateCode(For _for, String _indent) {
int s = counter + 1;

// This part is something similar to unifyFlow (we can do it better)
// FIXME (KGU) This might compromise highlighting ranges
if (code.indexOf("end_" + counter + colon) == code.indexOf("end_" + s + colon) - 1) {
code.replaceIfContains("B end_" + s, "B end_" + counter);
code.replaceIfContains("end_" + s + colon, "");
code.replaceIfContains("end_" + s, "end_" + counter);
code.replaceInElements("B end_" + s, "B end_" + counter);
code.replaceInElements("end_" + s + colon, "");
code.replaceInElements("end_" + s, "end_" + counter);
}
}

Expand Down Expand Up @@ -1320,13 +1342,13 @@ private void unifyFlow() {
if (lines[i].startsWith("end_")) {
if (lines[i + 1].contains("B end_")) {
// Removes end_0:
code.replaceIfContains(lines[i], "");
code.replaceIfContains(lines[i].replace(":", ""), lines[i + 1].replace(getIndent() + "B ", ""));
code.replaceInElements(lines[i], "");
code.replaceInElements(lines[i].replace(":", ""), lines[i + 1].replace(getIndent() + "B ", ""));
}
if (lines[i + 1].startsWith("end_")) {
code.replaceAll(lines[i], lines[i] + ":");
code.replaceIfContains(lines[i] + ":", "");
code.replaceIfContains(lines[i].replace(":", ""), lines[i + 1].replace(":", "").replace("\"]", ""));
code.replaceInElements(lines[i] + ":", "");
code.replaceInElements(lines[i].replace(":", ""), lines[i + 1].replace(":", "").replace("\"]", ""));
}
}
}
Expand All @@ -1335,7 +1357,7 @@ private void unifyFlow() {
// FIXME This inserts after the first line of code! And it will confuse the code preview!
// We need to append some information (array initializations) at the top of the code, if you have a way to do it we'd be glad to use it
private void appendTop(String line) {
code.insert(line, 1);
insertCode(line, 1);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lu/fisch/structorizer/gui/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Known issues:
- Shell export neither copes with nested array/record initialisers and component access
nor with cleanly handling usual and associative arrays as parameters or results.

Current development version 3.31-03 (2021-04-09)
Current development version 3.31-03 (2021-04-14)
- 01: Bugfix #851/2: COBOL import: SPECIAL-NAMES sections caused parser abort <2>
- 01: Bugfix #851/3: COBOL import flaws concerning floating-point literals <2>:
- Decimal and float literals weren't recognised,
Expand Down
38 changes: 20 additions & 18 deletions src/lu/fisch/utils/StringList.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@
*
* Author Date Description
* ------ ---- -----------
* Bob Fisch 2007.12.09 First Issue
* Kay Gürtzig 2015.11.04 Methods indexOf added.
* Kay Gürtzig 2015.11.24 Method clear added.
* Kay Gürtzig 2015.12.01 Methods replaceAll, replaceAllCi added.
* Kay Gürtzig 2015.12.01 Methods concatenate(...) added; getText() etc. reduced to them.
* Kay Gürtzig 2016.01.08 Method replaceAllBetween() added, replaceAll etc. reduced to it.
* Kay Gürtzig 2016.03.26 Method subSequence() added.
* Kay Gürtzig 2016.04.03 Method int removeAll(StringList, int, boolean) added
* Bob Fisch 2016.08.01 added method "toArray()" and "remove(int)" (which is a synonym to delete(int))
* Kay Gürtzig 2017.01.31 Method remove(int,int) added.
* Kay Gürtzig 2017.03.31 Methods addOrderedIfNew and addByLengthIfNew revised (now with return value)
* Kay Gürtzig 2017.06.18 Methods explodeWithDelimiter() revised (don't mistake '_by' for a regex anymore)
* Kay Gürtzig 2017.10.02 New functional variant with null separator for methods concatenate(...)
* Kay Gürtzig 2017.10.28 Method trim() added.
* Bob Fisch 2007-12-09 First Issue
* Kay Gürtzig 2015-11-04 Methods indexOf added.
* Kay Gürtzig 2015-11-24 Method clear added.
* Kay Gürtzig 2015-12-01 Methods replaceAll, replaceAllCi added.
* Kay Gürtzig 2015-12-01 Methods concatenate(...) added; getText() etc. reduced to them.
* Kay Gürtzig 2016-01-08 Method replaceAllBetween() added, replaceAll etc. reduced to it.
* Kay Gürtzig 2016-03-26 Method subSequence() added.
* Kay Gürtzig 2016-04-03 Method int removeAll(StringList, int, boolean) added
* Bob Fisch 2016-08-01 added method "toArray()" and "remove(int)" (which is a synonym to delete(int))
* Kay Gürtzig 2017-01-31 Method remove(int,int) added.
* Kay Gürtzig 2017-03-31 Methods addOrderedIfNew and addByLengthIfNew revised (now with return value)
* Kay Gürtzig 2017-06-18 Methods explodeWithDelimiter() revised (don't mistake '_by' for a regex anymore)
* Kay Gürtzig 2017-10-02 New functional variant with null separator for methods concatenate(...)
* Kay Gürtzig 2017-10-28 Method trim() added.
* Kay Gürtzig 2019-02-15 Method isEmpty() added
* Kay Gürtzig 2019-03-03 Bugfix in method explodeFirstOnly(String, String)
* Kay Gürtzig 2019-03-05 New method variants explodeWithDelimiter() for case-independent splitting
* Kay Gürtzig 2019-11-20 New methods count(String), count(String, boolean), insert(StringList, int)
* Kay Gürtzig 2020-03-18 Internal bugfix KGU#827 in toString, getCommaText() - caused errors with null elements
* A. Simonetta 2021-03-25 Issue #967: New method replaceIfContains
* Kay Gürtzig 2021-04-09 Renamed method replaceIfContains to replaceInElements
*
******************************************************************************************************
*
Expand Down Expand Up @@ -1180,7 +1182,7 @@ public int removeAll(StringList _subList, boolean _matchCase) {
*
* @see #replaceAllBetween(String, String, boolean, int, int)
* @see #replaceAllCi(String, String)
* @see #replaceIfContains(String, String)
* @see #replaceInElements(String, String)
*/
public int replaceAll(String _stringOld, String _stringNew) {
// START KGU#129 2016-01-08: Delegated to common submethod
Expand Down Expand Up @@ -1213,7 +1215,7 @@ public int replaceAll(String _stringOld, String _stringNew) {
*
* @see #replaceAll(String, String)
* @see #replaceAllBetween(String, String, boolean, int, int)
* @see #replaceIfContains(String, String)
* @see #replaceInElements(String, String)
*/
public int replaceAllCi(String _stringOld, String _stringNew) {
// START KGU#129 2016-01-08: Delegated to common submethod
Expand Down Expand Up @@ -1252,7 +1254,7 @@ public int replaceAllCi(String _stringOld, String _stringNew) {
*
* @see #replaceAll(String, String)
* @see #replaceAllCi(String, String)
* @see #replaceIfContains(String, String)
* @see #replaceInElements(String, String)
*/
public int replaceAllBetween(String _stringOld, String _stringNew, boolean _matchCase, int _fromIndex, int _toIndex) {
int nReplaced = 0;
Expand All @@ -1278,7 +1280,7 @@ public int replaceAllBetween(String _stringOld, String _stringNew, boolean _matc
* @see #replaceAllCi(String, String)
* @see #replaceAllBetween(String, String, boolean, int, int)
*/
public void replaceIfContains(String _stringOld, String _stringNew) {
public void replaceInElements(String _stringOld, String _stringNew) {
for (int i = 0; i < count(); i++) {
String c = strings.get(i).replace(_stringOld, _stringNew);
strings.setElementAt(c, i);
Expand Down

0 comments on commit e5f375b

Please sign in to comment.