Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    re6512c8 rc0aa336  
    2929#include "ResolvExpr/typeops.h"
    3030#include "InitTweak/GenInit.h"
    31 #include "InitTweak/InitTweak.h"
    3231
    3332namespace Tuples {
     
    7978                        }
    8079                  private:
    81                         ScopedMap< int, StructDecl * > typeMap;
     80                        ScopedMap< std::string, StructDecl * > typeMap;
    8281                };
    8382
     
    214213
    215214        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
     215                std::string mangleName = SymTab::Mangler::mangleType( tupleType );
    216216                tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
    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  ) );
     217                if ( ! typeMap.count( mangleName ) ) {
     218                        // generate struct type to replace tuple type
     219                        // xxx - should fix this to only generate one tuple struct for each number of type parameters
     220                        StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName );
    221221                        decl->set_body( true );
    222                         for ( size_t i = 0; i < tupleSize; ++i ) {
     222                        for ( size_t i = 0; i < tupleType->size(); ++i ) {
    223223                                TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any );
    224224                                decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    225225                                decl->get_parameters().push_back( tyParam );
    226226                        }
    227                         if ( tupleSize == 0 ) {
     227                        if ( tupleType->size() == 0 ) {
    228228                                // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created.
    229229                                decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    230230                        }
    231                         typeMap[tupleSize] = decl;
     231                        typeMap[mangleName] = decl;
    232232                        addDeclaration( decl );
    233233                }
    234234                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
    235235
    236                 StructDecl * decl = typeMap[tupleSize];
     236                StructDecl * decl = typeMap[mangleName];
    237237                StructInstType * newType = new StructInstType( qualifiers, decl );
    238238                for ( Type * t : *tupleType ) {
     
    337337                public:
    338338                        typedef Visitor Parent;
    339                         virtual void visit( ApplicationExpr * appExpr ) {
    340                                 if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
    341                                         if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
    342                                                 if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) {
    343                                                         // intrinsic dereference, subscript are pure, but need to recursively look for impurity
    344                                                         Parent::visit( appExpr );
    345                                                         return;
    346                                                 }
    347                                         }
    348                                 }
    349                                 maybeImpure = true;
    350                         }
     339                        virtual void visit( ApplicationExpr * appExpr ) { maybeImpure = true;   }
    351340                        virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; }
    352341                        bool maybeImpure = false;
Note: See TracChangeset for help on using the changeset viewer.