Changes in / [f9a7cf0:6e3e0717]


Ignore:
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    rf9a7cf0 r6e3e0717  
    9999
    100100/// Mutate a node field (only clones if not equal to existing value)
    101 template<typename node_t, typename field_t, typename assn_t>
    102 const node_t * mutate_field( const node_t * node, field_t node_t::* field, assn_t && val ) {
    103         // skip mutate if equivalent
     101template<typename node_t, typename field_t>
     102const node_t * mutate_field(
     103        const node_t * node,
     104        typename std::remove_const<typename std::remove_reference<field_t>::type>::type node_t::* field,
     105        field_t&& val
     106) {
    104107        if ( node->*field == val ) return node;
    105108       
    106         // mutate and return
    107109        node_t * ret = mutate( node );
    108         ret->*field = std::forward< assn_t >( val );
    109         return ret;
    110 }
    111 
    112 /// Mutate a single index of a node field (only clones if not equal to existing value)
    113 template<typename node_t, typename coll_t, typename ind_t, typename field_t>
    114 const node_t * mutate_field_index(
    115         const node_t * node, coll_t node_t::* field, ind_t i, field_t && val
    116 ) {
    117         // skip mutate if equivalent
    118         if  ( (node->*field)[i] == val ) return node;
    119 
    120         // mutate and return
    121         node_t * ret = mutate( node );
    122         (ret->*field)[i] = std::forward< field_t >( val );
     110        ret->*field = std::forward< field_t >( val );
    123111        return ret;
    124112}
  • src/InitTweak/InitTweak.cc

    rf9a7cf0 r6e3e0717  
    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 // InitTweak.cc --
    8 //
    9 // Author           : Rob Schluntz
    10 // Created On       : Fri May 13 11:26:36 2016
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Mon Jun 10 13:30:00 2019
    13 // Update Count     : 5
    14 //
    15 
    161#include <algorithm>               // for find, all_of
    172#include <cassert>                 // for assertf, assert, strict_dynamic_cast
     
    194#include <iterator>                // for back_insert_iterator, back_inserter
    205#include <memory>                  // for __shared_ptr
    21 #include <vector>
    226
    237#include "AST/Expr.hpp"
     
    323307        }
    324308
    325         struct CallFinder_old {
    326                 CallFinder_old( const std::list< std::string > & names ) : names( names ) {}
     309        struct CallFinder {
     310                CallFinder( const std::list< std::string > & names ) : names( names ) {}
    327311
    328312                void postvisit( ApplicationExpr * appExpr ) {
     
    347331        };
    348332
    349         struct CallFinder_new final {
    350                 std::vector< ast::ptr< ast::Expr > > matches;
    351                 const std::vector< std::string > names;
    352 
    353                 CallFinder_new( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {}
    354 
    355                 void handleCallExpr( const ast::Expr * expr ) {
    356                         std::string fname = getFunctionName( expr );
    357                         if ( std::find( names.begin(), names.end(), fname ) != names.end() ) {
    358                                 matches.emplace_back( expr );
    359                         }
    360                 }
    361 
    362                 void postvisit( const ast::ApplicationExpr * expr ) { handleCallExpr( expr ); }
    363                 void postvisit( const ast::UntypedExpr *     expr ) { handleCallExpr( expr ); }
    364         };
    365 
    366333        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) {
    367                 static PassVisitor<CallFinder_old> finder( std::list< std::string >{ "?{}", "^?{}" } );
     334                static PassVisitor<CallFinder> finder( std::list< std::string >{ "?{}", "^?{}" } );
    368335                finder.pass.matches = &matches;
    369336                maybeAccept( stmt, finder );
    370         }
    371 
    372         std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ) {
    373                 ast::Pass< CallFinder_new > finder{ std::vector< std::string >{ "?{}", "^?{}" } };
    374                 maybe_accept( stmt, finder );
    375                 return std::move( finder.pass.matches );
    376337        }
    377338
     
    475436        }
    476437
    477         const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr ) {
    478                 auto appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr );
    479                 if ( ! appExpr ) return nullptr;
    480 
    481                 const ast::DeclWithType * func = getCalledFunction( appExpr->func );
    482                 assertf( func,
    483                         "getCalledFunction returned nullptr: %s", toString( appExpr->func ).c_str() );
    484                
    485                 // check for Intrinsic only -- don't want to remove all overridable ctor/dtor because
    486                 // autogenerated ctor/dtor will call all member dtors, and some members may have a
    487                 // user-defined dtor
    488                 return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr;
    489         }
    490 
    491438        namespace {
    492439                template <typename Predicate>
     
    497444                        return std::all_of( callExprs.begin(), callExprs.end(), pred);
    498445                }
    499 
    500                 template <typename Predicate>
    501                 bool allofCtorDtor( const ast::Stmt * stmt, const Predicate & pred ) {
    502                         std::vector< ast::ptr< ast::Expr > > callExprs = collectCtorDtorCalls( stmt );
    503                         return std::all_of( callExprs.begin(), callExprs.end(), pred );
    504                 }
    505446        }
    506447
     
    511452                                assert( funcType );
    512453                                return funcType->get_parameters().size() == 1;
    513                         }
    514                         return false;
    515                 });
    516         }
    517 
    518         bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ) {
    519                 return allofCtorDtor( stmt, []( const ast::Expr * callExpr ){
    520                         if ( const ast::ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) {
    521                                 const ast::FunctionType * funcType =
    522                                         GenPoly::getFunctionType( appExpr->func->result );
    523                                 assert( funcType );
    524                                 return funcType->params.size() == 1;
    525454                        }
    526455                        return false;
  • src/InitTweak/InitTweak.h

    rf9a7cf0 r6e3e0717  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // InitTweak.h --
     7// RemoveInit.h --
    88//
    99// Author           : Rob Schluntz
    1010// Created On       : Fri May 13 11:26:36 2016
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Mon Jun 10 13:30:00 2019
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:30:33 2017
     13// Update Count     : 4
    1414//
    1515
     
    1919#include <memory>             // for shared_ptr
    2020#include <string>             // for string, allocator
    21 #include <vector>
    2221
    2322#include "AST/Fwd.hpp"        // for AST nodes
     
    6463        /// Non-Null if expr is a call expression whose target function is intrinsic
    6564        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
    66         const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);
    6765
    6866        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
     
    7068        /// Currently has assertions that make it less than fully general.
    7169        bool isIntrinsicSingleArgCallStmt( Statement * stmt );
    72         bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
    7370
    7471        /// True if stmt is a call statement where the function called is intrinsic.
     
    7774        /// get all Ctor/Dtor call expressions from a Statement
    7875        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
    79         std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt );
    8076
    8177        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
  • src/ResolvExpr/CurrentObject.cc

    rf9a7cf0 r6e3e0717  
    946946        }
    947947
    948         const Designation * CurrentObject::findNext( const Designation * designation ) {
    949                 using DesignatorChain = std::deque< ptr< Expr > >;
    950                 PRINT( std::cerr << "___findNext" << std::endl; )
    951                
    952                 // find all the d's
    953                 std::vector< DesignatorChain > desigAlts{ {} }, newDesigAlts;
    954                 std::deque< const Type * > curTypes{ objStack.back()->getType() }, newTypes;
    955                 for ( const Expr * expr : designation->designators ) {
    956                         PRINT( std::cerr << "____untyped: " << expr << std::endl; )
    957                         auto dit = desigAlts.begin();
    958                         if ( auto nexpr = dynamic_cast< const NameExpr * >( expr ) ) {
    959                                 for ( const Type * t : curTypes ) {
    960                                         assert( dit != desigAlts.end() );
    961 
    962                                         DesignatorChain & d = *dit;
    963                                         PRINT( std::cerr << "____actual: " << t << std::endl; )
    964                                         if ( auto refType = dynamic_cast< const ReferenceToType * >( t ) ) {
    965                                                 // concatenate identical field names
    966                                                 for ( const Decl * mem : refType->lookup( nexpr->name ) ) {
    967                                                         if ( auto field = dynamic_cast< const ObjectDecl * >( mem ) ) {
    968                                                                 PRINT( std::cerr << "____alt: " << field->type << std::endl; )
    969                                                                 DesignatorChain d2 = d;
    970                                                                 d2.emplace_back( new VariableExpr{ expr->location, field } );
    971                                                                 newDesigAlts.emplace_back( std::move( d2 ) );
    972                                                                 newTypes.emplace_back( field->type );
    973                                                         }
    974                                                 }
    975                                         }
    976 
    977                                         ++dit;
    978                                 }
    979                         } else {
    980                                 for ( const Type * t : curTypes ) {
    981                                         assert( dit != desigAlts.end() );
    982 
    983                                         DesignatorChain & d = *dit;
    984                                         if ( auto at = dynamic_cast< const ArrayType * >( t ) ) {
    985                                                 PRINT( std::cerr << "____alt: " << at->get_base() << std::endl; )
    986                                                 d.emplace_back( expr );
    987                                                 newDesigAlts.emplace_back( d );
    988                                                 newTypes.emplace_back( at->base );
    989                                         }
    990                                 }
    991                         }
    992 
    993                         // reset queue
    994                         desigAlts = std::move( newDesigAlts );
    995                         newDesigAlts.clear();
    996                         curTypes = std::move( newTypes );
    997                         newTypes.clear();
    998                         assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%zu) and current types (%zu) out of sync", desigAlts.size(), curTypes.size() );
    999                 }
    1000 
    1001                 if ( desigAlts.size() > 1 ) {
    1002                         SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
    1003                 } else if ( desigAlts.empty() ) {
    1004                         SemanticError( designation, "No reasonable alternatives for designation: " );
    1005                 }
    1006 
    1007                 DesignatorChain & d = desigAlts.back();
    1008                 PRINT( for ( Expression * expr : d ) {
    1009                         std::cerr << "____desig: " << expr << std::endl;
    1010                 } ) // for
    1011                 assertf( ! curTypes.empty(), "empty designator chosen");
    1012 
    1013                 // set new designators
    1014                 assertf( ! objStack.empty(), "empty object stack when setting designation" );
    1015                 Designation * actualDesignation =
    1016                         new Designation{ designation->location, DesignatorChain{d} };
    1017                 objStack.back()->setPosition( d ); // destroys d
    1018                 return actualDesignation;
    1019         }
    1020 
    1021         void CurrentObject::setNext( const Designation * designation ) {
     948        void CurrentObject::setNext( const ast::Designation * designation ) {
    1022949                PRINT( std::cerr << "____setNext" << designation << std::endl; )
    1023950                assertf( ! objStack.empty(), "obj stack empty in setNext" );
  • src/ResolvExpr/CurrentObject.h

    rf9a7cf0 r6e3e0717  
    111111                CurrentObject( const CodeLocation & loc, const Type * type );
    112112
    113                 /// resolves unresolved designation
    114                 const Designation * findNext( const Designation * designation );
    115113                /// sets current position using the resolved designation
    116114                void setNext( const ast::Designation * designation );
  • src/ResolvExpr/Resolver.cc

    rf9a7cf0 r6e3e0717  
    12271227                void previsit( const ast::WaitForStmt * );
    12281228
    1229                 const ast::SingleInit *      previsit( const ast::SingleInit * );
    1230                 const ast::ListInit *        previsit( const ast::ListInit * );
    1231                 const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
     1229                const ast::SingleInit * previsit( const ast::SingleInit * );
     1230                const ast::ListInit * previsit( const ast::ListInit * );
     1231                void previsit( const ast::ConstructorInit * );
    12321232        };
    12331233
     
    15101510                        // iterate designations and initializers in pairs, moving the cursor to the current
    15111511                        // designated object and resolving the initializer against that object
    1512                         listInit = ast::mutate_field_index(
    1513                                 listInit, &ast::ListInit::designations, i,
    1514                                 currentObject.findNext( listInit->designations[i] ) );
    1515                         listInit = ast::mutate_field_index(
    1516                                 listInit, &ast::ListInit::initializers, i,
    1517                                 listInit->initializers[i]->accept( *visitor ) );
    1518                 }
    1519 
    1520                 // move cursor out of brace-enclosed initializer-list
    1521                 currentObject.exitListInit();
     1512                        #warning unimplemented; Resolver port in progress
     1513                        assert(false);
     1514                }
    15221515
    15231516                visit_children = false;
     
    15251518        }
    15261519
    1527         const ast::ConstructorInit * Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) {
    1528                 visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor );
    1529                 visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor );
    1530 
    1531                 // found a constructor - can get rid of C-style initializer
    1532                 // xxx - Rob suggests this field is dead code
    1533                 ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::init, nullptr );
    1534 
    1535                 // intrinsic single-parameter constructors and destructors do nothing. Since this was
    1536                 // implicitly generated, there's no way for it to have side effects, so get rid of it to
    1537                 // clean up generated code
    1538                 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
    1539                         ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::ctor, nullptr );
    1540                 }
    1541                 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
    1542                         ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::dtor, nullptr );
    1543                 }
    1544 
    1545                 return ctorInit;
     1520        void Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) {
     1521                #warning unimplemented; Resolver port in progress
     1522                (void)ctorInit;
     1523                assert(false);
    15461524        }
    15471525
Note: See TracChangeset for help on using the changeset viewer.