source: src/SynTree/Statement.h @ 4328016

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4328016 was c8dfcd3, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

insert implicit ctor/dtors if field is unhandled in a struct ctor/dtor

  • Property mode set to 100644
File size: 14.4 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[3be261a]7// Statement.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[4e06c1e]11// Last Modified By : Peter A. Buhr
[1d4580a]12// Last Modified On : Fri Aug 12 13:57:46 2016
13// Update Count     : 65
[0dd3a2f]14//
15
[51b7345]16#ifndef STATEMENT_H
17#define STATEMENT_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22#include "Common/SemanticError.h"
[f1b1e4c]23#include "Type.h"
[0f8e4ac]24#include "Label.h"
[51b7345]25
[0dd3a2f]26class Statement {
27  public:
28        Statement( std::list<Label> labels );
29        virtual ~Statement();
[51b7345]30
[0dd3a2f]31        std::list<Label> & get_labels() { return labels; }
[de62360d]32        const std::list<Label> & get_labels() const { return labels; }
[51b7345]33
[0dd3a2f]34        virtual Statement *clone() const = 0;
35        virtual void accept( Visitor &v ) = 0;
36        virtual Statement *acceptMutator( Mutator &m ) = 0;
[de62360d]37        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]38  protected:
39        std::list<Label> labels;
[51b7345]40};
41
[0dd3a2f]42class CompoundStmt : public Statement {
43  public:
44        CompoundStmt( std::list<Label> labels );
45        CompoundStmt( const CompoundStmt &other );
46        virtual ~CompoundStmt();
[51b7345]47
[0dd3a2f]48        std::list<Statement*>& get_kids() { return kids; }
[c8dfcd3]49        void push_back( Statement * stmt ) { kids.push_back( stmt ); }
50        void push_front( Statement * stmt ) { kids.push_front( stmt ); }
[51b7345]51
[0dd3a2f]52        virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); }
53        virtual void accept( Visitor &v ) { v.visit( this ); }
54        virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]55        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]56  private:
57        std::list<Statement*> kids;
[51b7345]58};
59
[0dd3a2f]60class ExprStmt : public Statement {
61  public:
62        ExprStmt( std::list<Label> labels, Expression *expr );
[3be261a]63        ExprStmt( const ExprStmt &other );
[0dd3a2f]64        virtual ~ExprStmt();
[51b7345]65
[0dd3a2f]66        Expression *get_expr() { return expr; }
67        void set_expr( Expression *newValue ) { expr = newValue; }
[51b7345]68
[0dd3a2f]69        virtual ExprStmt *clone() const { return new ExprStmt( *this ); }
70        virtual void accept( Visitor &v ) { v.visit( this ); }
71        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]72        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]73  private:
74        Expression *expr;
75};
[51b7345]76
[7f5566b]77class AsmStmt : public Statement {
78  public:
79        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 );
[3be261a]80        AsmStmt( const AsmStmt &other );
[7f5566b]81        virtual ~AsmStmt();
82
83        bool get_voltile() { return voltile; }
84        void set_voltile( bool newValue ) { voltile = newValue; }
85        ConstantExpr *get_instruction() { return instruction; }
86        void set_instruction( ConstantExpr *newValue ) { instruction = newValue; }
87        std::list<Expression *> &get_output() { return output; }
88        void set_output( const std::list<Expression *> &newValue ) { output = newValue; }
89        std::list<Expression *> &get_input() { return input; }
90        void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
91        std::list<ConstantExpr *> &get_clobber() { return clobber; }
92        void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
93        std::list<Label> &get_gotolabels() { return gotolabels; }
94        void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
95
96        virtual AsmStmt *clone() const { return new AsmStmt( *this ); }
97        virtual void accept( Visitor &v ) { v.visit( this ); }
98        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
99        virtual void print( std::ostream &os, int indent = 0 ) const;
100  private:
101        bool voltile;
102        ConstantExpr *instruction;
103        std::list<Expression *> output, input;
104        std::list<ConstantExpr *> clobber;
105        std::list<Label> gotolabels;
106};
107
[0dd3a2f]108class IfStmt : public Statement {
109  public:
110        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
[3be261a]111        IfStmt( const IfStmt &other );
[0dd3a2f]112        virtual ~IfStmt();
113
114        Expression *get_condition() { return condition; }
115        void set_condition( Expression *newValue ) { condition = newValue; }
116        Statement *get_thenPart() { return thenPart; }
117        void set_thenPart( Statement *newValue ) { thenPart = newValue; }
118        Statement *get_elsePart() { return elsePart; }
119        void set_elsePart( Statement *newValue ) { elsePart = newValue; }
[3be261a]120
[0dd3a2f]121        virtual IfStmt *clone() const { return new IfStmt( *this ); }
122        virtual void accept( Visitor &v ) { v.visit( this ); }
123        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]124        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]125  private:
126        Expression *condition;
127        Statement *thenPart;
128        Statement *elsePart;
[51b7345]129};
130
[0dd3a2f]131class SwitchStmt : public Statement {
132  public:
[8688ce1]133        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
[3be261a]134        SwitchStmt( const SwitchStmt &other );
[0dd3a2f]135        virtual ~SwitchStmt();
[51b7345]136
[0dd3a2f]137        Expression *get_condition() { return condition; }
138        void set_condition( Expression *newValue ) { condition = newValue; }
[51b7345]139
[8688ce1]140        std::list<Statement *> & get_statements() { return statements; }
[51b7345]141
[0dd3a2f]142        virtual void accept( Visitor &v ) { v.visit( this ); }
143        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[51b7345]144
[0dd3a2f]145        virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
[de62360d]146        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]147  private:
148        Expression * condition;
[8688ce1]149        std::list<Statement *> statements;
[51b7345]150};
151
[0dd3a2f]152class CaseStmt : public Statement {
153  public:
[8688ce1]154        CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
[3be261a]155        CaseStmt( const CaseStmt &other );
[0dd3a2f]156        virtual ~CaseStmt();
157
[8688ce1]158        static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), std::list<Statement *> stmts = std::list<Statement *>() );
[b2152e7a]159
[de62360d]160        bool isDefault() const { return _isDefault; }
[0dd3a2f]161        void set_default(bool b) { _isDefault = b; }
162
163        Expression * &get_condition() { return condition; }
164        void set_condition( Expression *newValue ) { condition = newValue; }
165
166        std::list<Statement *> &get_statements() { return stmts; }
167        void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
[3be261a]168
[0dd3a2f]169        virtual void accept( Visitor &v ) { v.visit( this ); }
170        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
171
172        virtual CaseStmt *clone() const { return new CaseStmt( *this ); }
[de62360d]173        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]174  private:
175        Expression * condition;
176        std::list<Statement *> stmts;
177        bool _isDefault;
[51b7345]178};
179
[0dd3a2f]180class WhileStmt : public Statement {
181  public:
182        WhileStmt( std::list<Label> labels, Expression *condition,
183               Statement *body, bool isDoWhile = false );
[3be261a]184        WhileStmt( const WhileStmt &other );
[0dd3a2f]185        virtual ~WhileStmt();
186
187        Expression *get_condition() { return condition; }
188        void set_condition( Expression *newValue ) { condition = newValue; }
189        Statement *get_body() { return body; }
190        void set_body( Statement *newValue ) { body = newValue; }
191        bool get_isDoWhile() { return isDoWhile; }
192        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
[3be261a]193
[0dd3a2f]194        virtual WhileStmt *clone() const { return new WhileStmt( *this ); }
195        virtual void accept( Visitor &v ) { v.visit( this ); }
196        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]197        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]198  private:
199        Expression *condition;
200        Statement *body;
201        bool isDoWhile;
[51b7345]202};
203
[0dd3a2f]204class ForStmt : public Statement {
205  public:
[145f1fc]206        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
[0dd3a2f]207             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
[3be261a]208        ForStmt( const ForStmt &other );
[0dd3a2f]209        virtual ~ForStmt();
210
[145f1fc]211        std::list<Statement *> &get_initialization() { return initialization; }
212        void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
[0dd3a2f]213        Expression *get_condition() { return condition; }
214        void set_condition( Expression *newValue ) { condition = newValue; }
215        Expression *get_increment() { return increment; }
216        void set_increment( Expression *newValue ) { increment = newValue; }
217        Statement *get_body() { return body; }
218        void set_body( Statement *newValue ) { body = newValue; }
[3be261a]219
[0dd3a2f]220        virtual ForStmt *clone() const { return new ForStmt( *this ); }
221        virtual void accept( Visitor &v ) { v.visit( this ); }
222        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]223        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]224  private:
[145f1fc]225        std::list<Statement *> initialization;
[0dd3a2f]226        Expression *condition;
227        Expression *increment;
228        Statement *body;
[51b7345]229};
230
[0dd3a2f]231class BranchStmt : public Statement {
232  public:
[de62360d]233        enum Type { Goto = 0, Break, Continue };
[0dd3a2f]234
235        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
236        BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
237
[be5aa1b]238        Label get_originalTarget() { return originalTarget; }
[0dd3a2f]239        Label get_target() { return target; }
240        void set_target( Label newValue ) { target = newValue; }
[3be261a]241
[0dd3a2f]242        Expression *get_computedTarget() { return computedTarget; }
243        void set_target( Expression * newValue ) { computedTarget = newValue; }
244
245        Type get_type() { return type; }
246        const char *get_typename() { return brType[ type ]; }
247
248        virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
249        virtual void accept( Visitor &v ) { v.visit( this ); }
250        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]251        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]252  private:
253        static const char *brType[];
[be5aa1b]254        Label originalTarget;  // can give better error messages if we remember the label name that the user entered
[0dd3a2f]255        Label target;
256        Expression *computedTarget;
257        Type type;
[51b7345]258};
259
[0dd3a2f]260class ReturnStmt : public Statement {
261  public:
262        ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false );
[3be261a]263        ReturnStmt( const ReturnStmt &other );
[0dd3a2f]264        virtual ~ReturnStmt();
265
266        Expression *get_expr() { return expr; }
267        void set_expr( Expression *newValue ) { expr = newValue; }
[3be261a]268
[0dd3a2f]269        virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); }
270        virtual void accept( Visitor &v ) { v.visit( this ); }
271        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]272        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]273  private:
274        Expression *expr;
275        bool isThrow;
[51b7345]276};
277
278
[0dd3a2f]279class NullStmt : public CompoundStmt {
280  public:
281        NullStmt();
282        NullStmt( std::list<Label> labels );
[51b7345]283
[0dd3a2f]284        virtual NullStmt *clone() const { return new NullStmt( *this ); }
285        virtual void accept( Visitor &v ) { v.visit( this ); }
286        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]287        virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]288
[0dd3a2f]289  private:
[51b7345]290};
291
[3be261a]292class TryStmt : public Statement {
[0dd3a2f]293  public:
294        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 );
295        TryStmt( const TryStmt &other );
296        virtual ~TryStmt();
297
298        CompoundStmt *get_block() const { return block; }
299        void set_block( CompoundStmt *newValue ) { block = newValue; }
300        std::list<Statement *>& get_catchers() { return handlers; }
301
302        FinallyStmt *get_finally() const { return finallyBlock; }
303        void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
304
305        virtual TryStmt *clone() const { return new TryStmt( *this ); }
306        virtual void accept( Visitor &v ) { v.visit( this ); }
307        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]308        virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]309
[0dd3a2f]310  private:
311        CompoundStmt *block;
312        std::list<Statement *> handlers;
313        FinallyStmt *finallyBlock;
[3be261a]314};
[51b7345]315
[0dd3a2f]316class CatchStmt : public Statement {
317  public:
[1d4580a]318        CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool catchAny = false );
[3be261a]319        CatchStmt( const CatchStmt &other );
[0dd3a2f]320        virtual ~CatchStmt();
321
322        Declaration *get_decl() { return decl; }
323        void set_decl( Declaration *newValue ) { decl = newValue; }
324
325        Statement *get_body() { return body; }
326        void set_body( Statement *newValue ) { body = newValue; }
[3be261a]327
[0dd3a2f]328        virtual CatchStmt *clone() const { return new CatchStmt( *this ); }
329        virtual void accept( Visitor &v ) { v.visit( this ); }
330        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]331        virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]332
[0dd3a2f]333  private:
334        Declaration *decl;
335        Statement *body;
336        bool catchRest;
[51b7345]337};
338
[3be261a]339class FinallyStmt : public Statement {
[0dd3a2f]340  public:
341        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
[3be261a]342        FinallyStmt( const FinallyStmt &other );
[0dd3a2f]343        virtual ~FinallyStmt();
344
345        CompoundStmt *get_block() const { return block; }
346        void set_block( CompoundStmt *newValue ) { block = newValue; }
[3be261a]347
[0dd3a2f]348        virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); }
349        virtual void accept( Visitor &v ) { v.visit( this ); }
350        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]351        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]352  private:
353        CompoundStmt *block;
[3be261a]354};
[51b7345]355
356
357// represents a declaration that occurs as part of a compound statement
[0dd3a2f]358class DeclStmt : public Statement {
359  public:
360        DeclStmt( std::list<Label> labels, Declaration *decl );
361        DeclStmt( const DeclStmt &other );
362        virtual ~DeclStmt();
363
[f1b1e4c]364        Declaration *get_decl() const { return decl; }
[0dd3a2f]365        void set_decl( Declaration *newValue ) { decl = newValue; }
366
367        virtual DeclStmt *clone() const { return new DeclStmt( *this ); }
368        virtual void accept( Visitor &v ) { v.visit( this ); }
369        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]370        virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]371  private:
372        Declaration *decl;
[51b7345]373};
374
[f1b1e4c]375
376/// represents an implicit application of a constructor or destructor. Qualifiers are replaced
377/// immediately before and after the call so that qualified objects can be constructed
378/// with the same functions as unqualified objects.
379class ImplicitCtorDtorStmt : public Statement {
380  public:
381        ImplicitCtorDtorStmt( Statement * callStmt );
382        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
383        virtual ~ImplicitCtorDtorStmt();
384
385        Statement *get_callStmt() const { return callStmt; }
386        void set_callStmt( Statement * newValue ) { callStmt = newValue; }
387
388        virtual ImplicitCtorDtorStmt *clone() const { return new ImplicitCtorDtorStmt( *this ); }
389        virtual void accept( Visitor &v ) { v.visit( this ); }
390        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
391        virtual void print( std::ostream &os, int indent = 0 ) const;
392
393  private:
394        // Non-owned pointer to the constructor/destructor statement
395        Statement * callStmt;
396};
397
398
[3906301]399std::ostream & operator<<( std::ostream & out, const Statement * statement );
[baf7fee]400
[0dd3a2f]401#endif // STATEMENT_H
[51b7345]402
[0dd3a2f]403// Local Variables: //
404// tab-width: 4 //
405// mode: c++ //
406// compile-command: "make install" //
407// End: //
Note: See TracBrowser for help on using the repository browser.