| 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 |
| 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 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 6063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6074 } | 6074 } |
| 6075 if (first_value.IsDouble()) { | 6075 if (first_value.IsDouble()) { |
| 6076 if (!val.IsDouble()) { | 6076 if (!val.IsDouble()) { |
| 6077 ErrorMsg(val_pos, "expected case expression of type double"); | 6077 ErrorMsg(val_pos, "expected case expression of type double"); |
| 6078 } | 6078 } |
| 6079 continue; | 6079 continue; |
| 6080 } | 6080 } |
| 6081 if (val.clazz() != first_value.clazz()) { | 6081 if (val.clazz() != first_value.clazz()) { |
| 6082 ErrorMsg(val_pos, "all case expressions must be of same type"); | 6082 ErrorMsg(val_pos, "all case expressions must be of same type"); |
| 6083 } | 6083 } |
| 6084 Class& cls = Class::Handle(val.clazz()); | 6084 if (i == 0) { |
| 6085 const Function& equal_op = Function::Handle( | 6085 // The value is of some type other than int, String or double. |
| 6086 Resolver::ResolveDynamicAnyArgs(cls, Symbols::EqualOperator())); | 6086 // Check that the type class does not override the == operator. |
| 6087 ASSERT(!equal_op.IsNull()); | 6087 // Check this only in the first loop iteration since all values |
| 6088 cls = equal_op.Owner(); | 6088 // are of the same type, which we check above. |
| 6089 if (!cls.IsObjectClass()) { | 6089 Class& cls = Class::Handle(val.clazz()); |
| 6090 ErrorMsg(val_pos, | 6090 const Function& equal_op = Function::Handle( |
| 6091 "type class of case expression must not implement operator =="); | 6091 Resolver::ResolveDynamicAnyArgs(cls, Symbols::EqualOperator())); |
| 6092 ASSERT(!equal_op.IsNull()); |
| 6093 cls = equal_op.Owner(); |
| 6094 if (!cls.IsObjectClass()) { |
| 6095 ErrorMsg(val_pos, |
| 6096 "type class of case expression must not implement operator =="); |
| 6097 } |
| 6092 } | 6098 } |
| 6093 } | 6099 } |
| 6094 } | 6100 } |
| 6095 | 6101 |
| 6096 | 6102 |
| 6097 CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value, | 6103 CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value, |
| 6098 GrowableArray<LiteralNode*>* case_expr_values, | 6104 GrowableArray<LiteralNode*>* case_expr_values, |
| 6099 SourceLabel* case_label) { | 6105 SourceLabel* case_label) { |
| 6100 TRACE_PARSER("ParseCaseClause"); | 6106 TRACE_PARSER("ParseCaseClause"); |
| 6101 bool default_seen = false; | 6107 bool default_seen = false; |
| (...skipping 4501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10603 void Parser::SkipQualIdent() { | 10609 void Parser::SkipQualIdent() { |
| 10604 ASSERT(IsIdentifier()); | 10610 ASSERT(IsIdentifier()); |
| 10605 ConsumeToken(); | 10611 ConsumeToken(); |
| 10606 if (CurrentToken() == Token::kPERIOD) { | 10612 if (CurrentToken() == Token::kPERIOD) { |
| 10607 ConsumeToken(); // Consume the kPERIOD token. | 10613 ConsumeToken(); // Consume the kPERIOD token. |
| 10608 ExpectIdentifier("identifier expected after '.'"); | 10614 ExpectIdentifier("identifier expected after '.'"); |
| 10609 } | 10615 } |
| 10610 } | 10616 } |
| 10611 | 10617 |
| 10612 } // namespace dart | 10618 } // namespace dart |
| OLD | NEW |