| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 Statement* ParseNativeDeclaration(bool* ok); | 113 Statement* ParseNativeDeclaration(bool* ok); |
| 114 Block* ParseBlock(ZoneStringList* labels, bool* ok); | 114 Block* ParseBlock(ZoneStringList* labels, bool* ok); |
| 115 Block* ParseVariableStatement(bool* ok); | 115 Block* ParseVariableStatement(bool* ok); |
| 116 Block* ParseVariableDeclarations(bool accept_IN, Expression** var, bool* ok); | 116 Block* ParseVariableDeclarations(bool accept_IN, Expression** var, bool* ok); |
| 117 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, | 117 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, |
| 118 bool* ok); | 118 bool* ok); |
| 119 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); | 119 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); |
| 120 Statement* ParseContinueStatement(bool* ok); | 120 Statement* ParseContinueStatement(bool* ok); |
| 121 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); | 121 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); |
| 122 Statement* ParseReturnStatement(bool* ok); | 122 Statement* ParseReturnStatement(bool* ok); |
| 123 Block* WithHelper(Expression* obj, ZoneStringList* labels, bool* ok); | 123 Block* WithHelper(Expression* obj, |
| 124 ZoneStringList* labels, |
| 125 bool is_catch_block, |
| 126 bool* ok); |
| 124 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); | 127 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); |
| 125 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); | 128 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); |
| 126 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); | 129 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); |
| 127 LoopStatement* ParseDoStatement(ZoneStringList* labels, bool* ok); | 130 LoopStatement* ParseDoStatement(ZoneStringList* labels, bool* ok); |
| 128 LoopStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 131 LoopStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
| 129 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 132 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
| 130 Statement* ParseThrowStatement(bool* ok); | 133 Statement* ParseThrowStatement(bool* ok); |
| 131 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 134 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
| 132 TryStatement* ParseTryStatement(bool* ok); | 135 TryStatement* ParseTryStatement(bool* ok); |
| 133 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 136 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 characters_ = NULL; | 466 characters_ = NULL; |
| 464 atom = new RegExpAtom(char_vector); | 467 atom = new RegExpAtom(char_vector); |
| 465 FlushText(); | 468 FlushText(); |
| 466 } else if (text_.length() > 0) { | 469 } else if (text_.length() > 0) { |
| 467 ASSERT(last_added_ == ADD_ATOM); | 470 ASSERT(last_added_ == ADD_ATOM); |
| 468 atom = text_.RemoveLast(); | 471 atom = text_.RemoveLast(); |
| 469 FlushText(); | 472 FlushText(); |
| 470 } else if (terms_.length() > 0) { | 473 } else if (terms_.length() > 0) { |
| 471 ASSERT(last_added_ == ADD_ATOM); | 474 ASSERT(last_added_ == ADD_ATOM); |
| 472 atom = terms_.RemoveLast(); | 475 atom = terms_.RemoveLast(); |
| 473 if (atom->IsLookahead() || atom->IsAssertion()) { | 476 if (atom->max_match() == 0) { |
| 474 // Guaranteed not to match a non-empty string. | 477 // Guaranteed to only match an empty string. |
| 475 // Assertion as an atom can happen as, e.g., (?:\b) | |
| 476 LAST(ADD_TERM); | 478 LAST(ADD_TERM); |
| 477 if (min == 0) { | 479 if (min == 0) { |
| 478 return; | 480 return; |
| 479 } | 481 } |
| 480 terms_.Add(atom); | 482 terms_.Add(atom); |
| 481 return; | 483 return; |
| 482 } | 484 } |
| 483 } else { | 485 } else { |
| 484 // Only call immediately after adding an atom or character! | 486 // Only call immediately after adding an atom or character! |
| 485 UNREACHABLE(); | 487 UNREACHABLE(); |
| (...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 ExpectSemicolon(CHECK_OK); | 1919 ExpectSemicolon(CHECK_OK); |
| 1918 return NEW(ReturnStatement(GetLiteralUndefined())); | 1920 return NEW(ReturnStatement(GetLiteralUndefined())); |
| 1919 } | 1921 } |
| 1920 | 1922 |
| 1921 Expression* expr = ParseExpression(true, CHECK_OK); | 1923 Expression* expr = ParseExpression(true, CHECK_OK); |
| 1922 ExpectSemicolon(CHECK_OK); | 1924 ExpectSemicolon(CHECK_OK); |
| 1923 return NEW(ReturnStatement(expr)); | 1925 return NEW(ReturnStatement(expr)); |
| 1924 } | 1926 } |
| 1925 | 1927 |
| 1926 | 1928 |
| 1927 Block* Parser::WithHelper(Expression* obj, ZoneStringList* labels, bool* ok) { | 1929 Block* Parser::WithHelper(Expression* obj, |
| 1930 ZoneStringList* labels, |
| 1931 bool is_catch_block, |
| 1932 bool* ok) { |
| 1928 // Parse the statement and collect escaping labels. | 1933 // Parse the statement and collect escaping labels. |
| 1929 ZoneList<JumpTarget*>* target_list = NEW(ZoneList<JumpTarget*>(0)); | 1934 ZoneList<JumpTarget*>* target_list = NEW(ZoneList<JumpTarget*>(0)); |
| 1930 TargetCollector collector(target_list); | 1935 TargetCollector collector(target_list); |
| 1931 Statement* stat; | 1936 Statement* stat; |
| 1932 { Target target(this, &collector); | 1937 { Target target(this, &collector); |
| 1933 with_nesting_level_++; | 1938 with_nesting_level_++; |
| 1934 top_scope_->RecordWithStatement(); | 1939 top_scope_->RecordWithStatement(); |
| 1935 stat = ParseStatement(labels, CHECK_OK); | 1940 stat = ParseStatement(labels, CHECK_OK); |
| 1936 with_nesting_level_--; | 1941 with_nesting_level_--; |
| 1937 } | 1942 } |
| 1938 // Create resulting block with two statements. | 1943 // Create resulting block with two statements. |
| 1939 // 1: Evaluate the with expression. | 1944 // 1: Evaluate the with expression. |
| 1940 // 2: The try-finally block evaluating the body. | 1945 // 2: The try-finally block evaluating the body. |
| 1941 Block* result = NEW(Block(NULL, 2, false)); | 1946 Block* result = NEW(Block(NULL, 2, false)); |
| 1942 | 1947 |
| 1943 if (result != NULL) { | 1948 if (result != NULL) { |
| 1944 result->AddStatement(NEW(WithEnterStatement(obj))); | 1949 result->AddStatement(NEW(WithEnterStatement(obj, is_catch_block))); |
| 1945 | 1950 |
| 1946 // Create body block. | 1951 // Create body block. |
| 1947 Block* body = NEW(Block(NULL, 1, false)); | 1952 Block* body = NEW(Block(NULL, 1, false)); |
| 1948 body->AddStatement(stat); | 1953 body->AddStatement(stat); |
| 1949 | 1954 |
| 1950 // Create exit block. | 1955 // Create exit block. |
| 1951 Block* exit = NEW(Block(NULL, 1, false)); | 1956 Block* exit = NEW(Block(NULL, 1, false)); |
| 1952 exit->AddStatement(NEW(WithExitStatement())); | 1957 exit->AddStatement(NEW(WithExitStatement())); |
| 1953 | 1958 |
| 1954 // Return a try-finally statement. | 1959 // Return a try-finally statement. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1968 // code. If 'with' statements were allowed, the simplified setup of | 1973 // code. If 'with' statements were allowed, the simplified setup of |
| 1969 // the runtime context chain would allow access to properties in the | 1974 // the runtime context chain would allow access to properties in the |
| 1970 // global object from within a 'with' statement. | 1975 // global object from within a 'with' statement. |
| 1971 ASSERT(!Bootstrapper::IsActive()); | 1976 ASSERT(!Bootstrapper::IsActive()); |
| 1972 | 1977 |
| 1973 Expect(Token::WITH, CHECK_OK); | 1978 Expect(Token::WITH, CHECK_OK); |
| 1974 Expect(Token::LPAREN, CHECK_OK); | 1979 Expect(Token::LPAREN, CHECK_OK); |
| 1975 Expression* expr = ParseExpression(true, CHECK_OK); | 1980 Expression* expr = ParseExpression(true, CHECK_OK); |
| 1976 Expect(Token::RPAREN, CHECK_OK); | 1981 Expect(Token::RPAREN, CHECK_OK); |
| 1977 | 1982 |
| 1978 return WithHelper(expr, labels, CHECK_OK); | 1983 return WithHelper(expr, labels, false, CHECK_OK); |
| 1979 } | 1984 } |
| 1980 | 1985 |
| 1981 | 1986 |
| 1982 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 1987 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
| 1983 // CaseClause :: | 1988 // CaseClause :: |
| 1984 // 'case' Expression ':' Statement* | 1989 // 'case' Expression ':' Statement* |
| 1985 // 'default' ':' Statement* | 1990 // 'default' ':' Statement* |
| 1986 | 1991 |
| 1987 Expression* label = NULL; // NULL expression indicates default case | 1992 Expression* label = NULL; // NULL expression indicates default case |
| 1988 if (peek() == Token::CASE) { | 1993 if (peek() == Token::CASE) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 Expect(Token::LPAREN, CHECK_OK); | 2135 Expect(Token::LPAREN, CHECK_OK); |
| 2131 Handle<String> name = ParseIdentifier(CHECK_OK); | 2136 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 2132 Expect(Token::RPAREN, CHECK_OK); | 2137 Expect(Token::RPAREN, CHECK_OK); |
| 2133 | 2138 |
| 2134 if (peek() == Token::LBRACE) { | 2139 if (peek() == Token::LBRACE) { |
| 2135 // Allocate a temporary for holding the finally state while | 2140 // Allocate a temporary for holding the finally state while |
| 2136 // executing the finally block. | 2141 // executing the finally block. |
| 2137 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol()); | 2142 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol()); |
| 2138 Expression* obj = MakeCatchContext(name, catch_var); | 2143 Expression* obj = MakeCatchContext(name, catch_var); |
| 2139 { Target target(this, &catch_collector); | 2144 { Target target(this, &catch_collector); |
| 2140 catch_block = WithHelper(obj, NULL, CHECK_OK); | 2145 catch_block = WithHelper(obj, NULL, true, CHECK_OK); |
| 2141 } | 2146 } |
| 2142 } else { | 2147 } else { |
| 2143 Expect(Token::LBRACE, CHECK_OK); | 2148 Expect(Token::LBRACE, CHECK_OK); |
| 2144 } | 2149 } |
| 2145 | 2150 |
| 2146 tok = peek(); | 2151 tok = peek(); |
| 2147 } | 2152 } |
| 2148 | 2153 |
| 2149 if (tok == Token::FINALLY || !has_catch) { | 2154 if (tok == Token::FINALLY || !has_catch) { |
| 2150 Consume(Token::FINALLY); | 2155 Consume(Token::FINALLY); |
| (...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3789 int min; | 3794 int min; |
| 3790 int max; | 3795 int max; |
| 3791 switch (current()) { | 3796 switch (current()) { |
| 3792 // QuantifierPrefix :: | 3797 // QuantifierPrefix :: |
| 3793 // * | 3798 // * |
| 3794 // + | 3799 // + |
| 3795 // ? | 3800 // ? |
| 3796 // { | 3801 // { |
| 3797 case '*': | 3802 case '*': |
| 3798 min = 0; | 3803 min = 0; |
| 3799 max = RegExpQuantifier::kInfinity; | 3804 max = RegExpTree::kInfinity; |
| 3800 Advance(); | 3805 Advance(); |
| 3801 break; | 3806 break; |
| 3802 case '+': | 3807 case '+': |
| 3803 min = 1; | 3808 min = 1; |
| 3804 max = RegExpQuantifier::kInfinity; | 3809 max = RegExpTree::kInfinity; |
| 3805 Advance(); | 3810 Advance(); |
| 3806 break; | 3811 break; |
| 3807 case '?': | 3812 case '?': |
| 3808 min = 0; | 3813 min = 0; |
| 3809 max = 1; | 3814 max = 1; |
| 3810 Advance(); | 3815 Advance(); |
| 3811 break; | 3816 break; |
| 3812 case '{': | 3817 case '{': |
| 3813 if (ParseIntervalQuantifier(&min, &max)) { | 3818 if (ParseIntervalQuantifier(&min, &max)) { |
| 3814 break; | 3819 break; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3960 min = 10 * min + (current() - '0'); | 3965 min = 10 * min + (current() - '0'); |
| 3961 Advance(); | 3966 Advance(); |
| 3962 } | 3967 } |
| 3963 int max = 0; | 3968 int max = 0; |
| 3964 if (current() == '}') { | 3969 if (current() == '}') { |
| 3965 max = min; | 3970 max = min; |
| 3966 Advance(); | 3971 Advance(); |
| 3967 } else if (current() == ',') { | 3972 } else if (current() == ',') { |
| 3968 Advance(); | 3973 Advance(); |
| 3969 if (current() == '}') { | 3974 if (current() == '}') { |
| 3970 max = RegExpQuantifier::kInfinity; | 3975 max = RegExpTree::kInfinity; |
| 3971 Advance(); | 3976 Advance(); |
| 3972 } else { | 3977 } else { |
| 3973 while (IsDecimalDigit(current())) { | 3978 while (IsDecimalDigit(current())) { |
| 3974 max = 10 * max + (current() - '0'); | 3979 max = 10 * max + (current() - '0'); |
| 3975 Advance(); | 3980 Advance(); |
| 3976 } | 3981 } |
| 3977 if (current() != '}') { | 3982 if (current() != '}') { |
| 3978 Reset(start); | 3983 Reset(start); |
| 3979 return false; | 3984 return false; |
| 3980 } | 3985 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4179 CharacterRange RegExpParser::ParseClassAtom(uc16* char_class) { | 4184 CharacterRange RegExpParser::ParseClassAtom(uc16* char_class) { |
| 4180 ASSERT_EQ(0, *char_class); | 4185 ASSERT_EQ(0, *char_class); |
| 4181 uc32 first = current(); | 4186 uc32 first = current(); |
| 4182 if (first == '\\') { | 4187 if (first == '\\') { |
| 4183 switch (Next()) { | 4188 switch (Next()) { |
| 4184 case 'w': case 'W': case 'd': case 'D': case 's': case 'S': { | 4189 case 'w': case 'W': case 'd': case 'D': case 's': case 'S': { |
| 4185 *char_class = Next(); | 4190 *char_class = Next(); |
| 4186 Advance(2); | 4191 Advance(2); |
| 4187 return CharacterRange::Singleton(0); // Return dummy value. | 4192 return CharacterRange::Singleton(0); // Return dummy value. |
| 4188 } | 4193 } |
| 4194 case kEndMarker: |
| 4195 ReportError(CStrVector("\\ at end of pattern") CHECK_FAILED); |
| 4189 default: | 4196 default: |
| 4190 uc32 c = ParseClassCharacterEscape(CHECK_FAILED); | 4197 uc32 c = ParseClassCharacterEscape(CHECK_FAILED); |
| 4191 return CharacterRange::Singleton(c); | 4198 return CharacterRange::Singleton(c); |
| 4192 } | 4199 } |
| 4193 } else { | 4200 } else { |
| 4194 Advance(); | 4201 Advance(); |
| 4195 return CharacterRange::Singleton(first); | 4202 return CharacterRange::Singleton(first); |
| 4196 } | 4203 } |
| 4197 } | 4204 } |
| 4198 | 4205 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4370 start_position, | 4377 start_position, |
| 4371 is_expression); | 4378 is_expression); |
| 4372 return result; | 4379 return result; |
| 4373 } | 4380 } |
| 4374 | 4381 |
| 4375 | 4382 |
| 4376 #undef NEW | 4383 #undef NEW |
| 4377 | 4384 |
| 4378 | 4385 |
| 4379 } } // namespace v8::internal | 4386 } } // namespace v8::internal |
| OLD | NEW |