source: src/SynTree/Statement.h @ daf1af8

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

Added a new ThrowStmt? node to the Syntax Tree.

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