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;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.asm4.Type;
021 import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
022 import org.jetbrains.jet.lang.psi.JetExpression;
023 import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
024
025 public interface CallGenerator {
026
027 public class DefaultCallGenerator implements CallGenerator {
028
029 private ExpressionCodegen codegen;
030
031 public DefaultCallGenerator(ExpressionCodegen codegen) {
032 this.codegen = codegen;
033 }
034
035 @Override
036 public void genCall(
037 CallableMethod callableMethod,
038 ResolvedCall<?> resolvedCall, int mask,
039 ExpressionCodegen codegen
040 ) {
041 if (mask == 0) {
042 callableMethod.invokeWithNotNullAssertion(codegen.v, codegen.getState(), resolvedCall);
043 }
044 else {
045 callableMethod.invokeDefaultWithNotNullAssertion(codegen.v, codegen.getState(), resolvedCall, mask);
046 }
047 }
048
049 @Override
050 public void afterParameterPut(Type type, StackValue stackValue, ValueParameterDescriptor valueParameterDescriptor) {
051
052 }
053
054 @Override
055 public void putHiddenParams() {
056
057 }
058
059 @Override
060 public void genValueAndPut(
061 @NotNull ValueParameterDescriptor valueParameterDescriptor,
062 @NotNull JetExpression argumentExpression,
063 @NotNull Type parameterType
064 ) {
065 StackValue value = codegen.gen(argumentExpression);
066 value.put(parameterType, codegen.v);
067 }
068
069 @Override
070 public void putCapturedValueOnStack(
071 @NotNull StackValue stackValue, @NotNull Type valueType, int paramIndex
072 ) {
073 stackValue.put(stackValue.type, codegen.v);
074 }
075 };
076
077 void genCall(CallableMethod callableMethod, ResolvedCall<?> resolvedCall, int mask, ExpressionCodegen codegen);
078
079 void afterParameterPut(Type type, StackValue stackValue, ValueParameterDescriptor valueParameterDescriptor);
080
081 void genValueAndPut(
082 @NotNull ValueParameterDescriptor valueParameterDescriptor,
083 @NotNull JetExpression argumentExpression,
084 @NotNull Type parameterType
085 );
086
087 void putCapturedValueOnStack(
088 @NotNull StackValue stackValue,
089 @NotNull Type valueType, int paramIndex
090 );
091
092 void putHiddenParams();
093 }