| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 Expression* ParseMemberExpression(bool* ok); | 207 Expression* ParseMemberExpression(bool* ok); |
| 208 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); | 208 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); |
| 209 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack, | 209 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack, |
| 210 bool* ok); | 210 bool* ok); |
| 211 Expression* ParsePrimaryExpression(bool* ok); | 211 Expression* ParsePrimaryExpression(bool* ok); |
| 212 Expression* ParseArrayLiteral(bool* ok); | 212 Expression* ParseArrayLiteral(bool* ok); |
| 213 Expression* ParseObjectLiteral(bool* ok); | 213 Expression* ParseObjectLiteral(bool* ok); |
| 214 ObjectLiteral::Property* ParseObjectLiteralGetSet(bool is_getter, bool* ok); | 214 ObjectLiteral::Property* ParseObjectLiteralGetSet(bool is_getter, bool* ok); |
| 215 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); | 215 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 216 | 216 |
| 217 Expression* NewCompareNode(Token::Value op, Expression* x, Expression* y); | 217 Expression* NewCompareNode(Token::Value op, |
| 218 Expression* x, |
| 219 Expression* y, |
| 220 int position); |
| 218 | 221 |
| 219 // Populate the constant properties fixed array for a materialized object | 222 // Populate the constant properties fixed array for a materialized object |
| 220 // literal. | 223 // literal. |
| 221 void BuildObjectLiteralConstantProperties( | 224 void BuildObjectLiteralConstantProperties( |
| 222 ZoneList<ObjectLiteral::Property*>* properties, | 225 ZoneList<ObjectLiteral::Property*>* properties, |
| 223 Handle<FixedArray> constants, | 226 Handle<FixedArray> constants, |
| 224 bool* is_simple, | 227 bool* is_simple, |
| 225 bool* fast_elements, | 228 bool* fast_elements, |
| 226 int* depth); | 229 int* depth); |
| 227 | 230 |
| (...skipping 2582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2810 | 2813 |
| 2811 // Precedence = 1 | 2814 // Precedence = 1 |
| 2812 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { | 2815 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { |
| 2813 // Expression :: | 2816 // Expression :: |
| 2814 // AssignmentExpression | 2817 // AssignmentExpression |
| 2815 // Expression ',' AssignmentExpression | 2818 // Expression ',' AssignmentExpression |
| 2816 | 2819 |
| 2817 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); | 2820 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 2818 while (peek() == Token::COMMA) { | 2821 while (peek() == Token::COMMA) { |
| 2819 Expect(Token::COMMA, CHECK_OK); | 2822 Expect(Token::COMMA, CHECK_OK); |
| 2823 int position = scanner().location().beg_pos; |
| 2820 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | 2824 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 2821 result = NEW(BinaryOperation(Token::COMMA, result, right)); | 2825 result = NEW(BinaryOperation(Token::COMMA, result, right, position)); |
| 2822 } | 2826 } |
| 2823 return result; | 2827 return result; |
| 2824 } | 2828 } |
| 2825 | 2829 |
| 2826 | 2830 |
| 2827 // Precedence = 2 | 2831 // Precedence = 2 |
| 2828 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { | 2832 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { |
| 2829 // AssignmentExpression :: | 2833 // AssignmentExpression :: |
| 2830 // ConditionalExpression | 2834 // ConditionalExpression |
| 2831 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2835 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2914 | 2918 |
| 2915 | 2919 |
| 2916 // Precedence >= 4 | 2920 // Precedence >= 4 |
| 2917 Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { | 2921 Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { |
| 2918 ASSERT(prec >= 4); | 2922 ASSERT(prec >= 4); |
| 2919 Expression* x = ParseUnaryExpression(CHECK_OK); | 2923 Expression* x = ParseUnaryExpression(CHECK_OK); |
| 2920 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2924 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
| 2921 // prec1 >= 4 | 2925 // prec1 >= 4 |
| 2922 while (Precedence(peek(), accept_IN) == prec1) { | 2926 while (Precedence(peek(), accept_IN) == prec1) { |
| 2923 Token::Value op = Next(); | 2927 Token::Value op = Next(); |
| 2928 int position = scanner().location().beg_pos; |
| 2924 Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); | 2929 Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); |
| 2925 | 2930 |
| 2926 // Compute some expressions involving only number literals. | 2931 // Compute some expressions involving only number literals. |
| 2927 if (x && x->AsLiteral() && x->AsLiteral()->handle()->IsNumber() && | 2932 if (x && x->AsLiteral() && x->AsLiteral()->handle()->IsNumber() && |
| 2928 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) { | 2933 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) { |
| 2929 double x_val = x->AsLiteral()->handle()->Number(); | 2934 double x_val = x->AsLiteral()->handle()->Number(); |
| 2930 double y_val = y->AsLiteral()->handle()->Number(); | 2935 double y_val = y->AsLiteral()->handle()->Number(); |
| 2931 | 2936 |
| 2932 switch (op) { | 2937 switch (op) { |
| 2933 case Token::ADD: | 2938 case Token::ADD: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2997 // operations. (We could combine the two and get rid of this | 3002 // operations. (We could combine the two and get rid of this |
| 2998 // code and AST node eventually.) | 3003 // code and AST node eventually.) |
| 2999 if (Token::IsCompareOp(op)) { | 3004 if (Token::IsCompareOp(op)) { |
| 3000 // We have a comparison. | 3005 // We have a comparison. |
| 3001 Token::Value cmp = op; | 3006 Token::Value cmp = op; |
| 3002 switch (op) { | 3007 switch (op) { |
| 3003 case Token::NE: cmp = Token::EQ; break; | 3008 case Token::NE: cmp = Token::EQ; break; |
| 3004 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; | 3009 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; |
| 3005 default: break; | 3010 default: break; |
| 3006 } | 3011 } |
| 3007 x = NewCompareNode(cmp, x, y); | 3012 x = NewCompareNode(cmp, x, y, position); |
| 3008 if (cmp != op) { | 3013 if (cmp != op) { |
| 3009 // The comparison was negated - add a NOT. | 3014 // The comparison was negated - add a NOT. |
| 3010 x = NEW(UnaryOperation(Token::NOT, x)); | 3015 x = NEW(UnaryOperation(Token::NOT, x)); |
| 3011 } | 3016 } |
| 3012 | 3017 |
| 3013 } else { | 3018 } else { |
| 3014 // We have a "normal" binary operation. | 3019 // We have a "normal" binary operation. |
| 3015 x = NEW(BinaryOperation(op, x, y)); | 3020 x = NEW(BinaryOperation(op, x, y, position)); |
| 3016 } | 3021 } |
| 3017 } | 3022 } |
| 3018 } | 3023 } |
| 3019 return x; | 3024 return x; |
| 3020 } | 3025 } |
| 3021 | 3026 |
| 3022 | 3027 |
| 3023 Expression* Parser::NewCompareNode(Token::Value op, | 3028 Expression* Parser::NewCompareNode(Token::Value op, |
| 3024 Expression* x, | 3029 Expression* x, |
| 3025 Expression* y) { | 3030 Expression* y, |
| 3031 int position) { |
| 3026 ASSERT(op != Token::NE && op != Token::NE_STRICT); | 3032 ASSERT(op != Token::NE && op != Token::NE_STRICT); |
| 3027 if (!is_pre_parsing_ && (op == Token::EQ || op == Token::EQ_STRICT)) { | 3033 if (!is_pre_parsing_ && (op == Token::EQ || op == Token::EQ_STRICT)) { |
| 3028 bool is_strict = (op == Token::EQ_STRICT); | 3034 bool is_strict = (op == Token::EQ_STRICT); |
| 3029 Literal* x_literal = x->AsLiteral(); | 3035 Literal* x_literal = x->AsLiteral(); |
| 3030 if (x_literal != NULL && x_literal->IsNull()) { | 3036 if (x_literal != NULL && x_literal->IsNull()) { |
| 3031 return NEW(CompareToNull(is_strict, y)); | 3037 return NEW(CompareToNull(is_strict, y)); |
| 3032 } | 3038 } |
| 3033 | 3039 |
| 3034 Literal* y_literal = y->AsLiteral(); | 3040 Literal* y_literal = y->AsLiteral(); |
| 3035 if (y_literal != NULL && y_literal->IsNull()) { | 3041 if (y_literal != NULL && y_literal->IsNull()) { |
| 3036 return NEW(CompareToNull(is_strict, x)); | 3042 return NEW(CompareToNull(is_strict, x)); |
| 3037 } | 3043 } |
| 3038 } | 3044 } |
| 3039 return NEW(CompareOperation(op, x, y)); | 3045 return NEW(CompareOperation(op, x, y, position)); |
| 3040 } | 3046 } |
| 3041 | 3047 |
| 3042 | 3048 |
| 3043 Expression* Parser::ParseUnaryExpression(bool* ok) { | 3049 Expression* Parser::ParseUnaryExpression(bool* ok) { |
| 3044 // UnaryExpression :: | 3050 // UnaryExpression :: |
| 3045 // PostfixExpression | 3051 // PostfixExpression |
| 3046 // 'delete' UnaryExpression | 3052 // 'delete' UnaryExpression |
| 3047 // 'void' UnaryExpression | 3053 // 'void' UnaryExpression |
| 3048 // 'typeof' UnaryExpression | 3054 // 'typeof' UnaryExpression |
| 3049 // '++' UnaryExpression | 3055 // '++' UnaryExpression |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3079 op = Next(); | 3085 op = Next(); |
| 3080 Expression* expression = ParseUnaryExpression(CHECK_OK); | 3086 Expression* expression = ParseUnaryExpression(CHECK_OK); |
| 3081 // Signal a reference error if the expression is an invalid | 3087 // Signal a reference error if the expression is an invalid |
| 3082 // left-hand side expression. We could report this as a syntax | 3088 // left-hand side expression. We could report this as a syntax |
| 3083 // error here but for compatibility with JSC we choose to report the | 3089 // error here but for compatibility with JSC we choose to report the |
| 3084 // error at runtime. | 3090 // error at runtime. |
| 3085 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3091 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
| 3086 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol(); | 3092 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol(); |
| 3087 expression = NewThrowReferenceError(type); | 3093 expression = NewThrowReferenceError(type); |
| 3088 } | 3094 } |
| 3095 int position = scanner().location().beg_pos; |
| 3089 IncrementOperation* increment = NEW(IncrementOperation(op, expression)); | 3096 IncrementOperation* increment = NEW(IncrementOperation(op, expression)); |
| 3090 return NEW(CountOperation(true /* prefix */, increment)); | 3097 return NEW(CountOperation(true /* prefix */, increment, position)); |
| 3091 | 3098 |
| 3092 } else { | 3099 } else { |
| 3093 return ParsePostfixExpression(ok); | 3100 return ParsePostfixExpression(ok); |
| 3094 } | 3101 } |
| 3095 } | 3102 } |
| 3096 | 3103 |
| 3097 | 3104 |
| 3098 Expression* Parser::ParsePostfixExpression(bool* ok) { | 3105 Expression* Parser::ParsePostfixExpression(bool* ok) { |
| 3099 // PostfixExpression :: | 3106 // PostfixExpression :: |
| 3100 // LeftHandSideExpression ('++' | '--')? | 3107 // LeftHandSideExpression ('++' | '--')? |
| 3101 | 3108 |
| 3102 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); | 3109 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); |
| 3103 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) { | 3110 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) { |
| 3104 // Signal a reference error if the expression is an invalid | 3111 // Signal a reference error if the expression is an invalid |
| 3105 // left-hand side expression. We could report this as a syntax | 3112 // left-hand side expression. We could report this as a syntax |
| 3106 // error here but for compatibility with JSC we choose to report the | 3113 // error here but for compatibility with JSC we choose to report the |
| 3107 // error at runtime. | 3114 // error at runtime. |
| 3108 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3115 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
| 3109 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); | 3116 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); |
| 3110 expression = NewThrowReferenceError(type); | 3117 expression = NewThrowReferenceError(type); |
| 3111 } | 3118 } |
| 3112 Token::Value next = Next(); | 3119 Token::Value next = Next(); |
| 3120 int position = scanner().location().beg_pos; |
| 3113 IncrementOperation* increment = NEW(IncrementOperation(next, expression)); | 3121 IncrementOperation* increment = NEW(IncrementOperation(next, expression)); |
| 3114 expression = NEW(CountOperation(false /* postfix */, increment)); | 3122 expression = NEW(CountOperation(false /* postfix */, increment, position)); |
| 3115 } | 3123 } |
| 3116 return expression; | 3124 return expression; |
| 3117 } | 3125 } |
| 3118 | 3126 |
| 3119 | 3127 |
| 3120 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { | 3128 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { |
| 3121 // LeftHandSideExpression :: | 3129 // LeftHandSideExpression :: |
| 3122 // (NewExpression | MemberExpression) ... | 3130 // (NewExpression | MemberExpression) ... |
| 3123 | 3131 |
| 3124 Expression* result; | 3132 Expression* result; |
| (...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5314 parser.ParseLazy(script_source, name, | 5322 parser.ParseLazy(script_source, name, |
| 5315 start_position, end_position, is_expression); | 5323 start_position, end_position, is_expression); |
| 5316 return result; | 5324 return result; |
| 5317 } | 5325 } |
| 5318 | 5326 |
| 5319 | 5327 |
| 5320 #undef NEW | 5328 #undef NEW |
| 5321 | 5329 |
| 5322 | 5330 |
| 5323 } } // namespace v8::internal | 5331 } } // namespace v8::internal |
| OLD | NEW |