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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 208 } |
209 | 209 |
210 explicit AstNode(int position): position_(position) {} | 210 explicit AstNode(int position): position_(position) {} |
211 virtual ~AstNode() {} | 211 virtual ~AstNode() {} |
212 | 212 |
213 virtual void Accept(AstVisitor* v) = 0; | 213 virtual void Accept(AstVisitor* v) = 0; |
214 virtual NodeType node_type() const = 0; | 214 virtual NodeType node_type() const = 0; |
215 int position() const { return position_; } | 215 int position() const { return position_; } |
216 | 216 |
217 // Type testing & conversion functions overridden by concrete subclasses. | 217 // Type testing & conversion functions overridden by concrete subclasses. |
218 #define DECLARE_NODE_FUNCTIONS(type) \ | 218 #define DECLARE_NODE_FUNCTIONS(type) \ |
219 bool Is##type() { return node_type() == AstNode::k##type; } \ | 219 bool Is##type() const { return node_type() == AstNode::k##type; } \ |
220 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } | 220 type* As##type() { \ |
| 221 return Is##type() ? reinterpret_cast<type*>(this) : NULL; \ |
| 222 } \ |
| 223 const type* As##type() const { \ |
| 224 return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \ |
| 225 } |
221 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 226 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
222 #undef DECLARE_NODE_FUNCTIONS | 227 #undef DECLARE_NODE_FUNCTIONS |
223 | 228 |
224 virtual TargetCollector* AsTargetCollector() { return NULL; } | 229 virtual TargetCollector* AsTargetCollector() { return NULL; } |
225 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 230 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
226 virtual IterationStatement* AsIterationStatement() { return NULL; } | 231 virtual IterationStatement* AsIterationStatement() { return NULL; } |
227 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 232 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
228 | 233 |
229 protected: | 234 protected: |
230 static int GetNextId(Zone* zone) { | 235 static int GetNextId(Zone* zone) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // code generation. | 323 // code generation. |
319 kUninitialized, | 324 kUninitialized, |
320 // Evaluated for its side effects. | 325 // Evaluated for its side effects. |
321 kEffect, | 326 kEffect, |
322 // Evaluated for its value (and side effects). | 327 // Evaluated for its value (and side effects). |
323 kValue, | 328 kValue, |
324 // Evaluated for control flow (and side effects). | 329 // Evaluated for control flow (and side effects). |
325 kTest | 330 kTest |
326 }; | 331 }; |
327 | 332 |
328 virtual bool IsValidLeftHandSide() { return false; } | 333 virtual bool IsValidLeftHandSide() const { return false; } |
329 | 334 |
330 // Helpers for ToBoolean conversion. | 335 // Helpers for ToBoolean conversion. |
331 virtual bool ToBooleanIsTrue() { return false; } | 336 virtual bool ToBooleanIsTrue() const { return false; } |
332 virtual bool ToBooleanIsFalse() { return false; } | 337 virtual bool ToBooleanIsFalse() const { return false; } |
333 | 338 |
334 // Symbols that cannot be parsed as array indices are considered property | 339 // Symbols that cannot be parsed as array indices are considered property |
335 // names. We do not treat symbols that can be array indexes as property | 340 // names. We do not treat symbols that can be array indexes as property |
336 // names because [] for string objects is handled only by keyed ICs. | 341 // names because [] for string objects is handled only by keyed ICs. |
337 virtual bool IsPropertyName() { return false; } | 342 virtual bool IsPropertyName() const { return false; } |
338 | 343 |
339 // True iff the result can be safely overwritten (to avoid allocation). | 344 // True iff the result can be safely overwritten (to avoid allocation). |
340 // False for operations that can return one of their operands. | 345 // False for operations that can return one of their operands. |
341 virtual bool ResultOverwriteAllowed() { return false; } | 346 virtual bool ResultOverwriteAllowed() const { return false; } |
342 | 347 |
343 // True iff the expression is a literal represented as a smi. | 348 // True iff the expression is a literal represented as a smi. |
344 bool IsSmiLiteral(); | 349 bool IsSmiLiteral() const; |
345 | 350 |
346 // True iff the expression is a string literal. | 351 // True iff the expression is a string literal. |
347 bool IsStringLiteral(); | 352 bool IsStringLiteral() const; |
348 | 353 |
349 // True iff the expression is the null literal. | 354 // True iff the expression is the null literal. |
350 bool IsNullLiteral(); | 355 bool IsNullLiteral() const; |
351 | 356 |
352 // True if we can prove that the expression is the undefined literal. | 357 // True if we can prove that the expression is the undefined literal. |
353 bool IsUndefinedLiteral(Isolate* isolate); | 358 bool IsUndefinedLiteral(Isolate* isolate) const; |
354 | 359 |
355 // Expression type bounds | 360 // Expression type bounds |
356 Bounds bounds() { return bounds_; } | 361 Bounds bounds() const { return bounds_; } |
357 void set_bounds(Bounds bounds) { bounds_ = bounds; } | 362 void set_bounds(Bounds bounds) { bounds_ = bounds; } |
358 | 363 |
359 // Type feedback information for assignments and properties. | 364 // Type feedback information for assignments and properties. |
360 virtual bool IsMonomorphic() { | 365 virtual bool IsMonomorphic() { |
361 UNREACHABLE(); | 366 UNREACHABLE(); |
362 return false; | 367 return false; |
363 } | 368 } |
364 virtual SmallMapList* GetReceiverTypes() { | 369 virtual SmallMapList* GetReceiverTypes() { |
365 UNREACHABLE(); | 370 UNREACHABLE(); |
366 return NULL; | 371 return NULL; |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 | 1344 |
1340 protected: | 1345 protected: |
1341 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} | 1346 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} |
1342 }; | 1347 }; |
1343 | 1348 |
1344 | 1349 |
1345 class Literal V8_FINAL : public Expression { | 1350 class Literal V8_FINAL : public Expression { |
1346 public: | 1351 public: |
1347 DECLARE_NODE_TYPE(Literal) | 1352 DECLARE_NODE_TYPE(Literal) |
1348 | 1353 |
1349 virtual bool IsPropertyName() V8_OVERRIDE { | 1354 virtual bool IsPropertyName() const V8_OVERRIDE { |
1350 if (value_->IsInternalizedString()) { | 1355 if (value_->IsInternalizedString()) { |
1351 uint32_t ignored; | 1356 uint32_t ignored; |
1352 return !String::cast(*value_)->AsArrayIndex(&ignored); | 1357 return !String::cast(*value_)->AsArrayIndex(&ignored); |
1353 } | 1358 } |
1354 return false; | 1359 return false; |
1355 } | 1360 } |
1356 | 1361 |
1357 Handle<String> AsPropertyName() { | 1362 Handle<String> AsPropertyName() { |
1358 ASSERT(IsPropertyName()); | 1363 ASSERT(IsPropertyName()); |
1359 return Handle<String>::cast(value_); | 1364 return Handle<String>::cast(value_); |
1360 } | 1365 } |
1361 | 1366 |
1362 virtual bool ToBooleanIsTrue() V8_OVERRIDE { | 1367 virtual bool ToBooleanIsTrue() const V8_OVERRIDE { |
1363 return value_->BooleanValue(); | 1368 return value_->BooleanValue(); |
1364 } | 1369 } |
1365 virtual bool ToBooleanIsFalse() V8_OVERRIDE { | 1370 virtual bool ToBooleanIsFalse() const V8_OVERRIDE { |
1366 return !value_->BooleanValue(); | 1371 return !value_->BooleanValue(); |
1367 } | 1372 } |
1368 | 1373 |
1369 // Identity testers. | 1374 // Identity testers. |
1370 bool IsNull() const { | 1375 bool IsNull() const { |
1371 ASSERT(!value_.is_null()); | 1376 ASSERT(!value_.is_null()); |
1372 return value_->IsNull(); | 1377 return value_->IsNull(); |
1373 } | 1378 } |
1374 bool IsTrue() const { | 1379 bool IsTrue() const { |
1375 ASSERT(!value_.is_null()); | 1380 ASSERT(!value_.is_null()); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 Handle<FixedArray> constant_elements_; | 1635 Handle<FixedArray> constant_elements_; |
1631 ZoneList<Expression*>* values_; | 1636 ZoneList<Expression*>* values_; |
1632 const BailoutId first_element_id_; | 1637 const BailoutId first_element_id_; |
1633 }; | 1638 }; |
1634 | 1639 |
1635 | 1640 |
1636 class VariableProxy V8_FINAL : public Expression { | 1641 class VariableProxy V8_FINAL : public Expression { |
1637 public: | 1642 public: |
1638 DECLARE_NODE_TYPE(VariableProxy) | 1643 DECLARE_NODE_TYPE(VariableProxy) |
1639 | 1644 |
1640 virtual bool IsValidLeftHandSide() V8_OVERRIDE { | 1645 virtual bool IsValidLeftHandSide() const V8_OVERRIDE { |
1641 return var_ == NULL ? true : var_->IsValidLeftHandSide(); | 1646 return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
1642 } | 1647 } |
1643 | 1648 |
1644 bool IsVariable(Handle<String> n) { | 1649 bool IsVariable(Handle<String> n) const { |
1645 return !is_this() && name().is_identical_to(n); | 1650 return !is_this() && name().is_identical_to(n); |
1646 } | 1651 } |
1647 | 1652 |
1648 bool IsArguments() { return var_ != NULL && var_->is_arguments(); } | 1653 bool IsArguments() const { return var_ != NULL && var_->is_arguments(); } |
1649 | 1654 |
1650 bool IsLValue() { | 1655 bool IsLValue() const { return is_lvalue_; } |
1651 return is_lvalue_; | |
1652 } | |
1653 | 1656 |
1654 Handle<String> name() const { return name_; } | 1657 Handle<String> name() const { return name_; } |
1655 Variable* var() const { return var_; } | 1658 Variable* var() const { return var_; } |
1656 bool is_this() const { return is_this_; } | 1659 bool is_this() const { return is_this_; } |
1657 Interface* interface() const { return interface_; } | 1660 Interface* interface() const { return interface_; } |
1658 | 1661 |
1659 | 1662 |
1660 void MarkAsTrivial() { is_trivial_ = true; } | 1663 void MarkAsTrivial() { is_trivial_ = true; } |
1661 void MarkAsLValue() { is_lvalue_ = true; } | 1664 void MarkAsLValue() { is_lvalue_ = true; } |
1662 | 1665 |
(...skipping 17 matching lines...) Expand all Loading... |
1680 // or with a increment/decrement operator. | 1683 // or with a increment/decrement operator. |
1681 bool is_lvalue_; | 1684 bool is_lvalue_; |
1682 Interface* interface_; | 1685 Interface* interface_; |
1683 }; | 1686 }; |
1684 | 1687 |
1685 | 1688 |
1686 class Property V8_FINAL : public Expression { | 1689 class Property V8_FINAL : public Expression { |
1687 public: | 1690 public: |
1688 DECLARE_NODE_TYPE(Property) | 1691 DECLARE_NODE_TYPE(Property) |
1689 | 1692 |
1690 virtual bool IsValidLeftHandSide() V8_OVERRIDE { return true; } | 1693 virtual bool IsValidLeftHandSide() const V8_OVERRIDE { return true; } |
1691 | 1694 |
1692 Expression* obj() const { return obj_; } | 1695 Expression* obj() const { return obj_; } |
1693 Expression* key() const { return key_; } | 1696 Expression* key() const { return key_; } |
1694 | 1697 |
1695 BailoutId LoadId() const { return load_id_; } | 1698 BailoutId LoadId() const { return load_id_; } |
1696 | 1699 |
1697 bool IsStringAccess() const { return is_string_access_; } | 1700 bool IsStringAccess() const { return is_string_access_; } |
1698 bool IsFunctionPrototype() const { return is_function_prototype_; } | 1701 bool IsFunctionPrototype() const { return is_function_prototype_; } |
1699 | 1702 |
1700 // Type feedback information. | 1703 // Type feedback information. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 // actually be materialized, respectively. | 1966 // actually be materialized, respectively. |
1964 const BailoutId materialize_true_id_; | 1967 const BailoutId materialize_true_id_; |
1965 const BailoutId materialize_false_id_; | 1968 const BailoutId materialize_false_id_; |
1966 }; | 1969 }; |
1967 | 1970 |
1968 | 1971 |
1969 class BinaryOperation V8_FINAL : public Expression { | 1972 class BinaryOperation V8_FINAL : public Expression { |
1970 public: | 1973 public: |
1971 DECLARE_NODE_TYPE(BinaryOperation) | 1974 DECLARE_NODE_TYPE(BinaryOperation) |
1972 | 1975 |
1973 virtual bool ResultOverwriteAllowed(); | 1976 virtual bool ResultOverwriteAllowed() const V8_OVERRIDE; |
1974 | 1977 |
1975 Token::Value op() const { return op_; } | 1978 Token::Value op() const { return op_; } |
1976 Expression* left() const { return left_; } | 1979 Expression* left() const { return left_; } |
1977 Expression* right() const { return right_; } | 1980 Expression* right() const { return right_; } |
1978 Handle<AllocationSite> allocation_site() const { return allocation_site_; } | 1981 Handle<AllocationSite> allocation_site() const { return allocation_site_; } |
1979 void set_allocation_site(Handle<AllocationSite> allocation_site) { | 1982 void set_allocation_site(Handle<AllocationSite> allocation_site) { |
1980 allocation_site_ = allocation_site; | 1983 allocation_site_ = allocation_site; |
1981 } | 1984 } |
1982 | 1985 |
1983 BailoutId RightId() const { return right_id_; } | 1986 BailoutId RightId() const { return right_id_; } |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3362 | 3365 |
3363 private: | 3366 private: |
3364 Zone* zone_; | 3367 Zone* zone_; |
3365 Visitor visitor_; | 3368 Visitor visitor_; |
3366 }; | 3369 }; |
3367 | 3370 |
3368 | 3371 |
3369 } } // namespace v8::internal | 3372 } } // namespace v8::internal |
3370 | 3373 |
3371 #endif // V8_AST_H_ | 3374 #endif // V8_AST_H_ |
OLD | NEW |