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

Side by Side Diff: src/ast.h

Issue 13179002: Add parser support for generators. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: added additional syntax tests Created 7 years, 8 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
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 #define EXPRESSION_NODE_LIST(V) \ 95 #define EXPRESSION_NODE_LIST(V) \
96 V(FunctionLiteral) \ 96 V(FunctionLiteral) \
97 V(SharedFunctionInfoLiteral) \ 97 V(SharedFunctionInfoLiteral) \
98 V(Conditional) \ 98 V(Conditional) \
99 V(VariableProxy) \ 99 V(VariableProxy) \
100 V(Literal) \ 100 V(Literal) \
101 V(RegExpLiteral) \ 101 V(RegExpLiteral) \
102 V(ObjectLiteral) \ 102 V(ObjectLiteral) \
103 V(ArrayLiteral) \ 103 V(ArrayLiteral) \
104 V(Assignment) \ 104 V(Assignment) \
105 V(Yield) \
105 V(Throw) \ 106 V(Throw) \
106 V(Property) \ 107 V(Property) \
107 V(Call) \ 108 V(Call) \
108 V(CallNew) \ 109 V(CallNew) \
109 V(CallRuntime) \ 110 V(CallRuntime) \
110 V(UnaryOperation) \ 111 V(UnaryOperation) \
111 V(CountOperation) \ 112 V(CountOperation) \
112 V(BinaryOperation) \ 113 V(BinaryOperation) \
113 V(CompareOperation) \ 114 V(CompareOperation) \
114 V(ThisFunction) 115 V(ThisFunction)
(...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 int pos_; 1947 int pos_;
1947 BinaryOperation* binary_operation_; 1948 BinaryOperation* binary_operation_;
1948 const BailoutId assignment_id_; 1949 const BailoutId assignment_id_;
1949 1950
1950 bool is_monomorphic_ : 1; 1951 bool is_monomorphic_ : 1;
1951 KeyedAccessStoreMode store_mode_ : 4; 1952 KeyedAccessStoreMode store_mode_ : 4;
1952 SmallMapList receiver_types_; 1953 SmallMapList receiver_types_;
1953 }; 1954 };
1954 1955
1955 1956
1957 class Yield: public Expression {
1958 public:
1959 DECLARE_NODE_TYPE(Yield)
1960
1961 Expression* expression() const { return expression_; }
1962 bool is_delegating_yield() const { return is_delegating_yield_; }
1963 virtual int position() const { return pos_; }
1964
1965 protected:
1966 Yield(Isolate* isolate,
1967 Expression* expression,
1968 bool is_delegating_yield,
1969 int pos)
1970 : Expression(isolate),
1971 expression_(expression),
1972 is_delegating_yield_(is_delegating_yield),
1973 pos_(pos) { }
1974
1975 private:
1976 Expression* expression_;
1977 bool is_delegating_yield_;
1978 int pos_;
1979 };
1980
1981
1956 class Throw: public Expression { 1982 class Throw: public Expression {
1957 public: 1983 public:
1958 DECLARE_NODE_TYPE(Throw) 1984 DECLARE_NODE_TYPE(Throw)
1959 1985
1960 Expression* exception() const { return exception_; } 1986 Expression* exception() const { return exception_; }
1961 virtual int position() const { return pos_; } 1987 virtual int position() const { return pos_; }
1962 1988
1963 protected: 1989 protected:
1964 Throw(Isolate* isolate, Expression* exception, int pos) 1990 Throw(Isolate* isolate, Expression* exception, int pos)
1965 : Expression(isolate), exception_(exception), pos_(pos) {} 1991 : Expression(isolate), exception_(exception), pos_(pos) {}
(...skipping 20 matching lines...) Expand all
1986 enum IsFunctionFlag { 2012 enum IsFunctionFlag {
1987 kGlobalOrEval, 2013 kGlobalOrEval,
1988 kIsFunction 2014 kIsFunction
1989 }; 2015 };
1990 2016
1991 enum IsParenthesizedFlag { 2017 enum IsParenthesizedFlag {
1992 kIsParenthesized, 2018 kIsParenthesized,
1993 kNotParenthesized 2019 kNotParenthesized
1994 }; 2020 };
1995 2021
2022 enum IsGeneratorFlag {
2023 kIsGenerator,
2024 kNotGenerator
2025 };
2026
1996 DECLARE_NODE_TYPE(FunctionLiteral) 2027 DECLARE_NODE_TYPE(FunctionLiteral)
1997 2028
1998 Handle<String> name() const { return name_; } 2029 Handle<String> name() const { return name_; }
1999 Scope* scope() const { return scope_; } 2030 Scope* scope() const { return scope_; }
2000 ZoneList<Statement*>* body() const { return body_; } 2031 ZoneList<Statement*>* body() const { return body_; }
2001 void set_function_token_position(int pos) { function_token_position_ = pos; } 2032 void set_function_token_position(int pos) { function_token_position_ = pos; }
2002 int function_token_position() const { return function_token_position_; } 2033 int function_token_position() const { return function_token_position_; }
2003 int start_position() const; 2034 int start_position() const;
2004 int end_position() const; 2035 int end_position() const;
2005 int SourceSize() const { return end_position() - start_position(); } 2036 int SourceSize() const { return end_position() - start_position(); }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 // function will be called immediately: 2077 // function will be called immediately:
2047 // - (function() { ... })(); 2078 // - (function() { ... })();
2048 // - var x = function() { ... }(); 2079 // - var x = function() { ... }();
2049 bool is_parenthesized() { 2080 bool is_parenthesized() {
2050 return IsParenthesized::decode(bitfield_) == kIsParenthesized; 2081 return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2051 } 2082 }
2052 void set_parenthesized() { 2083 void set_parenthesized() {
2053 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); 2084 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2054 } 2085 }
2055 2086
2087 bool is_generator() {
2088 return IsGenerator::decode(bitfield_) == kIsGenerator;
2089 }
2090
2056 int ast_node_count() { return ast_properties_.node_count(); } 2091 int ast_node_count() { return ast_properties_.node_count(); }
2057 AstProperties::Flags* flags() { return ast_properties_.flags(); } 2092 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2058 void set_ast_properties(AstProperties* ast_properties) { 2093 void set_ast_properties(AstProperties* ast_properties) {
2059 ast_properties_ = *ast_properties; 2094 ast_properties_ = *ast_properties;
2060 } 2095 }
2061 2096
2062 protected: 2097 protected:
2063 FunctionLiteral(Isolate* isolate, 2098 FunctionLiteral(Isolate* isolate,
2064 Handle<String> name, 2099 Handle<String> name,
2065 Scope* scope, 2100 Scope* scope,
2066 ZoneList<Statement*>* body, 2101 ZoneList<Statement*>* body,
2067 int materialized_literal_count, 2102 int materialized_literal_count,
2068 int expected_property_count, 2103 int expected_property_count,
2069 int handler_count, 2104 int handler_count,
2070 bool has_only_simple_this_property_assignments, 2105 bool has_only_simple_this_property_assignments,
2071 Handle<FixedArray> this_property_assignments, 2106 Handle<FixedArray> this_property_assignments,
2072 int parameter_count, 2107 int parameter_count,
2073 Type type, 2108 Type type,
2074 ParameterFlag has_duplicate_parameters, 2109 ParameterFlag has_duplicate_parameters,
2075 IsFunctionFlag is_function, 2110 IsFunctionFlag is_function,
2076 IsParenthesizedFlag is_parenthesized) 2111 IsParenthesizedFlag is_parenthesized,
2112 IsGeneratorFlag is_generator)
2077 : Expression(isolate), 2113 : Expression(isolate),
2078 name_(name), 2114 name_(name),
2079 scope_(scope), 2115 scope_(scope),
2080 body_(body), 2116 body_(body),
2081 this_property_assignments_(this_property_assignments), 2117 this_property_assignments_(this_property_assignments),
2082 inferred_name_(isolate->factory()->empty_string()), 2118 inferred_name_(isolate->factory()->empty_string()),
2083 materialized_literal_count_(materialized_literal_count), 2119 materialized_literal_count_(materialized_literal_count),
2084 expected_property_count_(expected_property_count), 2120 expected_property_count_(expected_property_count),
2085 handler_count_(handler_count), 2121 handler_count_(handler_count),
2086 parameter_count_(parameter_count), 2122 parameter_count_(parameter_count),
2087 function_token_position_(RelocInfo::kNoPosition) { 2123 function_token_position_(RelocInfo::kNoPosition) {
2088 bitfield_ = 2124 bitfield_ =
2089 HasOnlySimpleThisPropertyAssignments::encode( 2125 HasOnlySimpleThisPropertyAssignments::encode(
2090 has_only_simple_this_property_assignments) | 2126 has_only_simple_this_property_assignments) |
2091 IsExpression::encode(type != DECLARATION) | 2127 IsExpression::encode(type != DECLARATION) |
2092 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | 2128 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) |
2093 Pretenure::encode(false) | 2129 Pretenure::encode(false) |
2094 HasDuplicateParameters::encode(has_duplicate_parameters) | 2130 HasDuplicateParameters::encode(has_duplicate_parameters) |
2095 IsFunction::encode(is_function) | 2131 IsFunction::encode(is_function) |
2096 IsParenthesized::encode(is_parenthesized); 2132 IsParenthesized::encode(is_parenthesized) |
2133 IsGenerator::encode(is_generator);
2097 } 2134 }
2098 2135
2099 private: 2136 private:
2100 Handle<String> name_; 2137 Handle<String> name_;
2101 Scope* scope_; 2138 Scope* scope_;
2102 ZoneList<Statement*>* body_; 2139 ZoneList<Statement*>* body_;
2103 Handle<FixedArray> this_property_assignments_; 2140 Handle<FixedArray> this_property_assignments_;
2104 Handle<String> inferred_name_; 2141 Handle<String> inferred_name_;
2105 AstProperties ast_properties_; 2142 AstProperties ast_properties_;
2106 2143
2107 int materialized_literal_count_; 2144 int materialized_literal_count_;
2108 int expected_property_count_; 2145 int expected_property_count_;
2109 int handler_count_; 2146 int handler_count_;
2110 int parameter_count_; 2147 int parameter_count_;
2111 int function_token_position_; 2148 int function_token_position_;
2112 2149
2113 unsigned bitfield_; 2150 unsigned bitfield_;
2114 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; 2151 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {};
2115 class IsExpression: public BitField<bool, 1, 1> {}; 2152 class IsExpression: public BitField<bool, 1, 1> {};
2116 class IsAnonymous: public BitField<bool, 2, 1> {}; 2153 class IsAnonymous: public BitField<bool, 2, 1> {};
2117 class Pretenure: public BitField<bool, 3, 1> {}; 2154 class Pretenure: public BitField<bool, 3, 1> {};
2118 class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {}; 2155 class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {};
2119 class IsFunction: public BitField<IsFunctionFlag, 5, 1> {}; 2156 class IsFunction: public BitField<IsFunctionFlag, 5, 1> {};
2120 class IsParenthesized: public BitField<IsParenthesizedFlag, 6, 1> {}; 2157 class IsParenthesized: public BitField<IsParenthesizedFlag, 6, 1> {};
2158 class IsGenerator: public BitField<IsGeneratorFlag, 7, 1> {};
2121 }; 2159 };
2122 2160
2123 2161
2124 class SharedFunctionInfoLiteral: public Expression { 2162 class SharedFunctionInfoLiteral: public Expression {
2125 public: 2163 public:
2126 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) 2164 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
2127 2165
2128 Handle<SharedFunctionInfo> shared_function_info() const { 2166 Handle<SharedFunctionInfo> shared_function_info() const {
2129 return shared_function_info_; 2167 return shared_function_info_;
2130 } 2168 }
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
2909 Assignment* NewAssignment(Token::Value op, 2947 Assignment* NewAssignment(Token::Value op,
2910 Expression* target, 2948 Expression* target,
2911 Expression* value, 2949 Expression* value,
2912 int pos) { 2950 int pos) {
2913 Assignment* assign = 2951 Assignment* assign =
2914 new(zone_) Assignment(isolate_, op, target, value, pos); 2952 new(zone_) Assignment(isolate_, op, target, value, pos);
2915 assign->Init(isolate_, this); 2953 assign->Init(isolate_, this);
2916 VISIT_AND_RETURN(Assignment, assign) 2954 VISIT_AND_RETURN(Assignment, assign)
2917 } 2955 }
2918 2956
2957 Yield* NewYield(Expression* expression, bool is_delegating_yield, int pos) {
2958 Yield* yield =
2959 new(zone_) Yield(isolate_, expression, is_delegating_yield, pos);
2960 VISIT_AND_RETURN(Yield, yield)
2961 }
2962
2919 Throw* NewThrow(Expression* exception, int pos) { 2963 Throw* NewThrow(Expression* exception, int pos) {
2920 Throw* t = new(zone_) Throw(isolate_, exception, pos); 2964 Throw* t = new(zone_) Throw(isolate_, exception, pos);
2921 VISIT_AND_RETURN(Throw, t) 2965 VISIT_AND_RETURN(Throw, t)
2922 } 2966 }
2923 2967
2924 FunctionLiteral* NewFunctionLiteral( 2968 FunctionLiteral* NewFunctionLiteral(
2925 Handle<String> name, 2969 Handle<String> name,
2926 Scope* scope, 2970 Scope* scope,
2927 ZoneList<Statement*>* body, 2971 ZoneList<Statement*>* body,
2928 int materialized_literal_count, 2972 int materialized_literal_count,
2929 int expected_property_count, 2973 int expected_property_count,
2930 int handler_count, 2974 int handler_count,
2931 bool has_only_simple_this_property_assignments, 2975 bool has_only_simple_this_property_assignments,
2932 Handle<FixedArray> this_property_assignments, 2976 Handle<FixedArray> this_property_assignments,
2933 int parameter_count, 2977 int parameter_count,
2934 FunctionLiteral::ParameterFlag has_duplicate_parameters, 2978 FunctionLiteral::ParameterFlag has_duplicate_parameters,
2935 FunctionLiteral::Type type, 2979 FunctionLiteral::Type type,
2936 FunctionLiteral::IsFunctionFlag is_function, 2980 FunctionLiteral::IsFunctionFlag is_function,
2937 FunctionLiteral::IsParenthesizedFlag is_parenthesized) { 2981 FunctionLiteral::IsParenthesizedFlag is_parenthesized,
2982 FunctionLiteral::IsGeneratorFlag is_generator) {
2938 FunctionLiteral* lit = new(zone_) FunctionLiteral( 2983 FunctionLiteral* lit = new(zone_) FunctionLiteral(
2939 isolate_, name, scope, body, 2984 isolate_, name, scope, body,
2940 materialized_literal_count, expected_property_count, handler_count, 2985 materialized_literal_count, expected_property_count, handler_count,
2941 has_only_simple_this_property_assignments, this_property_assignments, 2986 has_only_simple_this_property_assignments, this_property_assignments,
2942 parameter_count, type, has_duplicate_parameters, is_function, 2987 parameter_count, type, has_duplicate_parameters, is_function,
2943 is_parenthesized); 2988 is_parenthesized, is_generator);
2944 // Top-level literal doesn't count for the AST's properties. 2989 // Top-level literal doesn't count for the AST's properties.
2945 if (is_function == FunctionLiteral::kIsFunction) { 2990 if (is_function == FunctionLiteral::kIsFunction) {
2946 visitor_.VisitFunctionLiteral(lit); 2991 visitor_.VisitFunctionLiteral(lit);
2947 } 2992 }
2948 return lit; 2993 return lit;
2949 } 2994 }
2950 2995
2951 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( 2996 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral(
2952 Handle<SharedFunctionInfo> shared_function_info) { 2997 Handle<SharedFunctionInfo> shared_function_info) {
2953 SharedFunctionInfoLiteral* lit = 2998 SharedFunctionInfoLiteral* lit =
(...skipping 11 matching lines...) Expand all
2965 private: 3010 private:
2966 Isolate* isolate_; 3011 Isolate* isolate_;
2967 Zone* zone_; 3012 Zone* zone_;
2968 Visitor visitor_; 3013 Visitor visitor_;
2969 }; 3014 };
2970 3015
2971 3016
2972 } } // namespace v8::internal 3017 } } // namespace v8::internal
2973 3018
2974 #endif // V8_AST_H_ 3019 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698