source: src/SynTree/Statement.h @ 8217e8f

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 8217e8f was 65cdc1e, checked in by Andrew Beach <ajbeach@…>, 7 years ago

Syntax Nodes give public access to the fields with effective public access.X

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