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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 } | 1329 } |
1330 expr = GenerateStaticFieldLookup(field, ident_pos); | 1330 expr = GenerateStaticFieldLookup(field, ident_pos); |
1331 } | 1331 } |
1332 } | 1332 } |
1333 if (expr->EvalConstExpr() == NULL) { | 1333 if (expr->EvalConstExpr() == NULL) { |
1334 ReportError(expr_pos, "expression must be a compile-time constant"); | 1334 ReportError(expr_pos, "expression must be a compile-time constant"); |
1335 } | 1335 } |
1336 const Instance& val = EvaluateConstExpr(expr_pos, expr); | 1336 const Instance& val = EvaluateConstExpr(expr_pos, expr); |
1337 meta_values.Add(val, Heap::kOld); | 1337 meta_values.Add(val, Heap::kOld); |
1338 } | 1338 } |
1339 return Array::MakeFixedLength(meta_values); | 1339 return Array::MakeArray(meta_values); |
1340 } | 1340 } |
1341 | 1341 |
1342 | 1342 |
1343 SequenceNode* Parser::ParseStaticInitializer() { | 1343 SequenceNode* Parser::ParseStaticInitializer() { |
1344 ExpectIdentifier("field name expected"); | 1344 ExpectIdentifier("field name expected"); |
1345 CheckToken(Token::kASSIGN, "field initialier expected"); | 1345 CheckToken(Token::kASSIGN, "field initialier expected"); |
1346 ConsumeToken(); | 1346 ConsumeToken(); |
1347 OpenFunctionBlock(parsed_function()->function()); | 1347 OpenFunctionBlock(parsed_function()->function()); |
1348 TokenPosition expr_pos = TokenPos(); | 1348 TokenPosition expr_pos = TokenPos(); |
1349 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); | 1349 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); |
(...skipping 3642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4992 ParseClassMemberDefinition(&members, metadata_pos); | 4992 ParseClassMemberDefinition(&members, metadata_pos); |
4993 } | 4993 } |
4994 ExpectToken(Token::kRBRACE); | 4994 ExpectToken(Token::kRBRACE); |
4995 | 4995 |
4996 if (cls.LookupTypeParameter(class_name) != TypeParameter::null()) { | 4996 if (cls.LookupTypeParameter(class_name) != TypeParameter::null()) { |
4997 ReportError(class_pos, "class name conflicts with type parameter '%s'", | 4997 ReportError(class_pos, "class name conflicts with type parameter '%s'", |
4998 class_name.ToCString()); | 4998 class_name.ToCString()); |
4999 } | 4999 } |
5000 CheckConstructors(&members); | 5000 CheckConstructors(&members); |
5001 | 5001 |
5002 // Need to compute this here since MakeFixedLength() will clear the | 5002 // Need to compute this here since MakeArray() will clear the |
5003 // functions array in members. | 5003 // functions array in members. |
5004 const bool need_implicit_constructor = | 5004 const bool need_implicit_constructor = |
5005 !members.has_constructor() && !cls.is_patch(); | 5005 !members.has_constructor() && !cls.is_patch(); |
5006 | 5006 |
5007 cls.AddFields(members.fields()); | 5007 cls.AddFields(members.fields()); |
5008 | 5008 |
5009 // Creating a new array for functions marks the class as parsed. | 5009 // Creating a new array for functions marks the class as parsed. |
5010 Array& array = Array::Handle(Z, members.MakeFunctionsArray()); | 5010 Array& array = Array::Handle(Z, members.MakeFunctionsArray()); |
5011 cls.SetFunctions(array); | 5011 cls.SetFunctions(array); |
5012 | 5012 |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5793 ConsumeToken(); | 5793 ConsumeToken(); |
5794 TokenPosition interface_pos = TokenPos(); | 5794 TokenPosition interface_pos = TokenPos(); |
5795 interface = ParseType(ClassFinalizer::kResolveTypeParameters); | 5795 interface = ParseType(ClassFinalizer::kResolveTypeParameters); |
5796 if (interface.IsTypeParameter()) { | 5796 if (interface.IsTypeParameter()) { |
5797 ReportError(interface_pos, | 5797 ReportError(interface_pos, |
5798 "type parameter '%s' may not be used in interface list", | 5798 "type parameter '%s' may not be used in interface list", |
5799 String::Handle(Z, interface.UserVisibleName()).ToCString()); | 5799 String::Handle(Z, interface.UserVisibleName()).ToCString()); |
5800 } | 5800 } |
5801 all_interfaces.Add(interface, Heap::kOld); | 5801 all_interfaces.Add(interface, Heap::kOld); |
5802 } while (CurrentToken() == Token::kCOMMA); | 5802 } while (CurrentToken() == Token::kCOMMA); |
5803 cls_interfaces = Array::MakeFixedLength(all_interfaces); | 5803 cls_interfaces = Array::MakeArray(all_interfaces); |
5804 cls.set_interfaces(cls_interfaces); | 5804 cls.set_interfaces(cls_interfaces); |
5805 } | 5805 } |
5806 | 5806 |
5807 | 5807 |
5808 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { | 5808 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { |
5809 TRACE_PARSER("ParseMixins"); | 5809 TRACE_PARSER("ParseMixins"); |
5810 ASSERT(CurrentToken() == Token::kWITH); | 5810 ASSERT(CurrentToken() == Token::kWITH); |
5811 const GrowableObjectArray& mixin_types = | 5811 const GrowableObjectArray& mixin_types = |
5812 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 5812 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
5813 AbstractType& mixin_type = AbstractType::Handle(Z); | 5813 AbstractType& mixin_type = AbstractType::Handle(Z); |
5814 do { | 5814 do { |
5815 ConsumeToken(); | 5815 ConsumeToken(); |
5816 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); | 5816 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); |
5817 if (mixin_type.IsDynamicType()) { | 5817 if (mixin_type.IsDynamicType()) { |
5818 // The string 'dynamic' is not resolved yet at this point, but a malformed | 5818 // The string 'dynamic' is not resolved yet at this point, but a malformed |
5819 // type mapped to dynamic can be encountered here. | 5819 // type mapped to dynamic can be encountered here. |
5820 ReportError(mixin_type.token_pos(), "illegal mixin of a malformed type"); | 5820 ReportError(mixin_type.token_pos(), "illegal mixin of a malformed type"); |
5821 } | 5821 } |
5822 if (mixin_type.IsTypeParameter()) { | 5822 if (mixin_type.IsTypeParameter()) { |
5823 ReportError(mixin_type.token_pos(), | 5823 ReportError(mixin_type.token_pos(), |
5824 "mixin type '%s' may not be a type parameter", | 5824 "mixin type '%s' may not be a type parameter", |
5825 String::Handle(Z, mixin_type.UserVisibleName()).ToCString()); | 5825 String::Handle(Z, mixin_type.UserVisibleName()).ToCString()); |
5826 } | 5826 } |
5827 mixin_types.Add(mixin_type, Heap::kOld); | 5827 mixin_types.Add(mixin_type, Heap::kOld); |
5828 } while (CurrentToken() == Token::kCOMMA); | 5828 } while (CurrentToken() == Token::kCOMMA); |
5829 return MixinAppType::New( | 5829 return MixinAppType::New(super_type, |
5830 super_type, Array::Handle(Z, Array::MakeFixedLength(mixin_types))); | 5830 Array::Handle(Z, Array::MakeArray(mixin_types))); |
5831 } | 5831 } |
5832 | 5832 |
5833 | 5833 |
5834 void Parser::ParseTopLevelVariable(TopLevel* top_level, | 5834 void Parser::ParseTopLevelVariable(TopLevel* top_level, |
5835 const Object& owner, | 5835 const Object& owner, |
5836 TokenPosition metadata_pos) { | 5836 TokenPosition metadata_pos) { |
5837 TRACE_PARSER("ParseTopLevelVariable"); | 5837 TRACE_PARSER("ParseTopLevelVariable"); |
5838 const bool is_const = (CurrentToken() == Token::kCONST); | 5838 const bool is_const = (CurrentToken() == Token::kCONST); |
5839 // Const fields are implicitly final. | 5839 // Const fields are implicitly final. |
5840 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); | 5840 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6349 CheckToken(Token::kSTRING, "library url expected"); | 6349 CheckToken(Token::kSTRING, "library url expected"); |
6350 AstNode* conditional_url_literal = ParseStringLiteral(false); | 6350 AstNode* conditional_url_literal = ParseStringLiteral(false); |
6351 | 6351 |
6352 // If there was already a condition that triggered, don't try to match | 6352 // If there was already a condition that triggered, don't try to match |
6353 // again. | 6353 // again. |
6354 if (condition_triggered) { | 6354 if (condition_triggered) { |
6355 continue; | 6355 continue; |
6356 } | 6356 } |
6357 // Check if this conditional line overrides the default import. | 6357 // Check if this conditional line overrides the default import. |
6358 const String& key = String::Handle(String::ConcatAll( | 6358 const String& key = String::Handle(String::ConcatAll( |
6359 Array::Handle(Array::MakeFixedLength(pieces)), allocation_space_)); | 6359 Array::Handle(Array::MakeArray(pieces)), allocation_space_)); |
6360 const String& value = | 6360 const String& value = |
6361 (valueNode == NULL) | 6361 (valueNode == NULL) |
6362 ? Symbols::True() | 6362 ? Symbols::True() |
6363 : String::Cast(valueNode->AsLiteralNode()->literal()); | 6363 : String::Cast(valueNode->AsLiteralNode()->literal()); |
6364 // Call the embedder to supply us with the environment. | 6364 // Call the embedder to supply us with the environment. |
6365 const String& env_value = | 6365 const String& env_value = |
6366 String::Handle(Api::GetEnvironmentValue(T, key)); | 6366 String::Handle(Api::GetEnvironmentValue(T, key)); |
6367 if (!env_value.IsNull() && env_value.Equals(value)) { | 6367 if (!env_value.IsNull() && env_value.Equals(value)) { |
6368 condition_triggered = true; | 6368 condition_triggered = true; |
6369 url_literal = conditional_url_literal; | 6369 url_literal = conditional_url_literal; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6408 ConsumeToken(); | 6408 ConsumeToken(); |
6409 ParseIdentList(&show_list); | 6409 ParseIdentList(&show_list); |
6410 } else if (IsSymbol(Symbols::Hide())) { | 6410 } else if (IsSymbol(Symbols::Hide())) { |
6411 ConsumeToken(); | 6411 ConsumeToken(); |
6412 ParseIdentList(&hide_list); | 6412 ParseIdentList(&hide_list); |
6413 } else { | 6413 } else { |
6414 break; | 6414 break; |
6415 } | 6415 } |
6416 } | 6416 } |
6417 if (show_list.Length() > 0) { | 6417 if (show_list.Length() > 0) { |
6418 show_names = Array::MakeFixedLength(show_list); | 6418 show_names = Array::MakeArray(show_list); |
6419 } | 6419 } |
6420 if (hide_list.Length() > 0) { | 6420 if (hide_list.Length() > 0) { |
6421 hide_names = Array::MakeFixedLength(hide_list); | 6421 hide_names = Array::MakeArray(hide_list); |
6422 } | 6422 } |
6423 } | 6423 } |
6424 ExpectSemicolon(); | 6424 ExpectSemicolon(); |
6425 | 6425 |
6426 // Canonicalize library URL. | 6426 // Canonicalize library URL. |
6427 const String& canon_url = String::CheckedHandle( | 6427 const String& canon_url = String::CheckedHandle( |
6428 CallLibraryTagHandler(Dart_kCanonicalizeUrl, import_pos, url)); | 6428 CallLibraryTagHandler(Dart_kCanonicalizeUrl, import_pos, url)); |
6429 | 6429 |
6430 // Create a new library if it does not exist yet. | 6430 // Create a new library if it does not exist yet. |
6431 Library& library = Library::Handle(Z, Library::LookupLibrary(T, canon_url)); | 6431 Library& library = Library::Handle(Z, Library::LookupLibrary(T, canon_url)); |
(...skipping 4024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10456 tokens_iterator_.SetCurrentPosition(finally_pos); | 10456 tokens_iterator_.SetCurrentPosition(finally_pos); |
10457 rethrow_clause = EnsureFinallyClause( | 10457 rethrow_clause = EnsureFinallyClause( |
10458 parse, is_async, exception_var, stack_trace_var, | 10458 parse, is_async, exception_var, stack_trace_var, |
10459 is_async ? saved_exception_var : exception_var, | 10459 is_async ? saved_exception_var : exception_var, |
10460 is_async ? saved_stack_trace_var : stack_trace_var); | 10460 is_async ? saved_stack_trace_var : stack_trace_var); |
10461 } | 10461 } |
10462 } | 10462 } |
10463 | 10463 |
10464 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( | 10464 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( |
10465 handler_pos, catch_handler_list, | 10465 handler_pos, catch_handler_list, |
10466 Array::ZoneHandle(Z, Array::MakeFixedLength(handler_types)), context_var, | 10466 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), context_var, |
10467 exception_var, stack_trace_var, | 10467 exception_var, stack_trace_var, |
10468 is_async ? saved_exception_var : exception_var, | 10468 is_async ? saved_exception_var : exception_var, |
10469 is_async ? saved_stack_trace_var : stack_trace_var, | 10469 is_async ? saved_stack_trace_var : stack_trace_var, |
10470 (finally_clause != NULL) ? AllocateTryIndex() | 10470 (finally_clause != NULL) ? AllocateTryIndex() |
10471 : CatchClauseNode::kInvalidTryIndex, | 10471 : CatchClauseNode::kInvalidTryIndex, |
10472 needs_stack_trace); | 10472 needs_stack_trace); |
10473 | 10473 |
10474 // Now create the try/catch ast node and return it. If there is a label | 10474 // Now create the try/catch ast node and return it. If there is a label |
10475 // on the try/catch, close the block that's embedding the try statement | 10475 // on the try/catch, close the block that's embedding the try statement |
10476 // and attach the label to it. | 10476 // and attach the label to it. |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11817 ReportError("named argument expected"); | 11817 ReportError("named argument expected"); |
11818 } | 11818 } |
11819 arguments->Add(ParseExpr(require_const, kConsumeCascades)); | 11819 arguments->Add(ParseExpr(require_const, kConsumeCascades)); |
11820 } while (CurrentToken() == Token::kCOMMA); | 11820 } while (CurrentToken() == Token::kCOMMA); |
11821 } else { | 11821 } else { |
11822 ConsumeToken(); | 11822 ConsumeToken(); |
11823 } | 11823 } |
11824 ExpectToken(Token::kRPAREN); | 11824 ExpectToken(Token::kRPAREN); |
11825 SetAllowFunctionLiterals(saved_mode); | 11825 SetAllowFunctionLiterals(saved_mode); |
11826 if (named_argument_seen) { | 11826 if (named_argument_seen) { |
11827 arguments->set_names(Array::Handle(Z, Array::MakeFixedLength(names))); | 11827 arguments->set_names(Array::Handle(Z, Array::MakeArray(names))); |
11828 } | 11828 } |
11829 return arguments; | 11829 return arguments; |
11830 } | 11830 } |
11831 | 11831 |
11832 | 11832 |
11833 AstNode* Parser::ParseStaticCall(const Class& cls, | 11833 AstNode* Parser::ParseStaticCall(const Class& cls, |
11834 const String& func_name, | 11834 const String& func_name, |
11835 TokenPosition ident_pos, | 11835 TokenPosition ident_pos, |
11836 const TypeArguments& func_type_args, | 11836 const TypeArguments& func_type_args, |
11837 const LibraryPrefix* prefix) { | 11837 const LibraryPrefix* prefix) { |
(...skipping 3583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15421 TokenPosition* start, | 15421 TokenPosition* start, |
15422 TokenPosition* end) { | 15422 TokenPosition* end) { |
15423 UNREACHABLE(); | 15423 UNREACHABLE(); |
15424 return false; | 15424 return false; |
15425 } | 15425 } |
15426 | 15426 |
15427 | 15427 |
15428 } // namespace dart | 15428 } // namespace dart |
15429 | 15429 |
15430 #endif // DART_PRECOMPILED_RUNTIME | 15430 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |