source: src/SynTree/AddStmtVisitor.cc @ 8688ce1

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 8688ce1 was 8688ce1, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

move case-list management into parser

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