Changeset 63db3d76 for src/GenPoly


Ignore:
Timestamp:
Dec 4, 2015, 3:13:40 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
cdec5af
Parents:
47534159
Message:

Temporarily roll back dtype-to-void optimization until it works properly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGeneric.cc

    r47534159 r63db3d76  
    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        }
Note: See TracChangeset for help on using the changeset viewer.