mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-28 20:50:13 +00:00
applesoft constants
This commit is contained in:
parent
0ffff61265
commit
d801e85736
@ -18,13 +18,17 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
private final List<SourceLine> sourceLines = new ArrayList<> ();
|
||||
private final int endPtr;
|
||||
|
||||
final Map<Integer, List<Integer>> gotoLines = new TreeMap<> ();
|
||||
final Map<Integer, List<Integer>> gosubLines = new TreeMap<> ();
|
||||
final Map<String, List<Integer>> callLines = new TreeMap<> ();
|
||||
private final Map<Integer, List<Integer>> gotoLines = new TreeMap<> ();
|
||||
private final Map<Integer, List<Integer>> gosubLines = new TreeMap<> ();
|
||||
private final Map<Integer, List<Integer>> constants = new TreeMap<> ();
|
||||
|
||||
private final Map<String, List<Integer>> callLines = new TreeMap<> ();
|
||||
private final Map<String, List<Integer>> symbolLines = new TreeMap<> ();
|
||||
private final Map<String, List<Integer>> functionLines = new TreeMap<> ();
|
||||
private final Map<String, List<Integer>> arrayLines = new TreeMap<> ();
|
||||
|
||||
private final Map<String, List<String>> uniqueSymbols = new TreeMap<> ();
|
||||
private final Map<String, List<String>> uniqueArrays = new TreeMap<> ();
|
||||
|
||||
final List<Integer> stringsLine = new ArrayList<> ();
|
||||
final List<String> stringsText = new ArrayList<> ();
|
||||
@ -53,15 +57,17 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
for (SubLine subline : line.sublines)
|
||||
{
|
||||
for (String symbol : subline.getSymbols ())
|
||||
checkVar (symbol, line.lineNumber);
|
||||
checkVar (symbol, line.lineNumber, symbolLines, uniqueSymbols);
|
||||
for (String symbol : subline.getArrays ())
|
||||
checkArray (symbol, line.lineNumber);
|
||||
checkVar (symbol, line.lineNumber, arrayLines, uniqueArrays);
|
||||
for (String symbol : subline.getFunctions ())
|
||||
checkFunction (symbol, line.lineNumber);
|
||||
for (int targetLine : subline.getGosubLines ())
|
||||
addXref (line.lineNumber, targetLine, gosubLines);
|
||||
for (int targetLine : subline.getGotoLines ())
|
||||
addXref (line.lineNumber, targetLine, gotoLines);
|
||||
for (int targetLine : subline.getConstants ())
|
||||
addXref (line.lineNumber, targetLine, constants);
|
||||
if (subline.callTarget != null)
|
||||
addXref (line.lineNumber, subline.callTarget, callLines);
|
||||
}
|
||||
@ -70,14 +76,15 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void checkVar (String var, int lineNumber)
|
||||
void checkVar (String var, int lineNumber, Map<String, List<Integer>> map,
|
||||
Map<String, List<String>> unique)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
List<Integer> lines = symbolLines.get (var);
|
||||
List<Integer> lines = map.get (var);
|
||||
if (lines == null)
|
||||
{
|
||||
lines = new ArrayList<> ();
|
||||
symbolLines.put (var, lines);
|
||||
map.put (var, lines);
|
||||
}
|
||||
|
||||
if (lines.size () == 0)
|
||||
@ -89,30 +96,7 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
lines.add (lineNumber);
|
||||
}
|
||||
|
||||
checkUniqueName (var);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void checkArray (String var, int lineNumber)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
List<Integer> lines = arrayLines.get (var);
|
||||
if (lines == null)
|
||||
{
|
||||
lines = new ArrayList<> ();
|
||||
arrayLines.put (var, lines);
|
||||
}
|
||||
|
||||
if (lines.size () == 0)
|
||||
lines.add (lineNumber);
|
||||
else
|
||||
{
|
||||
int lastLine = lines.get (lines.size () - 1);
|
||||
if (lastLine != lineNumber)
|
||||
lines.add (lineNumber);
|
||||
}
|
||||
|
||||
checkUniqueName (var);
|
||||
checkUniqueName (var, unique);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@ -353,6 +337,9 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
if (basicPreferences.showFunctions && !functionLines.isEmpty ())
|
||||
showSymbols (fullText, functionLines, "Fnction");
|
||||
|
||||
if (basicPreferences.showConstants && !constants.isEmpty ())
|
||||
showIntegerLines (fullText, constants, " Const");
|
||||
|
||||
if (basicPreferences.showDuplicateSymbols && !uniqueSymbols.isEmpty ())
|
||||
{
|
||||
boolean headingShown = false;
|
||||
@ -422,9 +409,16 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
|
||||
for (Integer line : lines.keySet ())
|
||||
{
|
||||
String lineText = line + "";
|
||||
String list = lines.get (line).toString ();
|
||||
list = list.substring (1, list.length () - 1);
|
||||
fullText.append (String.format (" %6s %s%n", line, list));
|
||||
// fullText.append (String.format (" %6s %s%n", line, list));
|
||||
|
||||
for (String s : splitXref (list, 90, ' '))
|
||||
{
|
||||
fullText.append (String.format (" %6s %s%n", lineText, s));
|
||||
lineText = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -902,16 +896,16 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void checkUniqueName (String symbol)
|
||||
private void checkUniqueName (String symbol, Map<String, List<String>> map)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String uniqueName = getUniqueName (symbol);
|
||||
|
||||
List<String> usage = uniqueSymbols.get (uniqueName);
|
||||
List<String> usage = map.get (uniqueName);
|
||||
if (usage == null)
|
||||
{
|
||||
usage = new ArrayList<> ();
|
||||
uniqueSymbols.put (uniqueName, usage);
|
||||
map.put (uniqueName, usage);
|
||||
}
|
||||
|
||||
if (!usage.contains (symbol))
|
||||
@ -924,8 +918,8 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
{
|
||||
int ptr = symbol.length () - 1;
|
||||
|
||||
if (symbol.charAt (ptr) == Utility.ASCII_LEFT_BRACKET) // array
|
||||
ptr--;
|
||||
// if (symbol.charAt (ptr) == Utility.ASCII_LEFT_BRACKET) // array
|
||||
// ptr--;
|
||||
|
||||
if (symbol.charAt (ptr) == Utility.ASCII_DOLLAR // string
|
||||
|| symbol.charAt (ptr) == Utility.ASCII_PERCENT) // integer
|
||||
|
@ -27,6 +27,7 @@ public class SubLine
|
||||
private final List<String> symbols = new ArrayList<> ();
|
||||
private final List<String> functions = new ArrayList<> ();
|
||||
private final List<String> arrays = new ArrayList<> ();
|
||||
private final List<Integer> constants = new ArrayList<> ();
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
SubLine (SourceLine parent, int startPtr, int length)
|
||||
@ -135,19 +136,23 @@ public class SubLine
|
||||
return;
|
||||
|
||||
if (!Utility.isLetter ((byte) var.charAt (0)))
|
||||
{
|
||||
if (!constants.contains (var))
|
||||
constants.add (Integer.parseInt (var));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDefine && (var.equals (functionName) || var.equals (functionArgument)))
|
||||
return;
|
||||
|
||||
if (terminator == Utility.ASCII_LEFT_BRACKET)
|
||||
{
|
||||
// var += "(";
|
||||
if (!arrays.contains (var))
|
||||
arrays.add (var);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!symbols.contains (var))
|
||||
|
||||
if (!symbols.contains (var))
|
||||
symbols.add (var);
|
||||
}
|
||||
|
||||
@ -186,6 +191,13 @@ public class SubLine
|
||||
return gosubLines;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
List<Integer> getConstants ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return constants;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void doToken (byte b)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -18,6 +18,7 @@ public class BasicPreferences
|
||||
public boolean showXref = false;
|
||||
public boolean showCalls = false;
|
||||
public boolean showSymbols = false;
|
||||
public boolean showConstants = false;
|
||||
public boolean showFunctions = false;
|
||||
public boolean showDuplicateSymbols = false;
|
||||
public boolean splitDim = false;
|
||||
@ -43,6 +44,7 @@ public class BasicPreferences
|
||||
text.append (String.format ("Show Xref ................ %s%n", showXref));
|
||||
text.append (String.format ("Show CALL ................ %s%n", showCalls));
|
||||
text.append (String.format ("Show symbols ............. %s%n", showSymbols));
|
||||
text.append (String.format ("Show constants ........... %s%n", showConstants));
|
||||
text.append (String.format ("Show functions ........... %s%n", showFunctions));
|
||||
text.append (String.format ("Show duplicate symbols ... %s%n", showDuplicateSymbols));
|
||||
text.append (String.format ("List strings ............. %s%n", listStrings));
|
||||
|
@ -53,6 +53,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
private static final String PREFS_SHOW_XREF = "showXref";
|
||||
private static final String PREFS_SHOW_CALLS = "showCalls";
|
||||
private static final String PREFS_SHOW_SYMBOLS = "showSymbols";
|
||||
private static final String PREFS_SHOW_CONSTANTS = "showConstants";
|
||||
private static final String PREFS_SHOW_FUNCTIONS = "showFunctions";
|
||||
private static final String PREFS_SHOW_DUPLICATE_SYMBOLS = "showDuplicateSymbols";
|
||||
private static final String PREFS_LIST_STRINGS = "listStrings";
|
||||
@ -148,6 +149,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
final JMenuItem showCallsItem = new JCheckBoxMenuItem ("List CALLs");
|
||||
final JMenuItem showSymbolsItem = new JCheckBoxMenuItem ("List variables");
|
||||
final JMenuItem showFunctionsItem = new JCheckBoxMenuItem ("List functions");
|
||||
final JMenuItem showConstantsItem = new JCheckBoxMenuItem ("List constants");
|
||||
final JMenuItem showDuplicateSymbolsItem =
|
||||
new JCheckBoxMenuItem ("List duplicate variables");
|
||||
final JMenuItem listStringsItem = new JCheckBoxMenuItem ("List strings");
|
||||
@ -259,6 +261,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
applesoftMenu.add (showCallsItem);
|
||||
applesoftMenu.add (showSymbolsItem);
|
||||
applesoftMenu.add (showFunctionsItem);
|
||||
applesoftMenu.add (showConstantsItem);
|
||||
applesoftMenu.add (showDuplicateSymbolsItem);
|
||||
applesoftMenu.add (listStringsItem);
|
||||
|
||||
@ -323,6 +326,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
showCallsItem.addActionListener (basicPreferencesAction);
|
||||
showSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
showFunctionsItem.addActionListener (basicPreferencesAction);
|
||||
showConstantsItem.addActionListener (basicPreferencesAction);
|
||||
showDuplicateSymbolsItem.addActionListener (basicPreferencesAction);
|
||||
listStringsItem.addActionListener (basicPreferencesAction);
|
||||
blankAfterReturn.addActionListener (basicPreferencesAction);
|
||||
@ -376,6 +380,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
basicPreferences.showCalls = showCallsItem.isSelected ();
|
||||
basicPreferences.showSymbols = showSymbolsItem.isSelected ();
|
||||
basicPreferences.showFunctions = showFunctionsItem.isSelected ();
|
||||
basicPreferences.showConstants = showConstantsItem.isSelected ();
|
||||
basicPreferences.showDuplicateSymbols = showDuplicateSymbolsItem.isSelected ();
|
||||
basicPreferences.listStrings = listStringsItem.isSelected ();
|
||||
basicPreferences.blankAfterReturn = blankAfterReturn.isSelected ();
|
||||
@ -539,6 +544,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
prefs.putBoolean (PREFS_SHOW_CALLS, showCallsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_SYMBOLS, showSymbolsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_FUNCTIONS, showFunctionsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_CONSTANTS, showConstantsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS,
|
||||
showDuplicateSymbolsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_LIST_STRINGS, listStringsItem.isSelected ());
|
||||
@ -596,6 +602,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
showCallsItem.setSelected (prefs.getBoolean (PREFS_SHOW_CALLS, false));
|
||||
showSymbolsItem.setSelected (prefs.getBoolean (PREFS_SHOW_SYMBOLS, false));
|
||||
showFunctionsItem.setSelected (prefs.getBoolean (PREFS_SHOW_FUNCTIONS, false));
|
||||
showConstantsItem.setSelected (prefs.getBoolean (PREFS_SHOW_CONSTANTS, false));
|
||||
showDuplicateSymbolsItem
|
||||
.setSelected (prefs.getBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS, false));
|
||||
listStringsItem.setSelected (prefs.getBoolean (PREFS_LIST_STRINGS, false));
|
||||
|
Loading…
Reference in New Issue
Block a user