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.jet.codegen.context.CodegenContext;
020    import org.jetbrains.jet.codegen.state.GenerationState;
021    import org.jetbrains.jet.lang.psi.Call;
022    
023    import java.util.Collections;
024    import java.util.HashMap;
025    import java.util.List;
026    import java.util.Map;
027    
028    public class InliningContext {
029    
030        public final Map<Integer, LambdaInfo> expresssionMap;
031    
032        public final List<InvokeCall> invokeCalls;
033    
034        public final List<ConstructorInvocation> constructorInvocation;
035    
036        public final VarRemapper remapper;
037    
038        public final GenerationState state;
039    
040        public final NameGenerator nameGenerator;
041    
042        public final CodegenContext startContext;
043    
044        public final Call call;
045    
046        public final Map<String, String> typeMapping;
047    
048        public InliningContext(
049                Map<Integer, LambdaInfo> map,
050                List<InvokeCall> accesses,
051                List<ConstructorInvocation> invocation,
052                VarRemapper remapper,
053                GenerationState state,
054                NameGenerator nameGenerator,
055                CodegenContext startContext,
056                Call call,
057                Map<String, String> typeMapping
058        ) {
059            expresssionMap = map;
060            invokeCalls = accesses;
061            constructorInvocation = invocation;
062            this.remapper = remapper;
063            this.state = state;
064            this.nameGenerator = nameGenerator;
065            this.startContext = startContext;
066            this.call = call;
067            this.typeMapping = typeMapping;
068        }
069    
070        public InliningContext subInline(NameGenerator generator) {
071            return subInline(generator, Collections.<String, String>emptyMap());
072        }
073    
074        public InliningContext subInline(NameGenerator generator, Map<String, String> additionalTypeMappings) {
075            HashMap<String, String> newTypeMappings = new HashMap<String, String>(typeMapping);
076            newTypeMappings.putAll(additionalTypeMappings);
077            return new InliningContext(expresssionMap, invokeCalls, constructorInvocation, remapper, state, generator, startContext, call,
078                                    newTypeMappings);
079        }
080    }