OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 4831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4842 scope_->SetScopeName(name); | 4842 scope_->SetScopeName(name); |
4843 | 4843 |
4844 VariableProxy* proxy = NULL; | 4844 VariableProxy* proxy = NULL; |
4845 if (name != NULL) { | 4845 if (name != NULL) { |
4846 proxy = NewUnresolved(name, CONST); | 4846 proxy = NewUnresolved(name, CONST); |
4847 Declaration* declaration = | 4847 Declaration* declaration = |
4848 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4848 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
4849 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 4849 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
4850 } | 4850 } |
4851 | 4851 |
| 4852 // Parse optional type parameters. |
| 4853 typename TypeSystem::TypeParameters type_parameters = |
| 4854 this->NullTypeParameters(); |
| 4855 if (scope_->typed() && peek() == Token::LT) { // Braces required here. |
| 4856 type_parameters = ParseTypeParameters(CHECK_OK); |
| 4857 } |
| 4858 USE(type_parameters); // TODO(nikolaos): really use them! |
| 4859 |
| 4860 bool started_scope = false; |
| 4861 |
| 4862 // Parse optional extends clause. |
4852 Expression* extends = NULL; | 4863 Expression* extends = NULL; |
4853 if (Check(Token::EXTENDS)) { | 4864 if (Check(Token::EXTENDS)) { |
4854 block_scope->set_start_position(scanner()->location().end_pos); | 4865 block_scope->set_start_position(scanner()->location().end_pos); |
| 4866 started_scope = true; |
| 4867 // TODO(nikolaos): If this remains an expression, we have to explicitly |
| 4868 // allow type arguments. |
4855 ExpressionClassifier classifier(this); | 4869 ExpressionClassifier classifier(this); |
4856 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); | 4870 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); |
4857 RewriteNonPattern(&classifier, CHECK_OK); | 4871 RewriteNonPattern(&classifier, CHECK_OK); |
4858 } else { | 4872 } |
| 4873 |
| 4874 // Parse optional implements clause. |
| 4875 ZoneList<typesystem::Type*>* implements = nullptr; |
| 4876 if (scope_->typed() && CheckContextualKeyword(CStrVector("implements"))) { |
| 4877 implements = new (zone()) ZoneList<typesystem::Type*>(1, zone()); |
| 4878 if (!started_scope) { |
| 4879 block_scope->set_start_position(scanner()->location().end_pos); |
| 4880 started_scope = true; |
| 4881 } |
| 4882 do { |
| 4883 typesystem::Type* class_or_interface = ParseTypeReference(CHECK_OK); |
| 4884 implements->Add(class_or_interface, zone()); |
| 4885 } while (Check(Token::COMMA)); |
| 4886 } |
| 4887 USE(implements); // TODO(nikolaos): really use it! |
| 4888 |
| 4889 if (!started_scope) { |
4859 block_scope->set_start_position(scanner()->location().end_pos); | 4890 block_scope->set_start_position(scanner()->location().end_pos); |
4860 } | 4891 } |
4861 | 4892 |
4862 | |
4863 ClassLiteralChecker checker(this); | 4893 ClassLiteralChecker checker(this); |
4864 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | 4894 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
4865 FunctionLiteral* constructor = NULL; | 4895 FunctionLiteral* constructor = NULL; |
4866 bool has_seen_constructor = false; | 4896 bool has_seen_constructor = false; |
4867 | 4897 |
4868 Expect(Token::LBRACE, CHECK_OK); | 4898 Expect(Token::LBRACE, CHECK_OK); |
4869 | 4899 |
4870 const bool has_extends = extends != nullptr; | 4900 const bool has_extends = extends != nullptr; |
4871 while (peek() != Token::RBRACE) { | 4901 while (peek() != Token::RBRACE) { |
4872 if (Check(Token::SEMICOLON)) continue; | 4902 if (Check(Token::SEMICOLON)) continue; |
4873 FuncNameInferrer::State fni_state(fni_); | 4903 FuncNameInferrer::State fni_state(fni_); |
4874 const bool in_class = true; | 4904 const bool in_class = true; |
4875 const bool is_static = false; | 4905 const bool is_static = false; |
4876 bool is_computed_name = false; // Classes do not care about computed | 4906 bool is_computed_name = false; // Classes do not care about computed |
4877 // property names here. | 4907 // property names here. |
4878 ExpressionClassifier classifier(this); | 4908 ExpressionClassifier classifier(this); |
4879 const AstRawString* property_name = nullptr; | 4909 const AstRawString* property_name = nullptr; |
4880 ObjectLiteral::Property* property = ParsePropertyDefinition( | 4910 ObjectLiteral::Property* property = ParsePropertyDefinition( |
4881 &checker, in_class, has_extends, is_static, &is_computed_name, | 4911 &checker, in_class, has_extends, is_static, &is_computed_name, |
4882 &has_seen_constructor, &classifier, &property_name, CHECK_OK); | 4912 &has_seen_constructor, &classifier, &property_name, CHECK_OK); |
| 4913 // Ignore member variable declarations in typed mode. |
| 4914 if (property == nullptr) continue; |
4883 RewriteNonPattern(&classifier, CHECK_OK); | 4915 RewriteNonPattern(&classifier, CHECK_OK); |
4884 | 4916 |
4885 if (has_seen_constructor && constructor == NULL) { | 4917 if (has_seen_constructor && constructor == NULL) { |
4886 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4918 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4887 DCHECK_NOT_NULL(constructor); | 4919 DCHECK_NOT_NULL(constructor); |
4888 constructor->set_raw_name( | 4920 constructor->set_raw_name( |
4889 name != nullptr ? name : ast_value_factory()->empty_string()); | 4921 name != nullptr ? name : ast_value_factory()->empty_string()); |
4890 } else { | 4922 } else { |
4891 properties->Add(property, zone()); | 4923 properties->Add(property, zone()); |
4892 } | 4924 } |
(...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6990 try_block, target); | 7022 try_block, target); |
6991 final_loop = target; | 7023 final_loop = target; |
6992 } | 7024 } |
6993 | 7025 |
6994 return final_loop; | 7026 return final_loop; |
6995 } | 7027 } |
6996 | 7028 |
6997 | 7029 |
6998 } // namespace internal | 7030 } // namespace internal |
6999 } // namespace v8 | 7031 } // namespace v8 |
OLD | NEW |