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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 4790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4801 ConsumeToken(); | 4801 ConsumeToken(); |
4802 if (CurrentToken() != Token::kSTRING) { | 4802 if (CurrentToken() != Token::kSTRING) { |
4803 ErrorMsg("library url expected"); | 4803 ErrorMsg("library url expected"); |
4804 } | 4804 } |
4805 const String& url = *CurrentLiteral(); | 4805 const String& url = *CurrentLiteral(); |
4806 if (url.Length() == 0) { | 4806 if (url.Length() == 0) { |
4807 ErrorMsg("library url expected"); | 4807 ErrorMsg("library url expected"); |
4808 } | 4808 } |
4809 ConsumeToken(); | 4809 ConsumeToken(); |
4810 String& prefix = String::Handle(); | 4810 String& prefix = String::Handle(); |
4811 if (is_import && IsLiteral("as")) { | 4811 if (is_import && (CurrentToken() == Token::kAS)) { |
4812 ConsumeToken(); | 4812 ConsumeToken(); |
4813 prefix = ExpectIdentifier("prefix identifier expected")->raw(); | 4813 prefix = ExpectIdentifier("prefix identifier expected")->raw(); |
4814 } | 4814 } |
4815 | 4815 |
4816 Array& show_names = Array::Handle(); | 4816 Array& show_names = Array::Handle(); |
4817 Array& hide_names = Array::Handle(); | 4817 Array& hide_names = Array::Handle(); |
4818 if (IsLiteral("show") || IsLiteral("hide")) { | 4818 if (IsLiteral("show") || IsLiteral("hide")) { |
4819 GrowableObjectArray& show_list = | 4819 GrowableObjectArray& show_list = |
4820 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4820 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
4821 GrowableObjectArray& hide_list = | 4821 GrowableObjectArray& hide_list = |
(...skipping 2511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7333 | 7333 |
7334 | 7334 |
7335 AstNode* Parser::ParseBinaryExpr(int min_preced) { | 7335 AstNode* Parser::ParseBinaryExpr(int min_preced) { |
7336 TRACE_PARSER("ParseBinaryExpr"); | 7336 TRACE_PARSER("ParseBinaryExpr"); |
7337 ASSERT(min_preced >= 4); | 7337 ASSERT(min_preced >= 4); |
7338 AstNode* left_operand = ParseUnaryExpr(); | 7338 AstNode* left_operand = ParseUnaryExpr(); |
7339 if (left_operand->IsPrimaryNode() && | 7339 if (left_operand->IsPrimaryNode() && |
7340 (left_operand->AsPrimaryNode()->IsSuper())) { | 7340 (left_operand->AsPrimaryNode()->IsSuper())) { |
7341 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'"); | 7341 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'"); |
7342 } | 7342 } |
7343 if (IsLiteral("as")) { // Not a reserved word. | |
7344 token_kind_ = Token::kAS; | |
7345 } | |
7346 int current_preced = Token::Precedence(CurrentToken()); | 7343 int current_preced = Token::Precedence(CurrentToken()); |
7347 while (current_preced >= min_preced) { | 7344 while (current_preced >= min_preced) { |
7348 while (Token::Precedence(CurrentToken()) == current_preced) { | 7345 while (Token::Precedence(CurrentToken()) == current_preced) { |
7349 Token::Kind op_kind = CurrentToken(); | 7346 Token::Kind op_kind = CurrentToken(); |
7350 const intptr_t op_pos = TokenPos(); | 7347 const intptr_t op_pos = TokenPos(); |
7351 ConsumeToken(); | 7348 ConsumeToken(); |
7352 AstNode* right_operand = NULL; | 7349 AstNode* right_operand = NULL; |
7353 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { | 7350 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { |
7354 right_operand = ParseBinaryExpr(current_preced + 1); | 7351 right_operand = ParseBinaryExpr(current_preced + 1); |
7355 } else { | 7352 } else { |
(...skipping 3000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10356 SkipPostfixExpr(); | 10353 SkipPostfixExpr(); |
10357 } | 10354 } |
10358 } | 10355 } |
10359 | 10356 |
10360 | 10357 |
10361 void Parser::SkipBinaryExpr() { | 10358 void Parser::SkipBinaryExpr() { |
10362 SkipUnaryExpr(); | 10359 SkipUnaryExpr(); |
10363 const int min_prec = Token::Precedence(Token::kOR); | 10360 const int min_prec = Token::Precedence(Token::kOR); |
10364 const int max_prec = Token::Precedence(Token::kMUL); | 10361 const int max_prec = Token::Precedence(Token::kMUL); |
10365 while (((min_prec <= Token::Precedence(CurrentToken())) && | 10362 while (((min_prec <= Token::Precedence(CurrentToken())) && |
10366 (Token::Precedence(CurrentToken()) <= max_prec)) || | 10363 (Token::Precedence(CurrentToken()) <= max_prec))) { |
10367 IsLiteral("as")) { | 10364 if (CurrentToken() == Token::kIS) { |
10368 Token::Kind last_token = IsLiteral("as") ? Token::kAS : CurrentToken(); | 10365 ConsumeToken(); |
10369 ConsumeToken(); | |
10370 if (last_token == Token::kIS) { | |
10371 if (CurrentToken() == Token::kNOT) { | 10366 if (CurrentToken() == Token::kNOT) { |
10372 ConsumeToken(); | 10367 ConsumeToken(); |
10373 } | 10368 } |
10374 SkipType(false); | 10369 SkipType(false); |
10375 } else if (last_token == Token::kAS) { | 10370 } else if (CurrentToken() == Token::kAS) { |
| 10371 ConsumeToken(); |
10376 SkipType(false); | 10372 SkipType(false); |
10377 } else { | 10373 } else { |
| 10374 ConsumeToken(); |
10378 SkipUnaryExpr(); | 10375 SkipUnaryExpr(); |
10379 } | 10376 } |
10380 } | 10377 } |
10381 } | 10378 } |
10382 | 10379 |
10383 | 10380 |
10384 void Parser::SkipConditionalExpr() { | 10381 void Parser::SkipConditionalExpr() { |
10385 SkipBinaryExpr(); | 10382 SkipBinaryExpr(); |
10386 if (CurrentToken() == Token::kCONDITIONAL) { | 10383 if (CurrentToken() == Token::kCONDITIONAL) { |
10387 ConsumeToken(); | 10384 ConsumeToken(); |
(...skipping 29 matching lines...) Expand all Loading... |
10417 void Parser::SkipQualIdent() { | 10414 void Parser::SkipQualIdent() { |
10418 ASSERT(IsIdentifier()); | 10415 ASSERT(IsIdentifier()); |
10419 ConsumeToken(); | 10416 ConsumeToken(); |
10420 if (CurrentToken() == Token::kPERIOD) { | 10417 if (CurrentToken() == Token::kPERIOD) { |
10421 ConsumeToken(); // Consume the kPERIOD token. | 10418 ConsumeToken(); // Consume the kPERIOD token. |
10422 ExpectIdentifier("identifier expected after '.'"); | 10419 ExpectIdentifier("identifier expected after '.'"); |
10423 } | 10420 } |
10424 } | 10421 } |
10425 | 10422 |
10426 } // namespace dart | 10423 } // namespace dart |
OLD | NEW |