Enum Class SleighUtils
- All Implemented Interfaces:
Serializable,Comparable<SleighUtils>,Constable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic classAn exception indicating the parse tree did not match a patternstatic interfaceA function representing a non-terminal in the Sleigh semantic grammarstatic classAn exception carrying one or more Sleigh parsing errorsstatic final recordA Sleigh parsing errorNested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateSleighExpression(org.antlr.runtime.tree.Tree tree) Generate source for the given Sleigh parse treestatic List<org.antlr.runtime.tree.Tree> getChildren(org.antlr.runtime.tree.Tree tree) Get the children of a parse tree nodestatic booleanisUnconditionalBreakpoint(org.antlr.runtime.tree.Tree tree) Check if the given tree represents an unconditional breakpoint in the emulatorstatic org.antlr.runtime.tree.TreeSynthesize a tree (node)static voidMatch the given tree to a given pattern with per-child actionsstatic voidmatchDereference(org.antlr.runtime.tree.Tree tree, Consumer<org.antlr.runtime.tree.Tree> onSpace, Consumer<org.antlr.runtime.tree.Tree> onSize, Consumer<org.antlr.runtime.tree.Tree> onOffset) static voidmatchTree(org.antlr.runtime.tree.Tree tree, int type, Consumer<List<org.antlr.runtime.tree.Tree>> onChildren) Match the given tree to a given patternstatic org.antlr.runtime.tree.TreenotTree(org.antlr.runtime.tree.Tree boolExpr) Apply the boolean "not" operator to a Sleigh expressionstatic <T extends org.antlr.runtime.RuleReturnScope>
TparseSleigh(SleighUtils.ParseFunction<T> nt, String text, String follow) Parse a non-terminal symbol from the Sleigh semantic grammarstatic org.antlr.runtime.tree.TreeparseSleighExpression(String expression) Parse a semantic expressionstatic org.antlr.runtime.tree.TreeparseSleighSemantic(String sleigh) Parse a semantic block, that is a list of Sleigh semantic statementsstatic SleighUtils.AddressOfrecoverAddressOf(String defaultSpace, String expression) static SleighUtils.AddressOfrecoverAddressOf(String defaultSpace, org.antlr.runtime.tree.Tree tree) static StringrecoverConditionFromBreakpoint(String sleigh) Check if the given Sleigh semantic block implements a conditional breakpoint, and recover that conditionstatic StringrecoverConditionFromBreakpoint(org.antlr.runtime.tree.Tree tree) Check if the given tree represents a conditional breakpoint, and recover that conditionstatic org.antlr.runtime.tree.TreeremoveParenthesisTree(org.antlr.runtime.tree.Tree tree) Remove parenthesis from the root of the given treestatic voidrequireCount(int count, List<?> list) Require (as part of pattern matching) that the given list of children has a particular sizestatic StringsleighForConditionalBreak(String condition) Generate Sleigh source for a breakpoint predicated on the given conditionstatic SleighUtilsReturns the enum constant of this class with the specified name.static SleighUtils[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Field Details
-
CONDITION_ALWAYS
- See Also:
-
UNCONDITIONAL_BREAK
- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
parseSleigh
public static <T extends org.antlr.runtime.RuleReturnScope> T parseSleigh(SleighUtils.ParseFunction<T> nt, String text, String follow) Parse a non-terminal symbol from the Sleigh semantic grammarBecause the ANTLR parsing function for the non-terminal symbol depends on the "follows" set to determine when it has finished, we can't just invoke the function in isolation without some hacking. If EOF is not in the non-terminal's follows set, then it won't recognize EOF as completing the non-terminal. Instead, we have to present some token that it will recognize. Furthermore, regardless of the follow token, we have to check that all of the given input was consumed by the parser.
- Type Parameters:
T- the type of result from parsing- Parameters:
nt- the function from the parser implementing the non-terminal symboltext- the text to parsefollow- a token that would ordinarily follow the non-terminal symbol, or empty for EOF- Returns:
- the parsed result
-
parseSleighSemantic
Parse a semantic block, that is a list of Sleigh semantic statements- Parameters:
sleigh- the source- Returns:
- the parse tree
-
parseSleighExpression
Parse a semantic expression- Parameters:
expression- the expression as a string- Returns:
- the parse tree
-
getChildren
Get the children of a parse tree node- Parameters:
tree- the node- Returns:
- the list of children
-
matchTree
public static void matchTree(org.antlr.runtime.tree.Tree tree, int type, Consumer<List<org.antlr.runtime.tree.Tree>> onChildren) Match the given tree to a given pattern- Parameters:
tree- the (sub-)tree to match, actually its root nodetype- the expected type of the given nodeonChildren- actions (usually sub-matching) to perform on the children
-
requireCount
Require (as part of pattern matching) that the given list of children has a particular size- Parameters:
count- the required sizelist- the list of children
-
match
@SafeVarargs public static void match(org.antlr.runtime.tree.Tree tree, int type, Consumer<org.antlr.runtime.tree.Tree>... onChild) Match the given tree to a given pattern with per-child actions- Parameters:
tree- the (sub-)tree to match, actually its root nodetype- the expected type of the given nodeonChild- a list of actions (usually sub-matching) to perform on each corresponding child. The matcher will verify the number of children matches the number of actions.
-
matchDereference
-
isUnconditionalBreakpoint
public static boolean isUnconditionalBreakpoint(org.antlr.runtime.tree.Tree tree) Check if the given tree represents an unconditional breakpoint in the emulator- Parameters:
tree- the result of parsing a semantic block- Returns:
- true if an unconditional breakpoint, false otherwise
-
recoverConditionFromBreakpoint
Check if the given tree represents a conditional breakpoint, and recover that condition- Parameters:
tree- the result of parsing a semantic block- Returns:
- the condition if matched, null otherwise
-
recoverConditionFromBreakpoint
Check if the given Sleigh semantic block implements a conditional breakpoint, and recover that condition- Parameters:
sleigh- the source for a Sleigh semantic block- Returns:
- the condition if matched, null otherwise
-
recoverAddressOf
public static SleighUtils.AddressOf recoverAddressOf(String defaultSpace, org.antlr.runtime.tree.Tree tree) -
recoverAddressOf
-
makeTree
public static org.antlr.runtime.tree.Tree makeTree(int type, String text, List<org.antlr.runtime.tree.Tree> children) Synthesize a tree (node)- Parameters:
type- the type of the nodetext- the "text" of the nodechildren- the children- Returns:
- the new node
-
generateSleighExpression
Generate source for the given Sleigh parse treeCurrently, only nodes that could appear in a Sleigh expression are supported.
- Parameters:
tree- the expression tree- Returns:
- the generated string
-
removeParenthesisTree
public static org.antlr.runtime.tree.Tree removeParenthesisTree(org.antlr.runtime.tree.Tree tree) Remove parenthesis from the root of the given treeIf the root is parenthesis, this simply gets the child. This is applied recursively until a non-parenthesis child is encountered.
- Parameters:
tree- the result of parsing a Sleigh expression- Returns:
- the same or sub-tree
-
notTree
public static org.antlr.runtime.tree.Tree notTree(org.antlr.runtime.tree.Tree boolExpr) Apply the boolean "not" operator to a Sleigh expressionThis will attempt to invert the expression when possible, e.g., by changing a top-level "equals" to "not equals." If that is not possible, the this adds parenthesis and applies the actual Sleigh boolean "not" operator.
- Parameters:
boolExpr- the result of parsing a Sleigh expression- Returns:
- the tree for the inverted expression
-
sleighForConditionalBreak
Generate Sleigh source for a breakpoint predicated on the given condition- Parameters:
condition- a Sleigh expression- Returns:
- the Sleigh source
-