Class ExpressionList


  • public class ExpressionList
    extends java.lang.Object
    Essentially a glorified linked list of Instructions plus some additional state to allow us to transform sequences. ExpressionLists do have the notion of a parent which allows us to clone an existing parent, allow transformations and then possibly commit or abort the transformations at will.
    • Method Detail

      • doesNotContainContinueOrBreak

        public boolean doesNotContainContinueOrBreak​(Instruction _start,
                                                     Instruction _extent)
        Determine whether the sequence of instructions from _start to _extent is free of branches which extend beyond _extent. As a side effect, if we find a possible branch it is likely a break or continue so we mark the conditional as such.
        Parameters:
        _start -
        _extent -
        Returns:
      • doesNotContainCompositeOrBranch

        public boolean doesNotContainCompositeOrBranch​(Instruction _start,
                                                       Instruction _exclusiveEnd)
      • unwind

        public void unwind()
      • createList

        public Instruction createList​(Instruction _newTail)
        [1] [2] [3] [4] Note that passing null here essentially deletes the existing expression list and returns the expression
        Parameters:
        _newTail -
        Returns:
      • add

        public Instruction add​(Instruction _instruction)
        Add this instruction to the end of the list.
        Parameters:
        _instruction -
        Returns:
        The instruction we added
      • insertBetween

        public void insertBetween​(Instruction _prev,
                                  Instruction _next,
                                  Instruction _newOne)
        Insert the given instruction (_newone) between the existing entries (_prev and _next).
        Parameters:
        _prev -
        _next -
        _newOne -
      • replaceInclusive

        public void replaceInclusive​(Instruction _head,
                                     Instruction _tail,
                                     Instruction _newOne)
        Inclusive replace between _head and _tail with _newOne.
            |      | --> |       | ---> ... ---> |       | ---> |      |
            | prev |     | _head |               | _tail |      | next |
            |      | <-- |       | <--- ... <----|       | <--- |      |
         
        To
            |      | --> |         | ---> |      |
            | prev |     | _newOne |      | next |
            |      | <-- |         | <--- |      |
         
      • foldComposite

        public boolean foldComposite​(Instruction _instruction)
                              throws ClassParseException
        Fold headTail.tail into valid composites
         if(??){then}...
           ?? ?> [THEN] ...
               -------->
        
         if (??){THEN}else{ELSE}...
        
           ?? ?> [THEN] >> [ELSE] ...
               ------------>
                         -------->
        
         sun for (INIT,??,DELTA){BODY} ...
        
            [INIT] ?? ?> [BODY] [DELTA] << ...
                       ------------------>
                    <-------------------
        
         sun for (,??,DELTA){BODY} ...
        
             ?? ?> [BODY] [DELTA] << ...
                 ------------------>
              <-------------------
        
         sun while (?){l} ...
        
            ?? ?> [BODY] << ...
                ----------->
             <------------
        
         eclipse for (INIT,??,DELTA){BODY} ...
            [INIT] >> [BODY] [DELTA] ?? ?< ...
                    ---------------->
                      <-----------------
        
         eclipse for (,??,DELTA){BODY} ...
            >> [BODY] [DELTA] ?? ?< ...
             --------------->
               <-----------------
        
         eclipse while (??){BODY} ...
            >> [BODY] ?? ?< ...
             -------->
               <----------
        
         eclipe if (?1) { while (?2) {BODY} } else {ELSE} ...
            ?1 ?> >> [BODY] ?2 ?< >> [ELSE] ...
                   --------->
                      <---------
                --------------------->
                                   -------->
        
         sun for (,?1,DELTA){ if (?2) { THEN break; } BODY} ...
        
             ?1 ?> ?2 ?> [THEN] >> [BODY] [DELTA] << ...
                       ----------->
                 ---------------------------------->
                                 ------------------>
             <------------------------------------
        
         sun for (,?1,DELTA){ if (?2) { THEN continue; } BODY} ...
        
             ?1 ?> ?2 ?> THEN >> [BODY] [DELTA] << ...
                       --------->
                               -------->
                 -------------------------------->
             <----------------------------------
        
         Some exceptions based on sun javac optimizations
        
         if (?1){ if (?2){THEN} }else{ ELSE } ...
           One might expect
            ?1 ?> ?2 ?> [THEN] >> [ELSE] ...
                ----------------->
                      -------->!
                                ------------->
           However the conditional branch to the unconditional (!) is optimized away and instead the unconditional inverted and extended
        
            ?1 ?> ?2 ?> [THEN] >> [ELSE] ...
                ----------------->
                      --------*--------->
        
         sun if (?1) { while (?2) {l} } else {e} ...
           One might expect
            ?1 ?> ?2 ?> [BODY] << >> [ELSE] ...
                ------------------->
                      ----------->!
                    <----------
                                   -------->
        
           However as above the conditional branch to the unconditional (!) can be optimized away and the conditional inverted and extended
            ?1 ?> ?2 ?> [BODY] << >> [ELSE] ...
                -------------------->
                      -----------*--------->
                    <-----------
        
           However we can also now remove the forward unconditional completely as it is unreachable
            ?1 ?> ?2 ?> [BODY] << [ELSE] ...
                ----------------->
                      ------------------>
                    <-----------
        
         sun while(?1){if (?2) {THEN} else {ELSE} } ...
           One might expect
            ?1 ?> ?2 ?> [BODY] >> [ELSE] << ...
                 -------------------------->
                   <---------------------
                       ---------->
                                 ------->!
        
           However the unconditional branch to the unconditional backbranch (!) can be optimized away and the unconditional wrapped back directly to the loop control head
            ?1 ?> ?2 ?> [BODY] << [ELSE] << ...
                 -------------------------->
                   <---------------------
                       ---------->
                   <-----------
        
         
        Parameters:
        _instruction -
        Throws:
        ClassParseException
      • dumpDiagram

        public java.lang.String dumpDiagram​(Instruction _instruction)
        Aids debugging. Creates a diagrammatic form of the roots (+ tail instruction) so that we can analyze control flow.
         I I I C C I U I U[I]I
               |---------->1
                 |---->1
                     |------>2
                         |-->2
         
        Parameters:
        _instruction - The instruction we are considering adding (may be null)
        Returns: