| 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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 scanner_(isolate_), | 589 scanner_(isolate_), |
| 590 top_scope_(NULL), | 590 top_scope_(NULL), |
| 591 with_nesting_level_(0), | 591 with_nesting_level_(0), |
| 592 temp_scope_(NULL), | 592 temp_scope_(NULL), |
| 593 target_stack_(NULL), | 593 target_stack_(NULL), |
| 594 allow_natives_syntax_(allow_natives_syntax), | 594 allow_natives_syntax_(allow_natives_syntax), |
| 595 extension_(extension), | 595 extension_(extension), |
| 596 pre_data_(pre_data), | 596 pre_data_(pre_data), |
| 597 fni_(NULL), | 597 fni_(NULL), |
| 598 stack_overflow_(false) { | 598 stack_overflow_(false) { |
| 599 AstNode::ResetIds(); |
| 599 } | 600 } |
| 600 | 601 |
| 601 | 602 |
| 602 FunctionLiteral* Parser::ParseProgram(Handle<String> source, | 603 FunctionLiteral* Parser::ParseProgram(Handle<String> source, |
| 603 bool in_global_context) { | 604 bool in_global_context) { |
| 604 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); | 605 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); |
| 605 | 606 |
| 606 HistogramTimerScope timer(COUNTERS->parse()); | 607 HistogramTimerScope timer(COUNTERS->parse()); |
| 607 COUNTERS->total_parse_size()->Increment(source->length()); | 608 COUNTERS->total_parse_size()->Increment(source->length()); |
| 608 fni_ = new FuncNameInferrer(); | 609 fni_ = new FuncNameInferrer(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 } | 700 } |
| 700 | 701 |
| 701 // Make sure the target stack is empty. | 702 // Make sure the target stack is empty. |
| 702 ASSERT(target_stack_ == NULL); | 703 ASSERT(target_stack_ == NULL); |
| 703 | 704 |
| 704 // If there was a stack overflow we have to get rid of AST and it is | 705 // If there was a stack overflow we have to get rid of AST and it is |
| 705 // not safe to do before scope has been deleted. | 706 // not safe to do before scope has been deleted. |
| 706 if (result == NULL) { | 707 if (result == NULL) { |
| 707 Isolate::Current()->StackOverflow(); | 708 Isolate::Current()->StackOverflow(); |
| 708 zone_scope.DeleteOnExit(); | 709 zone_scope.DeleteOnExit(); |
| 710 } else { |
| 711 Handle<String> inferred_name(info->inferred_name()); |
| 712 result->set_inferred_name(inferred_name); |
| 709 } | 713 } |
| 710 return result; | 714 return result; |
| 711 } | 715 } |
| 712 | 716 |
| 713 | 717 |
| 714 Handle<String> Parser::GetSymbol(bool* ok) { | 718 Handle<String> Parser::GetSymbol(bool* ok) { |
| 715 int symbol_id = -1; | 719 int symbol_id = -1; |
| 716 if (pre_data() != NULL) { | 720 if (pre_data() != NULL) { |
| 717 symbol_id = pre_data()->GetSymbolIdentifier(); | 721 symbol_id = pre_data()->GetSymbolIdentifier(); |
| 718 } | 722 } |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 Expect(Token::DEFAULT, CHECK_OK); | 1792 Expect(Token::DEFAULT, CHECK_OK); |
| 1789 if (*default_seen_ptr) { | 1793 if (*default_seen_ptr) { |
| 1790 ReportMessage("multiple_defaults_in_switch", | 1794 ReportMessage("multiple_defaults_in_switch", |
| 1791 Vector<const char*>::empty()); | 1795 Vector<const char*>::empty()); |
| 1792 *ok = false; | 1796 *ok = false; |
| 1793 return NULL; | 1797 return NULL; |
| 1794 } | 1798 } |
| 1795 *default_seen_ptr = true; | 1799 *default_seen_ptr = true; |
| 1796 } | 1800 } |
| 1797 Expect(Token::COLON, CHECK_OK); | 1801 Expect(Token::COLON, CHECK_OK); |
| 1798 | 1802 int pos = scanner().location().beg_pos; |
| 1799 ZoneList<Statement*>* statements = new ZoneList<Statement*>(5); | 1803 ZoneList<Statement*>* statements = new ZoneList<Statement*>(5); |
| 1800 while (peek() != Token::CASE && | 1804 while (peek() != Token::CASE && |
| 1801 peek() != Token::DEFAULT && | 1805 peek() != Token::DEFAULT && |
| 1802 peek() != Token::RBRACE) { | 1806 peek() != Token::RBRACE) { |
| 1803 Statement* stat = ParseStatement(NULL, CHECK_OK); | 1807 Statement* stat = ParseStatement(NULL, CHECK_OK); |
| 1804 statements->Add(stat); | 1808 statements->Add(stat); |
| 1805 } | 1809 } |
| 1806 | 1810 |
| 1807 return new CaseClause(label, statements); | 1811 return new CaseClause(label, statements, pos); |
| 1808 } | 1812 } |
| 1809 | 1813 |
| 1810 | 1814 |
| 1811 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, | 1815 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, |
| 1812 bool* ok) { | 1816 bool* ok) { |
| 1813 // SwitchStatement :: | 1817 // SwitchStatement :: |
| 1814 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 1818 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
| 1815 | 1819 |
| 1816 SwitchStatement* statement = new SwitchStatement(labels); | 1820 SwitchStatement* statement = new SwitchStatement(labels); |
| 1817 Target target(&this->target_stack_, statement); | 1821 Target target(&this->target_stack_, statement); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 | 1873 |
| 1870 ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0); | 1874 ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0); |
| 1871 TargetCollector collector(target_list); | 1875 TargetCollector collector(target_list); |
| 1872 Block* try_block; | 1876 Block* try_block; |
| 1873 | 1877 |
| 1874 { Target target(&this->target_stack_, &collector); | 1878 { Target target(&this->target_stack_, &collector); |
| 1875 try_block = ParseBlock(NULL, CHECK_OK); | 1879 try_block = ParseBlock(NULL, CHECK_OK); |
| 1876 } | 1880 } |
| 1877 | 1881 |
| 1878 Block* catch_block = NULL; | 1882 Block* catch_block = NULL; |
| 1879 VariableProxy* catch_var = NULL; | 1883 Variable* catch_var = NULL; |
| 1880 Block* finally_block = NULL; | 1884 Block* finally_block = NULL; |
| 1881 | 1885 |
| 1882 Token::Value tok = peek(); | 1886 Token::Value tok = peek(); |
| 1883 if (tok != Token::CATCH && tok != Token::FINALLY) { | 1887 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 1884 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); | 1888 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); |
| 1885 *ok = false; | 1889 *ok = false; |
| 1886 return NULL; | 1890 return NULL; |
| 1887 } | 1891 } |
| 1888 | 1892 |
| 1889 // If we can break out from the catch block and there is a finally block, | 1893 // If we can break out from the catch block and there is a finally block, |
| 1890 // then we will need to collect jump targets from the catch block. Since | 1894 // then we will need to collect jump targets from the catch block. Since |
| 1891 // we don't know yet if there will be a finally block, we always collect | 1895 // we don't know yet if there will be a finally block, we always collect |
| 1892 // the jump targets. | 1896 // the jump targets. |
| 1893 ZoneList<BreakTarget*>* catch_target_list = new ZoneList<BreakTarget*>(0); | 1897 ZoneList<BreakTarget*>* catch_target_list = new ZoneList<BreakTarget*>(0); |
| 1894 TargetCollector catch_collector(catch_target_list); | 1898 TargetCollector catch_collector(catch_target_list); |
| 1895 bool has_catch = false; | 1899 bool has_catch = false; |
| 1896 if (tok == Token::CATCH) { | 1900 if (tok == Token::CATCH) { |
| 1897 has_catch = true; | 1901 has_catch = true; |
| 1898 Consume(Token::CATCH); | 1902 Consume(Token::CATCH); |
| 1899 | 1903 |
| 1900 Expect(Token::LPAREN, CHECK_OK); | 1904 Expect(Token::LPAREN, CHECK_OK); |
| 1901 Handle<String> name = ParseIdentifier(CHECK_OK); | 1905 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 1902 Expect(Token::RPAREN, CHECK_OK); | 1906 Expect(Token::RPAREN, CHECK_OK); |
| 1903 | 1907 |
| 1904 if (peek() == Token::LBRACE) { | 1908 if (peek() == Token::LBRACE) { |
| 1905 // Allocate a temporary for holding the finally state while | 1909 // Allocate a temporary for holding the finally state while |
| 1906 // executing the finally block. | 1910 // executing the finally block. |
| 1907 catch_var = top_scope_->NewTemporary(FACTORY->catch_var_symbol()); | 1911 catch_var = top_scope_->NewTemporary(FACTORY->catch_var_symbol()); |
| 1908 Literal* name_literal = new Literal(name); | 1912 Literal* name_literal = new Literal(name); |
| 1909 Expression* obj = new CatchExtensionObject(name_literal, catch_var); | 1913 VariableProxy* catch_var_use = new VariableProxy(catch_var); |
| 1914 Expression* obj = new CatchExtensionObject(name_literal, catch_var_use); |
| 1910 { Target target(&this->target_stack_, &catch_collector); | 1915 { Target target(&this->target_stack_, &catch_collector); |
| 1911 catch_block = WithHelper(obj, NULL, true, CHECK_OK); | 1916 catch_block = WithHelper(obj, NULL, true, CHECK_OK); |
| 1912 } | 1917 } |
| 1913 } else { | 1918 } else { |
| 1914 Expect(Token::LBRACE, CHECK_OK); | 1919 Expect(Token::LBRACE, CHECK_OK); |
| 1915 } | 1920 } |
| 1916 | 1921 |
| 1917 tok = peek(); | 1922 tok = peek(); |
| 1918 } | 1923 } |
| 1919 | 1924 |
| 1920 if (tok == Token::FINALLY || !has_catch) { | 1925 if (tok == Token::FINALLY || !has_catch) { |
| 1921 Consume(Token::FINALLY); | 1926 Consume(Token::FINALLY); |
| 1922 // Declare a variable for holding the finally state while | 1927 // Declare a variable for holding the finally state while |
| 1923 // executing the finally block. | 1928 // executing the finally block. |
| 1924 finally_block = ParseBlock(NULL, CHECK_OK); | 1929 finally_block = ParseBlock(NULL, CHECK_OK); |
| 1925 } | 1930 } |
| 1926 | 1931 |
| 1927 // Simplify the AST nodes by converting: | 1932 // Simplify the AST nodes by converting: |
| 1928 // 'try { } catch { } finally { }' | 1933 // 'try { } catch { } finally { }' |
| 1929 // to: | 1934 // to: |
| 1930 // 'try { try { } catch { } } finally { }' | 1935 // 'try { try { } catch { } } finally { }' |
| 1931 | 1936 |
| 1932 if (catch_block != NULL && finally_block != NULL) { | 1937 if (catch_block != NULL && finally_block != NULL) { |
| 1938 VariableProxy* catch_var_defn = new VariableProxy(catch_var); |
| 1933 TryCatchStatement* statement = | 1939 TryCatchStatement* statement = |
| 1934 new TryCatchStatement(try_block, catch_var, catch_block); | 1940 new TryCatchStatement(try_block, catch_var_defn, catch_block); |
| 1935 statement->set_escaping_targets(collector.targets()); | 1941 statement->set_escaping_targets(collector.targets()); |
| 1936 try_block = new Block(NULL, 1, false); | 1942 try_block = new Block(NULL, 1, false); |
| 1937 try_block->AddStatement(statement); | 1943 try_block->AddStatement(statement); |
| 1938 catch_block = NULL; | 1944 catch_block = NULL; |
| 1939 } | 1945 } |
| 1940 | 1946 |
| 1941 TryStatement* result = NULL; | 1947 TryStatement* result = NULL; |
| 1942 if (catch_block != NULL) { | 1948 if (catch_block != NULL) { |
| 1943 ASSERT(finally_block == NULL); | 1949 ASSERT(finally_block == NULL); |
| 1944 result = new TryCatchStatement(try_block, catch_var, catch_block); | 1950 VariableProxy* catch_var_defn = new VariableProxy(catch_var); |
| 1951 result = new TryCatchStatement(try_block, catch_var_defn, catch_block); |
| 1945 result->set_escaping_targets(collector.targets()); | 1952 result->set_escaping_targets(collector.targets()); |
| 1946 } else { | 1953 } else { |
| 1947 ASSERT(finally_block != NULL); | 1954 ASSERT(finally_block != NULL); |
| 1948 result = new TryFinallyStatement(try_block, finally_block); | 1955 result = new TryFinallyStatement(try_block, finally_block); |
| 1949 // Add the jump targets of the try block and the catch block. | 1956 // Add the jump targets of the try block and the catch block. |
| 1950 for (int i = 0; i < collector.targets()->length(); i++) { | 1957 for (int i = 0; i < collector.targets()->length(); i++) { |
| 1951 catch_collector.AddTarget(collector.targets()->at(i)); | 1958 catch_collector.AddTarget(collector.targets()->at(i)); |
| 1952 } | 1959 } |
| 1953 result->set_escaping_targets(catch_collector.targets()); | 1960 result->set_escaping_targets(catch_collector.targets()); |
| 1954 } | 1961 } |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2808 } | 2815 } |
| 2809 | 2816 |
| 2810 | 2817 |
| 2811 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 2818 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
| 2812 return property != NULL && | 2819 return property != NULL && |
| 2813 property->kind() != ObjectLiteral::Property::PROTOTYPE; | 2820 property->kind() != ObjectLiteral::Property::PROTOTYPE; |
| 2814 } | 2821 } |
| 2815 | 2822 |
| 2816 | 2823 |
| 2817 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { | 2824 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { |
| 2825 if (expression->AsLiteral() != NULL) return true; |
| 2818 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); | 2826 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); |
| 2819 return lit != NULL && lit->is_simple(); | 2827 return lit != NULL && lit->is_simple(); |
| 2820 } | 2828 } |
| 2821 | 2829 |
| 2822 | 2830 |
| 2823 bool CompileTimeValue::ArrayLiteralElementNeedsInitialization( | 2831 bool CompileTimeValue::ArrayLiteralElementNeedsInitialization( |
| 2824 Expression* value) { | 2832 Expression* value) { |
| 2825 // If value is a literal the property value is already set in the | 2833 // If value is a literal the property value is already set in the |
| 2826 // boilerplate object. | 2834 // boilerplate object. |
| 2827 if (value->AsLiteral() != NULL) return false; | 2835 if (value->AsLiteral() != NULL) return false; |
| (...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4633 Handle<String> source = Handle<String>(String::cast(script->source())); | 4641 Handle<String> source = Handle<String>(String::cast(script->source())); |
| 4634 result = parser.ParseProgram(source, info->is_global()); | 4642 result = parser.ParseProgram(source, info->is_global()); |
| 4635 } | 4643 } |
| 4636 } | 4644 } |
| 4637 | 4645 |
| 4638 info->SetFunction(result); | 4646 info->SetFunction(result); |
| 4639 return (result != NULL); | 4647 return (result != NULL); |
| 4640 } | 4648 } |
| 4641 | 4649 |
| 4642 } } // namespace v8::internal | 4650 } } // namespace v8::internal |
| OLD | NEW |