OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_AST_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
7 | 7 |
| 8 #include "src/ast/ast-types.h" |
8 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
9 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
10 #include "src/ast/variables.h" | 11 #include "src/ast/variables.h" |
11 #include "src/bailout-reason.h" | 12 #include "src/bailout-reason.h" |
12 #include "src/base/flags.h" | 13 #include "src/base/flags.h" |
13 #include "src/factory.h" | 14 #include "src/factory.h" |
14 #include "src/globals.h" | 15 #include "src/globals.h" |
15 #include "src/isolate.h" | 16 #include "src/isolate.h" |
16 #include "src/list.h" | 17 #include "src/list.h" |
17 #include "src/parsing/token.h" | 18 #include "src/parsing/token.h" |
18 #include "src/runtime/runtime.h" | 19 #include "src/runtime/runtime.h" |
19 #include "src/small-pointer-list.h" | 20 #include "src/small-pointer-list.h" |
20 #include "src/types.h" | |
21 #include "src/utils.h" | 21 #include "src/utils.h" |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 // The abstract syntax tree is an intermediate, light-weight | 26 // The abstract syntax tree is an intermediate, light-weight |
27 // representation of the parsed JavaScript code suitable for | 27 // representation of the parsed JavaScript code suitable for |
28 // compilation to native code. | 28 // compilation to native code. |
29 | 29 |
30 // Nodes are allocated in a separate zone, which allows faster | 30 // Nodes are allocated in a separate zone, which allows faster |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 return label_; | 932 return label_; |
933 } | 933 } |
934 void set_label(Expression* e) { label_ = e; } | 934 void set_label(Expression* e) { label_ = e; } |
935 Label* body_target() { return &body_target_; } | 935 Label* body_target() { return &body_target_; } |
936 ZoneList<Statement*>* statements() const { return statements_; } | 936 ZoneList<Statement*>* statements() const { return statements_; } |
937 | 937 |
938 static int num_ids() { return parent_num_ids() + 2; } | 938 static int num_ids() { return parent_num_ids() + 2; } |
939 BailoutId EntryId() const { return BailoutId(local_id(0)); } | 939 BailoutId EntryId() const { return BailoutId(local_id(0)); } |
940 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); } | 940 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); } |
941 | 941 |
942 Type* compare_type() { return compare_type_; } | 942 AstType* compare_type() { return compare_type_; } |
943 void set_compare_type(Type* type) { compare_type_ = type; } | 943 void set_compare_type(AstType* type) { compare_type_ = type; } |
944 | 944 |
945 // CaseClause will have both a slot in the feedback vector and the | 945 // CaseClause will have both a slot in the feedback vector and the |
946 // TypeFeedbackId to record the type information. TypeFeedbackId is used by | 946 // TypeFeedbackId to record the type information. TypeFeedbackId is used by |
947 // full codegen and the feedback vector slot is used by interpreter. | 947 // full codegen and the feedback vector slot is used by interpreter. |
948 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 948 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
949 FeedbackVectorSlotCache* cache); | 949 FeedbackVectorSlotCache* cache); |
950 | 950 |
951 FeedbackVectorSlot CompareOperationFeedbackSlot() { | 951 FeedbackVectorSlot CompareOperationFeedbackSlot() { |
952 return type_feedback_slot_; | 952 return type_feedback_slot_; |
953 } | 953 } |
954 | 954 |
955 private: | 955 private: |
956 friend class AstNodeFactory; | 956 friend class AstNodeFactory; |
957 | 957 |
958 static int parent_num_ids() { return Expression::num_ids(); } | 958 static int parent_num_ids() { return Expression::num_ids(); } |
959 CaseClause(Expression* label, ZoneList<Statement*>* statements, int pos); | 959 CaseClause(Expression* label, ZoneList<Statement*>* statements, int pos); |
960 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 960 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
961 | 961 |
962 Expression* label_; | 962 Expression* label_; |
963 Label body_target_; | 963 Label body_target_; |
964 ZoneList<Statement*>* statements_; | 964 ZoneList<Statement*>* statements_; |
965 Type* compare_type_; | 965 AstType* compare_type_; |
966 FeedbackVectorSlot type_feedback_slot_; | 966 FeedbackVectorSlot type_feedback_slot_; |
967 }; | 967 }; |
968 | 968 |
969 | 969 |
970 class SwitchStatement final : public BreakableStatement { | 970 class SwitchStatement final : public BreakableStatement { |
971 public: | 971 public: |
972 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { | 972 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
973 tag_ = tag; | 973 tag_ = tag; |
974 cases_ = cases; | 974 cases_ = cases; |
975 } | 975 } |
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 | 2128 |
2129 Expression* expression() const { return expression_; } | 2129 Expression* expression() const { return expression_; } |
2130 void set_expression(Expression* e) { expression_ = e; } | 2130 void set_expression(Expression* e) { expression_ = e; } |
2131 | 2131 |
2132 bool IsMonomorphic() const { return receiver_types_.length() == 1; } | 2132 bool IsMonomorphic() const { return receiver_types_.length() == 1; } |
2133 SmallMapList* GetReceiverTypes() { return &receiver_types_; } | 2133 SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
2134 IcCheckType GetKeyType() const { return KeyTypeField::decode(bit_field_); } | 2134 IcCheckType GetKeyType() const { return KeyTypeField::decode(bit_field_); } |
2135 KeyedAccessStoreMode GetStoreMode() const { | 2135 KeyedAccessStoreMode GetStoreMode() const { |
2136 return StoreModeField::decode(bit_field_); | 2136 return StoreModeField::decode(bit_field_); |
2137 } | 2137 } |
2138 Type* type() const { return type_; } | 2138 AstType* type() const { return type_; } |
2139 void set_key_type(IcCheckType type) { | 2139 void set_key_type(IcCheckType type) { |
2140 bit_field_ = KeyTypeField::update(bit_field_, type); | 2140 bit_field_ = KeyTypeField::update(bit_field_, type); |
2141 } | 2141 } |
2142 void set_store_mode(KeyedAccessStoreMode mode) { | 2142 void set_store_mode(KeyedAccessStoreMode mode) { |
2143 bit_field_ = StoreModeField::update(bit_field_, mode); | 2143 bit_field_ = StoreModeField::update(bit_field_, mode); |
2144 } | 2144 } |
2145 void set_type(Type* type) { type_ = type; } | 2145 void set_type(AstType* type) { type_ = type; } |
2146 | 2146 |
2147 static int num_ids() { return parent_num_ids() + 4; } | 2147 static int num_ids() { return parent_num_ids() + 4; } |
2148 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } | 2148 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } |
2149 BailoutId ToNumberId() const { return BailoutId(local_id(1)); } | 2149 BailoutId ToNumberId() const { return BailoutId(local_id(1)); } |
2150 TypeFeedbackId CountBinOpFeedbackId() const { | 2150 TypeFeedbackId CountBinOpFeedbackId() const { |
2151 return TypeFeedbackId(local_id(2)); | 2151 return TypeFeedbackId(local_id(2)); |
2152 } | 2152 } |
2153 TypeFeedbackId CountStoreFeedbackId() const { | 2153 TypeFeedbackId CountStoreFeedbackId() const { |
2154 return TypeFeedbackId(local_id(3)); | 2154 return TypeFeedbackId(local_id(3)); |
2155 } | 2155 } |
(...skipping 24 matching lines...) Expand all Loading... |
2180 class IsPrefixField : public BitField16<bool, 0, 1> {}; | 2180 class IsPrefixField : public BitField16<bool, 0, 1> {}; |
2181 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; | 2181 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; |
2182 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; | 2182 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; |
2183 class TokenField : public BitField16<Token::Value, 5, 8> {}; | 2183 class TokenField : public BitField16<Token::Value, 5, 8> {}; |
2184 | 2184 |
2185 // Starts with 16-bit field, which should get packed together with | 2185 // Starts with 16-bit field, which should get packed together with |
2186 // Expression's trailing 16-bit field. | 2186 // Expression's trailing 16-bit field. |
2187 uint16_t bit_field_; | 2187 uint16_t bit_field_; |
2188 FeedbackVectorSlot slot_; | 2188 FeedbackVectorSlot slot_; |
2189 FeedbackVectorSlot binary_operation_slot_; | 2189 FeedbackVectorSlot binary_operation_slot_; |
2190 Type* type_; | 2190 AstType* type_; |
2191 Expression* expression_; | 2191 Expression* expression_; |
2192 SmallMapList receiver_types_; | 2192 SmallMapList receiver_types_; |
2193 }; | 2193 }; |
2194 | 2194 |
2195 | 2195 |
2196 class CompareOperation final : public Expression { | 2196 class CompareOperation final : public Expression { |
2197 public: | 2197 public: |
2198 Token::Value op() const { return op_; } | 2198 Token::Value op() const { return op_; } |
2199 Expression* left() const { return left_; } | 2199 Expression* left() const { return left_; } |
2200 Expression* right() const { return right_; } | 2200 Expression* right() const { return right_; } |
2201 | 2201 |
2202 void set_left(Expression* e) { left_ = e; } | 2202 void set_left(Expression* e) { left_ = e; } |
2203 void set_right(Expression* e) { right_ = e; } | 2203 void set_right(Expression* e) { right_ = e; } |
2204 | 2204 |
2205 // Type feedback information. | 2205 // Type feedback information. |
2206 static int num_ids() { return parent_num_ids() + 1; } | 2206 static int num_ids() { return parent_num_ids() + 1; } |
2207 TypeFeedbackId CompareOperationFeedbackId() const { | 2207 TypeFeedbackId CompareOperationFeedbackId() const { |
2208 return TypeFeedbackId(local_id(0)); | 2208 return TypeFeedbackId(local_id(0)); |
2209 } | 2209 } |
2210 Type* combined_type() const { return combined_type_; } | 2210 AstType* combined_type() const { return combined_type_; } |
2211 void set_combined_type(Type* type) { combined_type_ = type; } | 2211 void set_combined_type(AstType* type) { combined_type_ = type; } |
2212 | 2212 |
2213 // CompareOperation will have both a slot in the feedback vector and the | 2213 // CompareOperation will have both a slot in the feedback vector and the |
2214 // TypeFeedbackId to record the type information. TypeFeedbackId is used | 2214 // TypeFeedbackId to record the type information. TypeFeedbackId is used |
2215 // by full codegen and the feedback vector slot is used by interpreter. | 2215 // by full codegen and the feedback vector slot is used by interpreter. |
2216 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 2216 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
2217 FeedbackVectorSlotCache* cache); | 2217 FeedbackVectorSlotCache* cache); |
2218 | 2218 |
2219 FeedbackVectorSlot CompareOperationFeedbackSlot() const { | 2219 FeedbackVectorSlot CompareOperationFeedbackSlot() const { |
2220 return type_feedback_slot_; | 2220 return type_feedback_slot_; |
2221 } | 2221 } |
2222 | 2222 |
2223 // Match special cases. | 2223 // Match special cases. |
2224 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); | 2224 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); |
2225 bool IsLiteralCompareUndefined(Expression** expr); | 2225 bool IsLiteralCompareUndefined(Expression** expr); |
2226 bool IsLiteralCompareNull(Expression** expr); | 2226 bool IsLiteralCompareNull(Expression** expr); |
2227 | 2227 |
2228 private: | 2228 private: |
2229 friend class AstNodeFactory; | 2229 friend class AstNodeFactory; |
2230 | 2230 |
2231 CompareOperation(Token::Value op, Expression* left, Expression* right, | 2231 CompareOperation(Token::Value op, Expression* left, Expression* right, |
2232 int pos) | 2232 int pos) |
2233 : Expression(pos, kCompareOperation), | 2233 : Expression(pos, kCompareOperation), |
2234 op_(op), | 2234 op_(op), |
2235 left_(left), | 2235 left_(left), |
2236 right_(right), | 2236 right_(right), |
2237 combined_type_(Type::None()) { | 2237 combined_type_(AstType::None()) { |
2238 DCHECK(Token::IsCompareOp(op)); | 2238 DCHECK(Token::IsCompareOp(op)); |
2239 } | 2239 } |
2240 | 2240 |
2241 static int parent_num_ids() { return Expression::num_ids(); } | 2241 static int parent_num_ids() { return Expression::num_ids(); } |
2242 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2242 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
2243 | 2243 |
2244 Token::Value op_; | 2244 Token::Value op_; |
2245 Expression* left_; | 2245 Expression* left_; |
2246 Expression* right_; | 2246 Expression* right_; |
2247 | 2247 |
2248 Type* combined_type_; | 2248 AstType* combined_type_; |
2249 FeedbackVectorSlot type_feedback_slot_; | 2249 FeedbackVectorSlot type_feedback_slot_; |
2250 }; | 2250 }; |
2251 | 2251 |
2252 | 2252 |
2253 class Spread final : public Expression { | 2253 class Spread final : public Expression { |
2254 public: | 2254 public: |
2255 Expression* expression() const { return expression_; } | 2255 Expression* expression() const { return expression_; } |
2256 void set_expression(Expression* e) { expression_ = e; } | 2256 void set_expression(Expression* e) { expression_ = e; } |
2257 | 2257 |
2258 int expression_position() const { return expr_pos_; } | 2258 int expression_position() const { return expr_pos_; } |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3464 : NULL; \ | 3464 : NULL; \ |
3465 } | 3465 } |
3466 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3466 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3467 #undef DECLARE_NODE_FUNCTIONS | 3467 #undef DECLARE_NODE_FUNCTIONS |
3468 | 3468 |
3469 | 3469 |
3470 } // namespace internal | 3470 } // namespace internal |
3471 } // namespace v8 | 3471 } // namespace v8 |
3472 | 3472 |
3473 #endif // V8_AST_AST_H_ | 3473 #endif // V8_AST_AST_H_ |
OLD | NEW |