00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef FALCON_SYNTREE_H
00017 #define FALCON_SYNTREE_H
00018
00019 #include <falcon/setup.h>
00020 #include <falcon/symbol.h>
00021 #include <falcon/symtab.h>
00022 #include <falcon/error.h>
00023 #include <falcon/string.h>
00024 #include <falcon/ltree.h>
00025 #include <falcon/symlist.h>
00026 #include <falcon/basealloc.h>
00027
00028 namespace Falcon
00029 {
00030
00031 class Value;
00032 class Expression;
00033 class Compiler;
00034
00039 class FALCON_DYN_CLASS ArrayDecl: public List
00040 {
00041 public:
00042 ArrayDecl();
00043 ArrayDecl( const ArrayDecl &other );
00044
00045
00046 ArrayDecl *clone() const { return new ArrayDecl( *this ); }
00047 };
00048
00049 class FALCON_DYN_CLASS DictDecl: public List
00050 {
00051
00052 public:
00053 typedef struct t_pair {
00054 Value *first;
00055 Value *second;
00056 } pair;
00057
00058 DictDecl();
00059 DictDecl( const DictDecl &other );
00060
00061 void pushBack( Value *first, Value *second );
00062 DictDecl *clone() const { return new DictDecl( *this ); }
00063 };
00064
00065
00066 class FALCON_DYN_CLASS RangeDecl: public BaseAlloc
00067 {
00068 Value *m_rstart;
00069 Value *m_rend;
00070 Value *m_step;
00071
00072 public:
00073 RangeDecl( Value *start, Value *end = 0, Value *step = 0 ):
00074 m_rstart( start ),
00075 m_rend( end ),
00076 m_step( step )
00077 {}
00078
00079 RangeDecl( const RangeDecl &other );
00080
00081 ~RangeDecl();
00082
00083 bool isOpen() const { return m_rend == 0; }
00084 Value *rangeStart() const { return m_rstart; }
00085 Value *rangeEnd() const { return m_rend; }
00086 Value *rangeStep() const { return m_step; }
00087 RangeDecl *clone() const { return new RangeDecl( *this ); }
00088 };
00089
00090
00091
00092
00093 class FALCON_DYN_CLASS Value: public BaseAlloc
00094 {
00095 public:
00096 typedef enum {
00097 t_nil,
00098 t_imm_bool,
00099 t_imm_integer,
00100 t_imm_string,
00101 t_imm_num,
00102 t_symbol,
00103 t_symdef,
00104 t_self,
00105 t_lbind,
00106
00107 t_byref,
00108 t_array_decl,
00109 t_dict_decl,
00110 t_range_decl,
00111
00112 t_expression
00113 } type_t;
00114
00115 private:
00116 type_t m_type;
00117 union {
00118 bool asBool;
00119 int64 asInteger;
00120 numeric asNumeric;
00121 String *asString;
00122 Symbol *asSymbol;
00123 ArrayDecl *asArray;
00124 DictDecl *asDict;
00125 RangeDecl *asRange;
00126 Expression *asExpr;
00127 Value *asRef;
00128 } m_content;
00129
00130 public:
00131
00132 Value():
00133 m_type( t_nil )
00134 {}
00135
00136 Value( const Value &other ) {
00137 copy( other );
00138 }
00139
00140 explicit Value( bool val ):
00141 m_type( t_imm_bool )
00142 {
00143 m_content.asBool = val;
00144 }
00145
00146 explicit Value( int64 val ):
00147 m_type( t_imm_integer )
00148 {
00149 m_content.asInteger = val;
00150 }
00151
00152 explicit Value( numeric val ):
00153 m_type( t_imm_num )
00154 {
00155 m_content.asNumeric = val;
00156 }
00157
00158 Value( String *val ):
00159 m_type( t_imm_string )
00160 {
00161 m_content.asString = val;
00162 }
00163
00164 Value( Symbol *val ):
00165 m_type( t_symbol )
00166 {
00167 m_content.asSymbol = val;
00168 }
00169
00170 Value( Expression *val ):
00171 m_type( t_expression )
00172 {
00173 m_content.asExpr = val;
00174 }
00175
00176 Value( ArrayDecl *val ):
00177 m_type( t_array_decl )
00178 {
00179 m_content.asArray = val;
00180 }
00181
00182 Value( DictDecl *val ):
00183 m_type( t_dict_decl )
00184 {
00185 m_content.asDict = val;
00186 }
00187
00188 Value( RangeDecl *val ):
00189 m_type( t_range_decl )
00190 {
00191 m_content.asRange = val;
00192 }
00193
00194 Value( Value *val ):
00195 m_type( t_byref )
00196 {
00197 m_content.asRef = val;
00198 }
00199
00200 ~Value();
00201
00204 void copy( const Value &other );
00205
00207 Value *clone() const;
00208
00213 void transfer( Value &other ) {
00214 m_type = other.m_type;
00215 m_content = other.m_content;
00216 other.m_type = t_nil;
00217 }
00218
00219 type_t type() const { return m_type; }
00220
00233 VarDef *genVarDef();
00234
00235 bool isImmediate() const {
00236 return m_type == t_nil ||
00237 m_type == t_imm_bool ||
00238 m_type == t_imm_integer ||
00239 m_type == t_imm_string ||
00240 m_type == t_imm_num;
00241 }
00242
00243 bool isSimple() const {
00244 return isImmediate() ||
00245 m_type == t_symbol || m_type == t_symdef || m_type == t_lbind ||
00246 m_type == t_self;
00247 }
00248
00249 bool isTrue() const {
00250 switch( m_type ) {
00251 case t_imm_integer: return asInteger() != 0;
00252 case t_imm_num: return asNumeric() != 0.0;
00253 case t_imm_string: return asString()->size() != 0;
00254 default: return false;
00255 }
00256 }
00257
00258 bool asBool() const { return m_content.asBool; }
00259 int64 asInteger() const { return m_content.asInteger; }
00260 numeric asNumeric() const { return m_content.asNumeric; }
00261 String *asString() const { return m_content.asString; }
00262 String *asSymdef() const { return m_content.asString; }
00263 String *asLBind() const { return m_content.asString; }
00264 Symbol *asSymbol() const { return m_content.asSymbol; }
00265
00266 Value *asReference() const { return m_content.asRef; }
00267 ArrayDecl *asArray() const { return m_content.asArray; }
00268 DictDecl *asDict() const { return m_content.asDict; }
00269 RangeDecl *asRange() const { return m_content.asRange; }
00270 Expression *asExpr() const { return m_content.asExpr; }
00271
00272 void setNil() { m_type = t_nil; }
00273 void setBool( bool val ) { m_type = t_imm_bool; m_content.asBool = val; }
00274 void setInteger( int64 val ) { m_type = t_imm_integer; m_content.asInteger = val; }
00275 void setNumeric( numeric val ) { m_type = t_imm_num; m_content.asNumeric = val; }
00276 void setString( String *val ) { m_type = t_imm_string; m_content.asString = val; }
00277 void setSymdef( String *val ) { m_type = t_symdef; m_content.asString = val; }
00278 void setSymbol( Symbol *val ) { m_type = t_symbol; m_content.asSymbol = val; }
00279 void setReference( Value *val ) { m_type = t_byref; m_content.asRef = val; }
00280 void setExpr( Expression *val ) { m_type = t_expression; m_content.asExpr = val; }
00281 void setArray( ArrayDecl *val ) { m_type = t_array_decl; m_content.asArray = val; }
00282 void setDict( DictDecl *val ) { m_type = t_dict_decl; m_content.asDict = val; }
00283 void setRange( RangeDecl *val ) { m_type = t_range_decl; m_content.asRange = val; }
00284 void setSelf() { m_type = t_self; }
00285 void setLBind( String *val ) { m_type = t_lbind; m_content.asString = val; }
00286
00287 bool isNil() const { return m_type == t_nil; }
00288 bool isBool() const { return m_type == t_imm_bool; }
00289 bool isInteger() const { return m_type == t_imm_integer; }
00290 bool isNumeric() const { return m_type == t_imm_num; }
00291 bool isString() const { return m_type == t_imm_string; }
00292 bool isSymdef() const { return m_type == t_symdef; }
00293 bool isSymbol() const { return m_type == t_symbol; }
00294 bool isReference() const { return m_type == t_byref; }
00295 bool isExpr() const { return m_type == t_expression; }
00296 bool isArray() const { return m_type == t_array_decl; }
00297 bool isDict() const { return m_type == t_dict_decl; }
00298 bool isSelf() const { return m_type == t_self; }
00299 bool isRange() const { return m_type == t_range_decl; }
00300 bool isLBind() const { return m_type == t_lbind; }
00301
00302 Value &operator =( const Value &other ) {
00303 copy( other );
00304 return *this;
00305 }
00306
00315 bool less( const Value &val ) const;
00316 bool operator <( const Value &val ) const { return less( val ); }
00317
00318
00325 bool isEqualByValue( const Value &other ) const;
00326
00327 bool operator==( const Value &other ) const { return isEqualByValue( other ); }
00328 bool operator!=( const Value &other ) const { return !isEqualByValue( other ); }
00329
00330 bool operator >=( const Value &other ) const { return ! less( other ); }
00331 bool operator <=( const Value &other ) const { return less( other ) || isEqualByValue( other ); }
00332 bool operator >( const Value &other) const { return ! ( less( other ) || isEqualByValue( other ) ); }
00333 };
00334
00335
00336
00337 class FALCON_DYN_CLASS ValuePtrTraits: public VoidpTraits
00338 {
00339 public:
00340 virtual void copy( void *targetZone, const void *sourceZone ) const;
00341 virtual int compare( const void *first, const void *second ) const;
00342 virtual void destroy( void *item ) const;
00343 virtual bool owning() const;
00344 };
00345
00346 namespace traits {
00347 extern ValuePtrTraits &t_valueptr();
00348 }
00349
00350
00351 class FALCON_DYN_CLASS Expression: public BaseAlloc
00352 {
00353 public:
00354 typedef enum {
00355 t_none,
00356 t_neg,
00357 t_bin_not,
00358 t_not,
00359
00360 t_bin_and,
00361 t_bin_or,
00362 t_bin_xor,
00363 t_shift_left,
00364 t_shift_right,
00365 t_and,
00366 t_or,
00367
00368 t_plus,
00369 t_minus,
00370 t_times,
00371 t_divide,
00372 t_modulo,
00373 t_power,
00374
00375 t_pre_inc,
00376 t_post_inc,
00377 t_pre_dec,
00378 t_post_dec,
00379
00380 t_gt,
00381 t_ge,
00382 t_lt,
00383 t_le,
00384 t_eq,
00385 t_neq,
00386
00387 t_has,
00388 t_hasnt,
00389 t_in,
00390 t_notin,
00391 t_provides,
00392
00393 t_iif,
00394 t_lambda,
00395
00396 t_obj_access,
00397 t_funcall,
00398 t_inherit,
00399 t_array_access,
00400 t_array_byte_access,
00401 t_strexpand,
00402 t_indirect,
00403
00404 t_assign,
00405 t_fbind,
00406
00407 t_aadd,
00408 t_asub,
00409 t_amul,
00410 t_adiv,
00411 t_amod,
00412 t_apow,
00413 t_aband,
00414 t_abor,
00415 t_abxor,
00416 t_ashl,
00417 t_ashr,
00418
00419 t_eval,
00420 t_deoob,
00421 t_oob,
00422 t_xoroob,
00423 t_isoob,
00424
00426 t_optimized
00427 } operator_t;
00428
00429 private:
00430 operator_t m_operator;
00431 Value *m_first;
00432 Value *m_second;
00433 Value *m_third;
00434
00435 public:
00436 Expression( operator_t t, Value *first, Value *second = 0, Value *third = 0 ):
00437 m_operator( t ),
00438 m_first( first ),
00439 m_second( second ),
00440 m_third( third )
00441 {}
00442
00443 Expression( const Expression &other );
00444 ~Expression();
00445
00446 operator_t type() const { return m_operator; }
00447 Value *first() const { return m_first; }
00448 void first( Value *f ) { delete m_first; m_first= f; }
00449
00450 Value *second() const { return m_second; }
00451 void second( Value *s ) { delete m_second; m_second = s; }
00452
00453 Value *third() const { return m_third; }
00454 void third( Value *t ) { delete m_third; m_third = t; }
00455
00456 bool isStandAlone() const;
00457
00458 bool isBinaryOperator() const
00459 {
00460 switch( m_operator )
00461 {
00462 case t_bin_and:
00463 case t_bin_or:
00464 case t_bin_xor:
00465 case t_shift_left:
00466 case t_shift_right:
00467 case t_and:
00468 case t_or:
00469
00470 case t_plus:
00471 case t_minus:
00472 case t_times:
00473 case t_divide:
00474 case t_modulo:
00475 case t_power:
00476
00477 case t_gt:
00478 case t_ge:
00479 case t_lt:
00480 case t_le:
00481 case t_eq:
00482 case t_neq:
00483
00484 case t_has:
00485 case t_hasnt:
00486 case t_in:
00487 case t_notin:
00488 case t_provides:
00489 return true;
00490
00491 default:
00492 return false;
00493 }
00494
00495 }
00496 };
00497
00498
00499
00500
00501
00502
00503 class FALCON_DYN_CLASS Statement: public SLElement
00504 {
00505 public:
00506 typedef enum {
00507 t_none,
00508 t_break,
00509 t_continue,
00510 t_launch,
00511 t_autoexp,
00512 t_return,
00513 t_attributes,
00514 t_raise,
00515 t_give,
00516 t_unref,
00517 t_if,
00518 t_elif,
00519 t_while,
00520 t_loop,
00521 t_forin,
00522 t_try,
00523 t_catch,
00524 t_switch,
00525 t_select,
00526 t_case,
00527 t_module,
00528 t_global,
00529
00530 t_class,
00531 t_function,
00532 t_propdef,
00533 t_fordot,
00534 t_self_print
00535
00536 } type_t;
00537
00538 protected:
00539 type_t m_type;
00540 uint32 m_line;
00541
00542 Statement( type_t t ):
00543 m_type(t),
00544 m_line(0)
00545 {}
00546
00547 Statement( int32 l, type_t t ):
00548 m_type(t),
00549 m_line(l)
00550 {}
00551
00552 public:
00553 Statement( const Statement &other );
00554 virtual ~Statement() {};
00555
00556 type_t type() const { return m_type; }
00557 uint32 line() const { return m_line; }
00558 void line( uint32 l ) { m_line = l; }
00559 virtual Statement *clone() const =0;
00560 };
00561
00562
00564 class FALCON_DYN_CLASS StatementList: public StrongList
00565 {
00566 public:
00567 StatementList() {}
00568 StatementList( const StatementList &other );
00569 ~StatementList();
00570
00571 Statement *front() const { return static_cast< Statement *>( StrongList::front() ); }
00572 Statement *back() const { return static_cast< Statement *>( StrongList::back() ); }
00573 Statement *pop_front() { return static_cast< Statement *>( StrongList::pop_front() ); }
00574 Statement *pop_back() { return static_cast< Statement *>( StrongList::pop_back() ); }
00575
00576 };
00577
00578 class FALCON_DYN_CLASS StmtNone: public Statement
00579 {
00580 public:
00581 StmtNone( int32 l ):
00582 Statement( l, t_none )
00583 {}
00584
00585 StmtNone( const StmtNone &other ):
00586 Statement( other )
00587 {}
00588
00589 Statement *clone() const;
00590 };
00591
00592
00593 class FALCON_DYN_CLASS StmtGlobal: public Statement
00594 {
00595 SymbolList m_symbols;
00596
00597 public:
00598 StmtGlobal(int line):
00599 Statement( line, t_global)
00600 {}
00601
00602 StmtGlobal( const StmtGlobal &other );
00603
00604 void addSymbol( Symbol *sym ) { m_symbols.pushBack( sym ); }
00605 SymbolList &getSymbols() { return m_symbols; }
00606 const SymbolList &getSymbols() const { return m_symbols; }
00607
00608 virtual Statement *clone() const;
00609 };
00610
00611
00612 class FALCON_DYN_CLASS StmtUnref: public Statement
00613 {
00614 Value *m_symbol;
00615
00616 public:
00617 StmtUnref( int line, Value *sym ):
00618 Statement( line, t_unref ),
00619 m_symbol( sym )
00620 {}
00621
00622 StmtUnref( const StmtUnref &other );
00623
00624 ~StmtUnref();
00625
00626 Value *symbol() const { return m_symbol; }
00627 virtual Statement *clone() const;
00628 };
00629
00630 class FALCON_DYN_CLASS StmtSelfPrint: public Statement
00631 {
00632 ArrayDecl *m_toPrint;
00633
00634 public:
00635 StmtSelfPrint( uint32 line, ArrayDecl *toPrint ):
00636 Statement( line, t_self_print ),
00637 m_toPrint( toPrint )
00638 {}
00639
00640 StmtSelfPrint( const StmtSelfPrint &other );
00641
00642 ~StmtSelfPrint();
00643
00644 virtual Statement *clone() const;
00645
00646 ArrayDecl *toPrint() const { return m_toPrint; }
00647 };
00648
00649
00650 class FALCON_DYN_CLASS StmtExpression: public Statement
00651 {
00652 Value *m_expr;
00653
00654 public:
00655 StmtExpression( uint32 line, type_t t, Value *exp ):
00656 Statement( line, t ),
00657 m_expr( exp )
00658 {}
00659
00660 StmtExpression( const StmtExpression &other );
00661
00662 virtual ~StmtExpression();
00663
00664 Value *value() const { return m_expr; }
00665 virtual Statement *clone() const;
00666 };
00667
00668 class FALCON_DYN_CLASS StmtFordot: public StmtExpression
00669 {
00670 public:
00671 StmtFordot( uint32 line, Value *exp ):
00672 StmtExpression( line, t_fordot, exp )
00673 {}
00674
00675 StmtFordot( const StmtFordot &other );
00676
00677 virtual Statement *clone() const;
00678 };
00679
00680 class FALCON_DYN_CLASS StmtAutoexpr: public StmtExpression
00681 {
00682 public:
00683 StmtAutoexpr( uint32 line, Value *exp ):
00684 StmtExpression( line, t_autoexp, exp )
00685 {}
00686
00687 StmtAutoexpr( const StmtAutoexpr &other );
00688
00689 virtual Statement *clone() const;
00690 };
00691
00692
00693 class FALCON_DYN_CLASS StmtReturn: public StmtExpression
00694 {
00695 public:
00696 StmtReturn( uint32 line, Value *exp ):
00697 StmtExpression( line, t_return, exp )
00698 {}
00699
00700 StmtReturn( const StmtReturn &other ):
00701 StmtExpression( other )
00702 {}
00703
00704 virtual Statement *clone() const;
00705 };
00706
00707
00708 class FALCON_DYN_CLASS StmtLaunch: public StmtExpression
00709 {
00710 public:
00711 StmtLaunch( uint32 line, Value *exp ):
00712 StmtExpression( line, t_launch, exp )
00713 {}
00714
00715 StmtLaunch( const StmtLaunch &other ):
00716 StmtExpression( other )
00717 {}
00718
00719 virtual Statement *clone() const;
00720 };
00721
00722
00723 class FALCON_DYN_CLASS StmtRaise: public StmtExpression
00724 {
00725 public:
00726 StmtRaise( uint32 line, Value *exp ):
00727 StmtExpression( line, t_raise, exp )
00728 {}
00729
00730 StmtRaise( const StmtRaise &other ):
00731 StmtExpression( other )
00732 {}
00733
00734 virtual Statement *clone() const;
00735 };
00736
00737
00738 class FALCON_DYN_CLASS StmtGive: public Statement
00739 {
00740 ArrayDecl *m_objects;
00741 ArrayDecl *m_attribs;
00742
00743 public:
00744 StmtGive( uint32 line, ArrayDecl *objects, ArrayDecl *attribs ):
00745 Statement( line, t_give ),
00746 m_objects( objects ),
00747 m_attribs( attribs )
00748 {}
00749
00750 StmtGive( const StmtGive &other );
00751
00752 virtual ~StmtGive();
00753
00754 ArrayDecl *objects() const { return m_objects; }
00755 ArrayDecl *attributes() const { return m_attribs; }
00756
00757 virtual Statement *clone() const;
00758 };
00759
00760
00762 class FALCON_DYN_CLASS StmtLoopCtl: public Statement
00763 {
00764
00765 public:
00766 StmtLoopCtl( uint32 line, type_t t ):
00767 Statement( line, t )
00768 {}
00769
00770 StmtLoopCtl( const StmtLoopCtl &other );
00771
00772
00773 };
00774
00775 class FALCON_DYN_CLASS StmtBreak: public StmtLoopCtl
00776 {
00777
00778 public:
00779 StmtBreak( uint32 line ):
00780 StmtLoopCtl( line, t_break )
00781 {}
00782
00783 StmtBreak( const StmtBreak &other ):
00784 StmtLoopCtl( other )
00785 {}
00786
00787 virtual Statement *clone() const;
00788 };
00789
00790 class FALCON_DYN_CLASS StmtContinue: public StmtLoopCtl
00791 {
00792 bool m_dropping;
00793
00794 public:
00795 StmtContinue( uint32 line, bool dropping = false ):
00796 StmtLoopCtl( line, t_continue ),
00797 m_dropping( dropping )
00798 {}
00799
00800 StmtContinue( const StmtContinue &other ):
00801 StmtLoopCtl( other )
00802 {}
00803
00804 bool dropping() const { return m_dropping; }
00805 virtual Statement *clone() const;
00806 };
00807
00808
00809 class FALCON_DYN_CLASS StmtBlock: public Statement
00810 {
00811 StatementList m_list;
00812
00813 public:
00814 StmtBlock( uint32 line, type_t t ):
00815 Statement( line, t )
00816 {}
00817
00818 StmtBlock( const StmtBlock &other );
00819
00820 const StatementList &children() const { return m_list; }
00821 StatementList &children() { return m_list; }
00822
00823
00824 };
00825
00826
00827 class FALCON_DYN_CLASS StmtConditional: public StmtBlock
00828 {
00829 protected:
00830 Value *m_condition;
00831
00832 public:
00833 StmtConditional( uint32 line, type_t t, Value *cond ):
00834 StmtBlock( line, t ),
00835 m_condition( cond )
00836 {}
00837
00838 StmtConditional( const StmtConditional &other );
00839
00840 virtual ~StmtConditional();
00841
00842 Value *condition() const { return m_condition; }
00843
00844
00845 };
00846
00847 class FALCON_DYN_CLASS StmtLoop: public StmtConditional
00848 {
00849 public:
00850 StmtLoop( uint32 line, Value *cond = 0):
00851 StmtConditional( line, t_loop, cond )
00852 {}
00853
00854 StmtLoop( const StmtLoop &other ):
00855 StmtConditional( other )
00856 {}
00857
00858 virtual Statement *clone() const;
00859
00860 void setCondition( Value *cond ) { m_condition = cond; }
00861 };
00862
00863
00864 class FALCON_DYN_CLASS StmtWhile: public StmtConditional
00865 {
00866 public:
00867 StmtWhile( uint32 line, Value *cond ):
00868 StmtConditional( line, t_while, cond )
00869 {}
00870
00871 StmtWhile( const StmtWhile &other ):
00872 StmtConditional( other )
00873 {}
00874
00875 virtual Statement *clone() const;
00876 };
00877
00878
00879 class FALCON_DYN_CLASS StmtElif: public StmtConditional
00880 {
00881 public:
00882 StmtElif( uint32 line, Value *cond ):
00883 StmtConditional( line, t_elif, cond )
00884 {}
00885
00886 StmtElif( const StmtElif &other ):
00887 StmtConditional( other )
00888 {}
00889
00890 virtual Statement *clone() const;
00891 };
00892
00893
00894 class FALCON_DYN_CLASS StmtIf: public StmtConditional
00895 {
00896 StatementList m_else;
00897 StatementList m_elseifs;
00898
00899 public:
00900 StmtIf( uint32 line, Value *cond ):
00901 StmtConditional( line, t_if, cond )
00902 {}
00903
00904 StmtIf( const StmtIf &other );
00905
00906 const StatementList &elseChildren() const { return m_else; }
00907 StatementList &elseChildren() { return m_else; }
00908 const StatementList &elifChildren() const { return m_elseifs; }
00909 StatementList &elifChildren() { return m_elseifs; }
00910
00911 virtual Statement *clone() const;
00912 };
00913
00914
00915 class FALCON_DYN_CLASS StmtForin: public StmtBlock
00916 {
00917 StatementList m_first;
00918 StatementList m_last;
00919 StatementList m_middle;
00920
00921 Value *m_source;
00922 ArrayDecl *m_dest;
00923
00924 public:
00925 StmtForin( uint32 line, ArrayDecl *dest, Value *source ):
00926 StmtBlock( line, t_forin ),
00927 m_source( source ),
00928 m_dest( dest )
00929 {}
00930
00931 StmtForin( const StmtForin &other );
00932
00933 virtual ~StmtForin();
00934
00935 const StatementList &firstBlock() const { return m_first; }
00936 StatementList &firstBlock() { return m_first; }
00937 const StatementList &lastBlock() const { return m_last; }
00938 StatementList &lastBlock() { return m_last; }
00939 const StatementList &middleBlock() const { return m_middle; }
00940 StatementList &middleBlock() { return m_middle; }
00941
00942 Value *source() const { return m_source; }
00943 ArrayDecl *dest() const { return m_dest; }
00944
00945 virtual Statement *clone() const;
00946 };
00947
00948
00949 class FALCON_DYN_CLASS StmtCaseBlock: public StmtBlock
00950 {
00951 public:
00952 StmtCaseBlock( uint32 line ):
00953 StmtBlock( line, t_case )
00954 {}
00955
00956 StmtCaseBlock( const StmtCaseBlock &other ):
00957 StmtBlock( other )
00958 {}
00959
00960 virtual Statement *clone() const;
00961 };
00962
00963
00967 class FALCON_DYN_CLASS StmtSwitch: public Statement
00968 {
00972 Map m_cases_int;
00973 Map m_cases_rng;
00974 Map m_cases_str;
00975 Map m_cases_obj;
00977 List m_obj_list;
00978
00979 StatementList m_blocks;
00980 StatementList m_defaultBlock;
00981
00982 int32 m_nilBlock;
00983
00984 Value *m_cfr;
00985
00986 public:
00987 StmtSwitch( uint32 line, Value *expr );
00988
00989 StmtSwitch( const StmtSwitch &other );
00990
00991 virtual ~StmtSwitch();
00992
00993 const Map &intCases() const { return m_cases_int; }
00994 const Map &rngCases() const { return m_cases_rng; }
00995 const Map &strCases() const { return m_cases_str; }
00996 const Map &objCases() const { return m_cases_obj; }
00997 const List &objList() const { return m_obj_list; }
00998 const StatementList &blocks() const { return m_blocks; }
00999
01000 void addBlock( StmtCaseBlock *sl );
01001
01002 Map &intCases() { return m_cases_int; }
01003 Map &rngCases() { return m_cases_rng; }
01004 Map &strCases() { return m_cases_str; }
01005 Map &objCases() { return m_cases_obj; }
01006 List &objList() { return m_obj_list; }
01007 StatementList &blocks() { return m_blocks; }
01008
01009 int32 nilBlock() const { return m_nilBlock; }
01010 void nilBlock( int32 v ) { m_nilBlock = v; }
01011
01012 const StatementList &defaultBlock() const { return m_defaultBlock; }
01013 StatementList &defaultBlock() { return m_defaultBlock; }
01014
01015 Value *switchItem() const { return m_cfr; }
01016
01017 bool addIntCase( Value *itm );
01018 bool addStringCase( Value *itm );
01019 bool addRangeCase( Value *itm );
01020 bool addSymbolCase( Value *itm );
01021
01022 int currentBlock() const { return m_blocks.size(); }
01023
01024 virtual Statement *clone() const;
01025 };
01026
01027
01031 class FALCON_DYN_CLASS StmtSelect: public StmtSwitch
01032 {
01033 public:
01034 StmtSelect( uint32 line, Value *expr );
01035 StmtSelect( const StmtSelect &other );
01036
01037 virtual Statement *clone() const;
01038 };
01039
01040 class FALCON_DYN_CLASS StmtCatchBlock: public StmtBlock
01041 {
01042 Value *m_into;
01043
01044 public:
01045 StmtCatchBlock( uint32 line, Value *into = 0 ):
01046 StmtBlock( line, t_catch ),
01047 m_into( into )
01048 {}
01049
01050 StmtCatchBlock( const StmtCatchBlock &other );
01051
01052 ~StmtCatchBlock();
01053
01054 Value *intoValue() const { return m_into; }
01055
01056 virtual Statement *clone() const;
01057 };
01058
01059
01060 class FALCON_DYN_CLASS StmtTry: public StmtBlock
01061 {
01062 Map m_cases_int;
01063 Map m_cases_sym;
01064
01066 List m_sym_list;
01067
01069 StatementList m_handlers;
01070
01072 List m_into_values;
01073
01076 StmtCatchBlock *m_default;
01077
01078 public:
01079 StmtTry( uint32 line );
01080 StmtTry( const StmtTry &other );
01081 ~StmtTry();
01082
01083 const StmtCatchBlock *defaultHandler() const { return m_default; }
01084 StmtCatchBlock *defaultHandler() { return m_default; }
01085 void defaultHandler( StmtCatchBlock *block );
01086
01087 bool defaultGiven() const { return m_default != 0; }
01088
01089 const StatementList &handlers() const { return m_handlers; }
01090 StatementList &handlers() { return m_handlers; }
01091
01092 const Map &intCases() const { return m_cases_int; }
01093 const Map &objCases() const { return m_cases_sym; }
01094 const List &objList() const { return m_sym_list; }
01095
01096 void addHandler( StmtCatchBlock *block );
01097
01098 bool addIntCase( Value *itm );
01099 bool addSymbolCase( Value *itm );
01100
01101 int currentBlock() const { return m_handlers.size(); }
01102
01103 virtual Statement *clone() const;
01104 };
01105
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121 class FALCON_DYN_CLASS StmtCallable: public Statement
01122 {
01123 Symbol *m_name;
01124
01125 public:
01126 StmtCallable( uint32 line, type_t t, Symbol *name ):
01127 Statement( line, t ),
01128 m_name( name )
01129 {}
01130
01131 StmtCallable( const StmtCallable &other ):
01132 Statement( other ),
01133 m_name( other.m_name )
01134 {}
01135
01136 virtual ~StmtCallable();
01137
01138 Symbol *symbol() { return m_name; }
01139 const Symbol *symbol() const { return m_name; }
01140 const String &name() const { return m_name->name(); }
01141
01142
01143 };
01144
01145 class StmtFunction;
01146
01147 class FALCON_DYN_CLASS StmtClass: public StmtCallable
01148 {
01149 StmtFunction *m_ctor;
01150 bool m_initGiven;
01152 bool m_bDeleteCtor;
01153
01154 Symbol *m_singleton;
01156 ArrayDecl m_initExpressions;
01157 public:
01158
01159 StmtClass( uint32 line, Symbol *name ):
01160 StmtCallable( line, t_class, name ),
01161 m_ctor(0),
01162 m_initGiven( false ),
01163 m_bDeleteCtor( false ),
01164 m_singleton(0)
01165 {}
01166
01167 StmtClass( const StmtClass &other );
01168 virtual ~StmtClass();
01169
01178 StmtFunction *ctorFunction() const { return m_ctor; }
01179 void ctorFunction( StmtFunction *func ) { m_ctor = func; }
01180
01181 bool initGiven() const { return m_initGiven; }
01182 void initGiven( bool val ) { m_initGiven = val; }
01183
01184 void addInitExpression( Value *expr ) { m_initExpressions.pushBack( expr ); }
01185 const ArrayDecl& initExpressions() const { return m_initExpressions; }
01186 ArrayDecl& initExpressions() { return m_initExpressions; }
01187
01189 Symbol *singleton() const { return m_singleton; }
01190 void singleton( Symbol *s ) { m_singleton = s; }
01191 virtual Statement *clone() const;
01192 };
01193
01194 class FALCON_DYN_CLASS StmtFunction: public StmtCallable
01195 {
01196
01197 private:
01198 int m_lambda_id;
01199 StatementList m_staticBlock;
01200 StatementList m_statements;
01201 const StmtClass *m_ctor_for;
01202
01203 public:
01204
01205 StmtFunction( uint32 line, Symbol *name ):
01206 StmtCallable( line, t_function, name ),
01207 m_lambda_id(0),
01208 m_ctor_for(0)
01209 {}
01210
01211 StmtFunction( const StmtFunction &other );
01212
01213 StatementList &statements() { return m_statements; }
01214 const StatementList &statements() const { return m_statements; }
01215
01216 StatementList &staticBlock() { return m_staticBlock; }
01217 const StatementList &staticBlock() const { return m_staticBlock; }
01218
01219 bool hasStatic() const { return !m_staticBlock.empty(); }
01220
01221 void setLambda( int id ) { m_lambda_id = id; }
01222 int lambdaId() const { return m_lambda_id; }
01223 bool isLambda() const { return m_lambda_id != 0; }
01224
01225 void setConstructorFor( const StmtClass *cd ) { m_ctor_for = cd; }
01226 const StmtClass *constructorFor() const { return m_ctor_for; }
01227
01228 virtual Statement *clone() const;
01229 };
01230
01231 class FALCON_DYN_CLASS StmtVarDef: public Statement
01232 {
01233 String *m_name;
01234 Value *m_value;
01235
01236 public:
01237
01238 StmtVarDef( uint32 line, String *name, Value *value ):
01239 Statement( line, t_propdef ),
01240 m_name( name ),
01241 m_value( value )
01242 {}
01243
01244 StmtVarDef( const StmtVarDef &other );
01245 virtual ~StmtVarDef();
01246
01247 String *name() const { return m_name; }
01248 Value *value() const { return m_value; }
01249
01250 virtual Statement *clone() const;
01251 };
01252
01259 class FALCON_DYN_CLASS SourceTree: public BaseAlloc
01260 {
01261 StatementList m_statements;
01262 StatementList m_functions;
01263 StatementList m_classes;
01264
01265 bool m_exportAll;
01266
01267 public:
01268
01269 SourceTree():
01270 m_exportAll( false )
01271 {}
01272
01273 SourceTree( const SourceTree &other );
01274
01275 const StatementList &statements() const { return m_statements; }
01276 StatementList &statements() { return m_statements; }
01277
01278 const StatementList &functions() const { return m_functions; }
01279 StatementList &functions() { return m_functions; }
01280
01281 const StatementList &classes() const { return m_classes; }
01282 StatementList &classes() { return m_classes; }
01283
01284 void setExportAll( bool mode = true ) { m_exportAll = mode; }
01285 bool isExportAll() const { return m_exportAll; }
01286
01287 SourceTree *clone() const;
01288 };
01289
01290
01291 }
01292
01293 #endif
01294
01295
01296