Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.h

    r65cdc1e r046e04a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug  3 14:08:00 2017
    13 // Update Count     : 69
     12// Last Modified On : Mon Jun 12 13:35:00 2017
     13// Update Count     : 67
    1414//
    1515
    16 #pragma once
     16#ifndef STATEMENT_H
     17#define STATEMENT_H
    1718
    1819#include "BaseSyntaxNode.h"
     
    2627class Statement : public BaseSyntaxNode {
    2728  public:
    28         std::list<Label> labels;
    29 
    3029        Statement( std::list<Label> labels );
    3130        virtual ~Statement();
     
    3837        virtual Statement *acceptMutator( Mutator &m ) = 0;
    3938        virtual void print( std::ostream &os, int indent = 0 ) const;
     39  protected:
     40        std::list<Label> labels;
    4041};
    4142
    4243class CompoundStmt : public Statement {
    4344  public:
    44         std::list<Statement*> kids;
    45 
    4645        CompoundStmt( std::list<Label> labels );
    4746        CompoundStmt( const CompoundStmt &other );
     
    5655        virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    5756        virtual void print( std::ostream &os, int indent = 0 ) const;
     57  private:
     58        std::list<Statement*> kids;
    5859};
    5960
     
    6768        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    6869        virtual void print( std::ostream &os, int indent = 0 ) const;
     70
     71  private:
    6972};
    7073
    7174class ExprStmt : public Statement {
    7275  public:
    73         Expression *expr;
    74 
    7576        ExprStmt( std::list<Label> labels, Expression *expr );
    7677        ExprStmt( const ExprStmt &other );
     
    8485        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    8586        virtual void print( std::ostream &os, int indent = 0 ) const;
     87  private:
     88        Expression *expr;
    8689};
    8790
    8891class AsmStmt : public Statement {
    8992  public:
    90         bool voltile;
    91         ConstantExpr *instruction;
    92         std::list<Expression *> output, input;
    93         std::list<ConstantExpr *> clobber;
    94         std::list<Label> gotolabels;
    95 
    9693        AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    9794        AsmStmt( const AsmStmt &other );
     
    115112        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    116113        virtual void print( std::ostream &os, int indent = 0 ) const;
     114  private:
     115        bool voltile;
     116        ConstantExpr *instruction;
     117        std::list<Expression *> output, input;
     118        std::list<ConstantExpr *> clobber;
     119        std::list<Label> gotolabels;
    117120};
    118121
    119122class IfStmt : public Statement {
    120123  public:
    121         Expression *condition;
    122         Statement *thenPart;
    123         Statement *elsePart;
    124 
    125124        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    126125        IfStmt( const IfStmt &other );
     
    138137        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    139138        virtual void print( std::ostream &os, int indent = 0 ) const;
     139  private:
     140        Expression *condition;
     141        Statement *thenPart;
     142        Statement *elsePart;
    140143};
    141144
    142145class SwitchStmt : public Statement {
    143146  public:
    144         Expression * condition;
    145 
    146147        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
    147148        SwitchStmt( const SwitchStmt &other );
     
    159160        virtual void print( std::ostream &os, int indent = 0 ) const;
    160161  private:
     162        Expression * condition;
    161163        std::list<Statement *> statements;
    162164};
     
    164166class CaseStmt : public Statement {
    165167  public:
    166         Expression * condition;
    167         std::list<Statement *> stmts;
    168 
    169168        CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
    170169        CaseStmt( const CaseStmt &other );
     
    188187        virtual void print( std::ostream &os, int indent = 0 ) const;
    189188  private:
     189        Expression * condition;
     190        std::list<Statement *> stmts;
    190191        bool _isDefault;
    191192};
     
    193194class WhileStmt : public Statement {
    194195  public:
    195         Expression *condition;
    196         Statement *body;
    197         bool isDoWhile;
    198 
    199196        WhileStmt( std::list<Label> labels, Expression *condition,
    200197               Statement *body, bool isDoWhile = false );
     
    213210        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    214211        virtual void print( std::ostream &os, int indent = 0 ) const;
     212  private:
     213        Expression *condition;
     214        Statement *body;
     215        bool isDoWhile;
    215216};
    216217
    217218class ForStmt : public Statement {
    218219  public:
    219         std::list<Statement *> initialization;
    220         Expression *condition;
    221         Expression *increment;
    222         Statement *body;
    223 
    224220        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    225221             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
     
    240236        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    241237        virtual void print( std::ostream &os, int indent = 0 ) const;
     238  private:
     239        std::list<Statement *> initialization;
     240        Expression *condition;
     241        Expression *increment;
     242        Statement *body;
    242243};
    243244
     
    246247        enum Type { Goto = 0, Break, Continue };
    247248
    248         // originalTarget kept for error messages.
    249         const Label originalTarget;
     249        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
     250        BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
     251
     252        Label get_originalTarget() { return originalTarget; }
     253        Label get_target() { return target; }
     254        void set_target( Label newValue ) { target = newValue; }
     255
     256        Expression *get_computedTarget() { return computedTarget; }
     257        void set_target( Expression * newValue ) { computedTarget = newValue; }
     258
     259        Type get_type() { return type; }
     260        const char *get_typename() { return brType[ type ]; }
     261
     262        virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
     263        virtual void accept( Visitor &v ) { v.visit( this ); }
     264        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     265        virtual void print( std::ostream &os, int indent = 0 ) const;
     266  private:
     267        static const char *brType[];
     268        Label originalTarget;  // can give better error messages if we remember the label name that the user entered
    250269        Label target;
    251270        Expression *computedTarget;
    252271        Type type;
    253 
    254         BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
    255         BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
    256 
    257         Label get_originalTarget() { return originalTarget; }
    258         Label get_target() { return target; }
    259         void set_target( Label newValue ) { target = newValue; }
    260 
    261         Expression *get_computedTarget() { return computedTarget; }
    262         void set_target( Expression * newValue ) { computedTarget = newValue; }
    263 
    264         Type get_type() { return type; }
    265         const char *get_typename() { return brType[ type ]; }
    266 
    267         virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
    268         virtual void accept( Visitor &v ) { v.visit( this ); }
    269         virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    270         virtual void print( std::ostream &os, int indent = 0 ) const;
    271   private:
    272         static const char *brType[];
    273272};
    274273
    275274class ReturnStmt : public Statement {
    276275  public:
    277         Expression *expr;
    278 
    279276        ReturnStmt( std::list<Label> labels, Expression *expr );
    280277        ReturnStmt( const ReturnStmt &other );
     
    288285        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    289286        virtual void print( std::ostream &os, int indent = 0 ) const;
     287  private:
     288        Expression *expr;
    290289};
    291290
     
    293292  public:
    294293        enum Kind { Terminate, Resume };
    295 
    296         const Kind kind;
    297         Expression * expr;
    298         Expression * target;
    299294
    300295        ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
     
    312307        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    313308        virtual void print( std::ostream &os, int indent = 0 ) const;
     309  private:
     310        Kind kind;
     311        Expression * expr;
     312        Expression * target;
    314313};
    315314
    316315class TryStmt : public Statement {
    317316  public:
     317        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
     318        TryStmt( const TryStmt &other );
     319        virtual ~TryStmt();
     320
     321        CompoundStmt *get_block() const { return block; }
     322        void set_block( CompoundStmt *newValue ) { block = newValue; }
     323        std::list<CatchStmt *>& get_catchers() { return handlers; }
     324
     325        FinallyStmt *get_finally() const { return finallyBlock; }
     326        void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
     327
     328        virtual TryStmt *clone() const { return new TryStmt( *this ); }
     329        virtual void accept( Visitor &v ) { v.visit( this ); }
     330        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     331        virtual void print( std::ostream &os, int indent = 0 ) const;
     332
     333  private:
    318334        CompoundStmt *block;
    319335        std::list<CatchStmt *> handlers;
    320336        FinallyStmt *finallyBlock;
    321 
    322         TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
    323         TryStmt( const TryStmt &other );
    324         virtual ~TryStmt();
    325 
    326         CompoundStmt *get_block() const { return block; }
    327         void set_block( CompoundStmt *newValue ) { block = newValue; }
    328         std::list<CatchStmt *>& get_catchers() { return handlers; }
    329 
    330         FinallyStmt *get_finally() const { return finallyBlock; }
    331         void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
    332 
    333         virtual TryStmt *clone() const { return new TryStmt( *this ); }
    334         virtual void accept( Visitor &v ) { v.visit( this ); }
    335         virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    336         virtual void print( std::ostream &os, int indent = 0 ) const;
    337337};
    338338
     
    340340  public:
    341341        enum Kind { Terminate, Resume };
    342 
    343         const Kind kind;
    344         Declaration *decl;
    345         Expression *cond;
    346         Statement *body;
    347342
    348343        CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
     
    363358        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    364359        virtual void print( std::ostream &os, int indent = 0 ) const;
     360
     361  private:
     362        Kind kind;
     363        Declaration *decl;
     364        Expression *cond;
     365        Statement *body;
    365366};
    366367
    367368class FinallyStmt : public Statement {
    368369  public:
    369         CompoundStmt *block;
    370 
    371370        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
    372371        FinallyStmt( const FinallyStmt &other );
     
    380379        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    381380        virtual void print( std::ostream &os, int indent = 0 ) const;
     381  private:
     382        CompoundStmt *block;
    382383};
    383384
     
    386387class DeclStmt : public Statement {
    387388  public:
    388         Declaration *decl;
    389 
    390389        DeclStmt( std::list<Label> labels, Declaration *decl );
    391390        DeclStmt( const DeclStmt &other );
     
    399398        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    400399        virtual void print( std::ostream &os, int indent = 0 ) const;
     400  private:
     401        Declaration *decl;
    401402};
    402403
     
    407408class ImplicitCtorDtorStmt : public Statement {
    408409  public:
    409         // Non-owned pointer to the constructor/destructor statement
    410         Statement * callStmt;
    411 
    412410        ImplicitCtorDtorStmt( Statement * callStmt );
    413411        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
     
    421419        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    422420        virtual void print( std::ostream &os, int indent = 0 ) const;
     421
     422  private:
     423        // Non-owned pointer to the constructor/destructor statement
     424        Statement * callStmt;
    423425};
    424426
    425427
    426428std::ostream & operator<<( std::ostream & out, const Statement * statement );
     429
     430#endif // STATEMENT_H
    427431
    428432// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.