source: src/SynTree/Statement.h @ b10c621c

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 b10c621c was 50377a4, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Refactor tree print code to use Indenter

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