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

Side by Side Diff: src/ast.cc

Issue 1148007: Merge bleeding_edge from version 2.1.3 up to revision 4205... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 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/ast.h ('k') | src/bootstrapper.cc » ('j') | src/heap.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (v->CheckStackOverflow()) return; \ 51 if (v->CheckStackOverflow()) return; \
52 v->Visit##type(this); \ 52 v->Visit##type(this); \
53 } 53 }
54 AST_NODE_LIST(DECL_ACCEPT) 54 AST_NODE_LIST(DECL_ACCEPT)
55 #undef DECL_ACCEPT 55 #undef DECL_ACCEPT
56 56
57 57
58 // ---------------------------------------------------------------------------- 58 // ----------------------------------------------------------------------------
59 // Implementation of other node functionality. 59 // Implementation of other node functionality.
60 60
61 Assignment* ExpressionStatement::StatementAsSimpleAssignment() {
62 return (expression()->AsAssignment() != NULL &&
63 !expression()->AsAssignment()->is_compound())
64 ? expression()->AsAssignment()
65 : NULL;
66 }
67
68
69 CountOperation* ExpressionStatement::StatementAsCountOperation() {
70 return expression()->AsCountOperation();
71 }
72
73
61 VariableProxy::VariableProxy(Handle<String> name, 74 VariableProxy::VariableProxy(Handle<String> name,
62 bool is_this, 75 bool is_this,
63 bool inside_with) 76 bool inside_with)
64 : name_(name), 77 : name_(name),
65 var_(NULL), 78 var_(NULL),
66 is_this_(is_this), 79 is_this_(is_this),
67 inside_with_(inside_with) { 80 inside_with_(inside_with),
81 is_trivial_(false),
82 reaching_definitions_(NULL) {
68 // names must be canonicalized for fast equality checks 83 // names must be canonicalized for fast equality checks
69 ASSERT(name->IsSymbol()); 84 ASSERT(name->IsSymbol());
70 } 85 }
71 86
72 87
73 VariableProxy::VariableProxy(bool is_this) 88 VariableProxy::VariableProxy(bool is_this)
74 : is_this_(is_this) { 89 : is_this_(is_this),
90 reaching_definitions_(NULL) {
75 } 91 }
76 92
77 93
78 void VariableProxy::BindTo(Variable* var) { 94 void VariableProxy::BindTo(Variable* var) {
79 ASSERT(var_ == NULL); // must be bound only once 95 ASSERT(var_ == NULL); // must be bound only once
80 ASSERT(var != NULL); // must bind 96 ASSERT(var != NULL); // must bind
81 ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name())); 97 ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name()));
82 // Ideally CONST-ness should match. However, this is very hard to achieve 98 // Ideally CONST-ness should match. However, this is very hard to achieve
83 // because we don't know the exact semantics of conflicting (const and 99 // because we don't know the exact semantics of conflicting (const and
84 // non-const) multiple variable declarations, const vars introduced via 100 // non-const) multiple variable declarations, const vars introduced via
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 min_match_ += node->min_match(); 493 min_match_ += node->min_match();
478 int node_max_match = node->max_match(); 494 int node_max_match = node->max_match();
479 if (kInfinity - max_match_ < node_max_match) { 495 if (kInfinity - max_match_ < node_max_match) {
480 max_match_ = kInfinity; 496 max_match_ = kInfinity;
481 } else { 497 } else {
482 max_match_ += node->max_match(); 498 max_match_ += node->max_match();
483 } 499 }
484 } 500 }
485 } 501 }
486 502
503 // IsPrimitive implementation. IsPrimitive is true if the value of an
504 // expression is known at compile-time to be any JS type other than Object
505 // (e.g, it is Undefined, Null, Boolean, String, or Number).
506
507 // The following expression types are never primitive because they express
508 // Object values.
509 bool FunctionLiteral::IsPrimitive() { return false; }
510 bool FunctionBoilerplateLiteral::IsPrimitive() { return false; }
511 bool RegExpLiteral::IsPrimitive() { return false; }
512 bool ObjectLiteral::IsPrimitive() { return false; }
513 bool ArrayLiteral::IsPrimitive() { return false; }
514 bool CatchExtensionObject::IsPrimitive() { return false; }
515 bool CallNew::IsPrimitive() { return false; }
516 bool ThisFunction::IsPrimitive() { return false; }
517
518
519 // The following expression types are not always primitive because we do not
520 // have enough information to conclude that they are.
521 bool VariableProxy::IsPrimitive() { return false; }
522 bool Property::IsPrimitive() { return false; }
523 bool Call::IsPrimitive() { return false; }
524 bool CallRuntime::IsPrimitive() { return false; }
525
526
527 // The value of a conditional is the value of one of the alternatives. It's
528 // always primitive if both alternatives are always primitive.
529 bool Conditional::IsPrimitive() {
530 return then_expression()->IsPrimitive() && else_expression()->IsPrimitive();
531 }
532
533
534 // A literal is primitive when it is not a JSObject.
535 bool Literal::IsPrimitive() { return !handle()->IsJSObject(); }
536
537
538 // The value of an assignment is the value of its right-hand side.
539 bool Assignment::IsPrimitive() {
540 switch (op()) {
541 case Token::INIT_VAR:
542 case Token::INIT_CONST:
543 case Token::ASSIGN:
544 return value()->IsPrimitive();
545
546 default:
547 // {|=, ^=, &=, <<=, >>=, >>>=, +=, -=, *=, /=, %=}
548 // Arithmetic operations are always primitive. They express Numbers
549 // with the exception of +, which expresses a Number or a String.
550 return true;
551 }
552 }
553
554
555 // Throw does not express a value, so it's trivially always primitive.
556 bool Throw::IsPrimitive() { return true; }
557
558
559 // Unary operations always express primitive values. delete and ! express
560 // Booleans, void Undefined, typeof String, +, -, and ~ Numbers.
561 bool UnaryOperation::IsPrimitive() { return true; }
562
563
564 // Count operations (pre- and post-fix increment and decrement) always
565 // express primitive values (Numbers). See ECMA-262-3, 11.3.1, 11.3.2,
566 // 11.4.4, ane 11.4.5.
567 bool CountOperation::IsPrimitive() { return true; }
568
569
570 // Binary operations depend on the operator.
571 bool BinaryOperation::IsPrimitive() {
572 switch (op()) {
573 case Token::COMMA:
574 // Value is the value of the right subexpression.
575 return right()->IsPrimitive();
576
577 case Token::OR:
578 case Token::AND:
579 // Value is the value one of the subexpressions.
580 return left()->IsPrimitive() && right()->IsPrimitive();
581
582 default:
583 // {|, ^, &, <<, >>, >>>, +, -, *, /, %}
584 // Arithmetic operations are always primitive. They express Numbers
585 // with the exception of +, which expresses a Number or a String.
586 return true;
587 }
588 }
589
590
591 // Compare operations always express Boolean values.
592 bool CompareOperation::IsPrimitive() { return true; }
593
594
595 // Implementation of a copy visitor. The visitor create a deep copy
596 // of ast nodes. Nodes that do not require a deep copy are copied
597 // with the default copy constructor.
598
599 AstNode::AstNode(AstNode* other) : num_(kNoNumber) {
600 // AST node number should be unique. Assert that we only copy AstNodes
601 // before node numbers are assigned.
602 ASSERT(other->num_ == kNoNumber);
603 }
604
605
606 Statement::Statement(Statement* other)
607 : AstNode(other), statement_pos_(other->statement_pos_) {}
608
609
610 Expression::Expression(Expression* other)
611 : AstNode(other),
612 bitfields_(other->bitfields_),
613 type_(other->type_) {}
614
615
616 BreakableStatement::BreakableStatement(BreakableStatement* other)
617 : Statement(other), labels_(other->labels_), type_(other->type_) {}
618
619
620 Block::Block(Block* other, ZoneList<Statement*>* statements)
621 : BreakableStatement(other),
622 statements_(statements->length()),
623 is_initializer_block_(other->is_initializer_block_) {
624 statements_.AddAll(*statements);
625 }
626
627
628 ExpressionStatement::ExpressionStatement(ExpressionStatement* other,
629 Expression* expression)
630 : Statement(other), expression_(expression) {}
631
632
633 IfStatement::IfStatement(IfStatement* other,
634 Expression* condition,
635 Statement* then_statement,
636 Statement* else_statement)
637 : Statement(other),
638 condition_(condition),
639 then_statement_(then_statement),
640 else_statement_(else_statement) {}
641
642
643 EmptyStatement::EmptyStatement(EmptyStatement* other) : Statement(other) {}
644
645
646 IterationStatement::IterationStatement(IterationStatement* other,
647 Statement* body)
648 : BreakableStatement(other), body_(body) {}
649
650
651 ForStatement::ForStatement(ForStatement* other,
652 Statement* init,
653 Expression* cond,
654 Statement* next,
655 Statement* body)
656 : IterationStatement(other, body),
657 init_(init),
658 cond_(cond),
659 next_(next),
660 may_have_function_literal_(other->may_have_function_literal_),
661 loop_variable_(other->loop_variable_),
662 peel_this_loop_(other->peel_this_loop_) {}
663
664
665 Assignment::Assignment(Assignment* other,
666 Expression* target,
667 Expression* value)
668 : Expression(other),
669 op_(other->op_),
670 target_(target),
671 value_(value),
672 pos_(other->pos_),
673 block_start_(other->block_start_),
674 block_end_(other->block_end_) {}
675
676
677 Property::Property(Property* other, Expression* obj, Expression* key)
678 : Expression(other),
679 obj_(obj),
680 key_(key),
681 pos_(other->pos_),
682 type_(other->type_) {}
683
684
685 Call::Call(Call* other,
686 Expression* expression,
687 ZoneList<Expression*>* arguments)
688 : Expression(other),
689 expression_(expression),
690 arguments_(arguments),
691 pos_(other->pos_) {}
692
693
694 UnaryOperation::UnaryOperation(UnaryOperation* other, Expression* expression)
695 : Expression(other), op_(other->op_), expression_(expression) {}
696
697
698 BinaryOperation::BinaryOperation(BinaryOperation* other,
699 Expression* left,
700 Expression* right)
701 : Expression(other),
702 op_(other->op_),
703 left_(left),
704 right_(right) {}
705
706
707 CountOperation::CountOperation(CountOperation* other, Expression* expression)
708 : Expression(other),
709 is_prefix_(other->is_prefix_),
710 op_(other->op_),
711 expression_(expression) {}
712
713
714 CompareOperation::CompareOperation(CompareOperation* other,
715 Expression* left,
716 Expression* right)
717 : Expression(other),
718 op_(other->op_),
719 left_(left),
720 right_(right),
721 is_for_loop_condition_(other->is_for_loop_condition_) {}
722
723
724 Expression* CopyAstVisitor::DeepCopyExpr(Expression* expr) {
725 expr_ = NULL;
726 if (expr != NULL) Visit(expr);
727 return expr_;
728 }
729
730
731 Statement* CopyAstVisitor::DeepCopyStmt(Statement* stmt) {
732 stmt_ = NULL;
733 if (stmt != NULL) Visit(stmt);
734 return stmt_;
735 }
736
737
738 ZoneList<Expression*>* CopyAstVisitor::DeepCopyExprList(
739 ZoneList<Expression*>* expressions) {
740 ZoneList<Expression*>* copy =
741 new ZoneList<Expression*>(expressions->length());
742 for (int i = 0; i < expressions->length(); i++) {
743 copy->Add(DeepCopyExpr(expressions->at(i)));
744 }
745 return copy;
746 }
747
748
749 ZoneList<Statement*>* CopyAstVisitor::DeepCopyStmtList(
750 ZoneList<Statement*>* statements) {
751 ZoneList<Statement*>* copy = new ZoneList<Statement*>(statements->length());
752 for (int i = 0; i < statements->length(); i++) {
753 copy->Add(DeepCopyStmt(statements->at(i)));
754 }
755 return copy;
756 }
757
758
759 void CopyAstVisitor::VisitBlock(Block* stmt) {
760 stmt_ = new Block(stmt,
761 DeepCopyStmtList(stmt->statements()));
762 }
763
764
765 void CopyAstVisitor::VisitExpressionStatement(
766 ExpressionStatement* stmt) {
767 stmt_ = new ExpressionStatement(stmt, DeepCopyExpr(stmt->expression()));
768 }
769
770
771 void CopyAstVisitor::VisitEmptyStatement(EmptyStatement* stmt) {
772 stmt_ = new EmptyStatement(stmt);
773 }
774
775
776 void CopyAstVisitor::VisitIfStatement(IfStatement* stmt) {
777 stmt_ = new IfStatement(stmt,
778 DeepCopyExpr(stmt->condition()),
779 DeepCopyStmt(stmt->then_statement()),
780 DeepCopyStmt(stmt->else_statement()));
781 }
782
783
784 void CopyAstVisitor::VisitContinueStatement(ContinueStatement* stmt) {
785 SetStackOverflow();
786 }
787
788
789 void CopyAstVisitor::VisitBreakStatement(BreakStatement* stmt) {
790 SetStackOverflow();
791 }
792
793
794 void CopyAstVisitor::VisitReturnStatement(ReturnStatement* stmt) {
795 SetStackOverflow();
796 }
797
798
799 void CopyAstVisitor::VisitWithEnterStatement(
800 WithEnterStatement* stmt) {
801 SetStackOverflow();
802 }
803
804
805 void CopyAstVisitor::VisitWithExitStatement(WithExitStatement* stmt) {
806 SetStackOverflow();
807 }
808
809
810 void CopyAstVisitor::VisitSwitchStatement(SwitchStatement* stmt) {
811 SetStackOverflow();
812 }
813
814
815 void CopyAstVisitor::VisitDoWhileStatement(DoWhileStatement* stmt) {
816 SetStackOverflow();
817 }
818
819
820 void CopyAstVisitor::VisitWhileStatement(WhileStatement* stmt) {
821 SetStackOverflow();
822 }
823
824
825 void CopyAstVisitor::VisitForStatement(ForStatement* stmt) {
826 stmt_ = new ForStatement(stmt,
827 DeepCopyStmt(stmt->init()),
828 DeepCopyExpr(stmt->cond()),
829 DeepCopyStmt(stmt->next()),
830 DeepCopyStmt(stmt->body()));
831 }
832
833
834 void CopyAstVisitor::VisitForInStatement(ForInStatement* stmt) {
835 SetStackOverflow();
836 }
837
838
839 void CopyAstVisitor::VisitTryCatchStatement(TryCatchStatement* stmt) {
840 SetStackOverflow();
841 }
842
843
844 void CopyAstVisitor::VisitTryFinallyStatement(
845 TryFinallyStatement* stmt) {
846 SetStackOverflow();
847 }
848
849
850 void CopyAstVisitor::VisitDebuggerStatement(
851 DebuggerStatement* stmt) {
852 SetStackOverflow();
853 }
854
855
856 void CopyAstVisitor::VisitFunctionLiteral(FunctionLiteral* expr) {
857 SetStackOverflow();
858 }
859
860
861 void CopyAstVisitor::VisitFunctionBoilerplateLiteral(
862 FunctionBoilerplateLiteral* expr) {
863 SetStackOverflow();
864 }
865
866
867 void CopyAstVisitor::VisitConditional(Conditional* expr) {
868 SetStackOverflow();
869 }
870
871
872 void CopyAstVisitor::VisitSlot(Slot* expr) {
873 UNREACHABLE();
874 }
875
876
877 void CopyAstVisitor::VisitVariableProxy(VariableProxy* expr) {
878 expr_ = new VariableProxy(*expr);
879 }
880
881
882 void CopyAstVisitor::VisitLiteral(Literal* expr) {
883 expr_ = new Literal(*expr);
884 }
885
886
887 void CopyAstVisitor::VisitRegExpLiteral(RegExpLiteral* expr) {
888 SetStackOverflow();
889 }
890
891
892 void CopyAstVisitor::VisitObjectLiteral(ObjectLiteral* expr) {
893 SetStackOverflow();
894 }
895
896
897 void CopyAstVisitor::VisitArrayLiteral(ArrayLiteral* expr) {
898 SetStackOverflow();
899 }
900
901
902 void CopyAstVisitor::VisitCatchExtensionObject(
903 CatchExtensionObject* expr) {
904 SetStackOverflow();
905 }
906
907
908 void CopyAstVisitor::VisitAssignment(Assignment* expr) {
909 expr_ = new Assignment(expr,
910 DeepCopyExpr(expr->target()),
911 DeepCopyExpr(expr->value()));
912 }
913
914
915 void CopyAstVisitor::VisitThrow(Throw* expr) {
916 SetStackOverflow();
917 }
918
919
920 void CopyAstVisitor::VisitProperty(Property* expr) {
921 expr_ = new Property(expr,
922 DeepCopyExpr(expr->obj()),
923 DeepCopyExpr(expr->key()));
924 }
925
926
927 void CopyAstVisitor::VisitCall(Call* expr) {
928 expr_ = new Call(expr,
929 DeepCopyExpr(expr->expression()),
930 DeepCopyExprList(expr->arguments()));
931 }
932
933
934 void CopyAstVisitor::VisitCallNew(CallNew* expr) {
935 SetStackOverflow();
936 }
937
938
939 void CopyAstVisitor::VisitCallRuntime(CallRuntime* expr) {
940 SetStackOverflow();
941 }
942
943
944 void CopyAstVisitor::VisitUnaryOperation(UnaryOperation* expr) {
945 expr_ = new UnaryOperation(expr, DeepCopyExpr(expr->expression()));
946 }
947
948
949 void CopyAstVisitor::VisitCountOperation(CountOperation* expr) {
950 expr_ = new CountOperation(expr,
951 DeepCopyExpr(expr->expression()));
952 }
953
954
955 void CopyAstVisitor::VisitBinaryOperation(BinaryOperation* expr) {
956 expr_ = new BinaryOperation(expr,
957 DeepCopyExpr(expr->left()),
958 DeepCopyExpr(expr->right()));
959 }
960
961
962 void CopyAstVisitor::VisitCompareOperation(CompareOperation* expr) {
963 expr_ = new CompareOperation(expr,
964 DeepCopyExpr(expr->left()),
965 DeepCopyExpr(expr->right()));
966 }
967
968
969 void CopyAstVisitor::VisitThisFunction(ThisFunction* expr) {
970 SetStackOverflow();
971 }
972
973
974 void CopyAstVisitor::VisitDeclaration(Declaration* decl) {
975 UNREACHABLE();
976 }
977
487 978
488 } } // namespace v8::internal 979 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/bootstrapper.cc » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698