Ignore:
Timestamp:
Feb 20, 2017, 12:05:49 PM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
3bff885
Parents:
facc44f (diff), d150ea2 (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    rfacc44f rbd9bcc8  
    2929#include "ResolvExpr/typeops.h"
    3030#include "InitTweak/GenInit.h"
     31#include "InitTweak/InitTweak.h"
    3132
    3233namespace Tuples {
     
    7879                        }
    7980                  private:
    80                         ScopedMap< std::string, StructDecl * > typeMap;
     81                        ScopedMap< int, StructDecl * > typeMap;
    8182                };
    8283
     
    213214
    214215        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
    215                 std::string mangleName = SymTab::Mangler::mangleType( tupleType );
    216216                tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
    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 );
     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  ) );
    221221                        decl->set_body( true );
    222                         for ( size_t i = 0; i < tupleType->size(); ++i ) {
     222                        for ( size_t i = 0; i < tupleSize; ++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 ( tupleType->size() == 0 ) {
     227                        if ( tupleSize == 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[mangleName] = decl;
     231                        typeMap[tupleSize] = decl;
    232232                        addDeclaration( decl );
    233233                }
    234234                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
    235235
    236                 StructDecl * decl = typeMap[mangleName];
     236                StructDecl * decl = typeMap[tupleSize];
    237237                StructInstType * newType = new StructInstType( qualifiers, decl );
    238238                for ( Type * t : *tupleType ) {
     
    337337                public:
    338338                        typedef Visitor Parent;
    339                         virtual void visit( ApplicationExpr * appExpr ) { maybeImpure = true;   }
     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                        }
    340351                        virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; }
    341352                        bool maybeImpure = false;
Note: See TracChangeset for help on using the changeset viewer.