00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_AST_H_
00029 #define V8_AST_H_
00030
00031 #include "execution.h"
00032 #include "factory.h"
00033 #include "runtime.h"
00034 #include "token.h"
00035 #include "variables.h"
00036 #include "macro-assembler.h"
00037
00038 namespace v8 { namespace internal {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define NODE_LIST(V) \
00054 V(Block) \
00055 V(Declaration) \
00056 V(ExpressionStatement) \
00057 V(EmptyStatement) \
00058 V(IfStatement) \
00059 V(ContinueStatement) \
00060 V(BreakStatement) \
00061 V(ReturnStatement) \
00062 V(WithEnterStatement) \
00063 V(WithExitStatement) \
00064 V(SwitchStatement) \
00065 V(LoopStatement) \
00066 V(ForInStatement) \
00067 V(TryCatch) \
00068 V(TryFinally) \
00069 V(DebuggerStatement) \
00070 V(FunctionLiteral) \
00071 V(FunctionBoilerplateLiteral) \
00072 V(Conditional) \
00073 V(Slot) \
00074 V(VariableProxy) \
00075 V(Literal) \
00076 V(RegExpLiteral) \
00077 V(ObjectLiteral) \
00078 V(ArrayLiteral) \
00079 V(Assignment) \
00080 V(Throw) \
00081 V(Property) \
00082 V(Call) \
00083 V(CallNew) \
00084 V(CallRuntime) \
00085 V(UnaryOperation) \
00086 V(CountOperation) \
00087 V(BinaryOperation) \
00088 V(CompareOperation) \
00089 V(ThisFunction)
00090
00091
00092 #define DEF_FORWARD_DECLARATION(type) class type;
00093 NODE_LIST(DEF_FORWARD_DECLARATION)
00094 #undef DEF_FORWARD_DECLARATION
00095
00096
00097
00098
00099 typedef ZoneList<Handle<String> > ZoneStringList;
00100
00101
00102 class Node: public ZoneObject {
00103 public:
00104 Node(): statement_pos_(RelocInfo::kNoPosition) { }
00105 virtual ~Node() { }
00106 virtual void Accept(Visitor* v) = 0;
00107
00108
00109 virtual Statement* AsStatement() { return NULL; }
00110 virtual ExpressionStatement* AsExpressionStatement() { return NULL; }
00111 virtual EmptyStatement* AsEmptyStatement() { return NULL; }
00112 virtual Expression* AsExpression() { return NULL; }
00113 virtual Literal* AsLiteral() { return NULL; }
00114 virtual Slot* AsSlot() { return NULL; }
00115 virtual VariableProxy* AsVariableProxy() { return NULL; }
00116 virtual Property* AsProperty() { return NULL; }
00117 virtual Call* AsCall() { return NULL; }
00118 virtual LabelCollector* AsLabelCollector() { return NULL; }
00119 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
00120 virtual IterationStatement* AsIterationStatement() { return NULL; }
00121 virtual UnaryOperation* AsUnaryOperation() { return NULL; }
00122 virtual BinaryOperation* AsBinaryOperation() { return NULL; }
00123 virtual Assignment* AsAssignment() { return NULL; }
00124 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; }
00125
00126 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
00127 int statement_pos() const { return statement_pos_; }
00128
00129 private:
00130 int statement_pos_;
00131 };
00132
00133
00134 class Statement: public Node {
00135 public:
00136 virtual Statement* AsStatement() { return this; }
00137 virtual ReturnStatement* AsReturnStatement() { return NULL; }
00138
00139 bool IsEmpty() { return AsEmptyStatement() != NULL; }
00140 };
00141
00142
00143 class Expression: public Node {
00144 public:
00145 virtual Expression* AsExpression() { return this; }
00146
00147 virtual bool IsValidLeftHandSide() { return false; }
00148
00149
00150
00151
00152 virtual void MarkAsStatement() { }
00153
00154
00155 StaticType* type() { return &type_; }
00156
00157 private:
00158 StaticType type_;
00159 };
00160
00161
00167 class ValidLeftHandSideSentinel: public Expression {
00168 public:
00169 virtual bool IsValidLeftHandSide() { return true; }
00170 virtual void Accept(Visitor* v) { UNREACHABLE(); }
00171 static ValidLeftHandSideSentinel* instance() { return &instance_; }
00172 private:
00173 static ValidLeftHandSideSentinel instance_;
00174 };
00175
00176
00177 class BreakableStatement: public Statement {
00178 public:
00179 enum Type {
00180 TARGET_FOR_ANONYMOUS,
00181 TARGET_FOR_NAMED_ONLY
00182 };
00183
00184
00185
00186 ZoneStringList* labels() const { return labels_; }
00187
00188
00189 virtual BreakableStatement* AsBreakableStatement() { return this; }
00190
00191
00192 Label* break_target() { return &break_target_; }
00193
00194
00195
00196 int break_stack_height() { return break_stack_height_; }
00197 void set_break_stack_height(int height) { break_stack_height_ = height; }
00198
00199
00200 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; }
00201
00202 protected:
00203 BreakableStatement(ZoneStringList* labels, Type type)
00204 : labels_(labels), type_(type) {
00205 ASSERT(labels == NULL || labels->length() > 0);
00206 }
00207
00208 private:
00209 ZoneStringList* labels_;
00210 Type type_;
00211 Label break_target_;
00212 int break_stack_height_;
00213 };
00214
00215
00216 class Block: public BreakableStatement {
00217 public:
00218 Block(ZoneStringList* labels, int capacity, bool is_initializer_block)
00219 : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY),
00220 statements_(capacity),
00221 is_initializer_block_(is_initializer_block) { }
00222
00223 virtual void Accept(Visitor* v);
00224
00225 void AddStatement(Statement* statement) { statements_.Add(statement); }
00226
00227 ZoneList<Statement*>* statements() { return &statements_; }
00228 bool is_initializer_block() const { return is_initializer_block_; }
00229
00230 private:
00231 ZoneList<Statement*> statements_;
00232 bool is_initializer_block_;
00233 };
00234
00235
00236 class Declaration: public Node {
00237 public:
00238 Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun)
00239 : proxy_(proxy),
00240 mode_(mode),
00241 fun_(fun) {
00242 ASSERT(mode == Variable::VAR || mode == Variable::CONST);
00243
00244 ASSERT(fun == NULL || mode == Variable::VAR);
00245 }
00246
00247 virtual void Accept(Visitor* v);
00248
00249 VariableProxy* proxy() const { return proxy_; }
00250 Variable::Mode mode() const { return mode_; }
00251 FunctionLiteral* fun() const { return fun_; }
00252
00253 private:
00254 VariableProxy* proxy_;
00255 Variable::Mode mode_;
00256 FunctionLiteral* fun_;
00257 };
00258
00259
00260 class IterationStatement: public BreakableStatement {
00261 public:
00262
00263 virtual IterationStatement* AsIterationStatement() { return this; }
00264
00265 Statement* body() const { return body_; }
00266
00267
00268 Label* continue_target() { return &continue_target_; }
00269
00270 protected:
00271 explicit IterationStatement(ZoneStringList* labels)
00272 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { }
00273
00274 void Initialize(Statement* body) {
00275 body_ = body;
00276 }
00277
00278 private:
00279 Statement* body_;
00280 Label continue_target_;
00281 };
00282
00283
00284 class LoopStatement: public IterationStatement {
00285 public:
00286 enum Type { DO_LOOP, FOR_LOOP, WHILE_LOOP };
00287
00288 LoopStatement(ZoneStringList* labels, Type type)
00289 : IterationStatement(labels), type_(type), init_(NULL),
00290 cond_(NULL), next_(NULL) { }
00291
00292 void Initialize(Statement* init,
00293 Expression* cond,
00294 Statement* next,
00295 Statement* body) {
00296 ASSERT(init == NULL || type_ == FOR_LOOP);
00297 ASSERT(next == NULL || type_ == FOR_LOOP);
00298 IterationStatement::Initialize(body);
00299 init_ = init;
00300 cond_ = cond;
00301 next_ = next;
00302 }
00303
00304 virtual void Accept(Visitor* v);
00305
00306 Type type() const { return type_; }
00307 Statement* init() const { return init_; }
00308 Expression* cond() const { return cond_; }
00309 Statement* next() const { return next_; }
00310
00311 #ifdef DEBUG
00312 const char* OperatorString() const;
00313 #endif
00314
00315 private:
00316 Type type_;
00317 Statement* init_;
00318 Expression* cond_;
00319 Statement* next_;
00320 };
00321
00322
00323 class ForInStatement: public IterationStatement {
00324 public:
00325 explicit ForInStatement(ZoneStringList* labels)
00326 : IterationStatement(labels), each_(NULL), enumerable_(NULL) { }
00327
00328 void Initialize(Expression* each, Expression* enumerable, Statement* body) {
00329 IterationStatement::Initialize(body);
00330 each_ = each;
00331 enumerable_ = enumerable;
00332 }
00333
00334 virtual void Accept(Visitor* v);
00335
00336 Expression* each() const { return each_; }
00337 Expression* enumerable() const { return enumerable_; }
00338
00339 private:
00340 Expression* each_;
00341 Expression* enumerable_;
00342 };
00343
00344
00345 class ExpressionStatement: public Statement {
00346 public:
00347 explicit ExpressionStatement(Expression* expression)
00348 : expression_(expression) { }
00349
00350 virtual void Accept(Visitor* v);
00351
00352
00353 virtual ExpressionStatement* AsExpressionStatement() { return this; }
00354
00355 void set_expression(Expression* e) { expression_ = e; }
00356 Expression* expression() { return expression_; }
00357
00358 private:
00359 Expression* expression_;
00360 };
00361
00362
00363 class ContinueStatement: public Statement {
00364 public:
00365 explicit ContinueStatement(IterationStatement* target)
00366 : target_(target) { }
00367
00368 virtual void Accept(Visitor* v);
00369
00370 IterationStatement* target() const { return target_; }
00371
00372 private:
00373 IterationStatement* target_;
00374 };
00375
00376
00377 class BreakStatement: public Statement {
00378 public:
00379 explicit BreakStatement(BreakableStatement* target)
00380 : target_(target) { }
00381
00382 virtual void Accept(Visitor* v);
00383
00384 BreakableStatement* target() const { return target_; }
00385
00386 private:
00387 BreakableStatement* target_;
00388 };
00389
00390
00391 class ReturnStatement: public Statement {
00392 public:
00393 explicit ReturnStatement(Expression* expression)
00394 : expression_(expression) { }
00395
00396 virtual void Accept(Visitor* v);
00397
00398
00399 virtual ReturnStatement* AsReturnStatement() { return this; }
00400
00401 Expression* expression() { return expression_; }
00402
00403 private:
00404 Expression* expression_;
00405 };
00406
00407
00408 class WithEnterStatement: public Statement {
00409 public:
00410 explicit WithEnterStatement(Expression* expression)
00411 : expression_(expression) { }
00412
00413 virtual void Accept(Visitor* v);
00414
00415 Expression* expression() const { return expression_; }
00416
00417 private:
00418 Expression* expression_;
00419 };
00420
00421
00422 class WithExitStatement: public Statement {
00423 public:
00424 WithExitStatement() { }
00425
00426 virtual void Accept(Visitor* v);
00427 };
00428
00429
00430 class CaseClause: public ZoneObject {
00431 public:
00432 CaseClause(Expression* label, ZoneList<Statement*>* statements)
00433 : label_(label), statements_(statements) { }
00434
00435 bool is_default() const { return label_ == NULL; }
00436 Expression* label() const {
00437 CHECK(!is_default());
00438 return label_;
00439 }
00440 ZoneList<Statement*>* statements() const { return statements_; }
00441
00442 private:
00443 Expression* label_;
00444 ZoneList<Statement*>* statements_;
00445 };
00446
00447
00448 class SwitchStatement: public BreakableStatement {
00449 public:
00450 explicit SwitchStatement(ZoneStringList* labels)
00451 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS),
00452 tag_(NULL), cases_(NULL) { }
00453
00454 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
00455 tag_ = tag;
00456 cases_ = cases;
00457 }
00458
00459 virtual void Accept(Visitor* v);
00460
00461 Expression* tag() const { return tag_; }
00462 ZoneList<CaseClause*>* cases() const { return cases_; }
00463
00464 private:
00465 Expression* tag_;
00466 ZoneList<CaseClause*>* cases_;
00467 };
00468
00469
00470
00471
00472
00473
00474
00475 class IfStatement: public Statement {
00476 public:
00477 IfStatement(Expression* condition,
00478 Statement* then_statement,
00479 Statement* else_statement)
00480 : condition_(condition),
00481 then_statement_(then_statement),
00482 else_statement_(else_statement) { }
00483
00484 virtual void Accept(Visitor* v);
00485
00486 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
00487 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
00488
00489 Expression* condition() const { return condition_; }
00490 Statement* then_statement() const { return then_statement_; }
00491 Statement* else_statement() const { return else_statement_; }
00492
00493 private:
00494 Expression* condition_;
00495 Statement* then_statement_;
00496 Statement* else_statement_;
00497 };
00498
00499
00500
00501
00502 class LabelCollector: public Node {
00503 public:
00504 explicit LabelCollector(ZoneList<Label*>* labels) : labels_(labels) { }
00505
00506
00507
00508
00509 void AddLabel(Label* label);
00510
00511
00512 virtual void Accept(Visitor* v) { UNREACHABLE(); }
00513 virtual LabelCollector* AsLabelCollector() { return this; }
00514
00515 ZoneList<Label*>* labels() { return labels_; }
00516
00517 private:
00518 ZoneList<Label*>* labels_;
00519 };
00520
00521
00522 class TryStatement: public Statement {
00523 public:
00524 explicit TryStatement(Block* try_block)
00525 : try_block_(try_block), escaping_labels_(NULL) { }
00526
00527 void set_escaping_labels(ZoneList<Label*>* labels) {
00528 escaping_labels_ = labels;
00529 }
00530
00531 Block* try_block() const { return try_block_; }
00532 ZoneList<Label*>* escaping_labels() const { return escaping_labels_; }
00533
00534 private:
00535 Block* try_block_;
00536 ZoneList<Label*>* escaping_labels_;
00537 };
00538
00539
00540 class TryCatch: public TryStatement {
00541 public:
00542 TryCatch(Block* try_block, Expression* catch_var, Block* catch_block)
00543 : TryStatement(try_block),
00544 catch_var_(catch_var),
00545 catch_block_(catch_block) {
00546 ASSERT(catch_var->AsVariableProxy() != NULL);
00547 }
00548
00549 virtual void Accept(Visitor* v);
00550
00551 Expression* catch_var() const { return catch_var_; }
00552 Block* catch_block() const { return catch_block_; }
00553
00554 private:
00555 Expression* catch_var_;
00556 Block* catch_block_;
00557 };
00558
00559
00560 class TryFinally: public TryStatement {
00561 public:
00562 TryFinally(Block* try_block, Block* finally_block)
00563 : TryStatement(try_block),
00564 finally_block_(finally_block) { }
00565
00566 virtual void Accept(Visitor* v);
00567
00568 Block* finally_block() const { return finally_block_; }
00569
00570 private:
00571 Block* finally_block_;
00572 };
00573
00574
00575 class DebuggerStatement: public Statement {
00576 public:
00577 virtual void Accept(Visitor* v);
00578 };
00579
00580
00581 class EmptyStatement: public Statement {
00582 public:
00583 virtual void Accept(Visitor* v);
00584
00585
00586 virtual EmptyStatement* AsEmptyStatement() { return this; }
00587 };
00588
00589
00590 class Literal: public Expression {
00591 public:
00592 explicit Literal(Handle<Object> handle) : handle_(handle) { }
00593
00594 virtual void Accept(Visitor* v);
00595
00596
00597 virtual Literal* AsLiteral() { return this; }
00598
00599
00600 bool IsIdenticalTo(const Literal* other) const {
00601 return handle_.is_identical_to(other->handle_);
00602 }
00603
00604
00605 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); }
00606 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); }
00607 bool IsFalse() const {
00608 return handle_.is_identical_to(Factory::false_value());
00609 }
00610
00611 Handle<Object> handle() const { return handle_; }
00612
00613 private:
00614 Handle<Object> handle_;
00615 };
00616
00617
00618
00619 class MaterializedLiteral: public Expression {
00620 public:
00621 explicit MaterializedLiteral(int literal_index)
00622 : literal_index_(literal_index) {}
00623 int literal_index() { return literal_index_; }
00624 private:
00625 int literal_index_;
00626 };
00627
00628
00629
00630
00631 class ObjectLiteral: public MaterializedLiteral {
00632 public:
00633
00634
00635
00636 class Property: public ZoneObject {
00637 public:
00638
00639 enum Kind {
00640 CONSTANT,
00641 COMPUTED,
00642 GETTER, SETTER,
00643 PROTOTYPE
00644 };
00645
00646 Property(Literal* key, Expression* value);
00647 Property(bool is_getter, FunctionLiteral* value);
00648
00649 Literal* key() { return key_; }
00650 Expression* value() { return value_; }
00651 Kind kind() { return kind_; }
00652
00653 private:
00654 Literal* key_;
00655 Expression* value_;
00656 Kind kind_;
00657 };
00658
00659 ObjectLiteral(Handle<FixedArray> constant_properties,
00660 ZoneList<Property*>* properties,
00661 int literal_index)
00662 : MaterializedLiteral(literal_index),
00663 constant_properties_(constant_properties),
00664 properties_(properties) {
00665 }
00666
00667 virtual void Accept(Visitor* v);
00668
00669 Handle<FixedArray> constant_properties() const {
00670 return constant_properties_;
00671 }
00672 ZoneList<Property*>* properties() const { return properties_; }
00673
00674 private:
00675 Handle<FixedArray> constant_properties_;
00676 ZoneList<Property*>* properties_;
00677 };
00678
00679
00680
00681 class RegExpLiteral: public MaterializedLiteral {
00682 public:
00683 RegExpLiteral(Handle<String> pattern,
00684 Handle<String> flags,
00685 int literal_index)
00686 : MaterializedLiteral(literal_index),
00687 pattern_(pattern),
00688 flags_(flags) {}
00689
00690 virtual void Accept(Visitor* v);
00691
00692 Handle<String> pattern() const { return pattern_; }
00693 Handle<String> flags() const { return flags_; }
00694
00695 private:
00696 Handle<String> pattern_;
00697 Handle<String> flags_;
00698 };
00699
00700
00701
00702 class ArrayLiteral: public Expression {
00703 public:
00704 ArrayLiteral(Handle<FixedArray> literals,
00705 ZoneList<Expression*>* values)
00706 : literals_(literals), values_(values) {
00707 }
00708
00709 virtual void Accept(Visitor* v);
00710
00711 Handle<FixedArray> literals() const { return literals_; }
00712 ZoneList<Expression*>* values() const { return values_; }
00713
00714 private:
00715 Handle<FixedArray> literals_;
00716 ZoneList<Expression*>* values_;
00717 };
00718
00719
00720 class VariableProxy: public Expression {
00721 public:
00722 virtual void Accept(Visitor* v);
00723
00724
00725 virtual Property* AsProperty() {
00726 return var_ == NULL ? NULL : var_->AsProperty();
00727 }
00728 virtual VariableProxy* AsVariableProxy() { return this; }
00729
00730 Variable* AsVariable() {
00731 return this == NULL || var_ == NULL ? NULL : var_->AsVariable();
00732 }
00733 virtual bool IsValidLeftHandSide() {
00734 return var_ == NULL ? true : var_->IsValidLeftHandSide();
00735 }
00736 bool IsVariable(Handle<String> n) {
00737 return !is_this() && name().is_identical_to(n);
00738 }
00739
00740
00741
00742
00743 Handle<String> name() const { return name_; }
00744 Variable* var() const { return var_; }
00745 UseCount* var_uses() { return &var_uses_; }
00746 UseCount* obj_uses() { return &obj_uses_; }
00747 bool is_this() const { return is_this_; }
00748 bool inside_with() const { return inside_with_; }
00749
00750
00751 void BindTo(Variable* var);
00752
00753 protected:
00754 Handle<String> name_;
00755 Variable* var_;
00756 bool is_this_;
00757 bool inside_with_;
00758
00759
00760 UseCount var_uses_;
00761 UseCount obj_uses_;
00762
00763 VariableProxy(Handle<String> name, bool is_this, bool inside_with);
00764 explicit VariableProxy(bool is_this);
00765
00766 friend class Scope;
00767 };
00768
00769
00770 class VariableProxySentinel: public VariableProxy {
00771 public:
00772 virtual bool IsValidLeftHandSide() { return !is_this(); }
00773 static VariableProxySentinel* this_proxy() { return &this_proxy_; }
00774 static VariableProxySentinel* identifier_proxy() {
00775 return &identifier_proxy_;
00776 }
00777
00778 private:
00779 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { }
00780 static VariableProxySentinel this_proxy_;
00781 static VariableProxySentinel identifier_proxy_;
00782 };
00783
00784
00785 class Slot: public Expression {
00786 public:
00787 enum Type {
00788
00789
00790 PARAMETER,
00791
00792
00793
00794 LOCAL,
00795
00796
00797
00798
00799
00800 CONTEXT,
00801
00802
00803
00804
00805
00806 LOOKUP,
00807
00808
00809
00810 GLOBAL
00811 };
00812
00813 Slot(Variable* var, Type type, int index)
00814 : var_(var), type_(type), index_(index) {
00815 ASSERT(var != NULL);
00816 }
00817
00818 virtual void Accept(Visitor* v);
00819
00820
00821 virtual Slot* AsSlot() { return this; }
00822
00823
00824 Variable* var() const { return var_; }
00825 Type type() const { return type_; }
00826 int index() const { return index_; }
00827
00828 private:
00829 Variable* var_;
00830 Type type_;
00831 int index_;
00832 };
00833
00834
00835 class Property: public Expression {
00836 public:
00837 Property(Expression* obj, Expression* key, int pos)
00838 : obj_(obj), key_(key), pos_(pos) { }
00839
00840 virtual void Accept(Visitor* v);
00841
00842
00843 virtual Property* AsProperty() { return this; }
00844
00845 virtual bool IsValidLeftHandSide() { return true; }
00846
00847 Expression* obj() const { return obj_; }
00848 Expression* key() const { return key_; }
00849 int position() const { return pos_; }
00850
00851
00852
00853 static Property* this_property() { return &this_property_; }
00854
00855 private:
00856 Expression* obj_;
00857 Expression* key_;
00858 int pos_;
00859
00860
00861 static Property this_property_;
00862 };
00863
00864
00865 class Call: public Expression {
00866 public:
00867 Call(Expression* expression,
00868 ZoneList<Expression*>* arguments,
00869 bool is_eval,
00870 int pos)
00871 : expression_(expression),
00872 arguments_(arguments),
00873 is_eval_(is_eval),
00874 pos_(pos) { }
00875
00876 virtual void Accept(Visitor* v);
00877
00878
00879 virtual Call* AsCall() { return this; }
00880
00881 Expression* expression() const { return expression_; }
00882 ZoneList<Expression*>* arguments() const { return arguments_; }
00883 bool is_eval() { return is_eval_; }
00884 int position() { return pos_; }
00885
00886 static Call* sentinel() { return &sentinel_; }
00887
00888 private:
00889 Expression* expression_;
00890 ZoneList<Expression*>* arguments_;
00891 bool is_eval_;
00892 int pos_;
00893
00894 static Call sentinel_;
00895 };
00896
00897
00898 class CallNew: public Call {
00899 public:
00900 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos)
00901 : Call(expression, arguments, false, pos) { }
00902
00903 virtual void Accept(Visitor* v);
00904 };
00905
00906
00907
00908
00909
00910
00911 class CallRuntime: public Expression {
00912 public:
00913 CallRuntime(Handle<String> name,
00914 Runtime::Function* function,
00915 ZoneList<Expression*>* arguments)
00916 : name_(name), function_(function), arguments_(arguments) { }
00917
00918 virtual void Accept(Visitor* v);
00919
00920 Handle<String> name() const { return name_; }
00921 Runtime::Function* function() const { return function_; }
00922 ZoneList<Expression*>* arguments() const { return arguments_; }
00923
00924 private:
00925 Handle<String> name_;
00926 Runtime::Function* function_;
00927 ZoneList<Expression*>* arguments_;
00928 };
00929
00930
00931 class UnaryOperation: public Expression {
00932 public:
00933 UnaryOperation(Token::Value op, Expression* expression)
00934 : op_(op), expression_(expression) {
00935 ASSERT(Token::IsUnaryOp(op));
00936 }
00937
00938 virtual void Accept(Visitor* v);
00939
00940
00941 virtual UnaryOperation* AsUnaryOperation() { return this; }
00942
00943 Token::Value op() const { return op_; }
00944 Expression* expression() const { return expression_; }
00945
00946 private:
00947 Token::Value op_;
00948 Expression* expression_;
00949 };
00950
00951
00952 class BinaryOperation: public Expression {
00953 public:
00954 BinaryOperation(Token::Value op, Expression* left, Expression* right)
00955 : op_(op), left_(left), right_(right) {
00956 ASSERT(Token::IsBinaryOp(op));
00957 }
00958
00959 virtual void Accept(Visitor* v);
00960
00961
00962 virtual BinaryOperation* AsBinaryOperation() { return this; }
00963
00964
00965
00966 bool ResultOverwriteAllowed() {
00967 switch (op_) {
00968 case Token::COMMA:
00969 case Token::OR:
00970 case Token::AND:
00971 return false;
00972 case Token::BIT_OR:
00973 case Token::BIT_XOR:
00974 case Token::BIT_AND:
00975 case Token::SHL:
00976 case Token::SAR:
00977 case Token::SHR:
00978 case Token::ADD:
00979 case Token::SUB:
00980 case Token::MUL:
00981 case Token::DIV:
00982 case Token::MOD:
00983 return true;
00984 default:
00985 UNREACHABLE();
00986 }
00987 return false;
00988 }
00989
00990 Token::Value op() const { return op_; }
00991 Expression* left() const { return left_; }
00992 Expression* right() const { return right_; }
00993
00994 private:
00995 Token::Value op_;
00996 Expression* left_;
00997 Expression* right_;
00998 };
00999
01000
01001 class CountOperation: public Expression {
01002 public:
01003 CountOperation(bool is_prefix, Token::Value op, Expression* expression)
01004 : is_prefix_(is_prefix), op_(op), expression_(expression) {
01005 ASSERT(Token::IsCountOp(op));
01006 }
01007
01008 virtual void Accept(Visitor* v);
01009
01010 bool is_prefix() const { return is_prefix_; }
01011 bool is_postfix() const { return !is_prefix_; }
01012 Token::Value op() const { return op_; }
01013 Expression* expression() const { return expression_; }
01014
01015 virtual void MarkAsStatement() { is_prefix_ = true; }
01016
01017 private:
01018 bool is_prefix_;
01019 Token::Value op_;
01020 Expression* expression_;
01021 };
01022
01023
01024 class CompareOperation: public Expression {
01025 public:
01026 CompareOperation(Token::Value op, Expression* left, Expression* right)
01027 : op_(op), left_(left), right_(right) {
01028 ASSERT(Token::IsCompareOp(op));
01029 }
01030
01031 virtual void Accept(Visitor* v);
01032
01033 Token::Value op() const { return op_; }
01034 Expression* left() const { return left_; }
01035 Expression* right() const { return right_; }
01036
01037 private:
01038 Token::Value op_;
01039 Expression* left_;
01040 Expression* right_;
01041 };
01042
01043
01044 class Conditional: public Expression {
01045 public:
01046 Conditional(Expression* condition,
01047 Expression* then_expression,
01048 Expression* else_expression)
01049 : condition_(condition),
01050 then_expression_(then_expression),
01051 else_expression_(else_expression) { }
01052
01053 virtual void Accept(Visitor* v);
01054
01055 Expression* condition() const { return condition_; }
01056 Expression* then_expression() const { return then_expression_; }
01057 Expression* else_expression() const { return else_expression_; }
01058
01059 private:
01060 Expression* condition_;
01061 Expression* then_expression_;
01062 Expression* else_expression_;
01063 };
01064
01065
01066 class Assignment: public Expression {
01067 public:
01068 Assignment(Token::Value op, Expression* target, Expression* value, int pos)
01069 : op_(op), target_(target), value_(value), pos_(pos) {
01070 ASSERT(Token::IsAssignmentOp(op));
01071 }
01072
01073 virtual void Accept(Visitor* v);
01074 virtual Assignment* AsAssignment() { return this; }
01075
01076 Token::Value binary_op() const;
01077
01078 Token::Value op() const { return op_; }
01079 Expression* target() const { return target_; }
01080 Expression* value() const { return value_; }
01081 int position() { return pos_; }
01082
01083 private:
01084 Token::Value op_;
01085 Expression* target_;
01086 Expression* value_;
01087 int pos_;
01088 };
01089
01090
01091 class Throw: public Expression {
01092 public:
01093 Throw(Expression* exception, int pos)
01094 : exception_(exception), pos_(pos) {}
01095
01096 virtual void Accept(Visitor* v);
01097 Expression* exception() const { return exception_; }
01098 int position() const { return pos_; }
01099
01100 private:
01101 Expression* exception_;
01102 int pos_;
01103 };
01104
01105
01106 class FunctionLiteral: public Expression {
01107 public:
01108 FunctionLiteral(Handle<String> name,
01109 Scope* scope,
01110 ZoneList<Statement*>* body,
01111 int materialized_literal_count,
01112 bool contains_array_literal,
01113 int expected_property_count,
01114 int num_parameters,
01115 int start_position,
01116 int end_position,
01117 bool is_expression)
01118 : name_(name),
01119 scope_(scope),
01120 body_(body),
01121 materialized_literal_count_(materialized_literal_count),
01122 contains_array_literal_(contains_array_literal),
01123 expected_property_count_(expected_property_count),
01124 num_parameters_(num_parameters),
01125 start_position_(start_position),
01126 end_position_(end_position),
01127 is_expression_(is_expression),
01128 function_token_position_(RelocInfo::kNoPosition) {
01129 }
01130
01131 virtual void Accept(Visitor* v);
01132
01133
01134 virtual FunctionLiteral* AsFunctionLiteral() { return this; }
01135
01136 Handle<String> name() const { return name_; }
01137 Scope* scope() const { return scope_; }
01138 ZoneList<Statement*>* body() const { return body_; }
01139 void set_function_token_position(int pos) { function_token_position_ = pos; }
01140 int function_token_position() const { return function_token_position_; }
01141 int start_position() const { return start_position_; }
01142 int end_position() const { return end_position_; }
01143 bool is_expression() const { return is_expression_; }
01144
01145 int materialized_literal_count() { return materialized_literal_count_; }
01146 bool contains_array_literal() { return contains_array_literal_; }
01147 int expected_property_count() { return expected_property_count_; }
01148 int num_parameters() { return num_parameters_; }
01149
01150 bool AllowsLazyCompilation();
01151
01152 private:
01153 Handle<String> name_;
01154 Scope* scope_;
01155 ZoneList<Statement*>* body_;
01156 int materialized_literal_count_;
01157 bool contains_array_literal_;
01158 int expected_property_count_;
01159 int num_parameters_;
01160 int start_position_;
01161 int end_position_;
01162 bool is_expression_;
01163 int function_token_position_;
01164 };
01165
01166
01167 class FunctionBoilerplateLiteral: public Expression {
01168 public:
01169 explicit FunctionBoilerplateLiteral(Handle<JSFunction> boilerplate)
01170 : boilerplate_(boilerplate) {
01171 ASSERT(boilerplate->IsBoilerplate());
01172 }
01173
01174 Handle<JSFunction> boilerplate() const { return boilerplate_; }
01175
01176 virtual void Accept(Visitor* v);
01177
01178 private:
01179 Handle<JSFunction> boilerplate_;
01180 };
01181
01182
01183 class ThisFunction: public Expression {
01184 public:
01185 virtual void Accept(Visitor* v);
01186 };
01187
01188
01189
01190
01191
01192
01193 class Visitor BASE_EMBEDDED {
01194 public:
01195 Visitor() : stack_overflow_(false) { }
01196 virtual ~Visitor() { }
01197
01198
01199 void Visit(Node* node) { node->Accept(this); }
01200
01201
01202 virtual void VisitStatements(ZoneList<Statement*>* statements);
01203 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
01204
01205
01206 bool HasStackOverflow() const { return stack_overflow_; }
01207 bool CheckStackOverflow() {
01208 if (stack_overflow_) return true;
01209 StackLimitCheck check;
01210 if (!check.HasOverflowed()) return false;
01211 return (stack_overflow_ = true);
01212 }
01213
01214
01215
01216
01217 void SetStackOverflow() { stack_overflow_ = true; }
01218
01219
01220
01221 #define DEF_VISIT(type) \
01222 virtual void Visit##type(type* node) = 0;
01223 NODE_LIST(DEF_VISIT)
01224 #undef DEF_VISIT
01225
01226 private:
01227 bool stack_overflow_;
01228 };
01229
01230
01231 } }
01232
01233 #endif // V8_AST_H_