Changeset ae63a18


Ignore:
Timestamp:
Dec 18, 2015, 2:56:11 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, 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, string, with_gc
Children:
8762501
Parents:
baf7fee (diff), c23f807 (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.
Message:

resolving conflicts

Files:
1 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • configure

    rbaf7fee rae63a18  
    29992999        cfa_incdir="${cfa_prefix}/include"
    30003000else
    3001         cfa_incdir=${$includedir}
     3001        cfa_incdir=${includedir}
    30023002fi
    30033003
  • configure.ac

    rbaf7fee rae63a18  
    4141        cfa_incdir="${cfa_prefix}/include"
    4242else
    43         cfa_incdir=${$includedir}
     43        cfa_incdir=${includedir}
    4444fi
    4545AC_DEFINE_UNQUOTED(CFA_INCDIR, "${cfa_incdir}", [Location of include files.])
  • doc/refrat/refrat.tex

    rbaf7fee rae63a18  
    112112\lstset{
    113113language=CFA,
    114 columns=fullflexible,
     114columns=flexible,
    115115basicstyle=\sf\small,
    116116tabsize=4,
    117117xleftmargin=\parindent,
    118118escapechar=@,
    119 %fancyvrb=true,
     119keepspaces=true,
    120120%showtabs=true,
    121 keepspaces=true,
    122 showtabs=true,
    123 tab=,
     121%tab=\rightarrowfill,
    124122}%
    125123
  • src/GenPoly/Box.cc

    rbaf7fee rae63a18  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Box.cc -- 
     7// Box.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Dec 02 11:52:37 2015
    13 // Update Count     : 201
     12// Last Modified On : Fri Dec 18 14:53:08 2015
     13// Update Count     : 217
    1414//
    1515
     
    2828#include "Parser/ParseNode.h"
    2929
     30#include "SynTree/Constant.h"
    3031#include "SynTree/Type.h"
    3132#include "SynTree/Expression.h"
     
    6162                        virtual Expression *mutate( CommaExpr *commaExpr );
    6263                        virtual Expression *mutate( ConditionalExpr *condExpr );
    63                         virtual Statement *mutate(ReturnStmt *catchStmt);
     64                        virtual Statement * mutate( ReturnStmt *returnStmt );
    6465                        virtual Type *mutate( PointerType *pointerType );
    65                         virtual Type *mutate( FunctionType *pointerType );
    66  
     66                        virtual Type * mutate( FunctionType *functionType );
     67
    6768                        virtual void doBeginScope();
    6869                        virtual void doEndScope();
     
    9293                class Pass2 : public PolyMutator {
    9394                  public:
    94                         Pass2();
    9595                        template< typename DeclClass >
    9696                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    103103                  private:
    104104                        void addAdapters( FunctionType *functionType );
    105  
     105
    106106                        std::map< UniqueId, std::string > adapterName;
    107107                };
     
    151151                        // the correct thing in some situations. It's not clear to me why this wasn't working.
    152152
    153                         // if the return type or a parameter type involved polymorphic types, then the adapter will need 
    154                         // to take those polymorphic types as pointers. Therefore, there can be two different functions 
     153                        // if the return type or a parameter type involved polymorphic types, then the adapter will need
     154                        // to take those polymorphic types as pointers. Therefore, there can be two different functions
    155155                        // with the same mangled name, so we need to further mangle the names.
    156156                        for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) {
    157                                 if ( isPolyVal( (*retval)->get_type(), tyVars ) ) {
     157                                if ( isPolyType( (*retval)->get_type(), tyVars ) ) {
    158158                                        name << "P";
    159159                                } else {
     
    164164                        std::list< DeclarationWithType *> &paramList = function->get_parameters();
    165165                        for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    166                                 if ( isPolyVal( (*arg)->get_type(), tyVars ) ) {
     166                                if ( isPolyType( (*arg)->get_type(), tyVars ) ) {
    167167                                        name << "P";
    168168                                } else {
    169                                         name << "M";                           
     169                                        name << "M";
    170170                                }
    171171                        } // for
     
    181181                }
    182182
    183                 Pass1::Pass1()
    184                         : useRetval( false ), tempNamer( "_temp" ) {
     183                Pass1::Pass1() : useRetval( false ), tempNamer( "_temp" ) {
    185184                        adapters.push(AdapterMap());
    186185                }
     
    194193                                                        if ( PointerType *pointer = dynamic_cast< PointerType *>( funType->get_parameters().front()->get_type() ) ) {
    195194                                                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( pointer->get_base() ) ) {
    196                                                                         name = typeInst->get_name();
    197                                                                         return true;
     195                                                                        if ( TypeInstType *typeInst2 = dynamic_cast< TypeInstType *>( funType->get_parameters().back()->get_type() ) ) {
     196                                                                                if ( typeInst->get_name() == typeInst2->get_name() ) {
     197                                                                                        name = typeInst->get_name();
     198                                                                                        return true;
     199                                                                                } // if
     200                                                                        } // if
    198201                                                                } // if
    199202                                                        } // if
     
    231234                                if ( isPolyRet( functionDecl->get_functionType(), typeName ) && functionDecl->get_linkage() == LinkageSpec::Cforall ) {
    232235                                        retval = functionDecl->get_functionType()->get_returnVals().front();
    233  
     236
    234237                                        // give names to unnamed return values
    235238                                        if ( retval->get_name() == "" ) {
     
    238241                                        } // if
    239242                                } // if
    240        
     243
    241244                                FunctionType *functionType = functionDecl->get_functionType();
    242245                                makeTyVarMap( functionDecl->get_functionType(), scopeTyVars );
     
    263266
    264267                                functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) );
    265  
     268
    266269                                scopeTyVars = oldtyVars;
    267270                                assignOps = oldassignOps;
     
    279282
    280283                TypeDecl *Pass1::mutate( TypeDecl *typeDecl ) {
    281 ///     std::cerr << "add " << typeDecl->get_name() << "\n";
    282284                        scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
    283285                        return Mutator::mutate( typeDecl );
     
    305307
    306308                void Pass1::passTypeVars( ApplicationExpr *appExpr, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
     309                        // pass size/align for type variables
    307310                        for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
    308311                                ResolvExpr::EqvClass eqvClass;
     
    313316                                                arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) );
    314317                                                arg++;
     318                                                arg = appExpr->get_args().insert( arg, new AlignofExpr( concrete->clone() ) );
     319                                                arg++;
    315320                                        } else {
    316321                                                throw SemanticError( "unbound type variable in application ", appExpr );
     
    318323                                } // if
    319324                        } // for
     325
     326                        // add size/align for generic types to parameter list
     327                        //assert( ! appExpr->get_function()->get_results().empty() );
     328                        if ( appExpr->get_function()->get_results().empty() ) return;
     329                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() );
     330                        assert( funcType );
     331
     332                        std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();
     333                        std::list< Expression* >::const_iterator fnArg = arg;
     334                        std::set< std::string > seenTypes; //< names for generic types we've seen
     335                        for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
     336                                Type *parmType = (*fnParm)->get_type();
     337                                if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, exprTyVars ) ) {
     338                                        std::string sizeName = sizeofName( parmType );
     339                                        if ( seenTypes.count( sizeName ) ) continue;
     340
     341                                        assert( ! (*fnArg)->get_results().empty() );
     342                                        Type *argType = (*fnArg)->get_results().front();
     343                                        arg = appExpr->get_args().insert( arg, new SizeofExpr( argType->clone() ) );
     344                                        arg++;
     345                                        arg = appExpr->get_args().insert( arg, new AlignofExpr( argType->clone() ) );
     346                                        arg++;
     347
     348                                        seenTypes.insert( sizeName );
     349                                }
     350                        }
    320351                }
    321352
     
    326357                }
    327358
    328                 TypeInstType *isPolyType( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
    329                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    330                                 if ( env ) {
    331                                         if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    332                                                 return isPolyType( newType, env, tyVars );
    333                                         } // if
    334                                 } // if
    335                                 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    336                                         return typeInst;
    337                                 } else {
    338                                         return 0;
    339                                 } // if
    340                         } else {
    341                                 return 0;
    342                         } // if
    343                 }
    344 
    345359                Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
    346                         if ( useRetval ) {
    347                                 assert( retval );
    348                                 arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
    349                                 arg++;
    350                         } else {
    351                                 ObjectDecl *newObj = makeTemporary( retType->clone() );
    352                                 Expression *paramExpr = new VariableExpr( newObj );
    353                                 if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) {
    354                                         paramExpr = new AddressExpr( paramExpr );
    355                                 } // if
    356                                 arg = appExpr->get_args().insert( arg, paramExpr );
    357                                 arg++;
    358 ///     stmtsToAdd.push_back( new ExprStmt( noLabels, appExpr ) );
    359                                 CommaExpr *commaExpr = new CommaExpr( appExpr, new VariableExpr( newObj ) );
    360                                 commaExpr->set_env( appExpr->get_env() );
    361                                 appExpr->set_env( 0 );
    362                                 return commaExpr;
    363                         } // if
    364                         return appExpr;
     360                        // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
     361                        // if ( useRetval ) {
     362                        //      assert( retval );
     363                        //      arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
     364                        //      arg++;
     365                        // } else {
     366
     367                        // Create temporary to hold return value of polymorphic function and produce that temporary as a result
     368                        // using a comma expression.  Possibly change comma expression into statement expression "{}" for multiple
     369                        // return values.
     370                        ObjectDecl *newObj = makeTemporary( retType->clone() );
     371                        Expression *paramExpr = new VariableExpr( newObj );
     372                        // If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the
     373                        // temporary is already boxed and can be used directly.
     374                        if ( ! isPolyType( newObj->get_type(), scopeTyVars, env ) ) {
     375                                paramExpr = new AddressExpr( paramExpr );
     376                        } // if
     377                        arg = appExpr->get_args().insert( arg, paramExpr ); // add argument to function call
     378                        arg++;
     379                        // Build a comma expression to call the function and emulate a normal return.
     380                        CommaExpr *commaExpr = new CommaExpr( appExpr, new VariableExpr( newObj ) );
     381                        commaExpr->set_env( appExpr->get_env() );
     382                        appExpr->set_env( 0 );
     383                        return commaExpr;
     384                        // } // if
     385                        // return appExpr;
    365386                }
    366387
     
    377398                Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) {
    378399                        Expression *ret = appExpr;
    379                         if ( ! function->get_returnVals().empty() && isPolyVal( function->get_returnVals().front()->get_type(), tyVars ) ) {
     400                        if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
    380401                                ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
    381402                        } // if
     
    385406                        appExpr->get_args().push_front( appExpr->get_function() );
    386407                        appExpr->set_function( new NameExpr( adapterName ) );
    387  
     408
    388409                        return ret;
    389410                }
     
    391412                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    392413                        assert( ! arg->get_results().empty() );
    393 ///   if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {
     414//   if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {
    394415                        TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param );
    395416                        if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) {
     
    411432                                } // if
    412433                        } // if
    413 ///   }
     434//   }
    414435                }
    415436
     
    428449
    429450                void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
    430 ///   std::cout << "function is ";
    431 ///   function->print( std::cout );
    432451                        for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) {
    433 ///     std::cout << "parameter is ";
    434 ///     (*param)->print( std::fcout );
    435 ///     std::cout << std::endl << "argument is ";
    436 ///     (*arg)->print( std::cout );
    437452                                assert( arg != appExpr->get_args().end() );
    438453                                addCast( *arg, (*param)->get_type(), exprTyVars );
     
    469484                        // actually make the adapter type
    470485                        FunctionType *adapter = adaptee->clone();
    471                         if ( ! adapter->get_returnVals().empty() && isPolyVal( adapter->get_returnVals().front()->get_type(), tyVars ) ) {
     486                        if ( ! adapter->get_returnVals().empty() && isPolyType( adapter->get_returnVals().front()->get_type(), tyVars ) ) {
    472487                                makeRetParm( adapter );
    473488                        } // if
     
    479494                        assert( param );
    480495                        assert( arg );
    481 ///   std::cout << "arg type is ";
    482 ///   arg->get_type()->print( std::cout );
    483 ///   std::cout << "param type is ";
    484 ///   param->get_type()->print( std::cout );
    485 ///   std::cout << " tyVars are: ";
    486 ///   printTyVarMap( std::cout, tyVars );
    487                         if ( isPolyVal( realParam->get_type(), tyVars ) ) {
    488 ///     if ( dynamic_cast< PointerType *>( arg->get_type() ) ) {
    489 ///       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
    490 ///     } else {
     496                        if ( isPolyType( realParam->get_type(), tyVars ) ) {
     497//     if ( dynamic_cast< PointerType *>( arg->get_type() ) ) {
     498//       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
     499//     } else {
    491500                                if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) {
    492501                                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     
    495504                                        return deref;
    496505                                } // if
    497 ///     }
     506//     }
    498507                        } // if
    499508                        return new VariableExpr( param );
     
    520529                        ApplicationExpr *adapteeApp = new ApplicationExpr( new CastExpr( new VariableExpr( adapteeDecl ), new PointerType( Type::Qualifiers(), realType ) ) );
    521530                        Statement *bodyStmt;
    522  
     531
    523532                        std::list< TypeDecl *>::iterator tyArg = realType->get_forall().begin();
    524533                        std::list< TypeDecl *>::iterator tyParam = adapterType->get_forall().begin();
     
    534543                                } // for
    535544                        } // for
    536  
     545
    537546                        std::list< DeclarationWithType *>::iterator arg = realType->get_parameters().begin();
    538547                        std::list< DeclarationWithType *>::iterator param = adapterType->get_parameters().begin();
     
    542551                                addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
    543552                                bodyStmt = new ExprStmt( noLabels, adapteeApp );
    544                         } else if ( isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     553                        } else if ( isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    545554                                if ( (*param)->get_name() == "" ) {
    546555                                        (*param)->set_name( "_ret" );
     
    591600                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
    592601                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
    593                                        
     602
    594603                                        // apply substitution to type variables to figure out what the adapter's type should look like
    595604                                        assert( env );
    596605                                        env->apply( realFunction );
    597                                         mangleName = SymTab::Mangler::mangle( realFunction ); 
     606                                        mangleName = SymTab::Mangler::mangle( realFunction );
    598607                                        mangleName += makePolyMonoSuffix( originalFunction, exprTyVars );
    599608
     
    614623                } // passAdapters
    615624
    616                 TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
    617                         if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    618                                 return isPolyType( ptr->get_base(), env, tyVars );
    619                         } else if ( env ) {
    620                                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    621                                         if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    622                                                 return isPolyPtr( newType, env, tyVars );
    623                                         } // if
    624                                 } // if
    625                         } // if
    626                         return 0;
    627                 }
    628 
    629                 TypeInstType *isPolyPtrPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
    630                         if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    631                                 return isPolyPtr( ptr->get_base(), env, tyVars );
    632                         } else if ( env ) {
    633                                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    634                                         if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    635                                                 return isPolyPtrPtr( newType, env, tyVars );
    636                                         } // if
    637                                 } // if
    638                         } // if
    639                         return 0;
    640                 }
    641 
    642                 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, std::string polyName, bool isIncr ) {
     625                Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) {
    643626                        NameExpr *opExpr;
    644627                        if ( isIncr ) {
     
    653636                                addAssign->get_args().push_back( appExpr->get_args().front() );
    654637                        } // if
    655                         addAssign->get_args().push_back( new NameExpr( polyName ) );
     638                        addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) );
    656639                        addAssign->get_results().front() = appExpr->get_results().front()->clone();
    657640                        if ( appExpr->get_env() ) {
     
    670653                                                assert( ! appExpr->get_results().empty() );
    671654                                                assert( appExpr->get_args().size() == 2 );
    672                                                 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars );
    673                                                 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars );
    674                                                 assert( ! typeInst1 || ! typeInst2 ); // the arguments cannot both be polymorphic pointers
     655                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
     656                                                Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
     657                                                assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers
    675658                                                UntypedExpr *ret = 0;
    676                                                 if ( typeInst1 || typeInst2 ) { // one of the arguments is a polymorphic pointer
     659                                                if ( baseType1 || baseType2 ) { // one of the arguments is a polymorphic pointer
    677660                                                        ret = new UntypedExpr( new NameExpr( "?+?" ) );
    678661                                                } // if
    679                                                 if ( typeInst1 ) {
     662                                                if ( baseType1 ) {
    680663                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    681664                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    682                                                         multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
     665                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
    683666                                                        ret->get_args().push_back( appExpr->get_args().front() );
    684667                                                        ret->get_args().push_back( multiply );
    685                                                 } else if ( typeInst2 ) {
     668                                                } else if ( baseType2 ) {
    686669                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    687670                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    688                                                         multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );
     671                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
    689672                                                        ret->get_args().push_back( multiply );
    690673                                                        ret->get_args().push_back( appExpr->get_args().back() );
    691674                                                } // if
    692                                                 if ( typeInst1 || typeInst2 ) {
     675                                                if ( baseType1 || baseType2 ) {
    693676                                                        ret->get_results().push_front( appExpr->get_results().front()->clone() );
    694677                                                        if ( appExpr->get_env() ) {
     
    703686                                                assert( ! appExpr->get_results().empty() );
    704687                                                assert( ! appExpr->get_args().empty() );
    705                                                 if ( isPolyType( appExpr->get_results().front(), env, scopeTyVars ) ) {
     688                                                if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) {
    706689                                                        Expression *ret = appExpr->get_args().front();
    707690                                                        delete ret->get_results().front();
     
    718701                                                assert( ! appExpr->get_results().empty() );
    719702                                                assert( appExpr->get_args().size() == 1 );
    720                                                 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
     703                                                if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
    721704                                                        Type *tempType = appExpr->get_results().front()->clone();
    722705                                                        if ( env ) {
     
    732715                                                                assignExpr->get_args().push_back( appExpr->get_args().front()->clone() );
    733716                                                        } // if
    734                                                         CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst->get_name(), varExpr->get_var()->get_name() == "?++" ) );
     717                                                        CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "?++" ) );
    735718                                                        return new CommaExpr( firstComma, tempExpr );
    736719                                                } // if
     
    738721                                                assert( ! appExpr->get_results().empty() );
    739722                                                assert( appExpr->get_args().size() == 1 );
    740                                                 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
    741                                                         return makeIncrDecrExpr( appExpr, typeInst->get_name(), varExpr->get_var()->get_name() == "++?" );
     723                                                if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
     724                                                        return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" );
    742725                                                } // if
    743726                                        } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
    744727                                                assert( ! appExpr->get_results().empty() );
    745728                                                assert( appExpr->get_args().size() == 2 );
    746                                                 TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars );
    747                                                 TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars );
    748                                                 if ( typeInst1 && typeInst2 ) {
     729                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
     730                                                Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
     731                                                if ( baseType1 && baseType2 ) {
    749732                                                        UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
    750733                                                        divide->get_args().push_back( appExpr );
    751                                                         divide->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
     734                                                        divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
    752735                                                        divide->get_results().push_front( appExpr->get_results().front()->clone() );
    753736                                                        if ( appExpr->get_env() ) {
     
    756739                                                        } // if
    757740                                                        return divide;
    758                                                 } else if ( typeInst1 ) {
     741                                                } else if ( baseType1 ) {
    759742                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    760743                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    761                                                         multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
     744                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
    762745                                                        appExpr->get_args().back() = multiply;
    763                                                 } else if ( typeInst2 ) {
     746                                                } else if ( baseType2 ) {
    764747                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    765748                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    766                                                         multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );
     749                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
    767750                                                        appExpr->get_args().front() = multiply;
    768751                                                } // if
     
    770753                                                assert( ! appExpr->get_results().empty() );
    771754                                                assert( appExpr->get_args().size() == 2 );
    772                                                 TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars );
    773                                                 if ( typeInst ) {
     755                                                Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env );
     756                                                if ( baseType ) {
    774757                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    775758                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    776                                                         multiply->get_args().push_back( new NameExpr( typeInst->get_name() ) );
     759                                                        multiply->get_args().push_back( new NameExpr( sizeofName( baseType ) ) );
    777760                                                        appExpr->get_args().back() = multiply;
    778761                                                } // if
     
    795778                        mutateAll( appExpr->get_args(), *this );
    796779                        useRetval = oldUseRetval;
    797  
     780
    798781                        assert( ! appExpr->get_function()->get_results().empty() );
    799782                        PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
     
    801784                        FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
    802785                        assert( function );
    803  
     786
    804787                        if ( Expression *newExpr = handleIntrinsics( appExpr ) ) {
    805788                                return newExpr;
    806789                        } // if
    807  
     790
    808791                        Expression *ret = appExpr;
    809  
     792
    810793                        std::list< Expression *>::iterator arg = appExpr->get_args().begin();
    811794                        std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin();
    812  
     795
    813796                        std::string typeName;
    814797                        if ( isPolyRet( function, typeName ) ) {
     
    824807                        } // if
    825808                        arg = appExpr->get_args().begin();
    826  
     809
    827810                        TyVarMap exprTyVars;
    828811                        makeTyVarMap( function, exprTyVars );
    829  
     812
    830813                        passTypeVars( appExpr, arg, exprTyVars );
    831814                        addInferredParams( appExpr, function, arg, exprTyVars );
    832815
    833816                        arg = paramBegin;
    834  
     817
    835818                        boxParams( appExpr, function, arg, exprTyVars );
    836819
     
    841824
    842825                Expression *Pass1::mutate( UntypedExpr *expr ) {
    843                         if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) {
     826                        if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
    844827                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    845828                                        if ( name->get_name() == "*?" ) {
     
    856839                Expression *Pass1::mutate( AddressExpr *addrExpr ) {
    857840                        assert( ! addrExpr->get_arg()->get_results().empty() );
     841
     842                        bool needs = false;
     843                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
     844                                if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     845                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
     846                                                if ( name->get_name() == "*?" ) {
     847                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
     848                                                                assert( ! appExpr->get_function()->get_results().empty() );
     849                                                                PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
     850                                                                assert( pointer );
     851                                                                FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
     852                                                                assert( function );
     853                                                                needs = needsAdapter( function, scopeTyVars );
     854                                                        } // if
     855                                                } // if
     856                                        } // if
     857                                } // if
     858                        } // if
    858859                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    859                         if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) ) {
     860                        if ( isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env ) || needs ) {
    860861                                Expression *ret = addrExpr->get_arg();
    861862                                delete ret->get_results().front();
     
    869870                }
    870871
    871                 Statement * Pass1::mutate(ReturnStmt *retStmt) {
    872                         // by this point, a cast expr on a polymorphic return value is redundant
    873                         while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( retStmt->get_expr() ) ) {
    874                                 retStmt->set_expr( castExpr->get_arg() );
    875                                 retStmt->get_expr()->set_env( castExpr->get_env() );
    876                                 castExpr->set_env( 0 );
    877                                 castExpr->set_arg( 0 );
    878                                 delete castExpr;
    879                         }
    880                         if ( retval && retStmt->get_expr() ) {
    881                                 assert( ! retStmt->get_expr()->get_results().empty() );
    882                                 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
    883 ///       retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
    884                                         TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
    885                                         assert( typeInst );
    886                                         std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
    887                                         if ( assignIter == assignOps.end() ) {
    888                                                 throw SemanticError( "Attempt to return dtype or ftype object in ", retStmt->get_expr() );
    889                                         } // if
    890                                         ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
    891                                         Expression *retParm = new NameExpr( retval->get_name() );
    892                                         retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
    893                                         assignExpr->get_args().push_back( retParm );
    894                                         assignExpr->get_args().push_back( retStmt->get_expr() );
    895                                         stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
    896                                 } else {
    897                                         useRetval = true;
    898                                         stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( retStmt->get_expr() ) ) );
    899                                         useRetval = false;
     872                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
     873                        if ( retval && returnStmt->get_expr() ) {
     874                                assert( ! returnStmt->get_expr()->get_results().empty() );
     875                                // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
     876                                // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     877                                // by this point, a cast expr on a polymorphic return value is redundant
     878                                while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( returnStmt->get_expr() ) ) {
     879                                        returnStmt->set_expr( castExpr->get_arg() );
     880                                        returnStmt->get_expr()->set_env( castExpr->get_env() );
     881                                        castExpr->set_env( 0 );
     882                                        castExpr->set_arg( 0 );
     883                                        delete castExpr;
     884                                } //while
     885                                TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
     886                                assert( typeInst );
     887                                std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
     888                                if ( assignIter == assignOps.end() ) {
     889                                        throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() );
    900890                                } // if
    901                                 retStmt->set_expr( 0 );
     891                                ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
     892                                Expression *retParm = new NameExpr( retval->get_name() );
     893                                retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     894                                assignExpr->get_args().push_back( retParm );
     895                                assignExpr->get_args().push_back( returnStmt->get_expr() );
     896                                stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
     897                                // } else {
     898                                //      useRetval = true;
     899                                //      stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( returnStmt->get_expr() ) ) );
     900                                //      useRetval = false;
     901                                // } // if
     902                                returnStmt->set_expr( 0 );
    902903                        } else {
    903                                 retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
    904                         } // if
    905                         return retStmt;
     904                                returnStmt->set_expr( mutateExpression( returnStmt->get_expr() ) );
     905                        } // if
     906                        return returnStmt;
    906907                }
    907908
     
    909910                        TyVarMap oldtyVars = scopeTyVars;
    910911                        makeTyVarMap( pointerType, scopeTyVars );
    911  
     912
    912913                        Type *ret = Mutator::mutate( pointerType );
    913  
     914
    914915                        scopeTyVars = oldtyVars;
    915916                        return ret;
     
    919920                        TyVarMap oldtyVars = scopeTyVars;
    920921                        makeTyVarMap( functionType, scopeTyVars );
    921  
     922
    922923                        Type *ret = Mutator::mutate( functionType );
    923  
     924
    924925                        scopeTyVars = oldtyVars;
    925926                        return ret;
     
    936937
    937938////////////////////////////////////////// Pass2 ////////////////////////////////////////////////////
    938 
    939                 Pass2::Pass2() {}
    940939
    941940                void Pass2::addAdapters( FunctionType *functionType ) {
     
    956955                                }
    957956                        }
    958 ///  deleteAll( functions );
     957//  deleteAll( functions );
    959958                }
    960959
     
    990989                        TyVarMap oldtyVars = scopeTyVars;
    991990                        makeTyVarMap( pointerType, scopeTyVars );
    992  
     991
    993992                        Type *ret = Mutator::mutate( pointerType );
    994  
     993
    995994                        scopeTyVars = oldtyVars;
    996995                        return ret;
     
    1000999                        TyVarMap oldtyVars = scopeTyVars;
    10011000                        makeTyVarMap( funcType, scopeTyVars );
    1002  
     1001
     1002                        // move polymorphic return type to parameter list
    10031003                        std::string typeName;
    10041004                        if ( isPolyRet( funcType, typeName ) ) {
     
    10081008                                funcType->get_returnVals().pop_front();
    10091009                        }
    1010  
     1010
     1011                        // add size/align and assertions for type parameters to parameter list
    10111012                        std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
    10121013                        std::list< DeclarationWithType *> inferredParams;
    1013                         ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
     1014                        ObjectDecl newObj( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
    10141015//   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
    10151016                        for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    1016                                 ObjectDecl *thisParm;
    1017                                 // add all size parameters to parameter list
     1017                                ObjectDecl *sizeParm, *alignParm;
     1018                                // add all size and alignment parameters to parameter list
    10181019                                if ( (*tyParm)->get_kind() == TypeDecl::Any ) {
    1019                                         thisParm = newObj->clone();
    1020                                         thisParm->set_name( (*tyParm)->get_name() );
    1021                                         last = funcType->get_parameters().insert( last, thisParm );
     1020                                        TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
     1021
     1022                                        sizeParm = newObj.clone();
     1023                                        sizeParm->set_name( sizeofName( &parmType ) );
     1024                                        last = funcType->get_parameters().insert( last, sizeParm );
     1025                                        ++last;
     1026
     1027                                        alignParm = newObj.clone();
     1028                                        alignParm->set_name( alignofName( &parmType ) );
     1029                                        last = funcType->get_parameters().insert( last, alignParm );
    10221030                                        ++last;
    10231031                                }
     
    10291037                                (*tyParm)->get_assertions().clear();
    10301038                        }
    1031                         delete newObj;
     1039
     1040                        // add size/align for generic types to parameter list
     1041                        std::set< std::string > seenTypes; //< sizeofName for generic types we've seen
     1042                        for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
     1043                                Type *parmType = (*fnParm)->get_type();
     1044                                if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, scopeTyVars ) ) {
     1045                                        std::string sizeName = sizeofName( parmType );
     1046                                        if ( seenTypes.count( sizeName ) ) continue;
     1047
     1048                                        ObjectDecl *sizeParm, *alignParm;
     1049                                        sizeParm = newObj.clone();
     1050                                        sizeParm->set_name( sizeName );
     1051                                        last = funcType->get_parameters().insert( last, sizeParm );
     1052                                        ++last;
     1053
     1054                                        alignParm = newObj.clone();
     1055                                        alignParm->set_name( alignofName( parmType ) );
     1056                                        last = funcType->get_parameters().insert( last, alignParm );
     1057                                        ++last;
     1058
     1059                                        seenTypes.insert( sizeName );
     1060                                }
     1061                        }
     1062
     1063                        // splice assertion parameters into parameter list
    10321064                        funcType->get_parameters().splice( last, inferredParams );
    10331065                        addAdapters( funcType );
    10341066                        mutateAll( funcType->get_returnVals(), *this );
    10351067                        mutateAll( funcType->get_parameters(), *this );
    1036  
     1068
    10371069                        scopeTyVars = oldtyVars;
    10381070                        return funcType;
     
    10451077                        TyVarMap oldtyVars = scopeTyVars;
    10461078                        makeTyVarMap( type, scopeTyVars );
    1047  
     1079
    10481080                        DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
    10491081                        ScrubTyVars::scrub( decl, scopeTyVars );
     
    10811113                        TyVarMap oldtyVars = scopeTyVars;
    10821114                        makeTyVarMap( pointerType, scopeTyVars );
    1083  
     1115
    10841116                        Type *ret = Mutator::mutate( pointerType );
    1085  
     1117
    10861118                        scopeTyVars = oldtyVars;
    10871119                        return ret;
     
    10911123                        TyVarMap oldtyVars = scopeTyVars;
    10921124                        makeTyVarMap( functionType, scopeTyVars );
    1093  
     1125
    10941126                        Type *ret = Mutator::mutate( functionType );
    1095  
     1127
    10961128                        scopeTyVars = oldtyVars;
    10971129                        return ret;
     
    11001132                Statement *Pass3::mutate( DeclStmt *declStmt ) {
    11011133                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    1102                                 if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) {
     1134                                if ( isPolyType( objectDecl->get_type(), scopeTyVars ) ) {
    11031135                                        // change initialization of a polymorphic value object
    11041136                                        // to allocate storage with alloca
    1105                                         TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() );
    1106                                         assert( typeInst );
     1137                                        Type *declType = objectDecl->get_type();
    11071138                                        UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
    1108                                         alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) );
     1139                                        alloc->get_args().push_back( new NameExpr( sizeofName( declType ) ) );
    11091140
    11101141                                        delete objectDecl->get_init();
  • src/GenPoly/GenPoly.cc

    rbaf7fee rae63a18  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Nov 24 15:23:08 2015
    13 // Update Count     : 11
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 15 16:11:18 2015
     13// Update Count     : 13
    1414//
    1515
    1616#include "GenPoly.h"
     17
     18#include "SymTab/Mangler.h"
     19#include "SynTree/Expression.h"
    1720#include "SynTree/Type.h"
    1821
     
    2124
    2225namespace GenPoly {
    23         /// A function needs an adapter if it returns a polymorphic value or if any of its
    24         /// parameters have polymorphic type
    2526        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    26                 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     27                if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    2728                        return true;
    2829                } // if
    2930                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                        if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) {
    3132                                return true;
    3233                        } // if
     
    6667        }
    6768
    68         bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
     69        namespace {
     70                /// Checks a parameter list for polymorphic parameters; will substitute according to env if present
     71                bool hasPolyParams( std::list< Expression* >& params, const TypeSubstitution *env ) {
     72                        for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
     73                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
     74                                assert(paramType && "Aggregate parameters should be type expressions");
     75                                if ( isPolyType( paramType->get_type(), env ) ) return true;
     76                        }
     77                        return false;
     78                }
     79
     80                /// Checks a parameter list for polymorphic parameters from tyVars; will substitute according to env if present
     81                bool hasPolyParams( std::list< Expression* >& params, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     82                        for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
     83                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
     84                                assert(paramType && "Aggregate parameters should be type expressions");
     85                                if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true;
     86                        }
     87                        return false;
     88                }
     89        }
     90
     91        Type *isPolyType( Type *type, const TypeSubstitution *env ) {
    6992                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
     93                        if ( env ) {
     94                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     95                                        return isPolyType( newType, env );
     96                                } // if
     97                        } // if
     98                        return type;
     99                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
     100                        if ( hasPolyParams( structType->get_parameters(), env ) ) return type;
     101                } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
     102                        if ( hasPolyParams( unionType->get_parameters(), env ) ) return type;
     103                }
     104                return 0;
     105        }
     106       
     107        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     108                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
     109                        if ( env ) {
     110                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     111                                        return isPolyType( newType, tyVars, env );
     112                                } // if
     113                        } // if
    70114                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    71                                 return true;
     115                                return type;
     116                        }
     117                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
     118                        if ( hasPolyParams( structType->get_parameters(), tyVars, env ) ) return type;
     119                } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
     120                        if ( hasPolyParams( unionType->get_parameters(), tyVars, env ) ) return type;
     121                }
     122                return 0;
     123        }
     124
     125        Type *isPolyPtr( Type *type, const TypeSubstitution *env ) {
     126                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
     127                        return isPolyType( ptr->get_base(), env );
     128                } else if ( env ) {
     129                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     130                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     131                                        return isPolyPtr( newType, env );
     132                                } // if
    72133                        } // if
    73134                } // if
    74                 return false;
     135                return 0;
     136        }
     137       
     138        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     139                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
     140                        return isPolyType( ptr->get_base(), tyVars, env );
     141                } else if ( env ) {
     142                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     143                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     144                                        return isPolyPtr( newType, tyVars, env );
     145                                } // if
     146                        } // if
     147                } // if
     148                return 0;
    75149        }
    76150
    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 );
     151        FunctionType * getFunctionType( Type *ty ) {
     152                PointerType *ptrType;
     153                if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {
     154                        return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise
    82155                } else {
    83                         return false;
     156                        return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
    84157                }
    85158        }
     
    91164                os << std::endl;
    92165        }
     166
     167        std::string sizeofName( Type *ty ) {
     168                return std::string( "_sizeof_" ) + SymTab::Mangler::mangleType( ty );
     169        }
     170
     171        std::string alignofName( Type *ty ) {
     172                return std::string( "_alignof_" ) + SymTab::Mangler::mangleType( ty );
     173        }
    93174} // namespace GenPoly
    94175
  • src/GenPoly/GenPoly.h

    rbaf7fee rae63a18  
    2020#include <string>
    2121#include <iostream>
     22
    2223#include "SynTree/Declaration.h"
     24#include "SynTree/TypeSubstitution.h"
    2325
    2426namespace GenPoly {
    2527        typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
    2628
     29        /// A function needs an adapter if it returns a polymorphic value or if any of its
     30        /// parameters have polymorphic type
    2731        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
     32
     33        /// true iff function has polymorphic return type
    2834        bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars );
    2935        bool isPolyRet( FunctionType *function, std::string &name );
    3036        bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars );
    31 //      bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
    32         bool isPolyVal( Type *type, const TyVarMap &tyVars );
    3337
    34   // true if type variable or any number of pointers to type variable
    35   bool isPolyObj( Type *type, const TyVarMap &tyVars );
     38        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
     39        Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
     40       
     41        /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
     42        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
     43
     44        /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
     45        Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
     46       
     47        /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
     48        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
     49
     50        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
     51        FunctionType * getFunctionType( Type *ty );
     52
     53        /// Prints type variable map
    3654        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
     55
     56        /// Gets the name of the sizeof parameter for the type
     57        std::string sizeofName( Type *ty );
     58
     59        /// Gets the name of the alignof parameter for the type
     60        std::string alignofName( Type *ty );
    3761} // namespace GenPoly
    3862
  • src/GenPoly/InstantiateGeneric.cc

    rbaf7fee rae63a18  
    7777                std::list< Type* > params;  ///< Instantiation parameters
    7878        };
    79 
     79       
    8080        /// Maps a concrete type to the instantiated struct type, accounting for scope
    8181        class InstantiationMap {
     
    143143        /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
    144144        class Instantiate : public DeclMutator {
     145                /// Map of (generic type, parameter list) pairs to concrete type instantiations
    145146                InstantiationMap instantiations;
     147                /// Namer for concrete types
    146148                UniqueName typeNamer;
    147149
     
    149151                Instantiate() : DeclMutator(), instantiations(), typeNamer("_conc_") {}
    150152
    151 //              virtual Declaration* mutate( StructDecl *aggregateDecl );
    152 //              virtual Declaration* mutate( UnionDecl *aggregateDecl );
    153 
    154153                virtual Type* mutate( StructInstType *inst );
    155154                virtual Type* mutate( UnionInstType *inst );
     155
     156//              virtual Expression* mutate( MemberExpr *memberExpr );
    156157               
    157158                virtual void doBeginScope();
     
    166167        /// Makes substitutions of params into baseParams; returns true if all parameters substituted for a concrete type
    167168        bool makeSubstitutions( const std::list< TypeDecl* >& baseParams, const std::list< Expression* >& params, std::list< TypeExpr* >& out ) {
    168                 bool allConcrete = true;  // will finish the substitution list even if they're not all concrete
     169                bool allConcrete = true;  // will finish the substitution list even if they're not all concrete
    169170
    170171                // substitute concrete types for given parameters, and incomplete types for placeholders
     
    172173                std::list< Expression* >::const_iterator param = params.begin();
    173174                for ( ; baseParam != baseParams.end() && param != params.end(); ++baseParam, ++param ) {
    174                         switch ( (*baseParam)->get_kind() ) {
    175                         case TypeDecl::Any: {   // any type is a valid substitution here; complete types can be used to instantiate generics
     175//                      switch ( (*baseParam)->get_kind() ) {
     176//                      case TypeDecl::Any: {   // any type is a valid substitution here; complete types can be used to instantiate generics
    176177                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
    177178                                assert(paramType && "Aggregate parameters should be type expressions");
     
    179180                                // check that the substituted type isn't a type variable itself
    180181                                if ( dynamic_cast< TypeInstType* >( paramType->get_type() ) ) {
    181                                         allConcrete = false;
     182                                        allConcrete = false;
    182183                                }
    183                                 break;
    184                         }
    185                         case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
    186                                 out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
    187                                 break;
    188                         case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
    189                                 out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
    190                                 break;
    191                         }
    192                 }
    193 
    194                 // if not enough parameters given, substitute remaining incomplete types for placeholders
    195                 for ( ; baseParam != baseParams.end(); ++baseParam ) {
    196                         switch ( (*baseParam)->get_kind() ) {
    197                         case TypeDecl::Any:    // no more substitutions here, fail early
    198                                 return false;
    199                         case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
    200                                 out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
    201                                 break;
    202                         case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
    203                                 out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
    204                                 break;
    205                         }
    206                 }
    207 
    208                 return allConcrete;
    209         }
    210        
     184//                              break;
     185//                      }
     186//                      case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
     187//                              out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
     188//                              break;
     189//                      case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
     190//                              out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
     191//                              break;
     192//                      }
     193                }
     194
     195                // if any parameters left over, not done
     196                if ( baseParam != baseParams.end() ) return false;
     197//              // if not enough parameters given, substitute remaining incomplete types for placeholders
     198//              for ( ; baseParam != baseParams.end(); ++baseParam ) {
     199//                      switch ( (*baseParam)->get_kind() ) {
     200//                      case TypeDecl::Any:    // no more substitutions here, fail early
     201//                              return false;
     202//                      case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
     203//                              out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
     204//                              break;
     205//                      case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
     206//                              out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
     207//                              break;
     208//                      }
     209//              }
     210
     211                return allConcrete;
     212        }
     213
    211214        /// Substitutes types of members of in according to baseParams => typeSubs, appending the result to out
    212215        void substituteMembers( const std::list< Declaration* >& in, const std::list< TypeDecl* >& baseParams, const std::list< TypeExpr* >& typeSubs,
     
    288291                return newInst;
    289292        }
     293
     294//      /// Gets the base struct or union declaration for a member expression; NULL if not applicable
     295//      AggregateDecl* getMemberBaseDecl( MemberExpr *memberExpr ) {
     296//              // get variable for member aggregate
     297//              VariableExpr *varExpr = dynamic_cast< VariableExpr* >( memberExpr->get_aggregate() );
     298//              if ( ! varExpr ) return NULL;
     299//
     300//              // get object for variable
     301//              ObjectDecl *objectDecl = dynamic_cast< ObjectDecl* >( varExpr->get_var() );
     302//              if ( ! objectDecl ) return NULL;
     303//
     304//              // get base declaration from object type
     305//              Type *objectType = objectDecl->get_type();
     306//              StructInstType *structType = dynamic_cast< StructInstType* >( objectType );
     307//              if ( structType ) return structType->get_baseStruct();
     308//              UnionInstType *unionType = dynamic_cast< UnionInstType* >( objectType );
     309//              if ( unionType ) return unionType->get_baseUnion();
     310//
     311//              return NULL;
     312//      }
     313//
     314//      /// Finds the declaration with the given name, returning decls.end() if none such
     315//      std::list< Declaration* >::const_iterator findDeclNamed( const std::list< Declaration* > &decls, const std::string &name ) {
     316//              for( std::list< Declaration* >::const_iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
     317//                      if ( (*decl)->get_name() == name ) return decl;
     318//              }
     319//              return decls.end();
     320//      }
     321//     
     322//      Expression* Instantiate::mutate( MemberExpr *memberExpr ) {
     323//              // mutate, exiting early if no longer MemberExpr
     324//              Expression *expr = Mutator::mutate( memberExpr );
     325//              memberExpr = dynamic_cast< MemberExpr* >( expr );
     326//              if ( ! memberExpr ) return expr;
     327//
     328//              // get declaration of member and base declaration of member, exiting early if not found
     329//              AggregateDecl *memberBase = getMemberBaseDecl( memberExpr );
     330//              if ( ! memberBase ) return memberExpr;
     331//              DeclarationWithType *memberDecl = memberExpr->get_member();
     332//              std::list< Declaration* >::const_iterator baseIt = findDeclNamed( memberBase->get_members(), memberDecl->get_name() );
     333//              if ( baseIt == memberBase->get_members().end() ) return memberExpr;
     334//              DeclarationWithType *baseDecl = dynamic_cast< DeclarationWithType* >( *baseIt );
     335//              if ( ! baseDecl ) return memberExpr;
     336//
     337//              // check if stated type of the member is not the type of the member's declaration; if so, need a cast
     338//              // this *SHOULD* be safe, I don't think anything but the void-replacements I put in for dtypes would make it past the typechecker
     339//              SymTab::Indexer dummy;
     340//              if ( ResolvExpr::typesCompatible( memberDecl->get_type(), baseDecl->get_type(), dummy ) ) return memberExpr;
     341//              else return new CastExpr( memberExpr, memberDecl->get_type() );
     342//      }
    290343       
    291344        void Instantiate::doBeginScope() {
    292345                DeclMutator::doBeginScope();
    293                 // push a new concrete type scope
    294346                instantiations.beginScope();
    295347        }
     
    297349        void Instantiate::doEndScope() {
    298350                DeclMutator::doEndScope();
    299                 // pop the last concrete type scope
    300351                instantiations.endScope();
    301352        }
  • src/GenPoly/Lvalue.cc

    rbaf7fee rae63a18  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:41:33 2015
    13 // Update Count     : 1
     12// Last Modified On : Tue Dec 15 15:33:13 2015
     13// Update Count     : 3
    1414//
    1515
     
    122122                        if ( retval && retStmt->get_expr() ) {
    123123                                assert( ! retStmt->get_expr()->get_results().empty() );
    124                                 while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {
    125                                         retStmt->set_expr( castExpr->get_arg() );
    126                                         retStmt->get_expr()->set_env( castExpr->get_env() );
    127                                         castExpr->set_env( 0 );
    128                                         castExpr->set_arg( 0 );
    129                                         delete castExpr;
    130                                 } // while
    131124                                if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     125                                        // ***** Code Removal ***** because casts may be stripped already
     126
     127                                        // strip casts because not allowed to take address of cast
     128                                        // while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {
     129                                        //      retStmt->set_expr( castExpr->get_arg() );
     130                                        //      retStmt->get_expr()->set_env( castExpr->get_env() );
     131                                        //      castExpr->set_env( 0 );
     132                                        //      castExpr->set_arg( 0 );
     133                                        //      delete castExpr;
     134                                        // } // while
    132135                                        retStmt->set_expr( new AddressExpr( retStmt->get_expr()->acceptMutator( *this ) ) );
    133136                                } else {
  • src/GenPoly/ScrubTyVars.cc

    rbaf7fee rae63a18  
    1313// Update Count     : 2
    1414//
     15
     16#include <sstream>
     17#include <string>
    1518
    1619#include "GenPoly.h"
     
    4245
    4346        Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
    44                 // sizeof( T ) => T parameter, which is the size of T
    45                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
    46                         Expression *expr = new NameExpr( typeInst->get_name() );
     47                // sizeof( T ) => _sizeof_T parameter, which is the size of T
     48                if ( Type *polyType = isPolyType( szeof->get_type() ) ) {
     49                        Expression *expr = new NameExpr( sizeofName( polyType ) );
    4750                        return expr;
    4851                } else {
    4952                        return Mutator::mutate( szeof );
     53                } // if
     54        }
     55
     56        Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
     57                // alignof( T ) => _alignof_T parameter, which is the alignment of T
     58                if ( Type *polyType = isPolyType( algnof->get_type() ) ) {
     59                        Expression *expr = new NameExpr( alignofName( polyType ) );
     60                        return expr;
     61                } else {
     62                        return Mutator::mutate( algnof );
    5063                } // if
    5164        }
  • src/GenPoly/ScrubTyVars.h

    rbaf7fee rae63a18  
    1616#ifndef _SCRUBTYVARS_H
    1717#define _SCRUBTYVARS_H
     18
     19#include <string>
    1820
    1921#include "GenPoly.h"
     
    3638                virtual Type* mutate( TypeInstType *typeInst );
    3739                Expression* mutate( SizeofExpr *szeof );
     40                Expression* mutate( AlignofExpr *algnof );
    3841                virtual Type* mutate( PointerType *pointer );
    3942          private:
  • src/GenPoly/Specialize.cc

    rbaf7fee rae63a18  
    1717
    1818#include "Specialize.h"
     19#include "GenPoly.h"
    1920#include "PolyMutator.h"
    2021
     
    8788        }
    8889
    89         /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
    90         FunctionType * getFunctionType( Type *ty ) {
    91                 PointerType *ptrType;
    92                 if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {
    93                         return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise
    94                 } else {
    95                         return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
    96                 }
    97         }
    98 
    9990        /// Generates a thunk that calls `actual` with type `funType` and returns its address
    10091        Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
  • src/InitTweak/RemoveInit.cc

    rbaf7fee rae63a18  
    77// RemoveInit.cc --
    88//
    9 // Author           : Rodolfo G. Esteves
     9// Author           : Rob Schluntz
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 16:39:32 2015
    13 // Update Count     : 1
     12// Last Modified On : Tue Dec 15 15:37:26 2015
     13// Update Count     : 15
    1414//
    1515
     
    2626                const std::list<Label> noLabels;
    2727        }
     28       
     29        class RemoveInit : public Mutator {
     30          public:
     31                RemoveInit();
     32                virtual ObjectDecl * mutate(ObjectDecl *objDecl);
     33                virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
     34
     35                virtual Statement * mutate( ReturnStmt * returnStmt );
     36               
     37                virtual CompoundStmt * mutate(CompoundStmt * compoundStmt);
     38               
     39          protected:
     40                std::list< Statement* > stmtsToAddBefore;
     41                std::list< Statement* > stmtsToAddAfter;
     42                void mutateStatementList( std::list< Statement* > &statements );
     43
     44                std::list<DeclarationWithType*> returnVals;
     45                UniqueName tempNamer;
     46                std::string funcName;
     47        };
    2848
    2949        void tweak( std::list< Declaration * > translationUnit ) {
     
    3252        }
    3353
     54        RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {}
     55       
    3456        void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
    3557                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     
    3860                        } // if
    3961                        *i = (*i)->acceptMutator( *this );
     62                        if ( ! stmtsToAddBefore.empty() ) {
     63                                statements.splice( i, stmtsToAddBefore );
     64                        } // if
    4065                } // for
    4166                if ( ! stmtsToAddAfter.empty() ) {
     
    4974        }
    5075
    51 // in the case where an object has an initializer and a polymorphic type, insert an assignment
    52 // immediately after the declaration. This will (seemingly) cause the later phases to do the right
    53 // thing with the assignment
     76        // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the
     77        // declaration. This will (seemingly) cause the later phases to do the right thing with the assignment
    5478        ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {
    5579                if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
     
    6387                return objDecl;
    6488        }
     89
     90        Statement *RemoveInit::mutate( ReturnStmt *returnStmt ) {
     91                // update for multiple return values
     92                assert( returnVals.size() == 0 || returnVals.size() == 1 );
     93                // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
     94                // is being returned
     95                if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
     96                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
     97                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
     98                       
     99                        UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
     100                        assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
     101                        assign->get_args().push_back( returnStmt->get_expr() );
     102                        stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign));
     103
     104                        returnStmt->set_expr( new VariableExpr( newObj ) );
     105                } // if
     106                return returnStmt;
     107        }
     108
     109        DeclarationWithType* RemoveInit::mutate( FunctionDecl *functionDecl ) {
     110                std::list<DeclarationWithType*> oldReturnVals = returnVals;
     111                std::string oldFuncName = funcName;
     112               
     113                FunctionType * type = functionDecl->get_functionType();
     114                returnVals = type->get_returnVals();
     115                funcName = functionDecl->get_name();
     116                DeclarationWithType * decl = Mutator::mutate( functionDecl );
     117                returnVals = oldReturnVals;
     118                funcName = oldFuncName;
     119                return decl;
     120        }
    65121} // namespace InitTweak
    66122
  • src/InitTweak/RemoveInit.h

    rbaf7fee rae63a18  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 16:40:11 2015
    13 // Update Count     : 1
     12// Last Modified On : Fri Nov 27 17:00:47 2015
     13// Update Count     : 2
    1414//
    1515
     
    2727        /// Adds assignment statements for polymorphic type initializers
    2828        void tweak( std::list< Declaration * > translationUnit );
    29 
    30         class RemoveInit : public Mutator {
    31           public:
    32                 // RemoveInit();
    33                 virtual ObjectDecl *mutate(ObjectDecl *objDecl);
    34                 virtual CompoundStmt *mutate(CompoundStmt *compoundStmt);
    35           protected:
    36                 std::list< Statement* > stmtsToAddAfter;
    37                 void mutateStatementList( std::list< Statement* > &statements );
    38         };
    3929} // namespace
    4030
  • src/Makefile.in

    rbaf7fee rae63a18  
    413413          esac; \
    414414        done; \
    415         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
     415        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
    416416        $(am__cd) $(top_srcdir) && \
    417           $(AUTOMAKE) --gnu src/Makefile
     417          $(AUTOMAKE) --foreign src/Makefile
    418418.PRECIOUS: Makefile
    419419Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • src/SymTab/Mangler.cc

    rbaf7fee rae63a18  
    3030
    3131namespace SymTab {
    32         Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) {
    33         }
    34 
    35 //Mangler::Mangler( const Mangler & )
    36 //  : mangleName(), varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( isTopLevel )
    37 //{
    38 //}
     32        std::string Mangler::mangleType( Type *ty ) {
     33                Mangler mangler( false, true );
     34                maybeAccept( ty, mangler );
     35                return mangler.get_mangleName();
     36        }
     37       
     38        Mangler::Mangler( bool mangleOverridable, bool typeMode )
     39                : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ) {}
     40               
    3941        Mangler::Mangler( const Mangler &rhs ) : mangleName() {
    4042                varNums = rhs.varNums;
     
    4244                isTopLevel = rhs.isTopLevel;
    4345                mangleOverridable = rhs.mangleOverridable;
     46                typeMode = rhs.typeMode;
    4447        }
    4548
     
    152155        void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {
    153156                printQualifiers( refType );
     157
    154158                mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();
    155159        }
    156160
     161        void Mangler::mangleGenericRef( ReferenceToType *refType, std::string prefix ) {
     162                printQualifiers( refType );
     163
     164                std::ostringstream oldName( mangleName.str() );
     165                mangleName.clear();
     166
     167                mangleName << prefix << refType->get_name();
     168
     169                std::list< Expression* >& params = refType->get_parameters();
     170                if ( ! params.empty() ) {
     171                        mangleName << "_";
     172                        for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) {
     173                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
     174                                assert(paramType && "Aggregate parameters should be type expressions");
     175                                maybeAccept( paramType->get_type(), *this );
     176                        }
     177                        mangleName << "_";
     178                }
     179
     180                oldName << mangleName.str().length() << mangleName.str();
     181                mangleName.str( oldName.str() );
     182        }
     183
    157184        void Mangler::visit( StructInstType *aggregateUseType ) {
    158                 mangleRef( aggregateUseType, "s" );
     185                if ( typeMode ) mangleGenericRef( aggregateUseType, "s" );
     186                else mangleRef( aggregateUseType, "s" );
    159187        }
    160188
    161189        void Mangler::visit( UnionInstType *aggregateUseType ) {
    162                 mangleRef( aggregateUseType, "u" );
     190                if ( typeMode ) mangleGenericRef( aggregateUseType, "u" );
     191                else mangleRef( aggregateUseType, "u" );
    163192        }
    164193
     
    209238
    210239        void Mangler::printQualifiers( Type *type ) {
     240                // skip if not including qualifiers
     241                if ( typeMode ) return;
     242               
    211243                if ( ! type->get_forall().empty() ) {
    212244                        std::list< std::string > assertionNames;
     
    227259                                varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
    228260                                for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    229                                         Mangler sub_mangler( mangleOverridable );
     261                                        Mangler sub_mangler( mangleOverridable, typeMode );
    230262                                        sub_mangler.nextVarNum = nextVarNum;
    231263                                        sub_mangler.isTopLevel = false;
  • src/SymTab/Mangler.h

    rbaf7fee rae63a18  
    2222
    2323namespace SymTab {
     24        /// Mangles names to a unique C identifier
    2425        class Mangler : public Visitor {
    2526          public:
     27                /// Mangle syntax tree object; primary interface to clients
    2628                template< typename SynTreeClass >
    27             static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients
     29            static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true );
     30                /// Mangle a type name; secondary interface
     31                static std::string mangleType( Type* ty );
    2832
    29 ///   using Visitor::visit;
    3033                virtual void visit( ObjectDecl *declaration );
    3134                virtual void visit( FunctionDecl *declaration );
     
    4548                std::string get_mangleName() { return mangleName.str(); }
    4649          private:
    47                 std::ostringstream mangleName;
     50                std::ostringstream mangleName;  ///< Mangled name being constructed
    4851                typedef std::map< std::string, std::pair< int, int > > VarMapType;
    49                 VarMapType varNums;
    50                 int nextVarNum;
    51                 bool isTopLevel;
    52                 bool mangleOverridable;
     52                VarMapType varNums;             ///< Map of type variables to indices
     53                int nextVarNum;                 ///< Next type variable index
     54                bool isTopLevel;                ///< Is the Mangler at the top level
     55                bool mangleOverridable;         ///< Specially mangle overridable built-in methods
     56                bool typeMode;                  ///< Produce a unique mangled name for a type
    5357 
    54                 Mangler( bool mangleOverridable );
     58                Mangler( bool mangleOverridable, bool typeMode );
    5559                Mangler( const Mangler & );
    5660 
    5761                void mangleDecl( DeclarationWithType *declaration );
    5862                void mangleRef( ReferenceToType *refType, std::string prefix );
     63                void mangleGenericRef( ReferenceToType *refType, std::string prefix );
    5964 
    6065                void printQualifiers( Type *type );
     
    6368        template< typename SynTreeClass >
    6469        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
    65                 Mangler mangler( mangleOverridable );
     70                Mangler mangler( mangleOverridable, false );
    6671                maybeAccept( decl, mangler );
    6772                return mangler.get_mangleName();
  • src/SynTree/PointerType.cc

    rbaf7fee rae63a18  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 10:15:16 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue Dec 15 15:39:10 2015
     13// Update Count     : 5
    1414//
    1515
     
    2020PointerType::PointerType( const Type::Qualifiers &tq, Type *base )
    2121        : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) {
    22         base->set_isLvalue( false );
    2322}
    2423
    2524PointerType::PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic )
    2625        : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) {
    27         base->set_isLvalue( false );
    2826}
    2927
  • src/SynTree/Type.h

    rbaf7fee rae63a18  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Type.h -- 
     7// Type.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Dec 09 14:08:41 2015
    13 // Update Count     : 17
     12// Last Modified On : Fri Dec 18 14:46:18 2015
     13// Update Count     : 18
    1414//
    1515
     
    2323class Type {
    2424  public:
    25         struct Qualifiers { 
     25        struct Qualifiers {
    2626                Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
    2727                Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
    28        
     28
    2929                Qualifiers &operator+=( const Qualifiers &other );
    3030                Qualifiers &operator-=( const Qualifiers &other );
     
    3636                bool operator<( const Qualifiers &other );
    3737                bool operator>( const Qualifiers &other );
    38        
     38
    3939                bool isConst;
    4040                bool isVolatile;
     
    4343                bool isAtomic;
    4444                bool isAttribute;
    45         };     
     45        };
    4646
    4747        Type( const Qualifiers &tq );
     
    8585class BasicType : public Type {
    8686  public:
    87         enum Kind { 
     87        enum Kind {
    8888                Bool,
    8989                Char,
     
    108108                LongDoubleImaginary,
    109109                NUMBER_OF_BASIC_TYPES
    110         }; 
     110        };
    111111
    112112        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
     
    149149  private:
    150150        Type *base;
    151        
     151
    152152        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
    153153        Expression *dimension;
     
    188188        virtual ~FunctionType();
    189189
    190         std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
    191         std::list<DeclarationWithType*>& get_parameters() { return parameters; }
     190        std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
     191        std::list<DeclarationWithType*> & get_parameters() { return parameters; }
    192192        bool get_isVarArgs() { return isVarArgs; }
    193193        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
     
    217217        void set_name( std::string newValue ) { name = newValue; }
    218218        std::list< Expression* >& get_parameters() { return parameters; }
    219        
     219
    220220        virtual ReferenceToType *clone() const = 0;
    221221        virtual void accept( Visitor &v ) = 0;
     
    240240        /// Accesses generic parameters of base struct (NULL if none such)
    241241        std::list<TypeDecl*> * get_baseParameters();
    242        
     242
    243243        /// Looks up the members of this struct named "name" and places them into "foundDecls".
    244244        /// Clones declarations into "foundDecls", caller responsible for freeing
     
    250250  private:
    251251        virtual std::string typeString() const;
    252        
     252
    253253        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
    254254        // where the structure used in this type is actually defined
     
    267267        /// Accesses generic parameters of base union (NULL if none such)
    268268        std::list<TypeDecl*> * get_baseParameters();
    269        
     269
    270270        /// looks up the members of this union named "name" and places them into "foundDecls"
    271271        /// Clones declarations into "foundDecls", caller responsible for freeing
     
    277277  private:
    278278        virtual std::string typeString() const;
    279        
     279
    280280        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    281281        // where the union used in this type is actually defined
     
    310310  private:
    311311        virtual std::string typeString() const;
    312        
     312
    313313        // this member is filled in by the validate pass, which instantiates the members of the correponding
    314314        // aggregate with the actual type parameters specified for this use of the context
     
    327327        bool get_isFtype() const { return isFtype; }
    328328        void set_isFtype( bool newValue ) { isFtype = newValue; }
    329        
     329
    330330        virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
    331331        virtual void accept( Visitor &v ) { v.visit( this ); }
  • src/driver/Makefile.in

    rbaf7fee rae63a18  
    195195          esac; \
    196196        done; \
    197         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/driver/Makefile'; \
     197        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/driver/Makefile'; \
    198198        $(am__cd) $(top_srcdir) && \
    199           $(AUTOMAKE) --gnu src/driver/Makefile
     199          $(AUTOMAKE) --foreign src/driver/Makefile
    200200.PRECIOUS: Makefile
    201201Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • src/examples/Makefile.in

    rbaf7fee rae63a18  
    191191          esac; \
    192192        done; \
    193         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/examples/Makefile'; \
     193        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/examples/Makefile'; \
    194194        $(am__cd) $(top_srcdir) && \
    195           $(AUTOMAKE) --gnu src/examples/Makefile
     195          $(AUTOMAKE) --foreign src/examples/Makefile
    196196.PRECIOUS: Makefile
    197197Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • src/examples/fstream_test.c

    rbaf7fee rae63a18  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:13:43 2015
    13 // Update Count     : 2
     12// Last Modified On : Mon Nov 23 14:43:32 2015
     13// Update Count     : 40
    1414//
    1515
     
    2020        ifstream *sin = ifstream_stdin();
    2121        int nombre;
    22         sout << "Appuyez un nombre, s'il vous plâit:\n";
    23         sin >> &nombre;
    24         sout << "Vous avez appuyé: " << nombre << "\n";
     22        sout | "Entrez un nombre, s'il vous plaît:\n";
     23        sin  | &nombre;
     24        sout | "Vous avez entré " | nombre | " stocké à l'adresse " | &nombre | endl;
     25        sout | "nombre " | nombre | " est "
     26                 | (nombre > 0 ? "plus grand que" :
     27                   nombre == 0 ? "égal à" : "moins de")
     28                 | " zéro" | endl;
     29
     30        sout | "Entrez trois nombres, s'il vous plaît:\n";
     31        int i, j, k;
     32        sin  | &i | &j | &k;
     33        sout | "Vous avez entré " | "i:" | i | " j:" | j | " k:" | k | endl;
     34
     35        sout | 3 | ' ' | 3.5 | ' ' | 'a' | ' ' | "abc" | endl;
    2536}
    2637
  • src/examples/hello.c

    rbaf7fee rae63a18  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 20 16:02:50 2015
    13 // Update Count     : 3
     12// Last Modified On : Sun Nov 22 17:40:37 2015
     13// Update Count     : 5
    1414//
    1515
     
    1919        ofstream *sout = ofstream_stdout();
    2020        ifstream *sin = ifstream_stdin();
    21         sout << "Bonjour au monde!\n";
    22         sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n";
    23         int i, j, k;
    24         sin >> &i >> &j >> &k;
    25         sout << "i:" << i << " j:" << j << " k:" << k << "\n";
     21        sout | "Bonjour au monde!\n";
    2622}
    2723
  • src/examples/iostream.c

    rbaf7fee rae63a18  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 20 13:19:19 2015
    13 // Update Count     : 9
     12// Last Modified On : Mon Dec  7 23:08:02 2015
     13// Update Count     : 24
    1414//
    1515
     
    2121
    2222forall( dtype ostype | ostream( ostype ) )
    23 ostype * ?<<?( ostype *os, char c ) {
     23ostype * ?|?( ostype *os, char c ) {
    2424        return write( os, &c, 1 );
    25 } // ?<<?
     25} // ?|?
    2626
    2727forall( dtype ostype | ostream( ostype ) )
    28 ostype * ?<<?( ostype *os, int i ) {
     28ostype * ?|?( ostype *os, int i ) {
    2929        char buffer[32];                                                                        // larger than the largest integer
    3030        sprintf( buffer, "%d", i );
    3131        return write( os, buffer, strlen( buffer ) );
    32 } // ?<<?
     32} // ?|?
    3333
    3434forall( dtype ostype | ostream( ostype ) )
    35 ostype * ?<<?( ostype *os, double d ) {
     35ostype * ?|?( ostype *os, double d ) {
    3636        char buffer[32];                                                                        // larger than the largest double
    3737        sprintf( buffer, "%g", d );
    3838        return write( os, buffer, strlen( buffer ) );
    39 } // ?<<?
     39} // ?|?
    4040
    4141forall( dtype ostype | ostream( ostype ) )
    42 ostype * ?<<?( ostype *os, const char *cp ) {
     42ostype * ?|?( ostype *os, const char *cp ) {
    4343        return write( os, cp, strlen( cp ) );
    44 } // ?<<?
     44} // ?|?
    4545
    4646forall( dtype ostype | ostream( ostype ) )
    47 ostype * ?<<?( ostype *os, const void *p ) {
     47ostype * ?|?( ostype *os, const void *p ) {
    4848        char buffer[32];                                                                        // larger than the largest pointer
    4949        sprintf( buffer, "%p", p );
    5050        return write( os, buffer, strlen( buffer ) );
    51 } // ?<<?
     51} // ?|?
     52
     53
     54forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
     55retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
     56  return manip(os);
     57}
     58
     59forall( dtype ostype | ostream( ostype ) )
     60ostype * endl( ostype * os ) {
     61  os | "\n";
     62  // flush
     63  return os;
     64} // endl
    5265
    5366forall( type elt_type | writeable( elt_type ),
     
    5669void write( iterator_type begin, iterator_type end, os_type *os ) {
    5770        void print( elt_type i ) {
    58                 os << i << ' ';
     71                os | i | ' ';
    5972        }
    6073        for_each( begin, end, print );
    61 } // ?<<?
     74} // ?|?
    6275
    6376forall( type elt_type | writeable( elt_type ),
     
    6578                dtype os_type | ostream( os_type ) )
    6679void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
    67         void print( elt_type i ) {
    68                 os << i << ' ';
    69         }
     80        void print( elt_type i ) { os | i | ' '; }
    7081        for_each_reverse( begin, end, print );
    71 } // ?<<?
     82} // ?|?
    7283
    7384
    7485forall( dtype istype | istream( istype ) )
    75 istype * ?>>?( istype *is, char *cp ) {
     86istype * ?|?( istype *is, char *cp ) {
    7687        return read( is, cp, 1 );
    77 } // ?>>?
     88} // ?|?
    7889
    7990forall( dtype istype | istream( istype ) )
    80 istype * ?>>?( istype *is, int *ip ) {
     91istype * ?|?( istype *is, int *ip ) {
    8192        char cur;
    8293 
    8394        // skip some whitespace
    8495        do {
    85                 is >> &cur;
     96                is | &cur;
    8697                if ( fail( is ) || eof( is ) ) return is;
    8798        } while ( !( cur >= '0' && cur <= '9' ) );
     
    91102        while ( cur >= '0' && cur <= '9' ) {
    92103                *ip = *ip * 10 + ( cur - '0' );
    93                 is >> &cur;
     104                is | &cur;
    94105                if ( fail( is ) || eof( is ) ) return is;
    95106        }
     
    97108        unread( is, cur );
    98109        return is;
    99 } // ?>>?
     110} // ?|?
    100111
    101112// Local Variables: //
  • src/examples/iostream.h

    rbaf7fee rae63a18  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:56:51 2015
    13 // Update Count     : 5
     12// Last Modified On : Mon Nov 23 14:15:25 2015
     13// Update Count     : 17
    1414//
    1515
     
    2727
    2828context writeable( type T ) {
    29         forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
     29        forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
    3030};
    3131
    3232// implement writable for some intrinsic types
    3333
    34 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, char );
    35 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, int );
    36 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
    37 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
    38 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * );
     34forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char );
     35forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int );
     36forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double );
     37forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * );
     38forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * );
     39
     40forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );
     41forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
    3942
    4043// writes the range [begin, end) to the given stream
     
    4952void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    5053
     54//******************************************************************************
    5155
    5256context istream( dtype istype ) {
     
    5862
    5963context readable( type T ) {
    60         forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
     64        forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
    6165};
    6266
    6367forall( dtype istype | istream( istype ) )
    64 istype * ?>>?( istype *, char * );
     68istype * ?|?( istype *, char * );
    6569
    6670forall( dtype istype | istream( istype ) )
    67 istype * ?>>?( istype *, int * );
     71istype * ?|?( istype *, int * );
    6872
    6973#endif // IOSTREAM_H
  • src/examples/sum.c

    rbaf7fee rae63a18  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 28 15:09:55 2015
    13 // Update Count     : 118
     12// Last Modified On : Sat Nov 21 18:08:18 2015
     13// Update Count     : 119
    1414//
    1515
     
    5353        }
    5454        sout << "sum from " << low << " to " << High << " is "
    55                  << (int)sum( size, a ) << ", check " << (int)s << "\n";
     55                 << (int)sum( size, a ) << ", check " << (int)s << endl;
    5656
    5757        int s = 0, a[size];
     
    6262        }
    6363        sout << "sum from " << low << " to " << High << " is "
    64                  << sum( size, (int *)a ) << ", check " << (int)s << "\n";
     64                 << sum( size, (int *)a ) << ", check " << (int)s << endl;
    6565
    6666        double s = 0.0, a[size];
     
    7272        printf( "%g\n", sum( size, (double *)a ) );
    7373//      sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is "
    74 //               << sum( size, (double *)a ) << ", check " << (double)s << "\n";
     74//               << sum( size, (double *)a ) << ", check " << (double)s << endl;
    7575
    7676        float s = 0.0, a[size];
     
    8282        printf( "%g\n", sum( size, (float *)a ) );
    8383//      sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is "
    84 //               << sum( size, (float *)a ) << ", check " << (float)s << "\n";
     84//               << sum( size, (float *)a ) << ", check " << (float)s << endl;
    8585}
    8686
  • src/examples/vector_test.c

    rbaf7fee rae63a18  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:54:34 2015
    13 // Update Count     : 9
     12// Last Modified On : Tue Dec 15 16:02:56 2015
     13// Update Count     : 13
    1414//
    1515
     
    2727        int num;
    2828
    29         sout << "enter N elements and C-d on a separate line:\n";
     29        sout | "enter N elements and C-d on a separate line:" | endl;
    3030        for ( ;; ) {
    31                 sin >> &num;
     31                sin | &num;
    3232          if ( fail( sin ) || eof( sin ) ) break;
    3333                append( &vec, num );
     
    3535        // write out the numbers
    3636
    37         sout << "Array elements:\n";
     37        sout | "Array elements:" | endl;
    3838        write( begin( vec ), end( vec ), sout );
    39         sout << "\n";
     39        sout | endl;
    4040
    41         sout << "Array elements reversed:\n";
     41        sout | "Array elements reversed:" | endl;
    4242        write_reverse( begin( vec ), end( vec ), sout );
    43         sout << "\n";
     43        sout | endl;
    4444}
    4545
  • src/libcfa/Makefile.am

    rbaf7fee rae63a18  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Thu Jun  4 22:49:16 2015
    14 ## Update Count     : 7
     13## Last Modified On : Wed Dec 16 22:58:17 2015
     14## Update Count     : 9
    1515###############################################################################
    1616
     
    4444
    4545libcfa-prelude.c : ${srcdir}/prelude.cf
    46         ${libdir}/cfa-cpp -l ${srcdir}/prelude.cf $@
     46        ../cfa-cpp -l ${srcdir}/prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    4747
    4848libcfa-prelude.o : libcfa-prelude.c
  • src/libcfa/Makefile.in

    rbaf7fee rae63a18  
    220220          esac; \
    221221        done; \
    222         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libcfa/Makefile'; \
     222        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/libcfa/Makefile'; \
    223223        $(am__cd) $(top_srcdir) && \
    224           $(AUTOMAKE) --gnu src/libcfa/Makefile
     224          $(AUTOMAKE) --foreign src/libcfa/Makefile
    225225.PRECIOUS: Makefile
    226226Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
     
    542542
    543543libcfa-prelude.c : ${srcdir}/prelude.cf
    544         ${libdir}/cfa-cpp -l ${srcdir}/prelude.cf $@
     544        ../cfa-cpp -l ${srcdir}/prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    545545
    546546libcfa-prelude.o : libcfa-prelude.c
  • src/main.cc

    rbaf7fee rae63a18  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 22:31:40 2015
    13 // Update Count     : 168
     12// Last Modified On : Thu Dec 17 12:59:06 2015
     13// Update Count     : 179
    1414//
    1515
     
    187187                // read in the builtins and the prelude
    188188                if ( ! nopreludep ) {                                                   // include gcc builtins
    189                         FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" );
     189                        // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
     190                        FILE * builtins = fopen( libcfap ? "./builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );
    190191                        if ( builtins == NULL ) {
    191192                                std::cerr << "Error: can't open builtins" << std::endl;
     
    196197
    197198                        if ( ! libcfap ) {
    198                                 // read the prelude in, if we're not generating the cfa library
     199                                // read the prelude in, if not generating the cfa library
    199200                                FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" );
    200201                                if ( prelude == NULL ) {
     
    203204                                } // if
    204205                   
    205                     parse( prelude, LinkageSpec::Intrinsic );
     206                                parse( prelude, LinkageSpec::Intrinsic );
    206207                        } // if
    207208                } // if
    208209
    209                 if ( libcfap ) {
    210                         parse( input, LinkageSpec::Intrinsic );
    211                 } else {
    212                         parse( input, LinkageSpec::Cforall, grammarp );
    213                 }
     210                parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );     
    214211 
    215212                if ( parsep ) {
Note: See TracChangeset for help on using the changeset viewer.