This commit is contained in:
Denis Molony 2020-12-23 20:50:26 +10:00
parent 8f019f7e8c
commit 14888c22e8

View File

@ -255,21 +255,23 @@ public class ApplesoftBasicProgram extends BasicProgram
programLoadAddress + ptr));
}
if (basicPreferences.showXref)
if (basicPreferences.showXref && !gosubLines.isEmpty ())
{
if (fullText.charAt (fullText.length () - 2) != '\n')
fullText.append ("\n");
fullText.append ("Subroutine:\n");
for (Integer line : gosubLines.keySet ())
{
fullText.append (String.format (" %5s %s%n", line, gosubLines.get (line)));
}
fullText.append ("\nGoTo:\n");
for (Integer line : gotoLines.keySet ())
if (basicPreferences.showXref && !gotoLines.isEmpty ())
{
if (fullText.charAt (fullText.length () - 2) != '\n')
fullText.append ("\n");
fullText.append ("GoTo:\n");
for (Integer line : gotoLines.keySet ())
fullText.append (String.format (" %5s %s%n", line, gotoLines.get (line)));
}
}
if (fullText.length () > 0)
while (fullText.charAt (fullText.length () - 1) == '\n')
@ -703,53 +705,12 @@ public class ApplesoftBasicProgram extends BasicProgram
case TOKEN_GOTO:
String target = new String (buffer, startPtr + 1, length - 2);
try
{
int targetLine = Integer.parseInt (target);
// gotoLines.add (Integer.parseInt (target));
if (gotoLines.containsKey (targetLine))
{
List<Integer> lines = gotoLines.get (targetLine);
lines.add (parent.lineNumber);
}
else
{
List<Integer> lines = new ArrayList<> ();
lines.add (parent.lineNumber);
gotoLines.put (targetLine, lines);
}
}
catch (NumberFormatException e)
{
System.out.println (
"Error parsing : GOTO " + target + " in " + parent.lineNumber);
}
addXref (target, gotoLines);
break;
case TOKEN_GOSUB:
target = new String (buffer, startPtr + 1, length - 2);
try
{
int targetLine = Integer.parseInt (target);
// gosubLines.add (Integer.parseInt (target));
if (gosubLines.containsKey (targetLine))
{
List<Integer> lines = gosubLines.get (targetLine);
lines.add (parent.lineNumber);
}
else
{
List<Integer> lines = new ArrayList<> ();
lines.add (parent.lineNumber);
gosubLines.put (targetLine, lines);
}
}
catch (NumberFormatException e)
{
System.out.println (HexFormatter.format (buffer, startPtr + 1, length - 2));
System.out.println (
"Error parsing : GOSUB " + target + " in " + parent.lineNumber);
}
addXref (target, gosubLines);
break;
}
}
@ -758,36 +719,38 @@ public class ApplesoftBasicProgram extends BasicProgram
if (isDigit (b)) // numeric, so must be a line number
{
String target = new String (buffer, startPtr, length - 1);
addXref (target, gotoLines);
}
else
recordEqualsPosition ();
}
}
private void addXref (String target, Map<Integer, List<Integer>> map)
{
try
{
targetLine = Integer.parseInt (target);
// gotoLines.add (targetLine);
if (gotoLines.containsKey (targetLine))
if (map.containsKey (targetLine))
{
List<Integer> lines = gotoLines.get (targetLine);
List<Integer> lines = map.get (targetLine);
lines.add (parent.lineNumber);
}
else
{
List<Integer> lines = new ArrayList<> ();
lines.add (parent.lineNumber);
gotoLines.put (targetLine, lines);
map.put (targetLine, lines);
}
}
catch (NumberFormatException e)
{
System.out.printf ("b: %d, start: %d, length: %d%n", b, startPtr,
(length - 1));
// System.out.printf ("b: %d, start: %d, length: %d%n", b, startPtr, (length - 1));
System.out.println (target);
System.out.println (HexFormatter.format (buffer, startPtr, length - 1));
System.out.println (e);
}
}
// else if (basicPreferences.alignAssign)
else
recordEqualsPosition ();
}
}
private boolean isImpliedGoto ()
{