source: src/SynTree/AddStmtVisitor.cc @ 930f69e

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 930f69e was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 3.0 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// AddStmtVisitor.cc --
8//
9// Author           : Rob Schluntz
10// Created On       : Wed Jun 22 12:11:17 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Aug  4 11:23:47 2016
13// Update Count     : 16
14//
15
16#include "AddStmtVisitor.h"
17
18#include "Common/SemanticError.h"  // for SemanticError
19#include "Declaration.h"           // for Declaration
20#include "Expression.h"            // for Expression
21#include "Statement.h"             // for CompoundStmt, ForStmt, IfStmt, Sta...
22#include "SynTree/Label.h"         // for Label, noLabels
23
24void AddStmtVisitor::visitStatementList( std::list< Statement* > &statements ) {
25        for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
26                if ( ! stmtsToAddAfter.empty() ) {
27                        statements.splice( i, stmtsToAddAfter );
28                } // if
29                (*i)->accept( *this );
30                if ( ! stmtsToAdd.empty() ) {
31                        statements.splice( i, stmtsToAdd );
32                } // if
33        } // for
34        if ( ! stmtsToAddAfter.empty() ) {
35                statements.splice( statements.end(), stmtsToAddAfter );
36        } // if
37}
38
39Statement * AddStmtVisitor::visitStatement( Statement *stmt ) {
40        maybeAccept( stmt, *this );
41        if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) {
42                CompoundStmt *compound = new CompoundStmt( noLabels );
43                compound->get_kids().splice( compound->get_kids().end(), stmtsToAdd );
44                compound->get_kids().push_back( stmt );
45                compound->get_kids().splice( compound->get_kids().end(), stmtsToAddAfter );
46                return compound;
47        } else {
48                return stmt;
49        }
50}
51
52void AddStmtVisitor::visit(CompoundStmt *compoundStmt) {
53        visitStatementList( compoundStmt->get_kids() );
54}
55
56void AddStmtVisitor::visit(IfStmt *ifStmt) {
57        ifStmt->set_thenPart( visitStatement( ifStmt->get_thenPart() ) );
58        ifStmt->set_elsePart( visitStatement( ifStmt->get_elsePart() ) );
59        maybeAccept( ifStmt->get_condition(), *this );
60}
61
62void AddStmtVisitor::visit(WhileStmt *whileStmt) {
63        whileStmt->set_body( visitStatement( whileStmt->get_body() ) );
64        maybeAccept( whileStmt->get_condition(), *this );
65}
66
67void AddStmtVisitor::visit(ForStmt *forStmt) {
68        forStmt->set_body( visitStatement( forStmt->get_body() ) );
69        acceptAll( forStmt->get_initialization(), *this );
70        maybeAccept( forStmt->get_condition(), *this );
71        maybeAccept( forStmt->get_increment(), *this );
72}
73
74void AddStmtVisitor::visit(SwitchStmt *switchStmt) {
75        visitStatementList( switchStmt->get_statements() );
76        maybeAccept( switchStmt->get_condition(), *this );
77}
78
79void AddStmtVisitor::visit(CaseStmt *caseStmt) {
80        visitStatementList( caseStmt->get_statements() );
81        maybeAccept( caseStmt->get_condition(), *this );
82}
83
84void AddStmtVisitor::visit(CatchStmt *catchStmt) {
85        catchStmt->set_body( visitStatement( catchStmt->get_body() ) );
86        maybeAccept( catchStmt->get_decl(), *this );
87}
88
89// Local Variables: //
90// tab-width: 4 //
91// mode: c++ //
92// compile-command: "make install" //
93// End: //
Note: See TracBrowser for help on using the repository browser.