Changes in / [f9a7cf0:6e3e0717]
- Location:
- src
- Files:
-
- 6 edited
-
AST/Node.hpp (modified) (1 diff)
-
InitTweak/InitTweak.cc (modified) (7 diffs)
-
InitTweak/InitTweak.h (modified) (5 diffs)
-
ResolvExpr/CurrentObject.cc (modified) (1 diff)
-
ResolvExpr/CurrentObject.h (modified) (1 diff)
-
ResolvExpr/Resolver.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
rf9a7cf0 r6e3e0717 99 99 100 100 /// 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 101 template<typename node_t, typename field_t> 102 const 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 ) { 104 107 if ( node->*field == val ) return node; 105 108 106 // mutate and return107 109 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 ); 123 111 return ret; 124 112 } -
src/InitTweak/InitTweak.cc
rf9a7cf0 r6e3e0717 1 //2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo3 //4 // The contents of this file are covered under the licence agreement in the5 // file "LICENCE" distributed with Cforall.6 //7 // InitTweak.cc --8 //9 // Author : Rob Schluntz10 // Created On : Fri May 13 11:26:36 201611 // Last Modified By : Aaron B. Moss12 // Last Modified On : Mon Jun 10 13:30:00 201913 // Update Count : 514 //15 16 1 #include <algorithm> // for find, all_of 17 2 #include <cassert> // for assertf, assert, strict_dynamic_cast … … 19 4 #include <iterator> // for back_insert_iterator, back_inserter 20 5 #include <memory> // for __shared_ptr 21 #include <vector>22 6 23 7 #include "AST/Expr.hpp" … … 323 307 } 324 308 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 ) {} 327 311 328 312 void postvisit( ApplicationExpr * appExpr ) { … … 347 331 }; 348 332 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 366 333 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 >{ "?{}", "^?{}" } ); 368 335 finder.pass.matches = &matches; 369 336 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 );376 337 } 377 338 … … 475 436 } 476 437 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 because486 // autogenerated ctor/dtor will call all member dtors, and some members may have a487 // user-defined dtor488 return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr;489 }490 491 438 namespace { 492 439 template <typename Predicate> … … 497 444 return std::all_of( callExprs.begin(), callExprs.end(), pred); 498 445 } 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 }505 446 } 506 447 … … 511 452 assert( funcType ); 512 453 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;525 454 } 526 455 return false; -
src/InitTweak/InitTweak.h
rf9a7cf0 r6e3e0717 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InitTweak.h --7 // RemoveInit.h -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Mon Jun 10 13:30:00 201913 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:30:33 2017 13 // Update Count : 4 14 14 // 15 15 … … 19 19 #include <memory> // for shared_ptr 20 20 #include <string> // for string, allocator 21 #include <vector>22 21 23 22 #include "AST/Fwd.hpp" // for AST nodes … … 64 63 /// Non-Null if expr is a call expression whose target function is intrinsic 65 64 ApplicationExpr * isIntrinsicCallExpr( Expression * expr ); 66 const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);67 65 68 66 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. … … 70 68 /// Currently has assertions that make it less than fully general. 71 69 bool isIntrinsicSingleArgCallStmt( Statement * stmt ); 72 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );73 70 74 71 /// True if stmt is a call statement where the function called is intrinsic. … … 77 74 /// get all Ctor/Dtor call expressions from a Statement 78 75 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ); 79 std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt );80 76 81 77 /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call -
src/ResolvExpr/CurrentObject.cc
rf9a7cf0 r6e3e0717 946 946 } 947 947 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 ) { 1022 949 PRINT( std::cerr << "____setNext" << designation << std::endl; ) 1023 950 assertf( ! objStack.empty(), "obj stack empty in setNext" ); -
src/ResolvExpr/CurrentObject.h
rf9a7cf0 r6e3e0717 111 111 CurrentObject( const CodeLocation & loc, const Type * type ); 112 112 113 /// resolves unresolved designation114 const Designation * findNext( const Designation * designation );115 113 /// sets current position using the resolved designation 116 114 void setNext( const ast::Designation * designation ); -
src/ResolvExpr/Resolver.cc
rf9a7cf0 r6e3e0717 1227 1227 void previsit( const ast::WaitForStmt * ); 1228 1228 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 * ); 1232 1232 }; 1233 1233 … … 1510 1510 // iterate designations and initializers in pairs, moving the cursor to the current 1511 1511 // 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 } 1522 1515 1523 1516 visit_children = false; … … 1525 1518 } 1526 1519 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); 1546 1524 } 1547 1525
Note:
See TracChangeset
for help on using the changeset viewer.