source: src/SynTree/Statement.h@ 38d70ab

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 38d70ab was 65cdc1e, checked in by Andrew Beach <ajbeach@…>, 8 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
RevLine 
[0dd3a2f]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//
[3be261a]7// Statement.h --
[0dd3a2f]8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
[65cdc1e]11// Last Modified By : Andrew Beach
12// Last Modified On : Thr Aug 3 14:08:00 2017
13// Update Count : 69
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b73452]17
[294647b]18#include "BaseSyntaxNode.h"
19#include "Label.h"
20#include "Mutator.h"
[51b73452]21#include "SynTree.h"
[294647b]22#include "Type.h"
[51b73452]23#include "Visitor.h"
24#include "Common/SemanticError.h"
25
[294647b]26class Statement : public BaseSyntaxNode {
[0dd3a2f]27 public:
[65cdc1e]28 std::list<Label> labels;
29
[0dd3a2f]30 Statement( std::list<Label> labels );
31 virtual ~Statement();
[51b73452]32
[0dd3a2f]33 std::list<Label> & get_labels() { return labels; }
[de62360d]34 const std::list<Label> & get_labels() const { return labels; }
[51b73452]35
[0dd3a2f]36 virtual Statement *clone() const = 0;
37 virtual void accept( Visitor &v ) = 0;
38 virtual Statement *acceptMutator( Mutator &m ) = 0;
[de62360d]39 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]40};
41
[0dd3a2f]42class CompoundStmt : public Statement {
43 public:
[65cdc1e]44 std::list<Statement*> kids;
45
[0dd3a2f]46 CompoundStmt( std::list<Label> labels );
47 CompoundStmt( const CompoundStmt &other );
48 virtual ~CompoundStmt();
[51b73452]49
[0dd3a2f]50 std::list<Statement*>& get_kids() { return kids; }
[c8dfcd3]51 void push_back( Statement * stmt ) { kids.push_back( stmt ); }
52 void push_front( Statement * stmt ) { kids.push_front( stmt ); }
[51b73452]53
[0dd3a2f]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 ); }
[de62360d]57 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]58};
59
[daf1af8]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
[0dd3a2f]71class ExprStmt : public Statement {
72 public:
[65cdc1e]73 Expression *expr;
74
[0dd3a2f]75 ExprStmt( std::list<Label> labels, Expression *expr );
[3be261a]76 ExprStmt( const ExprStmt &other );
[0dd3a2f]77 virtual ~ExprStmt();
[51b73452]78
[0dd3a2f]79 Expression *get_expr() { return expr; }
80 void set_expr( Expression *newValue ) { expr = newValue; }
[51b73452]81
[0dd3a2f]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 ); }
[de62360d]85 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]86};
[51b73452]87
[7f5566b]88class AsmStmt : public Statement {
89 public:
[65cdc1e]90 bool voltile;
91 ConstantExpr *instruction;
92 std::list<Expression *> output, input;
93 std::list<ConstantExpr *> clobber;
94 std::list<Label> gotolabels;
95
[7f5566b]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 );
[3be261a]97 AsmStmt( const AsmStmt &other );
[7f5566b]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
[0dd3a2f]119class IfStmt : public Statement {
120 public:
[65cdc1e]121 Expression *condition;
122 Statement *thenPart;
123 Statement *elsePart;
124
[0dd3a2f]125 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
[3be261a]126 IfStmt( const IfStmt &other );
[0dd3a2f]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; }
[3be261a]135
[0dd3a2f]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 ); }
[de62360d]139 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]140};
141
[0dd3a2f]142class SwitchStmt : public Statement {
143 public:
[65cdc1e]144 Expression * condition;
145
[8688ce1]146 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
[3be261a]147 SwitchStmt( const SwitchStmt &other );
[0dd3a2f]148 virtual ~SwitchStmt();
[51b73452]149
[0dd3a2f]150 Expression *get_condition() { return condition; }
151 void set_condition( Expression *newValue ) { condition = newValue; }
[51b73452]152
[8688ce1]153 std::list<Statement *> & get_statements() { return statements; }
[51b73452]154
[0dd3a2f]155 virtual void accept( Visitor &v ) { v.visit( this ); }
156 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[51b73452]157
[0dd3a2f]158 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
[de62360d]159 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]160 private:
[8688ce1]161 std::list<Statement *> statements;
[51b73452]162};
163
[0dd3a2f]164class CaseStmt : public Statement {
165 public:
[65cdc1e]166 Expression * condition;
167 std::list<Statement *> stmts;
168
[8688ce1]169 CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
[3be261a]170 CaseStmt( const CaseStmt &other );
[0dd3a2f]171 virtual ~CaseStmt();
172
[8688ce1]173 static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), std::list<Statement *> stmts = std::list<Statement *>() );
[b2152e7a]174
[de62360d]175 bool isDefault() const { return _isDefault; }
[0dd3a2f]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; }
[3be261a]183
[0dd3a2f]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 ); }
[de62360d]188 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]189 private:
190 bool _isDefault;
[51b73452]191};
192
[0dd3a2f]193class WhileStmt : public Statement {
194 public:
[65cdc1e]195 Expression *condition;
196 Statement *body;
197 bool isDoWhile;
198
[0dd3a2f]199 WhileStmt( std::list<Label> labels, Expression *condition,
200 Statement *body, bool isDoWhile = false );
[3be261a]201 WhileStmt( const WhileStmt &other );
[0dd3a2f]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; }
[3be261a]210
[0dd3a2f]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 ); }
[de62360d]214 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]215};
216
[0dd3a2f]217class ForStmt : public Statement {
218 public:
[65cdc1e]219 std::list<Statement *> initialization;
220 Expression *condition;
221 Expression *increment;
222 Statement *body;
223
[145f1fc]224 ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
[0dd3a2f]225 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
[3be261a]226 ForStmt( const ForStmt &other );
[0dd3a2f]227 virtual ~ForStmt();
228
[145f1fc]229 std::list<Statement *> &get_initialization() { return initialization; }
230 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
[0dd3a2f]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; }
[3be261a]237
[0dd3a2f]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 ); }
[de62360d]241 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]242};
243
[0dd3a2f]244class BranchStmt : public Statement {
245 public:
[de62360d]246 enum Type { Goto = 0, Break, Continue };
[0dd3a2f]247
[65cdc1e]248 // originalTarget kept for error messages.
249 const Label originalTarget;
250 Label target;
251 Expression *computedTarget;
252 Type type;
253
[0dd3a2f]254 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
255 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
256
[be5aa1b]257 Label get_originalTarget() { return originalTarget; }
[0dd3a2f]258 Label get_target() { return target; }
259 void set_target( Label newValue ) { target = newValue; }
[3be261a]260
[0dd3a2f]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 ); }
[de62360d]270 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]271 private:
272 static const char *brType[];
[51b73452]273};
274
[0dd3a2f]275class ReturnStmt : public Statement {
276 public:
[65cdc1e]277 Expression *expr;
278
[daf1af8]279 ReturnStmt( std::list<Label> labels, Expression *expr );
[3be261a]280 ReturnStmt( const ReturnStmt &other );
[0dd3a2f]281 virtual ~ReturnStmt();
282
283 Expression *get_expr() { return expr; }
284 void set_expr( Expression *newValue ) { expr = newValue; }
[3be261a]285
[0dd3a2f]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 ); }
[de62360d]289 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]290};
291
[daf1af8]292class ThrowStmt : public Statement {
[0dd3a2f]293 public:
[daf1af8]294 enum Kind { Terminate, Resume };
[51b73452]295
[65cdc1e]296 const Kind kind;
297 Expression * expr;
298 Expression * target;
299
[ca78437]300 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
[daf1af8]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 ); }
[0dd3a2f]311 virtual void accept( Visitor &v ) { v.visit( this ); }
[daf1af8]312 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]313 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]314};
315
[3be261a]316class TryStmt : public Statement {
[0dd3a2f]317 public:
[65cdc1e]318 CompoundStmt *block;
319 std::list<CatchStmt *> handlers;
320 FinallyStmt *finallyBlock;
321
[046e04a]322 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
[0dd3a2f]323 TryStmt( const TryStmt &other );
324 virtual ~TryStmt();
325
326 CompoundStmt *get_block() const { return block; }
327 void set_block( CompoundStmt *newValue ) { block = newValue; }
[046e04a]328 std::list<CatchStmt *>& get_catchers() { return handlers; }
[0dd3a2f]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 ); }
[de62360d]336 virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]337};
[51b73452]338
[0dd3a2f]339class CatchStmt : public Statement {
340 public:
[ca78437]341 enum Kind { Terminate, Resume };
342
[65cdc1e]343 const Kind kind;
344 Declaration *decl;
345 Expression *cond;
346 Statement *body;
347
[ca78437]348 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
349 Expression *cond, Statement *body );
[3be261a]350 CatchStmt( const CatchStmt &other );
[0dd3a2f]351 virtual ~CatchStmt();
352
[ca78437]353 Kind get_kind() { return kind; }
[0dd3a2f]354 Declaration *get_decl() { return decl; }
355 void set_decl( Declaration *newValue ) { decl = newValue; }
[ca78437]356 Expression *get_cond() { return cond; }
357 void set_cond( Expression *newCond ) { cond = newCond; }
[0dd3a2f]358 Statement *get_body() { return body; }
359 void set_body( Statement *newValue ) { body = newValue; }
[3be261a]360
[0dd3a2f]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 ); }
[de62360d]364 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]365};
366
[3be261a]367class FinallyStmt : public Statement {
[0dd3a2f]368 public:
[65cdc1e]369 CompoundStmt *block;
370
[0dd3a2f]371 FinallyStmt( std::list<Label> labels, CompoundStmt *block );
[3be261a]372 FinallyStmt( const FinallyStmt &other );
[0dd3a2f]373 virtual ~FinallyStmt();
374
375 CompoundStmt *get_block() const { return block; }
376 void set_block( CompoundStmt *newValue ) { block = newValue; }
[3be261a]377
[0dd3a2f]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 ); }
[de62360d]381 virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]382};
[51b73452]383
384
385// represents a declaration that occurs as part of a compound statement
[0dd3a2f]386class DeclStmt : public Statement {
387 public:
[65cdc1e]388 Declaration *decl;
389
[0dd3a2f]390 DeclStmt( std::list<Label> labels, Declaration *decl );
391 DeclStmt( const DeclStmt &other );
392 virtual ~DeclStmt();
393
[f1b1e4c]394 Declaration *get_decl() const { return decl; }
[0dd3a2f]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 ); }
[de62360d]400 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]401};
402
[f1b1e4c]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:
[65cdc1e]409 // Non-owned pointer to the constructor/destructor statement
410 Statement * callStmt;
411
[f1b1e4c]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
[3906301]426std::ostream & operator<<( std::ostream & out, const Statement * statement );
[baf7fee]427
[0dd3a2f]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.