| OLD | NEW |
| 1 // Copyright 2010 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 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 | 111 |
| 112 // Typedef only introduced to avoid unreadable code. | 112 // Typedef only introduced to avoid unreadable code. |
| 113 // Please do appreciate the required space in "> >". | 113 // Please do appreciate the required space in "> >". |
| 114 typedef ZoneList<Handle<String> > ZoneStringList; | 114 typedef ZoneList<Handle<String> > ZoneStringList; |
| 115 typedef ZoneList<Handle<Object> > ZoneObjectList; | 115 typedef ZoneList<Handle<Object> > ZoneObjectList; |
| 116 | 116 |
| 117 | 117 |
| 118 class AstNode: public ZoneObject { | 118 class AstNode: public ZoneObject { |
| 119 public: | 119 public: |
| 120 static const int kNoNumber = -1; |
| 121 |
| 122 AstNode() : num_(kNoNumber) {} |
| 120 virtual ~AstNode() { } | 123 virtual ~AstNode() { } |
| 121 virtual void Accept(AstVisitor* v) = 0; | 124 virtual void Accept(AstVisitor* v) = 0; |
| 122 | 125 |
| 123 // Type testing & conversion. | 126 // Type testing & conversion. |
| 124 virtual Statement* AsStatement() { return NULL; } | 127 virtual Statement* AsStatement() { return NULL; } |
| 125 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } | 128 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } |
| 126 virtual EmptyStatement* AsEmptyStatement() { return NULL; } | 129 virtual EmptyStatement* AsEmptyStatement() { return NULL; } |
| 127 virtual Expression* AsExpression() { return NULL; } | 130 virtual Expression* AsExpression() { return NULL; } |
| 128 virtual Literal* AsLiteral() { return NULL; } | 131 virtual Literal* AsLiteral() { return NULL; } |
| 129 virtual Slot* AsSlot() { return NULL; } | 132 virtual Slot* AsSlot() { return NULL; } |
| 130 virtual VariableProxy* AsVariableProxy() { return NULL; } | 133 virtual VariableProxy* AsVariableProxy() { return NULL; } |
| 131 virtual Property* AsProperty() { return NULL; } | 134 virtual Property* AsProperty() { return NULL; } |
| 132 virtual Call* AsCall() { return NULL; } | 135 virtual Call* AsCall() { return NULL; } |
| 133 virtual TargetCollector* AsTargetCollector() { return NULL; } | 136 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 134 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 137 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 135 virtual IterationStatement* AsIterationStatement() { return NULL; } | 138 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 136 virtual UnaryOperation* AsUnaryOperation() { return NULL; } | 139 virtual UnaryOperation* AsUnaryOperation() { return NULL; } |
| 137 virtual BinaryOperation* AsBinaryOperation() { return NULL; } | 140 virtual BinaryOperation* AsBinaryOperation() { return NULL; } |
| 138 virtual Assignment* AsAssignment() { return NULL; } | 141 virtual Assignment* AsAssignment() { return NULL; } |
| 139 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } | 142 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } |
| 140 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 143 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 141 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } | 144 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } |
| 142 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } | 145 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } |
| 143 virtual CompareOperation* AsCompareOperation() { return NULL; } | 146 virtual CompareOperation* AsCompareOperation() { return NULL; } |
| 147 |
| 148 int num() { return num_; } |
| 149 void set_num(int n) { num_ = n; } |
| 150 |
| 151 private: |
| 152 // Support for ast node numbering. |
| 153 int num_; |
| 144 }; | 154 }; |
| 145 | 155 |
| 146 | 156 |
| 147 class Statement: public AstNode { | 157 class Statement: public AstNode { |
| 148 public: | 158 public: |
| 149 Statement() : statement_pos_(RelocInfo::kNoPosition) {} | 159 Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
| 150 | 160 |
| 151 virtual Statement* AsStatement() { return this; } | 161 virtual Statement* AsStatement() { return this; } |
| 152 virtual ReturnStatement* AsReturnStatement() { return NULL; } | 162 virtual ReturnStatement* AsReturnStatement() { return NULL; } |
| 153 | 163 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 174 // Evaluated for control flow (and side effects). | 184 // Evaluated for control flow (and side effects). |
| 175 kTest, | 185 kTest, |
| 176 // Evaluated for control flow and side effects. Value is also | 186 // Evaluated for control flow and side effects. Value is also |
| 177 // needed if true. | 187 // needed if true. |
| 178 kValueTest, | 188 kValueTest, |
| 179 // Evaluated for control flow and side effects. Value is also | 189 // Evaluated for control flow and side effects. Value is also |
| 180 // needed if false. | 190 // needed if false. |
| 181 kTestValue | 191 kTestValue |
| 182 }; | 192 }; |
| 183 | 193 |
| 184 static const int kNoLabel = -1; | 194 Expression() |
| 185 | 195 : bitfields_(0), |
| 186 Expression() : num_(kNoLabel), def_(NULL), defined_vars_(NULL) {} | 196 def_(NULL), |
| 197 defined_vars_(NULL) {} |
| 187 | 198 |
| 188 virtual Expression* AsExpression() { return this; } | 199 virtual Expression* AsExpression() { return this; } |
| 189 | 200 |
| 190 virtual bool IsValidLeftHandSide() { return false; } | 201 virtual bool IsValidLeftHandSide() { return false; } |
| 191 | 202 |
| 192 // Symbols that cannot be parsed as array indices are considered property | 203 // Symbols that cannot be parsed as array indices are considered property |
| 193 // names. We do not treat symbols that can be array indexes as property | 204 // names. We do not treat symbols that can be array indexes as property |
| 194 // names because [] for string objects is handled only by keyed ICs. | 205 // names because [] for string objects is handled only by keyed ICs. |
| 195 virtual bool IsPropertyName() { return false; } | 206 virtual bool IsPropertyName() { return false; } |
| 196 | 207 |
| 197 // True if the expression does not have (evaluated) subexpressions. | 208 // True if the expression does not have (evaluated) subexpressions. |
| 198 // Function literals are leaves because their subexpressions are not | 209 // Function literals are leaves because their subexpressions are not |
| 199 // evaluated. | 210 // evaluated. |
| 200 virtual bool IsLeaf() { return false; } | 211 virtual bool IsLeaf() { return false; } |
| 201 | 212 |
| 202 // True if the expression has no side effects and is safe to | 213 // True if the expression has no side effects and is safe to |
| 203 // evaluate out of order. | 214 // evaluate out of order. |
| 204 virtual bool IsTrivial() { return false; } | 215 virtual bool IsTrivial() { return false; } |
| 205 | 216 |
| 206 // Mark the expression as being compiled as an expression | 217 // Mark the expression as being compiled as an expression |
| 207 // statement. This is used to transform postfix increments to | 218 // statement. This is used to transform postfix increments to |
| 208 // (faster) prefix increments. | 219 // (faster) prefix increments. |
| 209 virtual void MarkAsStatement() { /* do nothing */ } | 220 virtual void MarkAsStatement() { /* do nothing */ } |
| 210 | 221 |
| 211 // Static type information for this expression. | 222 // Static type information for this expression. |
| 212 StaticType* type() { return &type_; } | 223 StaticType* type() { return &type_; } |
| 213 | 224 |
| 214 int num() { return num_; } | |
| 215 | |
| 216 // AST node numbering ordered by evaluation order. | |
| 217 void set_num(int n) { num_ = n; } | |
| 218 | |
| 219 // Data flow information. | 225 // Data flow information. |
| 220 DefinitionInfo* var_def() { return def_; } | 226 DefinitionInfo* var_def() { return def_; } |
| 221 void set_var_def(DefinitionInfo* def) { def_ = def; } | 227 void set_var_def(DefinitionInfo* def) { def_ = def; } |
| 222 | 228 |
| 223 ZoneList<DefinitionInfo*>* defined_vars() { return defined_vars_; } | 229 ZoneList<DefinitionInfo*>* defined_vars() { return defined_vars_; } |
| 224 void set_defined_vars(ZoneList<DefinitionInfo*>* defined_vars) { | 230 void set_defined_vars(ZoneList<DefinitionInfo*>* defined_vars) { |
| 225 defined_vars_ = defined_vars; | 231 defined_vars_ = defined_vars; |
| 226 } | 232 } |
| 227 | 233 |
| 234 // AST analysis results |
| 235 |
| 236 // True if the expression rooted at this node can be compiled by the |
| 237 // side-effect free compiler. |
| 238 bool side_effect_free() { return SideEffectFreeField::decode(bitfields_); } |
| 239 void set_side_effect_free(bool is_side_effect_free) { |
| 240 bitfields_ &= ~SideEffectFreeField::mask(); |
| 241 bitfields_ |= SideEffectFreeField::encode(is_side_effect_free); |
| 242 } |
| 243 |
| 244 // Will ToInt32 (ECMA 262-3 9.5) or ToUint32 (ECMA 262-3 9.6) |
| 245 // be applied to the value of this expression? |
| 246 // If so, we may be able to optimize the calculation of the value. |
| 247 bool to_int32() { return ToInt32Field::decode(bitfields_); } |
| 248 void set_to_int32(bool to_int32) { |
| 249 bitfields_ &= ~ToInt32Field::mask(); |
| 250 bitfields_ |= ToInt32Field::encode(to_int32); |
| 251 } |
| 252 |
| 253 |
| 228 private: | 254 private: |
| 255 uint32_t bitfields_; |
| 229 StaticType type_; | 256 StaticType type_; |
| 230 int num_; | 257 |
| 231 DefinitionInfo* def_; | 258 DefinitionInfo* def_; |
| 232 ZoneList<DefinitionInfo*>* defined_vars_; | 259 ZoneList<DefinitionInfo*>* defined_vars_; |
| 260 |
| 261 // Using template BitField<type, start, size>. |
| 262 class SideEffectFreeField : public BitField<bool, 0, 1> {}; |
| 263 class ToInt32Field : public BitField<bool, 1, 1> {}; |
| 233 }; | 264 }; |
| 234 | 265 |
| 235 | 266 |
| 236 /** | 267 /** |
| 237 * A sentinel used during pre parsing that represents some expression | 268 * A sentinel used during pre parsing that represents some expression |
| 238 * that is a valid left hand side without having to actually build | 269 * that is a valid left hand side without having to actually build |
| 239 * the expression. | 270 * the expression. |
| 240 */ | 271 */ |
| 241 class ValidLeftHandSideSentinel: public Expression { | 272 class ValidLeftHandSideSentinel: public Expression { |
| 242 public: | 273 public: |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 return !is_this() && name().is_identical_to(n); | 970 return !is_this() && name().is_identical_to(n); |
| 940 } | 971 } |
| 941 | 972 |
| 942 bool IsArguments() { | 973 bool IsArguments() { |
| 943 Variable* variable = AsVariable(); | 974 Variable* variable = AsVariable(); |
| 944 return (variable == NULL) ? false : variable->is_arguments(); | 975 return (variable == NULL) ? false : variable->is_arguments(); |
| 945 } | 976 } |
| 946 | 977 |
| 947 Handle<String> name() const { return name_; } | 978 Handle<String> name() const { return name_; } |
| 948 Variable* var() const { return var_; } | 979 Variable* var() const { return var_; } |
| 949 UseCount* var_uses() { return &var_uses_; } | |
| 950 UseCount* obj_uses() { return &obj_uses_; } | |
| 951 bool is_this() const { return is_this_; } | 980 bool is_this() const { return is_this_; } |
| 952 bool inside_with() const { return inside_with_; } | 981 bool inside_with() const { return inside_with_; } |
| 953 | 982 |
| 954 // Bind this proxy to the variable var. | 983 // Bind this proxy to the variable var. |
| 955 void BindTo(Variable* var); | 984 void BindTo(Variable* var); |
| 956 | 985 |
| 957 protected: | 986 protected: |
| 958 Handle<String> name_; | 987 Handle<String> name_; |
| 959 Variable* var_; // resolved variable, or NULL | 988 Variable* var_; // resolved variable, or NULL |
| 960 bool is_this_; | 989 bool is_this_; |
| 961 bool inside_with_; | 990 bool inside_with_; |
| 962 | 991 |
| 963 // VariableProxy usage info. | |
| 964 UseCount var_uses_; // uses of the variable value | |
| 965 UseCount obj_uses_; // uses of the object the variable points to | |
| 966 | |
| 967 VariableProxy(Handle<String> name, bool is_this, bool inside_with); | 992 VariableProxy(Handle<String> name, bool is_this, bool inside_with); |
| 968 explicit VariableProxy(bool is_this); | 993 explicit VariableProxy(bool is_this); |
| 969 | 994 |
| 970 friend class Scope; | 995 friend class Scope; |
| 971 }; | 996 }; |
| 972 | 997 |
| 973 | 998 |
| 974 class VariableProxySentinel: public VariableProxy { | 999 class VariableProxySentinel: public VariableProxy { |
| 975 public: | 1000 public: |
| 976 virtual bool IsValidLeftHandSide() { return !is_this(); } | 1001 virtual bool IsValidLeftHandSide() { return !is_this(); } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 ASSERT(var != NULL); | 1040 ASSERT(var != NULL); |
| 1016 } | 1041 } |
| 1017 | 1042 |
| 1018 virtual void Accept(AstVisitor* v); | 1043 virtual void Accept(AstVisitor* v); |
| 1019 | 1044 |
| 1020 // Type testing & conversion | 1045 // Type testing & conversion |
| 1021 virtual Slot* AsSlot() { return this; } | 1046 virtual Slot* AsSlot() { return this; } |
| 1022 | 1047 |
| 1023 virtual bool IsLeaf() { return true; } | 1048 virtual bool IsLeaf() { return true; } |
| 1024 | 1049 |
| 1050 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } |
| 1051 |
| 1025 // Accessors | 1052 // Accessors |
| 1026 Variable* var() const { return var_; } | 1053 Variable* var() const { return var_; } |
| 1027 Type type() const { return type_; } | 1054 Type type() const { return type_; } |
| 1028 int index() const { return index_; } | 1055 int index() const { return index_; } |
| 1029 bool is_arguments() const { return var_->is_arguments(); } | 1056 bool is_arguments() const { return var_->is_arguments(); } |
| 1030 | 1057 |
| 1031 private: | 1058 private: |
| 1032 Variable* var_; | 1059 Variable* var_; |
| 1033 Type type_; | 1060 Type type_; |
| 1034 int index_; | 1061 int index_; |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 #undef DEF_VISIT | 1876 #undef DEF_VISIT |
| 1850 | 1877 |
| 1851 private: | 1878 private: |
| 1852 bool stack_overflow_; | 1879 bool stack_overflow_; |
| 1853 }; | 1880 }; |
| 1854 | 1881 |
| 1855 | 1882 |
| 1856 } } // namespace v8::internal | 1883 } } // namespace v8::internal |
| 1857 | 1884 |
| 1858 #endif // V8_AST_H_ | 1885 #endif // V8_AST_H_ |
| OLD | NEW |