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        private final String fieldName;
027    
028        private int shift = 0;
029    
030        private LambdaInfo recapturedFrom;
031    
032        public static final CapturedParamInfo STUB = new CapturedParamInfo("", AsmTypeConstants.OBJECT_TYPE, true, -1, -1);
033    
034        public CapturedParamInfo(@NotNull String fieldName, @NotNull Type type, boolean skipped, int index, int remapIndex) {
035            super(type, skipped, index, remapIndex);
036            this.fieldName = fieldName;
037        }
038    
039        public CapturedParamInfo(@NotNull String fieldName, @NotNull Type type, boolean skipped, int index, StackValue remapIndex) {
040            super(type, skipped, index, remapIndex);
041            this.fieldName = fieldName;
042        }
043    
044        public String getFieldName() {
045            return fieldName;
046        }
047    
048        @Override
049        public int getIndex() {
050            return shift + super.getIndex();
051        }
052    
053        public void setShift(int shift) {
054            this.shift = shift;
055        }
056    
057        public LambdaInfo getRecapturedFrom() {
058            return recapturedFrom;
059        }
060    
061        public void setRecapturedFrom(LambdaInfo recapturedFrom) {
062            this.recapturedFrom = recapturedFrom;
063        }
064    
065        public CapturedParamInfo newIndex(int newIndex) {
066            return clone(newIndex, getRemapValue());
067        }
068    
069        public CapturedParamInfo clone(int newIndex, StackValue newRamapIndex) {
070            CapturedParamInfo capturedParamInfo = new CapturedParamInfo(fieldName, type, isSkipped, newIndex, newRamapIndex);
071            capturedParamInfo.setLambda(lambda);
072            capturedParamInfo.setRecapturedFrom(recapturedFrom);
073            return capturedParamInfo;
074        }
075    }