Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: src/ast.h

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/assembler.cc ('k') | src/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 public: 128 public:
129 #define DECLARE_TYPE_ENUM(type) k##type, 129 #define DECLARE_TYPE_ENUM(type) k##type,
130 enum Type { 130 enum Type {
131 AST_NODE_LIST(DECLARE_TYPE_ENUM) 131 AST_NODE_LIST(DECLARE_TYPE_ENUM)
132 kInvalid = -1 132 kInvalid = -1
133 }; 133 };
134 #undef DECLARE_TYPE_ENUM 134 #undef DECLARE_TYPE_ENUM
135 135
136 static const int kNoNumber = -1; 136 static const int kNoNumber = -1;
137 137
138 AstNode() : id_(GetNextId()) { count_++; } 138 AstNode() : id_(GetNextId()) {
139 Isolate* isolate = Isolate::Current();
140 isolate->set_ast_node_count(isolate->ast_node_count() + 1);
141 }
139 142
140 virtual ~AstNode() { } 143 virtual ~AstNode() { }
141 144
142 virtual void Accept(AstVisitor* v) = 0; 145 virtual void Accept(AstVisitor* v) = 0;
143 virtual Type node_type() const { return kInvalid; } 146 virtual Type node_type() const { return kInvalid; }
144 147
145 // Type testing & conversion functions overridden by concrete subclasses. 148 // Type testing & conversion functions overridden by concrete subclasses.
146 #define DECLARE_NODE_FUNCTIONS(type) \ 149 #define DECLARE_NODE_FUNCTIONS(type) \
147 virtual type* As##type() { return NULL; } 150 virtual type* As##type() { return NULL; }
148 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 151 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
149 #undef DECLARE_NODE_FUNCTIONS 152 #undef DECLARE_NODE_FUNCTIONS
150 153
151 virtual Statement* AsStatement() { return NULL; } 154 virtual Statement* AsStatement() { return NULL; }
152 virtual Expression* AsExpression() { return NULL; } 155 virtual Expression* AsExpression() { return NULL; }
153 virtual TargetCollector* AsTargetCollector() { return NULL; } 156 virtual TargetCollector* AsTargetCollector() { return NULL; }
154 virtual BreakableStatement* AsBreakableStatement() { return NULL; } 157 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
155 virtual IterationStatement* AsIterationStatement() { return NULL; } 158 virtual IterationStatement* AsIterationStatement() { return NULL; }
156 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } 159 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
157 virtual Slot* AsSlot() { return NULL; } 160 virtual Slot* AsSlot() { return NULL; }
158 161
159 // True if the node is simple enough for us to inline calls containing it. 162 // True if the node is simple enough for us to inline calls containing it.
160 virtual bool IsInlineable() const { return false; } 163 virtual bool IsInlineable() const { return false; }
161 164
162 static int Count() { return count_; } 165 static int Count() { return Isolate::Current()->ast_node_count(); }
163 static void ResetIds() { current_id_ = 0; } 166 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); }
164 unsigned id() const { return id_; } 167 unsigned id() const { return id_; }
165 168
166 protected: 169 protected:
167 static unsigned GetNextId() { return current_id_++; } 170 static unsigned GetNextId() {
171 Isolate* isolate = Isolate::Current();
172 unsigned tmp = isolate->ast_node_id();
173 isolate->set_ast_node_id(tmp + 1);
174 return tmp;
175 }
168 static unsigned ReserveIdRange(int n) { 176 static unsigned ReserveIdRange(int n) {
169 unsigned tmp = current_id_; 177 Isolate* isolate = Isolate::Current();
170 current_id_ += n; 178 unsigned tmp = isolate->ast_node_id();
179 isolate->set_ast_node_id(tmp + n);
171 return tmp; 180 return tmp;
172 } 181 }
173 182
174 private: 183 private:
175 static unsigned current_id_;
176 static unsigned count_;
177 unsigned id_; 184 unsigned id_;
178 185
179 friend class CaseClause; // Generates AST IDs. 186 friend class CaseClause; // Generates AST IDs.
180 }; 187 };
181 188
182 189
183 class Statement: public AstNode { 190 class Statement: public AstNode {
184 public: 191 public:
185 Statement() : statement_pos_(RelocInfo::kNoPosition) {} 192 Statement() : statement_pos_(RelocInfo::kNoPosition) {}
186 193
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 335
329 /** 336 /**
330 * A sentinel used during pre parsing that represents some expression 337 * A sentinel used during pre parsing that represents some expression
331 * that is a valid left hand side without having to actually build 338 * that is a valid left hand side without having to actually build
332 * the expression. 339 * the expression.
333 */ 340 */
334 class ValidLeftHandSideSentinel: public Expression { 341 class ValidLeftHandSideSentinel: public Expression {
335 public: 342 public:
336 virtual bool IsValidLeftHandSide() { return true; } 343 virtual bool IsValidLeftHandSide() { return true; }
337 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } 344 virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
338 static ValidLeftHandSideSentinel* instance() { return &instance_; }
339
340 private:
341 static ValidLeftHandSideSentinel instance_;
342 }; 345 };
343 346
344 347
345 class BreakableStatement: public Statement { 348 class BreakableStatement: public Statement {
346 public: 349 public:
347 enum Type { 350 enum Type {
348 TARGET_FOR_ANONYMOUS, 351 TARGET_FOR_ANONYMOUS,
349 TARGET_FOR_NAMED_ONLY 352 TARGET_FOR_NAMED_ONLY
350 }; 353 };
351 354
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 894
892 Handle<String> AsPropertyName() { 895 Handle<String> AsPropertyName() {
893 ASSERT(IsPropertyName()); 896 ASSERT(IsPropertyName());
894 return Handle<String>::cast(handle_); 897 return Handle<String>::cast(handle_);
895 } 898 }
896 899
897 virtual bool ToBooleanIsTrue() { return handle_->ToBoolean()->IsTrue(); } 900 virtual bool ToBooleanIsTrue() { return handle_->ToBoolean()->IsTrue(); }
898 virtual bool ToBooleanIsFalse() { return handle_->ToBoolean()->IsFalse(); } 901 virtual bool ToBooleanIsFalse() { return handle_->ToBoolean()->IsFalse(); }
899 902
900 // Identity testers. 903 // Identity testers.
901 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } 904 bool IsNull() const {
902 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } 905 ASSERT(!handle_.is_null());
906 return handle_->IsNull();
907 }
908 bool IsTrue() const {
909 ASSERT(!handle_.is_null());
910 return handle_->IsTrue();
911 }
903 bool IsFalse() const { 912 bool IsFalse() const {
904 return handle_.is_identical_to(Factory::false_value()); 913 ASSERT(!handle_.is_null());
914 return handle_->IsFalse();
905 } 915 }
906 916
907 Handle<Object> handle() const { return handle_; } 917 Handle<Object> handle() const { return handle_; }
908 918
909 private: 919 private:
910 Handle<Object> handle_; 920 Handle<Object> handle_;
911 }; 921 };
912 922
913 923
914 // Base class for literals that needs space in the corresponding JSFunction. 924 // Base class for literals that needs space in the corresponding JSFunction.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 VariableProxy(Handle<String> name, bool is_this, bool inside_with); 1141 VariableProxy(Handle<String> name, bool is_this, bool inside_with);
1132 explicit VariableProxy(bool is_this); 1142 explicit VariableProxy(bool is_this);
1133 1143
1134 friend class Scope; 1144 friend class Scope;
1135 }; 1145 };
1136 1146
1137 1147
1138 class VariableProxySentinel: public VariableProxy { 1148 class VariableProxySentinel: public VariableProxy {
1139 public: 1149 public:
1140 virtual bool IsValidLeftHandSide() { return !is_this(); } 1150 virtual bool IsValidLeftHandSide() { return !is_this(); }
1141 static VariableProxySentinel* this_proxy() { return &this_proxy_; }
1142 static VariableProxySentinel* identifier_proxy() {
1143 return &identifier_proxy_;
1144 }
1145 1151
1146 private: 1152 private:
1147 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { } 1153 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { }
1148 static VariableProxySentinel this_proxy_; 1154
1149 static VariableProxySentinel identifier_proxy_; 1155 friend class AstSentinels;
1150 }; 1156 };
1151 1157
1152 1158
1153 class Slot: public Expression { 1159 class Slot: public Expression {
1154 public: 1160 public:
1155 enum Type { 1161 enum Type {
1156 // A slot in the parameter section on the stack. index() is 1162 // A slot in the parameter section on the stack. index() is
1157 // the parameter index, counting left-to-right, starting at 0. 1163 // the parameter index, counting left-to-right, starting at 0.
1158 PARAMETER, 1164 PARAMETER,
1159 1165
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 1252
1247 // Type feedback information. 1253 // Type feedback information.
1248 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1254 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1249 virtual bool IsMonomorphic() { return is_monomorphic_; } 1255 virtual bool IsMonomorphic() { return is_monomorphic_; }
1250 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } 1256 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
1251 virtual bool IsArrayLength() { return is_array_length_; } 1257 virtual bool IsArrayLength() { return is_array_length_; }
1252 virtual Handle<Map> GetMonomorphicReceiverType() { 1258 virtual Handle<Map> GetMonomorphicReceiverType() {
1253 return monomorphic_receiver_type_; 1259 return monomorphic_receiver_type_;
1254 } 1260 }
1255 1261
1256 // Returns a property singleton property access on 'this'. Used
1257 // during preparsing.
1258 static Property* this_property() { return &this_property_; }
1259
1260 private: 1262 private:
1261 Expression* obj_; 1263 Expression* obj_;
1262 Expression* key_; 1264 Expression* key_;
1263 int pos_; 1265 int pos_;
1264 Type type_; 1266 Type type_;
1265 1267
1266 ZoneMapList* receiver_types_; 1268 ZoneMapList* receiver_types_;
1267 bool is_monomorphic_ : 1; 1269 bool is_monomorphic_ : 1;
1268 bool is_array_length_ : 1; 1270 bool is_array_length_ : 1;
1269 bool is_string_length_ : 1; 1271 bool is_string_length_ : 1;
1270 bool is_string_access_ : 1; 1272 bool is_string_access_ : 1;
1271 bool is_function_prototype_ : 1; 1273 bool is_function_prototype_ : 1;
1272 bool is_arguments_access_ : 1; 1274 bool is_arguments_access_ : 1;
1273 Handle<Map> monomorphic_receiver_type_; 1275 Handle<Map> monomorphic_receiver_type_;
1274 ExternalArrayType array_type_; 1276 ExternalArrayType array_type_;
1275
1276 // Dummy property used during preparsing.
1277 static Property this_property_;
1278 }; 1277 };
1279 1278
1280 1279
1281 class Call: public Expression { 1280 class Call: public Expression {
1282 public: 1281 public:
1283 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1282 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1284 : expression_(expression), 1283 : expression_(expression),
1285 arguments_(arguments), 1284 arguments_(arguments),
1286 pos_(pos), 1285 pos_(pos),
1287 is_monomorphic_(false), 1286 is_monomorphic_(false),
(...skipping 17 matching lines...) Expand all
1305 Handle<JSFunction> target() { return target_; } 1304 Handle<JSFunction> target() { return target_; }
1306 Handle<JSObject> holder() { return holder_; } 1305 Handle<JSObject> holder() { return holder_; }
1307 Handle<JSGlobalPropertyCell> cell() { return cell_; } 1306 Handle<JSGlobalPropertyCell> cell() { return cell_; }
1308 1307
1309 bool ComputeTarget(Handle<Map> type, Handle<String> name); 1308 bool ComputeTarget(Handle<Map> type, Handle<String> name);
1310 bool ComputeGlobalTarget(Handle<GlobalObject> global, Handle<String> name); 1309 bool ComputeGlobalTarget(Handle<GlobalObject> global, Handle<String> name);
1311 1310
1312 // Bailout support. 1311 // Bailout support.
1313 int ReturnId() const { return return_id_; } 1312 int ReturnId() const { return return_id_; }
1314 1313
1315 static Call* sentinel() { return &sentinel_; }
1316
1317 #ifdef DEBUG 1314 #ifdef DEBUG
1318 // Used to assert that the FullCodeGenerator records the return site. 1315 // Used to assert that the FullCodeGenerator records the return site.
1319 bool return_is_recorded_; 1316 bool return_is_recorded_;
1320 #endif 1317 #endif
1321 1318
1322 private: 1319 private:
1323 Expression* expression_; 1320 Expression* expression_;
1324 ZoneList<Expression*>* arguments_; 1321 ZoneList<Expression*>* arguments_;
1325 int pos_; 1322 int pos_;
1326 1323
1327 bool is_monomorphic_; 1324 bool is_monomorphic_;
1328 CheckType check_type_; 1325 CheckType check_type_;
1329 ZoneMapList* receiver_types_; 1326 ZoneMapList* receiver_types_;
1330 Handle<JSFunction> target_; 1327 Handle<JSFunction> target_;
1331 Handle<JSObject> holder_; 1328 Handle<JSObject> holder_;
1332 Handle<JSGlobalPropertyCell> cell_; 1329 Handle<JSGlobalPropertyCell> cell_;
1333 1330
1334 int return_id_; 1331 int return_id_;
1335
1336 static Call sentinel_;
1337 }; 1332 };
1338 1333
1339 1334
1335 class AstSentinels {
1336 public:
1337 ~AstSentinels() { }
1338
1339 // Returns a property singleton property access on 'this'. Used
1340 // during preparsing.
1341 Property* this_property() { return &this_property_; }
1342 VariableProxySentinel* this_proxy() { return &this_proxy_; }
1343 VariableProxySentinel* identifier_proxy() { return &identifier_proxy_; }
1344 ValidLeftHandSideSentinel* valid_left_hand_side_sentinel() {
1345 return &valid_left_hand_side_sentinel_;
1346 }
1347 Call* call_sentinel() { return &call_sentinel_; }
1348 EmptyStatement* empty_statement() { return &empty_statement_; }
1349
1350 private:
1351 AstSentinels();
1352 VariableProxySentinel this_proxy_;
1353 VariableProxySentinel identifier_proxy_;
1354 ValidLeftHandSideSentinel valid_left_hand_side_sentinel_;
1355 Property this_property_;
1356 Call call_sentinel_;
1357 EmptyStatement empty_statement_;
1358
1359 friend class Isolate;
1360
1361 DISALLOW_COPY_AND_ASSIGN(AstSentinels);
1362 };
1363
1364
1340 class CallNew: public Expression { 1365 class CallNew: public Expression {
1341 public: 1366 public:
1342 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1367 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1343 : expression_(expression), arguments_(arguments), pos_(pos) { } 1368 : expression_(expression), arguments_(arguments), pos_(pos) { }
1344 1369
1345 DECLARE_NODE_TYPE(CallNew) 1370 DECLARE_NODE_TYPE(CallNew)
1346 1371
1347 virtual bool IsInlineable() const; 1372 virtual bool IsInlineable() const;
1348 1373
1349 Expression* expression() const { return expression_; } 1374 Expression* expression() const { return expression_; }
1350 ZoneList<Expression*>* arguments() const { return arguments_; } 1375 ZoneList<Expression*>* arguments() const { return arguments_; }
1351 int position() { return pos_; } 1376 int position() { return pos_; }
1352 1377
1353 private: 1378 private:
1354 Expression* expression_; 1379 Expression* expression_;
1355 ZoneList<Expression*>* arguments_; 1380 ZoneList<Expression*>* arguments_;
1356 int pos_; 1381 int pos_;
1357 }; 1382 };
1358 1383
1359 1384
1360 // The CallRuntime class does not represent any official JavaScript 1385 // The CallRuntime class does not represent any official JavaScript
1361 // language construct. Instead it is used to call a C or JS function 1386 // language construct. Instead it is used to call a C or JS function
1362 // with a set of arguments. This is used from the builtins that are 1387 // with a set of arguments. This is used from the builtins that are
1363 // implemented in JavaScript (see "v8natives.js"). 1388 // implemented in JavaScript (see "v8natives.js").
1364 class CallRuntime: public Expression { 1389 class CallRuntime: public Expression {
1365 public: 1390 public:
1366 CallRuntime(Handle<String> name, 1391 CallRuntime(Handle<String> name,
1367 Runtime::Function* function, 1392 const Runtime::Function* function,
1368 ZoneList<Expression*>* arguments) 1393 ZoneList<Expression*>* arguments)
1369 : name_(name), function_(function), arguments_(arguments) { } 1394 : name_(name), function_(function), arguments_(arguments) { }
1370 1395
1371 DECLARE_NODE_TYPE(CallRuntime) 1396 DECLARE_NODE_TYPE(CallRuntime)
1372 1397
1373 virtual bool IsInlineable() const; 1398 virtual bool IsInlineable() const;
1374 1399
1375 Handle<String> name() const { return name_; } 1400 Handle<String> name() const { return name_; }
1376 Runtime::Function* function() const { return function_; } 1401 const Runtime::Function* function() const { return function_; }
1377 ZoneList<Expression*>* arguments() const { return arguments_; } 1402 ZoneList<Expression*>* arguments() const { return arguments_; }
1378 bool is_jsruntime() const { return function_ == NULL; } 1403 bool is_jsruntime() const { return function_ == NULL; }
1379 1404
1380 private: 1405 private:
1381 Handle<String> name_; 1406 Handle<String> name_;
1382 Runtime::Function* function_; 1407 const Runtime::Function* function_;
1383 ZoneList<Expression*>* arguments_; 1408 ZoneList<Expression*>* arguments_;
1384 }; 1409 };
1385 1410
1386 1411
1387 class UnaryOperation: public Expression { 1412 class UnaryOperation: public Expression {
1388 public: 1413 public:
1389 UnaryOperation(Token::Value op, Expression* expression) 1414 UnaryOperation(Token::Value op, Expression* expression)
1390 : op_(op), expression_(expression) { 1415 : op_(op), expression_(expression) {
1391 ASSERT(Token::IsUnaryOp(op)); 1416 ASSERT(Token::IsUnaryOp(op));
1392 } 1417 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 expected_property_count_(expected_property_count), 1725 expected_property_count_(expected_property_count),
1701 has_only_simple_this_property_assignments_( 1726 has_only_simple_this_property_assignments_(
1702 has_only_simple_this_property_assignments), 1727 has_only_simple_this_property_assignments),
1703 this_property_assignments_(this_property_assignments), 1728 this_property_assignments_(this_property_assignments),
1704 num_parameters_(num_parameters), 1729 num_parameters_(num_parameters),
1705 start_position_(start_position), 1730 start_position_(start_position),
1706 end_position_(end_position), 1731 end_position_(end_position),
1707 is_expression_(is_expression), 1732 is_expression_(is_expression),
1708 contains_loops_(contains_loops), 1733 contains_loops_(contains_loops),
1709 function_token_position_(RelocInfo::kNoPosition), 1734 function_token_position_(RelocInfo::kNoPosition),
1710 inferred_name_(Heap::empty_string()), 1735 inferred_name_(HEAP->empty_string()),
1711 try_full_codegen_(false), 1736 try_full_codegen_(false),
1712 pretenure_(false) { } 1737 pretenure_(false) { }
1713 1738
1714 DECLARE_NODE_TYPE(FunctionLiteral) 1739 DECLARE_NODE_TYPE(FunctionLiteral)
1715 1740
1716 Handle<String> name() const { return name_; } 1741 Handle<String> name() const { return name_; }
1717 Scope* scope() const { return scope_; } 1742 Scope* scope() const { return scope_; }
1718 ZoneList<Statement*>* body() const { return body_; } 1743 ZoneList<Statement*>* body() const { return body_; }
1719 void set_function_token_position(int pos) { function_token_position_ = pos; } 1744 void set_function_token_position(int pos) { function_token_position_ = pos; }
1720 int function_token_position() const { return function_token_position_; } 1745 int function_token_position() const { return function_token_position_; }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 // Individual AST nodes. 2207 // Individual AST nodes.
2183 #define DEF_VISIT(type) \ 2208 #define DEF_VISIT(type) \
2184 virtual void Visit##type(type* node) = 0; 2209 virtual void Visit##type(type* node) = 0;
2185 AST_NODE_LIST(DEF_VISIT) 2210 AST_NODE_LIST(DEF_VISIT)
2186 #undef DEF_VISIT 2211 #undef DEF_VISIT
2187 2212
2188 private: 2213 private:
2189 bool stack_overflow_; 2214 bool stack_overflow_;
2190 }; 2215 };
2191 2216
2217
2192 } } // namespace v8::internal 2218 } } // namespace v8::internal
2193 2219
2194 #endif // V8_AST_H_ 2220 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698