source: src/SynTree/Statement.h @ ea6332d

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 ea6332d was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

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