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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 /** | 312 /** |
313 * A sentinel used during pre parsing that represents some expression | 313 * A sentinel used during pre parsing that represents some expression |
314 * that is a valid left hand side without having to actually build | 314 * that is a valid left hand side without having to actually build |
315 * the expression. | 315 * the expression. |
316 */ | 316 */ |
317 class ValidLeftHandSideSentinel: public Expression { | 317 class ValidLeftHandSideSentinel: public Expression { |
318 public: | 318 public: |
319 virtual bool IsValidLeftHandSide() { return true; } | 319 virtual bool IsValidLeftHandSide() { return true; } |
320 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } | 320 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
321 static ValidLeftHandSideSentinel* instance() { return &instance_; } | |
322 | 321 |
323 virtual bool IsPrimitive() { | 322 virtual bool IsPrimitive() { |
324 UNREACHABLE(); | 323 UNREACHABLE(); |
325 return false; | 324 return false; |
326 } | 325 } |
327 | |
328 private: | |
329 static ValidLeftHandSideSentinel instance_; | |
330 }; | 326 }; |
331 | 327 |
332 | 328 |
333 class BreakableStatement: public Statement { | 329 class BreakableStatement: public Statement { |
334 public: | 330 public: |
335 enum Type { | 331 enum Type { |
336 TARGET_FOR_ANONYMOUS, | 332 TARGET_FOR_ANONYMOUS, |
337 TARGET_FOR_NAMED_ONLY | 333 TARGET_FOR_NAMED_ONLY |
338 }; | 334 }; |
339 | 335 |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 VariableProxy(Handle<String> name, bool is_this, bool inside_with); | 1109 VariableProxy(Handle<String> name, bool is_this, bool inside_with); |
1114 explicit VariableProxy(bool is_this); | 1110 explicit VariableProxy(bool is_this); |
1115 | 1111 |
1116 friend class Scope; | 1112 friend class Scope; |
1117 }; | 1113 }; |
1118 | 1114 |
1119 | 1115 |
1120 class VariableProxySentinel: public VariableProxy { | 1116 class VariableProxySentinel: public VariableProxy { |
1121 public: | 1117 public: |
1122 virtual bool IsValidLeftHandSide() { return !is_this(); } | 1118 virtual bool IsValidLeftHandSide() { return !is_this(); } |
1123 static VariableProxySentinel* this_proxy() { return &this_proxy_; } | |
1124 static VariableProxySentinel* identifier_proxy() { | |
1125 return &identifier_proxy_; | |
1126 } | |
1127 | 1119 |
1128 virtual bool IsPrimitive() { | 1120 virtual bool IsPrimitive() { |
1129 UNREACHABLE(); | 1121 UNREACHABLE(); |
1130 return false; | 1122 return false; |
1131 } | 1123 } |
1132 | 1124 |
1133 private: | 1125 private: |
1134 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { } | 1126 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { } |
1135 static VariableProxySentinel this_proxy_; | 1127 |
1136 static VariableProxySentinel identifier_proxy_; | 1128 friend class AstSentinels; |
1137 }; | 1129 }; |
1138 | 1130 |
1139 | 1131 |
1140 class Slot: public Expression { | 1132 class Slot: public Expression { |
1141 public: | 1133 public: |
1142 enum Type { | 1134 enum Type { |
1143 // A slot in the parameter section on the stack. index() is | 1135 // A slot in the parameter section on the stack. index() is |
1144 // the parameter index, counting left-to-right, starting at 0. | 1136 // the parameter index, counting left-to-right, starting at 0. |
1145 PARAMETER, | 1137 PARAMETER, |
1146 | 1138 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 virtual bool IsValidLeftHandSide() { return true; } | 1205 virtual bool IsValidLeftHandSide() { return true; } |
1214 | 1206 |
1215 virtual bool IsPrimitive(); | 1207 virtual bool IsPrimitive(); |
1216 virtual bool IsCritical(); | 1208 virtual bool IsCritical(); |
1217 | 1209 |
1218 Expression* obj() const { return obj_; } | 1210 Expression* obj() const { return obj_; } |
1219 Expression* key() const { return key_; } | 1211 Expression* key() const { return key_; } |
1220 int position() const { return pos_; } | 1212 int position() const { return pos_; } |
1221 bool is_synthetic() const { return type_ == SYNTHETIC; } | 1213 bool is_synthetic() const { return type_ == SYNTHETIC; } |
1222 | 1214 |
1223 // Returns a property singleton property access on 'this'. Used | |
1224 // during preparsing. | |
1225 static Property* this_property() { return &this_property_; } | |
1226 | |
1227 private: | 1215 private: |
1228 Expression* obj_; | 1216 Expression* obj_; |
1229 Expression* key_; | 1217 Expression* key_; |
1230 int pos_; | 1218 int pos_; |
1231 Type type_; | 1219 Type type_; |
1232 | |
1233 // Dummy property used during preparsing. | |
1234 static Property this_property_; | |
1235 }; | 1220 }; |
1236 | 1221 |
1237 | 1222 |
1238 class Call: public Expression { | 1223 class Call: public Expression { |
1239 public: | 1224 public: |
1240 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) | 1225 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) |
1241 : expression_(expression), arguments_(arguments), pos_(pos) { } | 1226 : expression_(expression), arguments_(arguments), pos_(pos) { } |
1242 | 1227 |
1243 Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments); | 1228 Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments); |
1244 | 1229 |
1245 virtual void Accept(AstVisitor* v); | 1230 virtual void Accept(AstVisitor* v); |
1246 | 1231 |
1247 // Type testing and conversion. | 1232 // Type testing and conversion. |
1248 virtual Call* AsCall() { return this; } | 1233 virtual Call* AsCall() { return this; } |
1249 | 1234 |
1250 virtual bool IsPrimitive(); | 1235 virtual bool IsPrimitive(); |
1251 virtual bool IsCritical(); | 1236 virtual bool IsCritical(); |
1252 | 1237 |
1253 Expression* expression() const { return expression_; } | 1238 Expression* expression() const { return expression_; } |
1254 ZoneList<Expression*>* arguments() const { return arguments_; } | 1239 ZoneList<Expression*>* arguments() const { return arguments_; } |
1255 int position() { return pos_; } | 1240 int position() const { return pos_; } |
1256 | |
1257 static Call* sentinel() { return &sentinel_; } | |
1258 | 1241 |
1259 private: | 1242 private: |
1260 Expression* expression_; | 1243 Expression* expression_; |
1261 ZoneList<Expression*>* arguments_; | 1244 ZoneList<Expression*>* arguments_; |
1262 int pos_; | 1245 int pos_; |
1263 | |
1264 static Call sentinel_; | |
1265 }; | 1246 }; |
1266 | 1247 |
1267 | 1248 |
| 1249 class AstSentinels { |
| 1250 public: |
| 1251 ~AstSentinels() { } |
| 1252 |
| 1253 // Returns a property singleton property access on 'this'. Used |
| 1254 // during preparsing. |
| 1255 Property* this_property() { return &this_property_; } |
| 1256 VariableProxySentinel* this_proxy() { return &this_proxy_; } |
| 1257 VariableProxySentinel* identifier_proxy() { return &identifier_proxy_; } |
| 1258 ValidLeftHandSideSentinel* valid_left_hand_side_sentinel() { |
| 1259 return &valid_left_hand_side_sentinel_; |
| 1260 } |
| 1261 Call* call_sentinel() { return &call_sentinel_; } |
| 1262 EmptyStatement* empty_statement() { return &empty_statement_; } |
| 1263 |
| 1264 private: |
| 1265 AstSentinels(); |
| 1266 VariableProxySentinel this_proxy_; |
| 1267 VariableProxySentinel identifier_proxy_; |
| 1268 ValidLeftHandSideSentinel valid_left_hand_side_sentinel_; |
| 1269 Property this_property_; |
| 1270 Call call_sentinel_; |
| 1271 EmptyStatement empty_statement_; |
| 1272 |
| 1273 friend class Isolate; |
| 1274 |
| 1275 DISALLOW_COPY_AND_ASSIGN(AstSentinels); |
| 1276 }; |
| 1277 |
| 1278 |
1268 class CallNew: public Expression { | 1279 class CallNew: public Expression { |
1269 public: | 1280 public: |
1270 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) | 1281 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) |
1271 : expression_(expression), arguments_(arguments), pos_(pos) { } | 1282 : expression_(expression), arguments_(arguments), pos_(pos) { } |
1272 | 1283 |
1273 virtual void Accept(AstVisitor* v); | 1284 virtual void Accept(AstVisitor* v); |
1274 | 1285 |
1275 virtual bool IsPrimitive(); | 1286 virtual bool IsPrimitive(); |
1276 | 1287 |
1277 Expression* expression() const { return expression_; } | 1288 Expression* expression() const { return expression_; } |
1278 ZoneList<Expression*>* arguments() const { return arguments_; } | 1289 ZoneList<Expression*>* arguments() const { return arguments_; } |
1279 int position() { return pos_; } | 1290 int position() { return pos_; } |
1280 | 1291 |
1281 private: | 1292 private: |
1282 Expression* expression_; | 1293 Expression* expression_; |
1283 ZoneList<Expression*>* arguments_; | 1294 ZoneList<Expression*>* arguments_; |
1284 int pos_; | 1295 int pos_; |
1285 }; | 1296 }; |
1286 | 1297 |
1287 | 1298 |
1288 // The CallRuntime class does not represent any official JavaScript | 1299 // The CallRuntime class does not represent any official JavaScript |
1289 // language construct. Instead it is used to call a C or JS function | 1300 // language construct. Instead it is used to call a C or JS function |
1290 // with a set of arguments. This is used from the builtins that are | 1301 // with a set of arguments. This is used from the builtins that are |
1291 // implemented in JavaScript (see "v8natives.js"). | 1302 // implemented in JavaScript (see "v8natives.js"). |
1292 class CallRuntime: public Expression { | 1303 class CallRuntime: public Expression { |
1293 public: | 1304 public: |
1294 CallRuntime(Handle<String> name, | 1305 CallRuntime(Handle<String> name, |
1295 Runtime::Function* function, | 1306 const Runtime::Function* function, |
1296 ZoneList<Expression*>* arguments) | 1307 ZoneList<Expression*>* arguments) |
1297 : name_(name), function_(function), arguments_(arguments) { } | 1308 : name_(name), function_(function), arguments_(arguments) { } |
1298 | 1309 |
1299 virtual void Accept(AstVisitor* v); | 1310 virtual void Accept(AstVisitor* v); |
1300 | 1311 |
1301 virtual bool IsPrimitive(); | 1312 virtual bool IsPrimitive(); |
1302 | 1313 |
1303 Handle<String> name() const { return name_; } | 1314 Handle<String> name() const { return name_; } |
1304 Runtime::Function* function() const { return function_; } | 1315 const Runtime::Function* function() const { return function_; } |
1305 ZoneList<Expression*>* arguments() const { return arguments_; } | 1316 ZoneList<Expression*>* arguments() const { return arguments_; } |
1306 bool is_jsruntime() const { return function_ == NULL; } | 1317 bool is_jsruntime() const { return function_ == NULL; } |
1307 | 1318 |
1308 private: | 1319 private: |
1309 Handle<String> name_; | 1320 Handle<String> name_; |
1310 Runtime::Function* function_; | 1321 const Runtime::Function* function_; |
1311 ZoneList<Expression*>* arguments_; | 1322 ZoneList<Expression*>* arguments_; |
1312 }; | 1323 }; |
1313 | 1324 |
1314 | 1325 |
1315 class UnaryOperation: public Expression { | 1326 class UnaryOperation: public Expression { |
1316 public: | 1327 public: |
1317 UnaryOperation(Token::Value op, Expression* expression) | 1328 UnaryOperation(Token::Value op, Expression* expression) |
1318 : op_(op), expression_(expression) { | 1329 : op_(op), expression_(expression) { |
1319 ASSERT(Token::IsUnaryOp(op)); | 1330 ASSERT(Token::IsUnaryOp(op)); |
1320 } | 1331 } |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 | 2108 |
2098 // Holds the result of copying an expression. | 2109 // Holds the result of copying an expression. |
2099 Expression* expr_; | 2110 Expression* expr_; |
2100 // Holds the result of copying a statement. | 2111 // Holds the result of copying a statement. |
2101 Statement* stmt_; | 2112 Statement* stmt_; |
2102 }; | 2113 }; |
2103 | 2114 |
2104 } } // namespace v8::internal | 2115 } } // namespace v8::internal |
2105 | 2116 |
2106 #endif // V8_AST_H_ | 2117 #endif // V8_AST_H_ |
OLD | NEW |