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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "assembler.h" | 33 #include "assembler.h" |
34 #include "factory.h" | 34 #include "factory.h" |
35 #include "isolate.h" | 35 #include "isolate.h" |
36 #include "jsregexp.h" | 36 #include "jsregexp.h" |
37 #include "list-inl.h" | 37 #include "list-inl.h" |
38 #include "runtime.h" | 38 #include "runtime.h" |
39 #include "small-pointer-list.h" | 39 #include "small-pointer-list.h" |
40 #include "smart-pointers.h" | 40 #include "smart-pointers.h" |
41 #include "token.h" | 41 #include "token.h" |
42 #include "type-info.h" | 42 #include "type-info.h" // TODO(rossberg): this should eventually be removed |
| 43 #include "types.h" |
43 #include "utils.h" | 44 #include "utils.h" |
44 #include "variables.h" | 45 #include "variables.h" |
45 #include "interface.h" | 46 #include "interface.h" |
46 #include "zone-inl.h" | 47 #include "zone-inl.h" |
47 | 48 |
48 namespace v8 { | 49 namespace v8 { |
49 namespace internal { | 50 namespace internal { |
50 | 51 |
51 // The abstract syntax tree is an intermediate, light-weight | 52 // The abstract syntax tree is an intermediate, light-weight |
52 // representation of the parsed JavaScript code suitable for | 53 // representation of the parsed JavaScript code suitable for |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 AST_NODE_LIST(DEF_FORWARD_DECLARATION) | 157 AST_NODE_LIST(DEF_FORWARD_DECLARATION) |
157 #undef DEF_FORWARD_DECLARATION | 158 #undef DEF_FORWARD_DECLARATION |
158 | 159 |
159 | 160 |
160 // Typedef only introduced to avoid unreadable code. | 161 // Typedef only introduced to avoid unreadable code. |
161 // Please do appreciate the required space in "> >". | 162 // Please do appreciate the required space in "> >". |
162 typedef ZoneList<Handle<String> > ZoneStringList; | 163 typedef ZoneList<Handle<String> > ZoneStringList; |
163 typedef ZoneList<Handle<Object> > ZoneObjectList; | 164 typedef ZoneList<Handle<Object> > ZoneObjectList; |
164 | 165 |
165 | 166 |
166 #define DECLARE_NODE_TYPE(type) \ | 167 #define DECLARE_NODE_TYPE(type) \ |
167 virtual void Accept(AstVisitor* v); \ | 168 virtual void Accept(AstVisitor* v); \ |
168 virtual AstNode::Type node_type() const { return AstNode::k##type; } \ | 169 virtual AstNode::NodeType node_type() const { return AstNode::k##type; } \ |
169 template<class> friend class AstNodeFactory; | 170 template<class> friend class AstNodeFactory; |
170 | 171 |
171 | 172 |
172 enum AstPropertiesFlag { | 173 enum AstPropertiesFlag { |
173 kDontInline, | 174 kDontInline, |
174 kDontOptimize, | 175 kDontOptimize, |
175 kDontSelfOptimize, | 176 kDontSelfOptimize, |
176 kDontSoftInline, | 177 kDontSoftInline, |
177 kDontCache | 178 kDontCache |
178 }; | 179 }; |
(...skipping 11 matching lines...) Expand all Loading... |
190 | 191 |
191 private: | 192 private: |
192 Flags flags_; | 193 Flags flags_; |
193 int node_count_; | 194 int node_count_; |
194 }; | 195 }; |
195 | 196 |
196 | 197 |
197 class AstNode: public ZoneObject { | 198 class AstNode: public ZoneObject { |
198 public: | 199 public: |
199 #define DECLARE_TYPE_ENUM(type) k##type, | 200 #define DECLARE_TYPE_ENUM(type) k##type, |
200 enum Type { | 201 enum NodeType { |
201 AST_NODE_LIST(DECLARE_TYPE_ENUM) | 202 AST_NODE_LIST(DECLARE_TYPE_ENUM) |
202 kInvalid = -1 | 203 kInvalid = -1 |
203 }; | 204 }; |
204 #undef DECLARE_TYPE_ENUM | 205 #undef DECLARE_TYPE_ENUM |
205 | 206 |
206 void* operator new(size_t size, Zone* zone) { | 207 void* operator new(size_t size, Zone* zone) { |
207 return zone->New(static_cast<int>(size)); | 208 return zone->New(static_cast<int>(size)); |
208 } | 209 } |
209 | 210 |
210 AstNode() { } | 211 AstNode() { } |
211 | 212 |
212 virtual ~AstNode() { } | 213 virtual ~AstNode() { } |
213 | 214 |
214 virtual void Accept(AstVisitor* v) = 0; | 215 virtual void Accept(AstVisitor* v) = 0; |
215 virtual Type node_type() const = 0; | 216 virtual NodeType node_type() const = 0; |
216 | 217 |
217 // Type testing & conversion functions overridden by concrete subclasses. | 218 // Type testing & conversion functions overridden by concrete subclasses. |
218 #define DECLARE_NODE_FUNCTIONS(type) \ | 219 #define DECLARE_NODE_FUNCTIONS(type) \ |
219 bool Is##type() { return node_type() == AstNode::k##type; } \ | 220 bool Is##type() { return node_type() == AstNode::k##type; } \ |
220 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } | 221 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } |
221 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 222 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
222 #undef DECLARE_NODE_FUNCTIONS | 223 #undef DECLARE_NODE_FUNCTIONS |
223 | 224 |
224 virtual TargetCollector* AsTargetCollector() { return NULL; } | 225 virtual TargetCollector* AsTargetCollector() { return NULL; } |
225 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 226 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 348 |
348 // True iff the expression is a string literal. | 349 // True iff the expression is a string literal. |
349 bool IsStringLiteral(); | 350 bool IsStringLiteral(); |
350 | 351 |
351 // True iff the expression is the null literal. | 352 // True iff the expression is the null literal. |
352 bool IsNullLiteral(); | 353 bool IsNullLiteral(); |
353 | 354 |
354 // True iff the expression is the undefined literal. | 355 // True iff the expression is the undefined literal. |
355 bool IsUndefinedLiteral(); | 356 bool IsUndefinedLiteral(); |
356 | 357 |
| 358 // Expression type |
| 359 Handle<Type> type() { return type_; } |
| 360 |
357 // Type feedback information for assignments and properties. | 361 // Type feedback information for assignments and properties. |
358 virtual bool IsMonomorphic() { | 362 virtual bool IsMonomorphic() { |
359 UNREACHABLE(); | 363 UNREACHABLE(); |
360 return false; | 364 return false; |
361 } | 365 } |
362 virtual SmallMapList* GetReceiverTypes() { | 366 virtual SmallMapList* GetReceiverTypes() { |
363 UNREACHABLE(); | 367 UNREACHABLE(); |
364 return NULL; | 368 return NULL; |
365 } | 369 } |
366 Handle<Map> GetMonomorphicReceiverType() { | 370 Handle<Map> GetMonomorphicReceiverType() { |
367 ASSERT(IsMonomorphic()); | 371 ASSERT(IsMonomorphic()); |
368 SmallMapList* types = GetReceiverTypes(); | 372 SmallMapList* types = GetReceiverTypes(); |
369 ASSERT(types != NULL && types->length() == 1); | 373 ASSERT(types != NULL && types->length() == 1); |
370 return types->at(0); | 374 return types->at(0); |
371 } | 375 } |
372 virtual KeyedAccessStoreMode GetStoreMode() { | 376 virtual KeyedAccessStoreMode GetStoreMode() { |
373 UNREACHABLE(); | 377 UNREACHABLE(); |
374 return STANDARD_STORE; | 378 return STANDARD_STORE; |
375 } | 379 } |
376 | 380 |
377 // TODO(rossberg): this should move to its own AST node eventually. | 381 // TODO(rossberg): this should move to its own AST node eventually. |
378 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); | 382 void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); |
379 byte to_boolean_types() const { return to_boolean_types_; } | 383 byte to_boolean_types() const { return to_boolean_types_; } |
380 | 384 |
381 BailoutId id() const { return id_; } | 385 BailoutId id() const { return id_; } |
382 TypeFeedbackId test_id() const { return test_id_; } | 386 TypeFeedbackId test_id() const { return test_id_; } |
383 | 387 |
384 protected: | 388 protected: |
385 explicit Expression(Isolate* isolate) | 389 explicit Expression(Isolate* isolate) |
386 : id_(GetNextId(isolate)), | 390 : type_(Type::Any(), isolate), |
| 391 id_(GetNextId(isolate)), |
387 test_id_(GetNextId(isolate)) {} | 392 test_id_(GetNextId(isolate)) {} |
388 | 393 |
389 private: | 394 private: |
| 395 Handle<Type> type_; |
390 byte to_boolean_types_; | 396 byte to_boolean_types_; |
391 | 397 |
392 const BailoutId id_; | 398 const BailoutId id_; |
393 const TypeFeedbackId test_id_; | 399 const TypeFeedbackId test_id_; |
394 }; | 400 }; |
395 | 401 |
396 | 402 |
397 class BreakableStatement: public Statement { | 403 class BreakableStatement: public Statement { |
398 public: | 404 public: |
399 enum Type { | 405 enum BreakableType { |
400 TARGET_FOR_ANONYMOUS, | 406 TARGET_FOR_ANONYMOUS, |
401 TARGET_FOR_NAMED_ONLY | 407 TARGET_FOR_NAMED_ONLY |
402 }; | 408 }; |
403 | 409 |
404 // The labels associated with this statement. May be NULL; | 410 // The labels associated with this statement. May be NULL; |
405 // if it is != NULL, guaranteed to contain at least one entry. | 411 // if it is != NULL, guaranteed to contain at least one entry. |
406 ZoneStringList* labels() const { return labels_; } | 412 ZoneStringList* labels() const { return labels_; } |
407 | 413 |
408 // Type testing & conversion. | 414 // Type testing & conversion. |
409 virtual BreakableStatement* AsBreakableStatement() { return this; } | 415 virtual BreakableStatement* AsBreakableStatement() { return this; } |
410 | 416 |
411 // Code generation | 417 // Code generation |
412 Label* break_target() { return &break_target_; } | 418 Label* break_target() { return &break_target_; } |
413 | 419 |
414 // Testers. | 420 // Testers. |
415 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } | 421 bool is_target_for_anonymous() const { |
| 422 return breakable_type_ == TARGET_FOR_ANONYMOUS; |
| 423 } |
416 | 424 |
417 BailoutId EntryId() const { return entry_id_; } | 425 BailoutId EntryId() const { return entry_id_; } |
418 BailoutId ExitId() const { return exit_id_; } | 426 BailoutId ExitId() const { return exit_id_; } |
419 | 427 |
420 protected: | 428 protected: |
421 BreakableStatement(Isolate* isolate, ZoneStringList* labels, Type type) | 429 BreakableStatement( |
| 430 Isolate* isolate, ZoneStringList* labels, BreakableType breakable_type) |
422 : labels_(labels), | 431 : labels_(labels), |
423 type_(type), | 432 breakable_type_(breakable_type), |
424 entry_id_(GetNextId(isolate)), | 433 entry_id_(GetNextId(isolate)), |
425 exit_id_(GetNextId(isolate)) { | 434 exit_id_(GetNextId(isolate)) { |
426 ASSERT(labels == NULL || labels->length() > 0); | 435 ASSERT(labels == NULL || labels->length() > 0); |
427 } | 436 } |
428 | 437 |
429 | 438 |
430 private: | 439 private: |
431 ZoneStringList* labels_; | 440 ZoneStringList* labels_; |
432 Type type_; | 441 BreakableType breakable_type_; |
433 Label break_target_; | 442 Label break_target_; |
434 const BailoutId entry_id_; | 443 const BailoutId entry_id_; |
435 const BailoutId exit_id_; | 444 const BailoutId exit_id_; |
436 }; | 445 }; |
437 | 446 |
438 | 447 |
439 class Block: public BreakableStatement { | 448 class Block: public BreakableStatement { |
440 public: | 449 public: |
441 DECLARE_NODE_TYPE(Block) | 450 DECLARE_NODE_TYPE(Block) |
442 | 451 |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 public: | 1125 public: |
1117 explicit TargetCollector(Zone* zone) : targets_(0, zone) { } | 1126 explicit TargetCollector(Zone* zone) : targets_(0, zone) { } |
1118 | 1127 |
1119 // Adds a jump target to the collector. The collector stores a pointer not | 1128 // Adds a jump target to the collector. The collector stores a pointer not |
1120 // a copy of the target to make binding work, so make sure not to pass in | 1129 // a copy of the target to make binding work, so make sure not to pass in |
1121 // references to something on the stack. | 1130 // references to something on the stack. |
1122 void AddTarget(Label* target, Zone* zone); | 1131 void AddTarget(Label* target, Zone* zone); |
1123 | 1132 |
1124 // Virtual behaviour. TargetCollectors are never part of the AST. | 1133 // Virtual behaviour. TargetCollectors are never part of the AST. |
1125 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } | 1134 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
1126 virtual Type node_type() const { return kInvalid; } | 1135 virtual NodeType node_type() const { return kInvalid; } |
1127 virtual TargetCollector* AsTargetCollector() { return this; } | 1136 virtual TargetCollector* AsTargetCollector() { return this; } |
1128 | 1137 |
1129 ZoneList<Label*>* targets() { return &targets_; } | 1138 ZoneList<Label*>* targets() { return &targets_; } |
1130 | 1139 |
1131 private: | 1140 private: |
1132 ZoneList<Label*> targets_; | 1141 ZoneList<Label*> targets_; |
1133 }; | 1142 }; |
1134 | 1143 |
1135 | 1144 |
1136 class TryStatement: public Statement { | 1145 class TryStatement: public Statement { |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 : Expression(isolate), exception_(exception), pos_(pos) {} | 2119 : Expression(isolate), exception_(exception), pos_(pos) {} |
2111 | 2120 |
2112 private: | 2121 private: |
2113 Expression* exception_; | 2122 Expression* exception_; |
2114 int pos_; | 2123 int pos_; |
2115 }; | 2124 }; |
2116 | 2125 |
2117 | 2126 |
2118 class FunctionLiteral: public Expression { | 2127 class FunctionLiteral: public Expression { |
2119 public: | 2128 public: |
2120 enum Type { | 2129 enum FunctionType { |
2121 ANONYMOUS_EXPRESSION, | 2130 ANONYMOUS_EXPRESSION, |
2122 NAMED_EXPRESSION, | 2131 NAMED_EXPRESSION, |
2123 DECLARATION | 2132 DECLARATION |
2124 }; | 2133 }; |
2125 | 2134 |
2126 enum ParameterFlag { | 2135 enum ParameterFlag { |
2127 kNoDuplicateParameters = 0, | 2136 kNoDuplicateParameters = 0, |
2128 kHasDuplicateParameters = 1 | 2137 kHasDuplicateParameters = 1 |
2129 }; | 2138 }; |
2130 | 2139 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2209 | 2218 |
2210 protected: | 2219 protected: |
2211 FunctionLiteral(Isolate* isolate, | 2220 FunctionLiteral(Isolate* isolate, |
2212 Handle<String> name, | 2221 Handle<String> name, |
2213 Scope* scope, | 2222 Scope* scope, |
2214 ZoneList<Statement*>* body, | 2223 ZoneList<Statement*>* body, |
2215 int materialized_literal_count, | 2224 int materialized_literal_count, |
2216 int expected_property_count, | 2225 int expected_property_count, |
2217 int handler_count, | 2226 int handler_count, |
2218 int parameter_count, | 2227 int parameter_count, |
2219 Type type, | 2228 FunctionType function_type, |
2220 ParameterFlag has_duplicate_parameters, | 2229 ParameterFlag has_duplicate_parameters, |
2221 IsFunctionFlag is_function, | 2230 IsFunctionFlag is_function, |
2222 IsParenthesizedFlag is_parenthesized, | 2231 IsParenthesizedFlag is_parenthesized, |
2223 IsGeneratorFlag is_generator) | 2232 IsGeneratorFlag is_generator) |
2224 : Expression(isolate), | 2233 : Expression(isolate), |
2225 name_(name), | 2234 name_(name), |
2226 scope_(scope), | 2235 scope_(scope), |
2227 body_(body), | 2236 body_(body), |
2228 inferred_name_(isolate->factory()->empty_string()), | 2237 inferred_name_(isolate->factory()->empty_string()), |
2229 materialized_literal_count_(materialized_literal_count), | 2238 materialized_literal_count_(materialized_literal_count), |
2230 expected_property_count_(expected_property_count), | 2239 expected_property_count_(expected_property_count), |
2231 handler_count_(handler_count), | 2240 handler_count_(handler_count), |
2232 parameter_count_(parameter_count), | 2241 parameter_count_(parameter_count), |
2233 function_token_position_(RelocInfo::kNoPosition) { | 2242 function_token_position_(RelocInfo::kNoPosition) { |
2234 bitfield_ = | 2243 bitfield_ = |
2235 IsExpression::encode(type != DECLARATION) | | 2244 IsExpression::encode(function_type != DECLARATION) | |
2236 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | | 2245 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | |
2237 Pretenure::encode(false) | | 2246 Pretenure::encode(false) | |
2238 HasDuplicateParameters::encode(has_duplicate_parameters) | | 2247 HasDuplicateParameters::encode(has_duplicate_parameters) | |
2239 IsFunction::encode(is_function) | | 2248 IsFunction::encode(is_function) | |
2240 IsParenthesized::encode(is_parenthesized) | | 2249 IsParenthesized::encode(is_parenthesized) | |
2241 IsGenerator::encode(is_generator); | 2250 IsGenerator::encode(is_generator); |
2242 } | 2251 } |
2243 | 2252 |
2244 private: | 2253 private: |
2245 Handle<String> name_; | 2254 Handle<String> name_; |
2246 Scope* scope_; | 2255 Scope* scope_; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 ZoneList<RegExpTree*>* nodes() { return nodes_; } | 2381 ZoneList<RegExpTree*>* nodes() { return nodes_; } |
2373 private: | 2382 private: |
2374 ZoneList<RegExpTree*>* nodes_; | 2383 ZoneList<RegExpTree*>* nodes_; |
2375 int min_match_; | 2384 int min_match_; |
2376 int max_match_; | 2385 int max_match_; |
2377 }; | 2386 }; |
2378 | 2387 |
2379 | 2388 |
2380 class RegExpAssertion: public RegExpTree { | 2389 class RegExpAssertion: public RegExpTree { |
2381 public: | 2390 public: |
2382 enum Type { | 2391 enum AssertionType { |
2383 START_OF_LINE, | 2392 START_OF_LINE, |
2384 START_OF_INPUT, | 2393 START_OF_INPUT, |
2385 END_OF_LINE, | 2394 END_OF_LINE, |
2386 END_OF_INPUT, | 2395 END_OF_INPUT, |
2387 BOUNDARY, | 2396 BOUNDARY, |
2388 NON_BOUNDARY | 2397 NON_BOUNDARY |
2389 }; | 2398 }; |
2390 explicit RegExpAssertion(Type type) : type_(type) { } | 2399 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { } |
2391 virtual void* Accept(RegExpVisitor* visitor, void* data); | 2400 virtual void* Accept(RegExpVisitor* visitor, void* data); |
2392 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 2401 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
2393 RegExpNode* on_success); | 2402 RegExpNode* on_success); |
2394 virtual RegExpAssertion* AsAssertion(); | 2403 virtual RegExpAssertion* AsAssertion(); |
2395 virtual bool IsAssertion(); | 2404 virtual bool IsAssertion(); |
2396 virtual bool IsAnchoredAtStart(); | 2405 virtual bool IsAnchoredAtStart(); |
2397 virtual bool IsAnchoredAtEnd(); | 2406 virtual bool IsAnchoredAtEnd(); |
2398 virtual int min_match() { return 0; } | 2407 virtual int min_match() { return 0; } |
2399 virtual int max_match() { return 0; } | 2408 virtual int max_match() { return 0; } |
2400 Type type() { return type_; } | 2409 AssertionType assertion_type() { return assertion_type_; } |
2401 private: | 2410 private: |
2402 Type type_; | 2411 AssertionType assertion_type_; |
2403 }; | 2412 }; |
2404 | 2413 |
2405 | 2414 |
2406 class CharacterSet BASE_EMBEDDED { | 2415 class CharacterSet BASE_EMBEDDED { |
2407 public: | 2416 public: |
2408 explicit CharacterSet(uc16 standard_set_type) | 2417 explicit CharacterSet(uc16 standard_set_type) |
2409 : ranges_(NULL), | 2418 : ranges_(NULL), |
2410 standard_set_type_(standard_set_type) {} | 2419 standard_set_type_(standard_set_type) {} |
2411 explicit CharacterSet(ZoneList<CharacterRange>* ranges) | 2420 explicit CharacterSet(ZoneList<CharacterRange>* ranges) |
2412 : ranges_(ranges), | 2421 : ranges_(ranges), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2505 } | 2514 } |
2506 ZoneList<TextElement>* elements() { return &elements_; } | 2515 ZoneList<TextElement>* elements() { return &elements_; } |
2507 private: | 2516 private: |
2508 ZoneList<TextElement> elements_; | 2517 ZoneList<TextElement> elements_; |
2509 int length_; | 2518 int length_; |
2510 }; | 2519 }; |
2511 | 2520 |
2512 | 2521 |
2513 class RegExpQuantifier: public RegExpTree { | 2522 class RegExpQuantifier: public RegExpTree { |
2514 public: | 2523 public: |
2515 enum Type { GREEDY, NON_GREEDY, POSSESSIVE }; | 2524 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE }; |
2516 RegExpQuantifier(int min, int max, Type type, RegExpTree* body) | 2525 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body) |
2517 : body_(body), | 2526 : body_(body), |
2518 min_(min), | 2527 min_(min), |
2519 max_(max), | 2528 max_(max), |
2520 min_match_(min * body->min_match()), | 2529 min_match_(min * body->min_match()), |
2521 type_(type) { | 2530 quantifier_type_(type) { |
2522 if (max > 0 && body->max_match() > kInfinity / max) { | 2531 if (max > 0 && body->max_match() > kInfinity / max) { |
2523 max_match_ = kInfinity; | 2532 max_match_ = kInfinity; |
2524 } else { | 2533 } else { |
2525 max_match_ = max * body->max_match(); | 2534 max_match_ = max * body->max_match(); |
2526 } | 2535 } |
2527 } | 2536 } |
2528 virtual void* Accept(RegExpVisitor* visitor, void* data); | 2537 virtual void* Accept(RegExpVisitor* visitor, void* data); |
2529 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 2538 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
2530 RegExpNode* on_success); | 2539 RegExpNode* on_success); |
2531 static RegExpNode* ToNode(int min, | 2540 static RegExpNode* ToNode(int min, |
2532 int max, | 2541 int max, |
2533 bool is_greedy, | 2542 bool is_greedy, |
2534 RegExpTree* body, | 2543 RegExpTree* body, |
2535 RegExpCompiler* compiler, | 2544 RegExpCompiler* compiler, |
2536 RegExpNode* on_success, | 2545 RegExpNode* on_success, |
2537 bool not_at_start = false); | 2546 bool not_at_start = false); |
2538 virtual RegExpQuantifier* AsQuantifier(); | 2547 virtual RegExpQuantifier* AsQuantifier(); |
2539 virtual Interval CaptureRegisters(); | 2548 virtual Interval CaptureRegisters(); |
2540 virtual bool IsQuantifier(); | 2549 virtual bool IsQuantifier(); |
2541 virtual int min_match() { return min_match_; } | 2550 virtual int min_match() { return min_match_; } |
2542 virtual int max_match() { return max_match_; } | 2551 virtual int max_match() { return max_match_; } |
2543 int min() { return min_; } | 2552 int min() { return min_; } |
2544 int max() { return max_; } | 2553 int max() { return max_; } |
2545 bool is_possessive() { return type_ == POSSESSIVE; } | 2554 bool is_possessive() { return quantifier_type_ == POSSESSIVE; } |
2546 bool is_non_greedy() { return type_ == NON_GREEDY; } | 2555 bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; } |
2547 bool is_greedy() { return type_ == GREEDY; } | 2556 bool is_greedy() { return quantifier_type_ == GREEDY; } |
2548 RegExpTree* body() { return body_; } | 2557 RegExpTree* body() { return body_; } |
2549 | 2558 |
2550 private: | 2559 private: |
2551 RegExpTree* body_; | 2560 RegExpTree* body_; |
2552 int min_; | 2561 int min_; |
2553 int max_; | 2562 int max_; |
2554 int min_match_; | 2563 int min_match_; |
2555 int max_match_; | 2564 int max_match_; |
2556 Type type_; | 2565 QuantifierType quantifier_type_; |
2557 }; | 2566 }; |
2558 | 2567 |
2559 | 2568 |
2560 class RegExpCapture: public RegExpTree { | 2569 class RegExpCapture: public RegExpTree { |
2561 public: | 2570 public: |
2562 explicit RegExpCapture(RegExpTree* body, int index) | 2571 explicit RegExpCapture(RegExpTree* body, int index) |
2563 : body_(body), index_(index) { } | 2572 : body_(body), index_(index) { } |
2564 virtual void* Accept(RegExpVisitor* visitor, void* data); | 2573 virtual void* Accept(RegExpVisitor* visitor, void* data); |
2565 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 2574 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
2566 RegExpNode* on_success); | 2575 RegExpNode* on_success); |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3079 | 3088 |
3080 FunctionLiteral* NewFunctionLiteral( | 3089 FunctionLiteral* NewFunctionLiteral( |
3081 Handle<String> name, | 3090 Handle<String> name, |
3082 Scope* scope, | 3091 Scope* scope, |
3083 ZoneList<Statement*>* body, | 3092 ZoneList<Statement*>* body, |
3084 int materialized_literal_count, | 3093 int materialized_literal_count, |
3085 int expected_property_count, | 3094 int expected_property_count, |
3086 int handler_count, | 3095 int handler_count, |
3087 int parameter_count, | 3096 int parameter_count, |
3088 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3097 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3089 FunctionLiteral::Type type, | 3098 FunctionLiteral::FunctionType function_type, |
3090 FunctionLiteral::IsFunctionFlag is_function, | 3099 FunctionLiteral::IsFunctionFlag is_function, |
3091 FunctionLiteral::IsParenthesizedFlag is_parenthesized, | 3100 FunctionLiteral::IsParenthesizedFlag is_parenthesized, |
3092 FunctionLiteral::IsGeneratorFlag is_generator) { | 3101 FunctionLiteral::IsGeneratorFlag is_generator) { |
3093 FunctionLiteral* lit = new(zone_) FunctionLiteral( | 3102 FunctionLiteral* lit = new(zone_) FunctionLiteral( |
3094 isolate_, name, scope, body, | 3103 isolate_, name, scope, body, |
3095 materialized_literal_count, expected_property_count, handler_count, | 3104 materialized_literal_count, expected_property_count, handler_count, |
3096 parameter_count, type, has_duplicate_parameters, is_function, | 3105 parameter_count, function_type, has_duplicate_parameters, is_function, |
3097 is_parenthesized, is_generator); | 3106 is_parenthesized, is_generator); |
3098 // Top-level literal doesn't count for the AST's properties. | 3107 // Top-level literal doesn't count for the AST's properties. |
3099 if (is_function == FunctionLiteral::kIsFunction) { | 3108 if (is_function == FunctionLiteral::kIsFunction) { |
3100 visitor_.VisitFunctionLiteral(lit); | 3109 visitor_.VisitFunctionLiteral(lit); |
3101 } | 3110 } |
3102 return lit; | 3111 return lit; |
3103 } | 3112 } |
3104 | 3113 |
3105 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( | 3114 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( |
3106 Handle<SharedFunctionInfo> shared_function_info) { | 3115 Handle<SharedFunctionInfo> shared_function_info) { |
(...skipping 12 matching lines...) Expand all Loading... |
3119 private: | 3128 private: |
3120 Isolate* isolate_; | 3129 Isolate* isolate_; |
3121 Zone* zone_; | 3130 Zone* zone_; |
3122 Visitor visitor_; | 3131 Visitor visitor_; |
3123 }; | 3132 }; |
3124 | 3133 |
3125 | 3134 |
3126 } } // namespace v8::internal | 3135 } } // namespace v8::internal |
3127 | 3136 |
3128 #endif // V8_AST_H_ | 3137 #endif // V8_AST_H_ |
OLD | NEW |