// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // BasicInit.cc -- // // Author : Rodolfo G. Esteves // Created On : Mon May 18 07:44:20 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Tue May 19 16:30:43 2015 // Update Count : 1 // #include #include #include #include #include #include "Common/utility.h" #include "SynTree/Type.h" #include "SynTree/Statement.h" #include "SynTree/Expression.h" #include "SynTree/Declaration.h" #include "SynTree/Initializer.h" #include "BasicInit.h" #include "NameCollector.h" #include "NameAssociation.h" namespace InitTweak { CompoundStmt* BasicInit::mutate(CompoundStmt *compoundStmt) { index.visit( compoundStmt ); std::list< Statement * > &kids = compoundStmt->get_kids(); std::list< Statement * > newKids; for ( std::list< Statement * >::iterator i = kids.begin(); i!= kids.end(); i++ ) { //BasicInit newMut( ); (*i)->acceptMutator( *this ); newKids.push_back( *i ); if ( has_bindings() ) { // if ( get_bindings() != 0 ) { std::list< Statement *> newSt = get_statements(); //newSt.push_back( *i ); newKids.splice( newKids.end(), newSt ); bindings = 0; stmts.clear(); } // if } // for compoundStmt->get_kids() = newKids; return compoundStmt; } Statement * BasicInit::mutate(DeclStmt *declStmt) { declStmt->accept( index ); ObjectDecl *odecl = 0; if ( ( odecl = dynamic_cast(declStmt->get_decl()) ) != 0 ) { Initializer *init = odecl->get_init(); if ( init == 0 ) return declStmt; if ( Classify::type( odecl->get_type() ) == Classify::COMPOUND_T ) if ( Classify::initializer(init) == Classify::SINGLE_I ) throw( 0 ); // mismatch of type and initializer else { NameInCollection *col = Classify::declaration( odecl, &index ); bindings = NameAssociation< Expression *, BreakInitializer >::createNameAssoc(col); bindings->add_value( std::string(""), BreakInitializer(init) ); BasicInit::build_statements( bindings, odecl->get_name(), stmts ); } // if else if ( Classify::initializer(init) == Classify::COMPOUND_I ) throw( 0 ); // mismatch of type and initializer else { // Single inits SingleInit *sinit = dynamic_cast< SingleInit * > ( init ); assert( sinit != 0); std::list args; args.push_back( new AddressExpr( new NameExpr( odecl->get_name() )) ); // have to get address of object args.push_back( sinit->get_value() ); // replace declaration with initialization stmts.push_back(new ExprStmt(std::list