001 /*
002 * Copyright 2010-2013 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.jet.codegen.inline;
018
019 import org.jetbrains.asm4.AnnotationVisitor;
020 import org.jetbrains.asm4.Label;
021 import org.jetbrains.asm4.MethodVisitor;
022 import org.jetbrains.asm4.Opcodes;
023 import org.jetbrains.asm4.commons.InstructionAdapter;
024
025 public class RemapVisitor extends InstructionAdapter {
026
027 private final Label end;
028
029 private final VarRemapper remapper;
030
031 private final boolean remapReturn;
032
033 protected RemapVisitor(MethodVisitor mv, Label end, VarRemapper.ParamRemapper remapper, boolean remapReturn) {
034 super(InlineCodegenUtil.API, mv);
035 this.end = end;
036 this.remapper = remapper;
037 this.remapReturn = remapReturn;
038 }
039
040 @Override
041 public void visitInsn(int opcode) {
042 if (remapReturn && opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) {
043 super.visitJumpInsn(Opcodes.GOTO, end);
044 }
045 else {
046 super.visitInsn(opcode);
047 }
048 }
049
050 @Override
051 public void visitIincInsn(int var, int increment) {
052 remapper.visitIincInsn(var, increment, mv);
053 }
054
055 @Override
056 public void visitVarInsn(int opcode, int var) {
057 remapper.visitVarInsn(opcode, var, new InstructionAdapter(mv));
058 }
059
060 @Override
061 public void visitLocalVariable(
062 String name, String desc, String signature, Label start, Label end, int index
063 ) {
064
065 }
066
067 @Override
068 public AnnotationVisitor visitAnnotationDefault() {
069 return null;
070 }
071
072 @Override
073 public void visitMaxs(int maxStack, int maxLocals) {
074
075 }
076
077 @Override
078 public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
079 return null;
080 }
081
082 @Override
083 public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
084 return null;
085 }
086
087 @Override
088 public void visitFieldInsn(int opcode, String owner, String name, String desc) {
089 if (name.equals("$$$this")) {
090 super.visitVarInsn(Opcodes.ALOAD, 0);
091 } else {
092 super.visitFieldInsn(opcode, owner, name, desc);
093 }
094 }
095
096 //TODO not skip for lambdas
097 @Override
098 public void visitLineNumber(int line, Label start) {
099
100 }
101 }