Package mars.assembler.token
Class Macro
java.lang.Object
mars.assembler.token.Macro
Stores information about a macro definition for use by
MacroHandler.- Author:
- M.H.Sekhavat (sekhavat17@gmail.com), 2013; Sean Clarke, October 2024
-
Constructor Summary
ConstructorsConstructorDescriptionMacro(SourceLocation location, String name, List<Token> parameters) Create a new macro with the given signature. -
Method Summary
Modifier and TypeMethodDescriptionbooleanRegister a label which has been defined within the macro body.intcheckForParameter(Token token, AssemblerLog log) Check a token and determine whether it matches one of the parameters for this macro.getLines()Get the list of lines in the macro definition body.Get the location of the.macrodirective which started this macro's definition.getName()Get the name of this macro.Get the list of parameters for this macro, each of which is a token whose type isTokenType.MACRO_PARAMETER.booleanDetermine whether a given label matches one defined in the macro definition.toString()Convert this macro to a string containing the name and parameter count.
-
Constructor Details
-
Macro
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 typeTokenType.MACRO_PARAMETER.
-
-
Method Details
-
getLocation
Get the location of the.macrodirective which started this macro's definition.- Returns:
- The location of the macro definition.
-
getName
Get the name of this macro.- Returns:
- The macro name.
-
getParameters
Get the list of parameters for this macro, each of which is a token whose type isTokenType.MACRO_PARAMETER.- Returns:
- The parameter list.
-
getLines
Get the list of lines in the macro definition body.- Returns:
- The definition lines.
-
addLabel
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:
falseif this label has been previously defined in this macro, ortrueif this label has no conflicts.
-
hasLabel
Determine whether a given label matches one defined in the macro definition.- Parameters:
label- The label to search for.- Returns:
trueif the label is defined in this macro, orfalseotherwise.
-
checkForParameter
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 iftokenhas typeTokenType.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
-1iftokendoes not represent a parameter for this macro.
-
toString
Convert this macro to a string containing the name and parameter count. For example, a macromy_macrodefined with 3 parameters will result in the stringmy_macro/3.
-