source: src/SynTree/Statement.h @ c8dfcd3

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since c8dfcd3 was c8dfcd3, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

insert implicit ctor/dtors if field is unhandled in a struct ctor/dtor

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