made pseudocode be built on JetElement
instead of JetDeclaration to be able to be built on JetFile
This commit is contained in:
@@ -63,9 +63,9 @@ public interface JetControlFlowBuilder {
|
||||
void exitTryFinally();
|
||||
|
||||
// Subroutines
|
||||
void enterSubroutine(@NotNull JetDeclaration subroutine);
|
||||
void enterSubroutine(@NotNull JetElement subroutine);
|
||||
|
||||
Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine);
|
||||
Pseudocode exitSubroutine(@NotNull JetElement subroutine);
|
||||
|
||||
@NotNull
|
||||
JetElement getCurrentSubroutine();
|
||||
|
||||
@@ -147,13 +147,13 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public void enterSubroutine(@NotNull JetElement subroutine) {
|
||||
assert builder != null;
|
||||
builder.enterSubroutine(subroutine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
||||
assert builder != null;
|
||||
return builder.exitSubroutine(subroutine);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowInstructionsGenerator
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.LocalDeclarationInstruction;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl;
|
||||
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
@@ -58,16 +59,16 @@ public class JetControlFlowProcessor {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
public Pseudocode generatePseudocode(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode generatePseudocode(@NotNull JetElement subroutine) {
|
||||
Pseudocode pseudocode = generate(subroutine);
|
||||
((PseudocodeImpl)pseudocode).postProcess();
|
||||
((PseudocodeImpl) pseudocode).postProcess();
|
||||
for (LocalDeclarationInstruction localDeclarationInstruction : pseudocode.getLocalDeclarations()) {
|
||||
((PseudocodeImpl)localDeclarationInstruction.getBody()).postProcess();
|
||||
}
|
||||
return pseudocode;
|
||||
}
|
||||
|
||||
private Pseudocode generate(@NotNull JetDeclaration subroutine) {
|
||||
private Pseudocode generate(@NotNull JetElement subroutine) {
|
||||
builder.enterSubroutine(subroutine);
|
||||
CFPVisitor cfpVisitor = new CFPVisitor(false);
|
||||
if (subroutine instanceof JetDeclarationWithBody) {
|
||||
@@ -80,12 +81,6 @@ public class JetControlFlowProcessor {
|
||||
if (bodyExpression != null) {
|
||||
bodyExpression.accept(cfpVisitor);
|
||||
}
|
||||
}
|
||||
else if (subroutine instanceof JetProperty) {
|
||||
JetExpression initializer = ((JetProperty) subroutine).getInitializer();
|
||||
if (initializer != null) {
|
||||
initializer.accept(cfpVisitor);
|
||||
}
|
||||
} else {
|
||||
subroutine.accept(cfpVisitor);
|
||||
}
|
||||
@@ -911,13 +906,8 @@ public class JetControlFlowProcessor {
|
||||
generateInstructions(specifier, inCondition);
|
||||
}
|
||||
List<JetDeclaration> declarations = classOrObject.getDeclarations();
|
||||
List<JetProperty> properties = Lists.newArrayList();
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
if (declaration instanceof JetProperty) {
|
||||
generateInstructions(declaration, inCondition);
|
||||
properties.add((JetProperty) declaration);
|
||||
}
|
||||
else if (declaration instanceof JetClassInitializer) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetClassInitializer) {
|
||||
generateInstructions(declaration, inCondition);
|
||||
}
|
||||
}
|
||||
@@ -945,6 +935,15 @@ public class JetControlFlowProcessor {
|
||||
generateInstructions(specifier.getDelegateExpression(), inCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetFile(JetFile file) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty) {
|
||||
generateInstructions(declaration, inCondition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(JetElement element) {
|
||||
builder.unsupported(element);
|
||||
|
||||
@@ -56,13 +56,13 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
*/
|
||||
public class JetFlowInformationProvider {
|
||||
|
||||
private final JetDeclaration subroutine;
|
||||
private final JetElement subroutine;
|
||||
private final Pseudocode pseudocode;
|
||||
private final PseudocodeVariablesData pseudocodeVariablesData;
|
||||
private BindingTrace trace;
|
||||
|
||||
public JetFlowInformationProvider(
|
||||
@NotNull JetDeclaration declaration,
|
||||
@NotNull JetElement declaration,
|
||||
@NotNull BindingTrace trace) {
|
||||
|
||||
subroutine = declaration;
|
||||
|
||||
+4
-4
@@ -55,7 +55,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public void enterSubroutine(@NotNull JetElement subroutine) {
|
||||
if (builder != null && subroutine instanceof JetFunctionLiteral) {
|
||||
pushBuilder(subroutine, builder.getReturnSubroutine());
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
||||
super.exitSubroutine(subroutine);
|
||||
JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
||||
if (!builders.empty()) {
|
||||
@@ -143,7 +143,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public void enterSubroutine(@NotNull JetElement subroutine) {
|
||||
Label entryPoint = createUnboundLabel();
|
||||
BreakableBlockInfo blockInfo = new BreakableBlockInfo(subroutine, entryPoint, createUnboundLabel());
|
||||
// subroutineInfo.push(blockInfo);
|
||||
@@ -201,7 +201,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) {
|
||||
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
||||
bindLabel(getExitPoint(subroutine));
|
||||
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "<END>"));
|
||||
bindLabel(error);
|
||||
|
||||
+1
-7
@@ -32,7 +32,7 @@ public class LocalDeclarationInstruction extends InstructionWithNext {
|
||||
private final Pseudocode body;
|
||||
private Instruction sink;
|
||||
|
||||
public LocalDeclarationInstruction(@NotNull JetDeclaration element, Pseudocode body) {
|
||||
public LocalDeclarationInstruction(@NotNull JetElement element, Pseudocode body) {
|
||||
super(element);
|
||||
this.body = body;
|
||||
}
|
||||
@@ -41,12 +41,6 @@ public class LocalDeclarationInstruction extends InstructionWithNext {
|
||||
return body;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetDeclaration getElement() {
|
||||
return (JetDeclaration) super.getElement();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Instruction> getNextInstructions() {
|
||||
|
||||
Reference in New Issue
Block a user