OLD | NEW |
---|---|
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 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2025 enum ParameterFlag { | 2025 enum ParameterFlag { |
2026 kNoDuplicateParameters = 0, | 2026 kNoDuplicateParameters = 0, |
2027 kHasDuplicateParameters = 1 | 2027 kHasDuplicateParameters = 1 |
2028 }; | 2028 }; |
2029 | 2029 |
2030 enum IsFunctionFlag { | 2030 enum IsFunctionFlag { |
2031 kGlobalOrEval, | 2031 kGlobalOrEval, |
2032 kIsFunction | 2032 kIsFunction |
2033 }; | 2033 }; |
2034 | 2034 |
2035 enum IsParenthesizedFlag { | |
Michael Starzinger
2012/08/07 12:58:51
I am torn between "IsParenthesizedFlag" and just "
ulan
2012/08/07 13:18:33
I like IsParenthesizedFlag more.
| |
2036 kIsParenthesized, | |
2037 kNotParenthesized | |
2038 }; | |
2039 | |
2035 DECLARE_NODE_TYPE(FunctionLiteral) | 2040 DECLARE_NODE_TYPE(FunctionLiteral) |
2036 | 2041 |
2037 Handle<String> name() const { return name_; } | 2042 Handle<String> name() const { return name_; } |
2038 Scope* scope() const { return scope_; } | 2043 Scope* scope() const { return scope_; } |
2039 ZoneList<Statement*>* body() const { return body_; } | 2044 ZoneList<Statement*>* body() const { return body_; } |
2040 void set_function_token_position(int pos) { function_token_position_ = pos; } | 2045 void set_function_token_position(int pos) { function_token_position_ = pos; } |
2041 int function_token_position() const { return function_token_position_; } | 2046 int function_token_position() const { return function_token_position_; } |
2042 int start_position() const; | 2047 int start_position() const; |
2043 int end_position() const; | 2048 int end_position() const; |
2044 int SourceSize() const { return end_position() - start_position(); } | 2049 int SourceSize() const { return end_position() - start_position(); } |
(...skipping 28 matching lines...) Expand all Loading... | |
2073 | 2078 |
2074 bool pretenure() { return Pretenure::decode(bitfield_); } | 2079 bool pretenure() { return Pretenure::decode(bitfield_); } |
2075 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } | 2080 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } |
2076 | 2081 |
2077 bool has_duplicate_parameters() { | 2082 bool has_duplicate_parameters() { |
2078 return HasDuplicateParameters::decode(bitfield_); | 2083 return HasDuplicateParameters::decode(bitfield_); |
2079 } | 2084 } |
2080 | 2085 |
2081 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; } | 2086 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; } |
2082 | 2087 |
2088 bool is_parenthesized() { | |
2089 return IsParenthesized::decode(bitfield_) == kIsParenthesized; | |
2090 } | |
2091 | |
2083 int ast_node_count() { return ast_properties_.node_count(); } | 2092 int ast_node_count() { return ast_properties_.node_count(); } |
2084 AstProperties::Flags* flags() { return ast_properties_.flags(); } | 2093 AstProperties::Flags* flags() { return ast_properties_.flags(); } |
2085 void set_ast_properties(AstProperties* ast_properties) { | 2094 void set_ast_properties(AstProperties* ast_properties) { |
2086 ast_properties_ = *ast_properties; | 2095 ast_properties_ = *ast_properties; |
2087 } | 2096 } |
2088 | 2097 |
2089 protected: | 2098 protected: |
2090 template<class> friend class AstNodeFactory; | 2099 template<class> friend class AstNodeFactory; |
2091 | 2100 |
2092 FunctionLiteral(Isolate* isolate, | 2101 FunctionLiteral(Isolate* isolate, |
2093 Handle<String> name, | 2102 Handle<String> name, |
2094 Scope* scope, | 2103 Scope* scope, |
2095 ZoneList<Statement*>* body, | 2104 ZoneList<Statement*>* body, |
2096 int materialized_literal_count, | 2105 int materialized_literal_count, |
2097 int expected_property_count, | 2106 int expected_property_count, |
2098 int handler_count, | 2107 int handler_count, |
2099 bool has_only_simple_this_property_assignments, | 2108 bool has_only_simple_this_property_assignments, |
2100 Handle<FixedArray> this_property_assignments, | 2109 Handle<FixedArray> this_property_assignments, |
2101 int parameter_count, | 2110 int parameter_count, |
2102 Type type, | 2111 Type type, |
2103 ParameterFlag has_duplicate_parameters, | 2112 ParameterFlag has_duplicate_parameters, |
2104 IsFunctionFlag is_function) | 2113 IsFunctionFlag is_function, |
2114 IsParenthesizedFlag is_parenthesized) | |
2105 : Expression(isolate), | 2115 : Expression(isolate), |
2106 name_(name), | 2116 name_(name), |
2107 scope_(scope), | 2117 scope_(scope), |
2108 body_(body), | 2118 body_(body), |
2109 this_property_assignments_(this_property_assignments), | 2119 this_property_assignments_(this_property_assignments), |
2110 inferred_name_(isolate->factory()->empty_string()), | 2120 inferred_name_(isolate->factory()->empty_string()), |
2111 materialized_literal_count_(materialized_literal_count), | 2121 materialized_literal_count_(materialized_literal_count), |
2112 expected_property_count_(expected_property_count), | 2122 expected_property_count_(expected_property_count), |
2113 handler_count_(handler_count), | 2123 handler_count_(handler_count), |
2114 parameter_count_(parameter_count), | 2124 parameter_count_(parameter_count), |
2115 function_token_position_(RelocInfo::kNoPosition) { | 2125 function_token_position_(RelocInfo::kNoPosition) { |
2116 bitfield_ = | 2126 bitfield_ = |
2117 HasOnlySimpleThisPropertyAssignments::encode( | 2127 HasOnlySimpleThisPropertyAssignments::encode( |
2118 has_only_simple_this_property_assignments) | | 2128 has_only_simple_this_property_assignments) | |
2119 IsExpression::encode(type != DECLARATION) | | 2129 IsExpression::encode(type != DECLARATION) | |
2120 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | | 2130 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | |
2121 Pretenure::encode(false) | | 2131 Pretenure::encode(false) | |
2122 HasDuplicateParameters::encode(has_duplicate_parameters) | | 2132 HasDuplicateParameters::encode(has_duplicate_parameters) | |
2123 IsFunction::encode(is_function); | 2133 IsFunction::encode(is_function) | |
2134 IsParenthesized::encode(is_parenthesized); | |
2124 } | 2135 } |
2125 | 2136 |
2126 private: | 2137 private: |
2127 Handle<String> name_; | 2138 Handle<String> name_; |
2128 Scope* scope_; | 2139 Scope* scope_; |
2129 ZoneList<Statement*>* body_; | 2140 ZoneList<Statement*>* body_; |
2130 Handle<FixedArray> this_property_assignments_; | 2141 Handle<FixedArray> this_property_assignments_; |
2131 Handle<String> inferred_name_; | 2142 Handle<String> inferred_name_; |
2132 AstProperties ast_properties_; | 2143 AstProperties ast_properties_; |
2133 | 2144 |
2134 int materialized_literal_count_; | 2145 int materialized_literal_count_; |
2135 int expected_property_count_; | 2146 int expected_property_count_; |
2136 int handler_count_; | 2147 int handler_count_; |
2137 int parameter_count_; | 2148 int parameter_count_; |
2138 int function_token_position_; | 2149 int function_token_position_; |
2139 | 2150 |
2140 unsigned bitfield_; | 2151 unsigned bitfield_; |
2141 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; | 2152 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; |
2142 class IsExpression: public BitField<bool, 1, 1> {}; | 2153 class IsExpression: public BitField<bool, 1, 1> {}; |
2143 class IsAnonymous: public BitField<bool, 2, 1> {}; | 2154 class IsAnonymous: public BitField<bool, 2, 1> {}; |
2144 class Pretenure: public BitField<bool, 3, 1> {}; | 2155 class Pretenure: public BitField<bool, 3, 1> {}; |
2145 class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {}; | 2156 class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {}; |
2146 class IsFunction: public BitField<IsFunctionFlag, 5, 1> {}; | 2157 class IsFunction: public BitField<IsFunctionFlag, 5, 1> {}; |
2158 class IsParenthesized: public BitField<IsParenthesizedFlag, 6, 1> {}; | |
2147 }; | 2159 }; |
2148 | 2160 |
2149 | 2161 |
2150 class SharedFunctionInfoLiteral: public Expression { | 2162 class SharedFunctionInfoLiteral: public Expression { |
2151 public: | 2163 public: |
2152 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) | 2164 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) |
2153 | 2165 |
2154 Handle<SharedFunctionInfo> shared_function_info() const { | 2166 Handle<SharedFunctionInfo> shared_function_info() const { |
2155 return shared_function_info_; | 2167 return shared_function_info_; |
2156 } | 2168 } |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2940 Scope* scope, | 2952 Scope* scope, |
2941 ZoneList<Statement*>* body, | 2953 ZoneList<Statement*>* body, |
2942 int materialized_literal_count, | 2954 int materialized_literal_count, |
2943 int expected_property_count, | 2955 int expected_property_count, |
2944 int handler_count, | 2956 int handler_count, |
2945 bool has_only_simple_this_property_assignments, | 2957 bool has_only_simple_this_property_assignments, |
2946 Handle<FixedArray> this_property_assignments, | 2958 Handle<FixedArray> this_property_assignments, |
2947 int parameter_count, | 2959 int parameter_count, |
2948 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 2960 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
2949 FunctionLiteral::Type type, | 2961 FunctionLiteral::Type type, |
2950 FunctionLiteral::IsFunctionFlag is_function) { | 2962 FunctionLiteral::IsFunctionFlag is_function, |
2963 FunctionLiteral::IsParenthesizedFlag is_parenthesized) { | |
2951 FunctionLiteral* lit = new(zone_) FunctionLiteral( | 2964 FunctionLiteral* lit = new(zone_) FunctionLiteral( |
2952 isolate_, name, scope, body, | 2965 isolate_, name, scope, body, |
2953 materialized_literal_count, expected_property_count, handler_count, | 2966 materialized_literal_count, expected_property_count, handler_count, |
2954 has_only_simple_this_property_assignments, this_property_assignments, | 2967 has_only_simple_this_property_assignments, this_property_assignments, |
2955 parameter_count, type, has_duplicate_parameters, is_function); | 2968 parameter_count, type, has_duplicate_parameters, is_function, |
2969 is_parenthesized); | |
2956 // Top-level literal doesn't count for the AST's properties. | 2970 // Top-level literal doesn't count for the AST's properties. |
2957 if (is_function == FunctionLiteral::kIsFunction) { | 2971 if (is_function == FunctionLiteral::kIsFunction) { |
2958 visitor_.VisitFunctionLiteral(lit); | 2972 visitor_.VisitFunctionLiteral(lit); |
2959 } | 2973 } |
2960 return lit; | 2974 return lit; |
2961 } | 2975 } |
2962 | 2976 |
2963 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( | 2977 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( |
2964 Handle<SharedFunctionInfo> shared_function_info) { | 2978 Handle<SharedFunctionInfo> shared_function_info) { |
2965 SharedFunctionInfoLiteral* lit = | 2979 SharedFunctionInfoLiteral* lit = |
(...skipping 11 matching lines...) Expand all Loading... | |
2977 private: | 2991 private: |
2978 Isolate* isolate_; | 2992 Isolate* isolate_; |
2979 Zone* zone_; | 2993 Zone* zone_; |
2980 Visitor visitor_; | 2994 Visitor visitor_; |
2981 }; | 2995 }; |
2982 | 2996 |
2983 | 2997 |
2984 } } // namespace v8::internal | 2998 } } // namespace v8::internal |
2985 | 2999 |
2986 #endif // V8_AST_H_ | 3000 #endif // V8_AST_H_ |
OLD | NEW |