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.Pseudocode; 022 import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor; 023 import org.jetbrains.jet.lang.descriptors.VariableDescriptor; 024 import org.jetbrains.jet.lang.psi.*; 025 import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; 026 import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; 027 028 import java.util.List; 029 030 public interface JetControlFlowBuilder { 031 // Subroutines 032 void enterSubroutine(@NotNull JetElement subroutine); 033 034 @NotNull 035 Pseudocode exitSubroutine(@NotNull JetElement subroutine); 036 037 @NotNull 038 JetElement getCurrentSubroutine(); 039 @Nullable 040 JetElement getReturnSubroutine(); 041 042 // Lexical scopes 043 void enterLexicalScope(@NotNull JetElement element); 044 void exitLexicalScope(@NotNull JetElement element); 045 046 // Entry/exit points 047 @NotNull 048 Label getEntryPoint(@NotNull JetElement labelElement); 049 @NotNull 050 Label getExitPoint(@NotNull JetElement labelElement); 051 052 // Declarations 053 void declareParameter(@NotNull JetParameter parameter); 054 void declareVariable(@NotNull JetVariableDeclaration property); 055 void declareFunction(@NotNull JetElement subroutine, @NotNull Pseudocode pseudocode); 056 057 // Labels 058 @NotNull 059 Label createUnboundLabel(); 060 @NotNull 061 Label createUnboundLabel(@NotNull String name); 062 063 void bindLabel(@NotNull Label label); 064 065 // Jumps 066 void jump(@NotNull Label label); 067 void jumpOnFalse(@NotNull Label label); 068 void jumpOnTrue(@NotNull Label label); 069 void nondeterministicJump(@NotNull Label label); // Maybe, jump to label 070 void nondeterministicJump(@NotNull List<Label> label); 071 void jumpToError(); 072 073 void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine); 074 void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine); 075 076 void throwException(@NotNull JetThrowExpression throwExpression); 077 078 // Loops 079 LoopInfo enterLoop(@NotNull JetExpression expression, @Nullable Label loopExitPoint, @Nullable Label conditionEntryPoint); 080 081 void exitLoop(@NotNull JetExpression expression); 082 @Nullable 083 JetElement getCurrentLoop(); 084 085 // Try-Finally 086 void enterTryFinally(@NotNull GenerationTrigger trigger); 087 void exitTryFinally(); 088 089 void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel); 090 091 // Reading values 092 void mark(@NotNull JetElement element); 093 094 void loadUnit(@NotNull JetExpression expression); 095 void loadConstant(@NotNull JetExpression expression, @Nullable CompileTimeConstant<?> constant); 096 void createAnonymousObject(@NotNull JetObjectLiteralExpression expression); 097 void createFunctionLiteral(@NotNull JetFunctionLiteralExpression expression); 098 void loadStringTemplate(@NotNull JetStringTemplateExpression expression); 099 100 void readThis(@NotNull JetExpression expression, @Nullable ReceiverParameterDescriptor parameterDescriptor); 101 void readVariable(@NotNull JetExpression expression, @Nullable VariableDescriptor variableDescriptor); 102 103 void call(@NotNull JetExpression expression, @NotNull ResolvedCall<?> resolvedCall); 104 105 enum PredefinedOperation { 106 AND, 107 OR, 108 NOT_NULL_ASSERTION 109 } 110 void predefinedOperation(@NotNull JetExpression expression, @Nullable PredefinedOperation operation); 111 112 void compilationError(@NotNull JetElement element, @NotNull String message); 113 114 void write(@NotNull JetElement assignment, @NotNull JetElement lValue); 115 116 // Other 117 void unsupported(JetElement element); 118 }