rename "Jet" to "Kotlin" in CFG classes
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface JetControlFlowBuilder {
|
public interface KotlinControlFlowBuilder {
|
||||||
// Subroutines
|
// Subroutines
|
||||||
void enterSubroutine(@NotNull KtElement subroutine);
|
void enterSubroutine(@NotNull KtElement subroutine);
|
||||||
|
|
||||||
+2
-2
@@ -30,10 +30,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
|
public abstract class KotlinControlFlowBuilderAdapter implements KotlinControlFlowBuilder {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract JetControlFlowBuilder getDelegateBuilder();
|
protected abstract KotlinControlFlowBuilder getDelegateBuilder();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadUnit(@NotNull KtExpression expression) {
|
public void loadUnit(@NotNull KtExpression expression) {
|
||||||
+9
-9
@@ -29,7 +29,7 @@ import kotlin.jvm.functions.Function1;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.JetControlFlowInstructionsGenerator;
|
import org.jetbrains.kotlin.cfg.pseudocode.KotlinControlFlowInstructionsGenerator;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue;
|
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode;
|
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
|
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
|
||||||
@@ -61,17 +61,17 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.cfg.JetControlFlowBuilder.PredefinedOperation.*;
|
import static org.jetbrains.kotlin.cfg.KotlinControlFlowBuilder.PredefinedOperation.*;
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.kotlin.lexer.KtTokens.*;
|
import static org.jetbrains.kotlin.lexer.KtTokens.*;
|
||||||
|
|
||||||
public class JetControlFlowProcessor {
|
public class KotlinControlFlowProcessor {
|
||||||
|
|
||||||
private final JetControlFlowBuilder builder;
|
private final KotlinControlFlowBuilder builder;
|
||||||
private final BindingTrace trace;
|
private final BindingTrace trace;
|
||||||
|
|
||||||
public JetControlFlowProcessor(BindingTrace trace) {
|
public KotlinControlFlowProcessor(BindingTrace trace) {
|
||||||
this.builder = new JetControlFlowInstructionsGenerator();
|
this.builder = new KotlinControlFlowInstructionsGenerator();
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class CFPVisitor extends KtVisitorVoid {
|
private class CFPVisitor extends KtVisitorVoid {
|
||||||
private final JetControlFlowBuilder builder;
|
private final KotlinControlFlowBuilder builder;
|
||||||
|
|
||||||
private final KtVisitorVoid conditionVisitor = new KtVisitorVoid() {
|
private final KtVisitorVoid conditionVisitor = new KtVisitorVoid() {
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private CFPVisitor(@NotNull JetControlFlowBuilder builder) {
|
private CFPVisitor(@NotNull KotlinControlFlowBuilder builder) {
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +411,7 @@ public class JetControlFlowProcessor {
|
|||||||
generateInstructions(right);
|
generateInstructions(right);
|
||||||
}
|
}
|
||||||
builder.bindLabel(resultLabel);
|
builder.bindLabel(resultLabel);
|
||||||
JetControlFlowBuilder.PredefinedOperation operation = operationType == ANDAND ? AND : OR;
|
KotlinControlFlowBuilder.PredefinedOperation operation = operationType == ANDAND ? AND : OR;
|
||||||
builder.predefinedOperation(expression, operation, elementsToValues(Arrays.asList(left, right)));
|
builder.predefinedOperation(expression, operation, elementsToValues(Arrays.asList(left, right)));
|
||||||
}
|
}
|
||||||
|
|
||||||
+20
-21
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeUtil;
|
|||||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeUtilsKt;
|
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeUtilsKt;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitor;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitor;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.JetElementInstruction;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstruction;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction;
|
||||||
@@ -67,21 +67,20 @@ import java.util.*;
|
|||||||
|
|
||||||
import static org.jetbrains.kotlin.cfg.PseudocodeVariablesData.VariableUseState.*;
|
import static org.jetbrains.kotlin.cfg.PseudocodeVariablesData.VariableUseState.*;
|
||||||
import static org.jetbrains.kotlin.cfg.TailRecursionKind.*;
|
import static org.jetbrains.kotlin.cfg.TailRecursionKind.*;
|
||||||
import static org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraversalOrder.FORWARD;
|
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.UNREACHABLE_CODE;
|
import static org.jetbrains.kotlin.diagnostics.Errors.UNREACHABLE_CODE;
|
||||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||||
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||||
import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType;
|
import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType;
|
||||||
|
|
||||||
public class JetFlowInformationProvider {
|
public class KotlinFlowInformationProvider {
|
||||||
|
|
||||||
private final KtElement subroutine;
|
private final KtElement subroutine;
|
||||||
private final Pseudocode pseudocode;
|
private final Pseudocode pseudocode;
|
||||||
private final BindingTrace trace;
|
private final BindingTrace trace;
|
||||||
private PseudocodeVariablesData pseudocodeVariablesData;
|
private PseudocodeVariablesData pseudocodeVariablesData;
|
||||||
|
|
||||||
private JetFlowInformationProvider(
|
private KotlinFlowInformationProvider(
|
||||||
@NotNull KtElement declaration,
|
@NotNull KtElement declaration,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull Pseudocode pseudocode
|
@NotNull Pseudocode pseudocode
|
||||||
@@ -91,11 +90,11 @@ public class JetFlowInformationProvider {
|
|||||||
this.pseudocode = pseudocode;
|
this.pseudocode = pseudocode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetFlowInformationProvider(
|
public KotlinFlowInformationProvider(
|
||||||
@NotNull KtElement declaration,
|
@NotNull KtElement declaration,
|
||||||
@NotNull BindingTrace trace
|
@NotNull BindingTrace trace
|
||||||
) {
|
) {
|
||||||
this(declaration, trace, new JetControlFlowProcessor(trace).generatePseudocode(declaration));
|
this(declaration, trace, new KotlinControlFlowProcessor(trace).generatePseudocode(declaration));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PseudocodeVariablesData getPseudocodeVariablesData() {
|
public PseudocodeVariablesData getPseudocodeVariablesData() {
|
||||||
@@ -190,8 +189,8 @@ public class JetFlowInformationProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitInstruction(@NotNull Instruction instruction) {
|
public void visitInstruction(@NotNull Instruction instruction) {
|
||||||
if (instruction instanceof JetElementInstruction) {
|
if (instruction instanceof KtElementInstruction) {
|
||||||
JetElementInstruction elementInstruction = (JetElementInstruction) instruction;
|
KtElementInstruction elementInstruction = (KtElementInstruction) instruction;
|
||||||
returnedExpressions.add(elementInstruction.getElement());
|
returnedExpressions.add(elementInstruction.getElement());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -212,8 +211,8 @@ public class JetFlowInformationProvider {
|
|||||||
(CallableDescriptor) trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, localDeclaration);
|
(CallableDescriptor) trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, localDeclaration);
|
||||||
KotlinType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null;
|
KotlinType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null;
|
||||||
|
|
||||||
JetFlowInformationProvider providerForLocalDeclaration =
|
KotlinFlowInformationProvider providerForLocalDeclaration =
|
||||||
new JetFlowInformationProvider(localDeclaration, trace, localDeclarationInstruction.getBody());
|
new KotlinFlowInformationProvider(localDeclaration, trace, localDeclarationInstruction.getBody());
|
||||||
|
|
||||||
providerForLocalDeclaration.checkFunction(expectedType);
|
providerForLocalDeclaration.checkFunction(expectedType);
|
||||||
}
|
}
|
||||||
@@ -270,12 +269,12 @@ public class JetFlowInformationProvider {
|
|||||||
Set<KtElement> reachableElements = Sets.newHashSet();
|
Set<KtElement> reachableElements = Sets.newHashSet();
|
||||||
Set<KtElement> unreachableElements = Sets.newHashSet();
|
Set<KtElement> unreachableElements = Sets.newHashSet();
|
||||||
for (Instruction instruction : pseudocode.getInstructionsIncludingDeadCode()) {
|
for (Instruction instruction : pseudocode.getInstructionsIncludingDeadCode()) {
|
||||||
if (!(instruction instanceof JetElementInstruction)
|
if (!(instruction instanceof KtElementInstruction)
|
||||||
|| instruction instanceof LoadUnitValueInstruction
|
|| instruction instanceof LoadUnitValueInstruction
|
||||||
|| instruction instanceof MergeInstruction
|
|| instruction instanceof MergeInstruction
|
||||||
|| (instruction instanceof MagicInstruction && ((MagicInstruction) instruction).getSynthetic())) continue;
|
|| (instruction instanceof MagicInstruction && ((MagicInstruction) instruction).getSynthetic())) continue;
|
||||||
|
|
||||||
KtElement element = ((JetElementInstruction) instruction).getElement();
|
KtElement element = ((KtElementInstruction) instruction).getElement();
|
||||||
|
|
||||||
if (instruction instanceof JumpInstruction) {
|
if (instruction instanceof JumpInstruction) {
|
||||||
boolean isJumpElement = element instanceof KtBreakExpression
|
boolean isJumpElement = element instanceof KtBreakExpression
|
||||||
@@ -312,7 +311,7 @@ public class JetFlowInformationProvider {
|
|||||||
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
|
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
|
||||||
|
|
||||||
PseudocodeTraverserKt.traverse(
|
PseudocodeTraverserKt.traverse(
|
||||||
pseudocode, FORWARD, initializers,
|
pseudocode, TraversalOrder.FORWARD, initializers,
|
||||||
new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableControlFlowState>>() {
|
new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableControlFlowState>>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(
|
public void execute(
|
||||||
@@ -650,12 +649,12 @@ public class JetFlowInformationProvider {
|
|||||||
public void markUnusedExpressions() {
|
public void markUnusedExpressions() {
|
||||||
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
|
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
|
||||||
PseudocodeTraverserKt.traverse(
|
PseudocodeTraverserKt.traverse(
|
||||||
pseudocode, FORWARD, new JetFlowInformationProvider.FunctionVoid1<Instruction>() {
|
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Instruction instruction) {
|
public void execute(@NotNull Instruction instruction) {
|
||||||
if (!(instruction instanceof JetElementInstruction)) return;
|
if (!(instruction instanceof KtElementInstruction)) return;
|
||||||
|
|
||||||
KtElement element = ((JetElementInstruction)instruction).getElement();
|
KtElement element = ((KtElementInstruction)instruction).getElement();
|
||||||
if (!(element instanceof KtExpression)) return;
|
if (!(element instanceof KtExpression)) return;
|
||||||
|
|
||||||
if (BindingContextUtilsKt.isUsedAsStatement((KtExpression) element, trace.getBindingContext())
|
if (BindingContextUtilsKt.isUsedAsStatement((KtExpression) element, trace.getBindingContext())
|
||||||
@@ -678,7 +677,7 @@ public class JetFlowInformationProvider {
|
|||||||
|
|
||||||
public void markStatements() {
|
public void markStatements() {
|
||||||
PseudocodeTraverserKt.traverse(
|
PseudocodeTraverserKt.traverse(
|
||||||
pseudocode, FORWARD, new JetFlowInformationProvider.FunctionVoid1<Instruction>() {
|
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Instruction instruction) {
|
public void execute(@NotNull Instruction instruction) {
|
||||||
PseudoValue value = instruction instanceof InstructionWithValue
|
PseudoValue value = instruction instanceof InstructionWithValue
|
||||||
@@ -696,7 +695,7 @@ public class JetFlowInformationProvider {
|
|||||||
|
|
||||||
public void markIfWithoutElse() {
|
public void markIfWithoutElse() {
|
||||||
PseudocodeTraverserKt.traverse(
|
PseudocodeTraverserKt.traverse(
|
||||||
pseudocode, FORWARD, new JetFlowInformationProvider.FunctionVoid1<Instruction>() {
|
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Instruction instruction) {
|
public void execute(@NotNull Instruction instruction) {
|
||||||
PseudoValue value = instruction instanceof InstructionWithValue
|
PseudoValue value = instruction instanceof InstructionWithValue
|
||||||
@@ -718,7 +717,7 @@ public class JetFlowInformationProvider {
|
|||||||
|
|
||||||
public void markWhenWithoutElse() {
|
public void markWhenWithoutElse() {
|
||||||
PseudocodeTraverserKt.traverse(
|
PseudocodeTraverserKt.traverse(
|
||||||
pseudocode, FORWARD, new JetFlowInformationProvider.FunctionVoid1<Instruction>() {
|
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Instruction instruction) {
|
public void execute(@NotNull Instruction instruction) {
|
||||||
PseudoValue value = instruction instanceof InstructionWithValue
|
PseudoValue value = instruction instanceof InstructionWithValue
|
||||||
@@ -767,7 +766,7 @@ public class JetFlowInformationProvider {
|
|||||||
final Map<KtElement, KindAndCall> calls = new HashMap<KtElement, KindAndCall>();
|
final Map<KtElement, KindAndCall> calls = new HashMap<KtElement, KindAndCall>();
|
||||||
PseudocodeTraverserKt.traverse(
|
PseudocodeTraverserKt.traverse(
|
||||||
pseudocode,
|
pseudocode,
|
||||||
FORWARD,
|
TraversalOrder.FORWARD,
|
||||||
new FunctionVoid1<Instruction>() {
|
new FunctionVoid1<Instruction>() {
|
||||||
public void execute(@NotNull Instruction instruction) {
|
public void execute(@NotNull Instruction instruction) {
|
||||||
if (!(instruction instanceof CallInstruction)) return;
|
if (!(instruction instanceof CallInstruction)) return;
|
||||||
@@ -797,7 +796,7 @@ public class JetFlowInformationProvider {
|
|||||||
boolean isTail = PseudocodeTraverserKt.traverseFollowingInstructions(
|
boolean isTail = PseudocodeTraverserKt.traverseFollowingInstructions(
|
||||||
callInstruction,
|
callInstruction,
|
||||||
new HashSet<Instruction>(),
|
new HashSet<Instruction>(),
|
||||||
FORWARD,
|
TraversalOrder.FORWARD,
|
||||||
new TailRecursionDetector(subroutine, callInstruction)
|
new TailRecursionDetector(subroutine, callInstruction)
|
||||||
);
|
);
|
||||||
|
|
||||||
+11
-11
@@ -35,32 +35,32 @@ import org.jetbrains.kotlin.types.KotlinType;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAdapter {
|
public class KotlinControlFlowInstructionsGenerator extends KotlinControlFlowBuilderAdapter {
|
||||||
private JetControlFlowBuilder builder = null;
|
private KotlinControlFlowBuilder builder = null;
|
||||||
|
|
||||||
private final Stack<LoopInfo> loopInfo = new Stack<LoopInfo>();
|
private final Stack<LoopInfo> loopInfo = new Stack<LoopInfo>();
|
||||||
private final Stack<LexicalScope> lexicalScopes = new Stack<LexicalScope>();
|
private final Stack<LexicalScope> lexicalScopes = new Stack<LexicalScope>();
|
||||||
private final Map<KtElement, BreakableBlockInfo> elementToBlockInfo = new HashMap<KtElement, BreakableBlockInfo>();
|
private final Map<KtElement, BreakableBlockInfo> elementToBlockInfo = new HashMap<KtElement, BreakableBlockInfo>();
|
||||||
private int labelCount = 0;
|
private int labelCount = 0;
|
||||||
|
|
||||||
private final Stack<JetControlFlowInstructionsGeneratorWorker> builders = new Stack<JetControlFlowInstructionsGeneratorWorker>();
|
private final Stack<KotlinControlFlowInstructionsGeneratorWorker> builders = new Stack<KotlinControlFlowInstructionsGeneratorWorker>();
|
||||||
|
|
||||||
private final Stack<BlockInfo> allBlocks = new Stack<BlockInfo>();
|
private final Stack<BlockInfo> allBlocks = new Stack<BlockInfo>();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected JetControlFlowBuilder getDelegateBuilder() {
|
protected KotlinControlFlowBuilder getDelegateBuilder() {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushBuilder(KtElement scopingElement, KtElement subroutine) {
|
private void pushBuilder(KtElement scopingElement, KtElement subroutine) {
|
||||||
JetControlFlowInstructionsGeneratorWorker worker = new JetControlFlowInstructionsGeneratorWorker(scopingElement, subroutine);
|
KotlinControlFlowInstructionsGeneratorWorker worker = new KotlinControlFlowInstructionsGeneratorWorker(scopingElement, subroutine);
|
||||||
builders.push(worker);
|
builders.push(worker);
|
||||||
builder = worker;
|
builder = worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetControlFlowInstructionsGeneratorWorker popBuilder(@NotNull KtElement element) {
|
private KotlinControlFlowInstructionsGeneratorWorker popBuilder(@NotNull KtElement element) {
|
||||||
JetControlFlowInstructionsGeneratorWorker worker = builders.pop();
|
KotlinControlFlowInstructionsGeneratorWorker worker = builders.pop();
|
||||||
if (!builders.isEmpty()) {
|
if (!builders.isEmpty()) {
|
||||||
builder = builders.peek();
|
builder = builders.peek();
|
||||||
}
|
}
|
||||||
@@ -88,15 +88,15 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
public Pseudocode exitSubroutine(@NotNull KtElement subroutine) {
|
public Pseudocode exitSubroutine(@NotNull KtElement subroutine) {
|
||||||
super.exitSubroutine(subroutine);
|
super.exitSubroutine(subroutine);
|
||||||
builder.exitLexicalScope(subroutine);
|
builder.exitLexicalScope(subroutine);
|
||||||
JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
KotlinControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
||||||
if (!builders.empty()) {
|
if (!builders.empty()) {
|
||||||
JetControlFlowInstructionsGeneratorWorker builder = builders.peek();
|
KotlinControlFlowInstructionsGeneratorWorker builder = builders.peek();
|
||||||
builder.declareFunction(subroutine, worker.getPseudocode());
|
builder.declareFunction(subroutine, worker.getPseudocode());
|
||||||
}
|
}
|
||||||
return worker.getPseudocode();
|
return worker.getPseudocode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class JetControlFlowInstructionsGeneratorWorker implements JetControlFlowBuilder {
|
private class KotlinControlFlowInstructionsGeneratorWorker implements KotlinControlFlowBuilder {
|
||||||
|
|
||||||
private final PseudocodeImpl pseudocode;
|
private final PseudocodeImpl pseudocode;
|
||||||
private final Label error;
|
private final Label error;
|
||||||
@@ -115,7 +115,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private JetControlFlowInstructionsGeneratorWorker(@NotNull KtElement scopingElement, @NotNull KtElement returnSubroutine) {
|
private KotlinControlFlowInstructionsGeneratorWorker(@NotNull KtElement scopingElement, @NotNull KtElement returnSubroutine) {
|
||||||
this.pseudocode = new PseudocodeImpl(scopingElement);
|
this.pseudocode = new PseudocodeImpl(scopingElement);
|
||||||
this.error = pseudocode.createLabel("error", null);
|
this.error = pseudocode.createLabel("error", null);
|
||||||
this.sink = pseudocode.createLabel("sink", null);
|
this.sink = pseudocode.createLabel("sink", null);
|
||||||
@@ -228,8 +228,8 @@ public class PseudocodeImpl implements Pseudocode {
|
|||||||
mutableInstructionList.add(instruction);
|
mutableInstructionList.add(instruction);
|
||||||
instruction.setOwner(this);
|
instruction.setOwner(this);
|
||||||
|
|
||||||
if (instruction instanceof JetElementInstruction) {
|
if (instruction instanceof KtElementInstruction) {
|
||||||
JetElementInstruction elementInstruction = (JetElementInstruction) instruction;
|
KtElementInstruction elementInstruction = (KtElementInstruction) instruction;
|
||||||
representativeInstructions.put(elementInstruction.getElement(), instruction);
|
representativeInstructions.put(elementInstruction.getElement(), instruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.cfg.pseudocode;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.cfg.JetControlFlowProcessor;
|
import org.jetbrains.kotlin.cfg.KotlinControlFlowProcessor;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessTarget;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessTarget;
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessValueInstruction;
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessValueInstruction;
|
||||||
@@ -84,7 +84,7 @@ public class PseudocodeUtil {
|
|||||||
public void report(@NotNull Diagnostic diagnostic) {
|
public void report(@NotNull Diagnostic diagnostic) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return new JetControlFlowProcessor(mockTrace).generatePseudocode(declaration);
|
return new KotlinControlFlowProcessor(mockTrace).generatePseudocode(declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
|||||||
public abstract class InstructionWithNext(
|
public abstract class InstructionWithNext(
|
||||||
element: KtElement,
|
element: KtElement,
|
||||||
lexicalScope: LexicalScope
|
lexicalScope: LexicalScope
|
||||||
) : JetElementInstructionImpl(element, lexicalScope) {
|
) : KtElementInstructionImpl(element, lexicalScope) {
|
||||||
public var next: Instruction? = null
|
public var next: Instruction? = null
|
||||||
set(value: Instruction?) {
|
set(value: Instruction?) {
|
||||||
field = outgoingEdgeTo(value)
|
field = outgoingEdgeTo(value)
|
||||||
|
|||||||
+1
-1
@@ -18,6 +18,6 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
|
||||||
public interface JetElementInstruction : Instruction {
|
public interface KtElementInstruction : Instruction {
|
||||||
public val element: KtElement
|
public val element: KtElement
|
||||||
}
|
}
|
||||||
+2
-2
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
|
||||||
public abstract class JetElementInstructionImpl(
|
public abstract class KtElementInstructionImpl(
|
||||||
override val element: KtElement,
|
override val element: KtElement,
|
||||||
lexicalScope: LexicalScope
|
lexicalScope: LexicalScope
|
||||||
) : InstructionImpl(lexicalScope), JetElementInstruction {
|
) : InstructionImpl(lexicalScope), KtElementInstruction {
|
||||||
protected fun render(element: PsiElement): String =
|
protected fun render(element: PsiElement): String =
|
||||||
element.getText()?.replace("\\s+".toRegex(), " ") ?: ""
|
element.getText()?.replace("\\s+".toRegex(), " ") ?: ""
|
||||||
}
|
}
|
||||||
+2
-2
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cfg.pseudocode.instructions.eval
|
package org.jetbrains.kotlin.cfg.pseudocode.instructions.eval
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.JetElementInstruction
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstruction
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
|
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
|
||||||
|
|
||||||
public interface InstructionWithValue : JetElementInstruction {
|
public interface InstructionWithValue : KtElementInstruction {
|
||||||
public val outputValue: PseudoValue?
|
public val outputValue: PseudoValue?
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps
|
|||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.cfg.Label
|
import org.jetbrains.kotlin.cfg.Label
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.LexicalScope
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.LexicalScope
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.JetElementInstructionImpl
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstructionImpl
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionImpl
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionImpl
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||||
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
||||||
@@ -28,7 +28,7 @@ public abstract class AbstractJumpInstruction(
|
|||||||
element: KtElement,
|
element: KtElement,
|
||||||
public val targetLabel: Label,
|
public val targetLabel: Label,
|
||||||
lexicalScope: LexicalScope
|
lexicalScope: LexicalScope
|
||||||
) : JetElementInstructionImpl(element, lexicalScope), JumpInstruction {
|
) : KtElementInstructionImpl(element, lexicalScope), JumpInstruction {
|
||||||
public var resolvedTarget: Instruction? = null
|
public var resolvedTarget: Instruction? = null
|
||||||
set(value: Instruction?) {
|
set(value: Instruction?) {
|
||||||
field = outgoingEdgeTo(value)
|
field = outgoingEdgeTo(value)
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.cfg.Label
|
|||||||
import com.google.common.collect.Maps
|
import com.google.common.collect.Maps
|
||||||
import com.google.common.collect.Lists
|
import com.google.common.collect.Lists
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.LexicalScope
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.LexicalScope
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.JetElementInstructionImpl
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstructionImpl
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitor
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitor
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitorWithResult
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitorWithResult
|
||||||
@@ -34,7 +34,7 @@ public class NondeterministicJumpInstruction(
|
|||||||
targetLabels: List<Label>,
|
targetLabels: List<Label>,
|
||||||
lexicalScope: LexicalScope,
|
lexicalScope: LexicalScope,
|
||||||
public val inputValue: PseudoValue?
|
public val inputValue: PseudoValue?
|
||||||
) : JetElementInstructionImpl(element, lexicalScope), JumpInstruction {
|
) : KtElementInstructionImpl(element, lexicalScope), JumpInstruction {
|
||||||
private var _next: Instruction? = null
|
private var _next: Instruction? = null
|
||||||
private val _resolvedTargets: MutableMap<Label, Instruction> = Maps.newLinkedHashMap()
|
private val _resolvedTargets: MutableMap<Label, Instruction> = Maps.newLinkedHashMap()
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.cfg.JetFlowInformationProvider;
|
import org.jetbrains.kotlin.cfg.KotlinFlowInformationProvider;
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor;
|
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||||
@@ -68,7 +68,7 @@ public class ControlFlowAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkSecondaryConstructor(@NotNull KtSecondaryConstructor constructor) {
|
private void checkSecondaryConstructor(@NotNull KtSecondaryConstructor constructor) {
|
||||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider(constructor, trace);
|
KotlinFlowInformationProvider flowInformationProvider = new KotlinFlowInformationProvider(constructor, trace);
|
||||||
flowInformationProvider.checkDeclaration();
|
flowInformationProvider.checkDeclaration();
|
||||||
flowInformationProvider.checkFunction(builtIns.getUnitType());
|
flowInformationProvider.checkFunction(builtIns.getUnitType());
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ public class ControlFlowAnalyzer {
|
|||||||
private void checkDeclarationContainer(@NotNull BodiesResolveContext c, KtDeclarationContainer declarationContainer) {
|
private void checkDeclarationContainer(@NotNull BodiesResolveContext c, KtDeclarationContainer declarationContainer) {
|
||||||
// A pseudocode of class/object initialization corresponds to a class/object
|
// A pseudocode of class/object initialization corresponds to a class/object
|
||||||
// or initialization of properties corresponds to a package declared in a file
|
// or initialization of properties corresponds to a package declared in a file
|
||||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((KtElement) declarationContainer, trace);
|
KotlinFlowInformationProvider flowInformationProvider = new KotlinFlowInformationProvider((KtElement) declarationContainer, trace);
|
||||||
if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
|
if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
|
||||||
flowInformationProvider.checkForLocalClassOrObjectMode();
|
flowInformationProvider.checkForLocalClassOrObjectMode();
|
||||||
return;
|
return;
|
||||||
@@ -97,7 +97,7 @@ public class ControlFlowAnalyzer {
|
|||||||
|
|
||||||
private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KotlinType expectedReturnType) {
|
private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KotlinType expectedReturnType) {
|
||||||
if (!function.hasBody()) return;
|
if (!function.hasBody()) return;
|
||||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider(function, trace);
|
KotlinFlowInformationProvider flowInformationProvider = new KotlinFlowInformationProvider(function, trace);
|
||||||
if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
|
if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
|
||||||
flowInformationProvider.checkForLocalClassOrObjectMode();
|
flowInformationProvider.checkForLocalClassOrObjectMode();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import com.intellij.psi.util.CachedValuesManager
|
|||||||
import com.intellij.psi.util.PsiModificationTracker
|
import com.intellij.psi.util.PsiModificationTracker
|
||||||
import com.intellij.util.containers.ContainerUtil
|
import com.intellij.util.containers.ContainerUtil
|
||||||
import org.jetbrains.kotlin.asJava.KotlinCodeBlockModificationListener
|
import org.jetbrains.kotlin.asJava.KotlinCodeBlockModificationListener
|
||||||
import org.jetbrains.kotlin.cfg.JetFlowInformationProvider
|
import org.jetbrains.kotlin.cfg.KotlinFlowInformationProvider
|
||||||
import org.jetbrains.kotlin.container.get
|
import org.jetbrains.kotlin.container.get
|
||||||
import org.jetbrains.kotlin.context.SimpleGlobalContext
|
import org.jetbrains.kotlin.context.SimpleGlobalContext
|
||||||
import org.jetbrains.kotlin.context.withModule
|
import org.jetbrains.kotlin.context.withModule
|
||||||
@@ -300,7 +300,7 @@ public class ResolveElementCache(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val controlFlowTrace = DelegatingBindingTrace(trace.getBindingContext(), "Element control flow resolve", resolveElement)
|
val controlFlowTrace = DelegatingBindingTrace(trace.getBindingContext(), "Element control flow resolve", resolveElement)
|
||||||
JetFlowInformationProvider(resolveElement, controlFlowTrace).checkDeclaration()
|
KotlinFlowInformationProvider(resolveElement, controlFlowTrace).checkDeclaration()
|
||||||
controlFlowTrace.addOwnDataTo(trace, null, false)
|
controlFlowTrace.addOwnDataTo(trace, null, false)
|
||||||
|
|
||||||
return Pair(trace.getBindingContext(), statementFilterUsed)
|
return Pair(trace.getBindingContext(), statementFilterUsed)
|
||||||
@@ -430,7 +430,7 @@ public class ResolveElementCache(
|
|||||||
forceResolveAnnotationsInside(property)
|
forceResolveAnnotationsInside(property)
|
||||||
|
|
||||||
for (accessor in property.getAccessors()) {
|
for (accessor in property.getAccessors()) {
|
||||||
JetFlowInformationProvider(accessor, trace).checkDeclaration()
|
KotlinFlowInformationProvider(accessor, trace).checkDeclaration()
|
||||||
}
|
}
|
||||||
|
|
||||||
return trace
|
return trace
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.cfg.pseudocode.*
|
|||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitorWithResult
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionVisitorWithResult
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionWithNext
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionWithNext
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.JetElementInstruction
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstruction
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction
|
||||||
@@ -592,7 +592,7 @@ private fun ExtractionData.checkDeclarationsMovingOutOfScope(
|
|||||||
private fun ExtractionData.getLocalInstructions(pseudocode: Pseudocode): List<Instruction> {
|
private fun ExtractionData.getLocalInstructions(pseudocode: Pseudocode): List<Instruction> {
|
||||||
val instructions = ArrayList<Instruction>()
|
val instructions = ArrayList<Instruction>()
|
||||||
pseudocode.traverse(TraversalOrder.FORWARD) {
|
pseudocode.traverse(TraversalOrder.FORWARD) {
|
||||||
if (it is JetElementInstruction && it.element.isInsideOf(physicalElements)) {
|
if (it is KtElementInstruction && it.element.isInsideOf(physicalElements)) {
|
||||||
instructions.add(it)
|
instructions.add(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user