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.psi.*;
023    
024    import java.util.Collection;
025    import java.util.List;
026    
027    public interface JetControlFlowBuilder {
028        void read(@NotNull JetElement element);
029        void readUnit(@NotNull JetExpression expression);
030    
031        // General label management
032        @NotNull
033        Label createUnboundLabel();
034        @NotNull
035        Label createUnboundLabel(@NotNull String name);
036    
037        void bindLabel(@NotNull Label label);
038    
039        // Jumps
040        void jump(@NotNull Label label);
041        void jumpOnFalse(@NotNull Label label);
042        void jumpOnTrue(@NotNull Label label);
043        void nondeterministicJump(Label label); // Maybe, jump to label
044        void nondeterministicJump(List<Label> label);
045        void jumpToError();
046    
047        // Entry/exit points
048        Label getEntryPoint(@NotNull JetElement labelElement);
049        Label getExitPoint(@NotNull JetElement labelElement);
050    
051        // Loops
052        LoopInfo enterLoop(@NotNull JetExpression expression, @Nullable Label loopExitPoint, @Nullable Label conditionEntryPoint);
053    
054        void exitLoop(@NotNull JetExpression expression);
055        @Nullable
056        JetElement getCurrentLoop();
057    
058        // Finally
059        void enterTryFinally(@NotNull GenerationTrigger trigger);
060        void exitTryFinally();
061    
062        // Subroutines
063        void enterSubroutine(@NotNull JetElement subroutine);
064    
065        Pseudocode exitSubroutine(@NotNull JetElement subroutine);
066    
067        @NotNull
068        JetElement getCurrentSubroutine();
069        @Nullable
070        JetElement getReturnSubroutine();
071        
072        void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine);
073    
074        void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine);
075        
076        void throwException(@NotNull JetThrowExpression throwExpression);
077    
078        void write(@NotNull JetElement assignment, @NotNull JetElement lValue);
079        
080        void declare(@NotNull JetParameter parameter);
081        void declare(@NotNull JetVariableDeclaration property);
082    
083        // Other
084        void unsupported(JetElement element);
085    
086        void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel);
087    }