Class MergePatternsVisitor


  • public class MergePatternsVisitor
    extends Visitor
    A visitor which merges multiple patterns of a variant into one mask + pattern.

    In addition, it sets starting offsets for subrules. Expectation of a tree at input:

       Rule
         Variant
           Subrule
           Subrule
           Constant
           ...
     
    Expectation of the tree at output:
       Rule
         Variant
           Subrule
           Subrule
           Mask
           Pattern
     
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void visit​(Pattern pattern)
      Appends "true" bits to the mask (because these bits will be checked during decoding) and itself to the pattern (these bits should be the result of masking during decoding).
      void visit​(Subrule subrule)
      Sets the starting offset of the subrule.
      void visit​(Variant variant)
      Traverses all children nodes and adds one mask and pattern as a result of joining.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MergePatternsVisitor

        public MergePatternsVisitor()
    • Method Detail

      • visit

        public void visit​(Variant variant)
                   throws SemanticException
        Traverses all children nodes and adds one mask and pattern as a result of joining.
        Overrides:
        visit in class Visitor
        Parameters:
        variant - the variant node
        Throws:
        SemanticException - never
      • visit

        public void visit​(Pattern pattern)
        Appends "true" bits to the mask (because these bits will be checked during decoding) and itself to the pattern (these bits should be the result of masking during decoding).
        Overrides:
        visit in class Visitor
        Parameters:
        pattern - the pattern node
      • visit

        public void visit​(Subrule subrule)
                   throws SemanticException
        Sets the starting offset of the subrule.

        If the subrule has length specified, adds "false" bits to the mask because these bits will not be checked against a pattern during decoding.

        If the subrule does not refer to a rule (it is used only to return a value), it is removed from the tree.

        Overrides:
        visit in class Visitor
        Parameters:
        subrule - the subrule node
        Throws:
        SemanticException - when pre-pattern is longer than expected