Fix for missing symbol check in named sections

This commit is contained in:
caheckman 2019-09-24 17:09:49 -04:00
parent d4e7c04809
commit 882e020406
2 changed files with 11 additions and 11 deletions

View file

@ -2444,9 +2444,9 @@ SectionVector *SleighCompile::nextNamedSection(SectionVector *vec,ConstructTpl *
{ // Add additional named p-code sections { // Add additional named p-code sections
sym->incrementDefineCount(); sym->incrementDefineCount();
SymbolScope *curscope = symtab.getCurrentScope();
symtab.popScope(); // Pop the scope of the last named section symtab.popScope(); // Pop the scope of the last named section
SymbolScope *curscope = symtab.getCurrentScope(); // This should now be the Constructor scope SymbolScope *parscope = symtab.getCurrentScope()->getParent();
SymbolScope *parscope = curscope->getParent();
if (parscope != symtab.getGlobalScope()) if (parscope != symtab.getGlobalScope())
throw LowlevelError("nextNamedSection called when not in section scope"); // Unrecoverable throw LowlevelError("nextNamedSection called when not in section scope"); // Unrecoverable
symtab.addScope(); // Add new scope under the Constructor scope (not the last section scope) symtab.addScope(); // Add new scope under the Constructor scope (not the last section scope)

View file

@ -352,9 +352,9 @@ public class SleighCompile extends SleighBase {
entry("nextNamedSection", vec, section, sym); entry("nextNamedSection", vec, section, sym);
// Add additional named p-code sections // Add additional named p-code sections
sym.incrementDefineCount(); sym.incrementDefineCount();
SymbolScope curscope = symtab.getCurrentScope();
symtab.popScope(); // Pop the scope of the last named section symtab.popScope(); // Pop the scope of the last named section
SymbolScope curscope = symtab.getCurrentScope(); // This should now be the Constructor scope SymbolScope parscope = symtab.getCurrentScope().getParent();
SymbolScope parscope = curscope.getParent();
if (parscope != symtab.getGlobalScope()) { if (parscope != symtab.getGlobalScope()) {
throw new LowlevelError("nextNamedSection called when not in section scope"); // Unrecoverable throw new LowlevelError("nextNamedSection called when not in section scope"); // Unrecoverable
} }
@ -603,7 +603,7 @@ public class SleighCompile extends SleighBase {
// Make sure label symbols are used properly // Make sure label symbols are used properly
String checkSymbols(SymbolScope scope) { String checkSymbols(SymbolScope scope) {
entry("checkSymbols", scope); entry("checkSymbols", scope);
List<String> errors = new ArrayList<>(); List<String> symbolErrors = new ArrayList<>();
IteratorSTL<SleighSymbol> iter; IteratorSTL<SleighSymbol> iter;
for (iter = scope.begin(); !iter.equals(scope.end()); iter.increment()) { for (iter = scope.begin(); !iter.equals(scope.end()); iter.increment()) {
SleighSymbol sym = iter.get(); SleighSymbol sym = iter.get();
@ -612,15 +612,15 @@ public class SleighCompile extends SleighBase {
} }
LabelSymbol labsym = (LabelSymbol) sym; LabelSymbol labsym = (LabelSymbol) sym;
if (labsym.getRefCount() == 0) { if (labsym.getRefCount() == 0) {
errors.add(MessageFormattingUtils.format(labsym.location, symbolErrors.add(MessageFormattingUtils.format(labsym.location,
String.format("Label <%s> was placed but never used", sym.getName()))); String.format("Label <%s> was placed but never used", sym.getName())));
} }
else if (!labsym.isPlaced()) { else if (!labsym.isPlaced()) {
errors.add(MessageFormattingUtils.format(labsym.location, symbolErrors.add(MessageFormattingUtils.format(labsym.location,
String.format("Label <%s> was referenced but never placed", sym.getName()))); String.format("Label <%s> was referenced but never placed", sym.getName())));
} }
} }
return errors.stream().collect(Collectors.joining(" ")); return symbolErrors.stream().collect(Collectors.joining(" "));
} }
// Make sure symbol table errors are caught // Make sure symbol table errors are caught
@ -1701,9 +1701,9 @@ public class SleighCompile extends SleighBase {
* compiler without using the launcher. The full SoftwareModeling classpath * compiler without using the launcher. The full SoftwareModeling classpath
* must be established including any dependencies. * must be established including any dependencies.
* @param args compiler command line arguments * @param args compiler command line arguments
* @throws JDOMException * @throws JDOMException for XML errors
* @throws IOException * @throws IOException for file access errors
* @throws RecognitionException * @throws RecognitionException for parsing errors
*/ */
public static void main(String[] args) throws JDOMException, IOException, RecognitionException { public static void main(String[] args) throws JDOMException, IOException, RecognitionException {
System.exit(SleighCompileLauncher.runMain(args, new HashMap<String, String>())); System.exit(SleighCompileLauncher.runMain(args, new HashMap<String, String>()));