- Timestamp:
- Jun 10, 2019, 1:48:19 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f9a7cf0
- Parents:
- 05d55ff
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
r05d55ff r2d11663 99 99 100 100 /// Mutate a node field (only clones if not equal to existing value) 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 ) { 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 107 104 if ( node->*field == val ) return node; 108 105 106 // mutate and return 109 107 node_t * ret = mutate( node ); 110 ret->*field = std::forward< field_t >( val ); 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 ); 111 123 return ret; 112 124 } -
src/InitTweak/InitTweak.cc
r05d55ff r2d11663 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 1 16 #include <algorithm> // for find, all_of 2 17 #include <cassert> // for assertf, assert, strict_dynamic_cast … … 4 19 #include <iterator> // for back_insert_iterator, back_inserter 5 20 #include <memory> // for __shared_ptr 21 #include <vector> 6 22 7 23 #include "AST/Expr.hpp" … … 307 323 } 308 324 309 struct CallFinder {310 CallFinder ( const std::list< std::string > & names ) : names( names ) {}325 struct CallFinder_old { 326 CallFinder_old( const std::list< std::string > & names ) : names( names ) {} 311 327 312 328 void postvisit( ApplicationExpr * appExpr ) { … … 331 347 }; 332 348 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 333 366 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) { 334 static PassVisitor<CallFinder > finder( std::list< std::string >{ "?{}", "^?{}" } );367 static PassVisitor<CallFinder_old> finder( std::list< std::string >{ "?{}", "^?{}" } ); 335 368 finder.pass.matches = &matches; 336 369 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 ); 337 376 } 338 377 … … 436 475 } 437 476 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 438 491 namespace { 439 492 template <typename Predicate> … … 444 497 return std::all_of( callExprs.begin(), callExprs.end(), pred); 445 498 } 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 } 446 505 } 447 506 … … 452 511 assert( funcType ); 453 512 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; 454 525 } 455 526 return false; -
src/InitTweak/InitTweak.h
r05d55ff r2d11663 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.h --7 // InitTweak.h -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:30:33 201713 // Update Count : 411 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 10 13:30:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 19 19 #include <memory> // for shared_ptr 20 20 #include <string> // for string, allocator 21 #include <vector> 21 22 22 23 #include "AST/Fwd.hpp" // for AST nodes … … 63 64 /// Non-Null if expr is a call expression whose target function is intrinsic 64 65 ApplicationExpr * isIntrinsicCallExpr( Expression * expr ); 66 const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr); 65 67 66 68 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. … … 68 70 /// Currently has assertions that make it less than fully general. 69 71 bool isIntrinsicSingleArgCallStmt( Statement * stmt ); 72 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ); 70 73 71 74 /// True if stmt is a call statement where the function called is intrinsic. … … 74 77 /// get all Ctor/Dtor call expressions from a Statement 75 78 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ); 79 std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ); 76 80 77 81 /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call -
src/ResolvExpr/CurrentObject.cc
r05d55ff r2d11663 946 946 } 947 947 948 void CurrentObject::setNext( const ast::Designation * designation ) { 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 ) { 949 1022 PRINT( std::cerr << "____setNext" << designation << std::endl; ) 950 1023 assertf( ! objStack.empty(), "obj stack empty in setNext" ); -
src/ResolvExpr/CurrentObject.h
r05d55ff r2d11663 111 111 CurrentObject( const CodeLocation & loc, const Type * type ); 112 112 113 /// resolves unresolved designation 114 const Designation * findNext( const Designation * designation ); 113 115 /// sets current position using the resolved designation 114 116 void setNext( const ast::Designation * designation ); -
src/ResolvExpr/Resolver.cc
r05d55ff r2d11663 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 voidprevisit( const ast::ConstructorInit * );1229 const ast::SingleInit * previsit( const ast::SingleInit * ); 1230 const ast::ListInit * previsit( const ast::ListInit * ); 1231 const ast::ConstructorInit * 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 #warning unimplemented; Resolver port in progress 1513 assert(false); 1514 } 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(); 1515 1522 1516 1523 visit_children = false; … … 1518 1525 } 1519 1526 1520 void Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) { 1521 #warning unimplemented; Resolver port in progress 1522 (void)ctorInit; 1523 assert(false); 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; 1524 1546 } 1525 1547
Note: See TracChangeset
for help on using the changeset viewer.