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 |
| 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 2573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2584 ASSERT(IsIdentifier()); | 2584 ASSERT(IsIdentifier()); |
| 2585 ConsumeToken(); | 2585 ConsumeToken(); |
| 2586 ExpectToken(Token::kASSIGN); | 2586 ExpectToken(Token::kASSIGN); |
| 2587 AstNode* init_expr = NULL; | 2587 AstNode* init_expr = NULL; |
| 2588 intptr_t expr_pos = TokenPos(); | 2588 intptr_t expr_pos = TokenPos(); |
| 2589 if (field.is_const()) { | 2589 if (field.is_const()) { |
| 2590 init_expr = ParseConstExpr(); | 2590 init_expr = ParseConstExpr(); |
| 2591 } else { | 2591 } else { |
| 2592 init_expr = ParseExpr(kAllowConst, kConsumeCascades); | 2592 init_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 2593 if (init_expr->EvalConstExpr() != NULL) { | 2593 if (init_expr->EvalConstExpr() != NULL) { |
| 2594 init_expr = | 2594 Instance& expr_value = Instance::ZoneHandle(Z); |
| 2595 new LiteralNode(field.token_pos(), | 2595 if (!GetCachedConstant(expr_pos, &expr_value)) { |
| 2596 EvaluateConstExpr(expr_pos, init_expr)); | 2596 expr_value = EvaluateConstExpr(expr_pos, init_expr).raw(); |
| 2597 CacheConstantValue(expr_pos, expr_value); | |
| 2598 } | |
| 2599 init_expr = new(Z) LiteralNode(field.token_pos(), expr_value); | |
| 2597 } | 2600 } |
| 2598 } | 2601 } |
| 2599 set_current_class(saved_class); | 2602 set_current_class(saved_class); |
| 2600 set_library(saved_library); | 2603 set_library(saved_library); |
| 2601 SetScript(saved_script, saved_token_pos); | 2604 SetScript(saved_script, saved_token_pos); |
| 2602 return init_expr; | 2605 return init_expr; |
| 2603 } | 2606 } |
| 2604 | 2607 |
| 2605 | 2608 |
| 2606 void Parser::ParseInitializedInstanceFields(const Class& cls, | 2609 void Parser::ParseInitializedInstanceFields(const Class& cls, |
| 2607 LocalVariable* receiver, | 2610 LocalVariable* receiver, |
| 2608 GrowableArray<Field*>* initialized_fields) { | 2611 GrowableArray<Field*>* initialized_fields) { |
|
srdjan
2015/09/03 23:07:02
Formatting looks weird here
| |
| 2609 TRACE_PARSER("ParseInitializedInstanceFields"); | 2612 TRACE_PARSER("ParseInitializedInstanceFields"); |
| 2610 const Array& fields = Array::Handle(Z, cls.fields()); | 2613 const Array& fields = Array::Handle(Z, cls.fields()); |
| 2611 Field& f = Field::Handle(Z); | 2614 Field& f = Field::Handle(Z); |
| 2612 const intptr_t saved_pos = TokenPos(); | 2615 const intptr_t saved_pos = TokenPos(); |
| 2613 for (int i = 0; i < fields.Length(); i++) { | 2616 for (int i = 0; i < fields.Length(); i++) { |
| 2614 f ^= fields.At(i); | 2617 f ^= fields.At(i); |
| 2615 if (!f.is_static() && f.has_initializer()) { | 2618 if (!f.is_static() && f.has_initializer()) { |
| 2616 Field& field = Field::ZoneHandle(Z); | 2619 Field& field = Field::ZoneHandle(Z); |
| 2617 field ^= fields.At(i); | 2620 field ^= fields.At(i); |
| 2618 if (field.is_final()) { | 2621 if (field.is_final()) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2630 ConsumeToken(); | 2633 ConsumeToken(); |
| 2631 ExpectToken(Token::kASSIGN); | 2634 ExpectToken(Token::kASSIGN); |
| 2632 if (current_class().is_const()) { | 2635 if (current_class().is_const()) { |
| 2633 // If the class has a const contructor, the initializer | 2636 // If the class has a const contructor, the initializer |
| 2634 // expression must be a compile-time constant. | 2637 // expression must be a compile-time constant. |
| 2635 init_expr = ParseConstExpr(); | 2638 init_expr = ParseConstExpr(); |
| 2636 } else { | 2639 } else { |
| 2637 intptr_t expr_pos = TokenPos(); | 2640 intptr_t expr_pos = TokenPos(); |
| 2638 init_expr = ParseExpr(kAllowConst, kConsumeCascades); | 2641 init_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 2639 if (init_expr->EvalConstExpr() != NULL) { | 2642 if (init_expr->EvalConstExpr() != NULL) { |
| 2640 init_expr = new LiteralNode(field.token_pos(), | 2643 Instance& expr_value = Instance::ZoneHandle(Z); |
| 2641 EvaluateConstExpr(expr_pos, init_expr)); | 2644 if (!GetCachedConstant(expr_pos, &expr_value)) { |
| 2645 expr_value = EvaluateConstExpr(expr_pos, init_expr).raw(); | |
| 2646 CacheConstantValue(expr_pos, expr_value); | |
| 2647 } | |
| 2648 init_expr = new(Z) LiteralNode(field.token_pos(), expr_value); | |
| 2642 } | 2649 } |
| 2643 } | 2650 } |
| 2644 } | 2651 } |
| 2645 ASSERT(init_expr != NULL); | 2652 ASSERT(init_expr != NULL); |
| 2646 AstNode* instance = new LoadLocalNode(field.token_pos(), receiver); | 2653 AstNode* instance = new LoadLocalNode(field.token_pos(), receiver); |
| 2647 EnsureExpressionTemp(); | 2654 EnsureExpressionTemp(); |
| 2648 AstNode* field_init = | 2655 AstNode* field_init = |
| 2649 new StoreInstanceFieldNode(field.token_pos(), | 2656 new StoreInstanceFieldNode(field.token_pos(), |
| 2650 instance, | 2657 instance, |
| 2651 field, | 2658 field, |
| (...skipping 10381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13033 symbol = String::Concat(symbol, | 13040 symbol = String::Concat(symbol, |
| 13034 *ExpectIdentifier("identifier expected")); | 13041 *ExpectIdentifier("identifier expected")); |
| 13035 } | 13042 } |
| 13036 } else if (Token::CanBeOverloaded(CurrentToken())) { | 13043 } else if (Token::CanBeOverloaded(CurrentToken())) { |
| 13037 symbol = String::New(Token::Str(CurrentToken())); | 13044 symbol = String::New(Token::Str(CurrentToken())); |
| 13038 ConsumeToken(); | 13045 ConsumeToken(); |
| 13039 } else { | 13046 } else { |
| 13040 ReportError("illegal symbol literal"); | 13047 ReportError("illegal symbol literal"); |
| 13041 } | 13048 } |
| 13042 | 13049 |
| 13050 Instance& symbol_instance = Instance::ZoneHandle(Z); | |
| 13051 if (GetCachedConstant(symbol_pos, &symbol_instance)) { | |
| 13052 return new(Z) LiteralNode(symbol_pos, symbol_instance); | |
| 13053 } | |
| 13054 | |
| 13043 // Call Symbol class constructor to create a symbol instance. | 13055 // Call Symbol class constructor to create a symbol instance. |
| 13044 const Class& symbol_class = Class::Handle(I->object_store()->symbol_class()); | 13056 const Class& symbol_class = Class::Handle(I->object_store()->symbol_class()); |
| 13045 ASSERT(!symbol_class.IsNull()); | 13057 ASSERT(!symbol_class.IsNull()); |
| 13046 ArgumentListNode* constr_args = new(Z) ArgumentListNode(symbol_pos); | 13058 ArgumentListNode* constr_args = new(Z) ArgumentListNode(symbol_pos); |
| 13047 constr_args->Add(new(Z) LiteralNode( | 13059 constr_args->Add(new(Z) LiteralNode( |
| 13048 symbol_pos, String::ZoneHandle(Z, Symbols::New(symbol)))); | 13060 symbol_pos, String::ZoneHandle(Z, Symbols::New(symbol)))); |
| 13049 const Function& constr = Function::ZoneHandle(Z, | 13061 const Function& constr = Function::ZoneHandle(Z, |
| 13050 symbol_class.LookupConstructor(Symbols::SymbolCtor())); | 13062 symbol_class.LookupConstructor(Symbols::SymbolCtor())); |
| 13051 ASSERT(!constr.IsNull()); | 13063 ASSERT(!constr.IsNull()); |
| 13052 const Object& result = Object::Handle(Z, | 13064 const Object& result = Object::Handle(Z, |
| 13053 EvaluateConstConstructorCall(symbol_class, | 13065 EvaluateConstConstructorCall(symbol_class, |
| 13054 TypeArguments::Handle(Z), | 13066 TypeArguments::Handle(Z), |
| 13055 constr, | 13067 constr, |
| 13056 constr_args)); | 13068 constr_args)); |
| 13057 if (result.IsUnhandledException()) { | 13069 if (result.IsUnhandledException()) { |
| 13058 ReportErrors(Error::Cast(result), | 13070 ReportErrors(Error::Cast(result), |
| 13059 script_, symbol_pos, | 13071 script_, symbol_pos, |
| 13060 "error executing const Symbol constructor"); | 13072 "error executing const Symbol constructor"); |
| 13061 } | 13073 } |
| 13062 const Instance& instance = Instance::Cast(result); | 13074 symbol_instance ^= result.raw(); |
| 13063 return new(Z) LiteralNode(symbol_pos, | 13075 CacheConstantValue(symbol_pos, symbol_instance); |
| 13064 Instance::ZoneHandle(Z, instance.raw())); | 13076 return new(Z) LiteralNode(symbol_pos, symbol_instance); |
| 13065 } | 13077 } |
| 13066 | 13078 |
| 13067 | 13079 |
| 13068 RawFunction* Parser::BuildConstructorClosureFunction(const Function& ctr, | 13080 RawFunction* Parser::BuildConstructorClosureFunction(const Function& ctr, |
| 13069 intptr_t token_pos) { | 13081 intptr_t token_pos) { |
| 13070 ASSERT(ctr.kind() == RawFunction::kConstructor); | 13082 ASSERT(ctr.kind() == RawFunction::kConstructor); |
| 13071 Function& closure = Function::Handle(Z); | 13083 Function& closure = Function::Handle(Z); |
| 13072 closure = current_class().LookupClosureFunction(token_pos); | 13084 closure = current_class().LookupClosureFunction(token_pos); |
| 13073 if (!closure.IsNull()) { | 13085 if (!closure.IsNull()) { |
| 13074 ASSERT(closure.IsConstructorClosureFunction()); | 13086 ASSERT(closure.IsConstructorClosureFunction()); |
| (...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14270 void Parser::SkipQualIdent() { | 14282 void Parser::SkipQualIdent() { |
| 14271 ASSERT(IsIdentifier()); | 14283 ASSERT(IsIdentifier()); |
| 14272 ConsumeToken(); | 14284 ConsumeToken(); |
| 14273 if (CurrentToken() == Token::kPERIOD) { | 14285 if (CurrentToken() == Token::kPERIOD) { |
| 14274 ConsumeToken(); // Consume the kPERIOD token. | 14286 ConsumeToken(); // Consume the kPERIOD token. |
| 14275 ExpectIdentifier("identifier expected after '.'"); | 14287 ExpectIdentifier("identifier expected after '.'"); |
| 14276 } | 14288 } |
| 14277 } | 14289 } |
| 14278 | 14290 |
| 14279 } // namespace dart | 14291 } // namespace dart |
| OLD | NEW |