Class Macro

java.lang.Object
mars.assembler.token.Macro

public class Macro extends Object
Stores information about a macro definition for use by MacroHandler.
Author:
M.H.Sekhavat (sekhavat17@gmail.com), 2013; Sean Clarke, October 2024
  • Constructor Details

    • Macro

      public Macro(SourceLocation location, String name, List<Token> parameters)
      Create a new macro with the given signature.
      Parameters:
      name - The name of the macro.
      parameters - The list of parameters for the macro, each of which must have type TokenType.MACRO_PARAMETER.
  • Method Details

    • getLocation

      public SourceLocation getLocation()
      Get the location of the .macro directive which started this macro's definition.
      Returns:
      The location of the macro definition.
    • getName

      public String getName()
      Get the name of this macro.
      Returns:
      The macro name.
    • getParameters

      public List<Token> getParameters()
      Get the list of parameters for this macro, each of which is a token whose type is TokenType.MACRO_PARAMETER.
      Returns:
      The parameter list.
    • getLines

      public List<SourceLine> getLines()
      Get the list of lines in the macro definition body.
      Returns:
      The definition lines.
    • addLabel

      public boolean addLabel(String label)
      Register a label which has been defined within the macro body. The label will be modified upon macro expansion to avoid conflicts between instances of the same label.
      Parameters:
      label - The label defined within the macro body.
      Returns:
      false if this label has been previously defined in this macro, or true if this label has no conflicts.
    • hasLabel

      public boolean hasLabel(String label)
      Determine whether a given label matches one defined in the macro definition.
      Parameters:
      label - The label to search for.
      Returns:
      true if the label is defined in this macro, or false otherwise.
    • checkForParameter

      public int checkForParameter(Token token, AssemblerLog log)
      Check a token and determine whether it matches one of the parameters for this macro.
      Parameters:
      token - The token to check.
      log - The log, which an error will be written to if token has type TokenType.MACRO_PARAMETER (i.e. starts with %) but does not correspond to any parameter of this macro.
      Returns:
      The index in the parameter list of the matched parameter, or -1 if token does not represent a parameter for this macro.
    • toString

      public String toString()
      Convert this macro to a string containing the name and parameter count. For example, a macro my_macro defined with 3 parameters will result in the string my_macro/3.
      Overrides:
      toString in class Object
      Returns:
      The signature of this macro in string form.