| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 bool is_generator, | 631 bool is_generator, |
| 632 int function_token_position, | 632 int function_token_position, |
| 633 FunctionLiteral::FunctionType type, | 633 FunctionLiteral::FunctionType type, |
| 634 bool* ok) { | 634 bool* ok) { |
| 635 return parser_->ParseFunctionLiteral(name, function_name_location, | 635 return parser_->ParseFunctionLiteral(name, function_name_location, |
| 636 name_is_strict_reserved, is_generator, | 636 name_is_strict_reserved, is_generator, |
| 637 function_token_position, type, ok); | 637 function_token_position, type, ok); |
| 638 } | 638 } |
| 639 | 639 |
| 640 | 640 |
| 641 Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool* ok) { | 641 Expression* ParserTraits::ParseBinaryExpression(int prec, bool accept_IN, |
| 642 return parser_->ParseConditionalExpression(accept_IN, ok); | 642 bool* ok) { |
| 643 return parser_->ParseBinaryExpression(prec, accept_IN, ok); |
| 643 } | 644 } |
| 644 | 645 |
| 645 | 646 |
| 646 Parser::Parser(CompilationInfo* info) | 647 Parser::Parser(CompilationInfo* info) |
| 647 : ParserBase<ParserTraits>(&scanner_, | 648 : ParserBase<ParserTraits>(&scanner_, |
| 648 info->isolate()->stack_guard()->real_climit(), | 649 info->isolate()->stack_guard()->real_climit(), |
| 649 info->extension(), | 650 info->extension(), |
| 650 info->zone(), | 651 info->zone(), |
| 651 this), | 652 this), |
| 652 isolate_(info->isolate()), | 653 isolate_(info->isolate()), |
| (...skipping 2270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2923 result->set_scope(for_scope); | 2924 result->set_scope(for_scope); |
| 2924 loop->Initialize(NULL, cond, next, body); | 2925 loop->Initialize(NULL, cond, next, body); |
| 2925 return result; | 2926 return result; |
| 2926 } else { | 2927 } else { |
| 2927 loop->Initialize(init, cond, next, body); | 2928 loop->Initialize(init, cond, next, body); |
| 2928 return loop; | 2929 return loop; |
| 2929 } | 2930 } |
| 2930 } | 2931 } |
| 2931 | 2932 |
| 2932 | 2933 |
| 2933 // Precedence = 3 | |
| 2934 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { | |
| 2935 // ConditionalExpression :: | |
| 2936 // LogicalOrExpression | |
| 2937 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | |
| 2938 | |
| 2939 int pos = peek_position(); | |
| 2940 // We start using the binary expression parser for prec >= 4 only! | |
| 2941 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); | |
| 2942 if (peek() != Token::CONDITIONAL) return expression; | |
| 2943 Consume(Token::CONDITIONAL); | |
| 2944 // In parsing the first assignment expression in conditional | |
| 2945 // expressions we always accept the 'in' keyword; see ECMA-262, | |
| 2946 // section 11.12, page 58. | |
| 2947 Expression* left = ParseAssignmentExpression(true, CHECK_OK); | |
| 2948 Expect(Token::COLON, CHECK_OK); | |
| 2949 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | |
| 2950 return factory()->NewConditional(expression, left, right, pos); | |
| 2951 } | |
| 2952 | |
| 2953 | |
| 2954 // Precedence >= 4 | 2934 // Precedence >= 4 |
| 2955 Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { | 2935 Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { |
| 2956 ASSERT(prec >= 4); | 2936 ASSERT(prec >= 4); |
| 2957 Expression* x = ParseUnaryExpression(CHECK_OK); | 2937 Expression* x = ParseUnaryExpression(CHECK_OK); |
| 2958 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2938 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
| 2959 // prec1 >= 4 | 2939 // prec1 >= 4 |
| 2960 while (Precedence(peek(), accept_IN) == prec1) { | 2940 while (Precedence(peek(), accept_IN) == prec1) { |
| 2961 Token::Value op = Next(); | 2941 Token::Value op = Next(); |
| 2962 int pos = position(); | 2942 int pos = position(); |
| 2963 Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); | 2943 Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); |
| (...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5006 ASSERT(info()->isolate()->has_pending_exception()); | 4986 ASSERT(info()->isolate()->has_pending_exception()); |
| 5007 } else { | 4987 } else { |
| 5008 result = ParseProgram(); | 4988 result = ParseProgram(); |
| 5009 } | 4989 } |
| 5010 } | 4990 } |
| 5011 info()->SetFunction(result); | 4991 info()->SetFunction(result); |
| 5012 return (result != NULL); | 4992 return (result != NULL); |
| 5013 } | 4993 } |
| 5014 | 4994 |
| 5015 } } // namespace v8::internal | 4995 } } // namespace v8::internal |
| OLD | NEW |