| [51fcaf8d] | 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 | 
|---|
| [4e06c1e] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [8688ce1] | 12 | // Last Modified On : Thu Aug  4 11:23:47 2016 | 
|---|
|  | 13 | // Update Count     : 16 | 
|---|
| [51fcaf8d] | 14 | // | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include "AddStmtVisitor.h" | 
|---|
| [ea6332d] | 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 | 
|---|
| [51fcaf8d] | 23 |  | 
|---|
|  | 24 | void 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 |  | 
|---|
|  | 39 | Statement * 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 |  | 
|---|
|  | 52 | void AddStmtVisitor::visit(CompoundStmt *compoundStmt) { | 
|---|
|  | 53 | visitStatementList( compoundStmt->get_kids() ); | 
|---|
|  | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 | void 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 |  | 
|---|
|  | 62 | void AddStmtVisitor::visit(WhileStmt *whileStmt) { | 
|---|
|  | 63 | whileStmt->set_body( visitStatement( whileStmt->get_body() ) ); | 
|---|
|  | 64 | maybeAccept( whileStmt->get_condition(), *this ); | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 | void 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 |  | 
|---|
|  | 74 | void AddStmtVisitor::visit(SwitchStmt *switchStmt) { | 
|---|
| [8688ce1] | 75 | visitStatementList( switchStmt->get_statements() ); | 
|---|
| [51fcaf8d] | 76 | maybeAccept( switchStmt->get_condition(), *this ); | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | void AddStmtVisitor::visit(CaseStmt *caseStmt) { | 
|---|
|  | 80 | visitStatementList( caseStmt->get_statements() ); | 
|---|
|  | 81 | maybeAccept( caseStmt->get_condition(), *this ); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | void 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: // | 
|---|