Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: runtime/vm/parser.cc

Issue 1566553003: More 0 => Scanner::kNoSourcePos. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8 #ifndef DART_PRECOMPILED
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 has_final = false; 616 has_final = false;
617 has_const = false; 617 has_const = false;
618 has_static = false; 618 has_static = false;
619 has_var = false; 619 has_var = false;
620 has_factory = false; 620 has_factory = false;
621 has_operator = false; 621 has_operator = false;
622 has_native = false; 622 has_native = false;
623 metadata_pos = Scanner::kNoSourcePos; 623 metadata_pos = Scanner::kNoSourcePos;
624 operator_token = Token::kILLEGAL; 624 operator_token = Token::kILLEGAL;
625 type = NULL; 625 type = NULL;
626 name_pos = 0; 626 name_pos = Scanner::kNoSourcePos;
627 name = NULL; 627 name = NULL;
628 redirect_name = NULL; 628 redirect_name = NULL;
629 dict_name = NULL; 629 dict_name = NULL;
630 params.Clear(); 630 params.Clear();
631 kind = RawFunction::kRegularFunction; 631 kind = RawFunction::kRegularFunction;
632 field_ = NULL; 632 field_ = NULL;
633 } 633 }
634 634
635 bool IsConstructor() const { 635 bool IsConstructor() const {
636 return (kind == RawFunction::kConstructor) && !has_static; 636 return (kind == RawFunction::kConstructor) && !has_static;
(...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after
3476 func.set_is_debuggable(false); 3476 func.set_is_debuggable(false);
3477 generated_body_closure = OpenAsyncGeneratorFunction(func.token_pos()); 3477 generated_body_closure = OpenAsyncGeneratorFunction(func.token_pos());
3478 } else if (func.IsAsyncGenClosure()) { 3478 } else if (func.IsAsyncGenClosure()) {
3479 // The closure containing the body of an async* function is debuggable. 3479 // The closure containing the body of an async* function is debuggable.
3480 ASSERT(func.is_debuggable()); 3480 ASSERT(func.is_debuggable());
3481 OpenAsyncGeneratorClosure(); 3481 OpenAsyncGeneratorClosure();
3482 } 3482 }
3483 3483
3484 BoolScope allow_await(&this->await_is_keyword_, 3484 BoolScope allow_await(&this->await_is_keyword_,
3485 func.IsAsyncOrGenerator() || func.is_generated_body()); 3485 func.IsAsyncOrGenerator() || func.is_generated_body());
3486 intptr_t end_token_pos = 0; 3486 intptr_t end_token_pos = Scanner::kNoSourcePos;
3487 if (CurrentToken() == Token::kLBRACE) { 3487 if (CurrentToken() == Token::kLBRACE) {
3488 ConsumeToken(); 3488 ConsumeToken();
3489 if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) { 3489 if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) {
3490 const Class& owner = Class::Handle(Z, func.Owner()); 3490 const Class& owner = Class::Handle(Z, func.Owner());
3491 if (!owner.IsObjectClass()) { 3491 if (!owner.IsObjectClass()) {
3492 AddEqualityNullCheck(); 3492 AddEqualityNullCheck();
3493 } 3493 }
3494 } 3494 }
3495 ParseStatementSequence(); 3495 ParseStatementSequence();
3496 end_token_pos = TokenPos(); 3496 end_token_pos = TokenPos();
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
3997 method->has_native, 3997 method->has_native,
3998 current_class(), 3998 current_class(),
3999 method->decl_begin_pos)); 3999 method->decl_begin_pos));
4000 func.set_result_type(*method->type); 4000 func.set_result_type(*method->type);
4001 func.set_end_token_pos(method_end_pos); 4001 func.set_end_token_pos(method_end_pos);
4002 func.set_is_redirecting(is_redirecting); 4002 func.set_is_redirecting(is_redirecting);
4003 func.set_modifier(async_modifier); 4003 func.set_modifier(async_modifier);
4004 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { 4004 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) {
4005 func.set_is_reflectable(false); 4005 func.set_is_reflectable(false);
4006 } 4006 }
4007 if (FLAG_enable_mirrors && (method->metadata_pos > 0)) { 4007 if (FLAG_enable_mirrors && (method->metadata_pos != Scanner::kNoSourcePos)) {
hausner 2016/01/06 18:42:35 I would be ok with >= 0. In my mind, any position
rmacnak 2016/01/06 19:08:08 Okay, it's stricter and shorter so I'll use that.
4008 library_.AddFunctionMetadata(func, method->metadata_pos); 4008 library_.AddFunctionMetadata(func, method->metadata_pos);
4009 } 4009 }
4010 if (method->has_native) { 4010 if (method->has_native) {
4011 func.set_native_name(*native_name); 4011 func.set_native_name(*native_name);
4012 } 4012 }
4013 4013
4014 // If this method is a redirecting factory, set the redirection information. 4014 // If this method is a redirecting factory, set the redirection information.
4015 if (!redirection_type.IsNull()) { 4015 if (!redirection_type.IsNull()) {
4016 ASSERT(func.IsFactory()); 4016 ASSERT(func.IsFactory());
4017 func.SetRedirectionType(redirection_type); 4017 func.SetRedirectionType(redirection_type);
(...skipping 10 matching lines...) Expand all
4028 4028
4029 4029
4030 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { 4030 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) {
4031 TRACE_PARSER("ParseFieldDefinition"); 4031 TRACE_PARSER("ParseFieldDefinition");
4032 // The parser has read the first field name and is now at the token 4032 // The parser has read the first field name and is now at the token
4033 // after the field name. 4033 // after the field name.
4034 ASSERT(CurrentToken() == Token::kSEMICOLON || 4034 ASSERT(CurrentToken() == Token::kSEMICOLON ||
4035 CurrentToken() == Token::kCOMMA || 4035 CurrentToken() == Token::kCOMMA ||
4036 CurrentToken() == Token::kASSIGN); 4036 CurrentToken() == Token::kASSIGN);
4037 ASSERT(field->type != NULL); 4037 ASSERT(field->type != NULL);
4038 ASSERT(field->name_pos > 0); 4038 ASSERT(field->name_pos != Scanner::kNoSourcePos);
4039 ASSERT(current_member_ == field); 4039 ASSERT(current_member_ == field);
4040 // All const fields are also final. 4040 // All const fields are also final.
4041 ASSERT(!field->has_const || field->has_final); 4041 ASSERT(!field->has_const || field->has_final);
4042 4042
4043 if (field->has_abstract) { 4043 if (field->has_abstract) {
4044 ReportError("keyword 'abstract' not allowed in field declaration"); 4044 ReportError("keyword 'abstract' not allowed in field declaration");
4045 } 4045 }
4046 if (field->has_external) { 4046 if (field->has_external) {
4047 ReportError("keyword 'external' not allowed in field declaration"); 4047 ReportError("keyword 'external' not allowed in field declaration");
4048 } 4048 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4097 field->has_static, 4097 field->has_static,
4098 field->has_final, 4098 field->has_final,
4099 field->has_const, 4099 field->has_const,
4100 is_reflectable, 4100 is_reflectable,
4101 current_class(), 4101 current_class(),
4102 *field->type, 4102 *field->type,
4103 field->name_pos); 4103 field->name_pos);
4104 class_field.set_has_initializer(has_initializer); 4104 class_field.set_has_initializer(has_initializer);
4105 members->AddField(class_field); 4105 members->AddField(class_field);
4106 field->field_ = &class_field; 4106 field->field_ = &class_field;
4107 if (FLAG_enable_mirrors && (field->metadata_pos >= 0)) { 4107 if (FLAG_enable_mirrors && (field->metadata_pos != Scanner::kNoSourcePos)) {
4108 library_.AddFieldMetadata(class_field, field->metadata_pos); 4108 library_.AddFieldMetadata(class_field, field->metadata_pos);
4109 } 4109 }
4110 4110
4111 // Start tracking types for fields with simple initializers in their 4111 // Start tracking types for fields with simple initializers in their
4112 // definition. This avoids some of the overhead to track this at runtime 4112 // definition. This avoids some of the overhead to track this at runtime
4113 // and rules out many fields from being unnecessary unboxing candidates. 4113 // and rules out many fields from being unnecessary unboxing candidates.
4114 if (!field->has_static && has_initializer && has_simple_literal) { 4114 if (!field->has_static && has_initializer && has_simple_literal) {
4115 class_field.RecordStore(init_value); 4115 class_field.RecordStore(init_value);
4116 if (!init_value.IsNull() && init_value.IsDouble()) { 4116 if (!init_value.IsNull() && init_value.IsDouble()) {
4117 class_field.set_is_double_initialized(true); 4117 class_field.set_is_double_initialized(true);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
4456 current_member_ = NULL; 4456 current_member_ = NULL;
4457 CheckMemberNameConflict(members, &member); 4457 CheckMemberNameConflict(members, &member);
4458 members->AddMember(member); 4458 members->AddMember(member);
4459 } 4459 }
4460 4460
4461 4461
4462 void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes, 4462 void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes,
4463 const Object& tl_owner, 4463 const Object& tl_owner,
4464 intptr_t metadata_pos) { 4464 intptr_t metadata_pos) {
4465 TRACE_PARSER("ParseEnumDeclaration"); 4465 TRACE_PARSER("ParseEnumDeclaration");
4466 const intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos 4466 const intptr_t declaration_pos =
4467 : TokenPos(); 4467 (metadata_pos != Scanner::kNoSourcePos) ? metadata_pos : TokenPos();
4468 ConsumeToken(); 4468 ConsumeToken();
4469 const intptr_t name_pos = TokenPos(); 4469 const intptr_t name_pos = TokenPos();
4470 String* enum_name = 4470 String* enum_name =
4471 ExpectUserDefinedTypeIdentifier("enum type name expected"); 4471 ExpectUserDefinedTypeIdentifier("enum type name expected");
4472 if (FLAG_trace_parser) { 4472 if (FLAG_trace_parser) {
4473 OS::Print("TopLevel parsing enum '%s'\n", enum_name->ToCString()); 4473 OS::Print("TopLevel parsing enum '%s'\n", enum_name->ToCString());
4474 } 4474 }
4475 ExpectToken(Token::kLBRACE); 4475 ExpectToken(Token::kLBRACE);
4476 if (!IsIdentifier()) { 4476 if (!IsIdentifier()) {
4477 ReportError("Enumeration must have at least one name"); 4477 ReportError("Enumeration must have at least one name");
(...skipping 16 matching lines...) Expand all
4494 Object& obj = Object::Handle(Z, library_.LookupLocalObject(*enum_name)); 4494 Object& obj = Object::Handle(Z, library_.LookupLocalObject(*enum_name));
4495 if (!obj.IsNull()) { 4495 if (!obj.IsNull()) {
4496 ReportError(name_pos, "'%s' is already defined", enum_name->ToCString()); 4496 ReportError(name_pos, "'%s' is already defined", enum_name->ToCString());
4497 } 4497 }
4498 Class& cls = Class::Handle(Z); 4498 Class& cls = Class::Handle(Z);
4499 cls = Class::New(*enum_name, script_, declaration_pos); 4499 cls = Class::New(*enum_name, script_, declaration_pos);
4500 cls.set_library(library_); 4500 cls.set_library(library_);
4501 library_.AddClass(cls); 4501 library_.AddClass(cls);
4502 cls.set_is_synthesized_class(); 4502 cls.set_is_synthesized_class();
4503 cls.set_is_enum_class(); 4503 cls.set_is_enum_class();
4504 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 4504 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
4505 library_.AddClassMetadata(cls, tl_owner, metadata_pos); 4505 library_.AddClassMetadata(cls, tl_owner, metadata_pos);
4506 } 4506 }
4507 cls.set_super_type(Type::Handle(Z, Type::ObjectType())); 4507 cls.set_super_type(Type::Handle(Z, Type::ObjectType()));
4508 pending_classes.Add(cls, Heap::kOld); 4508 pending_classes.Add(cls, Heap::kOld);
4509 } 4509 }
4510 4510
4511 4511
4512 void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes, 4512 void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes,
4513 const Object& tl_owner, 4513 const Object& tl_owner,
4514 intptr_t metadata_pos) { 4514 intptr_t metadata_pos) {
4515 TRACE_PARSER("ParseClassDeclaration"); 4515 TRACE_PARSER("ParseClassDeclaration");
4516 bool is_patch = false; 4516 bool is_patch = false;
4517 bool is_abstract = false; 4517 bool is_abstract = false;
4518 intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos(); 4518 intptr_t declaration_pos =
4519 (metadata_pos != Scanner::kNoSourcePos) ? metadata_pos : TokenPos();
4519 if (is_patch_source() && 4520 if (is_patch_source() &&
4520 (CurrentToken() == Token::kIDENT) && 4521 (CurrentToken() == Token::kIDENT) &&
4521 CurrentLiteral()->Equals("patch")) { 4522 CurrentLiteral()->Equals("patch")) {
4522 ConsumeToken(); 4523 ConsumeToken();
4523 is_patch = true; 4524 is_patch = true;
4524 } else if (CurrentToken() == Token::kABSTRACT) { 4525 } else if (CurrentToken() == Token::kABSTRACT) {
4525 is_abstract = true; 4526 is_abstract = true;
4526 ConsumeToken(); 4527 ConsumeToken();
4527 } 4528 }
4528 ExpectToken(Token::kCLASS); 4529 ExpectToken(Token::kCLASS);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
4617 class_name.ToCString(), 4618 class_name.ToCString(),
4618 String::Handle(orig_bound.UserVisibleName()).ToCString()); 4619 String::Handle(orig_bound.UserVisibleName()).ToCString());
4619 } 4620 }
4620 } 4621 }
4621 cls.set_type_parameters(orig_type_parameters); 4622 cls.set_type_parameters(orig_type_parameters);
4622 } 4623 }
4623 4624
4624 if (is_abstract) { 4625 if (is_abstract) {
4625 cls.set_is_abstract(); 4626 cls.set_is_abstract();
4626 } 4627 }
4627 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 4628 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
4628 library_.AddClassMetadata(cls, tl_owner, metadata_pos); 4629 library_.AddClassMetadata(cls, tl_owner, metadata_pos);
4629 } 4630 }
4630 4631
4631 const bool is_mixin_declaration = (CurrentToken() == Token::kASSIGN); 4632 const bool is_mixin_declaration = (CurrentToken() == Token::kASSIGN);
4632 if (is_mixin_declaration && is_patch) { 4633 if (is_mixin_declaration && is_patch) {
4633 ReportError(classname_pos, 4634 ReportError(classname_pos,
4634 "mixin application '%s' may not be a patch class", 4635 "mixin application '%s' may not be a patch class",
4635 class_name.ToCString()); 4636 class_name.ToCString());
4636 } 4637 }
4637 4638
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
5050 mixin_application.set_is_synthesized_class(); 5051 mixin_application.set_is_synthesized_class();
5051 5052
5052 // This mixin application alias needs an implicit constructor, but it is 5053 // This mixin application alias needs an implicit constructor, but it is
5053 // too early to call 'AddImplicitConstructor(mixin_application)' here, 5054 // too early to call 'AddImplicitConstructor(mixin_application)' here,
5054 // because this class should be lazily compiled. 5055 // because this class should be lazily compiled.
5055 if (CurrentToken() == Token::kIMPLEMENTS) { 5056 if (CurrentToken() == Token::kIMPLEMENTS) {
5056 ParseInterfaceList(mixin_application); 5057 ParseInterfaceList(mixin_application);
5057 } 5058 }
5058 ExpectSemicolon(); 5059 ExpectSemicolon();
5059 pending_classes.Add(mixin_application, Heap::kOld); 5060 pending_classes.Add(mixin_application, Heap::kOld);
5060 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 5061 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
5061 library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos); 5062 library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos);
5062 } 5063 }
5063 } 5064 }
5064 5065
5065 5066
5066 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(". 5067 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(".
5067 // We need this lookahead to distinguish between the optional return type 5068 // We need this lookahead to distinguish between the optional return type
5068 // and the alias name of a function type alias. 5069 // and the alias name of a function type alias.
5069 // Token position remains unchanged. 5070 // Token position remains unchanged.
5070 bool Parser::IsFunctionTypeAliasName() { 5071 bool Parser::IsFunctionTypeAliasName() {
(...skipping 29 matching lines...) Expand all
5100 } 5101 }
5101 SetPosition(saved_pos); 5102 SetPosition(saved_pos);
5102 return is_mixin_def; 5103 return is_mixin_def;
5103 } 5104 }
5104 5105
5105 5106
5106 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, 5107 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes,
5107 const Object& tl_owner, 5108 const Object& tl_owner,
5108 intptr_t metadata_pos) { 5109 intptr_t metadata_pos) {
5109 TRACE_PARSER("ParseTypedef"); 5110 TRACE_PARSER("ParseTypedef");
5110 intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos(); 5111 intptr_t declaration_pos =
5112 (metadata_pos != Scanner::kNoSourcePos) ? metadata_pos : TokenPos();
5111 ExpectToken(Token::kTYPEDEF); 5113 ExpectToken(Token::kTYPEDEF);
5112 5114
5113 if (IsMixinAppAlias()) { 5115 if (IsMixinAppAlias()) {
5114 if (FLAG_warn_mixin_typedef) { 5116 if (FLAG_warn_mixin_typedef) {
5115 ReportWarning(TokenPos(), "deprecated mixin application typedef"); 5117 ReportWarning(TokenPos(), "deprecated mixin application typedef");
5116 } 5118 }
5117 ParseMixinAppAlias(pending_classes, tl_owner, metadata_pos); 5119 ParseMixinAppAlias(pending_classes, tl_owner, metadata_pos);
5118 return; 5120 return;
5119 } 5121 }
5120 5122
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
5216 signature_function = signature_class.signature_function(); 5218 signature_function = signature_class.signature_function();
5217 function_type_alias.PatchSignatureFunction(signature_function); 5219 function_type_alias.PatchSignatureFunction(signature_function);
5218 } 5220 }
5219 ASSERT(signature_function.signature_class() == signature_class.raw()); 5221 ASSERT(signature_function.signature_class() == signature_class.raw());
5220 5222
5221 // The alias should not be marked as finalized yet, since it needs to be 5223 // The alias should not be marked as finalized yet, since it needs to be
5222 // checked in the class finalizer for illegal self references. 5224 // checked in the class finalizer for illegal self references.
5223 ASSERT(!function_type_alias.IsCanonicalSignatureClass()); 5225 ASSERT(!function_type_alias.IsCanonicalSignatureClass());
5224 ASSERT(!function_type_alias.is_finalized()); 5226 ASSERT(!function_type_alias.is_finalized());
5225 pending_classes.Add(function_type_alias, Heap::kOld); 5227 pending_classes.Add(function_type_alias, Heap::kOld);
5226 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 5228 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
5227 library_.AddClassMetadata(function_type_alias, 5229 library_.AddClassMetadata(function_type_alias,
5228 tl_owner, 5230 tl_owner,
5229 metadata_pos); 5231 metadata_pos);
5230 } 5232 }
5231 } 5233 }
5232 5234
5233 5235
5234 // Consumes exactly one right angle bracket. If the current token is a single 5236 // Consumes exactly one right angle bracket. If the current token is a single
5235 // bracket token, it is consumed normally. However, if it is a double or triple 5237 // bracket token, it is consumed normally. However, if it is a double or triple
5236 // bracket, it is replaced by a single or double bracket token without 5238 // bracket, it is replaced by a single or double bracket token without
5237 // incrementing the token index. 5239 // incrementing the token index.
5238 void Parser::ConsumeRightAngleBracket() { 5240 void Parser::ConsumeRightAngleBracket() {
5239 if (token_kind_ == Token::kGT) { 5241 if (token_kind_ == Token::kGT) {
5240 ConsumeToken(); 5242 ConsumeToken();
5241 } else if (token_kind_ == Token::kSHR) { 5243 } else if (token_kind_ == Token::kSHR) {
5242 token_kind_ = Token::kGT; 5244 token_kind_ = Token::kGT;
5243 } else { 5245 } else {
5244 UNREACHABLE(); 5246 UNREACHABLE();
5245 } 5247 }
5246 } 5248 }
5247 5249
5248 5250
5249 intptr_t Parser::SkipMetadata() { 5251 intptr_t Parser::SkipMetadata() {
5250 if (CurrentToken() != Token::kAT) { 5252 if (CurrentToken() != Token::kAT) {
5251 return -1; 5253 return Scanner::kNoSourcePos;
5252 } 5254 }
5253 intptr_t metadata_pos = TokenPos(); 5255 intptr_t metadata_pos = TokenPos();
5254 while (CurrentToken() == Token::kAT) { 5256 while (CurrentToken() == Token::kAT) {
5255 ConsumeToken(); 5257 ConsumeToken();
5256 ExpectIdentifier("identifier expected"); 5258 ExpectIdentifier("identifier expected");
5257 if (CurrentToken() == Token::kPERIOD) { 5259 if (CurrentToken() == Token::kPERIOD) {
5258 ConsumeToken(); 5260 ConsumeToken();
5259 ExpectIdentifier("identifier expected"); 5261 ExpectIdentifier("identifier expected");
5260 if (CurrentToken() == Token::kPERIOD) { 5262 if (CurrentToken() == Token::kPERIOD) {
5261 ConsumeToken(); 5263 ConsumeToken();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5309 GrowableArray<AbstractType*> type_parameters_array(Z, 2); 5311 GrowableArray<AbstractType*> type_parameters_array(Z, 2);
5310 intptr_t index = 0; 5312 intptr_t index = 0;
5311 TypeParameter& type_parameter = TypeParameter::Handle(Z); 5313 TypeParameter& type_parameter = TypeParameter::Handle(Z);
5312 TypeParameter& existing_type_parameter = TypeParameter::Handle(Z); 5314 TypeParameter& existing_type_parameter = TypeParameter::Handle(Z);
5313 String& existing_type_parameter_name = String::Handle(Z); 5315 String& existing_type_parameter_name = String::Handle(Z);
5314 AbstractType& type_parameter_bound = Type::Handle(Z); 5316 AbstractType& type_parameter_bound = Type::Handle(Z);
5315 do { 5317 do {
5316 ConsumeToken(); 5318 ConsumeToken();
5317 const intptr_t metadata_pos = SkipMetadata(); 5319 const intptr_t metadata_pos = SkipMetadata();
5318 const intptr_t type_parameter_pos = TokenPos(); 5320 const intptr_t type_parameter_pos = TokenPos();
5319 const intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos 5321 const intptr_t declaration_pos = (metadata_pos != Scanner::kNoSourcePos)
5322 ? metadata_pos
5320 : type_parameter_pos; 5323 : type_parameter_pos;
5321 String& type_parameter_name = 5324 String& type_parameter_name =
5322 *ExpectUserDefinedTypeIdentifier("type parameter expected"); 5325 *ExpectUserDefinedTypeIdentifier("type parameter expected");
5323 // Check for duplicate type parameters. 5326 // Check for duplicate type parameters.
5324 for (intptr_t i = 0; i < index; i++) { 5327 for (intptr_t i = 0; i < index; i++) {
5325 existing_type_parameter ^= type_parameters_array.At(i)->raw(); 5328 existing_type_parameter ^= type_parameters_array.At(i)->raw();
5326 existing_type_parameter_name = existing_type_parameter.name(); 5329 existing_type_parameter_name = existing_type_parameter.name();
5327 if (existing_type_parameter_name.Equals(type_parameter_name)) { 5330 if (existing_type_parameter_name.Equals(type_parameter_name)) {
5328 ReportError(type_parameter_pos, "duplicate type parameter '%s'", 5331 ReportError(type_parameter_pos, "duplicate type parameter '%s'",
5329 type_parameter_name.ToCString()); 5332 type_parameter_name.ToCString());
5330 } 5333 }
5331 } 5334 }
5332 if (CurrentToken() == Token::kEXTENDS) { 5335 if (CurrentToken() == Token::kEXTENDS) {
5333 ConsumeToken(); 5336 ConsumeToken();
5334 // A bound may refer to the owner of the type parameter it applies to, 5337 // A bound may refer to the owner of the type parameter it applies to,
5335 // i.e. to the class or interface currently being parsed. 5338 // i.e. to the class or interface currently being parsed.
5336 // Postpone resolution in order to avoid resolving the class and its 5339 // Postpone resolution in order to avoid resolving the class and its
5337 // type parameters, as they are not fully parsed yet. 5340 // type parameters, as they are not fully parsed yet.
5338 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); 5341 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve);
5339 } else { 5342 } else {
5340 type_parameter_bound = I->object_store()->object_type(); 5343 type_parameter_bound = I->object_store()->object_type();
5341 } 5344 }
5342 type_parameter = TypeParameter::New(cls, 5345 type_parameter = TypeParameter::New(cls,
5343 index, 5346 index,
5344 type_parameter_name, 5347 type_parameter_name,
5345 type_parameter_bound, 5348 type_parameter_bound,
5346 declaration_pos); 5349 declaration_pos);
5347 type_parameters_array.Add( 5350 type_parameters_array.Add(
5348 &AbstractType::ZoneHandle(Z, type_parameter.raw())); 5351 &AbstractType::ZoneHandle(Z, type_parameter.raw()));
5349 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 5352 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
5350 library_.AddTypeParameterMetadata(type_parameter, metadata_pos); 5353 library_.AddTypeParameterMetadata(type_parameter, metadata_pos);
5351 } 5354 }
5352 index++; 5355 index++;
5353 } while (CurrentToken() == Token::kCOMMA); 5356 } while (CurrentToken() == Token::kCOMMA);
5354 Token::Kind token = CurrentToken(); 5357 Token::Kind token = CurrentToken();
5355 if ((token == Token::kGT) || (token == Token::kSHR)) { 5358 if ((token == Token::kGT) || (token == Token::kSHR)) {
5356 ConsumeRightAngleBracket(); 5359 ConsumeRightAngleBracket();
5357 } else { 5360 } else {
5358 ReportError("right angle bracket expected"); 5361 ReportError("right angle bracket expected");
5359 } 5362 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
5498 5501
5499 const bool is_reflectable = 5502 const bool is_reflectable =
5500 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); 5503 !(library_.is_dart_scheme() && library_.IsPrivate(var_name));
5501 5504
5502 field = Field::NewTopLevel(var_name, is_final, is_const, owner, name_pos); 5505 field = Field::NewTopLevel(var_name, is_final, is_const, owner, name_pos);
5503 field.SetFieldType(type); 5506 field.SetFieldType(type);
5504 field.set_is_reflectable(is_reflectable); 5507 field.set_is_reflectable(is_reflectable);
5505 field.SetStaticValue(Object::null_instance(), true); 5508 field.SetStaticValue(Object::null_instance(), true);
5506 top_level->AddField(field); 5509 top_level->AddField(field);
5507 library_.AddObject(field, var_name); 5510 library_.AddObject(field, var_name);
5508 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 5511 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
5509 library_.AddFieldMetadata(field, metadata_pos); 5512 library_.AddFieldMetadata(field, metadata_pos);
5510 } 5513 }
5511 if (CurrentToken() == Token::kASSIGN) { 5514 if (CurrentToken() == Token::kASSIGN) {
5512 ConsumeToken(); 5515 ConsumeToken();
5513 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw()); 5516 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw());
5514 bool has_simple_literal = false; 5517 bool has_simple_literal = false;
5515 if (LookaheadToken(1) == Token::kSEMICOLON) { 5518 if (LookaheadToken(1) == Token::kSEMICOLON) {
5516 has_simple_literal = IsSimpleLiteral(type, &field_value); 5519 has_simple_literal = IsSimpleLiteral(type, &field_value);
5517 } 5520 }
5518 SkipExpr(); 5521 SkipExpr();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
5689 library_.AddObject(func, func_name); 5692 library_.AddObject(func, func_name);
5690 } else { 5693 } else {
5691 // Need to remove the previously added function that is being patched. 5694 // Need to remove the previously added function that is being patched.
5692 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); 5695 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class());
5693 const Function& replaced_func = 5696 const Function& replaced_func =
5694 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); 5697 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name));
5695 ASSERT(!replaced_func.IsNull()); 5698 ASSERT(!replaced_func.IsNull());
5696 toplevel_cls.RemoveFunction(replaced_func); 5699 toplevel_cls.RemoveFunction(replaced_func);
5697 library_.ReplaceObject(func, func_name); 5700 library_.ReplaceObject(func, func_name);
5698 } 5701 }
5699 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 5702 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
5700 library_.AddFunctionMetadata(func, metadata_pos); 5703 library_.AddFunctionMetadata(func, metadata_pos);
5701 } 5704 }
5702 } 5705 }
5703 5706
5704 5707
5705 void Parser::ParseTopLevelAccessor(TopLevel* top_level, 5708 void Parser::ParseTopLevelAccessor(TopLevel* top_level,
5706 const Object& owner, 5709 const Object& owner,
5707 intptr_t metadata_pos) { 5710 intptr_t metadata_pos) {
5708 TRACE_PARSER("ParseTopLevelAccessor"); 5711 TRACE_PARSER("ParseTopLevelAccessor");
5709 const intptr_t decl_begin_pos = TokenPos(); 5712 const intptr_t decl_begin_pos = TokenPos();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
5854 // Need to remove the previously added accessor that is being patched. 5857 // Need to remove the previously added accessor that is being patched.
5855 const Class& toplevel_cls = Class::Handle(Z, 5858 const Class& toplevel_cls = Class::Handle(Z,
5856 owner.IsClass() ? Class::Cast(owner).raw() 5859 owner.IsClass() ? Class::Cast(owner).raw()
5857 : PatchClass::Cast(owner).patched_class()); 5860 : PatchClass::Cast(owner).patched_class());
5858 const Function& replaced_func = 5861 const Function& replaced_func =
5859 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); 5862 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name));
5860 ASSERT(!replaced_func.IsNull()); 5863 ASSERT(!replaced_func.IsNull());
5861 toplevel_cls.RemoveFunction(replaced_func); 5864 toplevel_cls.RemoveFunction(replaced_func);
5862 library_.ReplaceObject(func, accessor_name); 5865 library_.ReplaceObject(func, accessor_name);
5863 } 5866 }
5864 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 5867 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
5865 library_.AddFunctionMetadata(func, metadata_pos); 5868 library_.AddFunctionMetadata(func, metadata_pos);
5866 } 5869 }
5867 } 5870 }
5868 5871
5869 5872
5870 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 5873 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
5871 intptr_t token_pos, 5874 intptr_t token_pos,
5872 const String& url) { 5875 const String& url) {
5873 Dart_LibraryTagHandler handler = I->library_tag_handler(); 5876 Dart_LibraryTagHandler handler = I->library_tag_handler();
5874 if (handler == NULL) { 5877 if (handler == NULL) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
5953 if (url.Length() == 0) { 5956 if (url.Length() == 0) {
5954 ReportError("library url expected"); 5957 ReportError("library url expected");
5955 } 5958 }
5956 bool is_deferred_import = false; 5959 bool is_deferred_import = false;
5957 if (is_import && (IsSymbol(Symbols::Deferred()))) { 5960 if (is_import && (IsSymbol(Symbols::Deferred()))) {
5958 is_deferred_import = true; 5961 is_deferred_import = true;
5959 ConsumeToken(); 5962 ConsumeToken();
5960 CheckToken(Token::kAS, "'as' expected"); 5963 CheckToken(Token::kAS, "'as' expected");
5961 } 5964 }
5962 String& prefix = String::Handle(Z); 5965 String& prefix = String::Handle(Z);
5963 intptr_t prefix_pos = 0; 5966 intptr_t prefix_pos = Scanner::kNoSourcePos;
5964 if (is_import && (CurrentToken() == Token::kAS)) { 5967 if (is_import && (CurrentToken() == Token::kAS)) {
5965 ConsumeToken(); 5968 ConsumeToken();
5966 prefix_pos = TokenPos(); 5969 prefix_pos = TokenPos();
5967 prefix = ExpectIdentifier("prefix identifier expected")->raw(); 5970 prefix = ExpectIdentifier("prefix identifier expected")->raw();
5968 } 5971 }
5969 5972
5970 Array& show_names = Array::Handle(Z); 5973 Array& show_names = Array::Handle(Z);
5971 Array& hide_names = Array::Handle(Z); 5974 Array& hide_names = Array::Handle(Z);
5972 if (is_deferred_import || 5975 if (is_deferred_import ||
5973 IsSymbol(Symbols::Show()) || 5976 IsSymbol(Symbols::Show()) ||
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6016 // library import, call the library tag handler to request loading 6019 // library import, call the library tag handler to request loading
6017 // the library. 6020 // the library.
6018 if (library.LoadNotStarted() && 6021 if (library.LoadNotStarted() &&
6019 (!is_deferred_import || FLAG_load_deferred_eagerly)) { 6022 (!is_deferred_import || FLAG_load_deferred_eagerly)) {
6020 library.SetLoadRequested(); 6023 library.SetLoadRequested();
6021 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url); 6024 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url);
6022 } 6025 }
6023 6026
6024 Namespace& ns = Namespace::Handle(Z, 6027 Namespace& ns = Namespace::Handle(Z,
6025 Namespace::New(library, show_names, hide_names)); 6028 Namespace::New(library, show_names, hide_names));
6026 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 6029 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
6027 ns.AddMetadata(tl_owner, metadata_pos); 6030 ns.AddMetadata(tl_owner, metadata_pos);
6028 } 6031 }
6029 6032
6030 // Ensure that private dart:_ libraries are only imported into dart: 6033 // Ensure that private dart:_ libraries are only imported into dart:
6031 // libraries, including indirectly through exports. 6034 // libraries, including indirectly through exports.
6032 const String& lib_url = String::Handle(Z, library_.url()); 6035 const String& lib_url = String::Handle(Z, library_.url());
6033 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) && 6036 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) &&
6034 !lib_url.StartsWith(Symbols::DartScheme())) { 6037 !lib_url.StartsWith(Symbols::DartScheme())) {
6035 ReportError(import_pos, "private library is not accessible"); 6038 ReportError(import_pos, "private library is not accessible");
6036 } 6039 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
6102 // declaration that follows the library definitions. Therefore, we 6105 // declaration that follows the library definitions. Therefore, we
6103 // need to remember the position of the last token that was 6106 // need to remember the position of the last token that was
6104 // successfully consumed. 6107 // successfully consumed.
6105 intptr_t rewind_pos = TokenPos(); 6108 intptr_t rewind_pos = TokenPos();
6106 intptr_t metadata_pos = SkipMetadata(); 6109 intptr_t metadata_pos = SkipMetadata();
6107 if (CurrentToken() == Token::kLIBRARY) { 6110 if (CurrentToken() == Token::kLIBRARY) {
6108 if (is_patch_source()) { 6111 if (is_patch_source()) {
6109 ReportError("patch cannot override library name"); 6112 ReportError("patch cannot override library name");
6110 } 6113 }
6111 ParseLibraryName(); 6114 ParseLibraryName();
6112 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 6115 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
6113 library_.AddLibraryMetadata(tl_owner, metadata_pos); 6116 library_.AddLibraryMetadata(tl_owner, metadata_pos);
6114 } 6117 }
6115 rewind_pos = TokenPos(); 6118 rewind_pos = TokenPos();
6116 metadata_pos = SkipMetadata(); 6119 metadata_pos = SkipMetadata();
6117 } 6120 }
6118 while ((CurrentToken() == Token::kIMPORT) || 6121 while ((CurrentToken() == Token::kIMPORT) ||
6119 (CurrentToken() == Token::kEXPORT)) { 6122 (CurrentToken() == Token::kEXPORT)) {
6120 ParseLibraryImportExport(tl_owner, metadata_pos); 6123 ParseLibraryImportExport(tl_owner, metadata_pos);
6121 rewind_pos = TokenPos(); 6124 rewind_pos = TokenPos();
6122 metadata_pos = SkipMetadata(); 6125 metadata_pos = SkipMetadata();
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
7509 variable = new(Z) LocalVariable( 7512 variable = new(Z) LocalVariable(
7510 assign_pos, ident, type); 7513 assign_pos, ident, type);
7511 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Object::null_instance()); 7514 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Object::null_instance());
7512 initialization = new(Z) StoreLocalNode( 7515 initialization = new(Z) StoreLocalNode(
7513 ident_pos, variable, null_expr); 7516 ident_pos, variable, null_expr);
7514 } 7517 }
7515 7518
7516 ASSERT(current_block_ != NULL); 7519 ASSERT(current_block_ != NULL);
7517 const intptr_t previous_pos = 7520 const intptr_t previous_pos =
7518 current_block_->scope->PreviousReferencePos(ident); 7521 current_block_->scope->PreviousReferencePos(ident);
7519 if (previous_pos >= 0) { 7522 if (previous_pos != Scanner::kNoSourcePos) {
7520 ASSERT(!script_.IsNull()); 7523 ASSERT(!script_.IsNull());
7521 if (previous_pos > ident_pos) { 7524 if (previous_pos > ident_pos) {
7522 ReportError(ident_pos, 7525 ReportError(ident_pos,
7523 "initializer of '%s' may not refer to itself", 7526 "initializer of '%s' may not refer to itself",
7524 ident.ToCString()); 7527 ident.ToCString());
7525 7528
7526 } else { 7529 } else {
7527 intptr_t line_number; 7530 intptr_t line_number;
7528 script_.GetTokenLocation(previous_pos, &line_number, NULL); 7531 script_.GetTokenLocation(previous_pos, &line_number, NULL);
7529 ReportError(ident_pos, 7532 ReportError(ident_pos,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
7637 7640
7638 AstNode* Parser::ParseFunctionStatement(bool is_literal) { 7641 AstNode* Parser::ParseFunctionStatement(bool is_literal) {
7639 TRACE_PARSER("ParseFunctionStatement"); 7642 TRACE_PARSER("ParseFunctionStatement");
7640 AbstractType& result_type = AbstractType::Handle(Z); 7643 AbstractType& result_type = AbstractType::Handle(Z);
7641 const String* variable_name = NULL; 7644 const String* variable_name = NULL;
7642 const String* function_name = NULL; 7645 const String* function_name = NULL;
7643 7646
7644 result_type = Type::DynamicType(); 7647 result_type = Type::DynamicType();
7645 7648
7646 const intptr_t function_pos = TokenPos(); 7649 const intptr_t function_pos = TokenPos();
7647 intptr_t metadata_pos = -1; 7650 intptr_t metadata_pos = Scanner::kNoSourcePos;
7648 if (is_literal) { 7651 if (is_literal) {
7649 ASSERT(CurrentToken() == Token::kLPAREN); 7652 ASSERT(CurrentToken() == Token::kLPAREN);
7650 function_name = &Symbols::AnonymousClosure(); 7653 function_name = &Symbols::AnonymousClosure();
7651 } else { 7654 } else {
7652 metadata_pos = SkipMetadata(); 7655 metadata_pos = SkipMetadata();
7653 if (CurrentToken() == Token::kVOID) { 7656 if (CurrentToken() == Token::kVOID) {
7654 ConsumeToken(); 7657 ConsumeToken();
7655 result_type = Type::VoidType(); 7658 result_type = Type::VoidType();
7656 } else if ((CurrentToken() == Token::kIDENT) && 7659 } else if ((CurrentToken() == Token::kIDENT) &&
7657 (LookaheadToken(1) != Token::kLPAREN)) { 7660 (LookaheadToken(1) != Token::kLPAREN)) {
7658 result_type = ParseType(ClassFinalizer::kCanonicalize); 7661 result_type = ParseType(ClassFinalizer::kCanonicalize);
7659 } 7662 }
7660 const intptr_t name_pos = TokenPos(); 7663 const intptr_t name_pos = TokenPos();
7661 variable_name = ExpectIdentifier("function name expected"); 7664 variable_name = ExpectIdentifier("function name expected");
7662 function_name = variable_name; 7665 function_name = variable_name;
7663 7666
7664 // Check that the function name has not been referenced 7667 // Check that the function name has not been referenced
7665 // before this declaration. 7668 // before this declaration.
7666 ASSERT(current_block_ != NULL); 7669 ASSERT(current_block_ != NULL);
7667 const intptr_t previous_pos = 7670 const intptr_t previous_pos =
7668 current_block_->scope->PreviousReferencePos(*function_name); 7671 current_block_->scope->PreviousReferencePos(*function_name);
7669 if (previous_pos >= 0) { 7672 if (previous_pos != Scanner::kNoSourcePos) {
7670 ASSERT(!script_.IsNull()); 7673 ASSERT(!script_.IsNull());
7671 intptr_t line_number; 7674 intptr_t line_number;
7672 script_.GetTokenLocation(previous_pos, &line_number, NULL); 7675 script_.GetTokenLocation(previous_pos, &line_number, NULL);
7673 ReportError(name_pos, 7676 ReportError(name_pos,
7674 "identifier '%s' previously used in line %" Pd "", 7677 "identifier '%s' previously used in line %" Pd "",
7675 function_name->ToCString(), 7678 function_name->ToCString(),
7676 line_number); 7679 line_number);
7677 } 7680 }
7678 } 7681 }
7679 CheckToken(Token::kLPAREN); 7682 CheckToken(Token::kLPAREN);
(...skipping 11 matching lines...) Expand all
7691 function = I->LookupClosureFunction(innermost_function(), function_pos); 7694 function = I->LookupClosureFunction(innermost_function(), function_pos);
7692 if (function.IsNull()) { 7695 if (function.IsNull()) {
7693 // The function will be registered in the lookup table by the 7696 // The function will be registered in the lookup table by the
7694 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure 7697 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure
7695 // function has been properly setup. 7698 // function has been properly setup.
7696 is_new_closure = true; 7699 is_new_closure = true;
7697 function = Function::NewClosureFunction(*function_name, 7700 function = Function::NewClosureFunction(*function_name,
7698 innermost_function(), 7701 innermost_function(),
7699 function_pos); 7702 function_pos);
7700 function.set_result_type(result_type); 7703 function.set_result_type(result_type);
7701 if (FLAG_enable_mirrors && (metadata_pos >= 0)) { 7704 if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) {
7702 library_.AddFunctionMetadata(function, metadata_pos); 7705 library_.AddFunctionMetadata(function, metadata_pos);
7703 } 7706 }
7704 } 7707 }
7705 7708
7706 // The function type needs to be finalized at compile time, since the closure 7709 // The function type needs to be finalized at compile time, since the closure
7707 // may be type checked at run time when assigned to a function variable, 7710 // may be type checked at run time when assigned to a function variable,
7708 // passed as a function argument, or returned as a function result. 7711 // passed as a function argument, or returned as a function result.
7709 7712
7710 LocalVariable* function_variable = NULL; 7713 LocalVariable* function_variable = NULL;
7711 Type& function_type = Type::ZoneHandle(Z); 7714 Type& function_type = Type::ZoneHandle(Z);
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
8946 8949
8947 8950
8948 AstNode* Parser::ParseForInStatement(intptr_t forin_pos, 8951 AstNode* Parser::ParseForInStatement(intptr_t forin_pos,
8949 SourceLabel* label) { 8952 SourceLabel* label) {
8950 TRACE_PARSER("ParseForInStatement"); 8953 TRACE_PARSER("ParseForInStatement");
8951 bool loop_var_is_final = (CurrentToken() == Token::kFINAL); 8954 bool loop_var_is_final = (CurrentToken() == Token::kFINAL);
8952 if (CurrentToken() == Token::kCONST) { 8955 if (CurrentToken() == Token::kCONST) {
8953 ReportError("Loop variable cannot be 'const'"); 8956 ReportError("Loop variable cannot be 'const'");
8954 } 8957 }
8955 const String* loop_var_name = NULL; 8958 const String* loop_var_name = NULL;
8956 intptr_t loop_var_pos = 0; 8959 intptr_t loop_var_pos = Scanner::kNoSourcePos;
8957 bool new_loop_var = false; 8960 bool new_loop_var = false;
8958 AbstractType& loop_var_type = AbstractType::ZoneHandle(Z); 8961 AbstractType& loop_var_type = AbstractType::ZoneHandle(Z);
8959 if (LookaheadToken(1) == Token::kIN) { 8962 if (LookaheadToken(1) == Token::kIN) {
8960 loop_var_pos = TokenPos(); 8963 loop_var_pos = TokenPos();
8961 loop_var_name = ExpectIdentifier("variable name expected"); 8964 loop_var_name = ExpectIdentifier("variable name expected");
8962 } else { 8965 } else {
8963 // The case without a type is handled above, so require a type here. 8966 // The case without a type is handled above, so require a type here.
8964 // Delay creation of the local variable until we know its actual 8967 // Delay creation of the local variable until we know its actual
8965 // position, which is inside the loop body. 8968 // position, which is inside the loop body.
8966 new_loop_var = true; 8969 new_loop_var = true;
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
10040 ASSERT(outer_saved_try_ctx == NULL); 10043 ASSERT(outer_saved_try_ctx == NULL);
10041 } 10044 }
10042 } 10045 }
10043 return yield; 10046 return yield;
10044 } 10047 }
10045 10048
10046 10049
10047 AstNode* Parser::ParseStatement() { 10050 AstNode* Parser::ParseStatement() {
10048 TRACE_PARSER("ParseStatement"); 10051 TRACE_PARSER("ParseStatement");
10049 AstNode* statement = NULL; 10052 AstNode* statement = NULL;
10050 intptr_t label_pos = 0; 10053 intptr_t label_pos = Scanner::kNoSourcePos;
10051 String* label_name = NULL; 10054 String* label_name = NULL;
10052 if (IsIdentifier()) { 10055 if (IsIdentifier()) {
10053 if (LookaheadToken(1) == Token::kCOLON) { 10056 if (LookaheadToken(1) == Token::kCOLON) {
10054 // Statement starts with a label. 10057 // Statement starts with a label.
10055 label_name = CurrentLiteral(); 10058 label_name = CurrentLiteral();
10056 label_pos = TokenPos(); 10059 label_pos = TokenPos();
10057 ASSERT(label_pos > 0); 10060 ASSERT(label_pos != Scanner::kNoSourcePos);
10058 ConsumeToken(); // Consume identifier. 10061 ConsumeToken(); // Consume identifier.
10059 ConsumeToken(); // Consume colon. 10062 ConsumeToken(); // Consume colon.
10060 } 10063 }
10061 } 10064 }
10062 const intptr_t statement_pos = TokenPos(); 10065 const intptr_t statement_pos = TokenPos();
10063 const Token::Kind token = CurrentToken(); 10066 const Token::Kind token = CurrentToken();
10064 10067
10065 if (token == Token::kWHILE) { 10068 if (token == Token::kWHILE) {
10066 statement = ParseWhileStatement(label_name); 10069 statement = ParseWhileStatement(label_name);
10067 } else if (token == Token::kFOR) { 10070 } else if (token == Token::kFOR) {
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
10734 10737
10735 // Check whether the syntax of expression expr is a grammatically legal 10738 // Check whether the syntax of expression expr is a grammatically legal
10736 // assignable expression. This check is used to detect situations where 10739 // assignable expression. This check is used to detect situations where
10737 // the expression itself is assignable, but the source is grammatically 10740 // the expression itself is assignable, but the source is grammatically
10738 // wrong. The AST representation of an expression cannot distinguish 10741 // wrong. The AST representation of an expression cannot distinguish
10739 // between x = 0 and (x) = 0. The latter is illegal. 10742 // between x = 0 and (x) = 0. The latter is illegal.
10740 // A syntactically legal assignable expression always ends with an 10743 // A syntactically legal assignable expression always ends with an
10741 // identifier token or a ] token. We rewind the token iterator and 10744 // identifier token or a ] token. We rewind the token iterator and
10742 // check whether the token before end_pos is an identifier or ]. 10745 // check whether the token before end_pos is an identifier or ].
10743 bool Parser::IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos) { 10746 bool Parser::IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos) {
10744 ASSERT(expr->token_pos() >= 0); 10747 ASSERT(expr->token_pos() != Scanner::kNoSourcePos);
10745 ASSERT(expr->token_pos() < end_pos); 10748 ASSERT(expr->token_pos() < end_pos);
10746 SetPosition(expr->token_pos()); 10749 SetPosition(expr->token_pos());
10747 Token::Kind token = Token::kILLEGAL; 10750 Token::Kind token = Token::kILLEGAL;
10748 while (TokenPos() < end_pos) { 10751 while (TokenPos() < end_pos) {
10749 token = CurrentToken(); 10752 token = CurrentToken();
10750 ConsumeToken(); 10753 ConsumeToken();
10751 } 10754 }
10752 ASSERT(TokenPos() == end_pos); 10755 ASSERT(TokenPos() == end_pos);
10753 return Token::IsIdentifier(token) || (token == Token::kRBRACK); 10756 return Token::IsIdentifier(token) || (token == Token::kRBRACK);
10754 } 10757 }
(...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after
12696 12699
12697 12700
12698 // Parse "[" [ expr { "," expr } ["," ] "]". 12701 // Parse "[" [ expr { "," expr } ["," ] "]".
12699 // Note: if the list literal is empty and the brackets have no whitespace 12702 // Note: if the list literal is empty and the brackets have no whitespace
12700 // between them, the scanner recognizes the opening and closing bracket 12703 // between them, the scanner recognizes the opening and closing bracket
12701 // as one token of type Token::kINDEX. 12704 // as one token of type Token::kINDEX.
12702 AstNode* Parser::ParseListLiteral(intptr_t type_pos, 12705 AstNode* Parser::ParseListLiteral(intptr_t type_pos,
12703 bool is_const, 12706 bool is_const,
12704 const TypeArguments& type_arguments) { 12707 const TypeArguments& type_arguments) {
12705 TRACE_PARSER("ParseListLiteral"); 12708 TRACE_PARSER("ParseListLiteral");
12706 ASSERT(type_pos >= 0); 12709 ASSERT(type_pos != Scanner::kNoSourcePos);
12707 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); 12710 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX);
12708 const intptr_t literal_pos = TokenPos(); 12711 const intptr_t literal_pos = TokenPos();
12709 12712
12710 if (is_const) { 12713 if (is_const) {
12711 Instance& existing_const = Instance::ZoneHandle(Z); 12714 Instance& existing_const = Instance::ZoneHandle(Z);
12712 if (GetCachedConstant(literal_pos, &existing_const)) { 12715 if (GetCachedConstant(literal_pos, &existing_const)) {
12713 SkipListLiteral(); 12716 SkipListLiteral();
12714 return new(Z) LiteralNode(literal_pos, existing_const); 12717 return new(Z) LiteralNode(literal_pos, existing_const);
12715 } 12718 }
12716 } 12719 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
12899 } 12902 }
12900 pairs->Add(key); 12903 pairs->Add(key);
12901 pairs->Add(value); 12904 pairs->Add(value);
12902 } 12905 }
12903 12906
12904 12907
12905 AstNode* Parser::ParseMapLiteral(intptr_t type_pos, 12908 AstNode* Parser::ParseMapLiteral(intptr_t type_pos,
12906 bool is_const, 12909 bool is_const,
12907 const TypeArguments& type_arguments) { 12910 const TypeArguments& type_arguments) {
12908 TRACE_PARSER("ParseMapLiteral"); 12911 TRACE_PARSER("ParseMapLiteral");
12909 ASSERT(type_pos >= 0); 12912 ASSERT(type_pos != Scanner::kNoSourcePos);
12910 ASSERT(CurrentToken() == Token::kLBRACE); 12913 ASSERT(CurrentToken() == Token::kLBRACE);
12911 const intptr_t literal_pos = TokenPos(); 12914 const intptr_t literal_pos = TokenPos();
12912 12915
12913 if (is_const) { 12916 if (is_const) {
12914 Instance& existing_const = Instance::ZoneHandle(Z); 12917 Instance& existing_const = Instance::ZoneHandle(Z);
12915 if (GetCachedConstant(literal_pos, &existing_const)) { 12918 if (GetCachedConstant(literal_pos, &existing_const)) {
12916 SkipMapLiteral(); 12919 SkipMapLiteral();
12917 return new(Z) LiteralNode(literal_pos, existing_const); 12920 return new(Z) LiteralNode(literal_pos, existing_const);
12918 } 12921 }
12919 } 12922 }
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after
14508 const ArgumentListNode& function_args, 14511 const ArgumentListNode& function_args,
14509 const LocalVariable* temp_for_last_arg, 14512 const LocalVariable* temp_for_last_arg,
14510 bool is_super_invocation) { 14513 bool is_super_invocation) {
14511 UNREACHABLE(); 14514 UNREACHABLE();
14512 return NULL; 14515 return NULL;
14513 } 14516 }
14514 14517
14515 } // namespace dart 14518 } // namespace dart
14516 14519
14517 #endif // DART_PRECOMPILED 14520 #endif // DART_PRECOMPILED
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698