Skip to content

Commit

Permalink
Merge pull request #774 from fesch/bugfix
Browse files Browse the repository at this point in the history
Bugfixes -> version 3.30-02 candidate
  • Loading branch information
fesch authored Nov 12, 2019
2 parents e285969 + 6f215c7 commit 7338fa9
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 63 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.30-01"
version="3.30-01"
shortversion="3.30-02"
version="3.30-02"
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 @@ -260,7 +260,7 @@ public String toString()
public static final String E_HOME_PAGE = "https://structorizer.fisch.lu";
public static final String E_HELP_PAGE = "https://help.structorizer.fisch.lu/index.php";
// END KGU#563 2018-007-26
public static final String E_VERSION = "3.30-01";
public static final String E_VERSION = "3.30-02";
public static final String E_THANKS =
"Developed and maintained by\n"+
" - Robert Fisch <[email protected]>\n"+
Expand Down
79 changes: 66 additions & 13 deletions src/lu/fisch/structorizer/elements/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
* Kay Gürtzig 2019-03-31 Issue #696 - field specialRoutinePool added, type retrieval may use it
* Kay Gürtzig 2019-08-02 Issue #733: New method getPreferenceKeys() for partial preference export
* Kay Gürtzig 2019-10-13/15 Bugfix #763: Test for stale file association in getFile(), new method copyWithFilepaths()
* Kay Gürtzig 2019-11-08 Enh. #770: New analyser checks 27, 28 (CASE elements)
*
******************************************************************************************************
*
Expand Down Expand Up @@ -647,7 +648,7 @@ protected Set<String> getVariableSetFor(Element _element)
true, false, true, true, true, // 11 .. 15
true, true, true, true, true, // 16 .. 20
true, true, true, true, false, // 21 .. 25
false // 26
false, true, true // 26 .. 28
// Add another element for every new check...
// and DON'T FORGET to append its description to
// AnalyserPreferences.checkCaptions
Expand Down Expand Up @@ -3446,6 +3447,9 @@ else if(eleClassName.equals("Case"))
Case caseEle = ((Case) ele);
int si = caseEle.qs.size(); // Number of branches
StringList initialVars = _vars.copy();
// START KGU#758 2019-11-08: Enh. #770
analyse_27_28(caseEle, _errors);
// END KGU#758 2019-11-08
// This Hashtable will contain strings composed of as many '1' characters as
// branches initialise the respective new variable - so in the end we can see
// which variables aren't always initialised.
Expand All @@ -3471,12 +3475,12 @@ else if(eleClassName.equals("Case"))
//System.out.println(myInitVars);
// walk trough the hash table and check
Enumeration<String> keys = myInitVars.keys();
// adapt size if no "default"
if ( caseEle.getText().get(caseEle.getText().count()-1).equals("%") )
{
si--;
}
//System.out.println("SI = "+si+" = "+c.text.get(c.text.count()-1));
// adapt size if no "default"
if ( caseEle.getText().get(caseEle.getText().count()-1).equals("%") )
{
si--;
}
//System.out.println("SI = "+si+" = "+c.text.get(c.text.count()-1));
while ( keys.hasMoreElements() )
{
String key = keys.nextElement();
Expand Down Expand Up @@ -4664,19 +4668,19 @@ else if (Arranger.hasInstance()) {
// END KGU#376 2017-04-20
if (subResultFlags[0]) {
//error = new DetectedError("Diagram «%» is rather unsuited to be included as it makes use of return.",(Element) _node.getElement(i));
addError(_errors, new DetectedError(errorMsg(Menu.error23_1, name), this), 23);
addError(_errors, new DetectedError(errorMsg(Menu.error23_1, name), this), 23);
}
// Now associate all sub-analysis results with the Call element
for (DetectedError err: impErrors) {
// Unfortunately the error object doesn't know its category, so we relaunch it under category 23
addError(_errors, new DetectedError(name + ": " + err.getError(), this), 23);
addError(_errors, new DetectedError(name + ": " + err.getError(), this), 23);
}
// Add analysis for name conflicts and uncertain variables - might still occur among includes!
// START KGU#388 2017-09-17: Enh. #423
for (String key: importedTypes.keySet()) {
if (key.startsWith(":") && _types.containsKey(key)) {
//error = new DetectedError("There is a name conflict between local and imported type definition «%»!",(Element) _node.getElement(i));
addError(_errors, new DetectedError(errorMsg(Menu.error23_7, key.substring(1)), this), 23);
addError(_errors, new DetectedError(errorMsg(Menu.error23_7, key.substring(1)), this), 23);
}
else {
_types.put(key, importedTypes.get(key));
Expand All @@ -4687,7 +4691,7 @@ else if (Arranger.hasInstance()) {
String varName = importedVars.get(j);
if (!_vars.addIfNew(varName) || _uncertainVars.contains(varName)) {
//error = new DetectedError("There is a name conflict between local and imported variable «%»!",(Element) _node.getElement(i));
addError(_errors, new DetectedError(errorMsg(Menu.error23_4, varName), this), 23);
addError(_errors, new DetectedError(errorMsg(Menu.error23_4, varName), this), 23);
}
}
for (int j = 0; j < importedUncVars.count(); j++) {
Expand All @@ -4696,14 +4700,14 @@ else if (Arranger.hasInstance()) {
addError(_errors, new DetectedError(errorMsg(Menu.error03_2, new String[]{varName, ""}), this), 3);
if (_vars.contains(varName) || !_uncertainVars.addIfNew(varName)) {
//error = new DetectedError("There is a name conflict between local and imported variable «%»!",(Element) _node.getElement(i));
addError(_errors, new DetectedError(errorMsg(Menu.error23_4, varName), this), 23);
addError(_errors, new DetectedError(errorMsg(Menu.error23_4, varName), this), 23);
}
}
for (Entry<String, String> constEntry: importedRoot.constants.entrySet()) {
if (!_constants.containsKey(constEntry.getKey())) {
_constants.put(constEntry.getKey(), constEntry.getValue());
if (!this.constants.containsKey(constEntry.getKey())) {
this.constants.put(constEntry.getKey(), constEntry.getValue());
this.constants.put(constEntry.getKey(), constEntry.getValue());
}
}
}
Expand Down Expand Up @@ -4733,6 +4737,55 @@ private void analyse_24(Element _ele, Vector<DetectedError> _errors, HashMap<Str
}
// END KGU#514 2018-04-03

// START KGU#758 2019-11-08: Enh. #770 - check CASE elements
private void analyse_27_28(Case _case, Vector<DetectedError> _errors)
{
HashSet<String> selectors = new HashSet<String>();
HashSet<Integer> values = new HashSet<Integer>();
StringList text = _case.getUnbrokenText();
StringList duplicates = new StringList();
boolean nonNumbers = false;
for (int i = 1; i < text.count(); i++) {
StringList items = Element.splitExpressionList(text.get(i), ",");
for (int j = 0; j < items.count(); j++) {
int val = 0;
String item = items.get(j);
// Check for duplicates (including the default label)
if (!selectors.add(item)) {
duplicates.add(item);
}
// Check for non-integers and non-characters (without the default branch label)
if (j < items.count()-1) {
String constVal = this.constants.get(item);
if (constVal == null) {
constVal = item;
}
// Check if it is not a character literal
if (!constVal.endsWith("'") || !(constVal.startsWith("'\\") && constVal.length() > 3 || constVal.startsWith("'") && constVal.length() == 3)) {
try {
val = Integer.parseInt(constVal);
if (!values.add(val)) {
duplicates.addIfNew(constVal);
}
}
catch (NumberFormatException ex) {
nonNumbers = true;
}
}
}
}
}
if (nonNumbers) {
//error = new DetectedError("Some selector item seems not to be an integer constant.", _case);
addError(_errors, new DetectedError(Menu.error27.getText(), _case), 27);
}
if (!duplicates.isEmpty()) {
//error = new DetectedError("There are multiple (conflicting) selector items (%) in the CASE element!", _case);
addError(_errors, new DetectedError(errorMsg(Menu.error28, duplicates.concatenate(", ")), _case), 28);
}
}
// END KGU#758 2019-11-08

// START KGU#456 2017-11-06: Enh. #452
/**
* Reports the active guide and performs the specified checks and steps
Expand Down
18 changes: 17 additions & 1 deletion src/lu/fisch/structorizer/executor/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
* Kay Gürtzig 2019-09-24 Enh. #738 - Reflection of the executed element in code preview
* Kay Gürtzig 2019-10-04 Precaution against ConcurrentModificationException (from Arranger)
* Kay Gürtzig 2019-10-15 Issue #763 - precautions against collateral effects of widened save check.
* Kay Gürtzig 2019-11-08 Bugfix #769 - CASE selector list splitting was too simple for string literals
* Kay Gürtzig 2019-11-09 Bugfix #771 - Unhandled errors deep from the interpreter
*
******************************************************************************************************
*
Expand Down Expand Up @@ -311,6 +313,7 @@
import java.awt.event.WindowListener;
import java.io.Closeable;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -5817,7 +5820,10 @@ private String stepCase(Case element)
{
// START KGU#15 2015-10-21: Support for multiple constants per branch
//String test = convert(expression + text.get(q));
String[] constants = text.get(q).split(",");
// START KGU#755 2019-11-08: Bugfix #769 - string literals might contain commas
//String[] constants = text.get(q).split(",");
String[] constants = Element.splitExpressionList(text.get(q), ",").toArray();
// END KGU#755 2019-11-08
// END KGU#15 2015-10-21
boolean go = false;
if ((q == last) && hasDefaultBranch)
Expand Down Expand Up @@ -7078,6 +7084,16 @@ else if (error423message.contains("Encountered \"( {\"")) {
throw err;
}
}
// START KGU#756 2019-11-08: Internal interpreter errors may e.g. occur if a type name "Char" is evaluated
catch (Error ex) {
if (ex.getClass().getName().equals("bsh.Parser$LookaheadSuccess")) {
throw new EvalError("Syntax error in expression «" + expr + "» - possibly a misplaced type name.", null, null);
}
else {
throw ex;
}
}
// END KGU#756 2019-11-08
} while (error423);
}
return value;
Expand Down
7 changes: 6 additions & 1 deletion src/lu/fisch/structorizer/generators/BASHGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* Kay Gürtzig 2019-03-30 Issue #696: Type retrieval had to consider an alternative pool
* Kay Gürtzig 2019-09-27 Enh. #738: Support for code preview map on Root level
* Kay Gürttig 2019-10-15 Bugfix #765: Private field typeMap had to be made protected
* Kay Gürtzig 2019-11-08 Bugfix #769: Undercomplex selector list splitting in CASE generation mended
*
******************************************************************************************************
*
Expand Down Expand Up @@ -920,7 +921,11 @@ protected void generateCode(Case _case, String _indent) {
addCode("", "", disabled);
// START KGU#453 2017-11-02: Issue #447
//addCode(this.getIndent() + _case.getText().get(i+1).trim().replace(",", "|") + ")", _indent, disabled);
addCode(this.getIndent() + unbrokenText.get(i+1).trim().replace(",", "|") + ")", _indent, disabled);
// START KGU#755 2019-11-08: Bugfix #769 - more precise splitting necessary
//addCode(this.getIndent() + unbrokenText.get(i+1).trim().replace(",", "|") + ")", _indent, disabled);
StringList items = Element.splitExpressionList(unbrokenText.get(i+1).trim(), ",");
addCode(this.getIndent() + items.concatenate("|") + ")", _indent, disabled);
// END KGU#755 2019-11-08
// END KGU#453 2017-11-02
// END KGU#277 2016-10-14
// START KGU#15 2015-11-02
Expand Down
17 changes: 14 additions & 3 deletions src/lu/fisch/structorizer/generators/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
* Kay Gürtzig 2019-09-24/25 Bugfix #752: Declarations in Calls are to be handled, workaround for type defects
* Kay Gürtzig 2019-10-02 Enh. #721: New hooks for Jacascript in declaration handling
* Kay Gürtzig 2019-10-03 Bugfix #756: Transformation damage on expressions containing "<-" and brackets
* Kay Gürtzig 2019-11-08 Bugfix #769: Undercomplex selector list splitting in CASE generation mended
* Kay Gürtzig 2019-11-12 Bugfix #752: Outcommenting of incomplete declarations ended
*
******************************************************************************************************
*
Expand Down Expand Up @@ -1206,7 +1208,10 @@ protected void generateCode(Case _case, String _indent) {
for (int i = 0; i < _case.qs.size() - 1; i++) {
// START KGU#15 2015-10-21: Support for multiple constants per
// branch
StringList constants = StringList.explode(lines.get(i + 1), ",");
// START KGU#755 2019-11-08: Bugfix #769 - more precise splitting necessary
//StringList constants = StringList.explode(lines.get(i + 1), ",");
StringList constants = Element.splitExpressionList(lines.get(i + 1), ",");
// END KGU#755 2019-11-08
for (int j = 0; j < constants.count(); j++) {
code.add(_indent + "case " + constants.get(j).trim() + ":");
}
Expand Down Expand Up @@ -2147,7 +2152,10 @@ else if (_fullDecl) {
setDefHandled(_root.getSignatureString(false), _name);
// END KGU#424 2017-09-26
if (decl.contains("???")) {
appendComment(decl + ";", _indent);
// START #730 2019-11-12: Issue #752 don't comment it out, a missing declaration is a syntax error anyway
//appendComment(decl + ";", _indent);
addCode(decl + ";", _indent, false);
// END KGU#730 2019-11-12
}
else {
// START KGU#501 2018-02-22: Bugfix #517 In Java, C++, or C# we may need modifiers here
Expand All @@ -2158,7 +2166,10 @@ else if (_fullDecl) {
}
// Add a comment if there is no type info or internal declaration is not allowed
else if (types == null || _fullDecl){
appendComment(_name + ";", _indent);
// START #730 2019-11-12: Issue #752 don't comment it out, a missing declaration is a syntax error anyway
//appendComment(_name + ";", _indent);
addCode("??? " + _name + ";", _indent, false);
// END KGU#730 2019-11-12
// START KGU#424 2017-09-26: Ensure the declaration comment doesn't get lost
setDefHandled(_root.getSignatureString(false), _name);
// END KGU#424 2017-09-26
Expand Down
Loading

0 comments on commit 7338fa9

Please sign in to comment.