Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
Brian Wilkerson
2012/09/19 14:06:58
This file appears to have been accidentally includ
| |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package com.google.dart.compiler.resolver; | 5 package com.google.dart.compiler.resolver; |
| 6 | 6 |
| 7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
| 8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
| 9 import com.google.common.collect.Sets; | 9 import com.google.common.collect.Sets; |
| 10 import com.google.dart.compiler.DartCompilationPhase; | 10 import com.google.dart.compiler.DartCompilationPhase; |
| 11 import com.google.dart.compiler.DartCompilerContext; | 11 import com.google.dart.compiler.DartCompilerContext; |
| 12 import com.google.dart.compiler.ErrorCode; | 12 import com.google.dart.compiler.ErrorCode; |
| 13 import com.google.dart.compiler.ast.ASTNodes; | 13 import com.google.dart.compiler.ast.ASTNodes; |
| 14 import com.google.dart.compiler.ast.ASTVisitor; | 14 import com.google.dart.compiler.ast.ASTVisitor; |
| 15 import com.google.dart.compiler.ast.DartArrayLiteral; | 15 import com.google.dart.compiler.ast.DartArrayLiteral; |
| 16 import com.google.dart.compiler.ast.DartBinaryExpression; | 16 import com.google.dart.compiler.ast.DartBinaryExpression; |
| 17 import com.google.dart.compiler.ast.DartBlock; | 17 import com.google.dart.compiler.ast.DartBlock; |
| 18 import com.google.dart.compiler.ast.DartBooleanLiteral; | 18 import com.google.dart.compiler.ast.DartBooleanLiteral; |
| 19 import com.google.dart.compiler.ast.DartBreakStatement; | 19 import com.google.dart.compiler.ast.DartBreakStatement; |
| 20 import com.google.dart.compiler.ast.DartCase; | |
| 20 import com.google.dart.compiler.ast.DartCatchBlock; | 21 import com.google.dart.compiler.ast.DartCatchBlock; |
| 21 import com.google.dart.compiler.ast.DartClass; | 22 import com.google.dart.compiler.ast.DartClass; |
| 22 import com.google.dart.compiler.ast.DartClassMember; | 23 import com.google.dart.compiler.ast.DartClassMember; |
| 23 import com.google.dart.compiler.ast.DartContinueStatement; | 24 import com.google.dart.compiler.ast.DartContinueStatement; |
| 24 import com.google.dart.compiler.ast.DartDirective; | 25 import com.google.dart.compiler.ast.DartDirective; |
| 25 import com.google.dart.compiler.ast.DartDoWhileStatement; | 26 import com.google.dart.compiler.ast.DartDoWhileStatement; |
| 26 import com.google.dart.compiler.ast.DartDoubleLiteral; | 27 import com.google.dart.compiler.ast.DartDoubleLiteral; |
| 28 import com.google.dart.compiler.ast.DartExprStmt; | |
| 27 import com.google.dart.compiler.ast.DartExpression; | 29 import com.google.dart.compiler.ast.DartExpression; |
| 28 import com.google.dart.compiler.ast.DartField; | 30 import com.google.dart.compiler.ast.DartField; |
| 29 import com.google.dart.compiler.ast.DartFieldDefinition; | 31 import com.google.dart.compiler.ast.DartFieldDefinition; |
| 30 import com.google.dart.compiler.ast.DartForInStatement; | 32 import com.google.dart.compiler.ast.DartForInStatement; |
| 31 import com.google.dart.compiler.ast.DartForStatement; | 33 import com.google.dart.compiler.ast.DartForStatement; |
| 32 import com.google.dart.compiler.ast.DartFunction; | 34 import com.google.dart.compiler.ast.DartFunction; |
| 33 import com.google.dart.compiler.ast.DartFunctionExpression; | 35 import com.google.dart.compiler.ast.DartFunctionExpression; |
| 34 import com.google.dart.compiler.ast.DartFunctionObjectInvocation; | 36 import com.google.dart.compiler.ast.DartFunctionObjectInvocation; |
| 35 import com.google.dart.compiler.ast.DartFunctionTypeAlias; | 37 import com.google.dart.compiler.ast.DartFunctionTypeAlias; |
| 36 import com.google.dart.compiler.ast.DartGotoStatement; | 38 import com.google.dart.compiler.ast.DartGotoStatement; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 54 import com.google.dart.compiler.ast.DartRedirectConstructorInvocation; | 56 import com.google.dart.compiler.ast.DartRedirectConstructorInvocation; |
| 55 import com.google.dart.compiler.ast.DartReturnStatement; | 57 import com.google.dart.compiler.ast.DartReturnStatement; |
| 56 import com.google.dart.compiler.ast.DartStatement; | 58 import com.google.dart.compiler.ast.DartStatement; |
| 57 import com.google.dart.compiler.ast.DartStringInterpolation; | 59 import com.google.dart.compiler.ast.DartStringInterpolation; |
| 58 import com.google.dart.compiler.ast.DartStringLiteral; | 60 import com.google.dart.compiler.ast.DartStringLiteral; |
| 59 import com.google.dart.compiler.ast.DartSuperConstructorInvocation; | 61 import com.google.dart.compiler.ast.DartSuperConstructorInvocation; |
| 60 import com.google.dart.compiler.ast.DartSuperExpression; | 62 import com.google.dart.compiler.ast.DartSuperExpression; |
| 61 import com.google.dart.compiler.ast.DartSwitchMember; | 63 import com.google.dart.compiler.ast.DartSwitchMember; |
| 62 import com.google.dart.compiler.ast.DartSwitchStatement; | 64 import com.google.dart.compiler.ast.DartSwitchStatement; |
| 63 import com.google.dart.compiler.ast.DartThisExpression; | 65 import com.google.dart.compiler.ast.DartThisExpression; |
| 66 import com.google.dart.compiler.ast.DartThrowExpression; | |
| 64 import com.google.dart.compiler.ast.DartTryStatement; | 67 import com.google.dart.compiler.ast.DartTryStatement; |
| 65 import com.google.dart.compiler.ast.DartTypeExpression; | 68 import com.google.dart.compiler.ast.DartTypeExpression; |
| 66 import com.google.dart.compiler.ast.DartTypeNode; | 69 import com.google.dart.compiler.ast.DartTypeNode; |
| 67 import com.google.dart.compiler.ast.DartTypeParameter; | 70 import com.google.dart.compiler.ast.DartTypeParameter; |
| 68 import com.google.dart.compiler.ast.DartUnaryExpression; | 71 import com.google.dart.compiler.ast.DartUnaryExpression; |
| 69 import com.google.dart.compiler.ast.DartUnit; | 72 import com.google.dart.compiler.ast.DartUnit; |
| 70 import com.google.dart.compiler.ast.DartUnqualifiedInvocation; | 73 import com.google.dart.compiler.ast.DartUnqualifiedInvocation; |
| 71 import com.google.dart.compiler.ast.DartVariable; | 74 import com.google.dart.compiler.ast.DartVariable; |
| 72 import com.google.dart.compiler.ast.DartVariableStatement; | 75 import com.google.dart.compiler.ast.DartVariableStatement; |
| 73 import com.google.dart.compiler.ast.DartWhileStatement; | 76 import com.google.dart.compiler.ast.DartWhileStatement; |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 } | 1001 } |
| 999 | 1002 |
| 1000 | 1003 |
| 1001 @Override | 1004 @Override |
| 1002 public Element visitSwitchStatement(DartSwitchStatement x) { | 1005 public Element visitSwitchStatement(DartSwitchStatement x) { |
| 1003 getContext().pushScope("<switch>"); | 1006 getContext().pushScope("<switch>"); |
| 1004 addLabelToStatement(x); | 1007 addLabelToStatement(x); |
| 1005 // The scope of a label on the case statement is the case statement itself . These labels | 1008 // The scope of a label on the case statement is the case statement itself . These labels |
| 1006 // need to be resolved before the continue <label>; statements can be reso lved. | 1009 // need to be resolved before the continue <label>; statements can be reso lved. |
| 1007 for (DartSwitchMember member : x.getMembers()) { | 1010 for (DartSwitchMember member : x.getMembers()) { |
| 1008 recordSwitchMamberLabel(member); | 1011 recordSwitchMemberLabel(member); |
| 1009 } | 1012 } |
| 1010 x.visitChildren(this); | 1013 x.visitChildren(this); |
| 1011 getContext().popScope(); | 1014 getContext().popScope(); |
| 1012 return null; | 1015 return null; |
| 1013 } | 1016 } |
| 1014 | 1017 |
| 1015 @Override | 1018 @Override |
| 1019 public Element visitCase(DartCase node) { | |
| 1020 super.visitCase(node); | |
| 1021 List<DartStatement> statements = node.getStatements(); | |
| 1022 // the last statement should be: break, continue, return, throw | |
| 1023 if (!statements.isEmpty()) { | |
| 1024 DartStatement lastStatement = statements.get(statements.size() - 1); | |
| 1025 if (!isValidLastSwitchCaseStatement(lastStatement)) { | |
| 1026 onError(lastStatement, ResolverErrorCode.SWITCH_CASE_FALL_THROUGH); | |
| 1027 } | |
| 1028 } | |
| 1029 // done | |
| 1030 return null; | |
| 1031 } | |
| 1032 | |
| 1033 private boolean isValidLastSwitchCaseStatement(DartStatement statement) { | |
| 1034 if (statement instanceof DartExprStmt) { | |
| 1035 DartExprStmt exprStmt = (DartExprStmt) statement; | |
| 1036 if (exprStmt.getExpression() instanceof DartThrowExpression) { | |
| 1037 return true; | |
| 1038 } | |
| 1039 } | |
| 1040 return statement instanceof DartBreakStatement || statement instanceof Dar tContinueStatement | |
| 1041 || statement instanceof DartReturnStatement; | |
| 1042 } | |
| 1043 | |
| 1044 @Override | |
| 1016 public Element visitSwitchMember(DartSwitchMember x) { | 1045 public Element visitSwitchMember(DartSwitchMember x) { |
| 1017 getContext().pushScope("<switch member>"); | 1046 getContext().pushScope("<switch member>"); |
| 1018 x.visitChildren(this); | 1047 x.visitChildren(this); |
| 1019 getContext().popScope(); | 1048 getContext().popScope(); |
| 1020 return null; | 1049 return null; |
| 1021 } | 1050 } |
| 1022 | 1051 |
| 1023 private void recordSwitchMamberLabel(DartSwitchMember x) { | 1052 private void recordSwitchMemberLabel(DartSwitchMember x) { |
| 1024 List<DartLabel> labels = x.getLabels(); | 1053 List<DartLabel> labels = x.getLabels(); |
| 1025 for (DartLabel label : labels) { | 1054 for (DartLabel label : labels) { |
| 1026 LabelElement labelElement = Elements.switchMemberLabelElement(label, la bel.getName(), | 1055 LabelElement labelElement = Elements.switchMemberLabelElement(label, la bel.getName(), |
| 1027 innermostFunction); | 1056 innermostFunction); |
| 1028 recordElement(label.getLabel(), labelElement); | 1057 recordElement(label.getLabel(), labelElement); |
| 1029 recordElement(label, labelElement); | 1058 recordElement(label, labelElement); |
| 1030 if (getContext().getScope().hasLocalLabel(label.getName())) { | 1059 if (getContext().getScope().hasLocalLabel(label.getName())) { |
| 1031 onError(label, ResolverErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT); | 1060 onError(label, ResolverErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT); |
| 1032 } | 1061 } |
| 1033 getContext().getScope().addLabel(labelElement); | 1062 getContext().getScope().addLabel(labelElement); |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2336 ClassElement currentClass = (ClassElement) constructor.getEnclosingEle ment(); | 2365 ClassElement currentClass = (ClassElement) constructor.getEnclosingEle ment(); |
| 2337 if (nextClass == currentClass) { | 2366 if (nextClass == currentClass) { |
| 2338 return (ConstructorNodeElement) nextConstructorElement; | 2367 return (ConstructorNodeElement) nextConstructorElement; |
| 2339 } | 2368 } |
| 2340 } | 2369 } |
| 2341 } | 2370 } |
| 2342 } | 2371 } |
| 2343 return null; | 2372 return null; |
| 2344 } | 2373 } |
| 2345 } | 2374 } |
| OLD | NEW |