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