001 /*
002 * Copyright 2010-2015 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.kotlin.codegen.inline;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.kotlin.codegen.StackValue;
022
023 public class CapturedParamInfo extends ParameterInfo {
024 public final CapturedParamDesc desc;
025 private final String newFieldName;
026 private final boolean skipInConstructor;
027
028 //Now used only for bound function reference receiver
029 private boolean synthetic;
030
031 public CapturedParamInfo(@NotNull CapturedParamDesc desc, @NotNull String newFieldName, boolean skipped, int index, int remapIndex) {
032 super(desc.getType(), skipped, index, remapIndex, -1);
033 this.desc = desc;
034 this.newFieldName = newFieldName;
035 this.skipInConstructor = false;
036 }
037
038 public CapturedParamInfo(
039 @NotNull CapturedParamDesc desc,
040 @NotNull String newFieldName,
041 boolean skipped,
042 int index,
043 @Nullable StackValue remapIndex,
044 boolean skipInConstructor,
045 int declarationIndex
046 ) {
047 super(desc.getType(), skipped, index, remapIndex, declarationIndex);
048 this.desc = desc;
049 this.newFieldName = newFieldName;
050 this.skipInConstructor = skipInConstructor;
051 }
052
053 @NotNull
054 public String getNewFieldName() {
055 return newFieldName;
056 }
057
058 @NotNull
059 public String getOriginalFieldName() {
060 return desc.getFieldName();
061 }
062
063 @NotNull
064 public CapturedParamInfo cloneWithNewDeclarationIndex(int newDeclarationIndex) {
065 CapturedParamInfo result = new CapturedParamInfo(
066 desc, newFieldName, isSkipped, getIndex(), getRemapValue(), skipInConstructor, newDeclarationIndex
067 );
068 result.setLambda(getLambda());
069 result.setSynthetic(synthetic);
070 return result;
071 }
072
073 @NotNull
074 public String getContainingLambdaName() {
075 return desc.getContainingLambdaName();
076 }
077
078 public boolean isSkipInConstructor() {
079 return skipInConstructor;
080 }
081
082 public boolean isSynthetic() {
083 return synthetic;
084 }
085
086 public void setSynthetic(boolean synthetic) {
087 this.synthetic = synthetic;
088 }
089
090 public static boolean isSynthetic(@NotNull ParameterInfo info) {
091 return info instanceof CapturedParamInfo && ((CapturedParamInfo) info).isSynthetic();
092 }
093 }