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.lang.cfg; 018 019 import org.jetbrains.annotations.NotNull; 020 import org.jetbrains.annotations.Nullable; 021 import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue; 022 import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode; 023 import org.jetbrains.jet.lang.cfg.pseudocode.TypePredicate; 024 import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.*; 025 import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; 026 import org.jetbrains.jet.lang.psi.*; 027 import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; 028 import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; 029 import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; 030 031 import java.util.List; 032 import java.util.Map; 033 034 public interface JetControlFlowBuilder { 035 // Subroutines 036 void enterSubroutine(@NotNull JetElement subroutine); 037 038 @NotNull 039 Pseudocode exitSubroutine(@NotNull JetElement subroutine); 040 041 @NotNull 042 JetElement getCurrentSubroutine(); 043 @Nullable 044 JetElement getReturnSubroutine(); 045 046 // Lexical scopes 047 void enterLexicalScope(@NotNull JetElement element); 048 void exitLexicalScope(@NotNull JetElement element); 049 050 // Entry/exit points 051 @NotNull 052 Label getEntryPoint(@NotNull JetElement labelElement); 053 @NotNull 054 Label getExitPoint(@NotNull JetElement labelElement); 055 056 // Declarations 057 void declareParameter(@NotNull JetParameter parameter); 058 void declareVariable(@NotNull JetVariableDeclaration property); 059 void declareFunction(@NotNull JetElement subroutine, @NotNull Pseudocode pseudocode); 060 061 // Labels 062 @NotNull 063 Label createUnboundLabel(); 064 @NotNull 065 Label createUnboundLabel(@NotNull String name); 066 067 void bindLabel(@NotNull Label label); 068 069 // Jumps 070 void jump(@NotNull Label label, @NotNull JetElement element); 071 void jumpOnFalse(@NotNull Label label, @NotNull JetElement element, @Nullable PseudoValue conditionValue); 072 void jumpOnTrue(@NotNull Label label, @NotNull JetElement element, @Nullable PseudoValue conditionValue); 073 void nondeterministicJump(@NotNull Label label, @NotNull JetElement element, @Nullable PseudoValue inputValue); // Maybe, jump to label 074 void nondeterministicJump(@NotNull List<Label> label, @NotNull JetElement element); 075 void jumpToError(@NotNull JetElement element); 076 077 void returnValue(@NotNull JetReturnExpression returnExpression, @NotNull PseudoValue returnValue, @NotNull JetElement subroutine); 078 void returnNoValue(@NotNull JetReturnExpression returnExpression, @NotNull JetElement subroutine); 079 080 void throwException(@NotNull JetThrowExpression throwExpression, @NotNull PseudoValue thrownValue); 081 082 // Loops 083 LoopInfo enterLoop(@NotNull JetExpression expression, @Nullable Label loopExitPoint, @Nullable Label conditionEntryPoint); 084 085 void exitLoop(@NotNull JetExpression expression); 086 @Nullable 087 JetElement getCurrentLoop(); 088 089 // Try-Finally 090 void enterTryFinally(@NotNull GenerationTrigger trigger); 091 void exitTryFinally(); 092 093 void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel); 094 095 // Reading values 096 void mark(@NotNull JetElement element); 097 098 @Nullable 099 PseudoValue getBoundValue(@Nullable JetElement element); 100 void bindValue(@NotNull PseudoValue value, @NotNull JetElement element); 101 102 void loadUnit(@NotNull JetExpression expression); 103 104 @NotNull 105 InstructionWithValue loadConstant(@NotNull JetExpression expression, @Nullable CompileTimeConstant<?> constant); 106 @NotNull 107 InstructionWithValue createAnonymousObject(@NotNull JetObjectLiteralExpression expression); 108 @NotNull 109 InstructionWithValue createFunctionLiteral(@NotNull JetFunctionLiteralExpression expression); 110 @NotNull 111 InstructionWithValue loadStringTemplate(@NotNull JetStringTemplateExpression expression, @NotNull List<PseudoValue> inputValues); 112 113 @NotNull 114 MagicInstruction magic( 115 @NotNull JetElement instructionElement, 116 @Nullable JetElement valueElement, 117 @NotNull List<PseudoValue> inputValues, 118 @NotNull Map<PseudoValue, TypePredicate> expectedTypes, 119 boolean synthetic 120 ); 121 122 @NotNull 123 MergeInstruction merge( 124 @NotNull JetExpression expression, 125 @NotNull List<PseudoValue> inputValues 126 ); 127 128 @NotNull 129 ReadValueInstruction readVariable( 130 @NotNull JetElement instructionElement, 131 @NotNull JetExpression valueElement, 132 @NotNull ResolvedCall<?> resolvedCall, 133 @NotNull Map<PseudoValue, ReceiverValue> receiverValues 134 ); 135 136 @NotNull 137 CallInstruction call( 138 @NotNull JetElement instructionElement, 139 @Nullable JetExpression valueElement, 140 @NotNull ResolvedCall<?> resolvedCall, 141 @NotNull Map<PseudoValue, ReceiverValue> receiverValues, 142 @NotNull Map<PseudoValue, ValueParameterDescriptor> arguments 143 ); 144 145 enum PredefinedOperation { 146 AND, 147 OR, 148 NOT_NULL_ASSERTION 149 } 150 @NotNull 151 OperationInstruction predefinedOperation( 152 @NotNull JetExpression expression, 153 @NotNull PredefinedOperation operation, 154 @NotNull List<PseudoValue> inputValues 155 ); 156 157 void compilationError(@NotNull JetElement element, @NotNull String message); 158 159 void write( 160 @NotNull JetElement assignment, 161 @NotNull JetElement lValue, 162 @NotNull PseudoValue rValue, 163 @NotNull AccessTarget target, 164 @NotNull Map<PseudoValue, ReceiverValue> receiverValues); 165 166 // Other 167 void unsupported(JetElement element); 168 }