diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java index 9549a4ab0f0..4658d844a4f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java @@ -25,6 +25,7 @@ public interface JetControlFlowBuilder { void jumpOnTrue(@NotNull Label label); void nondeterministicJump(Label label); // Maybe, jump to label void jumpToError(JetThrowExpression expression); + void jumpToError(JetExpression nothingExpression); // Entry/exit points Label getEntryPoint(@NotNull JetElement labelElement); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java index 6137517b40c..7d4dd4744dc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java @@ -62,6 +62,11 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder { builder.jumpToError(expression); } + @Override + public void jumpToError(JetExpression nothingExpression) { + builder.jumpToError(nothingExpression); + } + @Override public Label getEntryPoint(@NotNull JetElement labelElement) { return builder.getEntryPoint(labelElement); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 7c49cf6c627..aa185dcee86 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -6,6 +6,8 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; +import org.jetbrains.jet.lang.types.JetStandardClasses; +import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetTypeInferrer; import org.jetbrains.jet.lexer.JetTokens; @@ -137,6 +139,12 @@ public class JetControlFlowProcessor { @Override public void visitSimpleNameExpression(JetSimpleNameExpression expression) { builder.read(expression); + if (trace.get(BindingContext.PROCESSED, expression)) { + JetType type = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression); + if (type != null && JetStandardClasses.isNothing(type)) { + builder.jumpToError(expression); + } + } } @Override @@ -522,6 +530,12 @@ public class JetControlFlowProcessor { value(selectorExpression, false); } builder.read(expression); + if (trace.get(BindingContext.PROCESSED, expression)) { + JetType type = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression); + if (type != null && JetStandardClasses.isNothing(type)) { + builder.jumpToError(expression); + } + } } private void visitCall(JetCallElement call) { @@ -547,6 +561,12 @@ public class JetControlFlowProcessor { value(expression.getCalleeExpression(), false); builder.read(expression); + if (trace.get(BindingContext.PROCESSED, expression)) { + JetType type = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression); + if (type != null && JetStandardClasses.isNothing(type)) { + builder.jumpToError(expression); + } + } } // @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 8e27cbd262b..7430be1bed2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -11,61 +11,61 @@ import java.util.Collection; * @author abreslav */ public interface JetFlowInformationProvider { - JetFlowInformationProvider THROW_EXCEPTION = new JetFlowInformationProvider() { - @Override - public void collectReturnedInformation(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions, @NotNull Collection elementsReturningUnit) { - throw new UnsupportedOperationException(); - } - - @Override - public void collectReturnExpressions(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions) { - throw new UnsupportedOperationException(); - } - - @Override - public void collectUnreachableExpressions(@NotNull JetElement subroutine, @NotNull Collection unreachableElements) { - throw new UnsupportedOperationException(); - } - - @Override - public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection dominated) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isBreakable(JetLoopExpression loop) { - throw new UnsupportedOperationException(); - } - - }; - - JetFlowInformationProvider NONE = new JetFlowInformationProvider() { - @Override - public void collectReturnedInformation(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions, @NotNull Collection elementsReturningUnit) { - - } - - @Override - public void collectReturnExpressions(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions) { - - } - - @Override - public void collectUnreachableExpressions(@NotNull JetElement subroutine, @NotNull Collection unreachableElements) { - - } - - @Override - public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection dominated) { - - } - - @Override - public boolean isBreakable(JetLoopExpression loop) { - return false; - } - - }; +// JetFlowInformationProvider THROW_EXCEPTION = new JetFlowInformationProvider() { +// @Override +// public void collectReturnedInformation(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions, @NotNull Collection elementsReturningUnit) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public void collectReturnExpressions(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public void collectUnreachableExpressions(@NotNull JetElement subroutine, @NotNull Collection unreachableElements) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection dominated) { +// throw new UnsupportedOperationException(); +// } +// +// @Override +// public boolean isBreakable(JetLoopExpression loop) { +// throw new UnsupportedOperationException(); +// } +// +// }; +// +// JetFlowInformationProvider NONE = new JetFlowInformationProvider() { +// @Override +// public void collectReturnedInformation(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions, @NotNull Collection elementsReturningUnit) { +// +// } +// +// @Override +// public void collectReturnExpressions(@NotNull JetElement subroutine, @NotNull Collection returnedExpressions) { +// +// } +// +// @Override +// public void collectUnreachableExpressions(@NotNull JetElement subroutine, @NotNull Collection unreachableElements) { +// +// } +// +// @Override +// public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection dominated) { +// +// } +// +// @Override +// public boolean isBreakable(JetLoopExpression loop) { +// return false; +// } +// +// }; /** * Collects expressions returned from the given subroutine and 'return;' expressions diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java index ef7ee3e76f2..0014eaa70be 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java @@ -250,6 +250,11 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd public void jumpToError(JetThrowExpression expression) { add(new UnconditionalJumpInstruction(error)); } + + @Override + public void jumpToError(JetExpression nothingExpression) { + add(new UnconditionalJumpInstruction(error)); + } @Override public void enterTryFinally(@NotNull GenerationTrigger generationTrigger) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 2f98129c988..f92959e2ef7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -144,7 +144,6 @@ public interface Errors { PsiElementOnlyDiagnosticFactory3 VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT); SimpleDiagnosticFactory UNREACHABLE_CODE = SimpleDiagnosticFactory.create(ERROR, "Unreachable code"); - ParameterizedDiagnosticFactory1 UNREACHABLE_BECAUSE_OF_NOTHING = ParameterizedDiagnosticFactory1.create(ERROR, "This code is unreachable, because ''{0}'' never terminates normally"); SimpleDiagnosticFactory MANY_CLASS_OBJECTS = SimpleDiagnosticFactory.create(ERROR, "Only one class object is allowed per class"); SimpleDiagnosticFactory CLASS_OBJECT_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "A class object is not allowed here"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTreeVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTreeVisitor.java new file mode 100644 index 00000000000..8b88df1f4ff --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTreeVisitor.java @@ -0,0 +1,796 @@ +package org.jetbrains.jet.lang.psi; + +import java.util.List; + +/** + * @author svtk + */ +public class JetTreeVisitor extends JetVisitor { + @Override + public Void visitNamespace(JetNamespace namespace, D data) { + List importDirectives = namespace.getImportDirectives(); + for (JetImportDirective directive : importDirectives) { + directive.visit(this, data); + } + List declarations = namespace.getDeclarations(); + for (JetDeclaration declaration : declarations) { + declaration.visit(this, data); + } + return null; + } + + @Override + public Void visitClass(JetClass klass, D data) { + List declarations = klass.getDeclarations(); + for (JetDeclaration declaration : declarations) { + declaration.visit(this, data); + } + return null; + } + + @Override + public Void visitClassObject(JetClassObject classObject, D data) { + JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration(); + if (objectDeclaration != null) { + objectDeclaration.visit(this, data); + } + return null; + } + + @Override + public Void visitConstructor(JetConstructor constructor, D data) { + visitDeclarationWithBody(constructor, data); + return null; + } + + @Override + public Void visitNamedFunction(JetNamedFunction function, D data) { + visitDeclarationWithBody(function, data); + return null; + } + + @Override + public Void visitProperty(JetProperty property, D data) { + List accessors = property.getAccessors(); + for (JetPropertyAccessor accessor : accessors) { + accessor.visit(this, data); + } + JetExpression initializer = property.getInitializer(); + if (initializer != null) { + initializer.visit(this, data); + } + return null; + } + + @Override + public Void visitTypedef(JetTypedef typedef, D data) { + return super.visitTypedef(typedef, data); + } + + @Override + public Void visitJetFile(JetFile file, D data) { + JetNamespace rootNamespace = file.getRootNamespace(); + return rootNamespace.visit(this, data); + } + + @Override + public Void visitImportDirective(JetImportDirective importDirective, D data) { + return super.visitImportDirective(importDirective, data); + } + + @Override + public Void visitClassBody(JetClassBody classBody, D data) { + List declarations = classBody.getDeclarations(); + for (JetDeclaration declaration : declarations) { + declaration.visit(this, data); + } + List secondaryConstructors = classBody.getSecondaryConstructors(); + for (JetConstructor constructor : secondaryConstructors) { + constructor.visit(this, data); + } + return null; + } + + @Override + public Void visitNamespaceBody(JetNamespaceBody body, D data) { + List declarations = body.getDeclarations(); + for (JetDeclaration declaration : declarations) { + declaration.visit(this, data); + } + return null; + } + + @Override + public Void visitModifierList(JetModifierList list, D data) { + return super.visitModifierList(list, data); + } + + @Override + public Void visitAnnotation(JetAnnotation annotation, D data) { + return super.visitAnnotation(annotation, data); + } + + @Override + public Void visitAnnotationEntry(JetAnnotationEntry annotationEntry, D data) { + return super.visitAnnotationEntry(annotationEntry, data); + } + + @Override + public Void visitTypeParameterList(JetTypeParameterList list, D data) { + List parameters = list.getParameters(); + for (JetTypeParameter parameter : parameters) { + parameter.visit(this, data); + } + return null; + } + + @Override + public Void visitTypeParameter(JetTypeParameter parameter, D data) { + return super.visitTypeParameter(parameter, data); + } + + @Override + public Void visitEnumEntry(JetEnumEntry enumEntry, D data) { + List delegationSpecifiers = enumEntry.getDelegationSpecifiers(); + for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) { + delegationSpecifier.visit(this, data); + } + JetModifierList modifierList = enumEntry.getModifierList(); + if (modifierList != null) { + modifierList.visit(this, data); + } + return null; + } + + @Override + public Void visitParameterList(JetParameterList list, D data) { + List parameters = list.getParameters(); + for (JetParameter parameter : parameters) { + parameter.visit(this, data); + } + return null; + } + + @Override + public Void visitParameter(JetParameter parameter, D data) { + return super.visitParameter(parameter, data); + } + + @Override + public Void visitDelegationSpecifierList(JetDelegationSpecifierList list, D data) { + List delegationSpecifiers = list.getDelegationSpecifiers(); + for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) { + delegationSpecifier.visit(this, data); + } + return null; + } + + @Override + public Void visitDelegationSpecifier(JetDelegationSpecifier specifier, D data) { + return super.visitDelegationSpecifier(specifier, data); + } + + @Override + public Void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier, D data) { + return super.visitDelegationByExpressionSpecifier(specifier, data); + } + + @Override + public Void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call, D data) { + return super.visitDelegationToSuperCallSpecifier(call, data); + } + + @Override + public Void visitDelegationToSuperClassSpecifier(JetDelegatorToSuperClass specifier, D data) { + return super.visitDelegationToSuperClassSpecifier(specifier, data); + } + + @Override + public Void visitDelegationToThisCall(JetDelegatorToThisCall thisCall, D data) { + return super.visitDelegationToThisCall(thisCall, data); + } + + @Override + public Void visitTypeReference(JetTypeReference typeReference, D data) { + return super.visitTypeReference(typeReference, data); + } + + @Override + public Void visitValueArgumentList(JetValueArgumentList list, D data) { + List arguments = list.getArguments(); + for (JetValueArgument argument : arguments) { + argument.visit(this, data); + } + return null; + } + + @Override + public Void visitArgument(JetValueArgument argument, D data) { + return super.visitArgument(argument, data); + } + + @Override + public Void visitLoopExpression(JetLoopExpression loopExpression, D data) { + JetExpression body = loopExpression.getBody(); + if (body != null) { + body.visit(this, data); + } + return null; + } + + @Override + public Void visitConstantExpression(JetConstantExpression expression, D data) { + return super.visitConstantExpression(expression, data); + } + + @Override + public Void visitSimpleNameExpression(JetSimpleNameExpression expression, D data) { + return super.visitSimpleNameExpression(expression, data); + } + + @Override + public Void visitReferenceExpression(JetReferenceExpression expression, D data) { + return super.visitReferenceExpression(expression, data); + } + + @Override + public Void visitTupleExpression(JetTupleExpression expression, D data) { + return super.visitTupleExpression(expression, data); + } + + @Override + public Void visitPrefixExpression(JetPrefixExpression expression, D data) { + JetExpression baseExpression = expression.getBaseExpression(); + if (baseExpression != null) { + baseExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitPostfixExpression(JetPostfixExpression expression, D data) { + JetExpression baseExpression = expression.getBaseExpression(); + baseExpression.visit(this, data); + return null; + } + + @Override + public Void visitUnaryExpression(JetUnaryExpression expression, D data) { + JetExpression baseExpression = expression.getBaseExpression(); + assert baseExpression != null; + baseExpression.visit(this, data); + return null; + } + + @Override + public Void visitBinaryExpression(JetBinaryExpression expression, D data) { + JetExpression left = expression.getLeft(); + left.visit(this, data); + JetExpression right = expression.getRight(); + if (right != null) { + right.visit(this, data); + } + return super.visitBinaryExpression(expression, data); + } + + @Override + public Void visitReturnExpression(JetReturnExpression expression, D data) { + JetExpression returnedExpression = expression.getReturnedExpression(); + if (returnedExpression != null) { + returnedExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression, D data) { + JetExpression labeledExpression = expression.getLabeledExpression(); + if (labeledExpression != null) { + labeledExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitThrowExpression(JetThrowExpression expression, D data) { + JetExpression thrownExpression = expression.getThrownExpression(); + if (thrownExpression != null) { + thrownExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitBreakExpression(JetBreakExpression expression, D data) { + return super.visitBreakExpression(expression, data); + } + + @Override + public Void visitContinueExpression(JetContinueExpression expression, D data) { + return super.visitContinueExpression(expression, data); + } + + @Override + public Void visitIfExpression(JetIfExpression expression, D data) { + JetExpression condition = expression.getCondition(); + if (condition != null) { + condition.visit(this, data); + } + JetExpression then = expression.getThen(); + if (then != null) { + then.visit(this, data); + } + JetExpression anElse = expression.getElse(); + if (anElse != null) { + anElse.visit(this, data); + } + return null; + } + + @Override + public Void visitWhenExpression(JetWhenExpression expression, D data) { + List entries = expression.getEntries(); + for (JetWhenEntry entry : entries) { + entry.visit(this, data); + } + JetExpression subjectExpression = expression.getSubjectExpression(); + if (subjectExpression != null) { + subjectExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitTryExpression(JetTryExpression expression, D data) { + JetBlockExpression tryBlock = expression.getTryBlock(); + tryBlock.visit(this, data); + List catchClauses = expression.getCatchClauses(); + for (JetCatchClause catchClause : catchClauses) { + catchClause.visit(this, data); + } + JetFinallySection finallyBlock = expression.getFinallyBlock(); + if (finallyBlock != null) { + finallyBlock.visit(this, data); + } + return null; + } + + @Override + public Void visitForExpression(JetForExpression expression, D data) { + JetParameter loopParameter = expression.getLoopParameter(); + if (loopParameter != null) { + loopParameter.visit(this, data); + } + JetExpression loopRange = expression.getLoopRange(); + if (loopRange != null) { + loopRange.visit(this, data); + } + visitLoopExpression(expression, data); + return null; + } + + @Override + public Void visitWhileExpression(JetWhileExpression expression, D data) { + JetExpression condition = expression.getCondition(); + if (condition != null) { + condition.visit(this, data); + } + visitLoopExpression(expression, data); + return null; + } + + @Override + public Void visitDoWhileExpression(JetDoWhileExpression expression, D data) { + JetExpression condition = expression.getCondition(); + if (condition != null) { + condition.visit(this, data); + } + visitLoopExpression(expression, data); + return null; + } + + @Override + public Void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression, D data) { + JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); + functionLiteral.visit(this, data); + visitDeclarationWithBody(expression, data); + return null; + } + + @Override + public Void visitAnnotatedExpression(JetAnnotatedExpression expression, D data) { + JetExpression baseExpression = expression.getBaseExpression(); + baseExpression.visit(this, data); + return null; + } + + @Override + public Void visitCallExpression(JetCallExpression expression, D data) { + JetExpression calleeExpression = expression.getCalleeExpression(); + if (calleeExpression != null) { + calleeExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitArrayAccessExpression(JetArrayAccessExpression expression, D data) { + JetExpression arrayExpression = expression.getArrayExpression(); + arrayExpression.visit(this, data); + List indexExpressions = expression.getIndexExpressions(); + for (JetExpression indexExpression : indexExpressions) { + indexExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitQualifiedExpression(JetQualifiedExpression expression, D data) { + JetExpression receiver = expression.getReceiverExpression(); + receiver.visit(this, data); + JetExpression selector = expression.getSelectorExpression(); + if (selector != null) { + selector.visit(this, data); + } + return null; + } + + @Override + public Void visitHashQualifiedExpression(JetHashQualifiedExpression expression, D data) { + visitQualifiedExpression(expression, data); + return null; + } + + @Override + public Void visitDotQualifiedExpression(JetDotQualifiedExpression expression, D data) { + visitQualifiedExpression(expression, data); + return null; + } + + @Override + public Void visitPredicateExpression(JetPredicateExpression expression, D data) { + visitQualifiedExpression(expression, data); + return null; + } + + @Override + public Void visitSafeQualifiedExpression(JetSafeQualifiedExpression expression, D data) { + visitQualifiedExpression(expression, data); + return null; + } + + @Override + public Void visitObjectLiteralExpression(JetObjectLiteralExpression expression, D data) { + JetObjectDeclaration objectDeclaration = expression.getObjectDeclaration(); + objectDeclaration.visit(this, data); + return null; + } + + @Override + public Void visitRootNamespaceExpression(JetRootNamespaceExpression expression, D data) { + return super.visitRootNamespaceExpression(expression, data); + } + + @Override + public Void visitBlockExpression(JetBlockExpression expression, D data) { + List statements = expression.getStatements(); + for (JetElement statement : statements) { + statement.visit(this, data); + } + return null; + } + + @Override + public Void visitCatchSection(JetCatchClause catchClause, D data) { + JetParameter catchParameter = catchClause.getCatchParameter(); + if (catchParameter != null) { + catchParameter.visit(this, data); + } + JetExpression catchBody = catchClause.getCatchBody(); + if (catchBody != null) { + catchBody.visit(this, data); + } + return null; + } + + @Override + public Void visitFinallySection(JetFinallySection finallySection, D data) { + JetBlockExpression finalExpression = finallySection.getFinalExpression(); + finalExpression.visit(this, data); + return null; + } + + @Override + public Void visitTypeArgumentList(JetTypeArgumentList typeArgumentList, D data) { + List arguments = typeArgumentList.getArguments(); + for (JetTypeProjection argument : arguments) { + argument.visit(this, data); + } + return null; + } + + @Override + public Void visitThisExpression(JetThisExpression expression, D data) { + JetReferenceExpression thisReference = expression.getThisReference(); + thisReference.visit(this, data); + JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier(); + if (superTypeQualifier != null) { + superTypeQualifier.visit(this, data); + } + visitLabelQualifiedExpression(expression, data); + return null; + } + + @Override + public Void visitParenthesizedExpression(JetParenthesizedExpression expression, D data) { + JetExpression innerExpression = expression.getExpression(); + if (innerExpression != null) { + innerExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitInitializerList(JetInitializerList list, D data) { + List initializers = list.getInitializers(); + for (JetDelegationSpecifier initializer : initializers) { + initializer.visit(this, data); + } + return null; + } + + @Override + public Void visitAnonymousInitializer(JetClassInitializer initializer, D data) { + JetExpression body = initializer.getBody(); + body.visit(this, data); + return null; + } + + @Override + public Void visitPropertyAccessor(JetPropertyAccessor accessor, D data) { + visitDeclarationWithBody(accessor, data); + return null; + } + + @Override + public Void visitTypeConstraintList(JetTypeConstraintList list, D data) { + List constraints = list.getConstraints(); + for (JetTypeConstraint constraint : constraints) { + constraint.visit(this, data); + } + return null; + } + + @Override + public Void visitTypeConstraint(JetTypeConstraint constraint, D data) { + JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName(); + if (subjectTypeParameterName != null) { + subjectTypeParameterName.visit(this, data); + } + return null; + } + + @Override + public Void visitUserType(JetUserType type, D data) { + return super.visitUserType(type, data); + } + + @Override + public Void visitTupleType(JetTupleType type, D data) { + return super.visitTupleType(type, data); + } + + @Override + public Void visitFunctionType(JetFunctionType type, D data) { + return super.visitFunctionType(type, data); + } + + @Override + public Void visitSelfType(JetSelfType type, D data) { + return super.visitSelfType(type, data); + } + + @Override + public Void visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeRHS expression, D data) { + JetExpression left = expression.getLeft(); + left.visit(this, data); + JetTypeReference right = expression.getRight(); + if (right != null) { + right.visit(this, data); + } + return null; + } + + @Override + public Void visitStringTemplateExpression(JetStringTemplateExpression expression, D data) { + JetStringTemplateEntry[] entries = expression.getEntries(); + for (JetStringTemplateEntry entry : entries) { + entry.visit(this, data); + } + return null; + } + + @Override + public Void visitNamedDeclaration(JetNamedDeclaration declaration, D data) { + return super.visitNamedDeclaration(declaration, data); + } + + @Override + public Void visitNullableType(JetNullableType nullableType, D data) { + return super.visitNullableType(nullableType, data); + } + + @Override + public Void visitTypeProjection(JetTypeProjection typeProjection, D data) { + return super.visitTypeProjection(typeProjection, data); + } + + @Override + public Void visitWhenEntry(JetWhenEntry jetWhenEntry, D data) { + JetExpression expression = jetWhenEntry.getExpression(); + if (expression != null) { + expression.visit(this, data); + } + JetWhenCondition[] conditions = jetWhenEntry.getConditions(); + for (JetWhenCondition condition : conditions) { + condition.visit(this, data); + } + return null; + } + + @Override + public Void visitIsExpression(JetIsExpression expression, D data) { + JetExpression leftHandSide = expression.getLeftHandSide(); + leftHandSide.visit(this, data); + JetSimpleNameExpression operationReference = expression.getOperationReference(); + operationReference.visit(this, data); + JetPattern pattern = expression.getPattern(); + if (pattern != null) { + pattern.visit(this, data); + } + return null; + } + + @Override + public Void visitWhenConditionCall(JetWhenConditionCall condition, D data) { + JetExpression callSuffixExpression = condition.getCallSuffixExpression(); + if (callSuffixExpression != null) { + callSuffixExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition, D data) { + JetPattern pattern = condition.getPattern(); + if (pattern != null) { + pattern.visit(this, data); + } + return null; + } + + @Override + public Void visitWhenConditionInRange(JetWhenConditionInRange condition, D data) { + JetSimpleNameExpression operationReference = condition.getOperationReference(); + operationReference.visit(this, data); + JetExpression rangeExpression = condition.getRangeExpression(); + if (rangeExpression != null) { + rangeExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitTypePattern(JetTypePattern pattern, D data) { + return super.visitTypePattern(pattern, data); + } + + @Override + public Void visitWildcardPattern(JetWildcardPattern pattern, D data) { + return super.visitWildcardPattern(pattern, data); + } + + @Override + public Void visitExpressionPattern(JetExpressionPattern pattern, D data) { + JetExpression expression = pattern.getExpression(); + if (expression != null) { + expression.visit(this, data); + } + return null; + } + + @Override + public Void visitTuplePattern(JetTuplePattern pattern, D data) { + List entries = pattern.getEntries(); + for (JetTuplePatternEntry entry : entries) { + entry.visit(this, data); + } + return null; + } + + @Override + public Void visitDecomposerPattern(JetDecomposerPattern pattern, D data) { + JetTuplePattern argumentList = pattern.getArgumentList(); + argumentList.visit(this, data); + JetExpression decomposerExpression = pattern.getDecomposerExpression(); + if (decomposerExpression != null) { + decomposerExpression.visit(this, data); + } + return null; + } + + @Override + public Void visitObjectDeclaration(JetObjectDeclaration objectDeclaration, D data) { + List declarations = objectDeclaration.getDeclarations(); + for (JetDeclaration declaration : declarations) { + declaration.visit(this, data); + } + JetDelegationSpecifierList delegationSpecifierList = objectDeclaration.getDelegationSpecifierList(); + if (delegationSpecifierList != null) { + delegationSpecifierList.visit(this, data); + } + return null; + } + + @Override + public Void visitBindingPattern(JetBindingPattern pattern, D data) { + JetWhenCondition condition = pattern.getCondition(); + if (condition != null) { + condition.visit(this, data); + } + JetProperty variableDeclaration = pattern.getVariableDeclaration(); + variableDeclaration.visit(this, data); + return null; + } + + @Override + public Void visitStringTemplateEntry(JetStringTemplateEntry entry, D data) { + JetExpression expression = entry.getExpression(); + if (expression != null) { + expression.visit(this, data); + } + return null; + } + + @Override + public Void visitStringTemplateEntryWithExpression(JetStringTemplateEntryWithExpression entry, D data) { + visitStringTemplateEntry(entry, data); + return null; + } + + @Override + public Void visitBlockStringTemplateEntry(JetBlockStringTemplateEntry entry, D data) { + visitStringTemplateEntry(entry, data); + return null; + } + + @Override + public Void visitSimpleNameStringTemplateEntry(JetSimpleNameStringTemplateEntry entry, D data) { + visitStringTemplateEntry(entry, data); + return null; + } + + @Override + public Void visitLiteralStringTemplateEntry(JetLiteralStringTemplateEntry entry, D data) { + visitStringTemplateEntry(entry, data); + return null; + } + + @Override + public Void visitEscapeStringTemplateEntry(JetEscapeStringTemplateEntry entry, D data) { + visitStringTemplateEntry(entry, data); + return null; + } + + private Void visitDeclarationWithBody(JetDeclarationWithBody declaration, D data) { + JetExpression bodyExpression = declaration.getBodyExpression(); + if (bodyExpression != null) { + bodyExpression.visit(this, data); + } + List valueParameters = declaration.getValueParameters(); + for (JetParameter valueParameter : valueParameters) { + valueParameter.visit(this, data); + } + return null; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTreeVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTreeVisitorVoid.java deleted file mode 100644 index 6b2e4de36e5..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTreeVisitorVoid.java +++ /dev/null @@ -1,728 +0,0 @@ -package org.jetbrains.jet.lang.psi; - -import java.util.List; - -/** - * @author svtk - */ -public class JetTreeVisitorVoid extends JetVisitorVoid { - @Override - public void visitNamespace(JetNamespace namespace) { - List importDirectives = namespace.getImportDirectives(); - for (JetImportDirective directive : importDirectives) { - directive.accept(this); - } - List declarations = namespace.getDeclarations(); - for (JetDeclaration declaration : declarations) { - declaration.accept(this); - } - } - - @Override - public void visitClass(JetClass klass) { - List declarations = klass.getDeclarations(); - for (JetDeclaration declaration : declarations) { - declaration.accept(this); - } - } - - @Override - public void visitClassObject(JetClassObject classObject) { - JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration(); - if (objectDeclaration != null) { - objectDeclaration.accept(this); - } - } - - @Override - public void visitConstructor(JetConstructor constructor) { - visitDeclarationWithBody(constructor); - } - - @Override - public void visitNamedFunction(JetNamedFunction function) { - visitDeclarationWithBody(function); - } - - @Override - public void visitProperty(JetProperty property) { - List accessors = property.getAccessors(); - for (JetPropertyAccessor accessor : accessors) { - accessor.accept(this); - } - JetExpression initializer = property.getInitializer(); - if (initializer != null) { - initializer.accept(this); - } - } - - @Override - public void visitTypedef(JetTypedef typedef) { - super.visitTypedef(typedef); - } - - @Override - public void visitJetFile(JetFile file) { - JetNamespace rootNamespace = file.getRootNamespace(); - rootNamespace.accept(this); - } - - @Override - public void visitImportDirective(JetImportDirective importDirective) { - super.visitImportDirective(importDirective); - } - - @Override - public void visitClassBody(JetClassBody classBody) { - List declarations = classBody.getDeclarations(); - for (JetDeclaration declaration : declarations) { - declaration.accept(this); - } - List secondaryConstructors = classBody.getSecondaryConstructors(); - for (JetConstructor constructor : secondaryConstructors) { - constructor.accept(this); - } - } - - @Override - public void visitNamespaceBody(JetNamespaceBody body) { - List declarations = body.getDeclarations(); - for (JetDeclaration declaration : declarations) { - declaration.accept(this); - } - } - - @Override - public void visitModifierList(JetModifierList list) { - super.visitModifierList(list); - } - - @Override - public void visitAnnotation(JetAnnotation annotation) { - super.visitAnnotation(annotation); - } - - @Override - public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { - super.visitAnnotationEntry(annotationEntry); - } - - @Override - public void visitTypeParameterList(JetTypeParameterList list) { - List parameters = list.getParameters(); - for (JetTypeParameter parameter : parameters) { - parameter.accept(this); - } - } - - @Override - public void visitTypeParameter(JetTypeParameter parameter) { - super.visitTypeParameter(parameter); - } - - @Override - public void visitEnumEntry(JetEnumEntry enumEntry) { - List delegationSpecifiers = enumEntry.getDelegationSpecifiers(); - for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) { - delegationSpecifier.accept(this); - } - JetModifierList modifierList = enumEntry.getModifierList(); - if (modifierList != null) { - modifierList.accept(this); - } - } - - @Override - public void visitParameterList(JetParameterList list) { - List parameters = list.getParameters(); - for (JetParameter parameter : parameters) { - parameter.accept(this); - } - } - - @Override - public void visitParameter(JetParameter parameter) { - super.visitParameter(parameter); - } - - @Override - public void visitDelegationSpecifierList(JetDelegationSpecifierList list) { - List delegationSpecifiers = list.getDelegationSpecifiers(); - for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) { - delegationSpecifier.accept(this); - } - } - - @Override - public void visitDelegationSpecifier(JetDelegationSpecifier specifier) { - super.visitDelegationSpecifier(specifier); - } - - @Override - public void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier) { - super.visitDelegationByExpressionSpecifier(specifier); - } - - @Override - public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) { - super.visitDelegationToSuperCallSpecifier(call); - } - - @Override - public void visitDelegationToSuperClassSpecifier(JetDelegatorToSuperClass specifier) { - super.visitDelegationToSuperClassSpecifier(specifier); - } - - @Override - public void visitDelegationToThisCall(JetDelegatorToThisCall thisCall) { - super.visitDelegationToThisCall(thisCall); - } - - @Override - public void visitTypeReference(JetTypeReference typeReference) { - super.visitTypeReference(typeReference); - } - - @Override - public void visitValueArgumentList(JetValueArgumentList list) { - List arguments = list.getArguments(); - for (JetValueArgument argument : arguments) { - argument.accept(this); - } - } - - @Override - public void visitArgument(JetValueArgument argument) { - super.visitArgument(argument); - } - - @Override - public void visitLoopExpression(JetLoopExpression loopExpression) { - JetExpression body = loopExpression.getBody(); - if (body != null) { - body.accept(this); - } - } - - @Override - public void visitConstantExpression(JetConstantExpression expression) { - super.visitConstantExpression(expression); - } - - @Override - public void visitSimpleNameExpression(JetSimpleNameExpression expression) { - super.visitSimpleNameExpression(expression); - } - - @Override - public void visitReferenceExpression(JetReferenceExpression expression) { - super.visitReferenceExpression(expression); - } - - @Override - public void visitTupleExpression(JetTupleExpression expression) { - super.visitTupleExpression(expression); - } - - @Override - public void visitPrefixExpression(JetPrefixExpression expression) { - JetExpression baseExpression = expression.getBaseExpression(); - if (baseExpression != null) { - baseExpression.accept(this); - } - } - - @Override - public void visitPostfixExpression(JetPostfixExpression expression) { - JetExpression baseExpression = expression.getBaseExpression(); - baseExpression.accept(this); - } - - @Override - public void visitUnaryExpression(JetUnaryExpression expression) { - JetExpression baseExpression = expression.getBaseExpression(); - assert baseExpression != null; - baseExpression.accept(this); - } - - @Override - public void visitBinaryExpression(JetBinaryExpression expression) { - JetExpression left = expression.getLeft(); - left.accept(this); - JetExpression right = expression.getRight(); - if (right != null) { - right.accept(this); - } - super.visitBinaryExpression(expression); - } - - @Override - public void visitReturnExpression(JetReturnExpression expression) { - JetExpression returnedExpression = expression.getReturnedExpression(); - if (returnedExpression != null) { - returnedExpression.accept(this); - } - } - - @Override - public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) { - JetExpression labeledExpression = expression.getLabeledExpression(); - if (labeledExpression != null) { - labeledExpression.accept(this); - } - } - - @Override - public void visitThrowExpression(JetThrowExpression expression) { - JetExpression thrownExpression = expression.getThrownExpression(); - if (thrownExpression != null) { - thrownExpression.accept(this); - } - } - - @Override - public void visitBreakExpression(JetBreakExpression expression) { - super.visitBreakExpression(expression); - } - - @Override - public void visitContinueExpression(JetContinueExpression expression) { - super.visitContinueExpression(expression); - } - - @Override - public void visitIfExpression(JetIfExpression expression) { - JetExpression condition = expression.getCondition(); - if (condition != null) { - condition.accept(this); - } - JetExpression then = expression.getThen(); - if (then != null) { - then.accept(this); - } - JetExpression anElse = expression.getElse(); - if (anElse != null) { - anElse.accept(this); - } - } - - @Override - public void visitWhenExpression(JetWhenExpression expression) { - List entries = expression.getEntries(); - for (JetWhenEntry entry : entries) { - entry.accept(this); - } - JetExpression subjectExpression = expression.getSubjectExpression(); - if (subjectExpression != null) { - subjectExpression.accept(this); - } - } - - @Override - public void visitTryExpression(JetTryExpression expression) { - JetBlockExpression tryBlock = expression.getTryBlock(); - tryBlock.accept(this); - List catchClauses = expression.getCatchClauses(); - for (JetCatchClause catchClause : catchClauses) { - catchClause.accept(this); - } - JetFinallySection finallyBlock = expression.getFinallyBlock(); - if (finallyBlock != null) { - finallyBlock.accept(this); - } - } - - @Override - public void visitForExpression(JetForExpression expression) { - JetParameter loopParameter = expression.getLoopParameter(); - if (loopParameter != null) { - loopParameter.accept(this); - } - JetExpression loopRange = expression.getLoopRange(); - if (loopRange != null) { - loopRange.accept(this); - } - visitLoopExpression(expression); - } - - @Override - public void visitWhileExpression(JetWhileExpression expression) { - JetExpression condition = expression.getCondition(); - if (condition != null) { - condition.accept(this); - } - visitLoopExpression(expression); - } - - @Override - public void visitDoWhileExpression(JetDoWhileExpression expression) { - JetExpression condition = expression.getCondition(); - if (condition != null) { - condition.accept(this); - } - visitLoopExpression(expression); - } - - @Override - public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { - JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); - functionLiteral.accept(this); - visitDeclarationWithBody(expression); - } - - @Override - public void visitAnnotatedExpression(JetAnnotatedExpression expression) { - JetExpression baseExpression = expression.getBaseExpression(); - baseExpression.accept(this); - } - - @Override - public void visitCallExpression(JetCallExpression expression) { - JetExpression calleeExpression = expression.getCalleeExpression(); - if (calleeExpression != null) { - calleeExpression.accept(this); - } - } - - @Override - public void visitArrayAccessExpression(JetArrayAccessExpression expression) { - JetExpression arrayExpression = expression.getArrayExpression(); - arrayExpression.accept(this); - List indexExpressions = expression.getIndexExpressions(); - for (JetExpression indexExpression : indexExpressions) { - indexExpression.accept(this); - } - } - - @Override - public void visitQualifiedExpression(JetQualifiedExpression expression) { - JetExpression receiver = expression.getReceiverExpression(); - receiver.accept(this); - JetExpression selector = expression.getSelectorExpression(); - if (selector != null) { - selector.accept(this); - } - } - - @Override - public void visitHashQualifiedExpression(JetHashQualifiedExpression expression) { - visitQualifiedExpression(expression); - } - - @Override - public void visitDotQualifiedExpression(JetDotQualifiedExpression expression) { - visitQualifiedExpression(expression); - } - - @Override - public void visitPredicateExpression(JetPredicateExpression expression) { - visitQualifiedExpression(expression); - } - - @Override - public void visitSafeQualifiedExpression(JetSafeQualifiedExpression expression) { - visitQualifiedExpression(expression); - } - - @Override - public void visitObjectLiteralExpression(JetObjectLiteralExpression expression) { - JetObjectDeclaration objectDeclaration = expression.getObjectDeclaration(); - objectDeclaration.accept(this); - } - - @Override - public void visitRootNamespaceExpression(JetRootNamespaceExpression expression) { - super.visitRootNamespaceExpression(expression); - } - - @Override - public void visitBlockExpression(JetBlockExpression expression) { - List statements = expression.getStatements(); - for (JetElement statement : statements) { - statement.accept(this); - } - } - - @Override - public void visitCatchSection(JetCatchClause catchClause) { - JetParameter catchParameter = catchClause.getCatchParameter(); - if (catchParameter != null) { - catchParameter.accept(this); - } - JetExpression catchBody = catchClause.getCatchBody(); - if (catchBody != null) { - catchBody.accept(this); - } - } - - @Override - public void visitFinallySection(JetFinallySection finallySection) { - JetBlockExpression finalExpression = finallySection.getFinalExpression(); - finalExpression.accept(this); - } - - @Override - public void visitTypeArgumentList(JetTypeArgumentList typeArgumentList) { - List arguments = typeArgumentList.getArguments(); - for (JetTypeProjection argument : arguments) { - argument.accept(this); - } - } - - @Override - public void visitThisExpression(JetThisExpression expression) { - JetReferenceExpression thisReference = expression.getThisReference(); - thisReference.accept(this); - JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier(); - if (superTypeQualifier != null) { - superTypeQualifier.accept(this); - } - visitLabelQualifiedExpression(expression); - } - - @Override - public void visitParenthesizedExpression(JetParenthesizedExpression expression) { - JetExpression innerExpression = expression.getExpression(); - if (innerExpression != null) { - innerExpression.accept(this); - } - } - - @Override - public void visitInitializerList(JetInitializerList list) { - List initializers = list.getInitializers(); - for (JetDelegationSpecifier initializer : initializers) { - initializer.accept(this); - } - } - - @Override - public void visitAnonymousInitializer(JetClassInitializer initializer) { - JetExpression body = initializer.getBody(); - body.accept(this); - } - - @Override - public void visitPropertyAccessor(JetPropertyAccessor accessor) { - visitDeclarationWithBody(accessor); - } - - @Override - public void visitTypeConstraintList(JetTypeConstraintList list) { - List constraints = list.getConstraints(); - for (JetTypeConstraint constraint : constraints) { - constraint.accept(this); - } - } - - @Override - public void visitTypeConstraint(JetTypeConstraint constraint) { - JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName(); - if (subjectTypeParameterName != null) { - subjectTypeParameterName.accept(this); - } - } - - @Override - public void visitUserType(JetUserType type) { - super.visitUserType(type); - } - - @Override - public void visitTupleType(JetTupleType type) { - super.visitTupleType(type); - } - - @Override - public void visitFunctionType(JetFunctionType type) { - super.visitFunctionType(type); - } - - @Override - public void visitSelfType(JetSelfType type) { - super.visitSelfType(type); - } - - @Override - public void visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeRHS expression) { - JetExpression left = expression.getLeft(); - left.accept(this); - JetTypeReference right = expression.getRight(); - if (right != null) { - right.accept(this); - } - } - - @Override - public void visitStringTemplateExpression(JetStringTemplateExpression expression) { - JetStringTemplateEntry[] entries = expression.getEntries(); - for (JetStringTemplateEntry entry : entries) { - entry.accept(this); - } - } - - @Override - public void visitNamedDeclaration(JetNamedDeclaration declaration) { - super.visitNamedDeclaration(declaration); - } - - @Override - public void visitNullableType(JetNullableType nullableType) { - super.visitNullableType(nullableType); - } - - @Override - public void visitTypeProjection(JetTypeProjection typeProjection) { - super.visitTypeProjection(typeProjection); - } - - @Override - public void visitWhenEntry(JetWhenEntry jetWhenEntry) { - JetExpression expression = jetWhenEntry.getExpression(); - if (expression != null) { - expression.accept(this); - } - JetWhenCondition[] conditions = jetWhenEntry.getConditions(); - for (JetWhenCondition condition : conditions) { - condition.accept(this); - } - } - - @Override - public void visitIsExpression(JetIsExpression expression) { - JetExpression leftHandSide = expression.getLeftHandSide(); - leftHandSide.accept(this); - JetSimpleNameExpression operationReference = expression.getOperationReference(); - operationReference.accept(this); - JetPattern pattern = expression.getPattern(); - if (pattern != null) { - pattern.accept(this); - } - } - - @Override - public void visitWhenConditionCall(JetWhenConditionCall condition) { - JetExpression callSuffixExpression = condition.getCallSuffixExpression(); - if (callSuffixExpression != null) { - callSuffixExpression.accept(this); - } - } - - @Override - public void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition) { - JetPattern pattern = condition.getPattern(); - if (pattern != null) { - pattern.accept(this); - } - } - - @Override - public void visitWhenConditionInRange(JetWhenConditionInRange condition) { - JetSimpleNameExpression operationReference = condition.getOperationReference(); - operationReference.accept(this); - JetExpression rangeExpression = condition.getRangeExpression(); - if (rangeExpression != null) { - rangeExpression.accept(this); - } - } - - @Override - public void visitTypePattern(JetTypePattern pattern) { - super.visitTypePattern(pattern); - } - - @Override - public void visitWildcardPattern(JetWildcardPattern pattern) { - super.visitWildcardPattern(pattern); - } - - @Override - public void visitExpressionPattern(JetExpressionPattern pattern) { - JetExpression expression = pattern.getExpression(); - expression.accept(this); - } - - @Override - public void visitTuplePattern(JetTuplePattern pattern) { - List entries = pattern.getEntries(); - for (JetTuplePatternEntry entry : entries) { - entry.accept(this); - } - } - - @Override - public void visitDecomposerPattern(JetDecomposerPattern pattern) { - JetTuplePattern argumentList = pattern.getArgumentList(); - argumentList.accept(this); - JetExpression decomposerExpression = pattern.getDecomposerExpression(); - if (decomposerExpression != null) { - decomposerExpression.accept(this); - } - } - - @Override - public void visitObjectDeclaration(JetObjectDeclaration objectDeclaration) { - List declarations = objectDeclaration.getDeclarations(); - for (JetDeclaration declaration : declarations) { - declaration.accept(this); - } - JetDelegationSpecifierList delegationSpecifierList = objectDeclaration.getDelegationSpecifierList(); - if (delegationSpecifierList != null) { - delegationSpecifierList.accept(this); - } - } - - @Override - public void visitBindingPattern(JetBindingPattern pattern) { - JetWhenCondition condition = pattern.getCondition(); - if (condition != null) { - condition.accept(this); - } - JetProperty variableDeclaration = pattern.getVariableDeclaration(); - variableDeclaration.accept(this); - } - - @Override - public void visitStringTemplateEntry(JetStringTemplateEntry entry) { - JetExpression expression = entry.getExpression(); - if (expression != null) { - expression.accept(this); - } - } - - @Override - public void visitStringTemplateEntryWithExpression(JetStringTemplateEntryWithExpression entry) { - visitStringTemplateEntry(entry); - } - - @Override - public void visitBlockStringTemplateEntry(JetBlockStringTemplateEntry entry) { - visitStringTemplateEntry(entry); - } - - @Override - public void visitSimpleNameStringTemplateEntry(JetSimpleNameStringTemplateEntry entry) { - visitStringTemplateEntry(entry); - } - - @Override - public void visitLiteralStringTemplateEntry(JetLiteralStringTemplateEntry entry) { - visitStringTemplateEntry(entry); - } - - @Override - public void visitEscapeStringTemplateEntry(JetEscapeStringTemplateEntry entry) { - visitStringTemplateEntry(entry); - } - - private void visitDeclarationWithBody(JetDeclarationWithBody declaration) { - JetExpression bodyExpression = declaration.getBodyExpression(); - if (bodyExpression != null) { - bodyExpression.accept(this); - } - List valueParameters = declaration.getValueParameters(); - for (JetParameter valueParameter : valueParameters) { - valueParameter.accept(this); - } - } -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java index 9e85eadfd73..d4f0dec17dd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java @@ -58,8 +58,7 @@ public class ControlFlowAnalyzer { private void checkFunction(JetDeclarationWithBody function, FunctionDescriptor functionDescriptor, final @NotNull JetType expectedReturnType) { JetExpression bodyExpression = function.getBodyExpression(); if (bodyExpression == null) return; - - JetFlowInformationProvider flowInformationProvider = context.getClassDescriptorResolver().computeFlowData((JetElement)function, bodyExpression); + JetFlowInformationProvider flowInformationProvider = context.getClassDescriptorResolver().computeFlowData((JetElement) function, bodyExpression); final boolean blockBody = function.hasBlockBody(); List unreachableElements = Lists.newArrayList(); @@ -105,29 +104,11 @@ public class ControlFlowAnalyzer { } }); } - markDominatedExpressionsAsUnreachable(bodyExpression, scope, expectedReturnType, flowInformationProvider); } - private void markDominatedExpressionsAsUnreachable(JetExpression expression, JetScope scope, JetType expectedReturnType, JetFlowInformationProvider flowInformationProvider) { - JetType type = typeInferrer.getType(scope, expression, expectedReturnType); - if (type == null || !JetStandardClasses.isNothing(type) || type.isNullable()) { - return; - } - - List dominated = new ArrayList(); - flowInformationProvider.collectDominatedExpressions(expression, dominated); - Set rootExpressions = JetPsiUtil.findRootExpressions(dominated); - for (JetElement rootExpression : rootExpressions) { - context.getTrace().report(UNREACHABLE_BECAUSE_OF_NOTHING.on(rootExpression, expression.getText())); - } - } - - private void checkProperty(JetProperty property) { JetExpression initializer = property.getInitializer(); if (initializer == null) return; - JetScope scope = this.context.getDeclaringScopes().get(property); - JetFlowInformationProvider flowInformationProvider = context.getClassDescriptorResolver().computeFlowData(property, initializer); - markDominatedExpressionsAsUnreachable(initializer, scope, NO_EXPECTED_TYPE, flowInformationProvider); + context.getClassDescriptorResolver().computeFlowData(property, initializer); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index cec4b09de34..7abaef85e08 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -393,7 +393,7 @@ public class JetTypeInferrer { private Map collectReturnedExpressionsWithTypes( @NotNull BindingTrace trace, JetScope outerScope, - JetDeclarationWithBody function, + final JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) { JetExpression bodyExpression = function.getBodyExpression(); assert bodyExpression != null; @@ -402,12 +402,26 @@ public class JetTypeInferrer { //todo function literals final Collection returnedExpressions = new ArrayList(); if (function.hasBlockBody()) { - bodyExpression.accept(new JetTreeVisitorVoid() { + //now this code is never invoked!, it should be invoked for inference of return type of function literal with local returns + bodyExpression.visit(new JetTreeVisitor() { @Override - public void visitReturnExpression(JetReturnExpression expression) { - returnedExpressions.add(expression); + public Void visitReturnExpression(JetReturnExpression expression, JetDeclarationWithBody outerFunction) { + if (expression.getLabeledExpression() == function || outerFunction == function) { + returnedExpressions.add(expression); + } + return null; } - }); + + @Override + public Void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression, JetDeclarationWithBody outerFunction) { + return super.visitFunctionLiteralExpression(expression, expression.getFunctionLiteral()); + } + + @Override + public Void visitNamedFunction(JetNamedFunction function, JetDeclarationWithBody outerFunction) { + return super.visitNamedFunction(function, function); + } + }, function); } else { returnedExpressions.add(bodyExpression); @@ -1894,14 +1908,15 @@ public class JetTypeInferrer { private boolean containsBreak(JetLoopExpression expression) { final boolean[] result = new boolean[1]; result[0] = false; - expression.accept(new JetTreeVisitorVoid() { + expression.visit(new JetTreeVisitor() { @Override - public void visitBreakExpression(JetBreakExpression expression) { - //todo get exact loop for this break, compare to expression + public Void visitBreakExpression(JetBreakExpression expression, Void v) { + //todo get exact loop for this break, compare to an expression //expression.getLabeledExpression() result[0] = true; + return null; } - }); + }, null); return result[0]; } diff --git a/idea/testData/cfg/ArrayAccess.instructions b/idea/testData/cfg/ArrayAccess.instructions index ea110204bd7..b2d18a45e79 100644 --- a/idea/testData/cfg/ArrayAccess.instructions +++ b/idea/testData/cfg/ArrayAccess.instructions @@ -36,15 +36,3 @@ l1: error: ===================== -== a == -val a = Array ---------------------- -l0: - - r(Array) - r(Array) -l1: - -error: - -===================== diff --git a/idea/testData/cfg/Assignments.instructions b/idea/testData/cfg/Assignments.instructions index 89fda838fce..07ceb36d2c8 100644 --- a/idea/testData/cfg/Assignments.instructions +++ b/idea/testData/cfg/Assignments.instructions @@ -55,56 +55,3 @@ l1: error: ===================== -== x == -var x = 1 ---------------------- -l0: - - r(1) -l1: - -error: - -===================== -== y == -val y = true && false ---------------------- -l0: - - r(true) - jf(l2) - r(false) -l2: - r(true && false) -l1: - -error: - -===================== -== z == -val z = false && true ---------------------- -l0: - - r(false) - jf(l2) - r(true) -l2: - r(false && true) -l1: - -error: - -===================== -== t == -val t = Test() ---------------------- -l0: - - r(Test) - r(Test()) -l1: - -error: - -===================== diff --git a/idea/testData/checker/UnreachableCode.jet b/idea/testData/checker/UnreachableCode.jet index b34b281adcc..15ba14178fc 100644 --- a/idea/testData/checker/UnreachableCode.jet +++ b/idea/testData/checker/UnreachableCode.jet @@ -136,9 +136,9 @@ fun tf() : Int { } fun failtest(a : Int) : Int { - if (fail() || true) { + if (fail() || true) { - } + } return 1 } diff --git a/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet b/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet index 2a72a04117d..432b5e53605 100644 --- a/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet +++ b/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet @@ -136,16 +136,16 @@ fun tf() : Int { } fun failtest(a : Int) : Int { - if (fail() || true) { + if (fail() || true) { - } - return 1 + } + return 1 } fun foo(a : Nothing) : Unit { 1 a - 2 + 2 } fun fail() : Nothing {