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

Side by Side Diff: src/ast.h

Issue 663683006: Implement ES6 Template Literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Implement tagged template literals Created 6 years, 1 month 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 | « no previous file | 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_AST_H_ 5 #ifndef V8_AST_H_
6 #define V8_AST_H_ 6 #define V8_AST_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/assembler.h" 10 #include "src/assembler.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 V(Property) \ 89 V(Property) \
90 V(Call) \ 90 V(Call) \
91 V(CallNew) \ 91 V(CallNew) \
92 V(CallRuntime) \ 92 V(CallRuntime) \
93 V(UnaryOperation) \ 93 V(UnaryOperation) \
94 V(CountOperation) \ 94 V(CountOperation) \
95 V(BinaryOperation) \ 95 V(BinaryOperation) \
96 V(CompareOperation) \ 96 V(CompareOperation) \
97 V(ThisFunction) \ 97 V(ThisFunction) \
98 V(SuperReference) \ 98 V(SuperReference) \
99 V(CaseClause) 99 V(CaseClause) \
100 V(TemplateLiteral)
100 101
101 #define AST_NODE_LIST(V) \ 102 #define AST_NODE_LIST(V) \
102 DECLARATION_NODE_LIST(V) \ 103 DECLARATION_NODE_LIST(V) \
103 MODULE_NODE_LIST(V) \ 104 MODULE_NODE_LIST(V) \
104 STATEMENT_NODE_LIST(V) \ 105 STATEMENT_NODE_LIST(V) \
105 EXPRESSION_NODE_LIST(V) 106 EXPRESSION_NODE_LIST(V)
106 107
107 // Forward declarations 108 // Forward declarations
108 class AstConstructionVisitor; 109 class AstConstructionVisitor;
109 template<class> class AstNodeFactory; 110 template<class> class AstNodeFactory;
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 : Expression(zone, position), value_(value) {} 1426 : Expression(zone, position), value_(value) {}
1426 static int parent_num_ids() { return Expression::num_ids(); } 1427 static int parent_num_ids() { return Expression::num_ids(); }
1427 1428
1428 private: 1429 private:
1429 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1430 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1430 1431
1431 const AstValue* value_; 1432 const AstValue* value_;
1432 }; 1433 };
1433 1434
1434 1435
1436 class TemplateLiteral FINAL : public Expression {
1437 public:
1438 DECLARE_NODE_TYPE(TemplateLiteral)
1439
1440 const ZoneList<Expression*>* cooked() const { return &cooked_; }
1441 const ZoneList<Expression*>* raw() const { return &raw_; }
1442 const ZoneList<Expression*>* expressions() const { return &expressions_; }
1443
1444 void AddTemplateSpan(Literal* cooked, Literal* raw, Zone* zone) {
1445 DCHECK(cooked != NULL);
1446 DCHECK(raw != NULL);
1447 cooked_.Add(cooked, zone);
1448 raw_.Add(raw, zone);
1449 }
1450
1451 void AddExpression(Expression* expression, Zone* zone) {
1452 DCHECK(expression != NULL);
1453 expressions_.Add(expression, zone);
1454 }
1455
1456 static int num_ids() { return parent_num_ids() + 1; }
1457
1458 private:
1459 TemplateLiteral(Zone* zone, int pos)
1460 : Expression(zone, pos),
1461 cooked_(8, zone),
1462 raw_(8, zone),
1463 expressions_(8, zone) {
1464 }
1465
1466 static int parent_num_ids() { return Expression::num_ids(); }
1467
1468 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1469
1470 ZoneList<Expression*> cooked_;
1471 ZoneList<Expression*> raw_;
1472 ZoneList<Expression*> expressions_;
1473 };
1474
1475
1435 // Base class for literals that needs space in the corresponding JSFunction. 1476 // Base class for literals that needs space in the corresponding JSFunction.
1436 class MaterializedLiteral : public Expression { 1477 class MaterializedLiteral : public Expression {
1437 public: 1478 public:
1438 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } 1479 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1439 1480
1440 int literal_index() { return literal_index_; } 1481 int literal_index() { return literal_index_; }
1441 1482
1442 int depth() const { 1483 int depth() const {
1443 // only callable after initialization. 1484 // only callable after initialization.
1444 DCHECK(depth_ >= 1); 1485 DCHECK(depth_ >= 1);
(...skipping 1937 matching lines...) Expand 10 before | Expand all | Expand 10 after
3382 CaseClause* clause = new (zone_) CaseClause(zone_, label, statements, pos); 3423 CaseClause* clause = new (zone_) CaseClause(zone_, label, statements, pos);
3383 VISIT_AND_RETURN(CaseClause, clause) 3424 VISIT_AND_RETURN(CaseClause, clause)
3384 } 3425 }
3385 3426
3386 Literal* NewStringLiteral(const AstRawString* string, int pos) { 3427 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3387 Literal* lit = 3428 Literal* lit =
3388 new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos); 3429 new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos);
3389 VISIT_AND_RETURN(Literal, lit) 3430 VISIT_AND_RETURN(Literal, lit)
3390 } 3431 }
3391 3432
3433 TemplateLiteral* NewTemplateLiteral(int pos) {
3434 TemplateLiteral* lit =
3435 new (zone_) TemplateLiteral(zone_, pos);
3436 VISIT_AND_RETURN(TemplateLiteral, lit);
3437 }
3438
3392 // A JavaScript symbol (ECMA-262 edition 6). 3439 // A JavaScript symbol (ECMA-262 edition 6).
3393 Literal* NewSymbolLiteral(const char* name, int pos) { 3440 Literal* NewSymbolLiteral(const char* name, int pos) {
3394 Literal* lit = 3441 Literal* lit =
3395 new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos); 3442 new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3396 VISIT_AND_RETURN(Literal, lit) 3443 VISIT_AND_RETURN(Literal, lit)
3397 } 3444 }
3398 3445
3399 Literal* NewNumberLiteral(double number, int pos) { 3446 Literal* NewNumberLiteral(double number, int pos) {
3400 Literal* lit = 3447 Literal* lit =
3401 new (zone_) Literal(zone_, ast_value_factory_->NewNumber(number), pos); 3448 new (zone_) Literal(zone_, ast_value_factory_->NewNumber(number), pos);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 private: 3696 private:
3650 Zone* zone_; 3697 Zone* zone_;
3651 Visitor visitor_; 3698 Visitor visitor_;
3652 AstValueFactory* ast_value_factory_; 3699 AstValueFactory* ast_value_factory_;
3653 }; 3700 };
3654 3701
3655 3702
3656 } } // namespace v8::internal 3703 } } // namespace v8::internal
3657 3704
3658 #endif // V8_AST_H_ 3705 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698