Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.byteCode.instruction;
 
 
 import java.util.List;
 
 import static com.facebook.presto.byteCode.OpCode.ILOAD;
 import static com.facebook.presto.byteCode.OpCode.ISTORE;
 import static com.google.common.base.MoreObjects.toStringHelper;
 
 public abstract class VariableInstruction
         implements InstructionNode
 {
     public static InstructionNode loadVariable(int slot)
     {
         return new LoadVariableInstruction(new Variable("unknown"slot, ParameterizedType.type(Object.class)));
     }
 
     public static InstructionNode loadVariable(Variable variable)
     {
         return new LoadVariableInstruction(variable);
     }
 
     public static InstructionNode storeVariable(Variable variable)
     {
         return new StoreVariableInstruction(variable);
     }
 
     public static InstructionNode incrementVariable(Variable variablebyte increment)
     {
         return new IncrementVariableInstruction(variableincrement);
     }
 
     private final Variable variable;
 
     private VariableInstruction(Variable variable)
     {
         this. = variable;
     }
 
     public Variable getVariable()
     {
         return ;
     }
 
     @Override
     public List<ByteCodeNodegetChildNodes()
     {
         return ImmutableList.of();
     }
 
     @Override
     public <T> T accept(ByteCodeNode parentByteCodeVisitor<T> visitor)
     {
         return visitor.visitVariableInstruction(parentthis);
     }
 
     @Override
     public String toString()
     {
         return toStringHelper(this)
                 .add("variable")
                 .toString();
     }
 
     public static class LoadVariableInstruction
             extends VariableInstruction
     {
         public LoadVariableInstruction(Variable variable)
         {
             super(variable);
         }
 
         @Override
         public void accept(MethodVisitor visitor)
         {
             visitor.visitVarInsn(Type.getType(getVariable().getType().getType()).getOpcode(.getOpCode()), getVariable().getSlot());
         }
 
        @Override
        public <T> T accept(ByteCodeNode parentByteCodeVisitor<T> visitor)
        {
            return visitor.visitLoadVariable(parentthis);
        }
    }
    public static class StoreVariableInstruction
            extends VariableInstruction
    {
        public StoreVariableInstruction(Variable variable)
        {
            super(variable);
        }
        @Override
        public void accept(MethodVisitor visitor)
        {
            visitor.visitVarInsn(Type.getType(getVariable().getType().getType()).getOpcode(.getOpCode()), getVariable().getSlot());
        }
        @Override
        public <T> T accept(ByteCodeNode parentByteCodeVisitor<T> visitor)
        {
            return visitor.visitStoreVariable(parentthis);
        }
    }
    public static class IncrementVariableInstruction
            extends VariableInstruction
    {
        private final byte increment;
        public IncrementVariableInstruction(Variable variablebyte increment)
        {
            super(variable);
            String type = variable.getType().getClassName();
            Preconditions.checkArgument(ImmutableList.of("byte""short""int").contains(type), "variable must be an byte, short or int, but is %s"type);
            this. = increment;
        }
        public byte getIncrement()
        {
            return ;
        }
        @Override
        public void accept(MethodVisitor visitor)
        {
            visitor.visitIincInsn(getVariable().getSlot(), );
        }
        @Override
        public <T> T accept(ByteCodeNode parentByteCodeVisitor<T> visitor)
        {
            return visitor.visitIncrementVariable(parentthis);
        }
    }
New to GrepCode? Check out our FAQ X