Class AssemblerLog

java.lang.Object
mars.assembler.log.AssemblerLog

public class AssemblerLog extends Object
A log for keeping track of errors occurring during the assembly process, whether during tokenizing, parsing, or assembling. While simply throwing an AssemblyError would be a valid way to report errors, using this log allows multiple LogMessages with varying LogLevels to be recorded in a single pass.

The original version of this class, written by Pete Sanderson, was called ErrorList.

Author:
Pete Sanderson, August 2003; Sean Clarke, October 2024
  • Constructor Details

    • AssemblerLog

      public AssemblerLog()
      Create a new, empty AssemblerLog.
  • Method Details

    • clear

      public void clear()
      Clear all messages from the log.
    • getMessages

      public List<LogMessage> getMessages()
      Get the list of all logged messages, regardless of level, in chronological order.
      Returns:
      The list of logged messages.
    • getMessageCount

      public int getMessageCount()
      Count the total number of logged messages, regardless of level.
      Returns:
      The number of messages.
    • getMessageCount

      public int getMessageCount(LogLevel level)
      Count the number of logged messages with a given level.
      Parameters:
      level - The level used to filter messages.
      Returns:
      The number of messages whose level is level.
    • hasMessages

      public boolean hasMessages(LogLevel level)
      Determine whether at least one message has been logged with a given level. This method is equivalent to the expression getMessageCount(level) > 0.
      Parameters:
      level - The level used to filter messages.
      Returns:
      true if at least one message has been logged with level level, or false if no such messages have been logged.
    • getMaxErrorCount

      public int getMaxErrorCount()
      Get the maximum number of errors which can be produced by a single assembler run.
      Returns:
      The maximum number of messages with level LogLevel.ERROR that can be logged.
    • setMaxErrorCount

      public void setMaxErrorCount(int maxErrorCount)
      Set the maximum number of errors which can be produced by a single assembler run.
      Parameters:
      maxErrorCount - The maximum number of messages with level LogLevel.ERROR that can be logged.
    • hasExceededMaxErrorCount

      public boolean hasExceededMaxErrorCount()
      Determine whether the current number of errors logged exceeds the maximum error count, indicating that the assembler should exit as soon as possible.
      Returns:
      true if the error count exceeds the maxiumm, or false otherwise.
      See Also:
    • setOutput

      public void setOutput(Consumer<LogMessage> output)
    • log

      public void log(LogMessage message)
      Log a message for the current assembler run. After this call, the newly logged message is considered to be the last message in chronological order.
      Parameters:
      message - The message to log
    • log

      public void log(LogLevel level, SourceLocation location, String content)
    • logInfo

      public void logInfo(SourceLocation location, String content)
    • logWarning

      public void logWarning(SourceLocation location, String content)
    • logError

      public void logError(SourceLocation location, String content)