Skip to content

Commit

Permalink
Merge pull request #1165 from fesch/bugfix
Browse files Browse the repository at this point in the history
version 3.32-21 candidate
  • Loading branch information
fesch authored Apr 19, 2024
2 parents 3e0b28c + 2d4416b commit 16bb227
Show file tree
Hide file tree
Showing 36 changed files with 1,619 additions and 699 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-20"
version="3.32-20"
shortversion="3.32-21"
version="3.32-21"
icon="icons/Structorizer.icns"
mainclassname="Structorizer"
copyright="Bob Fisch"
Expand Down
29 changes: 18 additions & 11 deletions src/com/creativewidgetworks/goldparser/engine/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Parsing used to fail with error.group_runaway if the file ended
* with a line comment since the newlines before the EOF are
* suppressed by lookahadDFA().
* Kay Gürtzig 2024-04-15 Improved version of bugfix #28 -> preserving the comment
*
******************************************************************************************************
*/
Expand Down Expand Up @@ -737,11 +738,7 @@ public ParseMessage parse() {
inputTokens.push(read);

// Handle the case where an unterminated comment block consumes the entire program
// START KGU#1144 2024-04-10: Bugfix #28 With a line comment, we may tolerate EOF
//if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0
&& !(groupStack.size() == 1 && groupStack.peek().group.getEndingMode() == EndingMode.OPEN)) {
// END KGU#1144 2024-04-10
if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
// Runaway group
parseMessage = ParseMessage.GROUP_ERROR;
} else {
Expand All @@ -760,11 +757,7 @@ public ParseMessage parse() {
} else if (SymbolType.ERROR.equals(read.getType())) {
parseMessage = ParseMessage.LEXICAL_ERROR;
done = true;
// START KGU#1144 2024-04-10: Bugfix #28 With a line comment, we may tolerate EOF
//} else if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
} else if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0
&& !(groupStack.size() == 1 && groupStack.peek().group.getEndingMode() == EndingMode.OPEN)) {
// END KGU #1144 2024-04-10
} else if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
// Runaway group
parseMessage = ParseMessage.GROUP_ERROR;
done = true;
Expand Down Expand Up @@ -987,7 +980,21 @@ protected Token produceToken() {
}
} else if (read.getType().equals(SymbolType.END)) {
// EOF always stops the loop. The caller method (parse) can flag a runaway group error.
token = read;
// START KGU#1144 2024-04-15: Bugfix #28 Save a line comment at end of file
//token = read;
// An open group (e.g. line comment) expecting just some NOISE, however, should be preserved
Token grp = null;
if (groupStack.size() == 1
&& (grp = groupStack.peek()).getGroup().getEndingMode() == EndingMode.OPEN
&& grp.getGroup().getEnd().getType().equals(SymbolType.NOISE)) {
groupStack.pop();
grp.setSymbol(grp.getGroup().getContainer());
token = grp;
}
else {
token = read;
}
// END KGU#1144 2024-04-15
done = true;
} else {
// We are in a group, Append to the Token on the top of the stack.
Expand Down
2 changes: 2 additions & 0 deletions src/lu/fisch/structorizer/elements/Alternative.java
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ protected String[] getRelevantParserKeys() {
/* (non-Javadoc)
* @see lu.fisch.structorizer.elements.Element#mayPassControl()
*/
@Override
public boolean mayPassControl()
{
// An alternative may only pass control if being disabled or containing at least one
Expand All @@ -842,6 +843,7 @@ public boolean mayPassControl()
* is to be involved
* @return the maximum line length
*/
@Override
public int getMaxLineLength(boolean _includeSubstructure)
{
int maxLen = super.getMaxLineLength(false);
Expand Down
34 changes: 28 additions & 6 deletions src/lu/fisch/structorizer/elements/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* Kay Gürtzig 2021-02-26 Enh. #410: New field isMethodDeclaration and method derivates for
* the representation of imported methods (OOP approach)
* Kay Gürtzig 2024-03-22 Issue #1154: Modified drawing of CALLs diverted for method declarations
* Kay Gürtzig 2024-04-17 Bugfix #1160: Rectification of rotated drawing
*
******************************************************************************************************
*
Expand Down Expand Up @@ -152,14 +153,26 @@ public Call(Instruction instr)
// END KGU#199 2016-07-07

// START KGU#227 2016-07-30: Enh. #128
/**
* Provides a subclassable left offset for drawing the text
*/
// START KGU#1150 2024-04-16: Bugfix #1160 For rotation we need X and Y
///**
// * Provides a subclassable left offset for drawing the text
// */
//@Override
//protected int getTextDrawingOffset()
//{
// return (Element.E_PADDING/2);
//}
@Override
protected int getTextDrawingOffsetX()
{
return rotated ? 0 : (Element.E_PADDING/2);
}
@Override
protected int getTextDrawingOffset()
protected int getTextDrawingOffsetY()
{
return (Element.E_PADDING/2);
return rotated ? (Element.E_PADDING/2) : 0;
}
// END KGU#1150 2024-04-16
// END KGU#227 2016-07-30

@Override
Expand All @@ -171,7 +184,16 @@ public Rect prepareDraw(Canvas _canvas)

// START KGU#227 2016-07-30: Enh. #128 - on this occasion, we just enlarge the instruction rect width
super.prepareDraw(_canvas);
rect0.right += 2*(E_PADDING/2);
// START KGU#1150 2024-04-16: Bugfix #1160 We must consider rotation
//rect0.right += 2*(E_PADDING/2);
if (rotated) {
// The border bars will virtually be drawn above and below the tetxt
rect0.bottom += 2*(E_PADDING/2);
}
else {
rect0.right += 2*(E_PADDING/2);
}
// END KGU#1150 2024-04-16
// END KGU#227 2016-07-30
return rect0;
}
Expand Down
26 changes: 22 additions & 4 deletions src/lu/fisch/structorizer/elements/Case.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* Kay Gürtzig 2019-03-13 Issues #518, #544, #557: Element drawing now restricted to visible rect.
* Kay Gürtzig 2021-01-02 Enh. #905: Mechanism to draw a warning symbol on related DetectedError
* Kay Gürtzig 2021-02-09 Bugfix #930: Wrong selector line width calculation in prepareDraw()
* Kay Gürtzig 2024-04-16 Bugfix #1160: Separate X and Y text offset for drawing rotated elements
*
******************************************************************************************************
*
Expand Down Expand Up @@ -397,6 +398,9 @@ else if (Element.E_APPLY_ALIASES) {
Vector<Boolean> rotFlags = new Vector<Boolean>();
// END KGU#401 217-05-17

// START KGU#1150 2024-04-16: Bugfix #1160 rotation defects
boolean shrinkByRot = caseShrinkByRot != 0 && nBranches > caseShrinkByRot;
// END KGU#1150 2024-04-16
if (qs.size() > 0)
{
for (int i = 0; i < nBranches; i++)
Expand All @@ -412,12 +416,26 @@ else if (Element.E_APPLY_ALIASES) {
maxHeight = rtt.bottom;
}
// START KGU#401 2017-05-17: Issue #405
boolean rotatable = rtt.bottom < rtt.right
boolean rotatable = shrinkByRot
&& rtt.bottom < rtt.right // This is no longer quite correct
&& sq.getSize() == 1 && (sq.getElement(0) instanceof Instruction ||
sq.getElement(0).isCollapsed(true));
rotX0Branches.addElement(rotatedWidth);
int rotWidth = (rotatable ? rtt.bottom : rtt.right);
int rotHeight = (rotatable ? rtt.right : rtt.bottom);
// START KGU#1150 2024-04-16: Bugfix #1160
//int rotWidth = (rotatable ? rtt.bottom : rtt.right);
//int rotHeight = (rotatable ? rtt.right : rtt.bottom);
int rotWidth = rtt.right;
int rotHeight = rtt.bottom;
if (rotatable) {
sq.resetDrawingInfoDown();
sq.getElement(0).rotated = true;
// The bounds may differ on rotated drawing!
rtt = sq.prepareDraw(_canvas);
rotWidth = rtt.bottom;
rotHeight = rtt.right;
// Now the original condition may no longer hold, however
}
// END KGU#1150 2024-04-16
rotatedWidth += Math.max(rotWidth, textWidths[i]);
if (rotatedHeight < rotHeight) {
rotatedHeight = rotHeight;
Expand All @@ -428,7 +446,7 @@ else if (Element.E_APPLY_ALIASES) {
}

// START KGU#401 2017-05-17: Issue #405
if (caseShrinkByRot != 0 && nBranches > caseShrinkByRot && rotatedWidth < fullWidth) {
if (shrinkByRot && rotatedWidth < fullWidth) {
x0Branches = rotX0Branches;
fullWidth = rotatedWidth;
maxHeight = rotatedHeight;
Expand Down
46 changes: 44 additions & 2 deletions src/lu/fisch/structorizer/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
* Issue #1129: Limitation of error lines in the Analyser warning popup
* Kay Gürtzig 2024-03-21 Bugfix #1128 revised (method retrieveComponentNmes()).
* Kay Gürtzig 2024-03-22 Issue #1154: New method drawHatched(Rect, Canvas) to allow subclassing
* Kay Gürtzig 2024-04-16 Bugfix #1160: Separate X and Y text offset for drawing rotated elements
*
******************************************************************************************************
*
Expand Down Expand Up @@ -310,7 +311,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-20";
public static final String E_VERSION = "3.32-21";
public static final String E_THANKS =
"Developed and maintained by\n"+
" - Robert Fisch <[email protected]>\n"+
Expand Down Expand Up @@ -1110,13 +1111,29 @@ public void setDrawPoint(Point point)
}

// START KGU#227 2016-07-30: Enh. #128
// START KGU#1150 2024-04-16: Bugfix #1160 For rotation we need X and Y
///**
// * Provides a subclassable left offset for drawing the text
// */
//protected int getTextDrawingOffset()
//{
// return 0;
//}
/**
* Provides a subclassable left offset for drawing the text
*/
protected int getTextDrawingOffset()
protected int getTextDrawingOffsetX()
{
return 0;
}
/**
* Provides a subclassable top offset for drawing the text
*/
protected int getTextDrawingOffsetY()
{
return 0;
}
// END KGU#1150 2024-04-16
// END KGU#227 2016-07-30

public void setText(String _text)
Expand Down Expand Up @@ -2432,6 +2449,7 @@ protected void drawBreakpointMark(Canvas _canvas, Rect _rect)
* Places a small red triangle in the upper left corner if this element
* is referred to by some {@link DetectedError} record in the owning
* {@link Root}.
*
* @param _canvas - the drawing canvas
* @param _rect - the outer drawing rectangle
*/
Expand Down Expand Up @@ -2479,6 +2497,11 @@ protected void drawWarningSignOnError(Canvas _canvas, Rect _rect) {
else {
_canvas.setColor(Color.BLUE);
}
// START KGU#1152 2024-04-17: Issue #1162 Avoid the background colour
if (isSimilarToFillColor(_canvas.getColor(), 25)) {
_canvas.setColor(Color.WHITE);
}
// END KGU#1152 2024-04-17
Rect markerBounds = getAnalyserMarkerBounds(_rect, false);
int[] xCoords = new int[] {
markerBounds.left, // left base corner
Expand All @@ -2500,10 +2523,29 @@ protected void drawWarningSignOnError(Canvas _canvas, Rect _rect) {
}
// END KGU#906 2021-01-02

// START KGU#1152 2024-04-17: Issue #1162 Auxiliary method for colour comparison
/**
* Compares the given {@code color} with the current fill colour of this element.
*
* @param color - the proposed draw colour
* @param tolerance - an integer tolerance for the RGB values
* @return {@code true} if all RGB components differ no more than by
* {@code tolerance}
*/
private boolean isSimilarToFillColor(Color color, int tolerance)
{
Color fill = getFillColor();
return (Math.abs(color.getRed() - fill.getRed()) < tolerance
&& Math.abs(color.getGreen() - fill.getGreen()) < tolerance
&& Math.abs(color.getBlue() - fill.getBlue()) < tolerance);
}
// END KGU#1152 2024-04-17

// START KGU#979 2021-06-10: Enh. #926, #979 - tooltip on the Analyser marker
/**
* Returns the bounds for the Analyser marker "driehoekje" with respect to the given
* Element rectangle {@code Rect}
*
* @param _rect - The bounding rectangle of the Element (with whatever relative reference point)
* @param _outer - whether {@code _rect} is the total bounds or just the text field's bounds
* @return the "driehoekje" bounds with respect to {@code _rect}
Expand Down
52 changes: 25 additions & 27 deletions src/lu/fisch/structorizer/elements/Forever.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@
*
* Revision List
*
* Author Date Description
* ------ ---- -----------
* Bob Fisch 2008.02.06 First Issue
* Kay Gürtzig 2015.10.11 Method selectElementByCoord(int,int) replaced by getElementByCoord(int,int,boolean)
* Kay Gürtzig 2015.10.12 Breakpoint support prepared
* Kay Gürtzig 2015.11.14 Bugfixes #31 (= KGU#82) and #32 (= KGU#83) in method copy()
* Kay Gürtzig 2015.11.30 Inheritance changed: implements ILoop
* Kay Gürtzig 2015.12.02 Bugfix #39 (KGU#91) -> getText(false) on drawing, constructors
* Author Date Description
* ------ ---- -----------
* Bob Fisch 2008-02-06 First Issue
* Kay Gürtzig 2015-10-11 Method selectElementByCoord(int,int) replaced by getElementByCoord(int,int,boolean)
* Kay Gürtzig 2015-10-12 Breakpoint support prepared
* Kay Gürtzig 2015-11-14 Bugfixes #31 (= KGU#82) and #32 (= KGU#83) in method copy()
* Kay Gürtzig 2015-11-30 Inheritance changed: implements ILoop
* Kay Gürtzig 2015-12-02 Bugfix #39 (KGU#91) -> getText(false) on drawing, constructors
* and methods setText() now ensure field text being empty
* Kay Gürtzig 2016.01.02 Bugfix #78 (KGU#119): New method equals(Element)
* Kay Gürtzig 2016.01.03 Bugfix #87 (KGU#121): Correction in getElementByCoord(), geIcon()
* Kay Gürtzig 2016.02.27 Bugfix #97 (KGU#136): field rect replaced by rect0 in prepareDraw()
* Kay Gürtzig 2016.03.01 Bugfix #97 (KGU#136): Translation-neutral selection
* Kay Gürtzig 2016.03.06 Enh. #77 (KGU#117): Method for test coverage tracking added
* Kay Gürtzig 2016.03.12 Enh. #124 (KGU#156): Generalized runtime data visualisation
* Kay Gürtzig 2016.04.24 Issue #169: Method findSelected() introduced, copy() modified (KGU#183)
* Kay Gürtzig 2016.07.21 KGU#207: Slight performance improvement in getElementByCoord()
* Kay Gürtzig 2016.07.30 Enh. #128: New mode "comments plus text" supported, drawing code delegated
* Kay Gürtzig 2018.04.04 Issue #529: Critical section in prepareDraw() reduced.
* Kay Gürtzig 2018.10.26 Enh. #619: Method getMaxLineLength() implemented
* Kay Gürtzig 2016-01-02 Bugfix #78 (KGU#119): New method equals(Element)
* Kay Gürtzig 2016-01-03 Bugfix #87 (KGU#121): Correction in getElementByCoord(), geIcon()
* Kay Gürtzig 2016-02-27 Bugfix #97 (KGU#136): field rect replaced by rect0 in prepareDraw()
* Kay Gürtzig 2016-03-01 Bugfix #97 (KGU#136): Translation-neutral selection
* Kay Gürtzig 2016-03-06 Enh. #77 (KGU#117): Method for test coverage tracking added
* Kay Gürtzig 2016-03-12 Enh. #124 (KGU#156): Generalized runtime data visualisation
* Kay Gürtzig 2016-04-24 Issue #169: Method findSelected() introduced, copy() modified (KGU#183)
* Kay Gürtzig 2016-07-21 KGU#207: Slight performance improvement in getElementByCoord()
* Kay Gürtzig 2016-07-30 Enh. #128: New mode "comments plus text" supported, drawing code delegated
* Kay Gürtzig 2018-04-04 Issue #529: Critical section in prepareDraw() reduced.
* Kay Gürtzig 2018-10-26 Enh. #619: Method getMaxLineLength() implemented
* Kay Gürtzig 2019-03-13 Issues #518, #544, #557: Element drawing now restricted to visible rect.
* Kay Gürtzig 2019-03-17 Issue #56: Accordng to the user guide, Forever may not have a breakpoint
*
Expand Down Expand Up @@ -353,13 +353,13 @@ public boolean isTestCovered(boolean _deeply)
* @see lu.fisch.structorizer.elements.Element#addFullText(lu.fisch.utils.StringList, boolean)
*/
@Override
protected void addFullText(StringList _lines, boolean _instructionsOnly)
{
protected void addFullText(StringList _lines, boolean _instructionsOnly)
{
if (!this.isDisabled(false)) {
this.q.addFullText(_lines, _instructionsOnly);
}
}
// END KGU 2015-10-16
}
// END KGU 2015-10-16

// START KGU 2015-11-30
@Override
Expand All @@ -379,7 +379,7 @@ public Element getLoop() {
@Override
public void convertToCalls(StringList _signatures)
{
getBody().convertToCalls(_signatures);
getBody().convertToCalls(_signatures);
}
// END KGU#199 2016-07-07

Expand Down Expand Up @@ -410,9 +410,7 @@ protected String[] getRelevantParserKeys() {
}

// START KGU 2017-10-21
/* (non-Javadoc)
* @see lu.fisch.structorizer.elements.Element#mayPassControl()
*/
@Override
public boolean mayPassControl()
{
// This may only pass control if being disabled or containing a reachable leave jump
Expand Down
Loading

0 comments on commit 16bb227

Please sign in to comment.