Changeset 0ddb713
- Timestamp:
- Dec 2, 2015, 11:58:59 AM (7 years ago)
- Branches:
- aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9cb8e88d
- Parents:
- 9ed3237 (diff), f2b2029 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 6 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r9ed3237 r0ddb713 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Aug 11 16:22:35201513 // Update Count : 8912 // Last Modified On : Wed Dec 02 11:52:37 2015 13 // Update Count : 201 14 14 // 15 15 … … 47 47 namespace { 48 48 const std::list<Label> noLabels; 49 50 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars ); 49 51 50 52 class Pass1 : public PolyMutator { … … 78 80 ObjectDecl *makeTemporary( Type *type ); 79 81 80 typedef std::map< std::string, FunctionDecl*> AdapterMap;82 typedef std::map< std::string, DeclarationWithType *> AdapterMap; 81 83 std::map< std::string, DeclarationWithType *> assignOps; 82 84 std::stack< AdapterMap > adapters; … … 140 142 141 143 namespace { 144 std::string makePolyMonoSuffix( FunctionType * function, const TyVarMap &tyVars ) { 145 std::stringstream name; 146 147 // NOTE: this function previously used isPolyObj, which failed to produce 148 // the correct thing in some situations. It's not clear to me why this wasn't working. 149 150 // if the return type or a parameter type involved polymorphic types, then the adapter will need 151 // to take those polymorphic types as pointers. Therefore, there can be two different functions 152 // with the same mangled name, so we need to further mangle the names. 153 for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) { 154 if ( isPolyVal( (*retval)->get_type(), tyVars ) ) { 155 name << "P"; 156 } else { 157 name << "M"; 158 } 159 } 160 name << "_"; 161 std::list< DeclarationWithType *> ¶mList = function->get_parameters(); 162 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) { 163 if ( isPolyVal( (*arg)->get_type(), tyVars ) ) { 164 name << "P"; 165 } else { 166 name << "M"; 167 } 168 } // for 169 return name.str(); 170 } 171 172 std::string mangleAdapterName( FunctionType * function, const TyVarMap &tyVars ) { 173 return SymTab::Mangler::mangle( function ) + makePolyMonoSuffix( function, tyVars ); 174 } 175 142 176 std::string makeAdapterName( const std::string &mangleName ) { 143 177 return "_adapter" + mangleName; 144 178 } 145 179 146 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) {147 bool doTransform = false;148 if ( ! function->get_returnVals().empty() ) {149 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) {150 151 // figure out if the return type is specified by a type parameter152 for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) {153 if ( (*tyVar)->get_name() == typeInst->get_name() ) {154 doTransform = true;155 name = typeInst->get_name();156 break;157 } // if158 } // for159 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) {160 doTransform = true;161 } // if162 } // if163 } // if164 return doTransform;165 }166 167 bool isPolyRet( FunctionType *function, std::string &name ) {168 TyVarMap dummyTyVars;169 return isPolyRet( function, name, dummyTyVars );170 }171 172 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {173 std::string dummyString;174 return isPolyRet( function, dummyString, otherTyVars );175 }176 177 180 Pass1::Pass1() 178 181 : useRetval( false ), tempNamer( "_temp" ) { 179 } 180 182 adapters.push(AdapterMap()); 183 } 184 185 // returns true if the given declaration is: (*?=?)(T *, T) for some T (return not checked, but maybe should be) 181 186 bool checkAssignment( DeclarationWithType *decl, std::string &name ) { 182 187 if ( decl->get_name() == "?=?" ) { … … 198 203 199 204 void Pass1::findAssignOps( const std::list< TypeDecl *> &forall ) { 200 assignOps.clear(); 205 // what if a nested function uses an assignment operator? 206 // assignOps.clear(); 201 207 for ( std::list< TypeDecl *>::const_iterator i = forall.begin(); i != forall.end(); ++i ) { 202 208 for ( std::list< DeclarationWithType *>::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { … … 210 216 211 217 DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) { 212 if ( functionDecl->get_statements() ) { 218 if ( functionDecl->get_statements() ) { // empty routine body ? 219 doBeginScope(); 213 220 TyVarMap oldtyVars = scopeTyVars; 221 std::map< std::string, DeclarationWithType *> oldassignOps = assignOps; 214 222 DeclarationWithType *oldRetval = retval; 215 223 bool oldUseRetval = useRetval; 216 224 225 // process polymorphic return value 217 226 retval = 0; 218 227 std::string typeName; … … 227 236 } // if 228 237 229 scopeTyVars.clear(); 230 /// std::cerr << "clear\n"; 238 FunctionType *functionType = functionDecl->get_functionType(); 231 239 makeTyVarMap( functionDecl->get_functionType(), scopeTyVars ); 232 240 findAssignOps( functionDecl->get_functionType()->get_forall() ); 241 242 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters(); 243 std::list< FunctionType *> functions; 244 for ( std::list< TypeDecl *>::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar ) { 245 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert ) { 246 findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter ); 247 } // for 248 } // for 249 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) { 250 findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter ); 251 } // for 252 AdapterMap & adapters = Pass1::adapters.top(); 253 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) { 254 std::string mangleName = mangleAdapterName( *funType, scopeTyVars ); 255 if ( adapters.find( mangleName ) == adapters.end() ) { 256 std::string adapterName = makeAdapterName( mangleName ); 257 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) ) ); 258 } // if 259 } // for 260 233 261 functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) ); 234 262 235 263 scopeTyVars = oldtyVars; 236 /// std::cerr << "end FunctionDecl: "; 237 /// for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) { 238 /// std::cerr << i->first << " "; 239 /// } 240 /// std::cerr << "\n"; 264 assignOps = oldassignOps; 265 // std::cerr << "end FunctionDecl: "; 266 // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) { 267 // std::cerr << i->first << " "; 268 // } 269 // std::cerr << "\n"; 241 270 retval = oldRetval; 242 271 useRetval = oldUseRetval; 243 //doEndScope();272 doEndScope(); 244 273 } // if 245 274 return functionDecl; … … 348 377 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg ); 349 378 } // if 350 std::string mangleName = SymTab::Mangler::mangle( function);379 std::string mangleName = mangleAdapterName( function, tyVars ); 351 380 std::string adapterName = makeAdapterName( mangleName ); 352 381 … … 457 486 /// return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() ); 458 487 /// } else { 459 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 460 deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) ); 461 deref->get_results().push_back( arg->get_type()->clone() ); 462 return deref; 488 if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) { 489 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 490 deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) ); 491 deref->get_results().push_back( arg->get_type()->clone() ); 492 return deref; 493 } // if 463 494 /// } 464 495 } // if … … 544 575 } // for 545 576 546 // parameter function types for which an appropriate adapter has been generated. 547 // we cannot use the types after applying substitutions, since two different 548 // parameter types may be unified to the same type 577 // parameter function types for which an appropriate adapter has been generated. we cannot use the types 578 // after applying substitutions, since two different parameter types may be unified to the same type 549 579 std::set< std::string > adaptersDone; 550 580 … … 554 584 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 555 585 556 // only attempt to create an adapter or pass one as a parameter if we haven't 557 // already done so for thispre-substitution parameter function type.586 // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this 587 // pre-substitution parameter function type. 558 588 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 559 std::string mangleName = SymTab::Mangler::mangle( realFunction );560 589 adaptersDone.insert( adaptersDone.begin(), mangleName ); 561 590 562 // apply substitution to type variables to figure out what the 563 // adapter's type should look like 591 // apply substitution to type variables to figure out what the adapter's type should look like 564 592 assert( env ); 565 593 env->apply( realFunction ); 566 mangleName = SymTab::Mangler::mangle( realFunction ); 567 568 if ( needsAdapter( realFunction, exprTyVars, true ) ) { 569 // the function still contains type variables, which means we are in a polymorphic 570 // context and the adapter function is a parameter - call the parameter and don't 571 // create a new adapter. 572 appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) ); 573 } else { 574 if ( isPolyRet( originalFunction, exprTyVars ) ) { 575 // if the return type involved polymorphic types, then 576 // the adapter will need to take those polymorphic types 577 // as pointers. Therefore, there can be two different 578 // functions with the same mangled name, so we need two adapter map 579 // stacks and also we need the mangled names to be different. 580 mangleName += "polyret_"; 581 } 582 583 AdapterMap & adapters = Pass1::adapters.top(); 584 AdapterMap::iterator adapter = adapters.find( mangleName ); 585 if ( adapter == adapters.end() ) { 586 // adapter has not been created yet in the current scope, so define it 587 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 588 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) ); 589 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) ); 590 } // if 591 assert( adapter != adapters.end() ); 592 593 // add the appropriate adapter as a parameter 594 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 594 mangleName = SymTab::Mangler::mangle( realFunction ); 595 mangleName += makePolyMonoSuffix( originalFunction, exprTyVars ); 596 597 AdapterMap & adapters = Pass1::adapters.top(); 598 AdapterMap::iterator adapter = adapters.find( mangleName ); 599 if ( adapter == adapters.end() ) { 600 // adapter has not been created yet in the current scope, so define it 601 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 602 adapter = adapters.insert( adapters.begin(), std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) ); 603 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) ); 595 604 } // if 605 assert( adapter != adapters.end() ); 606 607 // add the appropriate adapter as a parameter 608 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 596 609 } // if 597 610 } // for 598 } 611 } // passAdapters 599 612 600 613 TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) { … … 656 669 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars ); 657 670 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars ); 658 assert( ! typeInst1 || ! typeInst2 ); 671 assert( ! typeInst1 || ! typeInst2 ); // the arguments cannot both be polymorphic pointers 659 672 UntypedExpr *ret = 0; 660 if ( typeInst1 || typeInst2 ) { 673 if ( typeInst1 || typeInst2 ) { // one of the arguments is a polymorphic pointer 661 674 ret = new UntypedExpr( new NameExpr( "?+?" ) ); 662 675 } // if … … 769 782 770 783 Expression *Pass1::mutate( ApplicationExpr *appExpr ) { 771 ///std::cerr << "mutate appExpr: ";772 ///for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {773 ///std::cerr << i->first << " ";774 ///}775 ///std::cerr << "\n";784 // std::cerr << "mutate appExpr: "; 785 // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) { 786 // std::cerr << i->first << " "; 787 // } 788 // std::cerr << "\n"; 776 789 bool oldUseRetval = useRetval; 777 790 useRetval = false; … … 799 812 ret = addPolyRetParam( appExpr, function, typeName, arg ); 800 813 } else if ( needsAdapter( function, scopeTyVars ) ) { 801 ///std::cerr << "needs adapter: ";802 ///for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {803 ///std::cerr << i->first << " ";804 ///}805 ///std::cerr << "\n";814 // std::cerr << "needs adapter: "; 815 // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) { 816 // std::cerr << i->first << " "; 817 // } 818 // std::cerr << "\n"; 806 819 // change the application so it calls the adapter rather than the passed function 807 820 ret = applyAdapter( appExpr, function, arg, scopeTyVars ); … … 854 867 855 868 Statement * Pass1::mutate(ReturnStmt *retStmt) { 856 // a cast expr on a polymorphic return value is either redundant or invalid869 // by this point, a cast expr on a polymorphic return value is redundant 857 870 while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( retStmt->get_expr() ) ) { 858 871 retStmt->set_expr( castExpr->get_arg() ); … … 911 924 912 925 void Pass1::doBeginScope() { 913 // actually, maybe this could (should?) push 914 // a copy of the current map 915 adapters.push(AdapterMap()); 926 // push a copy of the current map 927 adapters.push(adapters.top()); 916 928 } 917 929 … … 934 946 std::set< std::string > adaptersDone; 935 947 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) { 936 std::string mangleName = SymTab::Mangler::mangle( *funType);948 std::string mangleName = mangleAdapterName( *funType, scopeTyVars ); 937 949 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 938 950 std::string adapterName = makeAdapterName( mangleName ); … … 1000 1012 for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1001 1013 ObjectDecl *thisParm; 1014 // add all size parameters to parameter list 1002 1015 if ( (*tyParm)->get_kind() == TypeDecl::Any ) { 1003 1016 thisParm = newObj->clone(); … … 1006 1019 ++last; 1007 1020 } 1021 // move all assertions into parameter list 1008 1022 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1009 1023 /// *assert = (*assert)->acceptMutator( *this ); -
src/GenPoly/Box.h
r9ed3237 r0ddb713 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue May 19 07:32:33201513 // Update Count : 212 // Last Modified On : Thu Nov 19 17:24:01 2015 13 // Update Count : 5 14 14 // 15 15 -
src/GenPoly/GenPoly.cc
r9ed3237 r0ddb713 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 07:37:46201513 // Update Count : 1 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Nov 24 15:23:08 2015 13 // Update Count : 11 14 14 // 15 15 … … 21 21 22 22 namespace GenPoly { 23 // interface functions 24 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 25 return isPolyVal( type, tyVars, false ); 23 // A function needs an adapter if it returns a polymorphic value or if any of its 24 // parameters have polymorphic type 25 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 26 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 27 return true; 28 } // if 29 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) { 30 if ( isPolyVal( (*innerArg)->get_type(), tyVars ) ) { 31 return true; 32 } // if 33 } // for 34 return false; 26 35 } 27 36 28 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 29 return needsAdapter( adaptee, tyVars, false ); 37 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) { 38 bool doTransform = false; 39 if ( ! function->get_returnVals().empty() ) { 40 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) { 41 42 // figure out if the return type is specified by a type parameter 43 for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) { 44 if ( (*tyVar)->get_name() == typeInst->get_name() ) { 45 doTransform = true; 46 name = typeInst->get_name(); 47 break; 48 } // if 49 } // for 50 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) { 51 doTransform = true; 52 } // if 53 } // if 54 } // if 55 return doTransform; 30 56 } 31 57 32 bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) { 33 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 58 bool isPolyRet( FunctionType *function, std::string &name ) { 59 TyVarMap dummyTyVars; 60 return isPolyRet( function, name, dummyTyVars ); 61 } 62 63 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) { 64 std::string dummyString; 65 return isPolyRet( function, dummyString, otherTyVars ); 66 } 67 68 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 69 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) { 34 70 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 35 71 return true; 36 72 } // if 37 return considerAllTyVars;38 73 } // if 39 74 return false; 40 75 } 41 76 42 // A function needs an adapter if it returns a polymorphic value or if any of its 43 // parameters have polymorphic type 44 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) { 45 bool needsAdapter = false; 46 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { 47 needsAdapter = true; 48 } // if 49 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); ! needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { 50 if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) { 51 needsAdapter = true; 52 } // if 53 } // for 54 return needsAdapter; 77 bool isPolyObj( Type *type, const TyVarMap &tyVars ) { 78 if ( isPolyVal( type, tyVars ) ) { 79 return true; 80 } else if ( PointerType *pt = dynamic_cast<PointerType*>( type ) ) { 81 return isPolyObj( pt->get_base(), tyVars ); 82 } else { 83 return false; 84 } 55 85 } 56 86 -
src/GenPoly/GenPoly.h
r9ed3237 r0ddb713 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 07:38:34201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Nov 24 15:24:38 2015 13 // Update Count : 6 14 14 // 15 15 … … 25 25 typedef std::map< std::string, TypeDecl::Kind > TyVarMap; 26 26 27 // considerAllTyVars allows ignoring the contents of the TyVarMap parameter, for the situations where 28 // it is important only that a TypeInstType node exists. 27 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); 28 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ); 29 bool isPolyRet( FunctionType *function, std::string &name ); 30 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ); 31 // bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars ); 32 bool isPolyVal( Type *type, const TyVarMap &tyVars ); 29 33 30 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); 31 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ); 32 bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars ); 33 bool isPolyVal( Type *type, const TyVarMap &tyVars ); 34 bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ); 34 // true if type variable or any number of pointers to type variable 35 bool isPolyObj( Type *type, const TyVarMap &tyVars ); 35 36 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 36 37 } // namespace GenPoly -
src/GenPoly/module.mk
r9ed3237 r0ddb713 22 22 GenPoly/Specialize.cc \ 23 23 GenPoly/CopyParams.cc \ 24 GenPoly/FindFunction.cc 24 GenPoly/FindFunction.cc \ 25 GenPoly/InstantiateGeneric.cc -
src/Makefile.in
r9ed3237 r0ddb713 121 121 GenPoly/cfa_cpp-CopyParams.$(OBJEXT) \ 122 122 GenPoly/cfa_cpp-FindFunction.$(OBJEXT) \ 123 GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT) \ 123 124 InitTweak/cfa_cpp-InitModel.$(OBJEXT) \ 124 125 InitTweak/cfa_cpp-InitExpander.$(OBJEXT) \ … … 347 348 GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc GenPoly/Specialize.cc \ 348 349 GenPoly/CopyParams.cc GenPoly/FindFunction.cc \ 349 InitTweak/InitModel.cc InitTweak/InitExpander.cc \350 InitTweak/ Mutate.cc InitTweak/Association.cc \351 InitTweak/ RemoveInit.cc Parser/parser.yy Parser/lex.ll\352 Parser/ TypedefTable.cc Parser/ParseNode.cc \353 Parser/ DeclarationNode.cc Parser/ExpressionNode.cc \354 Parser/ StatementNode.cc Parser/InitializerNode.cc \355 Parser/ TypeData.cc Parser/LinkageSpec.cc \356 Parser/ parseutility.cc Parser/Parser.cc \350 GenPoly/InstantiateGeneric.cc InitTweak/InitModel.cc \ 351 InitTweak/InitExpander.cc InitTweak/Mutate.cc \ 352 InitTweak/Association.cc InitTweak/RemoveInit.cc \ 353 Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \ 354 Parser/ParseNode.cc Parser/DeclarationNode.cc \ 355 Parser/ExpressionNode.cc Parser/StatementNode.cc \ 356 Parser/InitializerNode.cc Parser/TypeData.cc \ 357 Parser/LinkageSpec.cc Parser/parseutility.cc Parser/Parser.cc \ 357 358 ResolvExpr/AlternativeFinder.cc ResolvExpr/Alternative.cc \ 358 359 ResolvExpr/Unify.cc ResolvExpr/PtrsAssignable.cc \ … … 553 554 GenPoly/$(DEPDIR)/$(am__dirstamp) 554 555 GenPoly/cfa_cpp-FindFunction.$(OBJEXT): GenPoly/$(am__dirstamp) \ 556 GenPoly/$(DEPDIR)/$(am__dirstamp) 557 GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT): GenPoly/$(am__dirstamp) \ 555 558 GenPoly/$(DEPDIR)/$(am__dirstamp) 556 559 InitTweak/$(am__dirstamp): … … 784 787 -rm -f GenPoly/cfa_cpp-FindFunction.$(OBJEXT) 785 788 -rm -f GenPoly/cfa_cpp-GenPoly.$(OBJEXT) 789 -rm -f GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT) 786 790 -rm -f GenPoly/cfa_cpp-Lvalue.$(OBJEXT) 787 791 -rm -f GenPoly/cfa_cpp-PolyMutator.$(OBJEXT) … … 893 897 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-FindFunction.Po@am__quote@ 894 898 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-GenPoly.Po@am__quote@ 899 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Po@am__quote@ 895 900 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-Lvalue.Po@am__quote@ 896 901 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-PolyMutator.Po@am__quote@ … … 1357 1362 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/cfa_cpp-FindFunction.obj `if test -f 'GenPoly/FindFunction.cc'; then $(CYGPATH_W) 'GenPoly/FindFunction.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/FindFunction.cc'; fi` 1358 1363 1364 GenPoly/cfa_cpp-InstantiateGeneric.o: GenPoly/InstantiateGeneric.cc 1365 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/cfa_cpp-InstantiateGeneric.o -MD -MP -MF GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Tpo -c -o GenPoly/cfa_cpp-InstantiateGeneric.o `test -f 'GenPoly/InstantiateGeneric.cc' || echo '$(srcdir)/'`GenPoly/InstantiateGeneric.cc 1366 @am__fastdepCXX_TRUE@ $(am__mv) GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Tpo GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Po 1367 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='GenPoly/InstantiateGeneric.cc' object='GenPoly/cfa_cpp-InstantiateGeneric.o' libtool=no @AMDEPBACKSLASH@ 1368 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1369 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/cfa_cpp-InstantiateGeneric.o `test -f 'GenPoly/InstantiateGeneric.cc' || echo '$(srcdir)/'`GenPoly/InstantiateGeneric.cc 1370 1371 GenPoly/cfa_cpp-InstantiateGeneric.obj: GenPoly/InstantiateGeneric.cc 1372 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/cfa_cpp-InstantiateGeneric.obj -MD -MP -MF GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Tpo -c -o GenPoly/cfa_cpp-InstantiateGeneric.obj `if test -f 'GenPoly/InstantiateGeneric.cc'; then $(CYGPATH_W) 'GenPoly/InstantiateGeneric.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/InstantiateGeneric.cc'; fi` 1373 @am__fastdepCXX_TRUE@ $(am__mv) GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Tpo GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Po 1374 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='GenPoly/InstantiateGeneric.cc' object='GenPoly/cfa_cpp-InstantiateGeneric.obj' libtool=no @AMDEPBACKSLASH@ 1375 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1376 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/cfa_cpp-InstantiateGeneric.obj `if test -f 'GenPoly/InstantiateGeneric.cc'; then $(CYGPATH_W) 'GenPoly/InstantiateGeneric.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/InstantiateGeneric.cc'; fi` 1377 1359 1378 InitTweak/cfa_cpp-InitModel.o: InitTweak/InitModel.cc 1360 1379 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/cfa_cpp-InitModel.o -MD -MP -MF InitTweak/$(DEPDIR)/cfa_cpp-InitModel.Tpo -c -o InitTweak/cfa_cpp-InitModel.o `test -f 'InitTweak/InitModel.cc' || echo '$(srcdir)/'`InitTweak/InitModel.cc -
src/Parser/TypeData.cc
r9ed3237 r0ddb713 799 799 case DeclarationNode::Struct: 800 800 at = new StructDecl( aggregate->name ); 801 buildForall( aggregate->params, at->get_parameters() ); 801 802 break; 802 803 case DeclarationNode::Union: 803 804 at = new UnionDecl( aggregate->name ); 805 buildForall( aggregate->params, at->get_parameters() ); 804 806 break; 805 807 case DeclarationNode::Context: 806 808 at = new ContextDecl( aggregate->name ); 809 buildList( aggregate->params, at->get_parameters() ); 807 810 break; 808 811 default: 809 812 assert( false ); 810 813 } // switch 811 buildList( aggregate->params, at->get_parameters() );814 // buildList( aggregate->params, at->get_parameters() ); 812 815 buildList( aggregate->fields, at->get_members() ); 813 816 -
src/ResolvExpr/Unify.cc
r9ed3237 r0ddb713 61 61 62 62 template< typename RefType > void handleRefType( RefType *inst, Type *other ); 63 template< typename RefType > void handleGenericRefType( RefType *inst, Type *other ); 63 64 64 65 bool result; … … 496 497 497 498 template< typename RefType > 498 void Unify::handleRefType( RefType *inst, Type *other ) { 499 void Unify::handleRefType( RefType *inst, Type *other ) { 500 // check that other type is compatible and named the same 499 501 RefType *otherStruct = dynamic_cast< RefType* >( other ); 500 502 result = otherStruct && inst->get_name() == otherStruct->get_name(); 501 } 503 } 504 505 template< typename RefType > 506 void Unify::handleGenericRefType( RefType *inst, Type *other ) { 507 // Check that other type is compatible and named the same 508 handleRefType( inst, other ); 509 if ( ! result ) return; 510 // Check that parameters of types unify, if any 511 std::list< Expression* > params = inst->get_parameters(); 512 std::list< Expression* > otherParams = ((RefType*)other)->get_parameters(); 513 514 std::list< Expression* >::const_iterator it = params.begin(), jt = otherParams.begin(); 515 for ( ; it != params.end() && jt != otherParams.end(); ++it, ++jt ) { 516 TypeExpr *param = dynamic_cast< TypeExpr* >(*it); 517 assert(param && "Aggregate parameters should be type expressions"); 518 TypeExpr *otherParam = dynamic_cast< TypeExpr* >(*jt); 519 assert(otherParam && "Aggregate parameters should be type expressions"); 520 521 if ( ! unifyExact( param->get_type(), otherParam->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) { 522 result = false; 523 return; 524 } 525 } 526 result = ( it == params.end() && jt == otherParams.end() ); 527 } 502 528 503 529 void Unify::visit(StructInstType *structInst) { 504 handle RefType( structInst, type2 );530 handleGenericRefType( structInst, type2 ); 505 531 } 506 532 507 533 void Unify::visit(UnionInstType *unionInst) { 508 handle RefType( unionInst, type2 );534 handleGenericRefType( unionInst, type2 ); 509 535 } 510 536 -
src/SymTab/Validate.cc
r9ed3237 r0ddb713 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Aug 11 16:59:35201513 // Update Count : 19611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Nov 20 16:33:52 2015 13 // Update Count : 201 14 14 // 15 15 … … 126 126 }; 127 127 128 class A ddStructAssignment: public Visitor {128 class AutogenerateRoutines : public Visitor { 129 129 public: 130 130 /// Generates assignment operators for aggregate types as required 131 static void a ddStructAssignment( std::list< Declaration * > &translationUnit );131 static void autogenerateRoutines( std::list< Declaration * > &translationUnit ); 132 132 133 133 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } … … 152 152 virtual void visit( CatchStmt *catchStmt ); 153 153 154 A ddStructAssignment() : functionNesting( 0 ) {}154 AutogenerateRoutines() : functionNesting( 0 ) {} 155 155 private: 156 156 template< typename StmtClass > void visitStatement( StmtClass *stmt ); … … 196 196 acceptAll( translationUnit, pass1 ); 197 197 acceptAll( translationUnit, pass2 ); 198 // need to collect all of the assignment operators prior to 199 // this point and only generate assignment operators if one doesn't exist 200 AddStructAssignment::addStructAssignment( translationUnit ); 198 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 201 199 acceptAll( translationUnit, pass3 ); 202 200 } … … 502 500 static const std::list< std::string > noLabels; 503 501 504 void A ddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {505 A ddStructAssignmentvisitor;502 void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) { 503 AutogenerateRoutines visitor; 506 504 acceptAndAdd( translationUnit, visitor, false ); 507 505 } … … 627 625 } 628 626 627 /// Clones a reference type, replacing any parameters it may have with a clone of the provided list 628 template< typename GenericInstType > 629 GenericInstType *cloneWithParams( GenericInstType *refType, const std::list< Expression* >& params ) { 630 GenericInstType *clone = refType->clone(); 631 clone->get_parameters().clear(); 632 cloneAll( params, clone->get_parameters() ); 633 return clone; 634 } 629 635 630 636 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 631 637 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 632 633 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 638 639 // Make function polymorphic in same parameters as generic struct, if applicable 640 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 641 std::list< Expression* > structParams; // List of matching parameters to put on types 642 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 643 TypeDecl *typeParam = (*param)->clone(); 644 assignType->get_forall().push_back( typeParam ); 645 structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 646 } 647 648 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 634 649 assignType->get_returnVals().push_back( returnVal ); 635 650 636 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );651 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 ); 637 652 assignType->get_parameters().push_back( dstParam ); 638 653 639 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );654 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 640 655 assignType->get_parameters().push_back( srcParam ); 641 656 … … 673 688 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 674 689 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 675 676 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 690 691 // Make function polymorphic in same parameters as generic union, if applicable 692 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 693 std::list< Expression* > unionParams; // List of matching parameters to put on types 694 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 695 TypeDecl *typeParam = (*param)->clone(); 696 assignType->get_forall().push_back( typeParam ); 697 unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 698 } 699 700 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 677 701 assignType->get_returnVals().push_back( returnVal ); 678 702 679 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );703 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams ) ), 0 ); 680 704 assignType->get_parameters().push_back( dstParam ); 681 705 682 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );706 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 683 707 assignType->get_parameters().push_back( srcParam ); 684 708 … … 691 715 copy->get_args().push_back( new VariableExpr( dstParam ) ); 692 716 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 693 copy->get_args().push_back( new SizeofExpr( refType->clone() ) );717 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams ) ) ); 694 718 695 719 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); … … 699 723 } 700 724 701 void A ddStructAssignment::visit( EnumDecl *enumDecl ) {725 void AutogenerateRoutines::visit( EnumDecl *enumDecl ) { 702 726 if ( ! enumDecl->get_members().empty() ) { 703 727 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); … … 708 732 } 709 733 710 void A ddStructAssignment::visit( StructDecl *structDecl ) {734 void AutogenerateRoutines::visit( StructDecl *structDecl ) { 711 735 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 712 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );713 structInst ->set_baseStruct( structDecl );714 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );736 StructInstType structInst( Type::Qualifiers(), structDecl->get_name() ); 737 structInst.set_baseStruct( structDecl ); 738 declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) ); 715 739 structsDone.insert( structDecl->get_name() ); 716 740 } // if 717 741 } 718 742 719 void A ddStructAssignment::visit( UnionDecl *unionDecl ) {743 void AutogenerateRoutines::visit( UnionDecl *unionDecl ) { 720 744 if ( ! unionDecl->get_members().empty() ) { 721 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );722 unionInst ->set_baseUnion( unionDecl );723 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );724 } // if 725 } 726 727 void A ddStructAssignment::visit( TypeDecl *typeDecl ) {745 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() ); 746 unionInst.set_baseUnion( unionDecl ); 747 declsToAdd.push_back( makeUnionAssignment( unionDecl, &unionInst, functionNesting ) ); 748 } // if 749 } 750 751 void AutogenerateRoutines::visit( TypeDecl *typeDecl ) { 728 752 CompoundStmt *stmts = 0; 729 753 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 753 777 } 754 778 755 void A ddStructAssignment::visit( FunctionType *) {779 void AutogenerateRoutines::visit( FunctionType *) { 756 780 // ensure that we don't add assignment ops for types defined as part of the function 757 781 } 758 782 759 void A ddStructAssignment::visit( PointerType *) {783 void AutogenerateRoutines::visit( PointerType *) { 760 784 // ensure that we don't add assignment ops for types defined as part of the pointer 761 785 } 762 786 763 void A ddStructAssignment::visit( ContextDecl *) {787 void AutogenerateRoutines::visit( ContextDecl *) { 764 788 // ensure that we don't add assignment ops for types defined as part of the context 765 789 } 766 790 767 791 template< typename StmtClass > 768 inline void A ddStructAssignment::visitStatement( StmtClass *stmt ) {792 inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) { 769 793 std::set< std::string > oldStructs = structsDone; 770 794 addVisit( stmt, *this ); … … 772 796 } 773 797 774 void A ddStructAssignment::visit( FunctionDecl *functionDecl ) {798 void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) { 775 799 maybeAccept( functionDecl->get_functionType(), *this ); 776 800 acceptAll( functionDecl->get_oldDecls(), *this ); … … 780 804 } 781 805 782 void A ddStructAssignment::visit( CompoundStmt *compoundStmt ) {806 void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) { 783 807 visitStatement( compoundStmt ); 784 808 } 785 809 786 void A ddStructAssignment::visit( IfStmt *ifStmt ) {810 void AutogenerateRoutines::visit( IfStmt *ifStmt ) { 787 811 visitStatement( ifStmt ); 788 812 } 789 813 790 void A ddStructAssignment::visit( WhileStmt *whileStmt ) {814 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) { 791 815 visitStatement( whileStmt ); 792 816 } 793 817 794 void A ddStructAssignment::visit( ForStmt *forStmt ) {818 void AutogenerateRoutines::visit( ForStmt *forStmt ) { 795 819 visitStatement( forStmt ); 796 820 } 797 821 798 void A ddStructAssignment::visit( SwitchStmt *switchStmt ) {822 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 799 823 visitStatement( switchStmt ); 800 824 } 801 825 802 void A ddStructAssignment::visit( ChooseStmt *switchStmt ) {826 void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) { 803 827 visitStatement( switchStmt ); 804 828 } 805 829 806 void A ddStructAssignment::visit( CaseStmt *caseStmt ) {830 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 807 831 visitStatement( caseStmt ); 808 832 } 809 833 810 void A ddStructAssignment::visit( CatchStmt *cathStmt ) {834 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 811 835 visitStatement( cathStmt ); 812 836 } -
src/SynTree/Mutator.h
r9ed3237 r0ddb713 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 23 23:24:18201513 // Update Count : 712 // Last Modified On : Thu Nov 19 22:26:16 2015 13 // Update Count : 8 14 14 // 15 15 #include <cassert> … … 103 103 inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) { 104 104 if ( tree ) { 105 TreeType *newnode = dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) );105 TreeType *newnode = dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) ); 106 106 assert( newnode ); 107 107 return newnode; -
src/SynTree/ReferenceToType.cc
r9ed3237 r0ddb713 59 59 std::string StructInstType::typeString() const { return "struct"; } 60 60 61 std::list<TypeDecl*>* StructInstType::get_baseParameters() { 62 if ( ! baseStruct ) return NULL; 63 return &baseStruct->get_parameters(); 64 } 65 61 66 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 62 67 assert( baseStruct ); … … 65 70 66 71 std::string UnionInstType::typeString() const { return "union"; } 72 73 std::list<TypeDecl*>* UnionInstType::get_baseParameters() { 74 if ( ! baseUnion ) return NULL; 75 return &baseUnion->get_parameters(); 76 } 67 77 68 78 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { -
src/SynTree/Type.h
r9ed3237 r0ddb713 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 9 16:46:15201513 // Update Count : 1 412 // Last Modified On : Fri Nov 20 12:54:09 2015 13 // Update Count : 15 14 14 // 15 15 … … 201 201 std::list<DeclarationWithType*> parameters; 202 202 203 // does the function accept a variable number of arguments following the arguments204 // specified in the parameters list.This could be because of203 // Does the function accept a variable number of arguments following the arguments specified in the parameters list. 204 // This could be because of 205 205 // - an ellipsis in a prototype declaration 206 206 // - an unprototyped declaration … … 237 237 StructDecl *get_baseStruct() const { return baseStruct; } 238 238 void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } 239 240 // a utility function 239 240 /// Accesses generic parameters of base struct (NULL if none such) 241 std::list<TypeDecl*> * get_baseParameters(); 242 243 /// Looks up the members of this struct named "name" and places them into "foundDecls". 244 /// Clones declarations into "foundDecls", caller responsible for freeing 241 245 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 242 246 … … 260 264 UnionDecl *get_baseUnion() const { return baseUnion; } 261 265 void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; } 262 263 // a utility function 266 267 /// Accesses generic parameters of base union (NULL if none such) 268 std::list<TypeDecl*> * get_baseParameters(); 269 270 /// looks up the members of this union named "name" and places them into "foundDecls" 271 /// Clones declarations into "foundDecls", caller responsible for freeing 264 272 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 265 273 -
src/SynTree/TypeSubstitution.cc
r9ed3237 r0ddb713 126 126 Type *TypeSubstitution::handleType( TypeClass *type ) { 127 127 BoundVarsType oldBoundVars( boundVars ); 128 // bind type variables from forall-qualifiers 128 129 if ( freeOnly ) { 129 130 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { … … 136 137 } 137 138 139 template< typename TypeClass > 140 Type *TypeSubstitution::handleAggregateType( TypeClass *type ) { 141 BoundVarsType oldBoundVars( boundVars ); 142 // bind type variables from forall-qualifiers 143 if ( freeOnly ) { 144 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 145 boundVars.insert( (*tyvar )->get_name() ); 146 } // for 147 } // if 148 // bind type variables from generic type instantiations 149 std::list< TypeDecl* > *baseParameters = type->get_baseParameters(); 150 if ( baseParameters && ! type->get_parameters().empty() ) { 151 for ( std::list< TypeDecl* >::const_iterator tyvar = baseParameters->begin(); tyvar != baseParameters->end(); ++tyvar ) { 152 boundVars.insert( (*tyvar)->get_name() ); 153 } // for 154 } // if 155 Type *ret = Mutator::mutate( type ); 156 boundVars = oldBoundVars; 157 return ret; 158 } 159 138 160 Type * TypeSubstitution::mutate( VoidType *basicType ) { 139 161 return handleType( basicType ); … … 157 179 158 180 Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) { 159 return handle Type( aggregateUseType );181 return handleAggregateType( aggregateUseType ); 160 182 } 161 183 162 184 Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) { 163 return handle Type( aggregateUseType );185 return handleAggregateType( aggregateUseType ); 164 186 } 165 187 -
src/SynTree/TypeSubstitution.h
r9ed3237 r0ddb713 58 58 virtual Type* mutate(TypeInstType *aggregateUseType); 59 59 virtual Expression* mutate(NameExpr *nameExpr); 60 60 61 /// Records type variable bindings from forall-statements 61 62 template< typename TypeClass > Type *handleType( TypeClass *type ); 63 /// Records type variable bindings from forall-statements and instantiations of generic types 64 template< typename TypeClass > Type *handleAggregateType( TypeClass *type ); 62 65 63 66 virtual Type* mutate(VoidType *basicType); -
src/examples/Makefile.am
r9ed3237 r0ddb713 11 11 ## Created On : Sun May 31 09:08:15 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Thu Jun 4 23:13:10201514 ## Update Count : 2 213 ## Last Modified On : Fri Nov 20 16:03:46 2015 14 ## Update Count : 24 15 15 ############################################################################### 16 16 … … 19 19 CC = @CFA_BINDIR@/cfa 20 20 21 noinst_PROGRAMS = fstream_test vector_test 22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c 21 noinst_PROGRAMS = fstream_test vector_test # build but do not install 22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c 23 23 vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c -
src/examples/Makefile.in
r9ed3237 r0ddb713 49 49 PROGRAMS = $(noinst_PROGRAMS) 50 50 am_fstream_test_OBJECTS = iostream.$(OBJEXT) fstream.$(OBJEXT) \ 51 fstream_test.$(OBJEXT) 51 fstream_test.$(OBJEXT) iterator.$(OBJEXT) 52 52 fstream_test_OBJECTS = $(am_fstream_test_OBJECTS) 53 53 fstream_test_LDADD = $(LDADD) … … 176 176 top_builddir = @top_builddir@ 177 177 top_srcdir = @top_srcdir@ 178 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c 178 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c 179 179 vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c 180 180 all: all-am -
src/examples/fstream.c
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:12:33201513 // Update Count : 212 // Last Modified On : Thu Nov 19 22:43:31 2015 13 // Update Count : 4 14 14 // 15 15 … … 30 30 fwrite( data, size, 1, os->file ); 31 31 os->fail = ferror( os->file ); 32 } 32 } // if 33 33 return os; 34 } 34 } // write 35 35 36 36 int fail( ofstream *os ) { 37 37 return os->fail; 38 } 38 } // fail 39 39 40 40 static ofstream *make_ofstream() { … … 42 42 new_stream->fail = 0; 43 43 return new_stream; 44 } 44 } // make_ofstream 45 45 46 46 ofstream *ofstream_stdout() { … … 48 48 stdout_stream->file = stdout; 49 49 return stdout_stream; 50 } 50 } // ofstream_stdout 51 51 52 52 ofstream *ofstream_stderr() { … … 54 54 stderr_stream->file = stderr; 55 55 return stderr_stream; 56 } 56 } // ofstream_stderr 57 57 58 58 ofstream *ofstream_fromfile( const char *name ) { -
src/examples/hello.c
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:14:58201513 // Update Count : 112 // Last Modified On : Fri Nov 20 16:02:50 2015 13 // Update Count : 3 14 14 // 15 15 … … 28 28 // Local Variables: // 29 29 // tab-width: 4 // 30 // compile-command: "cfa hello.c fstream.o iostream.o " //30 // compile-command: "cfa hello.c fstream.o iostream.o iterator.o" // 31 31 // End: // -
src/examples/iostream.c
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:18:13201513 // Update Count : 212 // Last Modified On : Fri Nov 20 13:19:19 2015 13 // Update Count : 9 14 14 // 15 15 … … 17 17 extern "C" { 18 18 #include <stdio.h> 19 //#include <string.h> 20 //#include <ctype.h> 21 typedef long unsigned int size_t; 22 size_t strlen(const char *s); 19 #include <string.h> // strlen 23 20 } 24 21 … … 26 23 ostype * ?<<?( ostype *os, char c ) { 27 24 return write( os, &c, 1 ); 28 } 25 } // ?<<? 29 26 30 27 forall( dtype ostype | ostream( ostype ) ) 31 28 ostype * ?<<?( ostype *os, int i ) { 32 char buffer[ 20];// larger than the largest integer29 char buffer[32]; // larger than the largest integer 33 30 sprintf( buffer, "%d", i ); 34 31 return write( os, buffer, strlen( buffer ) ); 35 } 32 } // ?<<? 36 33 37 34 forall( dtype ostype | ostream( ostype ) ) 38 35 ostype * ?<<?( ostype *os, double d ) { 39 char buffer[32]; 36 char buffer[32]; // larger than the largest double 40 37 sprintf( buffer, "%g", d ); 41 38 return write( os, buffer, strlen( buffer ) ); 42 } 39 } // ?<<? 43 40 44 41 forall( dtype ostype | ostream( ostype ) ) 45 42 ostype * ?<<?( ostype *os, const char *cp ) { 46 43 return write( os, cp, strlen( cp ) ); 47 } 44 } // ?<<? 45 46 forall( dtype ostype | ostream( ostype ) ) 47 ostype * ?<<?( ostype *os, const void *p ) { 48 char buffer[32]; // larger than the largest pointer 49 sprintf( buffer, "%p", p ); 50 return write( os, buffer, strlen( buffer ) ); 51 } // ?<<? 52 53 forall( type elt_type | writeable( elt_type ), 54 type iterator_type | iterator( iterator_type, elt_type ), 55 dtype os_type | ostream( os_type ) ) 56 void write( iterator_type begin, iterator_type end, os_type *os ) { 57 void print( elt_type i ) { 58 os << i << ' '; 59 } 60 for_each( begin, end, print ); 61 } // ?<<? 62 63 forall( type elt_type | writeable( elt_type ), 64 type iterator_type | iterator( iterator_type, elt_type ), 65 dtype os_type | ostream( os_type ) ) 66 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 67 void print( elt_type i ) { 68 os << i << ' '; 69 } 70 for_each_reverse( begin, end, print ); 71 } // ?<<? 72 48 73 49 74 forall( dtype istype | istream( istype ) ) 50 75 istype * ?>>?( istype *is, char *cp ) { 51 76 return read( is, cp, 1 ); 52 } 77 } // ?>>? 53 78 54 79 forall( dtype istype | istream( istype ) ) … … 72 97 unread( is, cur ); 73 98 return is; 74 } 99 } // ?>>? 75 100 76 101 // Local Variables: // -
src/examples/iostream.h
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:18:46201513 // Update Count : 112 // Last Modified On : Thu Nov 19 17:56:51 2015 13 // Update Count : 5 14 14 // 15 15 16 16 #ifndef IOSTREAM_H 17 17 #define IOSTREAM_H 18 19 #include "iterator.h" 18 20 19 21 typedef unsigned long streamsize_type; … … 34 36 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double ); 35 37 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * ); 38 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * ); 39 40 // writes the range [begin, end) to the given stream 41 forall( type elt_type | writeable( elt_type ), 42 type iterator_type | iterator( iterator_type, elt_type ), 43 dtype os_type | ostream( os_type ) ) 44 void write( iterator_type begin, iterator_type end, os_type *os ); 45 46 forall( type elt_type | writeable( elt_type ), 47 type iterator_type | iterator( iterator_type, elt_type ), 48 dtype os_type | ostream( os_type ) ) 49 void write_reverse( iterator_type begin, iterator_type end, os_type *os ); 36 50 37 51 -
src/examples/iterator.c
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:41:41201513 // Update Count : 312 // Last Modified On : Thu Nov 19 17:54:37 2015 13 // Update Count : 24 14 14 // 15 15 16 16 #include "iterator.h" 17 17 18 /// forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 19 /// void 20 /// for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) 21 /// { 22 /// iterator_type i; 23 /// for ( i = begin; i != end; ++i ) { 24 /// func( *i ); 25 /// } 26 /// } 27 28 forall( type elt_type | writeable( elt_type ), 29 type iterator_type | iterator( iterator_type, elt_type ), 30 dtype os_type | ostream( os_type ) ) 31 void write_all( iterator_type begin, iterator_type end, os_type *os ) { 32 iterator_type i; 33 for ( i = begin; i != end; ++i ) { 34 os << *i << ' '; 18 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 19 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 20 for ( iterator_type i = begin; i != end; ++i ) { 21 func( *i ); 35 22 } 36 23 } 37 24 38 forall( type elt_type | writeable( elt_type ), 39 type iterator_type | iterator( iterator_type, elt_type ), 40 dtype os_type | ostream( os_type ) ) 41 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 42 iterator_type i; // "= end;" does not work 43 i = end; 44 do { 25 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 26 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 27 for ( iterator_type i = end; i != begin; ) { 45 28 --i; 46 os << *i << ' ';47 } while ( i != begin );29 func( *i ); 30 } 48 31 } 49 32 -
src/examples/iterator.h
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:41:57201513 // Update Count : 312 // Last Modified On : Thu Nov 19 17:58:28 2015 13 // Update Count : 6 14 14 // 15 15 16 16 #ifndef ITERATOR_H 17 17 #define ITERATOR_H 18 19 #include "iostream.h"20 18 21 19 // An iterator can be used to traverse a data structure. … … 34 32 }; 35 33 36 context iterator_for 34 context iterator_for( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) { 37 35 // [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); 38 36 iterator_type begin( collection_type ); … … 43 41 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 44 42 45 // writes the range [begin, end) to the given stream 46 forall( type elt_type | writeable( elt_type ), 47 type iterator_type | iterator( iterator_type, elt_type ), 48 dtype os_type | ostream( os_type ) ) 49 void write_all( iterator_type begin, iterator_type end, os_type *os ); 50 51 forall( type elt_type | writeable( elt_type ), 52 type iterator_type | iterator( iterator_type, elt_type ), 53 dtype os_type | ostream( os_type ) ) 54 void write_reverse( iterator_type begin, iterator_type end, os_type *os ); 43 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 44 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 55 45 56 46 #endif // ITERATOR_H -
src/examples/vector_test.c
r9ed3237 r0ddb713 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:42:55201513 // Update Count : 212 // Last Modified On : Thu Nov 19 17:54:34 2015 13 // Update Count : 9 14 14 // 15 15 … … 29 29 sout << "enter N elements and C-d on a separate line:\n"; 30 30 for ( ;; ) { 31 sin >> #31 sin >> # 32 32 if ( fail( sin ) || eof( sin ) ) break; 33 append( &vec, num );33 append( &vec, num ); 34 34 } 35 35 // write out the numbers 36 36 37 37 sout << "Array elements:\n"; 38 // write_all( begin( vec ), end( vec ), sout ); 39 // sout << "\n"; 40 for ( int index = 0; index <= last( vec ); index += 1 ) { 41 sout << vec[ index ] << " "; 42 } 38 write( begin( vec ), end( vec ), sout ); 43 39 sout << "\n"; 44 #if 1 40 45 41 sout << "Array elements reversed:\n"; 46 42 write_reverse( begin( vec ), end( vec ), sout ); 47 43 sout << "\n"; 48 #endif49 44 } 50 51 // ../bin/cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o52 45 53 46 // Local Variables: // -
src/libcfa/prelude.cf
r9ed3237 r0ddb713 7 7 // Author : Glen Ditchfield 8 8 // Created On : Sat Nov 29 07:23:41 2014 9 // Last Modified By : Peter A. Buhr10 // Last Modified On : T ue Jun 9 14:43:47 201511 // Update Count : 7 59 // Last Modified By : Rob Schluntz 10 // Last Modified On : Thu Nov 19 11:09:47 2015 11 // Update Count : 76 12 12 // 13 13 -
src/main.cc
r9ed3237 r0ddb713 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jul 30 16:08:18201513 // Update Count : 16 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 22:31:40 2015 13 // Update Count : 168 14 14 // 15 15 … … 24 24 #include "SynTree/Declaration.h" 25 25 #include "SynTree/Visitor.h" 26 #include "GenPoly/InstantiateGeneric.h" 26 27 #include "GenPoly/Lvalue.h" 27 28 #include "GenPoly/Specialize.h" … … 226 227 } // if 227 228 228 // add the assignment statement after the 229 // initialization of a type parameter 229 // add the assignment statement after the initialization of a type parameter 230 230 OPTPRINT( "validate" ) 231 231 SymTab::validate( translationUnit, symtabp ); … … 268 268 } 269 269 270 OPTPRINT( "instantiateGeneric" ) 271 GenPoly::instantiateGeneric( translationUnit ); 270 272 OPTPRINT( "copyParams" ); 271 273 GenPoly::copyParams( translationUnit );
Note: See TracChangeset
for help on using the changeset viewer.