Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r8cc5cb0 r777bfcf  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 11 12:24:11 2016
    13 // Update Count     : 443
     12// Last Modified On : Sun Aug 14 16:29:20 2016
     13// Update Count     : 483
    1414//
    1515
     
    4545        virtual ~ParseNode();
    4646
    47         ParseNode *get_link() const { return next; }
     47        ParseNode *get_next() const { return next; }
     48        ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; }
    4849        ParseNode *get_last();
    49         ParseNode *set_link( ParseNode * );
    50         void set_next( ParseNode *newlink ) { next = newlink; }
     50        ParseNode *set_last( ParseNode * );
    5151
    5252        virtual ParseNode *clone() const { return 0; };
     
    9292        ExpressionNode *expr;
    9393        bool aggregate;
    94         ExpressionNode *designator; // may be list
     94        ExpressionNode *designator;                                                     // may be list
    9595        InitializerNode *kids;
    9696        bool maybeConstructed;
     
    336336
    337337        StatementNode();
    338         StatementNode( const std::string *name );
    339         StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 );
    340         StatementNode( Type t, std::string *target );
    341338        StatementNode( DeclarationNode *decl );
    342 
    343339        ~StatementNode();
    344 
    345         static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
    346 
    347         StatementNode *set_block( StatementNode *b ) { block = b; return this; }
    348         StatementNode *get_block() const { return block; }
    349 
    350         void set_control( ExpressionNode *c ) { control = c; }
    351         ExpressionNode *get_control() const { return control; }
    352340
    353341        StatementNode::Type get_type() const { return type; }
     
    357345
    358346        void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
    359         void setCatchRest( bool newVal ) { isCatchRest = newVal; }
    360 
    361         std::string get_target() const;
    362 
    363         // StatementNode *add_controlexp( ExpressionNode * );
    364         StatementNode *append_block( StatementNode * );
     347
    365348        virtual StatementNode *append_last_case( StatementNode * );
    366349
    367         void print( std::ostream &os, int indent = 0) const;
     350        virtual void print( std::ostream &os, int indent = 0) const {}
    368351        virtual StatementNode *clone() const;
    369352        virtual Statement *build() const;
    370   private:
     353  public:
    371354        static const char *StType[];
    372355        Type type;
    373         ExpressionNode *control;
    374         StatementNode *block;
    375356        std::list<std::string> labels;
    376         std::string *target;                            // target label for jump statements
    377357        DeclarationNode *decl;
    378         bool isCatchRest;
    379358}; // StatementNode
    380359
    381360class StatementNode2 : public StatementNode {
    382361  public:
    383         StatementNode2() {}
     362        StatementNode2() { stmt = nullptr; }
    384363        StatementNode2( Statement *stmt ) : stmt( stmt ) {}
     364        StatementNode2( DeclarationNode *decl );
    385365        virtual ~StatementNode2() {}
    386366
     
    392372                return this;
    393373        }
     374        virtual std::list<std::string> get_labels() const { assert( false ); return StatementNode::get_labels(); }
     375
    394376        virtual StatementNode *append_last_case( StatementNode * );
    395         virtual std::list<std::string> get_labels() const { assert( false ); return StatementNode::get_labels(); }
    396377
    397378        virtual void print( std::ostream &os, int indent = 0 ) {}
     
    401382}; // StatementNode
    402383
     384Statement *build_expr( ExpressionNode *ctl );
     385
    403386struct ForCtl {
    404387        ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) :
    405                 init( new StatementNode( StatementNode::Exp, expr ) ), condition( condition ), change( change ) {}
     388                init( new StatementNode2( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    406389        ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) :
    407                 init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
     390                init( new StatementNode2( decl ) ), condition( condition ), change( change ) {}
    408391
    409392        StatementNode *init;
     
    412395};
    413396
    414 Statement *build_expr( ExpressionNode *ctl );
    415397Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt );
    416398Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt );
     
    423405Statement *build_return( ExpressionNode *ctl );
    424406Statement *build_throw( ExpressionNode *ctl );
     407Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt );
     408Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false );
     409Statement *build_finally( StatementNode *stmt );
    425410
    426411//##############################################################################
     
    429414  public:
    430415        CompoundStmtNode();
    431         CompoundStmtNode( const std::string * );
    432416        CompoundStmtNode( StatementNode * );
    433417        ~CompoundStmtNode();
     
    445429class AsmStmtNode : public StatementNode {
    446430  public:
    447         AsmStmtNode( Type, bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 );
     431        AsmStmtNode( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 );
    448432        ~AsmStmtNode();
    449433
    450         void print( std::ostream &os, int indent = 0 ) const;
     434        void print( std::ostream &os, int indent = 0 ) const {}
    451435        Statement *build() const;
    452436  private:
     
    477461                        errors.append( e );
    478462                } // try
    479                 cur = dynamic_cast< NodeType *>( cur->get_link() );
     463                cur = dynamic_cast< NodeType *>( cur->get_next() );
    480464        } // while
    481465        if ( ! errors.isEmpty() ) {
Note: See TracChangeset for help on using the changeset viewer.