source: src/SynTree/Statement.h @ cf5e5b1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since cf5e5b1 was cc32d83, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Push pragma directives through the translator

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