| 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 if (initialized_field->raw() == field->raw()) { | 1672 if (initialized_field->raw() == field->raw()) { |
| 1673 ErrorMsg(init_pos, | 1673 ErrorMsg(init_pos, |
| 1674 "duplicate initialization for field %s", | 1674 "duplicate initialization for field %s", |
| 1675 String::Handle(field->name()).ToCString()); | 1675 String::Handle(field->name()).ToCString()); |
| 1676 } | 1676 } |
| 1677 } | 1677 } |
| 1678 initialized_fields->Add(field); | 1678 initialized_fields->Add(field); |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 | 1681 |
| 1682 void Parser::CheckNoInitializersInExternal() { |
| 1683 if (CurrentToken() == Token::kCOLON) { |
| 1684 ErrorMsg("initializer lists invalid for 'external' constructors"); |
| 1685 } |
| 1686 } |
| 1687 |
| 1688 |
| 1682 void Parser::ParseInitializers(const Class& cls, | 1689 void Parser::ParseInitializers(const Class& cls, |
| 1683 LocalVariable* receiver, | 1690 LocalVariable* receiver, |
| 1684 GrowableArray<Field*>* initialized_fields) { | 1691 GrowableArray<Field*>* initialized_fields) { |
| 1685 TRACE_PARSER("ParseInitializers"); | 1692 TRACE_PARSER("ParseInitializers"); |
| 1686 bool super_init_seen = false; | 1693 bool super_init_seen = false; |
| 1687 if (CurrentToken() == Token::kCOLON) { | 1694 if (CurrentToken() == Token::kCOLON) { |
| 1688 if ((LookaheadToken(1) == Token::kTHIS) && | 1695 if ((LookaheadToken(1) == Token::kTHIS) && |
| 1689 ((LookaheadToken(2) == Token::kLPAREN) || | 1696 ((LookaheadToken(2) == Token::kLPAREN) || |
| 1690 ((LookaheadToken(2) == Token::kPERIOD) && | 1697 ((LookaheadToken(2) == Token::kPERIOD) && |
| 1691 (LookaheadToken(4) == Token::kLPAREN)))) { | 1698 (LookaheadToken(4) == Token::kLPAREN)))) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 p->set_invisible(true); | 1914 p->set_invisible(true); |
| 1908 AstNode* value = new LoadLocalNode(param.name_pos, p); | 1915 AstNode* value = new LoadLocalNode(param.name_pos, p); |
| 1909 AstNode* initializer = new StoreInstanceFieldNode( | 1916 AstNode* initializer = new StoreInstanceFieldNode( |
| 1910 param.name_pos, instance, field, value); | 1917 param.name_pos, instance, field, value); |
| 1911 current_block_->statements->Add(initializer); | 1918 current_block_->statements->Add(initializer); |
| 1912 } | 1919 } |
| 1913 } | 1920 } |
| 1914 } | 1921 } |
| 1915 | 1922 |
| 1916 // Now parse the explicit initializer list or constructor redirection. | 1923 // Now parse the explicit initializer list or constructor redirection. |
| 1917 ParseInitializers(cls, receiver, &initialized_fields); | 1924 if (!func.is_external()) { |
| 1925 ParseInitializers(cls, receiver, &initialized_fields); |
| 1926 } else { |
| 1927 // 'external' constructors should have no initializers. |
| 1928 CheckNoInitializersInExternal(); |
| 1929 } |
| 1918 | 1930 |
| 1919 SequenceNode* init_statements = CloseBlock(); | 1931 SequenceNode* init_statements = CloseBlock(); |
| 1920 if (init_statements->length() > 0) { | 1932 if (init_statements->length() > 0) { |
| 1921 // Generate guard around the initializer code. | 1933 // Generate guard around the initializer code. |
| 1922 LocalVariable* phase_param = LookupPhaseParameter(); | 1934 LocalVariable* phase_param = LookupPhaseParameter(); |
| 1923 AstNode* phase_value = new LoadLocalNode(TokenPos(), phase_param); | 1935 AstNode* phase_value = new LoadLocalNode(TokenPos(), phase_param); |
| 1924 AstNode* phase_check = new BinaryOpNode( | 1936 AstNode* phase_check = new BinaryOpNode( |
| 1925 TokenPos(), Token::kBIT_AND, phase_value, | 1937 TokenPos(), Token::kBIT_AND, phase_value, |
| 1926 new LiteralNode(TokenPos(), | 1938 new LiteralNode(TokenPos(), |
| 1927 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); | 1939 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); |
| (...skipping 7154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9082 void Parser::SkipQualIdent() { | 9094 void Parser::SkipQualIdent() { |
| 9083 ASSERT(IsIdentifier()); | 9095 ASSERT(IsIdentifier()); |
| 9084 ConsumeToken(); | 9096 ConsumeToken(); |
| 9085 if (CurrentToken() == Token::kPERIOD) { | 9097 if (CurrentToken() == Token::kPERIOD) { |
| 9086 ConsumeToken(); // Consume the kPERIOD token. | 9098 ConsumeToken(); // Consume the kPERIOD token. |
| 9087 ExpectIdentifier("identifier expected after '.'"); | 9099 ExpectIdentifier("identifier expected after '.'"); |
| 9088 } | 9100 } |
| 9089 } | 9101 } |
| 9090 | 9102 |
| 9091 } // namespace dart | 9103 } // namespace dart |
| OLD | NEW |