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.context; 018 019 import org.jetbrains.annotations.NotNull; 020 import org.jetbrains.annotations.Nullable; 021 import org.jetbrains.asm4.Label; 022 import org.jetbrains.jet.codegen.OwnerKind; 023 import org.jetbrains.jet.codegen.StackValue; 024 import org.jetbrains.jet.codegen.binding.MutableClosure; 025 import org.jetbrains.jet.codegen.state.GenerationState; 026 import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; 027 import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; 028 import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; 029 import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor; 030 import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; 031 032 public class MethodContext extends CodegenContext<CallableMemberDescriptor> { 033 034 private Label methodStartLabel; 035 036 protected MethodContext( 037 @NotNull FunctionDescriptor contextDescriptor, 038 @NotNull OwnerKind contextKind, 039 @NotNull CodegenContext parentContext, 040 @Nullable MutableClosure closure 041 ) { 042 super(contextDescriptor instanceof PropertyAccessorDescriptor 043 ? ((PropertyAccessorDescriptor) contextDescriptor).getCorrespondingProperty() 044 : contextDescriptor, contextKind, parentContext, closure, 045 parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null); 046 } 047 048 @Override 049 public StackValue lookupInContext(DeclarationDescriptor d, @Nullable StackValue result, GenerationState state, boolean ignoreNoOuter) { 050 if (getContextDescriptor() == d) { 051 return result != null ? result : StackValue.local(0, AsmTypeConstants.OBJECT_TYPE); 052 } 053 054 //noinspection ConstantConditions 055 return getParentContext().lookupInContext(d, result, state, ignoreNoOuter); 056 } 057 058 @Override 059 public boolean isStatic() { 060 //noinspection ConstantConditions 061 return getParentContext().isStatic(); 062 } 063 064 @Override 065 public StackValue getOuterExpression(StackValue prefix, boolean ignoreNoOuter) { 066 //noinspection ConstantConditions 067 return getParentContext().getOuterExpression(prefix, false); 068 } 069 070 @Nullable 071 public Label getMethodStartLabel() { 072 return methodStartLabel; 073 } 074 075 public void setMethodStartLabel(@NotNull Label methodStartLabel) { 076 this.methodStartLabel = methodStartLabel; 077 } 078 079 @Override 080 public String toString() { 081 return "Method: " + getContextDescriptor(); 082 } 083 084 }