source: src/SynTree/AddStmtVisitor.cc@ 3f869f0

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox memory 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 3f869f0 was 51fcaf8d, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

introduce AddStmtVisitor which provides statement insertion in the same manner as PolyMutator

  • Property mode set to 100644
File size: 2.9 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 : Rob Schluntz
12// Last Modified On : Wed Jun 22 12:16:29 2016
13// Update Count : 11
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_branches() );
74 maybeAccept( switchStmt->get_condition(), *this );
75}
76
77void AddStmtVisitor::visit(ChooseStmt *switchStmt) {
78 visitStatementList( switchStmt->get_branches() );
79 maybeAccept( switchStmt->get_condition(), *this );
80}
81
82void AddStmtVisitor::visit(CaseStmt *caseStmt) {
83 visitStatementList( caseStmt->get_statements() );
84 maybeAccept( caseStmt->get_condition(), *this );
85}
86
87void AddStmtVisitor::visit(CatchStmt *catchStmt) {
88 catchStmt->set_body( visitStatement( catchStmt->get_body() ) );
89 maybeAccept( catchStmt->get_decl(), *this );
90}
91
92// Local Variables: //
93// tab-width: 4 //
94// mode: c++ //
95// compile-command: "make install" //
96// End: //
Note: See TracBrowser for help on using the repository browser.