get rid of JetPseudocodeTrace
and JetControlFlowDataTraceFactory
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.cfg;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -64,7 +65,7 @@ public interface JetControlFlowBuilder {
|
||||
// Subroutines
|
||||
void enterSubroutine(@NotNull JetDeclaration subroutine);
|
||||
|
||||
void exitSubroutine(@NotNull JetDeclaration subroutine);
|
||||
Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine);
|
||||
|
||||
@NotNull
|
||||
JetElement getCurrentSubroutine();
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.cfg;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -157,9 +158,9 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
assert builder != null;
|
||||
builder.exitSubroutine(subroutine);
|
||||
return builder.exitSubroutine(subroutine);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -21,6 +21,9 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowInstructionsGenerator;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
@@ -45,12 +48,22 @@ public class JetControlFlowProcessor {
|
||||
private final JetControlFlowBuilder builder;
|
||||
private final BindingTrace trace;
|
||||
|
||||
public JetControlFlowProcessor(BindingTrace trace, JetControlFlowBuilder builder) {
|
||||
this.builder = builder;
|
||||
public JetControlFlowProcessor(BindingTrace trace) {
|
||||
this.builder = new JetControlFlowInstructionsGenerator();
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
public void generate(@NotNull JetDeclaration subroutine) {
|
||||
//todo
|
||||
public Pseudocode generatePseudocode(@NotNull JetDeclaration subroutine) {
|
||||
Pseudocode pseudocode = generate(subroutine);
|
||||
((PseudocodeImpl)pseudocode).postProcess();
|
||||
for (Pseudocode localPseudocode : pseudocode.getLocalDeclarations()) {
|
||||
((PseudocodeImpl)localPseudocode).postProcess();
|
||||
}
|
||||
return pseudocode;
|
||||
}
|
||||
|
||||
public Pseudocode generate(@NotNull JetDeclaration subroutine) {
|
||||
builder.enterSubroutine(subroutine);
|
||||
if (subroutine instanceof JetDeclarationWithBody) {
|
||||
JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine;
|
||||
@@ -67,7 +80,7 @@ public class JetControlFlowProcessor {
|
||||
else {
|
||||
subroutine.accept(new CFPVisitor(false));
|
||||
}
|
||||
builder.exitSubroutine(subroutine);
|
||||
return builder.exitSubroutine(subroutine);
|
||||
}
|
||||
|
||||
private void processLocalDeclaration(@NotNull JetDeclaration subroutine) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.cfg;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
@@ -33,12 +32,14 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.CAPTURED_IN_CLOSURE;
|
||||
@@ -49,67 +50,22 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
*/
|
||||
public class JetFlowInformationProvider {
|
||||
|
||||
private final Map<JetElement, Pseudocode> pseudocodeMap;
|
||||
private final Map<JetElement, PseudocodeData> pseudocodeDataMap;
|
||||
private final JetDeclaration subroutine;
|
||||
private final Pseudocode pseudocode;
|
||||
private final PseudocodeData pseudocodeData;
|
||||
private BindingTrace trace;
|
||||
|
||||
public JetFlowInformationProvider(@NotNull JetDeclaration declaration, @NotNull final JetExpression bodyExpression, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory, @NotNull BindingTrace trace) {
|
||||
public JetFlowInformationProvider(
|
||||
@NotNull JetDeclaration declaration,
|
||||
@NotNull BindingTrace trace) {
|
||||
|
||||
subroutine = declaration;
|
||||
this.trace = trace;
|
||||
final JetPseudocodeTrace pseudocodeTrace = flowDataTraceFactory.createTrace(declaration);
|
||||
pseudocodeMap = new LinkedHashMap<JetElement, Pseudocode>();
|
||||
pseudocodeDataMap = new HashMap<JetElement, PseudocodeData>();
|
||||
final Map<JetElement, Instruction> representativeInstructions = new HashMap<JetElement, Instruction>();
|
||||
final Map<JetExpression, LoopInfo> loopInfo = Maps.newHashMap();
|
||||
JetPseudocodeTrace wrappedTrace = new JetPseudocodeTrace() {
|
||||
@Override
|
||||
public void recordControlFlowData(@NotNull JetElement element, @NotNull Pseudocode pseudocode) {
|
||||
pseudocodeTrace.recordControlFlowData(element, pseudocode);
|
||||
pseudocodeMap.put(element, pseudocode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRepresentativeInstruction(@NotNull JetElement element, @NotNull Instruction instruction) {
|
||||
Instruction oldValue = representativeInstructions.put(element, instruction);
|
||||
// assert oldValue == null : element.getText();
|
||||
pseudocodeTrace.recordRepresentativeInstruction(element, instruction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordLoopInfo(JetExpression expression, LoopInfo blockInfo) {
|
||||
loopInfo.put(expression, blockInfo);
|
||||
pseudocodeTrace.recordLoopInfo(expression, blockInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
pseudocodeTrace.close();
|
||||
List<Pseudocode> values = Lists.newArrayList(pseudocodeMap.values());
|
||||
Collections.reverse(values);
|
||||
for (Pseudocode pseudocode : values) {
|
||||
pseudocode.postProcess();
|
||||
}
|
||||
}
|
||||
};
|
||||
JetControlFlowInstructionsGenerator instructionsGenerator = new JetControlFlowInstructionsGenerator(wrappedTrace);
|
||||
new JetControlFlowProcessor(trace, instructionsGenerator).generate(declaration);
|
||||
wrappedTrace.close();
|
||||
pseudocode = new JetControlFlowProcessor(trace).generatePseudocode(declaration);
|
||||
pseudocodeData = new PseudocodeData(pseudocode, trace);
|
||||
}
|
||||
|
||||
private PseudocodeData getPseudocodeData(@NotNull JetElement element) {
|
||||
PseudocodeData pseudocodeData = pseudocodeDataMap.get(element);
|
||||
if (pseudocodeData == null) {
|
||||
Pseudocode pseudocode = pseudocodeMap.get(element);
|
||||
assert pseudocode != null;
|
||||
pseudocodeData = new PseudocodeData(pseudocode, trace);
|
||||
pseudocodeDataMap.put(element, pseudocodeData);
|
||||
}
|
||||
return pseudocodeData;
|
||||
}
|
||||
|
||||
private void collectReturnExpressions(@NotNull JetElement subroutine, @NotNull final Collection<JetElement> returnedExpressions) {
|
||||
Pseudocode pseudocode = pseudocodeMap.get(subroutine);
|
||||
assert pseudocode != null;
|
||||
|
||||
private void collectReturnExpressions(@NotNull final Collection<JetElement> returnedExpressions) {
|
||||
final Set<Instruction> instructions = Sets.newHashSet(pseudocode.getInstructions());
|
||||
SubroutineExitInstruction exitInstruction = pseudocode.getExitInstruction();
|
||||
for (Instruction previousInstruction : exitInstruction.getPreviousInstructions()) {
|
||||
@@ -164,14 +120,16 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkDefiniteReturn(@NotNull final JetDeclarationWithBody function, final @NotNull JetType expectedReturnType) {
|
||||
public void checkDefiniteReturn(final @NotNull JetType expectedReturnType) {
|
||||
assert subroutine instanceof JetDeclarationWithBody;
|
||||
JetDeclarationWithBody function = (JetDeclarationWithBody) subroutine;
|
||||
assert function instanceof JetDeclaration;
|
||||
|
||||
JetExpression bodyExpression = function.getBodyExpression();
|
||||
if (bodyExpression == null) return;
|
||||
|
||||
List<JetElement> returnedExpressions = Lists.newArrayList();
|
||||
collectReturnExpressions(function.asElement(), returnedExpressions);
|
||||
collectReturnExpressions(returnedExpressions);
|
||||
|
||||
boolean nothingReturned = returnedExpressions.isEmpty();
|
||||
|
||||
@@ -211,9 +169,6 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
|
||||
private Set<JetElement> collectUnreachableCode(@NotNull JetElement subroutine) {
|
||||
Pseudocode pseudocode = pseudocodeMap.get(subroutine);
|
||||
assert pseudocode != null;
|
||||
|
||||
Collection<JetElement> unreachableElements = Lists.newArrayList();
|
||||
for (Instruction deadInstruction : pseudocode.getDeadInstructions()) {
|
||||
if (deadInstruction instanceof JetElementInstruction &&
|
||||
@@ -228,12 +183,11 @@ public class JetFlowInformationProvider {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Uninitialized variables analysis
|
||||
|
||||
public void markUninitializedVariables(@NotNull JetElement subroutine, final boolean processLocalDeclaration) {
|
||||
public void markUninitializedVariables(final boolean processLocalDeclaration) {
|
||||
final Collection<VariableDescriptor> varWithUninitializedErrorGenerated = Sets.newHashSet();
|
||||
final Collection<VariableDescriptor> varWithValReassignErrorGenerated = Sets.newHashSet();
|
||||
final boolean processClassOrObject = subroutine instanceof JetClassOrObject;
|
||||
|
||||
final PseudocodeData pseudocodeData = getPseudocodeData(subroutine);
|
||||
pseudocodeData.traverseInstructionsGraph(true, true, new PseudocodeData.TraverseInstructionGraphStrategy() {
|
||||
@Override
|
||||
public void execute(@NotNull Instruction instruction, @NotNull DeclarationData declarationData, @NotNull InstructionData instructionData) {
|
||||
@@ -447,20 +401,10 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void analyzeLocalDeclarations(Pseudocode pseudocode, boolean processLocalDeclaration) {
|
||||
for (Instruction instruction : pseudocode.getInstructions()) {
|
||||
if (instruction instanceof LocalDeclarationInstruction) {
|
||||
JetElement element = ((LocalDeclarationInstruction) instruction).getElement();
|
||||
markUninitializedVariables(element, processLocalDeclaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// "Unused variable" & "unused value" analyses
|
||||
|
||||
public void markUnusedVariables(@NotNull JetElement subroutine) {
|
||||
final PseudocodeData pseudocodeData = getPseudocodeData(subroutine);
|
||||
public void markUnusedVariables() {
|
||||
pseudocodeData.traverseInstructionsGraph(true, false, new PseudocodeData.TraverseInstructionGraphStrategy() {
|
||||
@Override
|
||||
public void execute(@NotNull Instruction instruction, @NotNull DeclarationData declarationData, @NotNull InstructionData instructionData) {
|
||||
@@ -541,8 +485,7 @@ public class JetFlowInformationProvider {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// "Unused literals" in block
|
||||
|
||||
public void markUnusedLiteralsInBlock(@NotNull JetElement subroutine) {
|
||||
Pseudocode pseudocode = pseudocodeMap.get(subroutine);
|
||||
public void markUnusedLiteralsInBlock() {
|
||||
assert pseudocode != null;
|
||||
JetControlFlowGraphTraverser<Void> traverser = JetControlFlowGraphTraverser.create(pseudocode, true, true);
|
||||
traverser.traverseAndAnalyzeInstructionGraph(new JetControlFlowGraphTraverser.InstructionDataAnalyzeStrategy<Void>() {
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.cfg.pseudocode;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface JetControlFlowDataTraceFactory {
|
||||
JetControlFlowDataTraceFactory EMPTY = new JetControlFlowDataTraceFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public JetPseudocodeTrace createTrace(JetElement element) {
|
||||
return JetPseudocodeTrace.EMPTY;
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
JetPseudocodeTrace createTrace(JetElement element);
|
||||
}
|
||||
+8
-17
@@ -35,12 +35,6 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
private final Stack<BlockInfo> allBlocks = new Stack<BlockInfo>();
|
||||
|
||||
private final JetPseudocodeTrace trace;
|
||||
|
||||
public JetControlFlowInstructionsGenerator(JetPseudocodeTrace trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
private void pushBuilder(JetElement scopingElement, JetElement subroutine) {
|
||||
JetControlFlowInstructionsGeneratorWorker worker = new JetControlFlowInstructionsGeneratorWorker(scopingElement, subroutine);
|
||||
builders.push(worker);
|
||||
@@ -49,7 +43,6 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
private JetControlFlowInstructionsGeneratorWorker popBuilder(@NotNull JetElement element) {
|
||||
JetControlFlowInstructionsGeneratorWorker worker = builders.pop();
|
||||
trace.recordControlFlowData(element, worker.getPseudocode());
|
||||
if (!builders.isEmpty()) {
|
||||
builder = builders.peek();
|
||||
}
|
||||
@@ -72,7 +65,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
super.exitSubroutine(subroutine);
|
||||
JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
||||
if (!builders.empty()) {
|
||||
@@ -80,32 +73,29 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
LocalDeclarationInstruction instruction = new LocalDeclarationInstruction(subroutine, worker.getPseudocode());
|
||||
builder.add(instruction);
|
||||
}
|
||||
return worker.getPseudocode();
|
||||
}
|
||||
|
||||
private class JetControlFlowInstructionsGeneratorWorker implements JetControlFlowBuilder {
|
||||
|
||||
private final Pseudocode pseudocode;
|
||||
private final PseudocodeImpl pseudocode;
|
||||
private final Label error;
|
||||
private final Label sink;
|
||||
private final JetElement returnSubroutine;
|
||||
|
||||
private JetControlFlowInstructionsGeneratorWorker(@NotNull JetElement scopingElement, @NotNull JetElement returnSubroutine) {
|
||||
this.pseudocode = new Pseudocode(scopingElement);
|
||||
this.pseudocode = new PseudocodeImpl(scopingElement);
|
||||
this.error = pseudocode.createLabel("error");
|
||||
this.sink = pseudocode.createLabel("sink");
|
||||
this.returnSubroutine = returnSubroutine;
|
||||
}
|
||||
|
||||
public Pseudocode getPseudocode() {
|
||||
public PseudocodeImpl getPseudocode() {
|
||||
return pseudocode;
|
||||
}
|
||||
|
||||
private void add(@NotNull Instruction instruction) {
|
||||
pseudocode.addInstruction(instruction);
|
||||
if (instruction instanceof JetElementInstruction) {
|
||||
JetElementInstruction elementInstruction = (JetElementInstruction) instruction;
|
||||
trace.recordRepresentativeInstruction(elementInstruction.getElement(), instruction);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -127,7 +117,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
loopInfo.push(blockInfo);
|
||||
elementToBlockInfo.put(expression, blockInfo);
|
||||
allBlocks.push(blockInfo);
|
||||
trace.recordLoopInfo(expression, blockInfo);
|
||||
pseudocode.recordLoopInfo(expression, blockInfo);
|
||||
return blockInfo;
|
||||
}
|
||||
|
||||
@@ -202,7 +192,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
bindLabel(getExitPoint(subroutine));
|
||||
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "<END>"));
|
||||
bindLabel(error);
|
||||
@@ -211,6 +201,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>"));
|
||||
elementToBlockInfo.remove(subroutine);
|
||||
allBlocks.pop();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.cfg.pseudocode;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.cfg.LoopInfo;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface JetPseudocodeTrace {
|
||||
|
||||
JetPseudocodeTrace EMPTY = new JetPseudocodeTrace() {
|
||||
@Override
|
||||
public void recordControlFlowData(@NotNull JetElement element, @NotNull Pseudocode pseudocode) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRepresentativeInstruction(@NotNull JetElement element, @NotNull Instruction instruction) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordLoopInfo(JetExpression expression, LoopInfo blockInfo) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void recordControlFlowData(@NotNull JetElement element, @NotNull Pseudocode pseudocode);
|
||||
void recordRepresentativeInstruction(@NotNull JetElement element, @NotNull Instruction instruction);
|
||||
void close();
|
||||
|
||||
void recordLoopInfo(JetExpression expression, LoopInfo blockInfo);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import java.util.*;
|
||||
* @author abreslav
|
||||
* @author svtk
|
||||
*/
|
||||
public class PseudocodeImpl implements IPseudocode {
|
||||
public class PseudocodeImpl implements Pseudocode {
|
||||
|
||||
public class PseudocodeLabel implements Label {
|
||||
private final String name;
|
||||
@@ -103,8 +103,8 @@ public class PseudocodeImpl implements IPseudocode {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<IPseudocode> getLocalDeclarations() {
|
||||
Set<IPseudocode> localDeclarations = Sets.newLinkedHashSet();
|
||||
public Set<Pseudocode> getLocalDeclarations() {
|
||||
Set<Pseudocode> localDeclarations = Sets.newLinkedHashSet();
|
||||
//todo look recursively inside local declarations
|
||||
for (Instruction instruction : instructions) {
|
||||
if (instruction instanceof LocalDeclarationInstruction) {
|
||||
|
||||
@@ -16,22 +16,15 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
@@ -37,7 +36,6 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
public class ControlFlowAnalyzer {
|
||||
private TopDownAnalysisParameters topDownAnalysisParameters;
|
||||
private BindingTrace trace;
|
||||
private JetControlFlowDataTraceFactory flowDataTraceFactory;
|
||||
|
||||
@Inject
|
||||
public void setTopDownAnalysisParameters(TopDownAnalysisParameters topDownAnalysisParameters) {
|
||||
@@ -49,11 +47,6 @@ public class ControlFlowAnalyzer {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setFlowDataTraceFactory(JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
this.flowDataTraceFactory = flowDataTraceFactory;
|
||||
}
|
||||
|
||||
public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
|
||||
for (JetClass aClass : bodiesResolveContext.getClasses().keySet()) {
|
||||
if (!bodiesResolveContext.completeAnalysisNeeded(aClass)) continue;
|
||||
@@ -86,8 +79,8 @@ public class ControlFlowAnalyzer {
|
||||
|
||||
private void checkClassOrObject(JetClassOrObject klass) {
|
||||
// A pseudocode of class initialization corresponds to a class
|
||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetDeclaration) klass, (JetExpression) klass, flowDataTraceFactory, trace);
|
||||
flowInformationProvider.markUninitializedVariables((JetElement) klass, topDownAnalysisParameters.isDeclaredLocally());
|
||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetDeclaration) klass, trace);
|
||||
flowInformationProvider.markUninitializedVariables(topDownAnalysisParameters.isDeclaredLocally());
|
||||
}
|
||||
|
||||
private void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor) {
|
||||
@@ -105,16 +98,16 @@ public class ControlFlowAnalyzer {
|
||||
|
||||
JetExpression bodyExpression = function.getBodyExpression();
|
||||
if (bodyExpression == null) return;
|
||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetDeclaration) function, bodyExpression, flowDataTraceFactory, trace);
|
||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetDeclaration) function, trace);
|
||||
|
||||
flowInformationProvider.checkDefiniteReturn(function, expectedReturnType);
|
||||
flowInformationProvider.checkDefiniteReturn(expectedReturnType);
|
||||
|
||||
// Property accessor is checked through initialization of a class check (at 'checkClassOrObject')
|
||||
boolean isPropertyAccessor = function instanceof JetPropertyAccessor;
|
||||
flowInformationProvider.markUninitializedVariables(function.asElement(), topDownAnalysisParameters.isDeclaredLocally() || isPropertyAccessor);
|
||||
flowInformationProvider.markUninitializedVariables(topDownAnalysisParameters.isDeclaredLocally() || isPropertyAccessor);
|
||||
|
||||
flowInformationProvider.markUnusedVariables(function.asElement());
|
||||
flowInformationProvider.markUnusedVariables();
|
||||
|
||||
flowInformationProvider.markUnusedLiteralsInBlock(function.asElement());
|
||||
flowInformationProvider.markUnusedLiteralsInBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerBasic;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -188,7 +187,7 @@ public class TopDownAnalyzer {
|
||||
TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters(Predicates.<PsiFile>alwaysFalse(), true, false);
|
||||
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
||||
project, topDownAnalysisParameters, new ObservableBindingTrace(trace),
|
||||
JetStandardClasses.FAKE_STANDARD_CLASSES_MODULE, null, ModuleConfiguration.EMPTY);
|
||||
JetStandardClasses.FAKE_STANDARD_CLASSES_MODULE, ModuleConfiguration.EMPTY);
|
||||
|
||||
injector.getTopDownAnalyzer().doProcessStandardLibraryNamespace(outerScope, standardLibraryNamespace, files);
|
||||
}
|
||||
@@ -220,7 +219,7 @@ public class TopDownAnalyzer {
|
||||
|
||||
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
||||
project, topDownAnalysisParameters, new ObservableBindingTrace(trace), moduleDescriptor,
|
||||
JetControlFlowDataTraceFactory.EMPTY, ModuleConfiguration.EMPTY);
|
||||
ModuleConfiguration.EMPTY);
|
||||
|
||||
injector.getTopDownAnalyzer().doProcess(outerScope, new NamespaceLikeBuilder() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user