source: src/SynTree/Statement.h @ 264e691

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 264e691 was 35a2d47, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

formatting

  • Property mode set to 100644
File size: 18.0 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
[936e9f4]11// Last Modified By : Peter A. Buhr
[35a2d47]12// Last Modified On : Tue Mar 12 09:01:53 2019
13// Update Count     : 83
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b7345]17
[ea6332d]18#include <iosfwd>                  // for ostream
19#include <list>                    // for list
20#include <memory>                  // for allocator
[35a2d47]21#include <vector>                                  // for vector
[ea6332d]22
23#include "BaseSyntaxNode.h"        // for BaseSyntaxNode
24#include "Common/SemanticError.h"  // for SemanticError
25#include "Label.h"                 // for Label
26#include "Mutator.h"               // for Mutator
27#include "Visitor.h"               // for Visitor
28
29class CatchStmt;
30class ConstantExpr;
31class Declaration;
32class Expression;
33class FinallyStmt;
[51b7345]34
[294647b]35class Statement : public BaseSyntaxNode {
[0dd3a2f]36  public:
[65cdc1e]37        std::list<Label> labels;
38
[ba3706f]39        Statement( const std::list<Label> & labels = {} );
[0dd3a2f]40        virtual ~Statement();
[51b7345]41
[0dd3a2f]42        std::list<Label> & get_labels() { return labels; }
[de62360d]43        const std::list<Label> & get_labels() const { return labels; }
[51b7345]44
[35a2d47]45        virtual Statement * clone() const override = 0;
46        virtual void accept( Visitor & v ) override = 0;
47        virtual Statement * acceptMutator( Mutator & m ) override = 0;
48        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]49};
50
[0dd3a2f]51class CompoundStmt : public Statement {
52  public:
[65cdc1e]53        std::list<Statement*> kids;
54
[ba3706f]55        CompoundStmt();
[a2dbad10]56        CompoundStmt( std::list<Statement *> stmts );
[35a2d47]57        CompoundStmt( const CompoundStmt & other );
[0dd3a2f]58        virtual ~CompoundStmt();
[51b7345]59
[0dd3a2f]60        std::list<Statement*>& get_kids() { return kids; }
[c8dfcd3]61        void push_back( Statement * stmt ) { kids.push_back( stmt ); }
62        void push_front( Statement * stmt ) { kids.push_front( stmt ); }
[51b7345]63
[35a2d47]64        virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); }
65        virtual void accept( Visitor & v ) override { v.visit( this ); }
66        virtual CompoundStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
67        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]68};
69
[70d826cd]70class NullStmt : public Statement {
[daf1af8]71  public:
[ba3706f]72        NullStmt( const std::list<Label> & labels = {} );
[daf1af8]73
[35a2d47]74        virtual NullStmt * clone() const override { return new NullStmt( *this ); }
75        virtual void accept( Visitor & v ) override { v.visit( this ); }
76        virtual NullStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
77        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[daf1af8]78};
79
[0dd3a2f]80class ExprStmt : public Statement {
81  public:
[35a2d47]82        Expression * expr;
[65cdc1e]83
[35a2d47]84        ExprStmt( Expression * expr );
85        ExprStmt( const ExprStmt & other );
[0dd3a2f]86        virtual ~ExprStmt();
[51b7345]87
[35a2d47]88        Expression * get_expr() { return expr; }
89        void set_expr( Expression * newValue ) { expr = newValue; }
[51b7345]90
[35a2d47]91        virtual ExprStmt * clone() const override { return new ExprStmt( *this ); }
92        virtual void accept( Visitor & v ) override { v.visit( this ); }
93        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
94        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0dd3a2f]95};
[51b7345]96
[7f5566b]97class AsmStmt : public Statement {
98  public:
[65cdc1e]99        bool voltile;
[35a2d47]100        Expression * instruction;
[65cdc1e]101        std::list<Expression *> output, input;
102        std::list<ConstantExpr *> clobber;
103        std::list<Label> gotolabels;
104
[35a2d47]105        AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
106        AsmStmt( const AsmStmt & other );
[7f5566b]107        virtual ~AsmStmt();
108
109        bool get_voltile() { return voltile; }
110        void set_voltile( bool newValue ) { voltile = newValue; }
[e612146c]111        Expression * get_instruction() { return instruction; }
112        void set_instruction( Expression * newValue ) { instruction = newValue; }
113        std::list<Expression *> & get_output() { return output; }
114        void set_output( const std::list<Expression *> & newValue ) { output = newValue; }
115        std::list<Expression *> & get_input() { return input; }
[35a2d47]116        void set_input( const std::list<Expression *> & newValue ) { input = newValue; }
[e612146c]117        std::list<ConstantExpr *> & get_clobber() { return clobber; }
[35a2d47]118        void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; }
[e612146c]119        std::list<Label> & get_gotolabels() { return gotolabels; }
[35a2d47]120        void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; }
[7f5566b]121
[e612146c]122        virtual AsmStmt * clone() const { return new AsmStmt( *this ); }
123        virtual void accept( Visitor & v ) { v.visit( this ); }
124        virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
[50377a4]125        virtual void print( std::ostream & os, Indenter indent = {} ) const;
[7f5566b]126};
127
[cc32d83]128class DirectiveStmt : public Statement {
129        public:
130        std::string directive;
131
132        DirectiveStmt( const std::string & );
133        virtual ~DirectiveStmt(){}
134
135        virtual DirectiveStmt * clone() const { return new DirectiveStmt( *this ); }
136        virtual void accept( Visitor & v ) { v.visit( this ); }
137        virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
138        virtual void print( std::ostream & os, Indenter indent = {} ) const;
139};
140
[0dd3a2f]141class IfStmt : public Statement {
142  public:
[35a2d47]143        Expression * condition;
144        Statement * thenPart;
145        Statement * elsePart;
[6d49ea3]146        std::list<Statement *> initialization;
[65cdc1e]147
[35a2d47]148        IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart,
[6d49ea3]149                        std::list<Statement *> initialization = std::list<Statement *>() );
[35a2d47]150        IfStmt( const IfStmt & other );
[0dd3a2f]151        virtual ~IfStmt();
152
[35a2d47]153        std::list<Statement *> & get_initialization() { return initialization; }
154        Expression * get_condition() { return condition; }
155        void set_condition( Expression * newValue ) { condition = newValue; }
156        Statement * get_thenPart() { return thenPart; }
157        void set_thenPart( Statement * newValue ) { thenPart = newValue; }
158        Statement * get_elsePart() { return elsePart; }
159        void set_elsePart( Statement * newValue ) { elsePart = newValue; }
160
161        virtual IfStmt * clone() const override { return new IfStmt( *this ); }
162        virtual void accept( Visitor & v ) override { v.visit( this ); }
163        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
164        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]165};
166
[0dd3a2f]167class SwitchStmt : public Statement {
168  public:
[65cdc1e]169        Expression * condition;
[871cdb4]170        std::list<Statement *> statements;
[65cdc1e]171
[35a2d47]172        SwitchStmt( Expression * condition, const std::list<Statement *> & statements );
173        SwitchStmt( const SwitchStmt & other );
[0dd3a2f]174        virtual ~SwitchStmt();
[51b7345]175
[35a2d47]176        Expression * get_condition() { return condition; }
177        void set_condition( Expression * newValue ) { condition = newValue; }
[51b7345]178
[8688ce1]179        std::list<Statement *> & get_statements() { return statements; }
[51b7345]180
[35a2d47]181        virtual void accept( Visitor & v ) override { v.visit( this ); }
182        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
[51b7345]183
[35a2d47]184        virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); }
185        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[871cdb4]186
[51b7345]187};
188
[0dd3a2f]189class CaseStmt : public Statement {
190  public:
[65cdc1e]191        Expression * condition;
192        std::list<Statement *> stmts;
193
[35a2d47]194        CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException);
195        CaseStmt( const CaseStmt & other );
[0dd3a2f]196        virtual ~CaseStmt();
197
[ba3706f]198        static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );
[b2152e7a]199
[de62360d]200        bool isDefault() const { return _isDefault; }
[0dd3a2f]201        void set_default(bool b) { _isDefault = b; }
202
[35a2d47]203        Expression * & get_condition() { return condition; }
204        void set_condition( Expression * newValue ) { condition = newValue; }
[0dd3a2f]205
[35a2d47]206        std::list<Statement *> & get_statements() { return stmts; }
207        void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; }
[3be261a]208
[35a2d47]209        virtual void accept( Visitor & v ) override { v.visit( this ); }
210        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
[0dd3a2f]211
[35a2d47]212        virtual CaseStmt * clone() const override { return new CaseStmt( *this ); }
213        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0dd3a2f]214  private:
215        bool _isDefault;
[51b7345]216};
217
[0dd3a2f]218class WhileStmt : public Statement {
219  public:
[35a2d47]220        Expression * condition;
221        Statement * body;
[ee3c93d]222        std::list<Statement *> initialization;
[65cdc1e]223        bool isDoWhile;
224
[35a2d47]225        WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false );
226        WhileStmt( const WhileStmt & other );
[0dd3a2f]227        virtual ~WhileStmt();
228
[35a2d47]229        Expression * get_condition() { return condition; }
230        void set_condition( Expression * newValue ) { condition = newValue; }
231        Statement * get_body() { return body; }
232        void set_body( Statement * newValue ) { body = newValue; }
[0dd3a2f]233        bool get_isDoWhile() { return isDoWhile; }
234        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
[3be261a]235
[35a2d47]236        virtual WhileStmt * clone() const override { return new WhileStmt( *this ); }
237        virtual void accept( Visitor & v ) override { v.visit( this ); }
238        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
239        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]240};
241
[0dd3a2f]242class ForStmt : public Statement {
243  public:
[65cdc1e]244        std::list<Statement *> initialization;
[35a2d47]245        Expression * condition;
246        Expression * increment;
247        Statement * body;
[65cdc1e]248
[35a2d47]249        ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0 );
250        ForStmt( const ForStmt & other );
[0dd3a2f]251        virtual ~ForStmt();
252
[35a2d47]253        std::list<Statement *> & get_initialization() { return initialization; }
254        Expression * get_condition() { return condition; }
255        void set_condition( Expression * newValue ) { condition = newValue; }
256        Expression * get_increment() { return increment; }
257        void set_increment( Expression * newValue ) { increment = newValue; }
258        Statement * get_body() { return body; }
259        void set_body( Statement * newValue ) { body = newValue; }
260
261        virtual ForStmt * clone() const override { return new ForStmt( *this ); }
262        virtual void accept( Visitor & v ) override { v.visit( this ); }
263        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
264        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]265};
266
[0dd3a2f]267class BranchStmt : public Statement {
268  public:
[6a276a0]269        enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault };
[0dd3a2f]270
[65cdc1e]271        // originalTarget kept for error messages.
272        const Label originalTarget;
273        Label target;
[35a2d47]274        Expression * computedTarget;
[65cdc1e]275        Type type;
276
[a16764a6]277        BranchStmt( Label target, Type ) throw (SemanticErrorException);
[35a2d47]278        BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);
[0dd3a2f]279
[be5aa1b]280        Label get_originalTarget() { return originalTarget; }
[0dd3a2f]281        Label get_target() { return target; }
282        void set_target( Label newValue ) { target = newValue; }
[3be261a]283
[35a2d47]284        Expression * get_computedTarget() { return computedTarget; }
[0dd3a2f]285        void set_target( Expression * newValue ) { computedTarget = newValue; }
286
287        Type get_type() { return type; }
[35a2d47]288        const char * get_typename() { return brType[ type ]; }
[0dd3a2f]289
[35a2d47]290        virtual BranchStmt * clone() const override { return new BranchStmt( *this ); }
291        virtual void accept( Visitor & v ) override { v.visit( this ); }
292        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
293        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[0dd3a2f]294  private:
[35a2d47]295        static const char * brType[];
[51b7345]296};
297
[0dd3a2f]298class ReturnStmt : public Statement {
299  public:
[35a2d47]300        Expression * expr;
[65cdc1e]301
[35a2d47]302        ReturnStmt( Expression * expr );
303        ReturnStmt( const ReturnStmt & other );
[0dd3a2f]304        virtual ~ReturnStmt();
305
[35a2d47]306        Expression * get_expr() { return expr; }
307        void set_expr( Expression * newValue ) { expr = newValue; }
[3be261a]308
[35a2d47]309        virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); }
310        virtual void accept( Visitor & v ) override { v.visit( this ); }
311        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
312        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]313};
314
[daf1af8]315class ThrowStmt : public Statement {
[0dd3a2f]316  public:
[daf1af8]317        enum Kind { Terminate, Resume };
[51b7345]318
[65cdc1e]319        const Kind kind;
320        Expression * expr;
321        Expression * target;
322
[ba3706f]323        ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
[35a2d47]324        ThrowStmt( const ThrowStmt & other );
[daf1af8]325        virtual ~ThrowStmt();
326
327        Kind get_kind() { return kind; }
328        Expression * get_expr() { return expr; }
329        void set_expr( Expression * newExpr ) { expr = newExpr; }
330        Expression * get_target() { return target; }
331        void set_target( Expression * newTarget ) { target = newTarget; }
332
[35a2d47]333        virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); }
334        virtual void accept( Visitor & v ) override { v.visit( this ); }
335        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
336        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]337};
338
[3be261a]339class TryStmt : public Statement {
[0dd3a2f]340  public:
[871cdb4]341        CompoundStmt * block;
[65cdc1e]342        std::list<CatchStmt *> handlers;
[871cdb4]343        FinallyStmt * finallyBlock;
[65cdc1e]344
[35a2d47]345        TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0 );
346        TryStmt( const TryStmt & other );
[0dd3a2f]347        virtual ~TryStmt();
348
[35a2d47]349        CompoundStmt * get_block() const { return block; }
350        void set_block( CompoundStmt * newValue ) { block = newValue; }
[046e04a]351        std::list<CatchStmt *>& get_catchers() { return handlers; }
[0dd3a2f]352
[35a2d47]353        FinallyStmt * get_finally() const { return finallyBlock; }
354        void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; }
[0dd3a2f]355
[35a2d47]356        virtual TryStmt * clone() const override { return new TryStmt( *this ); }
357        virtual void accept( Visitor & v ) override { v.visit( this ); }
358        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
359        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[3be261a]360};
[51b7345]361
[0dd3a2f]362class CatchStmt : public Statement {
363  public:
[ca78437]364        enum Kind { Terminate, Resume };
365
[65cdc1e]366        const Kind kind;
[35a2d47]367        Declaration * decl;
368        Expression * cond;
369        Statement * body;
[65cdc1e]370
[35a2d47]371        CatchStmt( Kind kind, Declaration * decl,
372                   Expression * cond, Statement * body );
373        CatchStmt( const CatchStmt & other );
[0dd3a2f]374        virtual ~CatchStmt();
375
[ca78437]376        Kind get_kind() { return kind; }
[35a2d47]377        Declaration * get_decl() { return decl; }
378        void set_decl( Declaration * newValue ) { decl = newValue; }
379        Expression * get_cond() { return cond; }
380        void set_cond( Expression * newCond ) { cond = newCond; }
381        Statement * get_body() { return body; }
382        void set_body( Statement * newValue ) { body = newValue; }
383
384        virtual CatchStmt * clone() const override { return new CatchStmt( *this ); }
385        virtual void accept( Visitor & v ) override { v.visit( this ); }
386        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
387        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]388};
389
[3be261a]390class FinallyStmt : public Statement {
[0dd3a2f]391  public:
[35a2d47]392        CompoundStmt * block;
[65cdc1e]393
[35a2d47]394        FinallyStmt( CompoundStmt * block );
395        FinallyStmt( const FinallyStmt & other );
[0dd3a2f]396        virtual ~FinallyStmt();
397
[35a2d47]398        CompoundStmt * get_block() const { return block; }
399        void set_block( CompoundStmt * newValue ) { block = newValue; }
[3be261a]400
[35a2d47]401        virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); }
402        virtual void accept( Visitor & v ) override { v.visit( this ); }
403        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
404        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[3be261a]405};
[51b7345]406
[135b431]407class WaitForStmt : public Statement {
408  public:
409
410        struct Target {
411                Expression * function;
412                std::list<Expression * > arguments;
413        };
414
415        struct Clause {
416                Target       target;
417                Statement  * statement;
418                Expression * condition;
419        };
420
[ba3706f]421        WaitForStmt();
[135b431]422        WaitForStmt( const WaitForStmt & );
423        virtual ~WaitForStmt();
424
425        std::vector<Clause> clauses;
426
427        struct {
428                Expression * time;
429                Statement  * statement;
430                Expression * condition;
431        } timeout;
432
433        struct {
434                Statement  * statement;
435                Expression * condition;
436        } orelse;
437
[35a2d47]438        virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); }
439        virtual void accept( Visitor & v ) override { v.visit( this ); }
440        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
441        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[135b431]442
443};
444
[61255ad]445class WithStmt : public Statement {
446public:
447        std::list< Expression * > exprs;
448        Statement * stmt;
449
450        WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
451        WithStmt( const WithStmt & other );
452        virtual ~WithStmt();
453
454        virtual WithStmt * clone() const override { return new WithStmt( *this ); }
455        virtual void accept( Visitor & v ) override { v.visit( this ); }
456        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
457        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
458};
459
[51b7345]460
461// represents a declaration that occurs as part of a compound statement
[0dd3a2f]462class DeclStmt : public Statement {
463  public:
[35a2d47]464        Declaration * decl;
[65cdc1e]465
[35a2d47]466        DeclStmt( Declaration * decl );
467        DeclStmt( const DeclStmt & other );
[0dd3a2f]468        virtual ~DeclStmt();
469
[35a2d47]470        Declaration * get_decl() const { return decl; }
471        void set_decl( Declaration * newValue ) { decl = newValue; }
[0dd3a2f]472
[35a2d47]473        virtual DeclStmt * clone() const override { return new DeclStmt( *this ); }
474        virtual void accept( Visitor & v ) override { v.visit( this ); }
475        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
476        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[51b7345]477};
478
[f1b1e4c]479
[35a2d47]480/// represents an implicit application of a constructor or destructor. Qualifiers are replaced immediately before and
481/// after the call so that qualified objects can be constructed with the same functions as unqualified objects.
[f1b1e4c]482class ImplicitCtorDtorStmt : public Statement {
483  public:
[65cdc1e]484        // Non-owned pointer to the constructor/destructor statement
485        Statement * callStmt;
486
[f1b1e4c]487        ImplicitCtorDtorStmt( Statement * callStmt );
488        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
489        virtual ~ImplicitCtorDtorStmt();
490
[35a2d47]491        Statement * get_callStmt() const { return callStmt; }
[f1b1e4c]492        void set_callStmt( Statement * newValue ) { callStmt = newValue; }
493
[35a2d47]494        virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); }
495        virtual void accept( Visitor & v ) override { v.visit( this ); }
496        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
497        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
[f1b1e4c]498};
499
[0dd3a2f]500// Local Variables: //
501// tab-width: 4 //
502// mode: c++ //
503// compile-command: "make install" //
504// End: //
Note: See TracBrowser for help on using the repository browser.