Changeset 33a7b6d


Ignore:
Timestamp:
Nov 15, 2016, 5:30:52 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
d9fa60a
Parents:
8f9cc50
Message:

changed use of formal types to actual types for boxing return parameters and passing type variables, fix bug where generic struct's members would change types when a member is accessed on a concrete instantiation

Location:
src
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r8f9cc50 r33a7b6d  
    12881288                        TyVarMap exprTyVars( (TypeDecl::Kind)-1 );
    12891289                        makeTyVarMap( function, exprTyVars );
     1290                        ReferenceToType *concRetType = dynamic_cast< ReferenceToType* >( appExpr->get_result() ); // xxx - is concRetType a good name?
    12901291                        ReferenceToType *dynRetType = isDynRet( function, exprTyVars );
    12911292
    12921293                        if ( dynRetType ) {
    1293                                 ret = addDynRetParam( appExpr, function, dynRetType, arg );
     1294                                ret = addDynRetParam( appExpr, function, concRetType, arg ); // xxx - used to use dynRetType instead of concRetType
    12941295                        } else if ( needsAdapter( function, scopeTyVars ) ) {
    12951296                                // std::cerr << "needs adapter: ";
     
    13011302                        arg = appExpr->get_args().begin();
    13021303
    1303                         passTypeVars( appExpr, dynRetType, arg, exprTyVars );
     1304                        passTypeVars( appExpr, concRetType, arg, exprTyVars ); // xxx - used to use dynRetType instead of concRetType
    13041305                        addInferredParams( appExpr, function, arg, exprTyVars );
    13051306
     
    13641365                        // line below cloned from FixFunction.cc
    13651366                        // xxx - functionObj is never added to a list of declarations...
     1367                        // alternatively, this function could return a new VariableExpr( functionDecl ) and change the result type of the new expression
    13661368                        ObjectDecl *functionObj = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0,
    13671369                                                                  new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
  • src/GenPoly/GenPoly.cc

    r8f9cc50 r33a7b6d  
    9292        }
    9393
    94         Type *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     94        ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    9595                type = replaceTypeInst( type, env );
    9696
     
    9898                        auto var = tyVars.find( typeInst->get_name() );
    9999                        if ( var != tyVars.end() && var->second == TypeDecl::Any ) {
    100                                 return type;
     100                                return typeInst;
    101101                        }
    102102                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
    103                         if ( hasDynParams( structType->get_parameters(), tyVars, env ) ) return type;
     103                        if ( hasDynParams( structType->get_parameters(), tyVars, env ) ) return structType;
    104104                } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
    105                         if ( hasDynParams( unionType->get_parameters(), tyVars, env ) ) return type;
     105                        if ( hasDynParams( unionType->get_parameters(), tyVars, env ) ) return unionType;
    106106                }
    107107                return 0;
  • src/GenPoly/GenPoly.h

    r8f9cc50 r33a7b6d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // GenPoly.h -- 
     7// GenPoly.h --
    88//
    99// Author           : Richard C. Bilson
     
    3434        /// Replaces a TypeInstType by its referrent in the environment, if applicable
    3535        Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
    36        
     36
    3737        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
    3838        Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
    39        
     39
    4040        /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
    4141        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    4242
    4343        /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
    44         Type *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
     44        ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    4545
    4646        /// true iff function has dynamic-layout return type under the given type variable map
     
    5555        /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
    5656        Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
    57        
     57
    5858        /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
    5959        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
     
    7676        /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
    7777        void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
    78        
     78
    7979        /// Prints type variable map
    8080        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
     
    8282        /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
    8383        inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
    84        
     84
    8585        /// Gets the name of the sizeof parameter for the type, given its mangled name
    8686        inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
     
    9494        /// Gets the name of the layout function for a given aggregate type, given its declaration
    9595        inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
    96        
     96
    9797} // namespace GenPoly
    9898
  • src/ResolvExpr/AlternativeFinder.cc

    r8f9cc50 r33a7b6d  
    218218                std::list< Declaration* > members;
    219219                aggInst->lookup( name, members );
     220                TypeSubstitution sub = TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
    220221                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    221222                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
    222                                 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) );
     223                                MemberExpr * memExpr = new MemberExpr( dwt, expr->clone() );
     224                                sub.apply( memExpr );
     225                                alternatives.push_back( Alternative( memExpr, env, newCost ) );
    223226                                renameTypes( alternatives.back().expr );
    224227                        } else {
     
    800803                AlternativeFinder funcFinder( indexer, env );
    801804                funcFinder.findWithAdjustment( memberExpr->get_aggregate() );
    802 
    803805                for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) {
    804806                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( agg->expr->get_result() ) ) {
  • src/SynTree/ReferenceToType.cc

    r8f9cc50 r33a7b6d  
    4646
    4747namespace {
    48         void doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) {
    49                 std::list< Declaration* > found;
     48        void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
    5049                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    5150                        if ( (*i)->get_name() == name ) {
    52                                 found.push_back( *i );
     51                                foundDecls.push_back( *i );
    5352                        } // if
    5453                } // for
    55                 applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );
    5654        }
    5755} // namespace
     
    6866void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    6967        assert( baseStruct );
    70         doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
     68        doLookup( baseStruct->get_members(), name, foundDecls );
    7169}
    7270
     
    9492void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
    9593        assert( baseUnion );
    96         doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
     94        doLookup( baseUnion->get_members(), name, foundDecls );
    9795}
    9896
  • src/tests/tupleAssign.c

    r8f9cc50 r33a7b6d  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// tupleAssign.c --
     8//
     9// Author           : Rob Schluntz
     10// Created On       : Tue Nov 15 17:24:32 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 15 17:27:28 2016
     13// Update Count     : 3
     14//
     15
    116int main() {
    217        {
     
    3954        }
    4055}
     56
     57// Local Variables: //
     58// tab-width: 4 //
     59// End: //
  • src/tests/tupleFunction.c

    r8f9cc50 r33a7b6d  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// tupleFunction.c --
     8//
     9// Author           : Rob Schluntz
     10// Created On       : Tue Nov 15 17:24:32 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 15 17:27:28 2016
     13// Update Count     : 3
     14//
     15
    116struct S {
    217        int f1, f2;
     
    7792        printf("x1=%d x2=%lg x3=%d\n", x1, x2, x3);
    7893}
     94
     95// Local Variables: //
     96// tab-width: 4 //
     97// End: //
     98
  • src/tests/tupleMember.c

    r8f9cc50 r33a7b6d  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// tupleFunction.c --
     8//
     9// Author           : Rob Schluntz
     10// Created On       : Tue Nov 15 17:24:32 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 15 17:27:28 2016
     13// Update Count     : 3
     14//
     15
    116void f() {
    217        printf("called f!\n");
     
    4156        printf("v.[f1, i.[f2, f3], f4]=[%d, [%d, %d], %lg]\n", h().[f1, i.[f2, f3], f4]);
    4257}
     58
     59// Local Variables: //
     60// tab-width: 4 //
     61// End: //
Note: See TracChangeset for help on using the changeset viewer.