Ignore:
Timestamp:
Feb 15, 2017, 8:42:12 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
32b8144
Parents:
97f65d5
Message:

generate tuples by arity to reduce the number of generated structs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    r97f65d5 re6512c8  
    7979                        }
    8080                  private:
    81                         ScopedMap< std::string, StructDecl * > typeMap;
     81                        ScopedMap< int, StructDecl * > typeMap;
    8282                };
    8383
     
    214214
    215215        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
    216                 std::string mangleName = SymTab::Mangler::mangleType( tupleType );
    217216                tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
    218                 if ( ! typeMap.count( mangleName ) ) {
    219                         // generate struct type to replace tuple type
    220                         // xxx - should fix this to only generate one tuple struct for each number of type parameters
    221                         StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName );
     217                unsigned tupleSize = tupleType->size();
     218                if ( ! typeMap.count( tupleSize ) ) {
     219                        // generate struct type to replace tuple type based on the number of components in the tuple
     220                        StructDecl * decl = new StructDecl( toString( "_tuple_type_", tupleSize  ) );
    222221                        decl->set_body( true );
    223                         for ( size_t i = 0; i < tupleType->size(); ++i ) {
     222                        for ( size_t i = 0; i < tupleSize; ++i ) {
    224223                                TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any );
    225224                                decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    226225                                decl->get_parameters().push_back( tyParam );
    227226                        }
    228                         if ( tupleType->size() == 0 ) {
     227                        if ( tupleSize == 0 ) {
    229228                                // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created.
    230229                                decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    231230                        }
    232                         typeMap[mangleName] = decl;
     231                        typeMap[tupleSize] = decl;
    233232                        addDeclaration( decl );
    234233                }
    235234                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
    236235
    237                 StructDecl * decl = typeMap[mangleName];
     236                StructDecl * decl = typeMap[tupleSize];
    238237                StructInstType * newType = new StructInstType( qualifiers, decl );
    239238                for ( Type * t : *tupleType ) {
Note: See TracChangeset for help on using the changeset viewer.