Changes in / [0ddb713:9ed3237]
- Location:
- src
- Files:
-
- 6 deleted
- 25 edited
-
GenPoly/Box.cc (modified) (19 diffs)
-
GenPoly/Box.h (modified) (1 diff)
-
GenPoly/GenPoly.cc (modified) (2 diffs)
-
GenPoly/GenPoly.h (modified) (2 diffs)
-
GenPoly/InstantiateGeneric.cc (deleted)
-
GenPoly/InstantiateGeneric.h (deleted)
-
GenPoly/module.mk (modified) (1 diff)
-
Makefile.in (modified) (6 diffs)
-
Parser/TypeData.cc (modified) (1 diff)
-
ResolvExpr/Unify.cc (modified) (2 diffs)
-
SymTab/Validate.cc (modified) (13 diffs)
-
SynTree/Mutator.h (modified) (2 diffs)
-
SynTree/ReferenceToType.cc (modified) (2 diffs)
-
SynTree/Type.h (modified) (4 diffs)
-
SynTree/TypeSubstitution.cc (modified) (2 diffs)
-
SynTree/TypeSubstitution.h (modified) (1 diff)
-
examples/Makefile.am (modified) (2 diffs)
-
examples/Makefile.in (modified) (2 diffs)
-
examples/fstream.c (modified) (5 diffs)
-
examples/hello.c (modified) (2 diffs)
-
examples/iostream.c (modified) (4 diffs)
-
examples/iostream.h (modified) (2 diffs)
-
examples/iterator.c (modified) (1 diff)
-
examples/iterator.h (modified) (3 diffs)
-
examples/runTests.sh (deleted)
-
examples/tests/log.txt (deleted)
-
examples/tests/vector_test.in.txt (deleted)
-
examples/tests/vector_test.out.txt (deleted)
-
examples/vector_test.c (modified) (2 diffs)
-
libcfa/prelude.cf (modified) (1 diff)
-
main.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r0ddb713 r9ed3237 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Dec 02 11:52:37201513 // Update Count : 20112 // Last Modified On : Tue Aug 11 16:22:35 2015 13 // Update Count : 89 14 14 // 15 15 … … 47 47 namespace { 48 48 const std::list<Label> noLabels; 49 50 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );51 49 52 50 class Pass1 : public PolyMutator { … … 80 78 ObjectDecl *makeTemporary( Type *type ); 81 79 82 typedef std::map< std::string, DeclarationWithType*> AdapterMap;80 typedef std::map< std::string, FunctionDecl *> AdapterMap; 83 81 std::map< std::string, DeclarationWithType *> assignOps; 84 82 std::stack< AdapterMap > adapters; … … 142 140 143 141 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 produce148 // 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 need151 // to take those polymorphic types as pointers. Therefore, there can be two different functions152 // 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 } // for169 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 176 142 std::string makeAdapterName( const std::string &mangleName ) { 177 143 return "_adapter" + mangleName; 178 144 } 179 145 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 parameter 152 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 } // if 158 } // for 159 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) { 160 doTransform = true; 161 } // if 162 } // if 163 } // if 164 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 180 177 Pass1::Pass1() 181 178 : useRetval( false ), tempNamer( "_temp" ) { 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) 179 } 180 186 181 bool checkAssignment( DeclarationWithType *decl, std::string &name ) { 187 182 if ( decl->get_name() == "?=?" ) { … … 203 198 204 199 void Pass1::findAssignOps( const std::list< TypeDecl *> &forall ) { 205 // what if a nested function uses an assignment operator? 206 // assignOps.clear(); 200 assignOps.clear(); 207 201 for ( std::list< TypeDecl *>::const_iterator i = forall.begin(); i != forall.end(); ++i ) { 208 202 for ( std::list< DeclarationWithType *>::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { … … 216 210 217 211 DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) { 218 if ( functionDecl->get_statements() ) { // empty routine body ? 219 doBeginScope(); 212 if ( functionDecl->get_statements() ) { 220 213 TyVarMap oldtyVars = scopeTyVars; 221 std::map< std::string, DeclarationWithType *> oldassignOps = assignOps;222 214 DeclarationWithType *oldRetval = retval; 223 215 bool oldUseRetval = useRetval; 224 225 // process polymorphic return value 216 226 217 retval = 0; 227 218 std::string typeName; … … 236 227 } // if 237 228 238 FunctionType *functionType = functionDecl->get_functionType(); 229 scopeTyVars.clear(); 230 /// std::cerr << "clear\n"; 239 231 makeTyVarMap( functionDecl->get_functionType(), scopeTyVars ); 240 232 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 } // for248 } // for249 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {250 findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );251 } // for252 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 } // if259 } // for260 261 233 functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) ); 262 234 263 235 scopeTyVars = oldtyVars; 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"; 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"; 270 241 retval = oldRetval; 271 242 useRetval = oldUseRetval; 272 doEndScope();243 // doEndScope(); 273 244 } // if 274 245 return functionDecl; … … 377 348 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg ); 378 349 } // if 379 std::string mangleName = mangleAdapterName( function, tyVars);350 std::string mangleName = SymTab::Mangler::mangle( function ); 380 351 std::string adapterName = makeAdapterName( mangleName ); 381 352 … … 486 457 /// return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() ); 487 458 /// } else { 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 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; 494 463 /// } 495 464 } // if … … 575 544 } // for 576 545 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 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 579 549 std::set< std::string > adaptersDone; 580 550 … … 584 554 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 585 555 586 // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this587 // pre-substitution parameter function type.556 // only attempt to create an adapter or pass one as a parameter if we haven't 557 // already done so for this pre-substitution parameter function type. 588 558 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 559 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 589 560 adaptersDone.insert( adaptersDone.begin(), mangleName ); 590 561 591 // apply substitution to type variables to figure out what the adapter's type should look like 562 // apply substitution to type variables to figure out what the 563 // adapter's type should look like 592 564 assert( env ); 593 565 env->apply( realFunction ); 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 ) ); 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 ) ); 604 595 } // if 605 assert( adapter != adapters.end() );606 607 // add the appropriate adapter as a parameter608 appExpr->get_args().push_front( new VariableExpr( adapter->second ) );609 596 } // if 610 597 } // for 611 } // passAdapters598 } 612 599 613 600 TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) { … … 669 656 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars ); 670 657 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars ); 671 assert( ! typeInst1 || ! typeInst2 ); // the arguments cannot both be polymorphic pointers658 assert( ! typeInst1 || ! typeInst2 ); 672 659 UntypedExpr *ret = 0; 673 if ( typeInst1 || typeInst2 ) { // one of the arguments is a polymorphic pointer660 if ( typeInst1 || typeInst2 ) { 674 661 ret = new UntypedExpr( new NameExpr( "?+?" ) ); 675 662 } // if … … 782 769 783 770 Expression *Pass1::mutate( ApplicationExpr *appExpr ) { 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";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"; 789 776 bool oldUseRetval = useRetval; 790 777 useRetval = false; … … 812 799 ret = addPolyRetParam( appExpr, function, typeName, arg ); 813 800 } else if ( needsAdapter( function, scopeTyVars ) ) { 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";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"; 819 806 // change the application so it calls the adapter rather than the passed function 820 807 ret = applyAdapter( appExpr, function, arg, scopeTyVars ); … … 867 854 868 855 Statement * Pass1::mutate(ReturnStmt *retStmt) { 869 // by this point, a cast expr on a polymorphic return value is redundant856 // a cast expr on a polymorphic return value is either redundant or invalid 870 857 while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( retStmt->get_expr() ) ) { 871 858 retStmt->set_expr( castExpr->get_arg() ); … … 924 911 925 912 void Pass1::doBeginScope() { 926 // push a copy of the current map 927 adapters.push(adapters.top()); 913 // actually, maybe this could (should?) push 914 // a copy of the current map 915 adapters.push(AdapterMap()); 928 916 } 929 917 … … 946 934 std::set< std::string > adaptersDone; 947 935 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) { 948 std::string mangleName = mangleAdapterName( *funType, scopeTyVars);936 std::string mangleName = SymTab::Mangler::mangle( *funType ); 949 937 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 950 938 std::string adapterName = makeAdapterName( mangleName ); … … 1012 1000 for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1013 1001 ObjectDecl *thisParm; 1014 // add all size parameters to parameter list1015 1002 if ( (*tyParm)->get_kind() == TypeDecl::Any ) { 1016 1003 thisParm = newObj->clone(); … … 1019 1006 ++last; 1020 1007 } 1021 // move all assertions into parameter list1022 1008 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1023 1009 /// *assert = (*assert)->acceptMutator( *this ); -
src/GenPoly/Box.h
r0ddb713 r9ed3237 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Nov 19 17:24:01201513 // Update Count : 512 // Last Modified On : Tue May 19 07:32:33 2015 13 // Update Count : 2 14 14 // 15 15 -
src/GenPoly/GenPoly.cc
r0ddb713 r9ed3237 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Nov 24 15:23:08201513 // Update Count : 1 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:37:46 2015 13 // Update Count : 1 14 14 // 15 15 … … 21 21 22 22 namespace GenPoly { 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; 23 // interface functions 24 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 25 return isPolyVal( type, tyVars, false ); 35 26 } 36 27 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; 28 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 29 return needsAdapter( adaptee, tyVars, false ); 56 30 } 57 31 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 ) ) { 32 bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) { 33 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 70 34 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 71 35 return true; 72 36 } // if 37 return considerAllTyVars; 73 38 } // if 74 39 return false; 75 40 } 76 41 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 } 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; 85 55 } 86 56 -
src/GenPoly/GenPoly.h
r0ddb713 r9ed3237 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Nov 24 15:24:38201513 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:38:34 2015 13 // Update Count : 1 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. 29 27 30 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 ); 31 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ); 32 bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars ); 32 33 bool isPolyVal( Type *type, const TyVarMap &tyVars ); 33 34 // true if type variable or any number of pointers to type variable 35 bool isPolyObj( Type *type, const TyVarMap &tyVars ); 34 bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ); 36 35 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 37 36 } // namespace GenPoly -
src/GenPoly/module.mk
r0ddb713 r9ed3237 22 22 GenPoly/Specialize.cc \ 23 23 GenPoly/CopyParams.cc \ 24 GenPoly/FindFunction.cc \ 25 GenPoly/InstantiateGeneric.cc 24 GenPoly/FindFunction.cc -
src/Makefile.in
r0ddb713 r9ed3237 121 121 GenPoly/cfa_cpp-CopyParams.$(OBJEXT) \ 122 122 GenPoly/cfa_cpp-FindFunction.$(OBJEXT) \ 123 GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT) \124 123 InitTweak/cfa_cpp-InitModel.$(OBJEXT) \ 125 124 InitTweak/cfa_cpp-InitExpander.$(OBJEXT) \ … … 348 347 GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc GenPoly/Specialize.cc \ 349 348 GenPoly/CopyParams.cc GenPoly/FindFunction.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 \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 \ 358 357 ResolvExpr/AlternativeFinder.cc ResolvExpr/Alternative.cc \ 359 358 ResolvExpr/Unify.cc ResolvExpr/PtrsAssignable.cc \ … … 554 553 GenPoly/$(DEPDIR)/$(am__dirstamp) 555 554 GenPoly/cfa_cpp-FindFunction.$(OBJEXT): GenPoly/$(am__dirstamp) \ 556 GenPoly/$(DEPDIR)/$(am__dirstamp)557 GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT): GenPoly/$(am__dirstamp) \558 555 GenPoly/$(DEPDIR)/$(am__dirstamp) 559 556 InitTweak/$(am__dirstamp): … … 787 784 -rm -f GenPoly/cfa_cpp-FindFunction.$(OBJEXT) 788 785 -rm -f GenPoly/cfa_cpp-GenPoly.$(OBJEXT) 789 -rm -f GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT)790 786 -rm -f GenPoly/cfa_cpp-Lvalue.$(OBJEXT) 791 787 -rm -f GenPoly/cfa_cpp-PolyMutator.$(OBJEXT) … … 897 893 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-FindFunction.Po@am__quote@ 898 894 @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@900 895 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-Lvalue.Po@am__quote@ 901 896 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-PolyMutator.Po@am__quote@ … … 1362 1357 @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` 1363 1358 1364 GenPoly/cfa_cpp-InstantiateGeneric.o: GenPoly/InstantiateGeneric.cc1365 @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.cc1366 @am__fastdepCXX_TRUE@ $(am__mv) GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Tpo GenPoly/$(DEPDIR)/cfa_cpp-InstantiateGeneric.Po1367 @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.cc1370 1371 GenPoly/cfa_cpp-InstantiateGeneric.obj: GenPoly/InstantiateGeneric.cc1372 @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.Po1374 @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 1378 1359 InitTweak/cfa_cpp-InitModel.o: InitTweak/InitModel.cc 1379 1360 @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
r0ddb713 r9ed3237 799 799 case DeclarationNode::Struct: 800 800 at = new StructDecl( aggregate->name ); 801 buildForall( aggregate->params, at->get_parameters() );802 801 break; 803 802 case DeclarationNode::Union: 804 803 at = new UnionDecl( aggregate->name ); 805 buildForall( aggregate->params, at->get_parameters() );806 804 break; 807 805 case DeclarationNode::Context: 808 806 at = new ContextDecl( aggregate->name ); 809 buildList( aggregate->params, at->get_parameters() );810 807 break; 811 808 default: 812 809 assert( false ); 813 810 } // switch 814 //buildList( aggregate->params, at->get_parameters() );811 buildList( aggregate->params, at->get_parameters() ); 815 812 buildList( aggregate->fields, at->get_members() ); 816 813 -
src/ResolvExpr/Unify.cc
r0ddb713 r9ed3237 61 61 62 62 template< typename RefType > void handleRefType( RefType *inst, Type *other ); 63 template< typename RefType > void handleGenericRefType( RefType *inst, Type *other );64 63 65 64 bool result; … … 497 496 498 497 template< typename RefType > 499 void Unify::handleRefType( RefType *inst, Type *other ) { 500 // check that other type is compatible and named the same 498 void Unify::handleRefType( RefType *inst, Type *other ) { 501 499 RefType *otherStruct = dynamic_cast< RefType* >( other ); 502 500 result = otherStruct && inst->get_name() == otherStruct->get_name(); 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 } 501 } 528 502 529 503 void Unify::visit(StructInstType *structInst) { 530 handle GenericRefType( structInst, type2 );504 handleRefType( structInst, type2 ); 531 505 } 532 506 533 507 void Unify::visit(UnionInstType *unionInst) { 534 handle GenericRefType( unionInst, type2 );508 handleRefType( unionInst, type2 ); 535 509 } 536 510 -
src/SymTab/Validate.cc
r0ddb713 r9ed3237 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Fri Nov 20 16:33:52201513 // Update Count : 20111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 11 16:59:35 2015 13 // Update Count : 196 14 14 // 15 15 … … 126 126 }; 127 127 128 class A utogenerateRoutines: public Visitor {128 class AddStructAssignment : public Visitor { 129 129 public: 130 130 /// Generates assignment operators for aggregate types as required 131 static void a utogenerateRoutines( std::list< Declaration * > &translationUnit );131 static void addStructAssignment( 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 utogenerateRoutines() : functionNesting( 0 ) {}154 AddStructAssignment() : 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 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 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 ); 199 201 acceptAll( translationUnit, pass3 ); 200 202 } … … 500 502 static const std::list< std::string > noLabels; 501 503 502 void A utogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) {503 A utogenerateRoutinesvisitor;504 void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) { 505 AddStructAssignment visitor; 504 506 acceptAndAdd( translationUnit, visitor, false ); 505 507 } … … 625 627 } 626 628 627 /// Clones a reference type, replacing any parameters it may have with a clone of the provided list628 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 }635 629 636 630 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 637 631 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 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 ); 632 633 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 649 634 assignType->get_returnVals().push_back( returnVal ); 650 635 651 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams) ), 0 );636 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 ); 652 637 assignType->get_parameters().push_back( dstParam ); 653 638 654 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 );639 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 655 640 assignType->get_parameters().push_back( srcParam ); 656 641 … … 688 673 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 689 674 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 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 ); 675 676 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 701 677 assignType->get_returnVals().push_back( returnVal ); 702 678 703 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams) ), 0 );679 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 ); 704 680 assignType->get_parameters().push_back( dstParam ); 705 681 706 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 );682 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 707 683 assignType->get_parameters().push_back( srcParam ); 708 684 … … 715 691 copy->get_args().push_back( new VariableExpr( dstParam ) ); 716 692 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 717 copy->get_args().push_back( new SizeofExpr( cloneWithParams( refType, unionParams) ) );693 copy->get_args().push_back( new SizeofExpr( refType->clone() ) ); 718 694 719 695 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); … … 723 699 } 724 700 725 void A utogenerateRoutines::visit( EnumDecl *enumDecl ) {701 void AddStructAssignment::visit( EnumDecl *enumDecl ) { 726 702 if ( ! enumDecl->get_members().empty() ) { 727 703 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); … … 732 708 } 733 709 734 void A utogenerateRoutines::visit( StructDecl *structDecl ) {710 void AddStructAssignment::visit( StructDecl *structDecl ) { 735 711 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 736 StructInstType structInst( Type::Qualifiers(), structDecl->get_name() );737 structInst .set_baseStruct( structDecl );738 declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) );712 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); 713 structInst->set_baseStruct( structDecl ); 714 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) ); 739 715 structsDone.insert( structDecl->get_name() ); 740 716 } // if 741 717 } 742 718 743 void A utogenerateRoutines::visit( UnionDecl *unionDecl ) {719 void AddStructAssignment::visit( UnionDecl *unionDecl ) { 744 720 if ( ! unionDecl->get_members().empty() ) { 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 A utogenerateRoutines::visit( TypeDecl *typeDecl ) {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 AddStructAssignment::visit( TypeDecl *typeDecl ) { 752 728 CompoundStmt *stmts = 0; 753 729 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 777 753 } 778 754 779 void A utogenerateRoutines::visit( FunctionType *) {755 void AddStructAssignment::visit( FunctionType *) { 780 756 // ensure that we don't add assignment ops for types defined as part of the function 781 757 } 782 758 783 void A utogenerateRoutines::visit( PointerType *) {759 void AddStructAssignment::visit( PointerType *) { 784 760 // ensure that we don't add assignment ops for types defined as part of the pointer 785 761 } 786 762 787 void A utogenerateRoutines::visit( ContextDecl *) {763 void AddStructAssignment::visit( ContextDecl *) { 788 764 // ensure that we don't add assignment ops for types defined as part of the context 789 765 } 790 766 791 767 template< typename StmtClass > 792 inline void A utogenerateRoutines::visitStatement( StmtClass *stmt ) {768 inline void AddStructAssignment::visitStatement( StmtClass *stmt ) { 793 769 std::set< std::string > oldStructs = structsDone; 794 770 addVisit( stmt, *this ); … … 796 772 } 797 773 798 void A utogenerateRoutines::visit( FunctionDecl *functionDecl ) {774 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 799 775 maybeAccept( functionDecl->get_functionType(), *this ); 800 776 acceptAll( functionDecl->get_oldDecls(), *this ); … … 804 780 } 805 781 806 void A utogenerateRoutines::visit( CompoundStmt *compoundStmt ) {782 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 807 783 visitStatement( compoundStmt ); 808 784 } 809 785 810 void A utogenerateRoutines::visit( IfStmt *ifStmt ) {786 void AddStructAssignment::visit( IfStmt *ifStmt ) { 811 787 visitStatement( ifStmt ); 812 788 } 813 789 814 void A utogenerateRoutines::visit( WhileStmt *whileStmt ) {790 void AddStructAssignment::visit( WhileStmt *whileStmt ) { 815 791 visitStatement( whileStmt ); 816 792 } 817 793 818 void A utogenerateRoutines::visit( ForStmt *forStmt ) {794 void AddStructAssignment::visit( ForStmt *forStmt ) { 819 795 visitStatement( forStmt ); 820 796 } 821 797 822 void A utogenerateRoutines::visit( SwitchStmt *switchStmt ) {798 void AddStructAssignment::visit( SwitchStmt *switchStmt ) { 823 799 visitStatement( switchStmt ); 824 800 } 825 801 826 void A utogenerateRoutines::visit( ChooseStmt *switchStmt ) {802 void AddStructAssignment::visit( ChooseStmt *switchStmt ) { 827 803 visitStatement( switchStmt ); 828 804 } 829 805 830 void A utogenerateRoutines::visit( CaseStmt *caseStmt ) {806 void AddStructAssignment::visit( CaseStmt *caseStmt ) { 831 807 visitStatement( caseStmt ); 832 808 } 833 809 834 void A utogenerateRoutines::visit( CatchStmt *cathStmt ) {810 void AddStructAssignment::visit( CatchStmt *cathStmt ) { 835 811 visitStatement( cathStmt ); 836 812 } -
src/SynTree/Mutator.h
r0ddb713 r9ed3237 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 22:26:16201513 // Update Count : 812 // Last Modified On : Thu Jul 23 23:24:18 2015 13 // Update Count : 7 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
r0ddb713 r9ed3237 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 66 61 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 67 62 assert( baseStruct ); … … 70 65 71 66 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 }77 67 78 68 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { -
src/SynTree/Type.h
r0ddb713 r9ed3237 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 20 12:54:09201513 // Update Count : 1 512 // Last Modified On : Thu Jul 9 16:46:15 2015 13 // Update Count : 14 14 14 // 15 15 … … 201 201 std::list<DeclarationWithType*> parameters; 202 202 203 // Does the function accept a variable number of arguments following the arguments specified in the parameters list.204 // This could be because of203 // does the function accept a variable number of arguments following the arguments 204 // specified in the parameters list. 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 /// 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 239 240 // a utility function 245 241 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 246 242 … … 264 260 UnionDecl *get_baseUnion() const { return baseUnion; } 265 261 void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; } 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 262 263 // a utility function 272 264 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 273 265 -
src/SynTree/TypeSubstitution.cc
r0ddb713 r9ed3237 126 126 Type *TypeSubstitution::handleType( TypeClass *type ) { 127 127 BoundVarsType oldBoundVars( boundVars ); 128 // bind type variables from forall-qualifiers129 128 if ( freeOnly ) { 130 129 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 131 130 boundVars.insert( (*tyvar )->get_name() ); 132 } // for133 } // if134 Type *ret = Mutator::mutate( type );135 boundVars = oldBoundVars;136 return ret;137 }138 139 template< typename TypeClass >140 Type *TypeSubstitution::handleAggregateType( TypeClass *type ) {141 BoundVarsType oldBoundVars( boundVars );142 // bind type variables from forall-qualifiers143 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 } // for147 } // if148 // bind type variables from generic type instantiations149 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 131 } // for 154 132 } // if … … 179 157 180 158 Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) { 181 return handle AggregateType( aggregateUseType );159 return handleType( aggregateUseType ); 182 160 } 183 161 184 162 Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) { 185 return handle AggregateType( aggregateUseType );163 return handleType( aggregateUseType ); 186 164 } 187 165 -
src/SynTree/TypeSubstitution.h
r0ddb713 r9ed3237 58 58 virtual Type* mutate(TypeInstType *aggregateUseType); 59 59 virtual Expression* mutate(NameExpr *nameExpr); 60 61 /// Records type variable bindings from forall-statements 60 62 61 template< typename TypeClass > Type *handleType( TypeClass *type ); 63 /// Records type variable bindings from forall-statements and instantiations of generic types64 template< typename TypeClass > Type *handleAggregateType( TypeClass *type );65 62 66 63 virtual Type* mutate(VoidType *basicType); -
src/examples/Makefile.am
r0ddb713 r9ed3237 11 11 ## Created On : Sun May 31 09:08:15 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Fri Nov 20 16:03:46201514 ## Update Count : 2 413 ## Last Modified On : Thu Jun 4 23:13:10 2015 14 ## Update Count : 22 15 15 ############################################################################### 16 16 … … 19 19 CC = @CFA_BINDIR@/cfa 20 20 21 noinst_PROGRAMS = fstream_test vector_test # build but do not install22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c21 noinst_PROGRAMS = fstream_test vector_test 22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c 23 23 vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c -
src/examples/Makefile.in
r0ddb713 r9ed3237 49 49 PROGRAMS = $(noinst_PROGRAMS) 50 50 am_fstream_test_OBJECTS = iostream.$(OBJEXT) fstream.$(OBJEXT) \ 51 fstream_test.$(OBJEXT) iterator.$(OBJEXT)51 fstream_test.$(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 iterator.c178 fstream_test_SOURCES = iostream.c fstream.c fstream_test.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
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 22:43:31201513 // Update Count : 412 // Last Modified On : Wed May 27 18:12:33 2015 13 // Update Count : 2 14 14 // 15 15 … … 30 30 fwrite( data, size, 1, os->file ); 31 31 os->fail = ferror( os->file ); 32 } // if32 } 33 33 return os; 34 } // write34 } 35 35 36 36 int fail( ofstream *os ) { 37 37 return os->fail; 38 } // fail38 } 39 39 40 40 static ofstream *make_ofstream() { … … 42 42 new_stream->fail = 0; 43 43 return new_stream; 44 } // make_ofstream44 } 45 45 46 46 ofstream *ofstream_stdout() { … … 48 48 stdout_stream->file = stdout; 49 49 return stdout_stream; 50 } // ofstream_stdout50 } 51 51 52 52 ofstream *ofstream_stderr() { … … 54 54 stderr_stream->file = stderr; 55 55 return stderr_stream; 56 } // ofstream_stderr56 } 57 57 58 58 ofstream *ofstream_fromfile( const char *name ) { -
src/examples/hello.c
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 20 16:02:50201513 // Update Count : 312 // Last Modified On : Wed May 27 18:14:58 2015 13 // Update Count : 1 14 14 // 15 15 … … 28 28 // Local Variables: // 29 29 // tab-width: 4 // 30 // compile-command: "cfa hello.c fstream.o iostream.o iterator.o" //30 // compile-command: "cfa hello.c fstream.o iostream.o" // 31 31 // End: // -
src/examples/iostream.c
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 20 13:19:19201513 // Update Count : 912 // Last Modified On : Wed May 27 18:18:13 2015 13 // Update Count : 2 14 14 // 15 15 … … 17 17 extern "C" { 18 18 #include <stdio.h> 19 #include <string.h> // strlen 19 //#include <string.h> 20 //#include <ctype.h> 21 typedef long unsigned int size_t; 22 size_t strlen(const char *s); 20 23 } 21 24 … … 23 26 ostype * ?<<?( ostype *os, char c ) { 24 27 return write( os, &c, 1 ); 25 } // ?<<?28 } 26 29 27 30 forall( dtype ostype | ostream( ostype ) ) 28 31 ostype * ?<<?( ostype *os, int i ) { 29 char buffer[ 32];// larger than the largest integer32 char buffer[20]; // larger than the largest integer 30 33 sprintf( buffer, "%d", i ); 31 34 return write( os, buffer, strlen( buffer ) ); 32 } // ?<<?35 } 33 36 34 37 forall( dtype ostype | ostream( ostype ) ) 35 38 ostype * ?<<?( ostype *os, double d ) { 36 char buffer[32]; // larger than the largest double39 char buffer[32]; // larger than the largest double 37 40 sprintf( buffer, "%g", d ); 38 41 return write( os, buffer, strlen( buffer ) ); 39 } // ?<<?42 } 40 43 41 44 forall( dtype ostype | ostream( ostype ) ) 42 45 ostype * ?<<?( ostype *os, const char *cp ) { 43 46 return write( os, cp, strlen( cp ) ); 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 47 } 73 48 74 49 forall( dtype istype | istream( istype ) ) 75 50 istype * ?>>?( istype *is, char *cp ) { 76 51 return read( is, cp, 1 ); 77 } // ?>>?52 } 78 53 79 54 forall( dtype istype | istream( istype ) ) … … 97 72 unread( is, cur ); 98 73 return is; 99 } // ?>>?74 } 100 75 101 76 // Local Variables: // -
src/examples/iostream.h
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 17:56:51201513 // Update Count : 512 // Last Modified On : Wed May 27 18:18:46 2015 13 // Update Count : 1 14 14 // 15 15 16 16 #ifndef IOSTREAM_H 17 17 #define IOSTREAM_H 18 19 #include "iterator.h"20 18 21 19 typedef unsigned long streamsize_type; … … 36 34 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double ); 37 35 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 stream41 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 );50 36 51 37 -
src/examples/iterator.c
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 17:54:37201513 // Update Count : 2412 // Last Modified On : Wed May 27 18:41:41 2015 13 // Update Count : 3 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 for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 20 for ( iterator_type i = begin; i != end; ++i ) { 21 func( *i ); 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 << ' '; 22 35 } 23 36 } 24 37 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; ) { 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 { 28 45 --i; 29 func( *i );30 } 46 os << *i << ' '; 47 } while ( i != begin ); 31 48 } 32 49 -
src/examples/iterator.h
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 17:58:28201513 // Update Count : 612 // Last Modified On : Wed May 27 18:41:57 2015 13 // Update Count : 3 14 14 // 15 15 16 16 #ifndef ITERATOR_H 17 17 #define ITERATOR_H 18 19 #include "iostream.h" 18 20 19 21 // An iterator can be used to traverse a data structure. … … 32 34 }; 33 35 34 context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {36 context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) { 35 37 // [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); 36 38 iterator_type begin( collection_type ); … … 41 43 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 42 44 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 ) ); 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 ); 45 55 46 56 #endif // ITERATOR_H -
src/examples/vector_test.c
r0ddb713 r9ed3237 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 17:54:34201513 // Update Count : 912 // Last Modified On : Wed May 27 18:42:55 2015 13 // Update Count : 2 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( begin( vec ), end( vec ), sout ); 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 } 39 43 sout << "\n"; 40 44 #if 1 41 45 sout << "Array elements reversed:\n"; 42 46 write_reverse( begin( vec ), end( vec ), sout ); 43 47 sout << "\n"; 48 #endif 44 49 } 50 51 // ../bin/cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o 45 52 46 53 // Local Variables: // -
src/libcfa/prelude.cf
r0ddb713 r9ed3237 7 7 // Author : Glen Ditchfield 8 8 // Created On : Sat Nov 29 07:23:41 2014 9 // Last Modified By : Rob Schluntz10 // Last Modified On : T hu Nov 19 11:09:47 201511 // Update Count : 7 69 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Tue Jun 9 14:43:47 2015 11 // Update Count : 75 12 12 // 13 13 -
src/main.cc
r0ddb713 r9ed3237 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Nov 19 22:31:40201513 // Update Count : 16 811 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jul 30 16:08:18 2015 13 // Update Count : 167 14 14 // 15 15 … … 24 24 #include "SynTree/Declaration.h" 25 25 #include "SynTree/Visitor.h" 26 #include "GenPoly/InstantiateGeneric.h"27 26 #include "GenPoly/Lvalue.h" 28 27 #include "GenPoly/Specialize.h" … … 227 226 } // if 228 227 229 // add the assignment statement after the initialization of a type parameter 228 // add the assignment statement after the 229 // 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 );272 270 OPTPRINT( "copyParams" ); 273 271 GenPoly::copyParams( translationUnit );
Note:
See TracChangeset
for help on using the changeset viewer.