| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 V(ThisFunction) | 95 V(ThisFunction) |
| 96 | 96 |
| 97 #define AST_NODE_LIST(V) \ | 97 #define AST_NODE_LIST(V) \ |
| 98 V(Declaration) \ | 98 V(Declaration) \ |
| 99 STATEMENT_NODE_LIST(V) \ | 99 STATEMENT_NODE_LIST(V) \ |
| 100 EXPRESSION_NODE_LIST(V) | 100 EXPRESSION_NODE_LIST(V) |
| 101 | 101 |
| 102 // Forward declarations | 102 // Forward declarations |
| 103 class TargetCollector; | 103 class TargetCollector; |
| 104 class MaterializedLiteral; | 104 class MaterializedLiteral; |
| 105 class DefinitionInfo; |
| 105 | 106 |
| 106 #define DEF_FORWARD_DECLARATION(type) class type; | 107 #define DEF_FORWARD_DECLARATION(type) class type; |
| 107 AST_NODE_LIST(DEF_FORWARD_DECLARATION) | 108 AST_NODE_LIST(DEF_FORWARD_DECLARATION) |
| 108 #undef DEF_FORWARD_DECLARATION | 109 #undef DEF_FORWARD_DECLARATION |
| 109 | 110 |
| 110 | 111 |
| 111 // Typedef only introduced to avoid unreadable code. | 112 // Typedef only introduced to avoid unreadable code. |
| 112 // Please do appreciate the required space in "> >". | 113 // Please do appreciate the required space in "> >". |
| 113 typedef ZoneList<Handle<String> > ZoneStringList; | 114 typedef ZoneList<Handle<String> > ZoneStringList; |
| 114 typedef ZoneList<Handle<Object> > ZoneObjectList; | 115 typedef ZoneList<Handle<Object> > ZoneObjectList; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Evaluated for control flow and side effects. Value is also | 176 // Evaluated for control flow and side effects. Value is also |
| 176 // needed if true. | 177 // needed if true. |
| 177 kValueTest, | 178 kValueTest, |
| 178 // Evaluated for control flow and side effects. Value is also | 179 // Evaluated for control flow and side effects. Value is also |
| 179 // needed if false. | 180 // needed if false. |
| 180 kTestValue | 181 kTestValue |
| 181 }; | 182 }; |
| 182 | 183 |
| 183 static const int kNoLabel = -1; | 184 static const int kNoLabel = -1; |
| 184 | 185 |
| 185 Expression() : num_(kNoLabel) {} | 186 Expression() : num_(kNoLabel), def_(NULL), defined_vars_(NULL) {} |
| 186 | 187 |
| 187 virtual Expression* AsExpression() { return this; } | 188 virtual Expression* AsExpression() { return this; } |
| 188 | 189 |
| 189 virtual bool IsValidLeftHandSide() { return false; } | 190 virtual bool IsValidLeftHandSide() { return false; } |
| 190 | 191 |
| 191 // Symbols that cannot be parsed as array indices are considered property | 192 // Symbols that cannot be parsed as array indices are considered property |
| 192 // names. We do not treat symbols that can be array indexes as property | 193 // names. We do not treat symbols that can be array indexes as property |
| 193 // names because [] for string objects is handled only by keyed ICs. | 194 // names because [] for string objects is handled only by keyed ICs. |
| 194 virtual bool IsPropertyName() { return false; } | 195 virtual bool IsPropertyName() { return false; } |
| 195 | 196 |
| 197 // True if the expression does not have (evaluated) subexpressions. |
| 198 // Function literals are leaves because their subexpressions are not |
| 199 // evaluated. |
| 200 virtual bool IsLeaf() { return false; } |
| 201 |
| 202 // True if the expression has no side effects and is safe to |
| 203 // evaluate out of order. |
| 204 virtual bool IsTrivial() { return false; } |
| 205 |
| 196 // Mark the expression as being compiled as an expression | 206 // Mark the expression as being compiled as an expression |
| 197 // statement. This is used to transform postfix increments to | 207 // statement. This is used to transform postfix increments to |
| 198 // (faster) prefix increments. | 208 // (faster) prefix increments. |
| 199 virtual void MarkAsStatement() { /* do nothing */ } | 209 virtual void MarkAsStatement() { /* do nothing */ } |
| 200 | 210 |
| 201 // Static type information for this expression. | 211 // Static type information for this expression. |
| 202 StaticType* type() { return &type_; } | 212 StaticType* type() { return &type_; } |
| 203 | 213 |
| 204 int num() { return num_; } | 214 int num() { return num_; } |
| 205 | 215 |
| 206 // AST node numbering ordered by evaluation order. | 216 // AST node numbering ordered by evaluation order. |
| 207 void set_num(int n) { num_ = n; } | 217 void set_num(int n) { num_ = n; } |
| 208 | 218 |
| 219 // Data flow information. |
| 220 DefinitionInfo* var_def() { return def_; } |
| 221 void set_var_def(DefinitionInfo* def) { def_ = def; } |
| 222 |
| 223 ZoneList<DefinitionInfo*>* defined_vars() { return defined_vars_; } |
| 224 void set_defined_vars(ZoneList<DefinitionInfo*>* defined_vars) { |
| 225 defined_vars_ = defined_vars; |
| 226 } |
| 227 |
| 209 private: | 228 private: |
| 210 StaticType type_; | 229 StaticType type_; |
| 211 int num_; | 230 int num_; |
| 231 DefinitionInfo* def_; |
| 232 ZoneList<DefinitionInfo*>* defined_vars_; |
| 212 }; | 233 }; |
| 213 | 234 |
| 214 | 235 |
| 215 /** | 236 /** |
| 216 * A sentinel used during pre parsing that represents some expression | 237 * A sentinel used during pre parsing that represents some expression |
| 217 * that is a valid left hand side without having to actually build | 238 * that is a valid left hand side without having to actually build |
| 218 * the expression. | 239 * the expression. |
| 219 */ | 240 */ |
| 220 class ValidLeftHandSideSentinel: public Expression { | 241 class ValidLeftHandSideSentinel: public Expression { |
| 221 public: | 242 public: |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 } | 734 } |
| 714 | 735 |
| 715 virtual bool IsPropertyName() { | 736 virtual bool IsPropertyName() { |
| 716 if (handle_->IsSymbol()) { | 737 if (handle_->IsSymbol()) { |
| 717 uint32_t ignored; | 738 uint32_t ignored; |
| 718 return !String::cast(*handle_)->AsArrayIndex(&ignored); | 739 return !String::cast(*handle_)->AsArrayIndex(&ignored); |
| 719 } | 740 } |
| 720 return false; | 741 return false; |
| 721 } | 742 } |
| 722 | 743 |
| 744 virtual bool IsLeaf() { return true; } |
| 745 virtual bool IsTrivial() { return true; } |
| 746 |
| 723 // Identity testers. | 747 // Identity testers. |
| 724 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } | 748 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } |
| 725 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } | 749 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } |
| 726 bool IsFalse() const { | 750 bool IsFalse() const { |
| 727 return handle_.is_identical_to(Factory::false_value()); | 751 return handle_.is_identical_to(Factory::false_value()); |
| 728 } | 752 } |
| 729 | 753 |
| 730 Handle<Object> handle() const { return handle_; } | 754 Handle<Object> handle() const { return handle_; } |
| 731 | 755 |
| 732 private: | 756 private: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 int literal_index, | 819 int literal_index, |
| 796 bool is_simple, | 820 bool is_simple, |
| 797 int depth) | 821 int depth) |
| 798 : MaterializedLiteral(literal_index, is_simple, depth), | 822 : MaterializedLiteral(literal_index, is_simple, depth), |
| 799 constant_properties_(constant_properties), | 823 constant_properties_(constant_properties), |
| 800 properties_(properties) {} | 824 properties_(properties) {} |
| 801 | 825 |
| 802 virtual ObjectLiteral* AsObjectLiteral() { return this; } | 826 virtual ObjectLiteral* AsObjectLiteral() { return this; } |
| 803 virtual void Accept(AstVisitor* v); | 827 virtual void Accept(AstVisitor* v); |
| 804 | 828 |
| 829 virtual bool IsLeaf() { return properties()->is_empty(); } |
| 830 |
| 805 Handle<FixedArray> constant_properties() const { | 831 Handle<FixedArray> constant_properties() const { |
| 806 return constant_properties_; | 832 return constant_properties_; |
| 807 } | 833 } |
| 808 ZoneList<Property*>* properties() const { return properties_; } | 834 ZoneList<Property*>* properties() const { return properties_; } |
| 809 | 835 |
| 810 private: | 836 private: |
| 811 Handle<FixedArray> constant_properties_; | 837 Handle<FixedArray> constant_properties_; |
| 812 ZoneList<Property*>* properties_; | 838 ZoneList<Property*>* properties_; |
| 813 }; | 839 }; |
| 814 | 840 |
| 815 | 841 |
| 816 // Node for capturing a regexp literal. | 842 // Node for capturing a regexp literal. |
| 817 class RegExpLiteral: public MaterializedLiteral { | 843 class RegExpLiteral: public MaterializedLiteral { |
| 818 public: | 844 public: |
| 819 RegExpLiteral(Handle<String> pattern, | 845 RegExpLiteral(Handle<String> pattern, |
| 820 Handle<String> flags, | 846 Handle<String> flags, |
| 821 int literal_index) | 847 int literal_index) |
| 822 : MaterializedLiteral(literal_index, false, 1), | 848 : MaterializedLiteral(literal_index, false, 1), |
| 823 pattern_(pattern), | 849 pattern_(pattern), |
| 824 flags_(flags) {} | 850 flags_(flags) {} |
| 825 | 851 |
| 826 virtual void Accept(AstVisitor* v); | 852 virtual void Accept(AstVisitor* v); |
| 827 | 853 |
| 854 virtual bool IsLeaf() { return true; } |
| 855 |
| 828 Handle<String> pattern() const { return pattern_; } | 856 Handle<String> pattern() const { return pattern_; } |
| 829 Handle<String> flags() const { return flags_; } | 857 Handle<String> flags() const { return flags_; } |
| 830 | 858 |
| 831 private: | 859 private: |
| 832 Handle<String> pattern_; | 860 Handle<String> pattern_; |
| 833 Handle<String> flags_; | 861 Handle<String> flags_; |
| 834 }; | 862 }; |
| 835 | 863 |
| 836 // An array literal has a literals object that is used | 864 // An array literal has a literals object that is used |
| 837 // for minimizing the work when constructing it at runtime. | 865 // for minimizing the work when constructing it at runtime. |
| 838 class ArrayLiteral: public MaterializedLiteral { | 866 class ArrayLiteral: public MaterializedLiteral { |
| 839 public: | 867 public: |
| 840 ArrayLiteral(Handle<FixedArray> constant_elements, | 868 ArrayLiteral(Handle<FixedArray> constant_elements, |
| 841 ZoneList<Expression*>* values, | 869 ZoneList<Expression*>* values, |
| 842 int literal_index, | 870 int literal_index, |
| 843 bool is_simple, | 871 bool is_simple, |
| 844 int depth) | 872 int depth) |
| 845 : MaterializedLiteral(literal_index, is_simple, depth), | 873 : MaterializedLiteral(literal_index, is_simple, depth), |
| 846 constant_elements_(constant_elements), | 874 constant_elements_(constant_elements), |
| 847 values_(values) {} | 875 values_(values) {} |
| 848 | 876 |
| 849 virtual void Accept(AstVisitor* v); | 877 virtual void Accept(AstVisitor* v); |
| 850 virtual ArrayLiteral* AsArrayLiteral() { return this; } | 878 virtual ArrayLiteral* AsArrayLiteral() { return this; } |
| 851 | 879 |
| 880 virtual bool IsLeaf() { return values()->is_empty(); } |
| 881 |
| 852 Handle<FixedArray> constant_elements() const { return constant_elements_; } | 882 Handle<FixedArray> constant_elements() const { return constant_elements_; } |
| 853 ZoneList<Expression*>* values() const { return values_; } | 883 ZoneList<Expression*>* values() const { return values_; } |
| 854 | 884 |
| 855 private: | 885 private: |
| 856 Handle<FixedArray> constant_elements_; | 886 Handle<FixedArray> constant_elements_; |
| 857 ZoneList<Expression*>* values_; | 887 ZoneList<Expression*>* values_; |
| 858 }; | 888 }; |
| 859 | 889 |
| 860 | 890 |
| 861 // Node for constructing a context extension object for a catch block. | 891 // Node for constructing a context extension object for a catch block. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 889 virtual VariableProxy* AsVariableProxy() { return this; } | 919 virtual VariableProxy* AsVariableProxy() { return this; } |
| 890 | 920 |
| 891 Variable* AsVariable() { | 921 Variable* AsVariable() { |
| 892 return this == NULL || var_ == NULL ? NULL : var_->AsVariable(); | 922 return this == NULL || var_ == NULL ? NULL : var_->AsVariable(); |
| 893 } | 923 } |
| 894 | 924 |
| 895 virtual bool IsValidLeftHandSide() { | 925 virtual bool IsValidLeftHandSide() { |
| 896 return var_ == NULL ? true : var_->IsValidLeftHandSide(); | 926 return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
| 897 } | 927 } |
| 898 | 928 |
| 929 virtual bool IsLeaf() { |
| 930 ASSERT(var_ != NULL); // Variable must be resolved. |
| 931 return var()->is_global() || var()->rewrite()->IsLeaf(); |
| 932 } |
| 933 |
| 934 // Reading from a mutable variable is a side effect, but 'this' is |
| 935 // immutable. |
| 936 virtual bool IsTrivial() { return is_this(); } |
| 937 |
| 899 bool IsVariable(Handle<String> n) { | 938 bool IsVariable(Handle<String> n) { |
| 900 return !is_this() && name().is_identical_to(n); | 939 return !is_this() && name().is_identical_to(n); |
| 901 } | 940 } |
| 902 | 941 |
| 903 bool IsArguments() { | 942 bool IsArguments() { |
| 904 Variable* variable = AsVariable(); | 943 Variable* variable = AsVariable(); |
| 905 return (variable == NULL) ? false : variable->is_arguments(); | 944 return (variable == NULL) ? false : variable->is_arguments(); |
| 906 } | 945 } |
| 907 | 946 |
| 908 Handle<String> name() const { return name_; } | 947 Handle<String> name() const { return name_; } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 Slot(Variable* var, Type type, int index) | 1013 Slot(Variable* var, Type type, int index) |
| 975 : var_(var), type_(type), index_(index) { | 1014 : var_(var), type_(type), index_(index) { |
| 976 ASSERT(var != NULL); | 1015 ASSERT(var != NULL); |
| 977 } | 1016 } |
| 978 | 1017 |
| 979 virtual void Accept(AstVisitor* v); | 1018 virtual void Accept(AstVisitor* v); |
| 980 | 1019 |
| 981 // Type testing & conversion | 1020 // Type testing & conversion |
| 982 virtual Slot* AsSlot() { return this; } | 1021 virtual Slot* AsSlot() { return this; } |
| 983 | 1022 |
| 1023 virtual bool IsLeaf() { return true; } |
| 1024 |
| 984 // Accessors | 1025 // Accessors |
| 985 Variable* var() const { return var_; } | 1026 Variable* var() const { return var_; } |
| 986 Type type() const { return type_; } | 1027 Type type() const { return type_; } |
| 987 int index() const { return index_; } | 1028 int index() const { return index_; } |
| 988 bool is_arguments() const { return var_->is_arguments(); } | 1029 bool is_arguments() const { return var_->is_arguments(); } |
| 989 | 1030 |
| 990 private: | 1031 private: |
| 991 Variable* var_; | 1032 Variable* var_; |
| 992 Type type_; | 1033 Type type_; |
| 993 int index_; | 1034 int index_; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 #ifdef DEBUG | 1371 #ifdef DEBUG |
| 1331 already_compiled_ = false; | 1372 already_compiled_ = false; |
| 1332 #endif | 1373 #endif |
| 1333 } | 1374 } |
| 1334 | 1375 |
| 1335 virtual void Accept(AstVisitor* v); | 1376 virtual void Accept(AstVisitor* v); |
| 1336 | 1377 |
| 1337 // Type testing & conversion | 1378 // Type testing & conversion |
| 1338 virtual FunctionLiteral* AsFunctionLiteral() { return this; } | 1379 virtual FunctionLiteral* AsFunctionLiteral() { return this; } |
| 1339 | 1380 |
| 1381 virtual bool IsLeaf() { return true; } |
| 1382 |
| 1340 Handle<String> name() const { return name_; } | 1383 Handle<String> name() const { return name_; } |
| 1341 Scope* scope() const { return scope_; } | 1384 Scope* scope() const { return scope_; } |
| 1342 ZoneList<Statement*>* body() const { return body_; } | 1385 ZoneList<Statement*>* body() const { return body_; } |
| 1343 void set_function_token_position(int pos) { function_token_position_ = pos; } | 1386 void set_function_token_position(int pos) { function_token_position_ = pos; } |
| 1344 int function_token_position() const { return function_token_position_; } | 1387 int function_token_position() const { return function_token_position_; } |
| 1345 int start_position() const { return start_position_; } | 1388 int start_position() const { return start_position_; } |
| 1346 int end_position() const { return end_position_; } | 1389 int end_position() const { return end_position_; } |
| 1347 bool is_expression() const { return is_expression_; } | 1390 bool is_expression() const { return is_expression_; } |
| 1348 | 1391 |
| 1349 int materialized_literal_count() { return materialized_literal_count_; } | 1392 int materialized_literal_count() { return materialized_literal_count_; } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 | 1439 |
| 1397 class FunctionBoilerplateLiteral: public Expression { | 1440 class FunctionBoilerplateLiteral: public Expression { |
| 1398 public: | 1441 public: |
| 1399 explicit FunctionBoilerplateLiteral(Handle<JSFunction> boilerplate) | 1442 explicit FunctionBoilerplateLiteral(Handle<JSFunction> boilerplate) |
| 1400 : boilerplate_(boilerplate) { | 1443 : boilerplate_(boilerplate) { |
| 1401 ASSERT(boilerplate->IsBoilerplate()); | 1444 ASSERT(boilerplate->IsBoilerplate()); |
| 1402 } | 1445 } |
| 1403 | 1446 |
| 1404 Handle<JSFunction> boilerplate() const { return boilerplate_; } | 1447 Handle<JSFunction> boilerplate() const { return boilerplate_; } |
| 1405 | 1448 |
| 1449 virtual bool IsLeaf() { return true; } |
| 1450 |
| 1406 virtual void Accept(AstVisitor* v); | 1451 virtual void Accept(AstVisitor* v); |
| 1407 | 1452 |
| 1408 private: | 1453 private: |
| 1409 Handle<JSFunction> boilerplate_; | 1454 Handle<JSFunction> boilerplate_; |
| 1410 }; | 1455 }; |
| 1411 | 1456 |
| 1412 | 1457 |
| 1413 class ThisFunction: public Expression { | 1458 class ThisFunction: public Expression { |
| 1414 public: | 1459 public: |
| 1415 virtual void Accept(AstVisitor* v); | 1460 virtual void Accept(AstVisitor* v); |
| 1461 virtual bool IsLeaf() { return true; } |
| 1416 }; | 1462 }; |
| 1417 | 1463 |
| 1418 | 1464 |
| 1419 // ---------------------------------------------------------------------------- | 1465 // ---------------------------------------------------------------------------- |
| 1420 // Regular expressions | 1466 // Regular expressions |
| 1421 | 1467 |
| 1422 | 1468 |
| 1423 class RegExpVisitor BASE_EMBEDDED { | 1469 class RegExpVisitor BASE_EMBEDDED { |
| 1424 public: | 1470 public: |
| 1425 virtual ~RegExpVisitor() { } | 1471 virtual ~RegExpVisitor() { } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 #undef DEF_VISIT | 1849 #undef DEF_VISIT |
| 1804 | 1850 |
| 1805 private: | 1851 private: |
| 1806 bool stack_overflow_; | 1852 bool stack_overflow_; |
| 1807 }; | 1853 }; |
| 1808 | 1854 |
| 1809 | 1855 |
| 1810 } } // namespace v8::internal | 1856 } } // namespace v8::internal |
| 1811 | 1857 |
| 1812 #endif // V8_AST_H_ | 1858 #endif // V8_AST_H_ |
| OLD | NEW |