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.annotations.NotNull; 020 import org.jetbrains.asm4.Type; 021 import org.jetbrains.jet.codegen.StackValue; 022 import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; 023 024 public class CapturedParamInfo extends ParameterInfo { 025 026 public static final CapturedParamInfo STUB = new CapturedParamInfo(CapturedParamDesc.createDesc(new CapturedParamOwner() { 027 @Override 028 public Type getType() { 029 return Type.getObjectType("STUB"); 030 } 031 }, "STUB", Type.getObjectType("STUB")), true, -1, -1); 032 033 public final CapturedParamDesc desc; 034 035 private int shift = 0; 036 037 public CapturedParamInfo(@NotNull CapturedParamDesc desc, boolean skipped, int index, int remapIndex) { 038 super(desc.getType(), skipped, index, remapIndex); 039 this.desc = desc; 040 } 041 042 public CapturedParamInfo(@NotNull CapturedParamDesc desc, boolean skipped, int index, StackValue remapIndex) { 043 super(desc.getType(), skipped, index, remapIndex); 044 this.desc = desc; 045 } 046 047 public String getFieldName() { 048 return desc.getFieldName(); 049 } 050 051 @Override 052 public int getIndex() { 053 return shift + super.getIndex(); 054 } 055 056 public void setShift(int shift) { 057 this.shift = shift; 058 } 059 060 public CapturedParamInfo newIndex(int newIndex) { 061 return clone(newIndex, getRemapValue()); 062 } 063 064 public CapturedParamInfo clone(int newIndex, StackValue newRamapIndex) { 065 CapturedParamInfo capturedParamInfo = new CapturedParamInfo(desc, isSkipped, newIndex, newRamapIndex); 066 capturedParamInfo.setLambda(lambda); 067 return capturedParamInfo; 068 } 069 070 public String getContainingLambdaName() { 071 return desc.getContainingLambda().getType().getInternalName(); 072 } 073 }