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