Chromium Code Reviews| Index: runtime/vm/parser.cc |
| diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc |
| index ac3cbb52ea1c812ef7e2047788ca362a7bb4539a..a4184baef56b49fb1b5bca8daf0109014f353120 100644 |
| --- a/runtime/vm/parser.cc |
| +++ b/runtime/vm/parser.cc |
| @@ -623,7 +623,7 @@ struct MemberDesc { |
| metadata_pos = Scanner::kNoSourcePos; |
| operator_token = Token::kILLEGAL; |
| type = NULL; |
| - name_pos = 0; |
| + name_pos = Scanner::kNoSourcePos; |
| name = NULL; |
| redirect_name = NULL; |
| dict_name = NULL; |
| @@ -3483,7 +3483,7 @@ SequenceNode* Parser::ParseFunc(const Function& func) { |
| BoolScope allow_await(&this->await_is_keyword_, |
| func.IsAsyncOrGenerator() || func.is_generated_body()); |
| - intptr_t end_token_pos = 0; |
| + intptr_t end_token_pos = Scanner::kNoSourcePos; |
| if (CurrentToken() == Token::kLBRACE) { |
| ConsumeToken(); |
| if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) { |
| @@ -4004,7 +4004,7 @@ void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) { |
| if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { |
| func.set_is_reflectable(false); |
| } |
| - if (FLAG_enable_mirrors && (method->metadata_pos > 0)) { |
| + 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.
|
| library_.AddFunctionMetadata(func, method->metadata_pos); |
| } |
| if (method->has_native) { |
| @@ -4035,7 +4035,7 @@ void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { |
| CurrentToken() == Token::kCOMMA || |
| CurrentToken() == Token::kASSIGN); |
| ASSERT(field->type != NULL); |
| - ASSERT(field->name_pos > 0); |
| + ASSERT(field->name_pos != Scanner::kNoSourcePos); |
| ASSERT(current_member_ == field); |
| // All const fields are also final. |
| ASSERT(!field->has_const || field->has_final); |
| @@ -4104,7 +4104,7 @@ void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { |
| class_field.set_has_initializer(has_initializer); |
| members->AddField(class_field); |
| field->field_ = &class_field; |
| - if (FLAG_enable_mirrors && (field->metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (field->metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddFieldMetadata(class_field, field->metadata_pos); |
| } |
| @@ -4463,8 +4463,8 @@ void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes, |
| const Object& tl_owner, |
| intptr_t metadata_pos) { |
| TRACE_PARSER("ParseEnumDeclaration"); |
| - const intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos |
| - : TokenPos(); |
| + const intptr_t declaration_pos = |
| + (metadata_pos != Scanner::kNoSourcePos) ? metadata_pos : TokenPos(); |
| ConsumeToken(); |
| const intptr_t name_pos = TokenPos(); |
| String* enum_name = |
| @@ -4501,7 +4501,7 @@ void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes, |
| library_.AddClass(cls); |
| cls.set_is_synthesized_class(); |
| cls.set_is_enum_class(); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddClassMetadata(cls, tl_owner, metadata_pos); |
| } |
| cls.set_super_type(Type::Handle(Z, Type::ObjectType())); |
| @@ -4515,7 +4515,8 @@ void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes, |
| TRACE_PARSER("ParseClassDeclaration"); |
| bool is_patch = false; |
| bool is_abstract = false; |
| - intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos(); |
| + intptr_t declaration_pos = |
| + (metadata_pos != Scanner::kNoSourcePos) ? metadata_pos : TokenPos(); |
| if (is_patch_source() && |
| (CurrentToken() == Token::kIDENT) && |
| CurrentLiteral()->Equals("patch")) { |
| @@ -4624,7 +4625,7 @@ void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes, |
| if (is_abstract) { |
| cls.set_is_abstract(); |
| } |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddClassMetadata(cls, tl_owner, metadata_pos); |
| } |
| @@ -5057,7 +5058,7 @@ void Parser::ParseMixinAppAlias( |
| } |
| ExpectSemicolon(); |
| pending_classes.Add(mixin_application, Heap::kOld); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos); |
| } |
| } |
| @@ -5107,7 +5108,8 @@ void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, |
| const Object& tl_owner, |
| intptr_t metadata_pos) { |
| TRACE_PARSER("ParseTypedef"); |
| - intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos(); |
| + intptr_t declaration_pos = |
| + (metadata_pos != Scanner::kNoSourcePos) ? metadata_pos : TokenPos(); |
| ExpectToken(Token::kTYPEDEF); |
| if (IsMixinAppAlias()) { |
| @@ -5223,7 +5225,7 @@ void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, |
| ASSERT(!function_type_alias.IsCanonicalSignatureClass()); |
| ASSERT(!function_type_alias.is_finalized()); |
| pending_classes.Add(function_type_alias, Heap::kOld); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddClassMetadata(function_type_alias, |
| tl_owner, |
| metadata_pos); |
| @@ -5248,7 +5250,7 @@ void Parser::ConsumeRightAngleBracket() { |
| intptr_t Parser::SkipMetadata() { |
| if (CurrentToken() != Token::kAT) { |
| - return -1; |
| + return Scanner::kNoSourcePos; |
| } |
| intptr_t metadata_pos = TokenPos(); |
| while (CurrentToken() == Token::kAT) { |
| @@ -5316,7 +5318,8 @@ void Parser::ParseTypeParameters(const Class& cls) { |
| ConsumeToken(); |
| const intptr_t metadata_pos = SkipMetadata(); |
| const intptr_t type_parameter_pos = TokenPos(); |
| - const intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos |
| + const intptr_t declaration_pos = (metadata_pos != Scanner::kNoSourcePos) |
| + ? metadata_pos |
| : type_parameter_pos; |
| String& type_parameter_name = |
| *ExpectUserDefinedTypeIdentifier("type parameter expected"); |
| @@ -5346,7 +5349,7 @@ void Parser::ParseTypeParameters(const Class& cls) { |
| declaration_pos); |
| type_parameters_array.Add( |
| &AbstractType::ZoneHandle(Z, type_parameter.raw())); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddTypeParameterMetadata(type_parameter, metadata_pos); |
| } |
| index++; |
| @@ -5505,7 +5508,7 @@ void Parser::ParseTopLevelVariable(TopLevel* top_level, |
| field.SetStaticValue(Object::null_instance(), true); |
| top_level->AddField(field); |
| library_.AddObject(field, var_name); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddFieldMetadata(field, metadata_pos); |
| } |
| if (CurrentToken() == Token::kASSIGN) { |
| @@ -5696,7 +5699,7 @@ void Parser::ParseTopLevelFunction(TopLevel* top_level, |
| toplevel_cls.RemoveFunction(replaced_func); |
| library_.ReplaceObject(func, func_name); |
| } |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddFunctionMetadata(func, metadata_pos); |
| } |
| } |
| @@ -5861,7 +5864,7 @@ void Parser::ParseTopLevelAccessor(TopLevel* top_level, |
| toplevel_cls.RemoveFunction(replaced_func); |
| library_.ReplaceObject(func, accessor_name); |
| } |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddFunctionMetadata(func, metadata_pos); |
| } |
| } |
| @@ -5960,7 +5963,7 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner, |
| CheckToken(Token::kAS, "'as' expected"); |
| } |
| String& prefix = String::Handle(Z); |
| - intptr_t prefix_pos = 0; |
| + intptr_t prefix_pos = Scanner::kNoSourcePos; |
| if (is_import && (CurrentToken() == Token::kAS)) { |
| ConsumeToken(); |
| prefix_pos = TokenPos(); |
| @@ -6023,7 +6026,7 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner, |
| Namespace& ns = Namespace::Handle(Z, |
| Namespace::New(library, show_names, hide_names)); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| ns.AddMetadata(tl_owner, metadata_pos); |
| } |
| @@ -6109,7 +6112,7 @@ void Parser::ParseLibraryDefinition(const Object& tl_owner) { |
| ReportError("patch cannot override library name"); |
| } |
| ParseLibraryName(); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddLibraryMetadata(tl_owner, metadata_pos); |
| } |
| rewind_pos = TokenPos(); |
| @@ -7516,7 +7519,7 @@ AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, |
| ASSERT(current_block_ != NULL); |
| const intptr_t previous_pos = |
| current_block_->scope->PreviousReferencePos(ident); |
| - if (previous_pos >= 0) { |
| + if (previous_pos != Scanner::kNoSourcePos) { |
| ASSERT(!script_.IsNull()); |
| if (previous_pos > ident_pos) { |
| ReportError(ident_pos, |
| @@ -7644,7 +7647,7 @@ AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
| result_type = Type::DynamicType(); |
| const intptr_t function_pos = TokenPos(); |
| - intptr_t metadata_pos = -1; |
| + intptr_t metadata_pos = Scanner::kNoSourcePos; |
| if (is_literal) { |
| ASSERT(CurrentToken() == Token::kLPAREN); |
| function_name = &Symbols::AnonymousClosure(); |
| @@ -7666,7 +7669,7 @@ AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
| ASSERT(current_block_ != NULL); |
| const intptr_t previous_pos = |
| current_block_->scope->PreviousReferencePos(*function_name); |
| - if (previous_pos >= 0) { |
| + if (previous_pos != Scanner::kNoSourcePos) { |
| ASSERT(!script_.IsNull()); |
| intptr_t line_number; |
| script_.GetTokenLocation(previous_pos, &line_number, NULL); |
| @@ -7698,7 +7701,7 @@ AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
| innermost_function(), |
| function_pos); |
| function.set_result_type(result_type); |
| - if (FLAG_enable_mirrors && (metadata_pos >= 0)) { |
| + if (FLAG_enable_mirrors && (metadata_pos != Scanner::kNoSourcePos)) { |
| library_.AddFunctionMetadata(function, metadata_pos); |
| } |
| } |
| @@ -8953,7 +8956,7 @@ AstNode* Parser::ParseForInStatement(intptr_t forin_pos, |
| ReportError("Loop variable cannot be 'const'"); |
| } |
| const String* loop_var_name = NULL; |
| - intptr_t loop_var_pos = 0; |
| + intptr_t loop_var_pos = Scanner::kNoSourcePos; |
| bool new_loop_var = false; |
| AbstractType& loop_var_type = AbstractType::ZoneHandle(Z); |
| if (LookaheadToken(1) == Token::kIN) { |
| @@ -10047,14 +10050,14 @@ AstNode* Parser::ParseYieldStatement() { |
| AstNode* Parser::ParseStatement() { |
| TRACE_PARSER("ParseStatement"); |
| AstNode* statement = NULL; |
| - intptr_t label_pos = 0; |
| + intptr_t label_pos = Scanner::kNoSourcePos; |
| String* label_name = NULL; |
| if (IsIdentifier()) { |
| if (LookaheadToken(1) == Token::kCOLON) { |
| // Statement starts with a label. |
| label_name = CurrentLiteral(); |
| label_pos = TokenPos(); |
| - ASSERT(label_pos > 0); |
| + ASSERT(label_pos != Scanner::kNoSourcePos); |
| ConsumeToken(); // Consume identifier. |
| ConsumeToken(); // Consume colon. |
| } |
| @@ -10741,7 +10744,7 @@ LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { |
| // identifier token or a ] token. We rewind the token iterator and |
| // check whether the token before end_pos is an identifier or ]. |
| bool Parser::IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos) { |
| - ASSERT(expr->token_pos() >= 0); |
| + ASSERT(expr->token_pos() != Scanner::kNoSourcePos); |
| ASSERT(expr->token_pos() < end_pos); |
| SetPosition(expr->token_pos()); |
| Token::Kind token = Token::kILLEGAL; |
| @@ -12703,7 +12706,7 @@ AstNode* Parser::ParseListLiteral(intptr_t type_pos, |
| bool is_const, |
| const TypeArguments& type_arguments) { |
| TRACE_PARSER("ParseListLiteral"); |
| - ASSERT(type_pos >= 0); |
| + ASSERT(type_pos != Scanner::kNoSourcePos); |
| ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); |
| const intptr_t literal_pos = TokenPos(); |
| @@ -12906,7 +12909,7 @@ AstNode* Parser::ParseMapLiteral(intptr_t type_pos, |
| bool is_const, |
| const TypeArguments& type_arguments) { |
| TRACE_PARSER("ParseMapLiteral"); |
| - ASSERT(type_pos >= 0); |
| + ASSERT(type_pos != Scanner::kNoSourcePos); |
| ASSERT(CurrentToken() == Token::kLBRACE); |
| const intptr_t literal_pos = TokenPos(); |