| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 virtual type* As##type() { return NULL; } | 158 virtual type* As##type() { return NULL; } |
| 159 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 159 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 160 #undef DECLARE_NODE_FUNCTIONS | 160 #undef DECLARE_NODE_FUNCTIONS |
| 161 | 161 |
| 162 virtual Statement* AsStatement() { return NULL; } | 162 virtual Statement* AsStatement() { return NULL; } |
| 163 virtual Expression* AsExpression() { return NULL; } | 163 virtual Expression* AsExpression() { return NULL; } |
| 164 virtual TargetCollector* AsTargetCollector() { return NULL; } | 164 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 165 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 165 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 166 virtual IterationStatement* AsIterationStatement() { return NULL; } | 166 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 167 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 167 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 168 virtual Slot* AsSlot() { return NULL; } | |
| 169 | 168 |
| 170 // True if the node is simple enough for us to inline calls containing it. | 169 // True if the node is simple enough for us to inline calls containing it. |
| 171 virtual bool IsInlineable() const = 0; | 170 virtual bool IsInlineable() const = 0; |
| 172 | 171 |
| 173 static int Count() { return Isolate::Current()->ast_node_count(); } | 172 static int Count() { return Isolate::Current()->ast_node_count(); } |
| 174 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } | 173 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
| 175 | 174 |
| 176 protected: | 175 protected: |
| 177 static unsigned GetNextId(Isolate* isolate) { | 176 static unsigned GetNextId(Isolate* isolate) { |
| 178 return ReserveIdRange(isolate, 1); | 177 return ReserveIdRange(isolate, 1); |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 int first_element_id_; | 1118 int first_element_id_; |
| 1120 }; | 1119 }; |
| 1121 | 1120 |
| 1122 | 1121 |
| 1123 class VariableProxy: public Expression { | 1122 class VariableProxy: public Expression { |
| 1124 public: | 1123 public: |
| 1125 VariableProxy(Isolate* isolate, Variable* var); | 1124 VariableProxy(Isolate* isolate, Variable* var); |
| 1126 | 1125 |
| 1127 DECLARE_NODE_TYPE(VariableProxy) | 1126 DECLARE_NODE_TYPE(VariableProxy) |
| 1128 | 1127 |
| 1129 // Type testing & conversion | |
| 1130 Variable* AsVariable() { return (this == NULL) ? NULL : var_; } | |
| 1131 | |
| 1132 virtual bool IsValidLeftHandSide() { | 1128 virtual bool IsValidLeftHandSide() { |
| 1133 return var_ == NULL ? true : var_->IsValidLeftHandSide(); | 1129 return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
| 1134 } | 1130 } |
| 1135 | 1131 |
| 1136 virtual bool IsTrivial() { | 1132 virtual bool IsTrivial() { |
| 1137 // Reading from a mutable variable is a side effect, but the | 1133 // Reading from a mutable variable is a side effect, but the |
| 1138 // variable for 'this' is immutable. | 1134 // variable for 'this' is immutable. |
| 1139 return is_this_ || is_trivial_; | 1135 return is_this_ || is_trivial_; |
| 1140 } | 1136 } |
| 1141 | 1137 |
| 1142 virtual bool IsInlineable() const; | 1138 virtual bool IsInlineable() const; |
| 1143 | 1139 |
| 1144 bool IsVariable(Handle<String> n) { | 1140 bool IsVariable(Handle<String> n) { |
| 1145 return !is_this() && name().is_identical_to(n); | 1141 return !is_this() && name().is_identical_to(n); |
| 1146 } | 1142 } |
| 1147 | 1143 |
| 1148 bool IsArguments() { | 1144 bool IsArguments() { return var_ != NULL && var_->is_arguments(); } |
| 1149 Variable* variable = AsVariable(); | |
| 1150 return (variable == NULL) ? false : variable->is_arguments(); | |
| 1151 } | |
| 1152 | 1145 |
| 1153 Handle<String> name() const { return name_; } | 1146 Handle<String> name() const { return name_; } |
| 1154 Variable* var() const { return var_; } | 1147 Variable* var() const { return var_; } |
| 1155 bool is_this() const { return is_this_; } | 1148 bool is_this() const { return is_this_; } |
| 1156 bool inside_with() const { return inside_with_; } | 1149 bool inside_with() const { return inside_with_; } |
| 1157 int position() const { return position_; } | 1150 int position() const { return position_; } |
| 1158 | 1151 |
| 1159 void MarkAsTrivial() { is_trivial_ = true; } | 1152 void MarkAsTrivial() { is_trivial_ = true; } |
| 1160 | 1153 |
| 1161 // Bind this proxy to the variable var. | 1154 // Bind this proxy to the variable var. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1185 virtual bool IsValidLeftHandSide() { return !is_this(); } | 1178 virtual bool IsValidLeftHandSide() { return !is_this(); } |
| 1186 | 1179 |
| 1187 private: | 1180 private: |
| 1188 VariableProxySentinel(Isolate* isolate, bool is_this) | 1181 VariableProxySentinel(Isolate* isolate, bool is_this) |
| 1189 : VariableProxy(isolate, is_this) { } | 1182 : VariableProxy(isolate, is_this) { } |
| 1190 | 1183 |
| 1191 friend class AstSentinels; | 1184 friend class AstSentinels; |
| 1192 }; | 1185 }; |
| 1193 | 1186 |
| 1194 | 1187 |
| 1195 class Slot: public Expression { | |
| 1196 public: | |
| 1197 enum Type { | |
| 1198 // A slot in the parameter section on the stack. index() is | |
| 1199 // the parameter index, counting left-to-right, starting at 0. | |
| 1200 PARAMETER, | |
| 1201 | |
| 1202 // A slot in the local section on the stack. index() is | |
| 1203 // the variable index in the stack frame, starting at 0. | |
| 1204 LOCAL, | |
| 1205 | |
| 1206 // An indexed slot in a heap context. index() is the | |
| 1207 // variable index in the context object on the heap, | |
| 1208 // starting at 0. var()->scope() is the corresponding | |
| 1209 // scope. | |
| 1210 CONTEXT, | |
| 1211 | |
| 1212 // A named slot in a heap context. var()->name() is the | |
| 1213 // variable name in the context object on the heap, | |
| 1214 // with lookup starting at the current context. index() | |
| 1215 // is invalid. | |
| 1216 LOOKUP | |
| 1217 }; | |
| 1218 | |
| 1219 Slot(Isolate* isolate, Variable* var, Type type, int index) | |
| 1220 : Expression(isolate), var_(var), type_(type), index_(index) { | |
| 1221 ASSERT(var != NULL); | |
| 1222 } | |
| 1223 | |
| 1224 virtual void Accept(AstVisitor* v); | |
| 1225 | |
| 1226 virtual Slot* AsSlot() { return this; } | |
| 1227 | |
| 1228 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } | |
| 1229 | |
| 1230 // Accessors | |
| 1231 Variable* var() const { return var_; } | |
| 1232 Type type() const { return type_; } | |
| 1233 int index() const { return index_; } | |
| 1234 bool is_arguments() const { return var_->is_arguments(); } | |
| 1235 virtual bool IsInlineable() const; | |
| 1236 | |
| 1237 private: | |
| 1238 Variable* var_; | |
| 1239 Type type_; | |
| 1240 int index_; | |
| 1241 }; | |
| 1242 | |
| 1243 | |
| 1244 class Property: public Expression { | 1188 class Property: public Expression { |
| 1245 public: | 1189 public: |
| 1246 Property(Isolate* isolate, | 1190 Property(Isolate* isolate, |
| 1247 Expression* obj, | 1191 Expression* obj, |
| 1248 Expression* key, | 1192 Expression* key, |
| 1249 int pos) | 1193 int pos) |
| 1250 : Expression(isolate), | 1194 : Expression(isolate), |
| 1251 obj_(obj), | 1195 obj_(obj), |
| 1252 key_(key), | 1196 key_(key), |
| 1253 pos_(pos), | 1197 pos_(pos), |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2244 // Stack overflow tracking support. | 2188 // Stack overflow tracking support. |
| 2245 bool HasStackOverflow() const { return stack_overflow_; } | 2189 bool HasStackOverflow() const { return stack_overflow_; } |
| 2246 bool CheckStackOverflow(); | 2190 bool CheckStackOverflow(); |
| 2247 | 2191 |
| 2248 // If a stack-overflow exception is encountered when visiting a | 2192 // If a stack-overflow exception is encountered when visiting a |
| 2249 // node, calling SetStackOverflow will make sure that the visitor | 2193 // node, calling SetStackOverflow will make sure that the visitor |
| 2250 // bails out without visiting more nodes. | 2194 // bails out without visiting more nodes. |
| 2251 void SetStackOverflow() { stack_overflow_ = true; } | 2195 void SetStackOverflow() { stack_overflow_ = true; } |
| 2252 void ClearStackOverflow() { stack_overflow_ = false; } | 2196 void ClearStackOverflow() { stack_overflow_ = false; } |
| 2253 | 2197 |
| 2254 // Nodes not appearing in the AST, including slots. | |
| 2255 virtual void VisitSlot(Slot* node) { UNREACHABLE(); } | |
| 2256 | |
| 2257 // Individual AST nodes. | 2198 // Individual AST nodes. |
| 2258 #define DEF_VISIT(type) \ | 2199 #define DEF_VISIT(type) \ |
| 2259 virtual void Visit##type(type* node) = 0; | 2200 virtual void Visit##type(type* node) = 0; |
| 2260 AST_NODE_LIST(DEF_VISIT) | 2201 AST_NODE_LIST(DEF_VISIT) |
| 2261 #undef DEF_VISIT | 2202 #undef DEF_VISIT |
| 2262 | 2203 |
| 2263 protected: | 2204 protected: |
| 2264 Isolate* isolate() { return isolate_; } | 2205 Isolate* isolate() { return isolate_; } |
| 2265 | 2206 |
| 2266 private: | 2207 private: |
| 2267 Isolate* isolate_; | 2208 Isolate* isolate_; |
| 2268 bool stack_overflow_; | 2209 bool stack_overflow_; |
| 2269 }; | 2210 }; |
| 2270 | 2211 |
| 2271 | 2212 |
| 2272 } } // namespace v8::internal | 2213 } } // namespace v8::internal |
| 2273 | 2214 |
| 2274 #endif // V8_AST_H_ | 2215 #endif // V8_AST_H_ |
| OLD | NEW |