Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: src/ast.h

Issue 9187005: Enable optimization of top-level code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: fixed problem with eval code, addressed comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 #undef DECLARE_NODE_FUNCTIONS 216 #undef DECLARE_NODE_FUNCTIONS
217 217
218 virtual Declaration* AsDeclaration() { return NULL; } 218 virtual Declaration* AsDeclaration() { return NULL; }
219 virtual Statement* AsStatement() { return NULL; } 219 virtual Statement* AsStatement() { return NULL; }
220 virtual Expression* AsExpression() { return NULL; } 220 virtual Expression* AsExpression() { return NULL; }
221 virtual TargetCollector* AsTargetCollector() { return NULL; } 221 virtual TargetCollector* AsTargetCollector() { return NULL; }
222 virtual BreakableStatement* AsBreakableStatement() { return NULL; } 222 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
223 virtual IterationStatement* AsIterationStatement() { return NULL; } 223 virtual IterationStatement* AsIterationStatement() { return NULL; }
224 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } 224 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
225 225
226 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); }
227
228 protected: 226 protected:
229 static int GetNextId(Isolate* isolate) { 227 static int GetNextId(Isolate* isolate) {
230 return ReserveIdRange(isolate, 1); 228 return ReserveIdRange(isolate, 1);
231 } 229 }
232 230
233 static int ReserveIdRange(Isolate* isolate, int n) { 231 static int ReserveIdRange(Isolate* isolate, int n) {
234 int tmp = isolate->ast_node_id(); 232 int tmp = isolate->ast_node_id();
235 isolate->set_ast_node_id(tmp + n); 233 isolate->set_ast_node_id(tmp + n);
236 return tmp; 234 return tmp;
237 } 235 }
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 1896
1899 1897
1900 class FunctionLiteral: public Expression { 1898 class FunctionLiteral: public Expression {
1901 public: 1899 public:
1902 enum Type { 1900 enum Type {
1903 ANONYMOUS_EXPRESSION, 1901 ANONYMOUS_EXPRESSION,
1904 NAMED_EXPRESSION, 1902 NAMED_EXPRESSION,
1905 DECLARATION 1903 DECLARATION
1906 }; 1904 };
1907 1905
1906 enum ParameterFlag {
1907 kNoDuplicateParameters = 0,
1908 kHasDuplicateParameters = 1
1909 };
1910
1911 enum IsFunctionFlag {
1912 kGlobalOrEval,
1913 kIsFunction
1914 };
1915
1908 DECLARE_NODE_TYPE(FunctionLiteral) 1916 DECLARE_NODE_TYPE(FunctionLiteral)
1909 1917
1910 Handle<String> name() const { return name_; } 1918 Handle<String> name() const { return name_; }
1911 Scope* scope() const { return scope_; } 1919 Scope* scope() const { return scope_; }
1912 ZoneList<Statement*>* body() const { return body_; } 1920 ZoneList<Statement*>* body() const { return body_; }
1913 void set_function_token_position(int pos) { function_token_position_ = pos; } 1921 void set_function_token_position(int pos) { function_token_position_ = pos; }
1914 int function_token_position() const { return function_token_position_; } 1922 int function_token_position() const { return function_token_position_; }
1915 int start_position() const; 1923 int start_position() const;
1916 int end_position() const; 1924 int end_position() const;
1925 int SourceSize() const { return end_position() - start_position(); }
1917 bool is_expression() const { return IsExpression::decode(bitfield_); } 1926 bool is_expression() const { return IsExpression::decode(bitfield_); }
1918 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); } 1927 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
1919 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } 1928 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; }
1920 LanguageMode language_mode() const; 1929 LanguageMode language_mode() const;
1921 1930
1922 int materialized_literal_count() { return materialized_literal_count_; } 1931 int materialized_literal_count() { return materialized_literal_count_; }
1923 int expected_property_count() { return expected_property_count_; } 1932 int expected_property_count() { return expected_property_count_; }
1924 int handler_count() { return handler_count_; } 1933 int handler_count() { return handler_count_; }
1925 bool has_only_simple_this_property_assignments() { 1934 bool has_only_simple_this_property_assignments() {
1926 return HasOnlySimpleThisPropertyAssignments::decode(bitfield_); 1935 return HasOnlySimpleThisPropertyAssignments::decode(bitfield_);
(...skipping 15 matching lines...) Expand all
1942 inferred_name_ = inferred_name; 1951 inferred_name_ = inferred_name;
1943 } 1952 }
1944 1953
1945 bool pretenure() { return Pretenure::decode(bitfield_); } 1954 bool pretenure() { return Pretenure::decode(bitfield_); }
1946 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } 1955 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
1947 1956
1948 bool has_duplicate_parameters() { 1957 bool has_duplicate_parameters() {
1949 return HasDuplicateParameters::decode(bitfield_); 1958 return HasDuplicateParameters::decode(bitfield_);
1950 } 1959 }
1951 1960
1961 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
1962
1952 int ast_node_count() { return ast_properties_.node_count(); } 1963 int ast_node_count() { return ast_properties_.node_count(); }
1953 AstProperties::Flags* flags() { return ast_properties_.flags(); } 1964 AstProperties::Flags* flags() { return ast_properties_.flags(); }
1954 void set_ast_properties(AstProperties* ast_properties) { 1965 void set_ast_properties(AstProperties* ast_properties) {
1955 ast_properties_ = *ast_properties; 1966 ast_properties_ = *ast_properties;
1956 } 1967 }
1957 1968
1958 protected: 1969 protected:
1959 template<class> friend class AstNodeFactory; 1970 template<class> friend class AstNodeFactory;
1960 1971
1961 FunctionLiteral(Isolate* isolate, 1972 FunctionLiteral(Isolate* isolate,
1962 Handle<String> name, 1973 Handle<String> name,
1963 Scope* scope, 1974 Scope* scope,
1964 ZoneList<Statement*>* body, 1975 ZoneList<Statement*>* body,
1965 int materialized_literal_count, 1976 int materialized_literal_count,
1966 int expected_property_count, 1977 int expected_property_count,
1967 int handler_count, 1978 int handler_count,
1968 bool has_only_simple_this_property_assignments, 1979 bool has_only_simple_this_property_assignments,
1969 Handle<FixedArray> this_property_assignments, 1980 Handle<FixedArray> this_property_assignments,
1970 int parameter_count, 1981 int parameter_count,
1971 Type type, 1982 Type type,
1972 bool has_duplicate_parameters) 1983 ParameterFlag has_duplicate_parameters,
1984 IsFunctionFlag is_function)
1973 : Expression(isolate), 1985 : Expression(isolate),
1974 name_(name), 1986 name_(name),
1975 scope_(scope), 1987 scope_(scope),
1976 body_(body), 1988 body_(body),
1977 this_property_assignments_(this_property_assignments), 1989 this_property_assignments_(this_property_assignments),
1978 inferred_name_(isolate->factory()->empty_string()), 1990 inferred_name_(isolate->factory()->empty_string()),
1979 materialized_literal_count_(materialized_literal_count), 1991 materialized_literal_count_(materialized_literal_count),
1980 expected_property_count_(expected_property_count), 1992 expected_property_count_(expected_property_count),
1981 handler_count_(handler_count), 1993 handler_count_(handler_count),
1982 parameter_count_(parameter_count), 1994 parameter_count_(parameter_count),
1983 function_token_position_(RelocInfo::kNoPosition) { 1995 function_token_position_(RelocInfo::kNoPosition) {
1984 bitfield_ = 1996 bitfield_ =
1985 HasOnlySimpleThisPropertyAssignments::encode( 1997 HasOnlySimpleThisPropertyAssignments::encode(
1986 has_only_simple_this_property_assignments) | 1998 has_only_simple_this_property_assignments) |
1987 IsExpression::encode(type != DECLARATION) | 1999 IsExpression::encode(type != DECLARATION) |
1988 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | 2000 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) |
1989 Pretenure::encode(false) | 2001 Pretenure::encode(false) |
1990 HasDuplicateParameters::encode(has_duplicate_parameters); 2002 HasDuplicateParameters::encode(has_duplicate_parameters) |
2003 IsFunction::encode(is_function);
1991 } 2004 }
1992 2005
1993 private: 2006 private:
1994 Handle<String> name_; 2007 Handle<String> name_;
1995 Scope* scope_; 2008 Scope* scope_;
1996 ZoneList<Statement*>* body_; 2009 ZoneList<Statement*>* body_;
1997 Handle<FixedArray> this_property_assignments_; 2010 Handle<FixedArray> this_property_assignments_;
1998 Handle<String> inferred_name_; 2011 Handle<String> inferred_name_;
1999 AstProperties ast_properties_; 2012 AstProperties ast_properties_;
2000 2013
2001 int materialized_literal_count_; 2014 int materialized_literal_count_;
2002 int expected_property_count_; 2015 int expected_property_count_;
2003 int handler_count_; 2016 int handler_count_;
2004 int parameter_count_; 2017 int parameter_count_;
2005 int function_token_position_; 2018 int function_token_position_;
2006 2019
2007 unsigned bitfield_; 2020 unsigned bitfield_;
2008 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; 2021 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {};
2009 class IsExpression: public BitField<bool, 1, 1> {}; 2022 class IsExpression: public BitField<bool, 1, 1> {};
2010 class IsAnonymous: public BitField<bool, 2, 1> {}; 2023 class IsAnonymous: public BitField<bool, 2, 1> {};
2011 class Pretenure: public BitField<bool, 3, 1> {}; 2024 class Pretenure: public BitField<bool, 3, 1> {};
2012 class HasDuplicateParameters: public BitField<bool, 4, 1> {}; 2025 class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {};
2026 class IsFunction: public BitField<IsFunctionFlag, 5, 1> {};
2013 }; 2027 };
2014 2028
2015 2029
2016 class SharedFunctionInfoLiteral: public Expression { 2030 class SharedFunctionInfoLiteral: public Expression {
2017 public: 2031 public:
2018 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) 2032 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
2019 2033
2020 Handle<SharedFunctionInfo> shared_function_info() const { 2034 Handle<SharedFunctionInfo> shared_function_info() const {
2021 return shared_function_info_; 2035 return shared_function_info_;
2022 } 2036 }
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 FunctionLiteral* NewFunctionLiteral( 2785 FunctionLiteral* NewFunctionLiteral(
2772 Handle<String> name, 2786 Handle<String> name,
2773 Scope* scope, 2787 Scope* scope,
2774 ZoneList<Statement*>* body, 2788 ZoneList<Statement*>* body,
2775 int materialized_literal_count, 2789 int materialized_literal_count,
2776 int expected_property_count, 2790 int expected_property_count,
2777 int handler_count, 2791 int handler_count,
2778 bool has_only_simple_this_property_assignments, 2792 bool has_only_simple_this_property_assignments,
2779 Handle<FixedArray> this_property_assignments, 2793 Handle<FixedArray> this_property_assignments,
2780 int parameter_count, 2794 int parameter_count,
2781 bool has_duplicate_parameters, 2795 FunctionLiteral::ParameterFlag has_duplicate_parameters,
2782 FunctionLiteral::Type type, 2796 FunctionLiteral::Type type,
2783 bool visit_with_visitor) { 2797 FunctionLiteral::IsFunctionFlag is_function) {
2784 FunctionLiteral* lit = new(zone_) FunctionLiteral( 2798 FunctionLiteral* lit = new(zone_) FunctionLiteral(
2785 isolate_, name, scope, body, 2799 isolate_, name, scope, body,
2786 materialized_literal_count, expected_property_count, handler_count, 2800 materialized_literal_count, expected_property_count, handler_count,
2787 has_only_simple_this_property_assignments, this_property_assignments, 2801 has_only_simple_this_property_assignments, this_property_assignments,
2788 parameter_count, type, has_duplicate_parameters); 2802 parameter_count, type, has_duplicate_parameters, is_function);
2789 if (visit_with_visitor) { 2803 // Top-level literal doesn't count for the AST's properties.
2804 if (is_function == FunctionLiteral::kIsFunction) {
2790 visitor_.VisitFunctionLiteral(lit); 2805 visitor_.VisitFunctionLiteral(lit);
2791 } 2806 }
2792 return lit; 2807 return lit;
2793 } 2808 }
2794 2809
2795 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( 2810 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral(
2796 Handle<SharedFunctionInfo> shared_function_info) { 2811 Handle<SharedFunctionInfo> shared_function_info) {
2797 SharedFunctionInfoLiteral* lit = 2812 SharedFunctionInfoLiteral* lit =
2798 new(zone_) SharedFunctionInfoLiteral(isolate_, shared_function_info); 2813 new(zone_) SharedFunctionInfoLiteral(isolate_, shared_function_info);
2799 VISIT_AND_RETURN(SharedFunctionInfoLiteral, lit) 2814 VISIT_AND_RETURN(SharedFunctionInfoLiteral, lit)
2800 } 2815 }
2801 2816
2802 ThisFunction* NewThisFunction() { 2817 ThisFunction* NewThisFunction() {
2803 ThisFunction* fun = new(zone_) ThisFunction(isolate_); 2818 ThisFunction* fun = new(zone_) ThisFunction(isolate_);
2804 VISIT_AND_RETURN(ThisFunction, fun) 2819 VISIT_AND_RETURN(ThisFunction, fun)
2805 } 2820 }
2806 2821
2807 #undef VISIT_AND_RETURN 2822 #undef VISIT_AND_RETURN
2808 2823
2809 private: 2824 private:
2810 Isolate* isolate_; 2825 Isolate* isolate_;
2811 Zone* zone_; 2826 Zone* zone_;
2812 Visitor visitor_; 2827 Visitor visitor_;
2813 }; 2828 };
2814 2829
2815 2830
2816 } } // namespace v8::internal 2831 } } // namespace v8::internal
2817 2832
2818 #endif // V8_AST_H_ 2833 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('k') | src/compiler.h » ('j') | src/compiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698