| 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 "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 7232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7243 ReportError(val_pos, "expected case expression of type String"); | 7243 ReportError(val_pos, "expected case expression of type String"); |
| 7244 } | 7244 } |
| 7245 continue; | 7245 continue; |
| 7246 } | 7246 } |
| 7247 if (val.IsDouble()) { | 7247 if (val.IsDouble()) { |
| 7248 ReportError(val_pos, "case expression may not be of type double"); | 7248 ReportError(val_pos, "case expression may not be of type double"); |
| 7249 } | 7249 } |
| 7250 if (val.clazz() != first_value.clazz()) { | 7250 if (val.clazz() != first_value.clazz()) { |
| 7251 ReportError(val_pos, "all case expressions must be of same type"); | 7251 ReportError(val_pos, "all case expressions must be of same type"); |
| 7252 } | 7252 } |
| 7253 if (val.clazz() == I->object_store()->symbol_class()) { |
| 7254 continue; |
| 7255 } |
| 7253 if (i == 0) { | 7256 if (i == 0) { |
| 7254 // The value is of some type other than int, String or double. | 7257 // The value is of some type other than int, String or double. |
| 7255 // Check that the type class does not override the == operator. | 7258 // Check that the type class does not override the == operator. |
| 7256 // Check this only in the first loop iteration since all values | 7259 // Check this only in the first loop iteration since all values |
| 7257 // are of the same type, which we check above. | 7260 // are of the same type, which we check above. |
| 7258 if (ImplementsEqualOperator(val)) { | 7261 if (ImplementsEqualOperator(val)) { |
| 7259 ReportError(val_pos, | 7262 ReportError(val_pos, |
| 7260 "type class of case expression must not " | 7263 "type class of case expression must not " |
| 7261 "implement operator =="); | 7264 "implement operator =="); |
| 7262 } | 7265 } |
| (...skipping 3749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11012 key_pos, key, key_type, Symbols::ListLiteralElement()); | 11015 key_pos, key, key_type, Symbols::ListLiteralElement()); |
| 11013 } | 11016 } |
| 11014 if (is_const) { | 11017 if (is_const) { |
| 11015 ASSERT(key->IsLiteralNode()); | 11018 ASSERT(key->IsLiteralNode()); |
| 11016 const Instance& key_value = key->AsLiteralNode()->literal(); | 11019 const Instance& key_value = key->AsLiteralNode()->literal(); |
| 11017 if (key_value.IsDouble()) { | 11020 if (key_value.IsDouble()) { |
| 11018 ReportError(key_pos, "key value must not be of type double"); | 11021 ReportError(key_pos, "key value must not be of type double"); |
| 11019 } | 11022 } |
| 11020 if (!key_value.IsInteger() && | 11023 if (!key_value.IsInteger() && |
| 11021 !key_value.IsString() && | 11024 !key_value.IsString() && |
| 11025 (key_value.clazz() != I->object_store()->symbol_class()) && |
| 11022 ImplementsEqualOperator(key_value)) { | 11026 ImplementsEqualOperator(key_value)) { |
| 11023 ReportError(key_pos, "key value must not implement operator =="); | 11027 ReportError(key_pos, "key value must not implement operator =="); |
| 11024 } | 11028 } |
| 11025 } | 11029 } |
| 11026 ExpectToken(Token::kCOLON); | 11030 ExpectToken(Token::kCOLON); |
| 11027 const intptr_t value_pos = TokenPos(); | 11031 const intptr_t value_pos = TokenPos(); |
| 11028 AstNode* value = ParseExpr(is_const, kConsumeCascades); | 11032 AstNode* value = ParseExpr(is_const, kConsumeCascades); |
| 11029 SetAllowFunctionLiterals(saved_mode); | 11033 SetAllowFunctionLiterals(saved_mode); |
| 11030 if (FLAG_enable_type_checks && | 11034 if (FLAG_enable_type_checks && |
| 11031 !is_const && | 11035 !is_const && |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11206 ConsumeToken(); | 11210 ConsumeToken(); |
| 11207 symbol = String::Concat(symbol, | 11211 symbol = String::Concat(symbol, |
| 11208 *ExpectIdentifier("identifier expected")); | 11212 *ExpectIdentifier("identifier expected")); |
| 11209 } | 11213 } |
| 11210 } else if (Token::CanBeOverloaded(CurrentToken())) { | 11214 } else if (Token::CanBeOverloaded(CurrentToken())) { |
| 11211 symbol = String::New(Token::Str(CurrentToken())); | 11215 symbol = String::New(Token::Str(CurrentToken())); |
| 11212 ConsumeToken(); | 11216 ConsumeToken(); |
| 11213 } else { | 11217 } else { |
| 11214 ReportError("illegal symbol literal"); | 11218 ReportError("illegal symbol literal"); |
| 11215 } | 11219 } |
| 11216 // Lookup class Symbol from internal library and call the | 11220 |
| 11217 // constructor to create a symbol instance. | 11221 // Call Symbol class constructor to create a symbol instance. |
| 11218 const Library& lib = Library::Handle(I, Library::InternalLibrary()); | 11222 const Class& symbol_class = Class::Handle(I->object_store()->symbol_class()); |
| 11219 const Class& symbol_class = Class::Handle(I, | |
| 11220 lib.LookupClass(Symbols::Symbol())); | |
| 11221 ASSERT(!symbol_class.IsNull()); | 11223 ASSERT(!symbol_class.IsNull()); |
| 11222 ArgumentListNode* constr_args = new(I) ArgumentListNode(symbol_pos); | 11224 ArgumentListNode* constr_args = new(I) ArgumentListNode(symbol_pos); |
| 11223 constr_args->Add(new(I) LiteralNode( | 11225 constr_args->Add(new(I) LiteralNode( |
| 11224 symbol_pos, String::ZoneHandle(I, Symbols::New(symbol)))); | 11226 symbol_pos, String::ZoneHandle(I, Symbols::New(symbol)))); |
| 11225 const Function& constr = Function::ZoneHandle(I, | 11227 const Function& constr = Function::ZoneHandle(I, |
| 11226 symbol_class.LookupConstructor(Symbols::SymbolCtor())); | 11228 symbol_class.LookupConstructor(Symbols::SymbolCtor())); |
| 11227 ASSERT(!constr.IsNull()); | 11229 ASSERT(!constr.IsNull()); |
| 11228 const Object& result = Object::Handle(I, | 11230 const Object& result = Object::Handle(I, |
| 11229 EvaluateConstConstructorCall(symbol_class, | 11231 EvaluateConstConstructorCall(symbol_class, |
| 11230 TypeArguments::Handle(I), | 11232 TypeArguments::Handle(I), |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12201 void Parser::SkipQualIdent() { | 12203 void Parser::SkipQualIdent() { |
| 12202 ASSERT(IsIdentifier()); | 12204 ASSERT(IsIdentifier()); |
| 12203 ConsumeToken(); | 12205 ConsumeToken(); |
| 12204 if (CurrentToken() == Token::kPERIOD) { | 12206 if (CurrentToken() == Token::kPERIOD) { |
| 12205 ConsumeToken(); // Consume the kPERIOD token. | 12207 ConsumeToken(); // Consume the kPERIOD token. |
| 12206 ExpectIdentifier("identifier expected after '.'"); | 12208 ExpectIdentifier("identifier expected after '.'"); |
| 12207 } | 12209 } |
| 12208 } | 12210 } |
| 12209 | 12211 |
| 12210 } // namespace dart | 12212 } // namespace dart |
| OLD | NEW |