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        // Entry/exit points
043        @NotNull
044        Label getEntryPoint(@NotNull JetElement labelElement);
045        @NotNull
046        Label getExitPoint(@NotNull JetElement labelElement);
047    
048        // Declarations
049        void declareParameter(@NotNull JetParameter parameter);
050        void declareVariable(@NotNull JetVariableDeclaration property);
051        void declareFunction(@NotNull JetElement subroutine, @NotNull Pseudocode pseudocode);
052    
053        // Labels
054        @NotNull
055        Label createUnboundLabel();
056        @NotNull
057        Label createUnboundLabel(@NotNull String name);
058    
059        void bindLabel(@NotNull Label label);
060    
061        // Jumps
062        void jump(@NotNull Label label);
063        void jumpOnFalse(@NotNull Label label);
064        void jumpOnTrue(@NotNull Label label);
065        void nondeterministicJump(@NotNull Label label); // Maybe, jump to label
066        void nondeterministicJump(@NotNull List<Label> label);
067        void jumpToError();
068    
069        void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine);
070        void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine);
071    
072        void throwException(@NotNull JetThrowExpression throwExpression);
073    
074        // Loops
075        LoopInfo enterLoop(@NotNull JetExpression expression, @Nullable Label loopExitPoint, @Nullable Label conditionEntryPoint);
076    
077        void exitLoop(@NotNull JetExpression expression);
078        @Nullable
079        JetElement getCurrentLoop();
080    
081        // Try-Finally
082        void enterTryFinally(@NotNull GenerationTrigger trigger);
083        void exitTryFinally();
084    
085        void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel);
086    
087        // Reading values
088        void mark(@NotNull JetElement element);
089    
090        void loadUnit(@NotNull JetExpression expression);
091        void loadConstant(@NotNull JetExpression expression, @Nullable CompileTimeConstant<?> constant);
092        void createAnonymousObject(@NotNull JetObjectLiteralExpression expression);
093        void createFunctionLiteral(@NotNull JetFunctionLiteralExpression expression);
094        void loadStringTemplate(@NotNull JetStringTemplateExpression expression);
095    
096        void readThis(@NotNull JetExpression expression, @Nullable ReceiverParameterDescriptor parameterDescriptor);
097        void readVariable(@NotNull JetExpression expression, @Nullable VariableDescriptor variableDescriptor);
098    
099        void call(@NotNull JetExpression expression, @NotNull ResolvedCall<?> resolvedCall);
100    
101        enum PredefinedOperation {
102            AND,
103            OR,
104            NOT_NULL_ASSERTION
105        }
106        void predefinedOperation(@NotNull JetExpression expression, @Nullable PredefinedOperation operation);
107    
108        void compilationError(@NotNull JetElement element, @NotNull String message);
109    
110        void write(@NotNull JetElement assignment, @NotNull JetElement lValue);
111        
112        // Other
113        void unsupported(JetElement element);
114    }